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);