Push LLVMContext _back_ through IRBuilder.
authorOwen Anderson <resistor@mac.com>
Wed, 8 Jul 2009 20:50:47 +0000 (20:50 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 8 Jul 2009 20:50:47 +0000 (20:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75040 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
docs/tutorial/LangImpl3.html
docs/tutorial/LangImpl4.html
docs/tutorial/LangImpl5.html
docs/tutorial/LangImpl6.html
docs/tutorial/LangImpl7.html
examples/Kaleidoscope/toy.cpp
include/llvm/Analysis/ScalarEvolutionExpander.h
include/llvm/Support/IRBuilder.h
lib/CodeGen/IntrinsicLowering.cpp
lib/CodeGen/ShadowStackGC.cpp
lib/Transforms/Scalar/SimplifyLibCalls.cpp
lib/VMCore/Core.cpp

index faf11d0592bed72d6b422fc2710462270eaf9ac4..5028a639de34554e040531585ece696b7451a3e7 100644 (file)
@@ -115,7 +115,7 @@ undeclared parameter):</p>
 Value *ErrorV(const char *Str) { Error(Str); return 0; }
 
 static Module *TheModule;
-static IRBuilder&lt;&gt; Builder;
+static IRBuilder&lt;&gt; Builder(getGlobalContext());
 static std::map&lt;std::string, Value*&gt; NamedValues;
 </pre>
 </div>
@@ -682,6 +682,7 @@ our makefile/command line about which options to use:</p>
 // See example below.
 
 #include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Support/IRBuilder.h"
@@ -1216,7 +1217,7 @@ double putchard(double X) {
 //===----------------------------------------------------------------------===//
 
 int main() {
-  TheModule = new Module("my cool jit");
+  TheModule = new Module("my cool jit", getGlobalContext());
 
   // Install standard binary operators.
   // 1 is lowest precedence.
index 9a3bfd21471e73526f1ed6c1d5ec45efe46d0756..f08665d64cd47e44226d58f2c301581bb2c18b70 100644 (file)
@@ -512,6 +512,7 @@ at runtime.</p>
 <pre>
 #include "llvm/DerivedTypes.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -861,7 +862,7 @@ static PrototypeAST *ParseExtern() {
 //===----------------------------------------------------------------------===//
 
 static Module *TheModule;
-static IRBuilder&lt;&gt; Builder;
+static IRBuilder&lt;&gt; Builder(getGlobalContext());
 static std::map&lt;std::string, Value*&gt; NamedValues;
 static FunctionPassManager *TheFPM;
 
@@ -1074,7 +1075,7 @@ int main() {
   getNextToken();
 
   // Make the module, which holds all the code.
-  TheModule = new Module("my cool jit");
+  TheModule = new Module("my cool jit", getGlobalContext());
   
   // Create the JIT.
   TheExecutionEngine = ExecutionEngine::create(TheModule);
index bf96b460465fdd58c8805b9a4af6dea91b34aa08..bb4b4075b88a12a329d361b94107d0a9f71ad628 100644 (file)
@@ -901,6 +901,7 @@ if/then/else and for expressions..  To build this example, use:
 <pre>
 #include "llvm/DerivedTypes.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -1352,7 +1353,7 @@ static PrototypeAST *ParseExtern() {
 //===----------------------------------------------------------------------===//
 
 static Module *TheModule;
-static IRBuilder&lt;&gt; Builder;
+static IRBuilder&lt;&gt; Builder(getGlobalContext());
 static std::map&lt;std::string, Value*&gt; NamedValues;
 static FunctionPassManager *TheFPM;
 
@@ -1708,7 +1709,7 @@ int main() {
   getNextToken();
 
   // Make the module, which holds all the code.
-  TheModule = new Module("my cool jit");
+  TheModule = new Module("my cool jit", getGlobalContext());
   
   // Create the JIT.
   TheExecutionEngine = ExecutionEngine::create(TheModule);
index 44ad15b009655fcf9bd95ecbf0a9cad5097996c1..c6d9ce1847427a78bd6590be410963ffd8c8ff5e 100644 (file)
@@ -821,6 +821,7 @@ if/then/else and for expressions..  To build this example, use:
 <pre>
 #include "llvm/DerivedTypes.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -1357,7 +1358,7 @@ static PrototypeAST *ParseExtern() {
 //===----------------------------------------------------------------------===//
 
 static Module *TheModule;
-static IRBuilder&lt;&gt; Builder;
+static IRBuilder&lt;&gt; Builder(getGlobalContext());
 static std::map&lt;std::string, Value*&gt; NamedValues;
 static FunctionPassManager *TheFPM;
 
@@ -1747,7 +1748,7 @@ int main() {
   getNextToken();
 
   // Make the module, which holds all the code.
-  TheModule = new Module("my cool jit");
+  TheModule = new Module("my cool jit", getGlobalContext());
   
   // Create the JIT.
   TheExecutionEngine = ExecutionEngine::create(TheModule);
index f5606484eb9ff947d0392787e1cf0763e1cee6db..71bb397b49a8e819196eea8a760eefe76e62da64 100644 (file)
@@ -1003,6 +1003,7 @@ variables and var/in support.  To build this example, use:
 <pre>
 #include "llvm/DerivedTypes.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -1605,7 +1606,7 @@ static PrototypeAST *ParseExtern() {
 //===----------------------------------------------------------------------===//
 
 static Module *TheModule;
-static IRBuilder&lt;&gt; Builder;
+static IRBuilder&lt;&gt; Builder(getGlobalContext());
 static std::map&lt;std::string, AllocaInst*&gt; NamedValues;
 static FunctionPassManager *TheFPM;
 
@@ -2099,7 +2100,7 @@ int main() {
   getNextToken();
 
   // Make the module, which holds all the code.
-  TheModule = new Module("my cool jit");
+  TheModule = new Module("my cool jit", getGlobalContext());
   
   // Create the JIT.
   TheExecutionEngine = ExecutionEngine::create(TheModule);
index 612cfa547ca1415d4d3f503c9e1ff0af8a494a8c..3893aeac591fb510d9b6411e552311694905f95a 100644 (file)
@@ -604,7 +604,7 @@ static PrototypeAST *ParseExtern() {
 //===----------------------------------------------------------------------===//
 
 static Module *TheModule;
-static IRBuilder<> Builder;
+static IRBuilder<> Builder(getGlobalContext());
 static std::map<std::string, AllocaInst*> NamedValues;
 static FunctionPassManager *TheFPM;
 
index 2c8bcd742b303011dc571f65d518db5c20c52da3..a591efd8cceaf92cd75d46e3e1a63a450c2b31a8 100644 (file)
@@ -37,7 +37,8 @@ namespace llvm {
     friend struct SCEVVisitor<SCEVExpander, Value*>;
   public:
     explicit SCEVExpander(ScalarEvolution &se)
-      : SE(se), Builder(TargetFolder(se.TD, se.getContext())) {}
+      : SE(se), Builder(*se.getContext(),
+                        TargetFolder(se.TD, se.getContext())) {}
 
     /// clear - Erase the contents of the InsertedExpressions map so that users
     /// trying to expand the same expression into multiple BasicBlocks or
index 0f4e471e05a019e74ce81e6e36a421788290d1ee..5069ead3914408cf5a8346507e74b5806a52b3ec 100644 (file)
@@ -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,20 @@ template <bool preserveNames=true, typename T = ConstantFolder> class IRBuilder{
   BasicBlock *BB;
   BasicBlock::iterator InsertPt;
   T Folder;
+  LLVMContext &Context;
 public:
-  IRBuilder(const T& F = T()) : Folder(F) { ClearInsertionPoint(); }
+  IRBuilder(LLVMContext &C, const T& F = T()) :
+    Folder(F), Context(C) { ClearInsertionPoint(); }
+  
   explicit IRBuilder(BasicBlock *TheBB, const T& F = T())
-    : Folder(F) { SetInsertPoint(TheBB); }
+      : Folder(F), Context(*TheBB->getParent()->getContext()) {
+    SetInsertPoint(TheBB);
+  }
+  
   IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T())
-    : Folder(F) { SetInsertPoint(TheBB, IP); }
+      : Folder(F), Context(*TheBB->getParent()->getContext()) {
+    SetInsertPoint(TheBB, IP);
+  }
 
   /// getFolder - Get the constant folder being used.
   const T& getFolder() { return Folder; }
@@ -125,7 +134,7 @@ public:
   ///
   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 +358,7 @@ public:
     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 +368,8 @@ public:
   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 +378,7 @@ public:
     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 +388,8 @@ public:
   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,7 +401,7 @@ public:
     return CreateConstGEP2_32(Ptr, 0, Idx, Name);
   }
   Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
-    Constant *StrConstant = ConstantArray::get(Str, true);
+    Constant *StrConstant = Context.getConstantArray(Str, true);
     GlobalVariable *gv = new GlobalVariable(*BB->getParent()->getParent(),
                                             StrConstant->getType(),
                                             true,
@@ -406,7 +415,7 @@ public:
   }
   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);
   }
@@ -683,13 +692,13 @@ public:
 
   /// 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);
   }
 
@@ -704,7 +713,7 @@ public:
     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);
   }
 };
index 052334a05ba59dd1124fd2d550982fd9cb85fbf5..64a5c9e699e46f785b14de578afd8daee1a23650 100644 (file)
@@ -301,7 +301,7 @@ static Value *LowerCTLZ(Value *V, Instruction *IP) {
 /// the bits are returned in inverse order. 
 /// @brief Lowering of llvm.part.select intrinsic.
 static Instruction *LowerPartSelect(CallInst *CI) {
-  IRBuilder<> Builder;
+  IRBuilder<> Builder(*CI->getParent()->getContext());
 
   // Make sure we're dealing with a part select intrinsic here
   Function *F = CI->getCalledFunction();
@@ -472,7 +472,7 @@ static Instruction *LowerPartSelect(CallInst *CI) {
 /// greater than %High then the inverse set of bits are replaced.
 /// @brief Lowering of llvm.bit.part.set intrinsic.
 static Instruction *LowerPartSet(CallInst *CI) {
-  IRBuilder<> Builder;
+  IRBuilder<> Builder(*CI->getParent()->getContext());
 
   // Make sure we're dealing with a part select intrinsic here
   Function *F = CI->getCalledFunction();
index 10d0109d57c66277d22dd466841eebf0b0283a36..6ba1243ce19aca95c5c6e57eac5a2532c58b1e06 100644 (file)
@@ -93,7 +93,7 @@ namespace {
 
   public:
     EscapeEnumerator(Function &F, const char *N = "cleanup")
-      : F(F), CleanupBBName(N), State(0) {}
+      : F(F), CleanupBBName(N), State(0), Builder(*F.getContext()) {}
 
     IRBuilder<> *Next() {
       switch (State) {
index 80ef96a9025994b40dc26c70295613ac6227b618..a2f9a82f334e2a877db86b61fb2afc69a2b747e5 100644 (file)
@@ -1639,7 +1639,7 @@ bool SimplifyLibCalls::runOnFunction(Function &F) {
   
   const TargetData &TD = getAnalysis<TargetData>();
   
-  IRBuilder<> Builder;
+  IRBuilder<> Builder(*Context);
 
   bool Changed = false;
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
index 54773c3ee738aeefc2910ae425f707d0bc4989e7..0e3d7e87b0ae12e9b9c67b3073f227bea6e27fbf 100644 (file)
@@ -1132,7 +1132,7 @@ LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
 /*===-- Instruction builders ----------------------------------------------===*/
 
 LLVMBuilderRef LLVMCreateBuilder(void) {
-  return wrap(new IRBuilder<>());
+  return wrap(new IRBuilder<>(getGlobalContext()));
 }
 
 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,