#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
-#include "llvm/IR/Statepoint.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/ValueHandle.h"
MDNode *DefaultFPMathTag;
FastMathFlags FMF;
+ ArrayRef<OperandBundleDef> DefaultOperandBundles;
+
public:
- IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr)
- : Context(context), DefaultFPMathTag(FPMathTag), FMF() {
+ IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : Context(context), DefaultFPMathTag(FPMathTag), FMF(),
+ DefaultOperandBundles(OpBundles) {
ClearInsertionPoint();
}
/// inserted into a block.
void ClearInsertionPoint() {
BB = nullptr;
- InsertPt = nullptr;
+ InsertPt.reset(nullptr);
}
BasicBlock *GetInsertBlock() const { return BB; }
/// the specified instruction.
void SetInsertPoint(Instruction *I) {
BB = I->getParent();
- InsertPt = I;
- assert(I != BB->end() && "Can't read debug loc from end()");
+ InsertPt = I->getIterator();
+ assert(InsertPt != BB->end() && "Can't read debug loc from end()");
SetCurrentDebugLocation(I->getDebugLoc());
}
void clearFastMathFlags() { FMF.clear(); }
/// \brief Set the floating point math metadata to be used.
- void SetDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
+ void setDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
/// \brief Set the fast-math flags to be used with generated fp-math operators
- void SetFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
+ void setFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
//===--------------------------------------------------------------------===//
// RAII helpers.
/// \brief Create a call to the experimental.gc.statepoint intrinsic to
/// start a new statepoint sequence.
CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
- Value *ActualCallee, StatepointFlags Flags,
+ Value *ActualCallee, uint32_t Flags,
ArrayRef<Use> CallArgs,
ArrayRef<Use> TransitionArgs,
ArrayRef<Use> DeoptArgs,
/// start a new statepoint sequence.
InvokeInst *CreateGCStatepointInvoke(
uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
- BasicBlock *NormalDest, BasicBlock *UnwindDest, StatepointFlags Flags,
+ BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs,
ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs,
const Twine &Name = "");
public:
IRBuilder(LLVMContext &C, const T &F, Inserter I = Inserter(),
- MDNode *FPMathTag = nullptr)
- : IRBuilderBase(C, FPMathTag), Inserter(std::move(I)), Folder(F) {}
-
- explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr)
- : IRBuilderBase(C, FPMathTag), Folder() {
- }
-
- explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr)
- : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
+ MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : IRBuilderBase(C, FPMathTag, OpBundles), Inserter(std::move(I)),
+ Folder(F) {}
+
+ explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : IRBuilderBase(C, FPMathTag, OpBundles), Folder() {}
+
+ explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
SetInsertPoint(TheBB);
}
- explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr)
- : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
+ explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() {
SetInsertPoint(TheBB);
}
- explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr)
- : IRBuilderBase(IP->getContext(), FPMathTag), Folder() {
+ explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles), Folder() {
SetInsertPoint(IP);
}
- IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F,
- MDNode *FPMathTag = nullptr)
- : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
+ IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F,
+ MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
SetInsertPoint(TheBB, IP);
}
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,
- MDNode *FPMathTag = nullptr)
- : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
+ MDNode *FPMathTag = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = None)
+ : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() {
SetInsertPoint(TheBB, IP);
}
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
Name);
}
+ InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
+ BasicBlock *UnwindDest, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> OpBundles,
+ const Twine &Name = "") {
+ return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
+ OpBundles), Name);
+ }
ResumeInst *CreateResume(Value *Exn) {
return Insert(ResumeInst::Create(Exn));
return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
}
- CleanupEndPadInst *CreateCleanupEndPad(CleanupPadInst *CleanupPad,
- BasicBlock *UnwindBB = nullptr) {
- return Insert(CleanupEndPadInst::Create(CleanupPad, UnwindBB));
- }
-
- CatchPadInst *CreateCatchPad(BasicBlock *NormalDest, BasicBlock *UnwindDest,
- ArrayRef<Value *> Args, const Twine &Name = "") {
- return Insert(CatchPadInst::Create(NormalDest, UnwindDest, Args), Name);
- }
-
- CatchEndPadInst *CreateCatchEndPad(BasicBlock *UnwindBB = nullptr) {
- return Insert(CatchEndPadInst::Create(Context, UnwindBB));
+ CatchSwitchInst *CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB,
+ unsigned NumHandlers,
+ const Twine &Name = "") {
+ return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
+ Name);
}
- TerminatePadInst *CreateTerminatePad(BasicBlock *UnwindBB = nullptr,
- ArrayRef<Value *> Args = {},
- const Twine &Name = "") {
- return Insert(TerminatePadInst::Create(Context, UnwindBB, Args), Name);
+ CatchPadInst *CreateCatchPad(Value *ParentPad, ArrayRef<Value *> Args,
+ const Twine &Name = "") {
+ return Insert(CatchPadInst::Create(ParentPad, Args), Name);
}
- CleanupPadInst *CreateCleanupPad(ArrayRef<Value *> Args,
+ CleanupPadInst *CreateCleanupPad(Value *ParentPad,
+ ArrayRef<Value *> Args = None,
const Twine &Name = "") {
- return Insert(CleanupPadInst::Create(Context, Args), Name);
+ return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
}
CatchReturnInst *CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB) {
}
CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args = None,
- const Twine &Name = "") {
- return Insert(CallInst::Create(Callee, Args), Name);
+ const Twine &Name = "", MDNode *FPMathTag = nullptr) {
+ PointerType *PTy = cast<PointerType>(Callee->getType());
+ FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
+ return CreateCall(FTy, Callee, Args, Name, FPMathTag);
}
CallInst *CreateCall(llvm::FunctionType *FTy, Value *Callee,
- ArrayRef<Value *> Args, const Twine &Name = "") {
- return Insert(CallInst::Create(FTy, Callee, Args), Name);
+ ArrayRef<Value *> Args, const Twine &Name = "",
+ MDNode *FPMathTag = nullptr) {
+ CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
+ if (isa<FPMathOperator>(CI))
+ CI = cast<CallInst>(AddFPMathAttributes(CI, FPMathTag, FMF));
+ return Insert(CI, Name);
+ }
+
+ CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> OpBundles,
+ const Twine &Name = "", MDNode *FPMathTag = nullptr) {
+ CallInst *CI = CallInst::Create(Callee, Args, OpBundles);
+ if (isa<FPMathOperator>(CI))
+ CI = cast<CallInst>(AddFPMathAttributes(CI, FPMathTag, FMF));
+ return Insert(CI, Name);
}
CallInst *CreateCall(Function *Callee, ArrayRef<Value *> Args,
- const Twine &Name = "") {
- return CreateCall(Callee->getFunctionType(), Callee, Args, Name);
+ const Twine &Name = "", MDNode *FPMathTag = nullptr) {
+ return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
}
Value *CreateSelect(Value *C, Value *True, Value *False,