summaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-08 19:03:57 +0000
committerOwen Anderson <resistor@mac.com>2009-07-08 19:03:57 +0000
commite9b11b431308f4766b73cda93e38ec930c912122 (patch)
treed72fc321dc0c445f8880443050c0a03c2ccdf7d2 /lib/Transforms
parent515cdbe49d9bb5cd05be2713faaa7e2a66ddc3bc (diff)
downloadexternal_llvm-e9b11b431308f4766b73cda93e38ec930c912122.zip
external_llvm-e9b11b431308f4766b73cda93e38ec930c912122.tar.gz
external_llvm-e9b11b431308f4766b73cda93e38ec930c912122.tar.bz2
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
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/ExtractGV.cpp4
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp35
-rw-r--r--lib/Transforms/Instrumentation/BlockProfiling.cpp8
-rw-r--r--lib/Transforms/Instrumentation/EdgeProfiling.cpp4
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp10
-rw-r--r--lib/Transforms/Scalar/SimplifyLibCalls.cpp5
-rw-r--r--lib/Transforms/Utils/CloneModule.cpp4
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp15
8 files changed, 37 insertions, 48 deletions
diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp
index e26bd3a..b7c5ca3 100644
--- a/lib/Transforms/IPO/ExtractGV.cpp
+++ b/lib/Transforms/IPO/ExtractGV.cpp
@@ -108,9 +108,9 @@ namespace {
}
ArrayType *AT = Context->getArrayType(SBP, AUGs.size());
Constant *Init = Context->getConstantArray(AT, AUGs);
- GlobalValue *gv = new GlobalVariable(M.getContext(), AT, false,
+ GlobalValue *gv = new GlobalVariable(M, AT, false,
GlobalValue::AppendingLinkage,
- Init, "llvm.used", &M);
+ Init, "llvm.used");
gv->setSection("llvm.metadata");
}
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index eb13067..2cd8b6b 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -490,11 +490,10 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
Context->getConstantInt(Type::Int32Ty, i),
Context);
assert(In && "Couldn't get element of initializer?");
- GlobalVariable *NGV = new GlobalVariable(*Context, 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());
Globals.insert(GV, NGV);
@@ -527,13 +526,12 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
Context);
assert(In && "Couldn't get element of initializer?");
- GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(),
- false,
+ GlobalVariable *NGV = new GlobalVariable(*Context,
+ STy->getElementType(), 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);
@@ -842,18 +840,17 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
// Create the new global variable. The contents of the malloc'd memory is
// undefined, so initialize with an undef value.
+ // 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
+ // this would only guarantee some lower alignment.
Constant *Init = Context->getUndef(MI->getAllocatedType());
- GlobalVariable *NewGV = new GlobalVariable(*Context, MI->getAllocatedType(),
- false,
+ GlobalVariable *NewGV = new GlobalVariable(*GV->getParent(),
+ MI->getAllocatedType(), false,
GlobalValue::InternalLinkage, Init,
GV->getName()+".body",
- (Module *)NULL,
+ GV,
GV->isThreadLocal());
- // 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
- // this would only guarantee some lower alignment.
- GV->getParent()->getGlobalList().insert(GV, NewGV);
-
+
// Anything that used the malloc now uses the global directly.
MI->replaceAllUsesWith(NewGV);
@@ -868,7 +865,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
new GlobalVariable(*Context, Type::Int1Ty, false,
GlobalValue::InternalLinkage,
Context->getConstantIntFalse(), GV->getName()+".init",
- (Module *)NULL, GV->isThreadLocal());
+ GV->isThreadLocal());
bool InitBoolUsed = false;
// 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);
GlobalVariable *NGV =
- new GlobalVariable(*Context, PFieldTy, false,
- GlobalValue::InternalLinkage,
+ new GlobalVariable(*GV->getParent(),
+ PFieldTy, false, GlobalValue::InternalLinkage,
Context->getNullValue(PFieldTy),
GV->getName() + ".f" + utostr(FieldNo), GV,
GV->isThreadLocal());
@@ -1587,7 +1584,6 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal,
GlobalVariable *NewGV = new GlobalVariable(*Context, Type::Int1Ty, false,
GlobalValue::InternalLinkage, Context->getConstantIntFalse(),
GV->getName()+".b",
- (Module *)NULL,
GV->isThreadLocal());
GV->getParent()->getGlobalList().insert(GV, NewGV);
@@ -1982,7 +1978,6 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
GlobalVariable *NGV = new GlobalVariable(*Context, CA->getType(),
GCL->isConstant(),
GCL->getLinkage(), CA, "",
- (Module *)NULL,
GCL->isThreadLocal());
GCL->getParent()->getGlobalList().insert(GCL, NGV);
NGV->takeName(GCL);
diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp
index 6dfcc0b..440f59b 100644
--- a/lib/Transforms/Instrumentation/BlockProfiling.cpp
+++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp
@@ -65,8 +65,8 @@ bool FunctionProfiler::runOnModule(Module &M) {
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions);
GlobalVariable *Counters =
- new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
- Context->getNullValue(ATy), "FuncProfCounters", &M);
+ new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
+ Context->getNullValue(ATy), "FuncProfCounters");
// Instrument all of the functions...
unsigned i = 0;
@@ -110,8 +110,8 @@ bool BlockProfiler::runOnModule(Module &M) {
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks);
GlobalVariable *Counters =
- new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
- Context->getNullValue(ATy), "BlockProfCounters", &M);
+ new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
+ Context->getNullValue(ATy), "BlockProfCounters");
// Instrument all of the blocks...
unsigned i = 0;
diff --git a/lib/Transforms/Instrumentation/EdgeProfiling.cpp b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
index b625341..c3ec4b9 100644
--- a/lib/Transforms/Instrumentation/EdgeProfiling.cpp
+++ b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
@@ -66,8 +66,8 @@ bool EdgeProfiler::runOnModule(Module &M) {
const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges);
GlobalVariable *Counters =
- new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
- Context->getNullValue(ATy), "EdgeProfCounters", &M);
+ new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
+ Context->getNullValue(ATy), "EdgeProfCounters");
// Instrument all of the edges...
unsigned i = 0;
diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp
index 0999a27..5101220 100644
--- a/lib/Transforms/Instrumentation/RSProfiling.cpp
+++ b/lib/Transforms/Instrumentation/RSProfiling.cpp
@@ -198,9 +198,8 @@ GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t,
uint64_t resetval) : T(t) {
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init;
- Counter = new GlobalVariable(M.getContext(), T, false,
- GlobalValue::InternalLinkage,
- Init, "RandomSteeringCounter", &M);
+ Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage,
+ Init, "RandomSteeringCounter");
}
GlobalRandomCounter::~GlobalRandomCounter() {}
@@ -238,9 +237,8 @@ GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t,
: AI(0), T(t) {
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init;
- Counter = new GlobalVariable(M.getContext(), T, false,
- GlobalValue::InternalLinkage,
- Init, "RandomSteeringCounter", &M);
+ Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage,
+ Init, "RandomSteeringCounter");
}
GlobalRandomCounterOpt::~GlobalRandomCounterOpt() {}
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index 72308c8..80ef96a 100644
--- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
@@ -1290,9 +1290,8 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization {
// 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(*Context, C->getType(),
- true, GlobalVariable::InternalLinkage,
- C, "str", Callee->getParent());
+ C = new GlobalVariable(*Callee->getParent(), C->getType(), true,
+ GlobalVariable::InternalLinkage, C, "str");
EmitPutS(C, B);
return CI->use_empty() ? (Value*)CI :
Context->getConstantInt(CI->getType(), FormatStr.size()+1);
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
index afebd5b..bb5f3e6 100644
--- a/lib/Transforms/Utils/CloneModule.cpp
+++ b/lib/Transforms/Utils/CloneModule.cpp
@@ -56,11 +56,11 @@ Module *llvm::CloneModule(const Module *M,
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
- GlobalVariable *GV = new GlobalVariable(M->getContext(),
+ GlobalVariable *GV = new GlobalVariable(*New,
I->getType()->getElementType(),
false,
GlobalValue::ExternalLinkage, 0,
- I->getName(), New);
+ I->getName());
GV->setAlignment(I->getAlignment());
ValueMap[I] = GV;
}
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index 1eefdc4..8ef060a 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -139,11 +139,10 @@ bool LowerInvoke::doInitialization(Module &M) {
// 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(M.getContext(),
- PtrJBList, false,
+ JBListHead = new GlobalVariable(M, PtrJBList, false,
GlobalValue::LinkOnceAnyLinkage,
Context->getNullValue(PtrJBList),
- "llvm.sjljeh.jblist", &M);
+ "llvm.sjljeh.jblist");
}
// 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");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
- GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
- Msg->getType(), true,
+ GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
- Msg, "abortmsg", M);
+ Msg, "abortmsg");
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
AbortMessage = Context->getConstantExprGetElementPtr(MsgGV, &GEPIdx[0], 2);
} else {
@@ -197,10 +195,9 @@ void LowerInvoke::createAbortMessage(Module *M) {
"Recompile program with -enable-correct-eh-support.\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
- GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
- Msg->getType(), true,
+ GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
- Msg, "abortmsg", M);
+ Msg, "abortmsg");
std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
}