# HG changeset patch # User Benjamin Kramer # Date 1247508975 -7200 # Node ID 61f12f4651b52b737090c6eff718334790892788 # Parent 8ca25bd765a38f90d91f49ae7f961a3e802afc54 Don't use llvm::getGlobalContext() anymore diff -r 8ca25bd765a3 -r 61f12f4651b5 dmd/module.h --- a/dmd/module.h Mon Jul 13 12:17:58 2009 +0200 +++ b/dmd/module.h Mon Jul 13 20:16:15 2009 +0200 @@ -31,7 +31,10 @@ class Ir; struct DValue; typedef DValue elem; -namespace llvm { class Module; } +namespace llvm { + class LLVMContext; + class Module; +} #else #ifdef IN_GCC @@ -178,7 +181,7 @@ #if IN_LLVM // LDC - llvm::Module* genLLVMModule(Ir* sir); + llvm::Module* genLLVMModule(llvm::LLVMContext& context, Ir* sir); void buildTargetFiles(); File* buildFilePath(const char* forcename, const char* path, const char* ext); Module *isModule() { return this; } diff -r 8ca25bd765a3 -r 61f12f4651b5 dmd2/module.h --- a/dmd2/module.h Mon Jul 13 12:17:58 2009 +0200 +++ b/dmd2/module.h Mon Jul 13 20:16:15 2009 +0200 @@ -31,7 +31,10 @@ class Ir; struct DValue; typedef DValue elem; -namespace llvm { class Module; } +namespace llvm { + class LLVMContext; + class Module; +} #else #ifdef IN_GCC @@ -185,7 +188,7 @@ #if IN_LLVM // LDC - llvm::Module* genLLVMModule(Ir* sir); + llvm::Module* genLLVMModule(llvm::LLVMContext& context, Ir* sir); void buildTargetFiles(); File* buildFilePath(const char* forcename, const char* path, const char* ext); Module *isModule() { return this; } diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/aa.cpp --- a/gen/aa.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/aa.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -105,7 +105,7 @@ llvm::BasicBlock* failbb = llvm::BasicBlock::Create("aaboundscheckfail", gIR->topfunc(), oldend); llvm::BasicBlock* okbb = llvm::BasicBlock::Create("aaboundsok", gIR->topfunc(), oldend); - LLValue* nullaa = llvm::getGlobalContext().getNullValue(ret->getType()); + LLValue* nullaa = gIR->context().getNullValue(ret->getType()); LLValue* cond = gIR->ir->CreateICmpNE(nullaa, ret, "aaboundscheck"); gIR->ir->CreateCondBr(cond, okbb, failbb); diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/arrays.cpp --- a/gen/arrays.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/arrays.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -60,7 +60,7 @@ assert(isaPointer(v)); const LLType* t = v->getType()->getContainedType(0); - DtoStore(llvm::getGlobalContext().getNullValue(t), v); + DtoStore(gIR->context().getNullValue(t), v); } ////////////////////////////////////////////////////////////////////////////////////////// diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/classes.cpp --- a/gen/classes.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/classes.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -211,7 +211,7 @@ // monitor always defaults to zero tmp = DtoGEPi(dst,0,1,"monitor"); - val = llvm::getGlobalContext().getNullValue(tmp->getType()->getContainedType(0)); + val = gIR->context().getNullValue(tmp->getType()->getContainedType(0)); DtoStore(val, tmp); // done? @@ -262,7 +262,7 @@ else if (to->ty == Tbool) { IF_LOG Logger::println("to bool"); LLValue* llval = val->getRVal(); - LLValue* zero = llvm::getGlobalContext().getNullValue(llval->getType()); + LLValue* zero = gIR->context().getNullValue(llval->getType()); return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero, "tmp")); } // class -> integer @@ -326,8 +326,8 @@ // Sure we could have jumped over the code above in this case, but // it's just a GEP and (maybe) a pointer-to-pointer BitCast, so it // should be pretty cheap and perfectly safe even if the original was null. - LLValue* isNull = gIR->ir->CreateICmpEQ(orig, llvm::getGlobalContext().getNullValue(orig->getType()), ".nullcheck"); - v = gIR->ir->CreateSelect(isNull, llvm::getGlobalContext().getNullValue(ifType), v, ".interface"); + LLValue* isNull = gIR->ir->CreateICmpEQ(orig, gIR->context().getNullValue(orig->getType()), ".nullcheck"); + v = gIR->ir->CreateSelect(isNull, gIR->context().getNullValue(ifType), v, ".interface"); // return r-value return new DImValue(_to, v); @@ -602,7 +602,7 @@ LLConstant* ptr; if (nvars == 0) - return llvm::getGlobalContext().getNullValue( arrayT ); + return gIR->context().getNullValue( arrayT ); // array type const llvm::ArrayType* arrTy = llvm::ArrayType::get(arrayInits[0]->getType(), nvars); diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/complex.cpp --- a/gen/complex.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/complex.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -111,9 +111,9 @@ DtoGetComplexParts(loc, to, val, re, im); if(!re) - re = llvm::getGlobalContext().getNullValue(DtoType(baserety)); + re = gIR->context().getNullValue(DtoType(baserety)); if(!im) - im = llvm::getGlobalContext().getNullValue(DtoType(baseimty)); + im = gIR->context().getNullValue(DtoType(baseimty)); LLValue* res = DtoAggrPair(complexTy, re, im); diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/functions.cpp --- a/gen/functions.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/functions.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -811,7 +811,7 @@ } } else - llvm::ReturnInst::Create(llvm::getGlobalContext().getNullValue(func->getReturnType()), bb); + llvm::ReturnInst::Create(gIR->context().getNullValue(func->getReturnType()), bb); } // std::cout << *func << std::endl; diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/irstate.cpp --- a/gen/irstate.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/irstate.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -22,7 +22,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// IRScope::IRScope() - : builder(llvm::getGlobalContext()) + : builder(gIR->context()) { begin = end = NULL; } diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/irstate.h --- a/gen/irstate.h Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/irstate.h Mon Jul 13 20:16:15 2009 +0200 @@ -16,6 +16,7 @@ #include "llvm/Support/CallSite.h" namespace llvm { + class LLVMContext; class TargetMachine; } @@ -108,6 +109,9 @@ const LLStructType* mutexType; const LLStructType* moduleRefType; + // helper to get the LLVMContext of the module + llvm::LLVMContext& context() const { return module->getContext(); } + // functions typedef std::vector FunctionVector; FunctionVector functions; diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/llvm.h --- a/gen/llvm.h Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/llvm.h Mon Jul 13 20:16:15 2009 +0200 @@ -11,7 +11,6 @@ #include "llvm/Module.h" #include "llvm/Value.h" #include "llvm/Attributes.h" -#include "llvm/LLVMContext.h" #include "llvm/Target/TargetData.h" diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/llvmhelpers.cpp --- a/gen/llvmhelpers.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/llvmhelpers.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -464,13 +464,13 @@ if (basetype->iscomplex()) { const LLType* basefp = DtoComplexBaseType(basetype); - LLValue* res = DtoAggrPair(DtoType(type), llvm::getGlobalContext().getNullValue(basefp), llvm::getGlobalContext().getNullValue(basefp)); + LLValue* res = DtoAggrPair(DtoType(type), gIR->context().getNullValue(basefp), gIR->context().getNullValue(basefp)); return new DImValue(type, res); } // integer, floating, pointer and class have no special representation else if (basetype->isintegral() || basetype->isfloating() || basety == Tpointer || basety == Tclass) { - return new DConstValue(type, llvm::getGlobalContext().getNullValue(lltype)); + return new DConstValue(type, gIR->context().getNullValue(lltype)); } // dynamic array else if (basety == Tarray) @@ -482,7 +482,7 @@ // delegate else if (basety == Tdelegate) { - return new DNullValue(type, llvm::getGlobalContext().getNullValue(lltype)); + return new DNullValue(type, gIR->context().getNullValue(lltype)); } // unknown @@ -577,7 +577,7 @@ } else if (totype->ty == Tbool) { LLValue* src = val->getRVal(); - LLValue* zero = llvm::getGlobalContext().getNullValue(src->getType()); + LLValue* zero = gIR->context().getNullValue(src->getType()); rval = gIR->ir->CreateICmpNE(src, zero, "tmp"); } else if (totype->isintegral()) { @@ -609,7 +609,7 @@ if (totype->ty == Tbool) { rval = val->getRVal(); - LLValue* zero = llvm::getGlobalContext().getNullValue(rval->getType()); + LLValue* zero = gIR->context().getNullValue(rval->getType()); rval = gIR->ir->CreateFCmpUNE(rval, zero, "tmp"); } else if (totype->iscomplex()) { @@ -1124,7 +1124,7 @@ { Logger::println("const void initializer"); const LLType* ty = DtoType(type); - _init = llvm::getGlobalContext().getNullValue(ty); + _init = gIR->context().getNullValue(ty); } else { Logger::println("unsupported const initializer: %s", init->toChars()); diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/main.cpp --- a/gen/main.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/main.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -7,6 +7,7 @@ #include "gen/llvm-version.h" #include "llvm/LinkAllVMCore.h" #include "llvm/Linker.h" +#include "llvm/LLVMContext.h" #include "llvm/System/Signals.h" #include "llvm/Target/SubtargetFeature.h" #include "llvm/Target/TargetMachine.h" @@ -401,7 +402,8 @@ if (global.errors) fatal(); - llvm::Module mod("dummy", llvm::getGlobalContext()); + llvm::LLVMContext context; + llvm::Module mod("dummy", context); // override triple if needed const char* defaultTriple = DEFAULT_TARGET_TRIPLE; @@ -888,7 +890,7 @@ printf("code %s\n", m->toChars()); if (global.params.obj) { - llvm::Module* lm = m->genLLVMModule(&ir); + llvm::Module* lm = m->genLLVMModule(context, &ir); if (!singleObj) { m->deleteObjFile(); @@ -915,7 +917,7 @@ char* name = m->toChars(); char* filename = m->objfile->name->str; - llvm::Linker linker(name, name, llvm::getGlobalContext()); + llvm::Linker linker(name, name, context); std::string errormsg; for (int i = 0; i < llvmModules.size(); i++) diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/passes/SimplifyDRuntimeCalls.cpp --- a/gen/passes/SimplifyDRuntimeCalls.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/passes/SimplifyDRuntimeCalls.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -355,7 +355,7 @@ } bool SimplifyDRuntimeCalls::runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA) { - IRBuilder<> Builder(llvm::getGlobalContext()); + IRBuilder<> Builder(*Context); bool Changed = false; for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/runtime.cpp --- a/gen/runtime.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/runtime.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -150,7 +150,7 @@ static void LLVM_D_BuildRuntimeModule() { Logger::println("building module"); - M = new llvm::Module("ldc internal runtime", llvm::getGlobalContext()); + M = new llvm::Module("ldc internal runtime", gIR->context()); Logger::println("building basic types"); const LLType* voidTy = LLType::VoidTy; diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/statements.cpp --- a/gen/statements.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/statements.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -114,7 +114,7 @@ // and return 0 instead // if we're not in main, just bitcast if (p->topfunc() == p->mainFunc) - v = llvm::getGlobalContext().getNullValue(p->mainFunc->getReturnType()); + v = gIR->context().getNullValue(p->mainFunc->getReturnType()); else v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp"); @@ -1380,7 +1380,7 @@ static LLConstant* generate_unique_critical_section() { const LLType* Mty = DtoMutexType(); - return new llvm::GlobalVariable(*gIR->module, Mty, false, llvm::GlobalValue::InternalLinkage, llvm::getGlobalContext().getNullValue(Mty), ".uniqueCS"); + return new llvm::GlobalVariable(*gIR->module, Mty, false, llvm::GlobalValue::InternalLinkage, gIR->context().getNullValue(Mty), ".uniqueCS"); } void SynchronizedStatement::toIR(IRState* p) diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/structs.cpp --- a/gen/structs.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/structs.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -162,22 +162,22 @@ { if (is64 && diff % 8 == 0) { - values.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int64Ty)); + values.push_back(gIR->context().getNullValue(llvm::Type::Int64Ty)); diff -= 8; } else if (diff % 4 == 0) { - values.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int32Ty)); + values.push_back(gIR->context().getNullValue(llvm::Type::Int32Ty)); diff -= 4; } else if (diff % 2 == 0) { - values.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int16Ty)); + values.push_back(gIR->context().getNullValue(llvm::Type::Int16Ty)); diff -= 2; } else { - values.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int8Ty)); + values.push_back(gIR->context().getNullValue(llvm::Type::Int8Ty)); diff -= 1; } } diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/todebug.cpp --- a/gen/todebug.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/todebug.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -19,7 +19,7 @@ using namespace llvm::dwarf; -#define DBG_NULL ( llvm::getGlobalContext().getNullValue(DBG_TYPE) ) +#define DBG_NULL ( gIR->context().getNullValue(DBG_TYPE) ) #define DBG_TYPE ( getPtrToType(llvm::StructType::get(NULL,NULL)) ) #define DBG_CAST(X) ( llvm::ConstantExpr::getBitCast(X, DBG_TYPE) ) @@ -297,7 +297,7 @@ std::vector initvals(11); initvals[0] = DBG_TAG(DW_TAG_structure_type); for (int i = 1; i < initvals.size(); ++i) - initvals[i] = llvm::getGlobalContext().getNullValue(getDwarfCompositeTypeType()->getContainedType(i)); + initvals[i] = gIR->context().getNullValue(getDwarfCompositeTypeType()->getContainedType(i)); gv->setInitializer(LLConstantStruct::get(getDwarfCompositeTypeType(), initvals)); ir->diCompositeType = llvm::DICompositeType(gv); diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/toir.cpp --- a/gen/toir.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/toir.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -341,7 +341,7 @@ return llvm::ConstantAggregateZero::get(t); } else { - return llvm::getGlobalContext().getNullValue(t); + return gIR->context().getNullValue(t); } assert(0); return NULL; @@ -1656,7 +1656,7 @@ LLValue* rval = dval->getRVal(); DtoDeleteMemory(rval); if (dval->isVar()) - DtoStore(llvm::getGlobalContext().getNullValue(rval->getType()), dval->getLVal()); + DtoStore(gIR->context().getNullValue(rval->getType()), dval->getLVal()); } // class else if (et->ty == Tclass) @@ -1680,7 +1680,7 @@ } if (dval->isVar()) { LLValue* lval = dval->getLVal(); - DtoStore(llvm::getGlobalContext().getNullValue(lval->getType()->getContainedType(0)), lval); + DtoStore(gIR->context().getNullValue(lval->getType()->getContainedType(0)), lval); } } // dyn array @@ -2547,7 +2547,7 @@ // it should be possible to avoid the temporary in some cases LLValue* tmp = DtoAlloca(type,"aaliteral"); DValue* aa = new DVarValue(type, tmp); - DtoStore(llvm::getGlobalContext().getNullValue(DtoType(type)), tmp); + DtoStore(gIR->context().getNullValue(DtoType(type)), tmp); const size_t n = keys->dim; for (size_t i=0; igetType()); + rhs = gIR->context().getNullValue(lhs->getType()); } LLValue* l = gIR->ir->CreateExtractValue(lhs, 0); @@ -741,7 +741,7 @@ LLConstant* getNullValue(const LLType* t) { - return llvm::getGlobalContext().getNullValue(t); + return gIR->context().getNullValue(t); } ////////////////////////////////////////////////////////////////////////////////////////// diff -r 8ca25bd765a3 -r 61f12f4651b5 gen/toobj.cpp --- a/gen/toobj.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/gen/toobj.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -71,7 +71,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Module* Module::genLLVMModule(Ir* sir) +llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir) { bool logenabled = Logger::enabled(); if (llvmForceLogging && !logenabled) @@ -94,7 +94,7 @@ // create a new ir state // TODO look at making the instance static and moving most functionality into IrModule where it belongs - IRState ir(new llvm::Module(mname, llvm::getGlobalContext())); + IRState ir(new llvm::Module(mname, context)); gIR = &ir; ir.dmodule = this; @@ -554,7 +554,7 @@ // provide the default initializer const LLStructType* modulerefTy = DtoModuleReferenceType(); std::vector mrefvalues; - mrefvalues.push_back(llvm::getGlobalContext().getNullValue(modulerefTy->getContainedType(0))); + mrefvalues.push_back(gIR->context().getNullValue(modulerefTy->getContainedType(0))); mrefvalues.push_back(llvm::ConstantExpr::getBitCast(moduleinfo, modulerefTy->getContainedType(1))); LLConstant* thismrefinit = LLConstantStruct::get(modulerefTy, mrefvalues); diff -r 8ca25bd765a3 -r 61f12f4651b5 ir/irstruct.cpp --- a/ir/irstruct.cpp Mon Jul 13 12:17:58 2009 +0200 +++ b/ir/irstruct.cpp Mon Jul 13 20:16:15 2009 +0200 @@ -117,22 +117,22 @@ { if (global.params.is64bit && diff % 8 == 0) { - constants.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int64Ty)); + constants.push_back(gIR->context().getNullValue(llvm::Type::Int64Ty)); diff -= 8; } else if (diff % 4 == 0) { - constants.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int32Ty)); + constants.push_back(gIR->context().getNullValue(llvm::Type::Int32Ty)); diff -= 4; } else if (diff % 2 == 0) { - constants.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int16Ty)); + constants.push_back(gIR->context().getNullValue(llvm::Type::Int16Ty)); diff -= 2; } else { - constants.push_back(llvm::getGlobalContext().getNullValue(llvm::Type::Int8Ty)); + constants.push_back(gIR->context().getNullValue(llvm::Type::Int8Ty)); diff -= 1; } }