[llvm-commits] [llvm] r74985 - in /llvm/trunk: examples/BrainF/ include/llvm/ include/llvm/Support/ lib/Analysis/ lib/AsmParser/ lib/Bitcode/Reader/ lib/CodeGen/ lib/Linker/ lib/Transforms/IPO/ lib/Transforms/Instrumentation/ lib/Transforms/Scalar/ lib/Transforms/Utils/ lib/VMCore/ tools/bugpoint/
Owen Anderson
resistor at mac.com
Tue Jul 7 18:26:07 PDT 2009
Author: resistor
Date: Tue Jul 7 20:26:06 2009
New Revision: 74985
URL: http://llvm.org/viewvc/llvm-project?rev=74985&view=rev
Log:
Push LLVMContext through GlobalVariables and IRBuilder.
Modified:
llvm/trunk/examples/BrainF/BrainF.cpp
llvm/trunk/include/llvm/GlobalVariable.h
llvm/trunk/include/llvm/Support/IRBuilder.h
llvm/trunk/lib/Analysis/DebugInfo.cpp
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/CodeGen/ShadowStackGC.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp
llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp
llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp
llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp
llvm/trunk/lib/VMCore/Core.cpp
llvm/trunk/lib/VMCore/Globals.cpp
llvm/trunk/lib/VMCore/Module.cpp
llvm/trunk/tools/bugpoint/ExtractFunction.cpp
llvm/trunk/tools/bugpoint/Miscompilation.cpp
Modified: llvm/trunk/examples/BrainF/BrainF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/BrainF/BrainF.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/examples/BrainF/BrainF.cpp (original)
+++ llvm/trunk/examples/BrainF/BrainF.cpp Tue Jul 7 20:26:06 2009
@@ -128,6 +128,7 @@
get("Error: The head has left the tape.", true);
GlobalVariable *aberrormsg = new GlobalVariable(
+ module->getContext(),
msg_0->getType(),
true,
GlobalValue::InternalLinkage,
Modified: llvm/trunk/include/llvm/GlobalVariable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalVariable.h?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/include/llvm/GlobalVariable.h (original)
+++ llvm/trunk/include/llvm/GlobalVariable.h Tue Jul 7 20:26:06 2009
@@ -26,6 +26,7 @@
namespace llvm {
+class LLVMContext;
class Module;
class Constant;
template<typename ValueSubClass, typename ItemParentClass>
@@ -49,13 +50,15 @@
}
/// 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);
Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Jul 7 20:26:06 2009
@@ -20,6 +20,7 @@
#include "llvm/GlobalAlias.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/ConstantFolder.h"
namespace llvm {
@@ -42,12 +43,16 @@
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; }
@@ -125,7 +130,7 @@
///
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));
@@ -349,7 +354,7 @@
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);
@@ -359,8 +364,8 @@
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))
@@ -369,7 +374,7 @@
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);
@@ -379,8 +384,8 @@
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))
@@ -392,8 +397,9 @@
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,
@@ -405,7 +411,7 @@
}
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);
}
@@ -697,13 +703,13 @@
/// 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);
}
@@ -718,7 +724,7 @@
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);
}
};
Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Jul 7 20:26:06 2009
@@ -490,7 +490,7 @@
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");
@@ -516,7 +516,7 @@
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");
@@ -542,7 +542,7 @@
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");
@@ -579,7 +579,7 @@
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");
@@ -598,7 +598,7 @@
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");
@@ -632,7 +632,7 @@
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");
@@ -668,7 +668,7 @@
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");
@@ -708,7 +708,7 @@
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");
@@ -746,7 +746,7 @@
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");
@@ -780,7 +780,7 @@
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");
@@ -806,7 +806,7 @@
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");
@@ -826,7 +826,7 @@
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");
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Jul 7 20:26:06 2009
@@ -516,7 +516,8 @@
}
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)
@@ -607,7 +608,7 @@
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);
}
@@ -651,7 +652,7 @@
}
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);
}
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jul 7 20:26:06 2009
@@ -1258,7 +1258,7 @@
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())
Modified: llvm/trunk/lib/CodeGen/ShadowStackGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ShadowStackGC.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ShadowStackGC.cpp (original)
+++ llvm/trunk/lib/CodeGen/ShadowStackGC.cpp Tue Jul 7 20:26:06 2009
@@ -229,7 +229,7 @@
// 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());
@@ -292,7 +292,7 @@
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);
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Tue Jul 7 20:26:06 2009
@@ -573,7 +573,7 @@
// 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());
@@ -606,7 +606,7 @@
// 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());
@@ -634,8 +634,9 @@
// 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.
@@ -1156,7 +1157,7 @@
// 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());
Modified: llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp Tue Jul 7 20:26:06 2009
@@ -108,7 +108,7 @@
}
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");
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Jul 7 20:26:06 2009
@@ -490,12 +490,13 @@
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);
@@ -526,7 +527,8 @@
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,
@@ -841,7 +843,8 @@
// 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,
@@ -862,7 +865,8 @@
// 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;
@@ -1282,7 +1286,8 @@
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());
@@ -1579,7 +1584,7 @@
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,
@@ -1974,7 +1979,8 @@
}
// 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());
@@ -2222,7 +2228,7 @@
} 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()));
Modified: llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp Tue Jul 7 20:26:06 2009
@@ -65,7 +65,7 @@
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...
@@ -110,7 +110,7 @@
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...
Modified: llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp Tue Jul 7 20:26:06 2009
@@ -66,7 +66,7 @@
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...
Modified: llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp Tue Jul 7 20:26:06 2009
@@ -198,7 +198,8 @@
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);
}
@@ -237,7 +238,8 @@
: 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);
}
Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Tue Jul 7 20:26:06 2009
@@ -1290,7 +1290,8 @@
// 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 :
Modified: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneModule.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Tue Jul 7 20:26:06 2009
@@ -56,7 +56,8 @@
//
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);
Modified: llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp Tue Jul 7 20:26:06 2009
@@ -139,7 +139,8 @@
// 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);
@@ -182,7 +183,8 @@
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));
@@ -195,7 +197,8 @@
"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));
Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Tue Jul 7 20:26:06 2009
@@ -700,7 +700,8 @@
/*--.. 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)));
}
Modified: llvm/trunk/lib/VMCore/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Globals.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Globals.cpp (original)
+++ llvm/trunk/lib/VMCore/Globals.cpp Tue Jul 7 20:26:06 2009
@@ -16,6 +16,7 @@
#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"
@@ -93,11 +94,13 @@
// 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) {
@@ -113,11 +116,13 @@
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) {
Modified: llvm/trunk/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Tue Jul 7 20:26:06 2009
@@ -28,17 +28,20 @@
//===----------------------------------------------------------------------===//
// 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);
@@ -270,7 +273,8 @@
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.
}
Modified: llvm/trunk/tools/bugpoint/ExtractFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExtractFunction.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ExtractFunction.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExtractFunction.cpp Tue Jul 7 20:26:06 2009
@@ -236,7 +236,8 @@
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);
}
@@ -247,7 +248,8 @@
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);
}
}
Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=74985&r1=74984&r2=74985&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)
+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Tue Jul 7 20:26:06 2009
@@ -703,7 +703,8 @@
// 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);
@@ -722,7 +723,8 @@
// 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
More information about the llvm-commits
mailing list