Switch GlobalVariable ctors to a sane API, where *either* a context or a module is required.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75025 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2009-07-08 19:03:57 +00:00
parent 515cdbe49d
commit e9b11b4313
21 changed files with 134 additions and 164 deletions

View File

@ -128,13 +128,12 @@ void BrainF::header(LLVMContext& C) {
get("Error: The head has left the tape.", true); get("Error: The head has left the tape.", true);
GlobalVariable *aberrormsg = new GlobalVariable( GlobalVariable *aberrormsg = new GlobalVariable(
module->getContext(), *module,
msg_0->getType(), msg_0->getType(),
true, true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
msg_0, msg_0,
"aberrormsg", "aberrormsg");
module);
//declare i32 @puts(i8 *) //declare i32 @puts(i8 *)
Function *puts_func = cast<Function>(module-> Function *puts_func = cast<Function>(module->

View File

@ -26,9 +26,9 @@
namespace llvm { namespace llvm {
class LLVMContext;
class Module; class Module;
class Constant; class Constant;
class LLVMContext;
template<typename ValueSubClass, typename ItemParentClass> template<typename ValueSubClass, typename ItemParentClass>
class SymbolTableListTraits; class SymbolTableListTraits;
@ -50,17 +50,16 @@ public:
} }
/// GlobalVariable ctor - If a parent module is specified, the global is /// GlobalVariable ctor - If a parent module is specified, the global is
/// automatically inserted into the end of the specified modules global list. /// automatically inserted into the end of the specified modules global list.
GlobalVariable(LLVMContext &Context, const Type *Ty, GlobalVariable(LLVMContext &Context, const Type *Ty, bool isConstant,
bool isConstant, LinkageTypes Linkage, LinkageTypes Linkage,
Constant *Initializer = 0, const std::string &Name = "", Constant *Initializer = 0, const std::string &Name = "",
Module *Parent = 0, bool ThreadLocal = false, bool ThreadLocal = false, unsigned AddressSpace = 0);
unsigned AddressSpace = 0);
/// GlobalVariable ctor - This creates a global and inserts it before the /// GlobalVariable ctor - This creates a global and inserts it before the
/// specified other global. /// specified other global.
GlobalVariable(LLVMContext &Context, const Type *Ty, GlobalVariable(Module &M, const Type *Ty, bool isConstant,
bool isConstant, LinkageTypes Linkage, LinkageTypes Linkage, Constant *Initializer,
Constant *Initializer, const std::string &Name, const std::string &Name,
GlobalVariable *InsertBefore, bool ThreadLocal = false, GlobalVariable *InsertBefore = 0, bool ThreadLocal = false,
unsigned AddressSpace = 0); unsigned AddressSpace = 0);
~GlobalVariable() { ~GlobalVariable() {

View File

@ -20,7 +20,6 @@
#include "llvm/GlobalAlias.h" #include "llvm/GlobalAlias.h"
#include "llvm/GlobalVariable.h" #include "llvm/GlobalVariable.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/LLVMContext.h"
#include "llvm/Support/ConstantFolder.h" #include "llvm/Support/ConstantFolder.h"
namespace llvm { namespace llvm {
@ -43,16 +42,12 @@ template <bool preserveNames=true, typename T = ConstantFolder> class IRBuilder{
BasicBlock *BB; BasicBlock *BB;
BasicBlock::iterator InsertPt; BasicBlock::iterator InsertPt;
T Folder; T Folder;
LLVMContext& Context;
public: public:
IRBuilder(const T& F = T(), LLVMContext &C = getGlobalContext()) : IRBuilder(const T& F = T()) : Folder(F) { ClearInsertionPoint(); }
Folder(F), Context(C) { ClearInsertionPoint(); } explicit IRBuilder(BasicBlock *TheBB, const T& F = T())
explicit IRBuilder(BasicBlock *TheBB, const T& F = T(), : Folder(F) { SetInsertPoint(TheBB); }
LLVMContext &C = getGlobalContext()) : IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T())
Folder(F), Context(C) { SetInsertPoint(TheBB); } : Folder(F) { SetInsertPoint(TheBB, IP); }
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T(),
LLVMContext &C = getGlobalContext())
: Folder(F), Context(C) { SetInsertPoint(TheBB, IP); }
/// getFolder - Get the constant folder being used. /// getFolder - Get the constant folder being used.
const T& getFolder() { return Folder; } const T& getFolder() { return Folder; }
@ -130,7 +125,7 @@ public:
/// ///
ReturnInst *CreateAggregateRet(Value * const* retVals, unsigned N) { ReturnInst *CreateAggregateRet(Value * const* retVals, unsigned N) {
const Type *RetType = BB->getParent()->getReturnType(); const Type *RetType = BB->getParent()->getReturnType();
Value *V = Context.getUndef(RetType); Value *V = UndefValue::get(RetType);
for (unsigned i = 0; i != N; ++i) for (unsigned i = 0; i != N; ++i)
V = CreateInsertValue(V, retVals[i], i, "mrv"); V = CreateInsertValue(V, retVals[i], i, "mrv");
return Insert(ReturnInst::Create(V)); return Insert(ReturnInst::Create(V));
@ -354,7 +349,7 @@ public:
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name); return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
} }
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") { Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
Value *Idx = Context.getConstantInt(Type::Int32Ty, Idx0); Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
if (Constant *PC = dyn_cast<Constant>(Ptr)) if (Constant *PC = dyn_cast<Constant>(Ptr))
return Folder.CreateGetElementPtr(PC, &Idx, 1); return Folder.CreateGetElementPtr(PC, &Idx, 1);
@ -364,8 +359,8 @@ public:
Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1, Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
const char *Name = "") { const char *Name = "") {
Value *Idxs[] = { Value *Idxs[] = {
Context.getConstantInt(Type::Int32Ty, Idx0), ConstantInt::get(Type::Int32Ty, Idx0),
Context.getConstantInt(Type::Int32Ty, Idx1) ConstantInt::get(Type::Int32Ty, Idx1)
}; };
if (Constant *PC = dyn_cast<Constant>(Ptr)) if (Constant *PC = dyn_cast<Constant>(Ptr))
@ -374,7 +369,7 @@ public:
return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name); return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
} }
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") { Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
Value *Idx = Context.getConstantInt(Type::Int64Ty, Idx0); Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
if (Constant *PC = dyn_cast<Constant>(Ptr)) if (Constant *PC = dyn_cast<Constant>(Ptr))
return Folder.CreateGetElementPtr(PC, &Idx, 1); return Folder.CreateGetElementPtr(PC, &Idx, 1);
@ -384,8 +379,8 @@ public:
Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
const char *Name = "") { const char *Name = "") {
Value *Idxs[] = { Value *Idxs[] = {
Context.getConstantInt(Type::Int64Ty, Idx0), ConstantInt::get(Type::Int64Ty, Idx0),
Context.getConstantInt(Type::Int64Ty, Idx1) ConstantInt::get(Type::Int64Ty, Idx1)
}; };
if (Constant *PC = dyn_cast<Constant>(Ptr)) if (Constant *PC = dyn_cast<Constant>(Ptr))
@ -397,21 +392,21 @@ public:
return CreateConstGEP2_32(Ptr, 0, Idx, Name); return CreateConstGEP2_32(Ptr, 0, Idx, Name);
} }
Value *CreateGlobalString(const char *Str = "", const char *Name = "") { Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
Constant *StrConstant = Context.getConstantArray(Str, true); Constant *StrConstant = ConstantArray::get(Str, true);
GlobalVariable *gv = new GlobalVariable(Context, GlobalVariable *gv = new GlobalVariable(*BB->getParent()->getParent(),
StrConstant->getType(), StrConstant->getType(),
true, true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
StrConstant, StrConstant,
"", "",
BB->getParent()->getParent(), 0,
false); false);
gv->setName(Name); gv->setName(Name);
return gv; return gv;
} }
Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") { Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
Value *gv = CreateGlobalString(Str, Name); Value *gv = CreateGlobalString(Str, Name);
Value *zero = Context.getConstantInt(Type::Int32Ty, 0); Value *zero = ConstantInt::get(Type::Int32Ty, 0);
Value *Args[] = { zero, zero }; Value *Args[] = { zero, zero };
return CreateGEP(gv, Args, Args+2, Name); return CreateGEP(gv, Args, Args+2, Name);
} }
@ -688,13 +683,13 @@ public:
/// CreateIsNull - Return an i1 value testing if \arg Arg is null. /// CreateIsNull - Return an i1 value testing if \arg Arg is null.
Value *CreateIsNull(Value *Arg, const char *Name = "") { Value *CreateIsNull(Value *Arg, const char *Name = "") {
return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()), return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
Name); Name);
} }
/// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null. /// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
Value *CreateIsNotNull(Value *Arg, const char *Name = "") { Value *CreateIsNotNull(Value *Arg, const char *Name = "") {
return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()), return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
Name); Name);
} }
@ -709,7 +704,7 @@ public:
Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty); Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty);
Value *Difference = CreateSub(LHS_int, RHS_int); Value *Difference = CreateSub(LHS_int, RHS_int);
return CreateSDiv(Difference, return CreateSDiv(Difference,
Context.getConstantExprSizeOf(ArgType->getElementType()), ConstantExpr::getSizeOf(ArgType->getElementType()),
Name); Name);
} }
}; };

View File

@ -490,9 +490,9 @@ Constant *DIFactory::GetStringConstant(const std::string &String) {
Constant *ConstStr = VMContext.getConstantArray(String); Constant *ConstStr = VMContext.getConstantArray(String);
// Otherwise create and return a new string global. // Otherwise create and return a new string global.
GlobalVariable *StrGV = new GlobalVariable(VMContext,ConstStr->getType(), true, GlobalVariable *StrGV = new GlobalVariable(M, ConstStr->getType(), true,
GlobalVariable::InternalLinkage, GlobalVariable::InternalLinkage,
ConstStr, ".str", &M); ConstStr, ".str");
StrGV->setSection("llvm.metadata"); StrGV->setSection("llvm.metadata");
return Slot = VMContext.getConstantExprBitCast(StrGV, DestTy); return Slot = VMContext.getConstantExprBitCast(StrGV, DestTy);
} }
@ -516,9 +516,9 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
DIDescriptor &Entry = SimpleConstantCache[Init]; DIDescriptor &Entry = SimpleConstantCache[Init];
if (!Entry.isNull()) return DIArray(Entry.getGV()); if (!Entry.isNull()) return DIArray(Entry.getGV());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.array", &M); Init, "llvm.dbg.array");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
Entry = DIDescriptor(GV); Entry = DIDescriptor(GV);
return DIArray(GV); return DIArray(GV);
@ -542,9 +542,9 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
M.addTypeName("llvm.dbg.subrange.type", Init->getType()); M.addTypeName("llvm.dbg.subrange.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.subrange", &M); Init, "llvm.dbg.subrange");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
Entry = DIDescriptor(GV); Entry = DIDescriptor(GV);
return DISubrange(GV); return DISubrange(GV);
@ -579,9 +579,9 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::LinkOnceAnyLinkage, GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.compile_unit", &M); Init, "llvm.dbg.compile_unit");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DICompileUnit(GV); return DICompileUnit(GV);
} }
@ -598,9 +598,9 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.enumerator", &M); Init, "llvm.dbg.enumerator");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DIEnumerator(GV); return DIEnumerator(GV);
} }
@ -632,9 +632,9 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.basictype.type", Init->getType()); M.addTypeName("llvm.dbg.basictype.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.basictype", &M); Init, "llvm.dbg.basictype");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DIBasicType(GV); return DIBasicType(GV);
} }
@ -668,9 +668,9 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.derivedtype", &M); Init, "llvm.dbg.derivedtype");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DIDerivedType(GV); return DIDerivedType(GV);
} }
@ -708,9 +708,9 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.composite.type", Init->getType()); M.addTypeName("llvm.dbg.composite.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.composite", &M); Init, "llvm.dbg.composite");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DICompositeType(GV); return DICompositeType(GV);
} }
@ -746,9 +746,9 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::LinkOnceAnyLinkage, GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.subprogram", &M); Init, "llvm.dbg.subprogram");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DISubprogram(GV); return DISubprogram(GV);
} }
@ -780,9 +780,9 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::LinkOnceAnyLinkage, GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.global_variable", &M); Init, "llvm.dbg.global_variable");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DIGlobalVariable(GV); return DIGlobalVariable(GV);
} }
@ -806,9 +806,9 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.variable.type", Init->getType()); M.addTypeName("llvm.dbg.variable.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.variable", &M); Init, "llvm.dbg.variable");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DIVariable(GV); return DIVariable(GV);
} }
@ -826,9 +826,9 @@ DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
sizeof(Elts)/sizeof(Elts[0])); sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.block.type", Init->getType()); M.addTypeName("llvm.dbg.block.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true, GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Init, "llvm.dbg.block", &M); Init, "llvm.dbg.block");
GV->setSection("llvm.metadata"); GV->setSection("llvm.metadata");
return DIBlock(GV); return DIBlock(GV);
} }

View File

@ -516,9 +516,8 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
} }
if (GV == 0) { if (GV == 0) {
GV = new GlobalVariable(Context, Ty, false, GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, 0,
GlobalValue::ExternalLinkage, 0, Name, Name, 0, false, AddrSpace);
M, false, AddrSpace);
} else { } else {
if (GV->getType()->getElementType() != Ty) if (GV->getType()->getElementType() != Ty)
return Error(TyLoc, return Error(TyLoc,
@ -608,8 +607,8 @@ GlobalValue *LLParser::GetGlobalVal(const std::string &Name, const Type *Ty,
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M); FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
} else { } else {
FwdVal = new GlobalVariable(Context, PTy->getElementType(), false, FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
GlobalValue::ExternalWeakLinkage, 0, Name, M); GlobalValue::ExternalWeakLinkage, 0, Name);
} }
ForwardRefVals[Name] = std::make_pair(FwdVal, Loc); ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
@ -652,8 +651,8 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc) {
} }
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M); FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
} else { } else {
FwdVal = new GlobalVariable(Context, PTy->getElementType(), false, FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
GlobalValue::ExternalWeakLinkage, 0, "", M); GlobalValue::ExternalWeakLinkage, 0, "");
} }
ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc); ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);

View File

@ -1254,7 +1254,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
isThreadLocal = Record[7]; isThreadLocal = Record[7];
GlobalVariable *NewGV = GlobalVariable *NewGV =
new GlobalVariable(Context, Ty, isConstant, Linkage, 0, "", TheModule, new GlobalVariable(*TheModule, Ty, isConstant, Linkage, 0, "", 0,
isThreadLocal, AddressSpace); isThreadLocal, AddressSpace);
NewGV->setAlignment(Alignment); NewGV->setAlignment(Alignment);
if (!Section.empty()) if (!Section.empty())

View File

@ -229,10 +229,9 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
// to be a ModulePass (which means it cannot be in the 'llc' pipeline // to be a ModulePass (which means it cannot be in the 'llc' pipeline
// (which uses a FunctionPassManager (which segfaults (not asserts) if // (which uses a FunctionPassManager (which segfaults (not asserts) if
// provided a ModulePass))). // provided a ModulePass))).
Constant *GV = new GlobalVariable(*F.getContext(), FrameMap->getType(), true, Constant *GV = new GlobalVariable(*F.getParent(), FrameMap->getType(), true,
GlobalVariable::InternalLinkage, GlobalVariable::InternalLinkage,
FrameMap, "__gc_" + F.getName(), FrameMap, "__gc_" + F.getName());
F.getParent());
Constant *GEPIndices[2] = { ConstantInt::get(Type::Int32Ty, 0), Constant *GEPIndices[2] = { ConstantInt::get(Type::Int32Ty, 0),
ConstantInt::get(Type::Int32Ty, 0) }; ConstantInt::get(Type::Int32Ty, 0) };
@ -292,10 +291,10 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) {
if (!Head) { if (!Head) {
// If the root chain does not exist, insert a new one with linkonce // If the root chain does not exist, insert a new one with linkonce
// linkage! // linkage!
Head = new GlobalVariable(M.getContext(), StackEntryPtrTy, false, Head = new GlobalVariable(M, StackEntryPtrTy, false,
GlobalValue::LinkOnceAnyLinkage, GlobalValue::LinkOnceAnyLinkage,
Constant::getNullValue(StackEntryPtrTy), Constant::getNullValue(StackEntryPtrTy),
"llvm_gc_root_chain", &M); "llvm_gc_root_chain");
} else if (Head->hasExternalLinkage() && Head->isDeclaration()) { } else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
Head->setInitializer(Constant::getNullValue(StackEntryPtrTy)); Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
Head->setLinkage(GlobalValue::LinkOnceAnyLinkage); Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);

View File

@ -573,9 +573,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// symbol over in the dest module... the initializer will be filled in // symbol over in the dest module... the initializer will be filled in
// later by LinkGlobalInits. // later by LinkGlobalInits.
GlobalVariable *NewDGV = GlobalVariable *NewDGV =
new GlobalVariable(Context, SGV->getType()->getElementType(), new GlobalVariable(*Dest, SGV->getType()->getElementType(),
SGV->isConstant(), SGV->getLinkage(), /*init*/0, SGV->isConstant(), SGV->getLinkage(), /*init*/0,
SGV->getName(), Dest, false, SGV->getName(), 0, false,
SGV->getType()->getAddressSpace()); SGV->getType()->getAddressSpace());
// Propagate alignment, visibility and section info. // Propagate alignment, visibility and section info.
CopyGVAttributes(NewDGV, SGV); CopyGVAttributes(NewDGV, SGV);
@ -606,9 +606,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// AppendingVars map. The name is cleared out so that no linkage is // AppendingVars map. The name is cleared out so that no linkage is
// performed. // performed.
GlobalVariable *NewDGV = GlobalVariable *NewDGV =
new GlobalVariable(Context, SGV->getType()->getElementType(), new GlobalVariable(*Dest, SGV->getType()->getElementType(),
SGV->isConstant(), SGV->getLinkage(), /*init*/0, SGV->isConstant(), SGV->getLinkage(), /*init*/0,
"", Dest, false, "", 0, false,
SGV->getType()->getAddressSpace()); SGV->getType()->getAddressSpace());
// Set alignment allowing CopyGVAttributes merge it with alignment of SGV. // Set alignment allowing CopyGVAttributes merge it with alignment of SGV.
@ -634,9 +634,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// we are replacing may be a function (if a prototype, weak, etc) or a // we are replacing may be a function (if a prototype, weak, etc) or a
// global variable. // global variable.
GlobalVariable *NewDGV = GlobalVariable *NewDGV =
new GlobalVariable(Context, SGV->getType()->getElementType(), new GlobalVariable(*Dest, SGV->getType()->getElementType(),
SGV->isConstant(), NewLinkage, /*init*/0, SGV->isConstant(), NewLinkage, /*init*/0,
DGV->getName(), Dest, false, DGV->getName(), 0, false,
SGV->getType()->getAddressSpace()); SGV->getType()->getAddressSpace());
// Propagate alignment, section, and visibility info. // Propagate alignment, section, and visibility info.
@ -1157,8 +1157,8 @@ static bool LinkAppendingVars(Module *M,
// Create the new global variable... // Create the new global variable...
GlobalVariable *NG = GlobalVariable *NG =
new GlobalVariable(Context, NewType, G1->isConstant(), G1->getLinkage(), new GlobalVariable(*M, NewType, G1->isConstant(), G1->getLinkage(),
/*init*/0, First->first, M, G1->isThreadLocal(), /*init*/0, First->first, 0, G1->isThreadLocal(),
G1->getType()->getAddressSpace()); G1->getType()->getAddressSpace());
// Propagate alignment, visibility and section info. // Propagate alignment, visibility and section info.

View File

@ -108,9 +108,9 @@ namespace {
} }
ArrayType *AT = Context->getArrayType(SBP, AUGs.size()); ArrayType *AT = Context->getArrayType(SBP, AUGs.size());
Constant *Init = Context->getConstantArray(AT, AUGs); Constant *Init = Context->getConstantArray(AT, AUGs);
GlobalValue *gv = new GlobalVariable(M.getContext(), AT, false, GlobalValue *gv = new GlobalVariable(M, AT, false,
GlobalValue::AppendingLinkage, GlobalValue::AppendingLinkage,
Init, "llvm.used", &M); Init, "llvm.used");
gv->setSection("llvm.metadata"); gv->setSection("llvm.metadata");
} }

View File

@ -490,11 +490,10 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
Context->getConstantInt(Type::Int32Ty, i), Context->getConstantInt(Type::Int32Ty, i),
Context); Context);
assert(In && "Couldn't get element of initializer?"); assert(In && "Couldn't get element of initializer?");
GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(i), GlobalVariable *NGV = new GlobalVariable(*Context,
false, STy->getElementType(i), false,
GlobalVariable::InternalLinkage, GlobalVariable::InternalLinkage,
In, GV->getName()+"."+utostr(i), In, GV->getName()+"."+utostr(i),
(Module *)NULL,
GV->isThreadLocal(), GV->isThreadLocal(),
GV->getType()->getAddressSpace()); GV->getType()->getAddressSpace());
Globals.insert(GV, NGV); Globals.insert(GV, NGV);
@ -527,13 +526,12 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
Context); Context);
assert(In && "Couldn't get element of initializer?"); assert(In && "Couldn't get element of initializer?");
GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(), GlobalVariable *NGV = new GlobalVariable(*Context,
false, STy->getElementType(), false,
GlobalVariable::InternalLinkage, GlobalVariable::InternalLinkage,
In, GV->getName()+"."+utostr(i), In, GV->getName()+"."+utostr(i),
(Module *)NULL,
GV->isThreadLocal(), GV->isThreadLocal(),
GV->getType()->getAddressSpace()); GV->getType()->getAddressSpace());
Globals.insert(GV, NGV); Globals.insert(GV, NGV);
NewGlobals.push_back(NGV); NewGlobals.push_back(NGV);
@ -842,18 +840,17 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
// Create the new global variable. The contents of the malloc'd memory is // Create the new global variable. The contents of the malloc'd memory is
// undefined, so initialize with an undef value. // undefined, so initialize with an undef value.
Constant *Init = Context->getUndef(MI->getAllocatedType());
GlobalVariable *NewGV = new GlobalVariable(*Context, MI->getAllocatedType(),
false,
GlobalValue::InternalLinkage, Init,
GV->getName()+".body",
(Module *)NULL,
GV->isThreadLocal());
// FIXME: This new global should have the alignment returned by malloc. Code // FIXME: This new global should have the alignment returned by malloc. Code
// could depend on malloc returning large alignment (on the mac, 16 bytes) but // could depend on malloc returning large alignment (on the mac, 16 bytes) but
// this would only guarantee some lower alignment. // this would only guarantee some lower alignment.
GV->getParent()->getGlobalList().insert(GV, NewGV); Constant *Init = Context->getUndef(MI->getAllocatedType());
GlobalVariable *NewGV = new GlobalVariable(*GV->getParent(),
MI->getAllocatedType(), false,
GlobalValue::InternalLinkage, Init,
GV->getName()+".body",
GV,
GV->isThreadLocal());
// Anything that used the malloc now uses the global directly. // Anything that used the malloc now uses the global directly.
MI->replaceAllUsesWith(NewGV); MI->replaceAllUsesWith(NewGV);
@ -868,7 +865,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
new GlobalVariable(*Context, Type::Int1Ty, false, new GlobalVariable(*Context, Type::Int1Ty, false,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Context->getConstantIntFalse(), GV->getName()+".init", Context->getConstantIntFalse(), GV->getName()+".init",
(Module *)NULL, GV->isThreadLocal()); GV->isThreadLocal());
bool InitBoolUsed = false; bool InitBoolUsed = false;
// Loop over all uses of GV, processing them in turn. // Loop over all uses of GV, processing them in turn.
@ -1286,8 +1283,8 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
const Type *PFieldTy = Context->getPointerTypeUnqual(FieldTy); const Type *PFieldTy = Context->getPointerTypeUnqual(FieldTy);
GlobalVariable *NGV = GlobalVariable *NGV =
new GlobalVariable(*Context, PFieldTy, false, new GlobalVariable(*GV->getParent(),
GlobalValue::InternalLinkage, PFieldTy, false, GlobalValue::InternalLinkage,
Context->getNullValue(PFieldTy), Context->getNullValue(PFieldTy),
GV->getName() + ".f" + utostr(FieldNo), GV, GV->getName() + ".f" + utostr(FieldNo), GV,
GV->isThreadLocal()); GV->isThreadLocal());
@ -1587,7 +1584,6 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal,
GlobalVariable *NewGV = new GlobalVariable(*Context, Type::Int1Ty, false, GlobalVariable *NewGV = new GlobalVariable(*Context, Type::Int1Ty, false,
GlobalValue::InternalLinkage, Context->getConstantIntFalse(), GlobalValue::InternalLinkage, Context->getConstantIntFalse(),
GV->getName()+".b", GV->getName()+".b",
(Module *)NULL,
GV->isThreadLocal()); GV->isThreadLocal());
GV->getParent()->getGlobalList().insert(GV, NewGV); GV->getParent()->getGlobalList().insert(GV, NewGV);
@ -1982,7 +1978,6 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
GlobalVariable *NGV = new GlobalVariable(*Context, CA->getType(), GlobalVariable *NGV = new GlobalVariable(*Context, CA->getType(),
GCL->isConstant(), GCL->isConstant(),
GCL->getLinkage(), CA, "", GCL->getLinkage(), CA, "",
(Module *)NULL,
GCL->isThreadLocal()); GCL->isThreadLocal());
GCL->getParent()->getGlobalList().insert(GCL, NGV); GCL->getParent()->getGlobalList().insert(GCL, NGV);
NGV->takeName(GCL); NGV->takeName(GCL);

View File

@ -65,8 +65,8 @@ bool FunctionProfiler::runOnModule(Module &M) {
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions); const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions);
GlobalVariable *Counters = GlobalVariable *Counters =
new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage, new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
Context->getNullValue(ATy), "FuncProfCounters", &M); Context->getNullValue(ATy), "FuncProfCounters");
// Instrument all of the functions... // Instrument all of the functions...
unsigned i = 0; unsigned i = 0;
@ -110,8 +110,8 @@ bool BlockProfiler::runOnModule(Module &M) {
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks); const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks);
GlobalVariable *Counters = GlobalVariable *Counters =
new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage, new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
Context->getNullValue(ATy), "BlockProfCounters", &M); Context->getNullValue(ATy), "BlockProfCounters");
// Instrument all of the blocks... // Instrument all of the blocks...
unsigned i = 0; unsigned i = 0;

View File

@ -66,8 +66,8 @@ bool EdgeProfiler::runOnModule(Module &M) {
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges); const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges);
GlobalVariable *Counters = GlobalVariable *Counters =
new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage, new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
Context->getNullValue(ATy), "EdgeProfCounters", &M); Context->getNullValue(ATy), "EdgeProfCounters");
// Instrument all of the edges... // Instrument all of the edges...
unsigned i = 0; unsigned i = 0;

View File

@ -198,9 +198,8 @@ GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t,
uint64_t resetval) : T(t) { uint64_t resetval) : T(t) {
ConstantInt* Init = M.getContext().getConstantInt(T, resetval); ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init; ResetValue = Init;
Counter = new GlobalVariable(M.getContext(), T, false, Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage,
GlobalValue::InternalLinkage, Init, "RandomSteeringCounter");
Init, "RandomSteeringCounter", &M);
} }
GlobalRandomCounter::~GlobalRandomCounter() {} GlobalRandomCounter::~GlobalRandomCounter() {}
@ -238,9 +237,8 @@ GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t,
: AI(0), T(t) { : AI(0), T(t) {
ConstantInt* Init = M.getContext().getConstantInt(T, resetval); ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init; ResetValue = Init;
Counter = new GlobalVariable(M.getContext(), T, false, Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage,
GlobalValue::InternalLinkage, Init, "RandomSteeringCounter");
Init, "RandomSteeringCounter", &M);
} }
GlobalRandomCounterOpt::~GlobalRandomCounterOpt() {} GlobalRandomCounterOpt::~GlobalRandomCounterOpt() {}

View File

@ -1290,9 +1290,8 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization {
// pass to be run after this pass, to merge duplicate strings. // pass to be run after this pass, to merge duplicate strings.
FormatStr.erase(FormatStr.end()-1); FormatStr.erase(FormatStr.end()-1);
Constant *C = Context->getConstantArray(FormatStr, true); Constant *C = Context->getConstantArray(FormatStr, true);
C = new GlobalVariable(*Context, C->getType(), C = new GlobalVariable(*Callee->getParent(), C->getType(), true,
true, GlobalVariable::InternalLinkage, GlobalVariable::InternalLinkage, C, "str");
C, "str", Callee->getParent());
EmitPutS(C, B); EmitPutS(C, B);
return CI->use_empty() ? (Value*)CI : return CI->use_empty() ? (Value*)CI :
Context->getConstantInt(CI->getType(), FormatStr.size()+1); Context->getConstantInt(CI->getType(), FormatStr.size()+1);

View File

@ -56,11 +56,11 @@ Module *llvm::CloneModule(const Module *M,
// //
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) { I != E; ++I) {
GlobalVariable *GV = new GlobalVariable(M->getContext(), GlobalVariable *GV = new GlobalVariable(*New,
I->getType()->getElementType(), I->getType()->getElementType(),
false, false,
GlobalValue::ExternalLinkage, 0, GlobalValue::ExternalLinkage, 0,
I->getName(), New); I->getName());
GV->setAlignment(I->getAlignment()); GV->setAlignment(I->getAlignment());
ValueMap[I] = GV; ValueMap[I] = GV;
} }

View File

@ -139,11 +139,10 @@ bool LowerInvoke::doInitialization(Module &M) {
// Now that we've done that, insert the jmpbuf list head global, unless it // Now that we've done that, insert the jmpbuf list head global, unless it
// already exists. // already exists.
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) { if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
JBListHead = new GlobalVariable(M.getContext(), JBListHead = new GlobalVariable(M, PtrJBList, false,
PtrJBList, false,
GlobalValue::LinkOnceAnyLinkage, GlobalValue::LinkOnceAnyLinkage,
Context->getNullValue(PtrJBList), Context->getNullValue(PtrJBList),
"llvm.sjljeh.jblist", &M); "llvm.sjljeh.jblist");
} }
// VisualStudio defines setjmp as _setjmp via #include <csetjmp> / <setjmp.h>, // VisualStudio defines setjmp as _setjmp via #include <csetjmp> / <setjmp.h>,
@ -183,10 +182,9 @@ void LowerInvoke::createAbortMessage(Module *M) {
Context->getConstantArray("ERROR: Exception thrown, but not caught!\n"); Context->getConstantArray("ERROR: Exception thrown, but not caught!\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0 AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
GlobalVariable *MsgGV = new GlobalVariable(M->getContext(), GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
Msg->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Msg, "abortmsg", M); Msg, "abortmsg");
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty)); std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
AbortMessage = Context->getConstantExprGetElementPtr(MsgGV, &GEPIdx[0], 2); AbortMessage = Context->getConstantExprGetElementPtr(MsgGV, &GEPIdx[0], 2);
} else { } else {
@ -197,10 +195,9 @@ void LowerInvoke::createAbortMessage(Module *M) {
"Recompile program with -enable-correct-eh-support.\n"); "Recompile program with -enable-correct-eh-support.\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0 AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
GlobalVariable *MsgGV = new GlobalVariable(M->getContext(), GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
Msg->getType(), true,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
Msg, "abortmsg", M); Msg, "abortmsg");
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty)); std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2); AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
} }

View File

@ -700,10 +700,8 @@ void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
/*--.. Operations on global variables ......................................--*/ /*--.. Operations on global variables ......................................--*/
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) { LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
LLVMContext &Context = unwrap(M)->getContext(); return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
return wrap(new GlobalVariable(Context, unwrap(Ty), false, GlobalValue::ExternalLinkage, 0, Name));
GlobalValue::ExternalLinkage, 0, Name,
unwrap(M)));
} }
LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) { LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {

View File

@ -97,8 +97,7 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
bool constant, LinkageTypes Link, bool constant, LinkageTypes Link,
Constant *InitVal, const std::string &Name, Constant *InitVal, const std::string &Name,
Module *ParentModule, bool ThreadLocal, bool ThreadLocal, unsigned AddressSpace)
unsigned AddressSpace)
: GlobalValue(Context.getPointerType(Ty, AddressSpace), : GlobalValue(Context.getPointerType(Ty, AddressSpace),
Value::GlobalVariableVal, Value::GlobalVariableVal,
OperandTraits<GlobalVariable>::op_begin(this), OperandTraits<GlobalVariable>::op_begin(this),
@ -111,18 +110,14 @@ GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
} }
LeakDetector::addGarbageObject(this); LeakDetector::addGarbageObject(this);
if (ParentModule)
ParentModule->getGlobalList().push_back(this);
} }
GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, GlobalVariable::GlobalVariable(Module &M, const Type *Ty, bool constant,
bool constant, LinkageTypes Link, LinkageTypes Link, Constant *InitVal,
Constant *InitVal, const std::string &Name, const std::string &Name,
GlobalVariable *Before, bool ThreadLocal, GlobalVariable *Before, bool ThreadLocal,
unsigned AddressSpace) unsigned AddressSpace)
: GlobalValue(Context.getPointerType(Ty, AddressSpace), : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
Value::GlobalVariableVal,
OperandTraits<GlobalVariable>::op_begin(this), OperandTraits<GlobalVariable>::op_begin(this),
InitVal != 0, Link, Name), InitVal != 0, Link, Name),
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) { isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
@ -136,6 +131,8 @@ GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
if (Before) if (Before)
Before->getParent()->getGlobalList().insert(Before, this); Before->getParent()->getGlobalList().insert(Before, this);
else
M.getGlobalList().push_back(this);
} }
void GlobalVariable::setParent(Module *parent) { void GlobalVariable::setParent(Module *parent) {

View File

@ -28,20 +28,17 @@ using namespace llvm;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Methods to implement the globals and functions lists. // 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 *ilist_traits<GlobalVariable>::createSentinel() {
GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), Type::Int32Ty,
Type::Int32Ty, false, false, GlobalValue::ExternalLinkage);
GlobalValue::ExternalLinkage);
// This should not be garbage monitored. // This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret); LeakDetector::removeGarbageObject(Ret);
return Ret; return Ret;
} }
GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() { GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
GlobalValue::ExternalLinkage); GlobalValue::ExternalLinkage);
// This should not be garbage monitored. // This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret); LeakDetector::removeGarbageObject(Ret);
@ -273,10 +270,9 @@ Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) {
if (GV == 0) { if (GV == 0) {
// Nope, add it // Nope, add it
GlobalVariable *New = GlobalVariable *New =
new GlobalVariable(getContext(), Ty, false, new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
GlobalVariable::ExternalLinkage, 0, Name); 0, Name);
GlobalList.push_back(New); return New; // Return the new declaration.
return New; // Return the new declaration.
} }
// If the variable exists but has the wrong type, return a bitcast to the // If the variable exists but has the wrong type, return a bitcast to the

View File

@ -236,9 +236,9 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
GV->eraseFromParent(); GV->eraseFromParent();
if (!M1Tors.empty()) { if (!M1Tors.empty()) {
Constant *M1Init = GetTorInit(M1Tors); Constant *M1Init = GetTorInit(M1Tors);
new GlobalVariable(M1->getContext(), M1Init->getType(), false, new GlobalVariable(*M1, M1Init->getType(), false,
GlobalValue::AppendingLinkage, GlobalValue::AppendingLinkage,
M1Init, GlobalName, M1); M1Init, GlobalName);
} }
GV = M2->getNamedGlobal(GlobalName); GV = M2->getNamedGlobal(GlobalName);
@ -248,9 +248,9 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
GV->eraseFromParent(); GV->eraseFromParent();
if (!M2Tors.empty()) { if (!M2Tors.empty()) {
Constant *M2Init = GetTorInit(M2Tors); Constant *M2Init = GetTorInit(M2Tors);
new GlobalVariable(M2->getContext(), M2Init->getType(), false, new GlobalVariable(*M2, M2Init->getType(), false,
GlobalValue::AppendingLinkage, GlobalValue::AppendingLinkage,
M2Init, GlobalName, M2); M2Init, GlobalName);
} }
} }

View File

@ -703,10 +703,9 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// 1. Add a string constant with its name to the global file // 1. Add a string constant with its name to the global file
Constant *InitArray = ConstantArray::get(F->getName()); Constant *InitArray = ConstantArray::get(F->getName());
GlobalVariable *funcName = GlobalVariable *funcName =
new GlobalVariable(Safe->getContext(), new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/,
InitArray->getType(), true /*isConstant*/,
GlobalValue::InternalLinkage, InitArray, GlobalValue::InternalLinkage, InitArray,
F->getName() + "_name", Safe); F->getName() + "_name");
// 2. Use `GetElementPtr *funcName, 0, 0' to convert the string to an // 2. Use `GetElementPtr *funcName, 0, 0' to convert the string to an
// sbyte* so it matches the signature of the resolver function. // sbyte* so it matches the signature of the resolver function.
@ -723,9 +722,9 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Create a new global to hold the cached function pointer. // Create a new global to hold the cached function pointer.
Constant *NullPtr = ConstantPointerNull::get(F->getType()); Constant *NullPtr = ConstantPointerNull::get(F->getType());
GlobalVariable *Cache = GlobalVariable *Cache =
new GlobalVariable(F->getParent()->getContext(), new GlobalVariable(*F->getParent(), F->getType(),
F->getType(), false,GlobalValue::InternalLinkage, false, GlobalValue::InternalLinkage,
NullPtr,F->getName()+".fpcache", F->getParent()); NullPtr,F->getName()+".fpcache");
// Construct a new stub function that will re-route calls to F // Construct a new stub function that will re-route calls to F
const FunctionType *FuncTy = F->getFunctionType(); const FunctionType *FuncTy = F->getFunctionType();