get("Error: The head has left the tape.", true);
GlobalVariable *aberrormsg = new GlobalVariable(
+ module->getContext(),
msg_0->getType(),
true,
GlobalValue::InternalLinkage,
namespace llvm {
+class LLVMContext;
class Module;
class Constant;
template<typename ValueSubClass, typename ItemParentClass>
}
/// GlobalVariable ctor - If a parent module is specified, the global is
/// automatically inserted into the end of the specified modules global list.
- GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
+ GlobalVariable(LLVMContext &Context, const Type *Ty,
+ bool isConstant, LinkageTypes Linkage,
Constant *Initializer = 0, const std::string &Name = "",
Module *Parent = 0, bool ThreadLocal = false,
unsigned AddressSpace = 0);
/// GlobalVariable ctor - This creates a global and inserts it before the
/// specified other global.
- GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
+ GlobalVariable(LLVMContext &Context, const Type *Ty,
+ bool isConstant, LinkageTypes Linkage,
Constant *Initializer, const std::string &Name,
GlobalVariable *InsertBefore, bool ThreadLocal = false,
unsigned AddressSpace = 0);
#include "llvm/GlobalAlias.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/ConstantFolder.h"
namespace llvm {
BasicBlock *BB;
BasicBlock::iterator InsertPt;
T Folder;
+ LLVMContext& Context;
public:
- IRBuilder(const T& F = T()) : Folder(F) { ClearInsertionPoint(); }
- explicit IRBuilder(BasicBlock *TheBB, const T& F = T())
- : Folder(F) { SetInsertPoint(TheBB); }
- IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T())
- : Folder(F) { SetInsertPoint(TheBB, IP); }
+ IRBuilder(const T& F = T(), LLVMContext &C = getGlobalContext()) :
+ Folder(F), Context(C) { ClearInsertionPoint(); }
+ explicit IRBuilder(BasicBlock *TheBB, const T& F = T(),
+ LLVMContext &C = getGlobalContext()) :
+ Folder(F), Context(C) { SetInsertPoint(TheBB); }
+ 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.
const T& getFolder() { return Folder; }
///
ReturnInst *CreateAggregateRet(Value * const* retVals, unsigned N) {
const Type *RetType = BB->getParent()->getReturnType();
- Value *V = UndefValue::get(RetType);
+ Value *V = Context.getUndef(RetType);
for (unsigned i = 0; i != N; ++i)
V = CreateInsertValue(V, retVals[i], i, "mrv");
return Insert(ReturnInst::Create(V));
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
}
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
- Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
+ Value *Idx = Context.getConstantInt(Type::Int32Ty, Idx0);
if (Constant *PC = dyn_cast<Constant>(Ptr))
return Folder.CreateGetElementPtr(PC, &Idx, 1);
Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
const char *Name = "") {
Value *Idxs[] = {
- ConstantInt::get(Type::Int32Ty, Idx0),
- ConstantInt::get(Type::Int32Ty, Idx1)
+ Context.getConstantInt(Type::Int32Ty, Idx0),
+ Context.getConstantInt(Type::Int32Ty, Idx1)
};
if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
}
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
- Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
+ Value *Idx = Context.getConstantInt(Type::Int64Ty, Idx0);
if (Constant *PC = dyn_cast<Constant>(Ptr))
return Folder.CreateGetElementPtr(PC, &Idx, 1);
Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
const char *Name = "") {
Value *Idxs[] = {
- ConstantInt::get(Type::Int64Ty, Idx0),
- ConstantInt::get(Type::Int64Ty, Idx1)
+ Context.getConstantInt(Type::Int64Ty, Idx0),
+ Context.getConstantInt(Type::Int64Ty, Idx1)
};
if (Constant *PC = dyn_cast<Constant>(Ptr))
return CreateConstGEP2_32(Ptr, 0, Idx, Name);
}
Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
- Constant *StrConstant = ConstantArray::get(Str, true);
- GlobalVariable *gv = new GlobalVariable(StrConstant->getType(),
+ Constant *StrConstant = Context.getConstantArray(Str, true);
+ GlobalVariable *gv = new GlobalVariable(Context,
+ StrConstant->getType(),
true,
GlobalValue::InternalLinkage,
StrConstant,
}
Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
Value *gv = CreateGlobalString(Str, Name);
- Value *zero = ConstantInt::get(Type::Int32Ty, 0);
+ Value *zero = Context.getConstantInt(Type::Int32Ty, 0);
Value *Args[] = { zero, zero };
return CreateGEP(gv, Args, Args+2, Name);
}
/// CreateIsNull - Return an i1 value testing if \arg Arg is null.
Value *CreateIsNull(Value *Arg, const char *Name = "") {
- return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
+ return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()),
Name);
}
/// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
Value *CreateIsNotNull(Value *Arg, const char *Name = "") {
- return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
+ return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()),
Name);
}
Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty);
Value *Difference = CreateSub(LHS_int, RHS_int);
return CreateSDiv(Difference,
- ConstantExpr::getSizeOf(ArgType->getElementType()),
+ Context.getConstantExprSizeOf(ArgType->getElementType()),
Name);
}
};
Constant *ConstStr = VMContext.getConstantArray(String);
// Otherwise create and return a new string global.
- GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
+ GlobalVariable *StrGV = new GlobalVariable(VMContext,ConstStr->getType(), true,
GlobalVariable::InternalLinkage,
ConstStr, ".str", &M);
StrGV->setSection("llvm.metadata");
DIDescriptor &Entry = SimpleConstantCache[Init];
if (!Entry.isNull()) return DIArray(Entry.getGV());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.array", &M);
GV->setSection("llvm.metadata");
M.addTypeName("llvm.dbg.subrange.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.subrange", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.compile_unit", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.enumerator", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.basictype.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.basictype", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.derivedtype", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.composite.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.composite", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.subprogram", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.global_variable", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.variable.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.variable", &M);
GV->setSection("llvm.metadata");
sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.block.type", Init->getType());
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
GlobalValue::InternalLinkage,
Init, "llvm.dbg.block", &M);
GV->setSection("llvm.metadata");
}
if (GV == 0) {
- GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0, Name,
+ GV = new GlobalVariable(Context, Ty, false,
+ GlobalValue::ExternalLinkage, 0, Name,
M, false, AddrSpace);
} else {
if (GV->getType()->getElementType() != Ty)
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
} else {
- FwdVal = new GlobalVariable(PTy->getElementType(), false,
+ FwdVal = new GlobalVariable(Context, PTy->getElementType(), false,
GlobalValue::ExternalWeakLinkage, 0, Name, M);
}
}
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
} else {
- FwdVal = new GlobalVariable(PTy->getElementType(), false,
+ FwdVal = new GlobalVariable(Context, PTy->getElementType(), false,
GlobalValue::ExternalWeakLinkage, 0, "", M);
}
isThreadLocal = Record[7];
GlobalVariable *NewGV =
- new GlobalVariable(Ty, isConstant, Linkage, 0, "", TheModule,
+ new GlobalVariable(Context, Ty, isConstant, Linkage, 0, "", TheModule,
isThreadLocal, AddressSpace);
NewGV->setAlignment(Alignment);
if (!Section.empty())
// to be a ModulePass (which means it cannot be in the 'llc' pipeline
// (which uses a FunctionPassManager (which segfaults (not asserts) if
// provided a ModulePass))).
- Constant *GV = new GlobalVariable(FrameMap->getType(), true,
+ Constant *GV = new GlobalVariable(*F.getContext(), FrameMap->getType(), true,
GlobalVariable::InternalLinkage,
FrameMap, "__gc_" + F.getName(),
F.getParent());
if (!Head) {
// If the root chain does not exist, insert a new one with linkonce
// linkage!
- Head = new GlobalVariable(StackEntryPtrTy, false,
+ Head = new GlobalVariable(M.getContext(), StackEntryPtrTy, false,
GlobalValue::LinkOnceAnyLinkage,
Constant::getNullValue(StackEntryPtrTy),
"llvm_gc_root_chain", &M);
// symbol over in the dest module... the initializer will be filled in
// later by LinkGlobalInits.
GlobalVariable *NewDGV =
- new GlobalVariable(SGV->getType()->getElementType(),
+ new GlobalVariable(Context, SGV->getType()->getElementType(),
SGV->isConstant(), SGV->getLinkage(), /*init*/0,
SGV->getName(), Dest, false,
SGV->getType()->getAddressSpace());
// AppendingVars map. The name is cleared out so that no linkage is
// performed.
GlobalVariable *NewDGV =
- new GlobalVariable(SGV->getType()->getElementType(),
+ new GlobalVariable(Context, SGV->getType()->getElementType(),
SGV->isConstant(), SGV->getLinkage(), /*init*/0,
"", Dest, false,
SGV->getType()->getAddressSpace());
// we are replacing may be a function (if a prototype, weak, etc) or a
// global variable.
GlobalVariable *NewDGV =
- new GlobalVariable(SGV->getType()->getElementType(), SGV->isConstant(),
- NewLinkage, /*init*/0, DGV->getName(), Dest, false,
+ new GlobalVariable(Context, SGV->getType()->getElementType(),
+ SGV->isConstant(), NewLinkage, /*init*/0,
+ DGV->getName(), Dest, false,
SGV->getType()->getAddressSpace());
// Propagate alignment, section, and visibility info.
// Create the new global variable...
GlobalVariable *NG =
- new GlobalVariable(NewType, G1->isConstant(), G1->getLinkage(),
+ new GlobalVariable(Context, NewType, G1->isConstant(), G1->getLinkage(),
/*init*/0, First->first, M, G1->isThreadLocal(),
G1->getType()->getAddressSpace());
}
ArrayType *AT = Context->getArrayType(SBP, AUGs.size());
Constant *Init = Context->getConstantArray(AT, AUGs);
- GlobalValue *gv = new GlobalVariable(AT, false,
+ GlobalValue *gv = new GlobalVariable(M.getContext(), AT, false,
GlobalValue::AppendingLinkage,
Init, "llvm.used", &M);
gv->setSection("llvm.metadata");
Context->getConstantInt(Type::Int32Ty, i),
Context);
assert(In && "Couldn't get element of initializer?");
- GlobalVariable *NGV = new GlobalVariable(STy->getElementType(i), false,
+ GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(i),
+ false,
GlobalVariable::InternalLinkage,
In, GV->getName()+"."+utostr(i),
(Module *)NULL,
GV->isThreadLocal(),
- GV->getType()->getAddressSpace());
+ GV->getType()->getAddressSpace());
Globals.insert(GV, NGV);
NewGlobals.push_back(NGV);
Context);
assert(In && "Couldn't get element of initializer?");
- GlobalVariable *NGV = new GlobalVariable(STy->getElementType(), false,
+ GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(),
+ false,
GlobalVariable::InternalLinkage,
In, GV->getName()+"."+utostr(i),
(Module *)NULL,
// Create the new global variable. The contents of the malloc'd memory is
// undefined, so initialize with an undef value.
Constant *Init = Context->getUndef(MI->getAllocatedType());
- GlobalVariable *NewGV = new GlobalVariable(MI->getAllocatedType(), false,
+ GlobalVariable *NewGV = new GlobalVariable(*Context, MI->getAllocatedType(),
+ false,
GlobalValue::InternalLinkage, Init,
GV->getName()+".body",
(Module *)NULL,
// If there is a comparison against null, we will insert a global bool to
// keep track of whether the global was initialized yet or not.
GlobalVariable *InitBool =
- new GlobalVariable(Type::Int1Ty, false, GlobalValue::InternalLinkage,
+ new GlobalVariable(*Context, Type::Int1Ty, false,
+ GlobalValue::InternalLinkage,
Context->getConstantIntFalse(), GV->getName()+".init",
(Module *)NULL, GV->isThreadLocal());
bool InitBoolUsed = false;
const Type *PFieldTy = Context->getPointerTypeUnqual(FieldTy);
GlobalVariable *NGV =
- new GlobalVariable(PFieldTy, false, GlobalValue::InternalLinkage,
+ new GlobalVariable(*Context, PFieldTy, false,
+ GlobalValue::InternalLinkage,
Context->getNullValue(PFieldTy),
GV->getName() + ".f" + utostr(FieldNo), GV,
GV->isThreadLocal());
DOUT << " *** SHRINKING TO BOOL: " << *GV;
// Create the new global, initializing it to false.
- GlobalVariable *NewGV = new GlobalVariable(Type::Int1Ty, false,
+ GlobalVariable *NewGV = new GlobalVariable(*Context, Type::Int1Ty, false,
GlobalValue::InternalLinkage, Context->getConstantIntFalse(),
GV->getName()+".b",
(Module *)NULL,
}
// Create the new global and insert it next to the existing list.
- GlobalVariable *NGV = new GlobalVariable(CA->getType(), GCL->isConstant(),
+ GlobalVariable *NGV = new GlobalVariable(*Context, CA->getType(),
+ GCL->isConstant(),
GCL->getLinkage(), CA, "",
(Module *)NULL,
GCL->isThreadLocal());
} else if (AllocaInst *AI = dyn_cast<AllocaInst>(CurInst)) {
if (AI->isArrayAllocation()) return false; // Cannot handle array allocs.
const Type *Ty = AI->getType()->getElementType();
- AllocaTmps.push_back(new GlobalVariable(Ty, false,
+ AllocaTmps.push_back(new GlobalVariable(*Context, Ty, false,
GlobalValue::InternalLinkage,
Context->getUndef(Ty),
AI->getName()));
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions);
GlobalVariable *Counters =
- new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
+ new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
Context->getNullValue(ATy), "FuncProfCounters", &M);
// Instrument all of the functions...
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks);
GlobalVariable *Counters =
- new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
+ new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
Context->getNullValue(ATy), "BlockProfCounters", &M);
// Instrument all of the blocks...
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges);
GlobalVariable *Counters =
- new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
+ new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
Context->getNullValue(ATy), "EdgeProfCounters", &M);
// Instrument all of the edges...
uint64_t resetval) : T(t) {
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init;
- Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
+ Counter = new GlobalVariable(M.getContext(), T, false,
+ GlobalValue::InternalLinkage,
Init, "RandomSteeringCounter", &M);
}
: AI(0), T(t) {
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init;
- Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
+ Counter = new GlobalVariable(M.getContext(), T, false,
+ GlobalValue::InternalLinkage,
Init, "RandomSteeringCounter", &M);
}
// pass to be run after this pass, to merge duplicate strings.
FormatStr.erase(FormatStr.end()-1);
Constant *C = Context->getConstantArray(FormatStr, true);
- C = new GlobalVariable(C->getType(), true,GlobalVariable::InternalLinkage,
+ C = new GlobalVariable(*Context, C->getType(),
+ true, GlobalVariable::InternalLinkage,
C, "str", Callee->getParent());
EmitPutS(C, B);
return CI->use_empty() ? (Value*)CI :
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
- GlobalVariable *GV = new GlobalVariable(I->getType()->getElementType(),
+ GlobalVariable *GV = new GlobalVariable(M->getContext(),
+ I->getType()->getElementType(),
false,
GlobalValue::ExternalLinkage, 0,
I->getName(), New);
// Now that we've done that, insert the jmpbuf list head global, unless it
// already exists.
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
- JBListHead = new GlobalVariable(PtrJBList, false,
+ JBListHead = new GlobalVariable(M.getContext(),
+ PtrJBList, false,
GlobalValue::LinkOnceAnyLinkage,
Context->getNullValue(PtrJBList),
"llvm.sjljeh.jblist", &M);
Context->getConstantArray("ERROR: Exception thrown, but not caught!\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
- GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
+ GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
+ Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg", M);
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
"Recompile program with -enable-correct-eh-support.\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
- GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
+ GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
+ Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg", M);
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
/*--.. Operations on global variables ......................................--*/
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
- return wrap(new GlobalVariable(unwrap(Ty), false,
+ LLVMContext &Context = unwrap(M)->getContext();
+ return wrap(new GlobalVariable(Context, unwrap(Ty), false,
GlobalValue::ExternalLinkage, 0, Name,
unwrap(M)));
}
#include "llvm/GlobalVariable.h"
#include "llvm/GlobalAlias.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/LeakDetector.h"
// GlobalVariable Implementation
//===----------------------------------------------------------------------===//
-GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
+GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
+ bool constant, LinkageTypes Link,
Constant *InitVal, const std::string &Name,
Module *ParentModule, bool ThreadLocal,
unsigned AddressSpace)
- : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
+ : GlobalValue(Context.getPointerType(Ty, AddressSpace),
+ Value::GlobalVariableVal,
OperandTraits<GlobalVariable>::op_begin(this),
InitVal != 0, Link, Name),
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
ParentModule->getGlobalList().push_back(this);
}
-GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
+GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
+ bool constant, LinkageTypes Link,
Constant *InitVal, const std::string &Name,
GlobalVariable *Before, bool ThreadLocal,
unsigned AddressSpace)
- : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
+ : GlobalValue(Context.getPointerType(Ty, AddressSpace),
+ Value::GlobalVariableVal,
OperandTraits<GlobalVariable>::op_begin(this),
InitVal != 0, Link, Name),
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
//===----------------------------------------------------------------------===//
// 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(Type::Int32Ty, false,
+ 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);
if (GV == 0) {
// Nope, add it
GlobalVariable *New =
- new GlobalVariable(Ty, false, GlobalVariable::ExternalLinkage, 0, Name);
+ new GlobalVariable(getContext(), Ty, false,
+ GlobalVariable::ExternalLinkage, 0, Name);
GlobalList.push_back(New);
return New; // Return the new declaration.
}
GV->eraseFromParent();
if (!M1Tors.empty()) {
Constant *M1Init = GetTorInit(M1Tors);
- new GlobalVariable(M1Init->getType(), false, GlobalValue::AppendingLinkage,
+ new GlobalVariable(M1->getContext(), M1Init->getType(), false,
+ GlobalValue::AppendingLinkage,
M1Init, GlobalName, M1);
}
GV->eraseFromParent();
if (!M2Tors.empty()) {
Constant *M2Init = GetTorInit(M2Tors);
- new GlobalVariable(M2Init->getType(), false, GlobalValue::AppendingLinkage,
+ new GlobalVariable(M2->getContext(), M2Init->getType(), false,
+ GlobalValue::AppendingLinkage,
M2Init, GlobalName, M2);
}
}
// 1. Add a string constant with its name to the global file
Constant *InitArray = ConstantArray::get(F->getName());
GlobalVariable *funcName =
- new GlobalVariable(InitArray->getType(), true /*isConstant*/,
+ new GlobalVariable(Safe->getContext(),
+ InitArray->getType(), true /*isConstant*/,
GlobalValue::InternalLinkage, InitArray,
F->getName() + "_name", Safe);
// Create a new global to hold the cached function pointer.
Constant *NullPtr = ConstantPointerNull::get(F->getType());
GlobalVariable *Cache =
- new GlobalVariable(F->getType(), false,GlobalValue::InternalLinkage,
+ new GlobalVariable(F->getParent()->getContext(),
+ F->getType(), false,GlobalValue::InternalLinkage,
NullPtr,F->getName()+".fpcache", F->getParent());
// Construct a new stub function that will re-route calls to F