Value *ErrorV(const char *Str) { Error(Str); return 0; }
static Module *TheModule;
-static IRBuilder<> Builder;
+static IRBuilder<> Builder(getGlobalContext());
static std::map<std::string, Value*> NamedValues;
</pre>
</div>
// 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"
//===----------------------------------------------------------------------===//
int main() {
- TheModule = new Module("my cool jit");
+ TheModule = new Module("my cool jit", getGlobalContext());
// Install standard binary operators.
// 1 is lowest precedence.
<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"
//===----------------------------------------------------------------------===//
static Module *TheModule;
-static IRBuilder<> Builder;
+static IRBuilder<> Builder(getGlobalContext());
static std::map<std::string, Value*> NamedValues;
static FunctionPassManager *TheFPM;
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);
<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"
//===----------------------------------------------------------------------===//
static Module *TheModule;
-static IRBuilder<> Builder;
+static IRBuilder<> Builder(getGlobalContext());
static std::map<std::string, Value*> NamedValues;
static FunctionPassManager *TheFPM;
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);
<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"
//===----------------------------------------------------------------------===//
static Module *TheModule;
-static IRBuilder<> Builder;
+static IRBuilder<> Builder(getGlobalContext());
static std::map<std::string, Value*> NamedValues;
static FunctionPassManager *TheFPM;
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);
<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"
//===----------------------------------------------------------------------===//
static Module *TheModule;
-static IRBuilder<> Builder;
+static IRBuilder<> Builder(getGlobalContext());
static std::map<std::string, AllocaInst*> NamedValues;
static FunctionPassManager *TheFPM;
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);
//===----------------------------------------------------------------------===//
static Module *TheModule;
-static IRBuilder<> Builder;
+static IRBuilder<> Builder(getGlobalContext());
static std::map<std::string, AllocaInst*> NamedValues;
static FunctionPassManager *TheFPM;
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
#include "llvm/GlobalAlias.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/ConstantFolder.h"
namespace llvm {
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; }
///
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));
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);
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))
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);
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))
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,
}
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);
}
/// 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);
}
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);
}
};
/// 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();
/// 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();
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) {
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) {
/*===-- Instruction builders ----------------------------------------------===*/
LLVMBuilderRef LLVMCreateBuilder(void) {
- return wrap(new IRBuilder<>());
+ return wrap(new IRBuilder<>(getGlobalContext()));
}
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,