diff options
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/Instructions.h | 64 | ||||
-rw-r--r-- | include/llvm/Support/LLVMBuilder.h | 10 |
2 files changed, 63 insertions, 11 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 6773783..2913341 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -1544,13 +1544,65 @@ class InvokeInst : public TerminatorInst { InvokeInst(const InvokeInst &BI); void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, Value* const *Args, unsigned NumArgs); + + template<typename InputIterator> + void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, + InputIterator ArgBegin, InputIterator ArgEnd, + const std::string &Name, + // This argument ensures that we have an iterator we can + // do arithmetic on in constant time + std::random_access_iterator_tag) { + typename std::iterator_traits<InputIterator>::difference_type NumArgs = + std::distance(ArgBegin, ArgEnd); + + if (NumArgs > 0) { + // This requires that the iterator points to contiguous memory. + init(Func, IfNormal, IfException, &*ArgBegin, NumArgs); + } + else { + init(Func, IfNormal, IfException, 0, NumArgs); + } + + setName(Name); + } + public: - InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, - Value* const* Args, unsigned NumArgs, const std::string &Name = "", - Instruction *InsertBefore = 0); - InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, - Value* const* Args, unsigned NumArgs, const std::string &Name, - BasicBlock *InsertAtEnd); + /// Construct an InvokeInst given a range of arguments. + /// InputIterator must be a random-access iterator pointing to + /// contiguous storage (e.g. a std::vector<>::iterator). Checks are + /// made for random-accessness but not for contiguous storage as + /// that would incur runtime overhead. + /// + /// @brief Construct an InvokeInst from a range of arguments + template<typename InputIterator> + InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, + InputIterator ArgBegin, InputIterator ArgEnd, + const std::string &Name = "", Instruction *InsertBefore = 0) + : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) + ->getElementType())->getReturnType(), + Instruction::Invoke, 0, 0, InsertBefore) { + init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, + typename std::iterator_traits<InputIterator>::iterator_category()); + } + + /// Construct an InvokeInst given a range of arguments. + /// InputIterator must be a random-access iterator pointing to + /// contiguous storage (e.g. a std::vector<>::iterator). Checks are + /// made for random-accessness but not for contiguous storage as + /// that would incur runtime overhead. + /// + /// @brief Construct an InvokeInst from a range of arguments + template<typename InputIterator> + InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, + InputIterator ArgBegin, InputIterator ArgEnd, + const std::string &Name, BasicBlock *InsertAtEnd) + : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) + ->getElementType())->getReturnType(), + Instruction::Invoke, 0, 0, InsertAtEnd) { + init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, + typename std::iterator_traits<InputIterator>::iterator_category()); + } + ~InvokeInst(); virtual InvokeInst *clone() const; diff --git a/include/llvm/Support/LLVMBuilder.h b/include/llvm/Support/LLVMBuilder.h index 0323f29..ce403f1 100644 --- a/include/llvm/Support/LLVMBuilder.h +++ b/include/llvm/Support/LLVMBuilder.h @@ -115,12 +115,12 @@ public: } /// CreateInvoke - Create an invoke instruction. + template<typename InputIterator> InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest, - BasicBlock *UnwindDest, - Value *const* Args, unsigned NumArgs, - const char *Name = "") { - return Insert(new InvokeInst(Callee, NormalDest, UnwindDest, Args, NumArgs, - Name)); + BasicBlock *UnwindDest, InputIterator ArgBegin, + InputIterator ArgEnd, const char *Name = "") { + return(Insert(new InvokeInst(Callee, NormalDest, UnwindDest, + ArgBegin, ArgEnd, Name))); } UnwindInst *CreateUnwind() { |