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
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 @@
         }
         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 @@
                                     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 @@
                                     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 @@
 
   // 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(*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
   // 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);
-
+  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.
   MI->replaceAllUsesWith(NewGV);
 
@@ -868,7 +865,7 @@
     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 @@
     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 @@
   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 @@
   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 @@
 
   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 @@
 
   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 @@
 
   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 @@
                                          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 @@
   : 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 @@
       // 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 @@
   //
   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 @@
     // 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 @@
       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 @@
                         "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);
   }