Remove every uses of getGlobalContext() in LLVM (but the C API)

At the same time, fixes InstructionsTest::CastInst unittest: yes
you can leave the IR in an invalid state and exit when you don't
destroy the context (like the global one), no longer now.

This is the first part of http://reviews.llvm.org/D19094

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266379
diff --git a/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
index a733bd5..89adb66 100644
--- a/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
@@ -25,6 +25,7 @@
 
 class ObjectLinkingLayerExecutionTest : public testing::Test,
                                         public OrcExecutionTest {
+
 };
 
 class SectionMemoryManagerWrapper : public SectionMemoryManager {
@@ -64,9 +65,10 @@
 
   ObjectLinkingLayer<> ObjLayer;
 
-  auto M = llvm::make_unique<Module>("", getGlobalContext());
+  LLVMContext Context;
+  auto M = llvm::make_unique<Module>("", Context);
   M->setTargetTriple("x86_64-unknown-linux-gnu");
-  Type *Int32Ty = IntegerType::get(getGlobalContext(), 32);
+  Type *Int32Ty = IntegerType::get(Context, 32);
   GlobalVariable *GV =
     new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
                          ConstantInt::get(Int32Ty, 42), "foo");
@@ -131,14 +133,13 @@
   // instance (for Module 1) which is unsafe, as it will prevent relocation of
   // Module 2.
 
-  ModuleBuilder MB1(getGlobalContext(), "", "dummy");
+  ModuleBuilder MB1(Context, "", "dummy");
   {
     MB1.getModule()->setDataLayout(TM->createDataLayout());
     Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("bar");
-    BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
-                                              BarImpl);
+    BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
     IRBuilder<> Builder(BarEntry);
-    IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
+    IntegerType *Int32Ty = IntegerType::get(Context, 32);
     Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
     Builder.CreateRet(FourtyTwo);
   }
@@ -147,13 +148,12 @@
   std::vector<object::ObjectFile*> Obj1Set;
   Obj1Set.push_back(Obj1.getBinary());
 
-  ModuleBuilder MB2(getGlobalContext(), "", "dummy");
+  ModuleBuilder MB2(Context, "", "dummy");
   {
     MB2.getModule()->setDataLayout(TM->createDataLayout());
     Function *BarDecl = MB2.createFunctionDecl<int32_t(void)>("bar");
     Function *FooImpl = MB2.createFunctionDecl<int32_t(void)>("foo");
-    BasicBlock *FooEntry = BasicBlock::Create(getGlobalContext(), "entry",
-                                              FooImpl);
+    BasicBlock *FooEntry = BasicBlock::Create(Context, "entry", FooImpl);
     IRBuilder<> Builder(FooEntry);
     Builder.CreateRet(Builder.CreateCall(BarDecl));
   }
@@ -203,14 +203,13 @@
   // RuntimeDyld::MemoryManager::needsToReserveAllocationSpace hook, which is
   // called once per object before any sections are allocated.
 
-  ModuleBuilder MB1(getGlobalContext(), "", "dummy");
+  ModuleBuilder MB1(Context, "", "dummy");
   {
     MB1.getModule()->setDataLayout(TM->createDataLayout());
     Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("foo");
-    BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
-                                              BarImpl);
+    BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
     IRBuilder<> Builder(BarEntry);
-    IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
+    IntegerType *Int32Ty = IntegerType::get(Context, 32);
     Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
     Builder.CreateRet(FourtyTwo);
   }
@@ -219,14 +218,13 @@
   std::vector<object::ObjectFile*> Obj1Set;
   Obj1Set.push_back(Obj1.getBinary());
 
-  ModuleBuilder MB2(getGlobalContext(), "", "dummy");
+  ModuleBuilder MB2(Context, "", "dummy");
   {
     MB2.getModule()->setDataLayout(TM->createDataLayout());
     Function *BarImpl = MB2.createFunctionDecl<int32_t(void)>("bar");
-    BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
-                                              BarImpl);
+    BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
     IRBuilder<> Builder(BarEntry);
-    IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
+    IntegerType *Int32Ty = IntegerType::get(Context, 32);
     Value *Seven = ConstantInt::getSigned(Int32Ty, 7);
     Builder.CreateRet(Seven);
   }