llvm.org GIT mirror llvm / d1fbd14
Push LLVMContext _back_ through IRBuilder. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75040 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
12 changed file(s) with 47 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
114114 Value *ErrorV(const char *Str) { Error(Str); return 0; }
115115
116116 static Module *TheModule;
117 static IRBuilder<> Builder;
117 static IRBuilder<> Builder(getGlobalContext());
118118 static std::map<std::string, Value*> NamedValues;
119119
120120
681681 // See example below.
682682
683683 #include "llvm/DerivedTypes.h"
684 #include "llvm/LLVMContext.h"
684685 #include "llvm/Module.h"
685686 #include "llvm/Analysis/Verifier.h"
686687 #include "llvm/Support/IRBuilder.h"
12151216 //===----------------------------------------------------------------------===//
12161217
12171218 int main() {
1218 TheModule = new Module("my cool jit");
1219 TheModule = new Module("my cool jit", getGlobalContext());
12191220
12201221 // Install standard binary operators.
12211222 // 1 is lowest precedence.
511511

                  
                
512512 #include "llvm/DerivedTypes.h"
513513 #include "llvm/ExecutionEngine/ExecutionEngine.h"
514 #include "llvm/LLVMContext.h"
514515 #include "llvm/Module.h"
515516 #include "llvm/ModuleProvider.h"
516517 #include "llvm/PassManager.h"
860861 //===----------------------------------------------------------------------===//
861862
862863 static Module *TheModule;
863 static IRBuilder<> Builder;
864 static IRBuilder<> Builder(getGlobalContext());
864865 static std::map<std::string, Value*> NamedValues;
865866 static FunctionPassManager *TheFPM;
866867
10731074 getNextToken();
10741075
10751076 // Make the module, which holds all the code.
1076 TheModule = new Module("my cool jit");
1077 TheModule = new Module("my cool jit", getGlobalContext());
10771078
10781079 // Create the JIT.
10791080 TheExecutionEngine = ExecutionEngine::create(TheModule);
900900

                  
                
901901 #include "llvm/DerivedTypes.h"
902902 #include "llvm/ExecutionEngine/ExecutionEngine.h"
903 #include "llvm/LLVMContext.h"
903904 #include "llvm/Module.h"
904905 #include "llvm/ModuleProvider.h"
905906 #include "llvm/PassManager.h"
13511352 //===----------------------------------------------------------------------===//
13521353
13531354 static Module *TheModule;
1354 static IRBuilder<> Builder;
1355 static IRBuilder<> Builder(getGlobalContext());
13551356 static std::map<std::string, Value*> NamedValues;
13561357 static FunctionPassManager *TheFPM;
13571358
17071708 getNextToken();
17081709
17091710 // Make the module, which holds all the code.
1710 TheModule = new Module("my cool jit");
1711 TheModule = new Module("my cool jit", getGlobalContext());
17111712
17121713 // Create the JIT.
17131714 TheExecutionEngine = ExecutionEngine::create(TheModule);
820820

                  
                
821821 #include "llvm/DerivedTypes.h"
822822 #include "llvm/ExecutionEngine/ExecutionEngine.h"
823 #include "llvm/LLVMContext.h"
823824 #include "llvm/Module.h"
824825 #include "llvm/ModuleProvider.h"
825826 #include "llvm/PassManager.h"
13561357 //===----------------------------------------------------------------------===//
13571358
13581359 static Module *TheModule;
1359 static IRBuilder<> Builder;
1360 static IRBuilder<> Builder(getGlobalContext());
13601361 static std::map<std::string, Value*> NamedValues;
13611362 static FunctionPassManager *TheFPM;
13621363
17461747 getNextToken();
17471748
17481749 // Make the module, which holds all the code.
1749 TheModule = new Module("my cool jit");
1750 TheModule = new Module("my cool jit", getGlobalContext());
17501751
17511752 // Create the JIT.
17521753 TheExecutionEngine = ExecutionEngine::create(TheModule);
10021002

                  
                
10031003 #include "llvm/DerivedTypes.h"
10041004 #include "llvm/ExecutionEngine/ExecutionEngine.h"
1005 #include "llvm/LLVMContext.h"
10051006 #include "llvm/Module.h"
10061007 #include "llvm/ModuleProvider.h"
10071008 #include "llvm/PassManager.h"
16041605 //===----------------------------------------------------------------------===//
16051606
16061607 static Module *TheModule;
1607 static IRBuilder<> Builder;
1608 static IRBuilder<> Builder(getGlobalContext());
16081609 static std::map<std::string, AllocaInst*> NamedValues;
16091610 static FunctionPassManager *TheFPM;
16101611
20982099 getNextToken();
20992100
21002101 // Make the module, which holds all the code.
2101 TheModule = new Module("my cool jit");
2102 TheModule = new Module("my cool jit", getGlobalContext());
21022103
21032104 // Create the JIT.
21042105 TheExecutionEngine = ExecutionEngine::create(TheModule);
603603 //===----------------------------------------------------------------------===//
604604
605605 static Module *TheModule;
606 static IRBuilder<> Builder;
606 static IRBuilder<> Builder(getGlobalContext());
607607 static std::map NamedValues;
608608 static FunctionPassManager *TheFPM;
609609
3636 friend struct SCEVVisitor;
3737 public:
3838 explicit SCEVExpander(ScalarEvolution &se)
39 : SE(se), Builder(TargetFolder(se.TD, se.getContext())) {}
39 : SE(se), Builder(*se.getContext(),
40 TargetFolder(se.TD, se.getContext())) {}
4041
4142 /// clear - Erase the contents of the InsertedExpressions map so that users
4243 /// trying to expand the same expression into multiple BasicBlocks or
1919 #include "llvm/GlobalAlias.h"
2020 #include "llvm/GlobalVariable.h"
2121 #include "llvm/Function.h"
22 #include "llvm/LLVMContext.h"
2223 #include "llvm/Support/ConstantFolder.h"
2324
2425 namespace llvm {
4142 BasicBlock *BB;
4243 BasicBlock::iterator InsertPt;
4344 T Folder;
45 LLVMContext &Context;
4446 public:
45 IRBuilder(const T& F = T()) : Folder(F) { ClearInsertionPoint(); }
47 IRBuilder(LLVMContext &C, const T& F = T()) :
48 Folder(F), Context(C) { ClearInsertionPoint(); }
49
4650 explicit IRBuilder(BasicBlock *TheBB, const T& F = T())
47 : Folder(F) { SetInsertPoint(TheBB); }
51 : Folder(F), Context(*TheBB->getParent()->getContext()) {
52 SetInsertPoint(TheBB);
53 }
54
4855 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T())
49 : Folder(F) { SetInsertPoint(TheBB, IP); }
56 : Folder(F), Context(*TheBB->getParent()->getContext()) {
57 SetInsertPoint(TheBB, IP);
58 }
5059
5160 /// getFolder - Get the constant folder being used.
5261 const T& getFolder() { return Folder; }
124133 ///
125134 ReturnInst *CreateAggregateRet(Value * const* retVals, unsigned N) {
126135 const Type *RetType = BB->getParent()->getReturnType();
127 Value *V = UndefValue::get(RetType);
136 Value *V = Context.getUndef(RetType);
128137 for (unsigned i = 0; i != N; ++i)
129138 V = CreateInsertValue(V, retVals[i], i, "mrv");
130139 return Insert(ReturnInst::Create(V));
348357 return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
349358 }
350359 Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
351 Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
360 Value *Idx = Context.getConstantInt(Type::Int32Ty, Idx0);
352361
353362 if (Constant *PC = dyn_cast(Ptr))
354363 return Folder.CreateGetElementPtr(PC, &Idx, 1);
358367 Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
359368 const char *Name = "") {
360369 Value *Idxs[] = {
361 ConstantInt::get(Type::Int32Ty, Idx0),
362 ConstantInt::get(Type::Int32Ty, Idx1)
370 Context.getConstantInt(Type::Int32Ty, Idx0),
371 Context.getConstantInt(Type::Int32Ty, Idx1)
363372 };
364373
365374 if (Constant *PC = dyn_cast(Ptr))
368377 return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
369378 }
370379 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
371 Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
380 Value *Idx = Context.getConstantInt(Type::Int64Ty, Idx0);
372381
373382 if (Constant *PC = dyn_cast(Ptr))
374383 return Folder.CreateGetElementPtr(PC, &Idx, 1);
378387 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
379388 const char *Name = "") {
380389 Value *Idxs[] = {
381 ConstantInt::get(Type::Int64Ty, Idx0),
382 ConstantInt::get(Type::Int64Ty, Idx1)
390 Context.getConstantInt(Type::Int64Ty, Idx0),
391 Context.getConstantInt(Type::Int64Ty, Idx1)
383392 };
384393
385394 if (Constant *PC = dyn_cast(Ptr))
391400 return CreateConstGEP2_32(Ptr, 0, Idx, Name);
392401 }
393402 Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
394 Constant *StrConstant = ConstantArray::get(Str, true);
403 Constant *StrConstant = Context.getConstantArray(Str, true);
395404 GlobalVariable *gv = new GlobalVariable(*BB->getParent()->getParent(),
396405 StrConstant->getType(),
397406 true,
405414 }
406415 Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
407416 Value *gv = CreateGlobalString(Str, Name);
408 Value *zero = ConstantInt::get(Type::Int32Ty, 0);
417 Value *zero = Context.getConstantInt(Type::Int32Ty, 0);
409418 Value *Args[] = { zero, zero };
410419 return CreateGEP(gv, Args, Args+2, Name);
411420 }
682691
683692 /// CreateIsNull - Return an i1 value testing if \arg Arg is null.
684693 Value *CreateIsNull(Value *Arg, const char *Name = "") {
685 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
694 return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()),
686695 Name);
687696 }
688697
689698 /// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
690699 Value *CreateIsNotNull(Value *Arg, const char *Name = "") {
691 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
700 return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()),
692701 Name);
693702 }
694703
703712 Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty);
704713 Value *Difference = CreateSub(LHS_int, RHS_int);
705714 return CreateSDiv(Difference,
706 ConstantExpr::getSizeOf(ArgType->getElementType()),
715 Context.getConstantExprSizeOf(ArgType->getElementType()),
707716 Name);
708717 }
709718 };
300300 /// the bits are returned in inverse order.
301301 /// @brief Lowering of llvm.part.select intrinsic.
302302 static Instruction *LowerPartSelect(CallInst *CI) {
303 IRBuilder<> Builder;
303 IRBuilder<> Builder(*CI->getParent()->getContext());
304304
305305 // Make sure we're dealing with a part select intrinsic here
306306 Function *F = CI->getCalledFunction();
471471 /// greater than %High then the inverse set of bits are replaced.
472472 /// @brief Lowering of llvm.bit.part.set intrinsic.
473473 static Instruction *LowerPartSet(CallInst *CI) {
474 IRBuilder<> Builder;
474 IRBuilder<> Builder(*CI->getParent()->getContext());
475475
476476 // Make sure we're dealing with a part select intrinsic here
477477 Function *F = CI->getCalledFunction();
9292
9393 public:
9494 EscapeEnumerator(Function &F, const char *N = "cleanup")
95 : F(F), CleanupBBName(N), State(0) {}
95 : F(F), CleanupBBName(N), State(0), Builder(*F.getContext()) {}
9696
9797 IRBuilder<> *Next() {
9898 switch (State) {
16381638
16391639 const TargetData &TD = getAnalysis();
16401640
1641 IRBuilder<> Builder;
1641 IRBuilder<> Builder(*Context);
16421642
16431643 bool Changed = false;
16441644 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
11311131 /*===-- Instruction builders ----------------------------------------------===*/
11321132
11331133 LLVMBuilderRef LLVMCreateBuilder(void) {
1134 return wrap(new IRBuilder<>());
1134 return wrap(new IRBuilder<>(getGlobalContext()));
11351135 }
11361136
11371137 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,