diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Core.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Globals.cpp | 17 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 16 |
3 files changed, 15 insertions, 24 deletions
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 1ac66ed660..54773c3ee7 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -700,10 +700,8 @@ void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) { /*--.. Operations on global variables ......................................--*/ LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) { - LLVMContext &Context = unwrap(M)->getContext(); - return wrap(new GlobalVariable(Context, unwrap(Ty), false, - GlobalValue::ExternalLinkage, 0, Name, - unwrap(M))); + return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false, + GlobalValue::ExternalLinkage, 0, Name)); } LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) { diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index f8c1071052..b3087f7cc4 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -97,8 +97,7 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) { GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, bool constant, LinkageTypes Link, Constant *InitVal, const std::string &Name, - Module *ParentModule, bool ThreadLocal, - unsigned AddressSpace) + bool ThreadLocal, unsigned AddressSpace) : GlobalValue(Context.getPointerType(Ty, AddressSpace), Value::GlobalVariableVal, OperandTraits<GlobalVariable>::op_begin(this), @@ -111,18 +110,14 @@ GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, } LeakDetector::addGarbageObject(this); - - if (ParentModule) - ParentModule->getGlobalList().push_back(this); } -GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, - bool constant, LinkageTypes Link, - Constant *InitVal, const std::string &Name, +GlobalVariable::GlobalVariable(Module &M, const Type *Ty, bool constant, + LinkageTypes Link, Constant *InitVal, + const std::string &Name, GlobalVariable *Before, bool ThreadLocal, unsigned AddressSpace) - : GlobalValue(Context.getPointerType(Ty, AddressSpace), - Value::GlobalVariableVal, + : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal, OperandTraits<GlobalVariable>::op_begin(this), InitVal != 0, Link, Name), isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) { @@ -136,6 +131,8 @@ GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, if (Before) Before->getParent()->getGlobalList().insert(Before, this); + else + M.getGlobalList().push_back(this); } void GlobalVariable::setParent(Module *parent) { diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 6f3de0257e..8739848961 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -28,20 +28,17 @@ using namespace llvm; //===----------------------------------------------------------------------===// // Methods to implement the globals and functions lists. -// NOTE: It is ok to allocate the globals used for these methods from the -// global context, because all we ever do is use them to compare for equality. // GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() { - GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), - Type::Int32Ty, false, - GlobalValue::ExternalLinkage); + GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), Type::Int32Ty, + false, GlobalValue::ExternalLinkage); // This should not be garbage monitored. LeakDetector::removeGarbageObject(Ret); return Ret; } GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() { - GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, + GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, GlobalValue::ExternalLinkage); // This should not be garbage monitored. LeakDetector::removeGarbageObject(Ret); @@ -273,10 +270,9 @@ Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) { if (GV == 0) { // Nope, add it GlobalVariable *New = - new GlobalVariable(getContext(), Ty, false, - GlobalVariable::ExternalLinkage, 0, Name); - GlobalList.push_back(New); - return New; // Return the new declaration. + new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage, + 0, Name); + return New; // Return the new declaration. } // If the variable exists but has the wrong type, return a bitcast to the |