ConstantInt::get{True,False} moved to LLVMContext

Non-breaking build fix for LLVM r76533. Also fixes a context related
bug in GarbageCollect2Stack.
This commit is contained in:
Benjamin Kramer 2009-07-21 13:11:39 +02:00
parent 51c02d192a
commit a398cd39b3
3 changed files with 31 additions and 32 deletions

View file

@ -784,11 +784,11 @@ LLValue* DtoArrayCompare(Loc& loc, TOK op, DValue* l, DValue* r)
break; break;
case TOKleg: case TOKleg:
skip = true; skip = true;
res = llvm::ConstantInt::getTrue(); res = gIR->context().getConstantIntTrue();
break; break;
case TOKunord: case TOKunord:
skip = true; skip = true;
res = llvm::ConstantInt::getFalse(); res = gIR->context().getConstantIntFalse();
break; break;
default: default:

View file

@ -85,7 +85,6 @@ static void EmitMemZero(LLVMContext& Context, IRBuilder<>& B, Value* Dst,
namespace { namespace {
class FunctionInfo { class FunctionInfo {
protected: protected:
LLVMContext* Context;
const Type* Ty; const Type* Ty;
public: public:
@ -94,7 +93,7 @@ namespace {
// Analyze the current call, filling in some fields. Returns true if // Analyze the current call, filling in some fields. Returns true if
// this is an allocation we can stack-allocate. // this is an allocation we can stack-allocate.
virtual bool analyze(CallSite CS, const Analysis& A) { virtual bool analyze(LLVMContext& context, CallSite CS, const Analysis& A) {
Value* TypeInfo = CS.getArgument(TypeInfoArgNr); Value* TypeInfo = CS.getArgument(TypeInfoArgNr);
Ty = A.getTypeFor(TypeInfo); Ty = A.getTypeFor(TypeInfo);
return (Ty != NULL); return (Ty != NULL);
@ -102,15 +101,15 @@ namespace {
// Returns the alloca to replace this call. // Returns the alloca to replace this call.
// It will always be inserted before the call. // It will always be inserted before the call.
virtual AllocaInst* promote(CallSite CS, IRBuilder<>& B, const Analysis& A) { virtual AllocaInst* promote(LLVMContext& context, CallSite CS, IRBuilder<>& B, const Analysis& A) {
NumGcToStack++; NumGcToStack++;
Instruction* Begin = CS.getCaller()->getEntryBlock().begin(); Instruction* Begin = CS.getCaller()->getEntryBlock().begin();
return new AllocaInst(Ty, ".nongc_mem", Begin); // FIXME: align? return new AllocaInst(Ty, ".nongc_mem", Begin); // FIXME: align?
} }
FunctionInfo(LLVMContext* context, unsigned typeInfoArgNr, bool safeToDelete) FunctionInfo(unsigned typeInfoArgNr, bool safeToDelete)
: Context(context), TypeInfoArgNr(typeInfoArgNr), SafeToDelete(safeToDelete) {} : TypeInfoArgNr(typeInfoArgNr), SafeToDelete(safeToDelete) {}
}; };
class ArrayFI : public FunctionInfo { class ArrayFI : public FunctionInfo {
@ -119,15 +118,15 @@ namespace {
bool Initialized; bool Initialized;
public: public:
ArrayFI(LLVMContext* context, unsigned tiArgNr, bool safeToDelete, ArrayFI(unsigned tiArgNr, bool safeToDelete,
bool initialized, unsigned arrSizeArgNr) bool initialized, unsigned arrSizeArgNr)
: FunctionInfo(context, tiArgNr, safeToDelete), : FunctionInfo(tiArgNr, safeToDelete),
ArrSizeArgNr(arrSizeArgNr), ArrSizeArgNr(arrSizeArgNr),
Initialized(initialized) Initialized(initialized)
{} {}
virtual bool analyze(CallSite CS, const Analysis& A) { virtual bool analyze(LLVMContext& context, CallSite CS, const Analysis& A) {
if (!FunctionInfo::analyze(CS, A)) if (!FunctionInfo::analyze(context, CS, A))
return false; return false;
arrSize = CS.getArgument(ArrSizeArgNr); arrSize = CS.getArgument(ArrSizeArgNr);
@ -155,7 +154,7 @@ namespace {
return true; return true;
} }
virtual AllocaInst* promote(CallSite CS, IRBuilder<>& B, const Analysis& A) { virtual AllocaInst* promote(LLVMContext& context, CallSite CS, IRBuilder<>& B, const Analysis& A) {
IRBuilder<> Builder = B; IRBuilder<> Builder = B;
// If the allocation is of constant size it's best to put it in the // If the allocation is of constant size it's best to put it in the
// entry block, so do so if we're not already there. // entry block, so do so if we're not already there.
@ -178,11 +177,11 @@ namespace {
if (Initialized) { if (Initialized) {
// For now, only zero-init is supported. // For now, only zero-init is supported.
uint64_t size = A.TD.getTypeStoreSize(Ty); uint64_t size = A.TD.getTypeStoreSize(Ty);
Value* TypeSize = Context->getConstantInt(arrSize->getType(), size); Value* TypeSize = context.getConstantInt(arrSize->getType(), size);
// Use the original B to put initialization at the // Use the original B to put initialization at the
// allocation site. // allocation site.
Value* Size = B.CreateMul(TypeSize, arrSize); Value* Size = B.CreateMul(TypeSize, arrSize);
EmitMemZero(*Context, B, alloca, Size, A); EmitMemZero(context, B, alloca, Size, A);
} }
return alloca; return alloca;
@ -192,7 +191,7 @@ namespace {
// FunctionInfo for _d_allocclass // FunctionInfo for _d_allocclass
class AllocClassFI : public FunctionInfo { class AllocClassFI : public FunctionInfo {
public: public:
virtual bool analyze(CallSite CS, const Analysis& A) { virtual bool analyze(LLVMContext& context, CallSite CS, const Analysis& A) {
// This call contains no TypeInfo parameter, so don't call the // This call contains no TypeInfo parameter, so don't call the
// base class implementation here... // base class implementation here...
if (CS.arg_size() != 1) if (CS.arg_size() != 1)
@ -223,8 +222,8 @@ namespace {
if (hasDestructor == NULL || hasCustomDelete == NULL) if (hasDestructor == NULL || hasCustomDelete == NULL)
return false; return false;
if (Context->getConstantExprOr(hasDestructor, hasCustomDelete) if (context.getConstantExprOr(hasDestructor, hasCustomDelete)
!= ConstantInt::getFalse()) != context.getConstantIntFalse())
return false; return false;
Ty = MD_GetElement(node, CD_BodyType)->getType(); Ty = MD_GetElement(node, CD_BodyType)->getType();
@ -233,7 +232,7 @@ namespace {
// The default promote() should be fine. // The default promote() should be fine.
AllocClassFI(LLVMContext* context) : FunctionInfo(context, ~0u, true) {} AllocClassFI() : FunctionInfo(~0u, true) {}
}; };
} }
@ -259,6 +258,7 @@ namespace {
GarbageCollect2Stack(); GarbageCollect2Stack();
bool doInitialization(Module &M) { bool doInitialization(Module &M) {
Context = &M.getContext();
this->M = &M; this->M = &M;
return false; return false;
} }
@ -286,10 +286,9 @@ FunctionPass *createGarbageCollect2Stack() {
GarbageCollect2Stack::GarbageCollect2Stack() GarbageCollect2Stack::GarbageCollect2Stack()
: FunctionPass(&ID), : FunctionPass(&ID),
AllocMemoryT(Context, 0, true), AllocMemoryT(0, true),
NewArrayVT(Context, 0, true, false, 1), NewArrayVT(0, true, false, 1),
NewArrayT(Context, 0, true, true, 1), NewArrayT(0, true, true, 1)
AllocClass(Context)
{ {
KnownFunctions["_d_allocmemoryT"] = &AllocMemoryT; KnownFunctions["_d_allocmemoryT"] = &AllocMemoryT;
KnownFunctions["_d_newarrayvT"] = &NewArrayVT; KnownFunctions["_d_newarrayvT"] = &NewArrayVT;
@ -297,7 +296,7 @@ GarbageCollect2Stack::GarbageCollect2Stack()
KnownFunctions["_d_allocclass"] = &AllocClass; KnownFunctions["_d_allocclass"] = &AllocClass;
} }
static void RemoveCall(CallSite CS, const Analysis& A) { static void RemoveCall(LLVMContext& context, CallSite CS, const Analysis& A) {
if (CS.isInvoke()) { if (CS.isInvoke()) {
InvokeInst* Invoke = cast<InvokeInst>(CS.getInstruction()); InvokeInst* Invoke = cast<InvokeInst>(CS.getInstruction());
// If this was an invoke instruction, we need to do some extra // If this was an invoke instruction, we need to do some extra
@ -306,7 +305,7 @@ static void RemoveCall(CallSite CS, const Analysis& A) {
// Create a "conditional" branch that -simplifycfg can clean up, so we // Create a "conditional" branch that -simplifycfg can clean up, so we
// can keep using the DominatorTree without updating it. // can keep using the DominatorTree without updating it.
BranchInst::Create(Invoke->getNormalDest(), Invoke->getUnwindDest(), BranchInst::Create(Invoke->getNormalDest(), Invoke->getUnwindDest(),
ConstantInt::getTrue(), Invoke->getParent()); context.getConstantIntTrue(), Invoke->getParent());
} }
// Remove the runtime call. // Remove the runtime call.
if (A.CGNode) if (A.CGNode)
@ -361,20 +360,20 @@ bool GarbageCollect2Stack::runOnFunction(Function &F) {
if (Inst->use_empty() && info->SafeToDelete) { if (Inst->use_empty() && info->SafeToDelete) {
Changed = true; Changed = true;
NumDeleted++; NumDeleted++;
RemoveCall(CS, A); RemoveCall(*Context, CS, A);
continue; continue;
} }
DEBUG(DOUT << "GarbageCollect2Stack inspecting: " << *Inst); DEBUG(DOUT << "GarbageCollect2Stack inspecting: " << *Inst);
if (!info->analyze(CS, A) || !isSafeToStackAllocate(Inst, DT)) if (!info->analyze(*Context, CS, A) || !isSafeToStackAllocate(Inst, DT))
continue; continue;
// Let's alloca this! // Let's alloca this!
Changed = true; Changed = true;
IRBuilder<> Builder(BB, Inst); IRBuilder<> Builder(BB, Inst);
Value* newVal = info->promote(CS, Builder, A); Value* newVal = info->promote(*Context, CS, Builder, A);
DEBUG(DOUT << "Promoted to: " << *newVal); DEBUG(DOUT << "Promoted to: " << *newVal);
@ -384,7 +383,7 @@ bool GarbageCollect2Stack::runOnFunction(Function &F) {
newVal = Builder.CreateBitCast(newVal, Inst->getType()); newVal = Builder.CreateBitCast(newVal, Inst->getType());
Inst->replaceAllUsesWith(newVal); Inst->replaceAllUsesWith(newVal);
RemoveCall(CS, A); RemoveCall(*Context, CS, A);
} }
} }

View file

@ -1356,11 +1356,11 @@ DValue* CmpExp::toElem(IRState* p)
break; break;
case TOKleg: case TOKleg:
skip = true; skip = true;
eval = llvm::ConstantInt::getTrue(); eval = gIR->context().getConstantIntTrue();
break; break;
case TOKunord: case TOKunord:
skip = true; skip = true;
eval = llvm::ConstantInt::getFalse(); eval = gIR->context().getConstantIntFalse();
break; break;
default: default:
@ -1844,7 +1844,7 @@ DValue* AndAndExp::toElem(IRState* p)
llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "andandval"); llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "andandval");
// If we jumped over evaluation of the right-hand side, // If we jumped over evaluation of the right-hand side,
// the result is false. Otherwise it's the value of the right-hand side. // the result is false. Otherwise it's the value of the right-hand side.
phi->addIncoming(LLConstantInt::getFalse(), oldblock); phi->addIncoming(gIR->context().getConstantIntFalse(), oldblock);
phi->addIncoming(vbool, newblock); phi->addIncoming(vbool, newblock);
resval = phi; resval = phi;
} }
@ -1891,7 +1891,7 @@ DValue* OrOrExp::toElem(IRState* p)
llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "ororval"); llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "ororval");
// If we jumped over evaluation of the right-hand side, // If we jumped over evaluation of the right-hand side,
// the result is true. Otherwise, it's the value of the right-hand side. // the result is true. Otherwise, it's the value of the right-hand side.
phi->addIncoming(LLConstantInt::getTrue(), oldblock); phi->addIncoming(gIR->context().getConstantIntTrue(), oldblock);
phi->addIncoming(vbool, newblock); phi->addIncoming(vbool, newblock);
resval = phi; resval = phi;
} }