diff options
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/IR/Attributes.h | 39 | ||||
-rw-r--r-- | llvm/include/llvm/IR/IRBuilder.h | 288 | ||||
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 87 | ||||
-rw-r--r-- | llvm/lib/IR/IRBuilder.cpp | 41 |
4 files changed, 288 insertions, 167 deletions
diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index a05a0107304..660fc589ddb 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -6,11 +6,11 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -/// +// /// \file /// \brief This file contains the simple types necessary to represent the /// attributes associated with functions and their calls. -/// +// //===----------------------------------------------------------------------===// #ifndef LLVM_IR_ATTRIBUTES_H @@ -35,7 +35,6 @@ namespace llvm { class AttrBuilder; class AttributeImpl; class AttributeListImpl; -class AttributeList; class AttributeSetNode; template<typename T> struct DenseMapInfo; class Function; @@ -203,6 +202,9 @@ inline Attribute unwrap(LLVMAttributeRef Attr) { /// copy. Adding and removing enum attributes is intended to be fast, but adding /// and removing string or integer attributes involves a FoldingSet lookup. class AttributeSet { + friend AttributeListImpl; + template <typename Ty> friend struct DenseMapInfo; + // TODO: Extract AvailableAttrs from AttributeSetNode and store them here. // This will allow an efficient implementation of addAttribute and // removeAttribute for enum attrs. @@ -210,9 +212,6 @@ class AttributeSet { /// Private implementation pointer. AttributeSetNode *SetNode = nullptr; - friend AttributeListImpl; - template <typename Ty> friend struct DenseMapInfo; - private: explicit AttributeSet(AttributeSetNode *ASN) : SetNode(ASN) {} @@ -292,14 +291,14 @@ public: /// \class /// \brief Provide DenseMapInfo for AttributeSet. template <> struct DenseMapInfo<AttributeSet> { - static inline AttributeSet getEmptyKey() { - uintptr_t Val = static_cast<uintptr_t>(-1); + static AttributeSet getEmptyKey() { + auto Val = static_cast<uintptr_t>(-1); Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable; return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val)); } - static inline AttributeSet getTombstoneKey() { - uintptr_t Val = static_cast<uintptr_t>(-2); + static AttributeSet getTombstoneKey() { + auto Val = static_cast<uintptr_t>(-2); Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable; return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val)); } @@ -333,7 +332,6 @@ private: friend class AttributeListImpl; friend class AttributeSet; friend class AttributeSetNode; - template <typename Ty> friend struct DenseMapInfo; /// \brief The attributes that we are managing. This can be null to represent @@ -652,14 +650,14 @@ public: /// \class /// \brief Provide DenseMapInfo for AttributeList. template <> struct DenseMapInfo<AttributeList> { - static inline AttributeList getEmptyKey() { - uintptr_t Val = static_cast<uintptr_t>(-1); + static AttributeList getEmptyKey() { + auto Val = static_cast<uintptr_t>(-1); Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable; return AttributeList(reinterpret_cast<AttributeListImpl *>(Val)); } - static inline AttributeList getTombstoneKey() { - uintptr_t Val = static_cast<uintptr_t>(-2); + static AttributeList getTombstoneKey() { + auto Val = static_cast<uintptr_t>(-2); Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable; return AttributeList(reinterpret_cast<AttributeListImpl *>(Val)); } @@ -691,9 +689,11 @@ class AttrBuilder { public: AttrBuilder() = default; + AttrBuilder(const Attribute &A) { addAttribute(A); } + AttrBuilder(AttributeList AS, unsigned Idx); AttrBuilder(AttributeSet AS); @@ -800,18 +800,19 @@ public: using td_range = iterator_range<td_iterator>; using td_const_range = iterator_range<td_const_iterator>; - td_iterator td_begin() { return TargetDepAttrs.begin(); } - td_iterator td_end() { return TargetDepAttrs.end(); } + td_iterator td_begin() { return TargetDepAttrs.begin(); } + td_iterator td_end() { return TargetDepAttrs.end(); } td_const_iterator td_begin() const { return TargetDepAttrs.begin(); } - td_const_iterator td_end() const { return TargetDepAttrs.end(); } + td_const_iterator td_end() const { return TargetDepAttrs.end(); } td_range td_attrs() { return td_range(td_begin(), td_end()); } + td_const_range td_attrs() const { return td_const_range(td_begin(), td_end()); } - bool td_empty() const { return TargetDepAttrs.empty(); } + bool td_empty() const { return TargetDepAttrs.empty(); } bool operator==(const AttrBuilder &B); bool operator!=(const AttrBuilder &B) { diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index 12b9af4f026..e46544a4f9b 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -1,4 +1,4 @@ -//===---- llvm/IRBuilder.h - Builder for LLVM Instructions ------*- C++ -*-===// +//===- llvm/IRBuilder.h - Builder for LLVM Instructions ---------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -42,17 +42,16 @@ #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/Casting.h" -#include <algorithm> #include <cassert> #include <cstddef> #include <cstdint> #include <functional> +#include <utility> namespace llvm { class APInt; class MDNode; -class Module; class Use; /// \brief This provides the default implementation of the IRBuilder @@ -176,7 +175,7 @@ public: /// \brief Creates a new insertion point at the given location. InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint) - : Block(InsertBlock), Point(InsertPoint) {} + : Block(InsertBlock), Point(InsertPoint) {} /// \brief Returns true if this insert point is set. bool isSet() const { return (Block != nullptr); } @@ -576,16 +575,16 @@ public: ArrayRef<Value *> GCArgs, const Twine &Name = ""); - // \brief Conveninence function for the common case when CallArgs are filled - // in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be - // .get()'ed to get the Value pointer. + /// \brief Conveninence function for the common case when CallArgs are filled + /// in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be + /// .get()'ed to get the Value pointer. CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, ArrayRef<Use> CallArgs, ArrayRef<Value *> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name = ""); - /// brief Create an invoke to the experimental.gc.statepoint intrinsic to + /// \brief Create an invoke to the experimental.gc.statepoint intrinsic to /// start a new statepoint sequence. InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, @@ -594,7 +593,7 @@ public: ArrayRef<Value *> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name = ""); - /// brief Create an invoke to the experimental.gc.statepoint intrinsic to + /// \brief Create an invoke to the experimental.gc.statepoint intrinsic to /// start a new statepoint sequence. InvokeInst *CreateGCStatepointInvoke( uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, @@ -687,7 +686,7 @@ public: explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr, ArrayRef<OperandBundleDef> OpBundles = None) - : IRBuilderBase(C, FPMathTag, OpBundles), Folder() {} + : IRBuilderBase(C, FPMathTag, OpBundles) {} explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr, ArrayRef<OperandBundleDef> OpBundles = None) @@ -697,13 +696,13 @@ public: explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr, ArrayRef<OperandBundleDef> OpBundles = None) - : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() { + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles) { SetInsertPoint(TheBB); } explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr, ArrayRef<OperandBundleDef> OpBundles = None) - : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles), Folder() { + : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles) { SetInsertPoint(IP); } @@ -717,7 +716,7 @@ public: IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag = nullptr, ArrayRef<OperandBundleDef> OpBundles = None) - : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() { + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles) { SetInsertPoint(TheBB, IP); } @@ -908,91 +907,108 @@ private: public: Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name); return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW, HasNSW); } + Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateAdd(LHS, RHS, Name, false, true); } + Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateAdd(LHS, RHS, Name, true, false); } + Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name); return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW, HasNSW); } + Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateSub(LHS, RHS, Name, false, true); } + Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateSub(LHS, RHS, Name, true, false); } + Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name); return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW, HasNSW); } + Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateMul(LHS, RHS, Name, false, true); } + Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateMul(LHS, RHS, Name, true, false); } + Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "", bool isExact = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateUDiv(LC, RC, isExact), Name); if (!isExact) return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name); return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name); } + Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateUDiv(LHS, RHS, Name, true); } + Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "", bool isExact = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateSDiv(LC, RC, isExact), Name); if (!isExact) return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name); return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name); } + Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateSDiv(LHS, RHS, Name, true); } + Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") { if (Value *V = foldConstant(Instruction::URem, LHS, RHS, Name)) return V; return Insert(BinaryOperator::CreateURem(LHS, RHS), Name); } + Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") { if (Value *V = foldConstant(Instruction::SRem, LHS, RHS, Name)) return V; return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name); } + Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name); return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name, HasNUW, HasNSW); } + Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name, HasNUW, HasNSW); } + Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name, @@ -1001,17 +1017,19 @@ public: Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "", bool isExact = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateLShr(LC, RC, isExact), Name); if (!isExact) return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name); return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name); } + Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "", bool isExact = false) { return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); } + Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "", bool isExact = false) { return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); @@ -1019,50 +1037,56 @@ public: Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "", bool isExact = false) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateAShr(LC, RC, isExact), Name); if (!isExact) return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name); return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name); } + Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "", bool isExact = false) { return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); } + Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "", bool isExact = false) { return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); } Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") { - if (Constant *RC = dyn_cast<Constant>(RHS)) { + if (auto *RC = dyn_cast<Constant>(RHS)) { if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isMinusOne()) return LHS; // LHS & -1 -> LHS - if (Constant *LC = dyn_cast<Constant>(LHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) return Insert(Folder.CreateAnd(LC, RC), Name); } return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name); } + Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") { return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } + Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") { return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") { - if (Constant *RC = dyn_cast<Constant>(RHS)) { + if (auto *RC = dyn_cast<Constant>(RHS)) { if (RC->isNullValue()) return LHS; // LHS | 0 -> LHS - if (Constant *LC = dyn_cast<Constant>(LHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) return Insert(Folder.CreateOr(LC, RC), Name); } return Insert(BinaryOperator::CreateOr(LHS, RHS), Name); } + Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") { return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } + Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") { return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } @@ -1071,18 +1095,22 @@ public: if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) return V; return Insert(BinaryOperator::CreateXor(LHS, RHS), Name); } + Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") { return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } + Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") { return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } + Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "", MDNode *FPMD = nullptr) { if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMF); return Insert(I, Name); } + /// Copy fast-math-flags from an instruction rather than using the builder's /// default FMF. Value *CreateFAddFMF(Value *L, Value *R, Instruction *FMFSource, @@ -1092,12 +1120,14 @@ public: FMFSource->getFastMathFlags()); return Insert(I, Name); } + Value *CreateFSub(Value *L, Value *R, const Twine &Name = "", MDNode *FPMD = nullptr) { if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMF); return Insert(I, Name); } + /// Copy fast-math-flags from an instruction rather than using the builder's /// default FMF. Value *CreateFSubFMF(Value *L, Value *R, Instruction *FMFSource, @@ -1107,12 +1137,14 @@ public: FMFSource->getFastMathFlags()); return Insert(I, Name); } + Value *CreateFMul(Value *L, Value *R, const Twine &Name = "", MDNode *FPMD = nullptr) { if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMF); return Insert(I, Name); } + /// Copy fast-math-flags from an instruction rather than using the builder's /// default FMF. Value *CreateFMulFMF(Value *L, Value *R, Instruction *FMFSource, @@ -1122,12 +1154,14 @@ public: FMFSource->getFastMathFlags()); return Insert(I, Name); } + Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "", MDNode *FPMD = nullptr) { if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMF); return Insert(I, Name); } + /// Copy fast-math-flags from an instruction rather than using the builder's /// default FMF. Value *CreateFDivFMF(Value *L, Value *R, Instruction *FMFSource, @@ -1137,12 +1171,14 @@ public: FMFSource->getFastMathFlags()); return Insert(I, Name); } + Value *CreateFRem(Value *L, Value *R, const Twine &Name = "", MDNode *FPMD = nullptr) { if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMF); return Insert(I, Name); } + /// Copy fast-math-flags from an instruction rather than using the builder's /// default FMF. Value *CreateFRemFMF(Value *L, Value *R, Instruction *FMFSource, @@ -1165,28 +1201,32 @@ public: Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name); BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name); if (HasNUW) BO->setHasNoUnsignedWrap(); if (HasNSW) BO->setHasNoSignedWrap(); return BO; } + Value *CreateNSWNeg(Value *V, const Twine &Name = "") { return CreateNeg(V, Name, false, true); } + Value *CreateNUWNeg(Value *V, const Twine &Name = "") { return CreateNeg(V, Name, true, false); } + Value *CreateFNeg(Value *V, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateFNeg(VC), Name); return Insert(setFPAttrs(BinaryOperator::CreateFNeg(V), FPMathTag, FMF), Name); } + Value *CreateNot(Value *V, const Twine &Name = "") { - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateNot(VC), Name); return Insert(BinaryOperator::CreateNot(V), Name); } @@ -1205,26 +1245,32 @@ public: const DataLayout &DL = BB->getParent()->getParent()->getDataLayout(); return Insert(new AllocaInst(Ty, DL.getAllocaAddrSpace(), ArraySize), Name); } - // \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of - // converting the string to 'bool' for the isVolatile parameter. + + /// \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of + /// converting the string to 'bool' for the isVolatile parameter. LoadInst *CreateLoad(Value *Ptr, const char *Name) { return Insert(new LoadInst(Ptr), Name); } + LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") { return Insert(new LoadInst(Ptr), Name); } + LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") { return Insert(new LoadInst(Ty, Ptr), Name); } + LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") { return Insert(new LoadInst(Ptr, nullptr, isVolatile), Name); } + StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) { return Insert(new StoreInst(Val, Ptr, isVolatile)); } - // \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")' - // correctly, instead of converting the string to 'bool' for the isVolatile - // parameter. + + /// \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")' + /// correctly, instead of converting the string to 'bool' for the isVolatile + /// parameter. LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) { LoadInst *LI = CreateLoad(Ptr, Name); LI->setAlignment(Align); @@ -1242,17 +1288,20 @@ public: LI->setAlignment(Align); return LI; } + StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, bool isVolatile = false) { StoreInst *SI = CreateStore(Val, Ptr, isVolatile); SI->setAlignment(Align); return SI; } + FenceInst *CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID = SyncScope::System, const Twine &Name = "") { return Insert(new FenceInst(Context, Ordering, SSID), Name); } + AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, AtomicOrdering SuccessOrdering, @@ -1261,18 +1310,21 @@ public: return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering, FailureOrdering, SSID)); } + AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, AtomicOrdering Ordering, SyncScope::ID SSID = SyncScope::System) { return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SSID)); } + Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &Name = "") { return CreateGEP(nullptr, Ptr, IdxList, Name); } + Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList, const Twine &Name = "") { - if (Constant *PC = dyn_cast<Constant>(Ptr)) { + if (auto *PC = dyn_cast<Constant>(Ptr)) { // Every index must be constant. size_t i, e; for (i = 0, e = IdxList.size(); i != e; ++i) @@ -1283,13 +1335,15 @@ public: } return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name); } + Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &Name = "") { return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name); } + Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList, const Twine &Name = "") { - if (Constant *PC = dyn_cast<Constant>(Ptr)) { + if (auto *PC = dyn_cast<Constant>(Ptr)) { // Every index must be constant. size_t i, e; for (i = 0, e = IdxList.size(); i != e; ++i) @@ -1301,43 +1355,50 @@ public: } return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, IdxList), Name); } + Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") { return CreateGEP(nullptr, Ptr, Idx, Name); } + Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") { - if (Constant *PC = dyn_cast<Constant>(Ptr)) - if (Constant *IC = dyn_cast<Constant>(Idx)) + if (auto *PC = dyn_cast<Constant>(Ptr)) + if (auto *IC = dyn_cast<Constant>(Idx)) return Insert(Folder.CreateGetElementPtr(Ty, PC, IC), Name); return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name); } + Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") { - if (Constant *PC = dyn_cast<Constant>(Ptr)) - if (Constant *IC = dyn_cast<Constant>(Idx)) + if (auto *PC = dyn_cast<Constant>(Ptr)) + if (auto *IC = dyn_cast<Constant>(Idx)) return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IC), Name); return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name); } + Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") { return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name); } + Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name = "") { Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0); - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name); return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name); } + Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name = "") { Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0); - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name); return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name); } + Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name = "") { Value *Idxs[] = { @@ -1345,11 +1406,12 @@ public: ConstantInt::get(Type::getInt32Ty(Context), Idx1) }; - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name); return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name); } + Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name = "") { Value *Idxs[] = { @@ -1357,28 +1419,31 @@ public: ConstantInt::get(Type::getInt32Ty(Context), Idx1) }; - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name); return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name); } + Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") { Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0); - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idx), Name); return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name); } + Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") { Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0); - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idx), Name); return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name); } + Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "") { Value *Idxs[] = { @@ -1386,11 +1451,12 @@ public: ConstantInt::get(Type::getInt64Ty(Context), Idx1) }; - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idxs), Name); return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name); } + Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "") { Value *Idxs[] = { @@ -1398,12 +1464,13 @@ public: ConstantInt::get(Type::getInt64Ty(Context), Idx1) }; - if (Constant *PC = dyn_cast<Constant>(Ptr)) + if (auto *PC = dyn_cast<Constant>(Ptr)) return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idxs), Name); return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name); } + Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name = "") { return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name); @@ -1426,12 +1493,15 @@ public: Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::Trunc, V, DestTy, Name); } + Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::ZExt, V, DestTy, Name); } + Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::SExt, V, DestTy, Name); } + /// \brief Create a ZExt or Trunc from the integer value V to DestTy. Return /// the value untouched if the type of V is already DestTy. Value *CreateZExtOrTrunc(Value *V, Type *DestTy, @@ -1446,6 +1516,7 @@ public: return CreateTrunc(V, DestTy, Name); return V; } + /// \brief Create a SExt or Trunc from the integer value V to DestTy. Return /// the value untouched if the type of V is already DestTy. Value *CreateSExtOrTrunc(Value *V, Type *DestTy, @@ -1460,78 +1531,93 @@ public: return CreateTrunc(V, DestTy, Name); return V; } + Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){ return CreateCast(Instruction::FPToUI, V, DestTy, Name); } + Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){ return CreateCast(Instruction::FPToSI, V, DestTy, Name); } + Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){ return CreateCast(Instruction::UIToFP, V, DestTy, Name); } + Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){ return CreateCast(Instruction::SIToFP, V, DestTy, Name); } + Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::FPTrunc, V, DestTy, Name); } + Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::FPExt, V, DestTy, Name); } + Value *CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::PtrToInt, V, DestTy, Name); } + Value *CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::IntToPtr, V, DestTy, Name); } + Value *CreateBitCast(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::BitCast, V, DestTy, Name); } + Value *CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name); } + Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name); return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name); } + Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name); return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name); } + Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name); return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name); } + Value *CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateCast(Op, VC, DestTy), Name); return Insert(CastInst::Create(Op, V, DestTy), Name); } + Value *CreatePointerCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreatePointerCast(VC, DestTy), Name); return Insert(CastInst::CreatePointerCast(V, DestTy), Name); } @@ -1541,7 +1627,7 @@ public: if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) { + if (auto *VC = dyn_cast<Constant>(V)) { return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy), Name); } @@ -1554,7 +1640,7 @@ public: const Twine &Name = "") { if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name); return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name); } @@ -1571,11 +1657,10 @@ public: return CreateBitCast(V, DestTy, Name); } -public: Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; - if (Constant *VC = dyn_cast<Constant>(V)) + if (auto *VC = dyn_cast<Constant>(V)) return Insert(Folder.CreateFPCast(VC, DestTy), Name); return Insert(CastInst::CreateFPCast(V, DestTy), Name); } @@ -1592,30 +1677,39 @@ public: Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name); } + Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name); } + Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name); } + Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name); } + Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name); } + Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name); } + Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name); } + Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name); } + Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name); } + Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") { return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name); } @@ -1624,54 +1718,67 @@ public: MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag); } + Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag); @@ -1679,15 +1786,16 @@ public: Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name = "") { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateICmp(P, LC, RC), Name); return Insert(new ICmpInst(P, LHS, RHS), Name); } + Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - if (Constant *LC = dyn_cast<Constant>(LHS)) - if (Constant *RC = dyn_cast<Constant>(RHS)) + if (auto *LC = dyn_cast<Constant>(LHS)) + if (auto *RC = dyn_cast<Constant>(RHS)) return Insert(Folder.CreateFCmp(P, LC, RC), Name); return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name); } @@ -1703,8 +1811,8 @@ public: CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args = None, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - PointerType *PTy = cast<PointerType>(Callee->getType()); - FunctionType *FTy = cast<FunctionType>(PTy->getElementType()); + auto *PTy = cast<PointerType>(Callee->getType()); + auto *FTy = cast<FunctionType>(PTy->getElementType()); return CreateCall(FTy, Callee, Args, Name, FPMathTag); } @@ -1733,9 +1841,9 @@ public: Value *CreateSelect(Value *C, Value *True, Value *False, const Twine &Name = "", Instruction *MDFrom = nullptr) { - if (Constant *CC = dyn_cast<Constant>(C)) - if (Constant *TC = dyn_cast<Constant>(True)) - if (Constant *FC = dyn_cast<Constant>(False)) + if (auto *CC = dyn_cast<Constant>(C)) + if (auto *TC = dyn_cast<Constant>(True)) + if (auto *FC = dyn_cast<Constant>(False)) return Insert(Folder.CreateSelect(CC, TC, FC), Name); SelectInst *Sel = SelectInst::Create(C, True, False); @@ -1753,8 +1861,8 @@ public: Value *CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name = "") { - if (Constant *VC = dyn_cast<Constant>(Vec)) - if (Constant *IC = dyn_cast<Constant>(Idx)) + if (auto *VC = dyn_cast<Constant>(Vec)) + if (auto *IC = dyn_cast<Constant>(Idx)) return Insert(Folder.CreateExtractElement(VC, IC), Name); return Insert(ExtractElementInst::Create(Vec, Idx), Name); } @@ -1766,9 +1874,9 @@ public: Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name = "") { - if (Constant *VC = dyn_cast<Constant>(Vec)) - if (Constant *NC = dyn_cast<Constant>(NewElt)) - if (Constant *IC = dyn_cast<Constant>(Idx)) + if (auto *VC = dyn_cast<Constant>(Vec)) + if (auto *NC = dyn_cast<Constant>(NewElt)) + if (auto *IC = dyn_cast<Constant>(Idx)) return Insert(Folder.CreateInsertElement(VC, NC, IC), Name); return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name); } @@ -1780,9 +1888,9 @@ public: Value *CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name = "") { - if (Constant *V1C = dyn_cast<Constant>(V1)) - if (Constant *V2C = dyn_cast<Constant>(V2)) - if (Constant *MC = dyn_cast<Constant>(Mask)) + if (auto *V1C = dyn_cast<Constant>(V1)) + if (auto *V2C = dyn_cast<Constant>(V2)) + if (auto *MC = dyn_cast<Constant>(Mask)) return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name); return Insert(new ShuffleVectorInst(V1, V2, Mask), Name); } @@ -1796,7 +1904,7 @@ public: Value *CreateExtractValue(Value *Agg, ArrayRef<unsigned> Idxs, const Twine &Name = "") { - if (Constant *AggC = dyn_cast<Constant>(Agg)) + if (auto *AggC = dyn_cast<Constant>(Agg)) return Insert(Folder.CreateExtractValue(AggC, Idxs), Name); return Insert(ExtractValueInst::Create(Agg, Idxs), Name); } @@ -1804,8 +1912,8 @@ public: Value *CreateInsertValue(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs, const Twine &Name = "") { - if (Constant *AggC = dyn_cast<Constant>(Agg)) - if (Constant *ValC = dyn_cast<Constant>(Val)) + if (auto *AggC = dyn_cast<Constant>(Agg)) + if (auto *ValC = dyn_cast<Constant>(Val)) return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name); return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name); } @@ -1840,7 +1948,7 @@ public: Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") { assert(LHS->getType() == RHS->getType() && "Pointer subtraction operand types must match!"); - PointerType *ArgType = cast<PointerType>(LHS->getType()); + auto *ArgType = cast<PointerType>(LHS->getType()); Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context)); Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context)); Value *Difference = CreateSub(LHS_int, RHS_int); @@ -1897,7 +2005,7 @@ public: Value *CreateExtractInteger(const DataLayout &DL, Value *From, IntegerType *ExtractedTy, uint64_t Offset, const Twine &Name) { - IntegerType *IntTy = cast<IntegerType>(From->getType()); + auto *IntTy = cast<IntegerType>(From->getType()); assert(DL.getTypeStoreSize(ExtractedTy) + Offset <= DL.getTypeStoreSize(IntTy) && "Element extends past full value"); @@ -1929,7 +2037,7 @@ private: if (OffsetValue) { bool IsOffsetZero = false; - if (ConstantInt *CI = dyn_cast<ConstantInt>(OffsetValue)) + if (const auto *CI = dyn_cast<ConstantInt>(OffsetValue)) IsOffsetZero = CI->isZero(); if (!IsOffsetZero) { @@ -1958,14 +2066,14 @@ public: Value *OffsetValue = nullptr) { assert(isa<PointerType>(PtrValue->getType()) && "trying to create an alignment assumption on a non-pointer?"); - PointerType *PtrTy = cast<PointerType>(PtrValue->getType()); + auto *PtrTy = cast<PointerType>(PtrValue->getType()); Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace()); Value *Mask = ConstantInt::get(IntPtrTy, Alignment > 0 ? Alignment - 1 : 0); return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy, OffsetValue); } - // + /// \brief Create an assume intrinsic call that represents an alignment /// assumption on the provided pointer. /// @@ -1980,7 +2088,7 @@ public: Value *OffsetValue = nullptr) { assert(isa<PointerType>(PtrValue->getType()) && "trying to create an alignment assumption on a non-pointer?"); - PointerType *PtrTy = cast<PointerType>(PtrValue->getType()); + auto *PtrTy = cast<PointerType>(PtrValue->getType()); Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace()); if (Alignment->getType() != IntPtrTy) diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 1a060ba2768..bc0f5a27076 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -38,7 +38,6 @@ #include <cstddef> #include <cstdint> #include <limits> -#include <map> #include <string> #include <tuple> #include <utility> @@ -186,14 +185,14 @@ uint64_t Attribute::getValueAsInt() const { } StringRef Attribute::getKindAsString() const { - if (!pImpl) return StringRef(); + if (!pImpl) return {}; assert(isStringAttribute() && "Invalid attribute type to get the kind as a string!"); return pImpl->getKindAsString(); } StringRef Attribute::getValueAsString() const { - if (!pImpl) return StringRef(); + if (!pImpl) return {}; assert(isStringAttribute() && "Invalid attribute type to get the value as a string!"); return pImpl->getValueAsString(); @@ -241,7 +240,7 @@ std::pair<unsigned, Optional<unsigned>> Attribute::getAllocSizeArgs() const { } std::string Attribute::getAsString(bool InAttrGrp) const { - if (!pImpl) return ""; + if (!pImpl) return {}; if (hasAttribute(Attribute::SanitizeAddress)) return "sanitize_address"; @@ -538,7 +537,7 @@ AttributeSet AttributeSet::addAttributes(LLVMContext &C, return *this; AttrBuilder B(AS); - for (Attribute I : *this) + for (const auto I : *this) B.addAttribute(I); return get(C, B); @@ -637,7 +636,7 @@ AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs) // There's memory after the node where we can store the entries in. std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>()); - for (Attribute I : *this) { + for (const auto I : *this) { if (!I.isStringAttribute()) { AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum(); } @@ -656,7 +655,7 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C, SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end()); std::sort(SortedAttrs.begin(), SortedAttrs.end()); - for (Attribute Attr : SortedAttrs) + for (const auto Attr : SortedAttrs) Attr.Profile(ID); void *InsertPoint; @@ -719,7 +718,7 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C, const AttrBuilder &B) { } bool AttributeSetNode::hasAttribute(StringRef Kind) const { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Kind)) return true; return false; @@ -727,43 +726,43 @@ bool AttributeSetNode::hasAttribute(StringRef Kind) const { Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const { if (hasAttribute(Kind)) { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Kind)) return I; } - return Attribute(); + return {}; } Attribute AttributeSetNode::getAttribute(StringRef Kind) const { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Kind)) return I; - return Attribute(); + return {}; } unsigned AttributeSetNode::getAlignment() const { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Attribute::Alignment)) return I.getAlignment(); return 0; } unsigned AttributeSetNode::getStackAlignment() const { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Attribute::StackAlignment)) return I.getStackAlignment(); return 0; } uint64_t AttributeSetNode::getDereferenceableBytes() const { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Attribute::Dereferenceable)) return I.getDereferenceableBytes(); return 0; } uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Attribute::DereferenceableOrNull)) return I.getDereferenceableOrNullBytes(); return 0; @@ -771,7 +770,7 @@ uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { std::pair<unsigned, Optional<unsigned>> AttributeSetNode::getAllocSizeArgs() const { - for (Attribute I : *this) + for (const auto I : *this) if (I.hasAttribute(Attribute::AllocSize)) return I.getAllocSizeArgs(); return std::make_pair(0, 0); @@ -813,7 +812,7 @@ AttributeListImpl::AttributeListImpl(LLVMContext &C, "Too many attributes"); static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U, "function should be stored in slot 0"); - for (Attribute I : Sets[0]) { + for (const auto I : Sets[0]) { if (!I.isStringAttribute()) AvailableFunctionAttrs |= 1ULL << I.getKindAsEnum(); } @@ -870,17 +869,17 @@ AttributeList::get(LLVMContext &C, ArrayRef<std::pair<unsigned, Attribute>> Attrs) { // If there are no attributes then return a null AttributesList pointer. if (Attrs.empty()) - return AttributeList(); + return {}; assert(std::is_sorted(Attrs.begin(), Attrs.end(), [](const std::pair<unsigned, Attribute> &LHS, const std::pair<unsigned, Attribute> &RHS) { return LHS.first < RHS.first; }) && "Misordered Attributes list!"); - assert(none_of(Attrs, - [](const std::pair<unsigned, Attribute> &Pair) { - return Pair.second.hasAttribute(Attribute::None); - }) && + assert(llvm::none_of(Attrs, + [](const std::pair<unsigned, Attribute> &Pair) { + return Pair.second.hasAttribute(Attribute::None); + }) && "Pointless attribute!"); // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes @@ -906,7 +905,7 @@ AttributeList::get(LLVMContext &C, ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) { // If there are no attributes then return a null AttributesList pointer. if (Attrs.empty()) - return AttributeList(); + return {}; assert(std::is_sorted(Attrs.begin(), Attrs.end(), [](const std::pair<unsigned, AttributeSet> &LHS, @@ -914,16 +913,16 @@ AttributeList::get(LLVMContext &C, return LHS.first < RHS.first; }) && "Misordered Attributes list!"); - assert(none_of(Attrs, - [](const std::pair<unsigned, AttributeSet> &Pair) { - return !Pair.second.hasAttributes(); - }) && + assert(llvm::none_of(Attrs, + [](const std::pair<unsigned, AttributeSet> &Pair) { + return !Pair.second.hasAttributes(); + }) && "Pointless attribute!"); unsigned MaxIndex = Attrs.back().first; SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1); - for (auto Pair : Attrs) + for (const auto Pair : Attrs) AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second; return getImpl(C, AttrVec); @@ -953,7 +952,7 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs, // If all attribute sets were empty, we can use the empty attribute list. if (NumSets == 0) - return AttributeList(); + return {}; SmallVector<AttributeSet, 8> AttrSets; AttrSets.reserve(NumSets); @@ -973,7 +972,7 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs, AttributeList AttributeList::get(LLVMContext &C, unsigned Index, const AttrBuilder &B) { if (!B.hasAttributes()) - return AttributeList(); + return {}; Index = attrIdxToArrayIdx(Index); SmallVector<AttributeSet, 8> AttrSets(Index + 1); AttrSets[Index] = AttributeSet::get(C, B); @@ -983,7 +982,7 @@ AttributeList AttributeList::get(LLVMContext &C, unsigned Index, AttributeList AttributeList::get(LLVMContext &C, unsigned Index, ArrayRef<Attribute::AttrKind> Kinds) { SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; - for (Attribute::AttrKind K : Kinds) + for (const auto K : Kinds) Attrs.emplace_back(Index, Attribute::get(C, K)); return get(C, Attrs); } @@ -991,7 +990,7 @@ AttributeList AttributeList::get(LLVMContext &C, unsigned Index, AttributeList AttributeList::get(LLVMContext &C, unsigned Index, ArrayRef<StringRef> Kinds) { SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; - for (StringRef K : Kinds) + for (const auto K : Kinds) Attrs.emplace_back(Index, Attribute::get(C, K)); return get(C, Attrs); } @@ -999,22 +998,22 @@ AttributeList AttributeList::get(LLVMContext &C, unsigned Index, AttributeList AttributeList::get(LLVMContext &C, ArrayRef<AttributeList> Attrs) { if (Attrs.empty()) - return AttributeList(); + return {}; if (Attrs.size() == 1) return Attrs[0]; unsigned MaxSize = 0; - for (AttributeList List : Attrs) + for (const auto List : Attrs) MaxSize = std::max(MaxSize, List.getNumAttrSets()); // If every list was empty, there is no point in merging the lists. if (MaxSize == 0) - return AttributeList(); + return {}; SmallVector<AttributeSet, 8> NewAttrSets(MaxSize); for (unsigned I = 0; I < MaxSize; ++I) { AttrBuilder CurBuilder; - for (AttributeList List : Attrs) + for (const auto List : Attrs) CurBuilder.merge(List.getAttributes(I - 1)); NewAttrSets[I] = AttributeSet::get(C, CurBuilder); } @@ -1124,7 +1123,7 @@ AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const { if (!pImpl) - return AttributeList(); + return {}; Index = attrIdxToArrayIdx(Index); SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end()); @@ -1139,7 +1138,7 @@ AttributeList::removeAttributes(LLVMContext &C, unsigned Index, AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned WithoutIndex) const { if (!pImpl) - return AttributeList(); + return {}; WithoutIndex = attrIdxToArrayIdx(WithoutIndex); if (WithoutIndex >= getNumAttrSets()) return *this; @@ -1273,7 +1272,7 @@ std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const { AttributeSet AttributeList::getAttributes(unsigned Index) const { Index = attrIdxToArrayIdx(Index); if (!pImpl || Index >= getNumAttrSets()) - return AttributeSet(); + return {}; return pImpl->begin()[Index]; } @@ -1313,12 +1312,12 @@ LLVM_DUMP_METHOD void AttributeList::dump() const { // FIXME: Remove this ctor, use AttributeSet. AttrBuilder::AttrBuilder(AttributeList AL, unsigned Index) { AttributeSet AS = AL.getAttributes(Index); - for (const Attribute &A : AS) + for (const auto &A : AS) addAttribute(A); } AttrBuilder::AttrBuilder(AttributeSet AS) { - for (const Attribute &A : AS) + for (const auto &A : AS) addAttribute(A); } @@ -1389,7 +1388,7 @@ AttrBuilder &AttrBuilder::removeAttributes(AttributeList A, uint64_t Index) { } AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { - std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A); + auto I = TargetDepAttrs.find(A); if (I != TargetDepAttrs.end()) TargetDepAttrs.erase(I); return *this; @@ -1529,7 +1528,7 @@ bool AttrBuilder::hasAttributes() const { bool AttrBuilder::hasAttributes(AttributeList AL, uint64_t Index) const { AttributeSet AS = AL.getAttributes(Index); - for (Attribute Attr : AS) { + for (const auto Attr : AS) { if (Attr.isEnumAttribute() || Attr.isIntAttribute()) { if (contains(Attr.getKindAsEnum())) return true; diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp index c9eef2dfcb3..485b62139ac 100644 --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -1,4 +1,4 @@ -//===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===// +//===- IRBuilder.cpp - Builder for LLVM Instrs ----------------------------===// // // The LLVM Compiler Infrastructure // @@ -13,12 +13,27 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/IRBuilder.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/None.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Operator.h" #include "llvm/IR/Statepoint.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/MathExtras.h" +#include <cassert> +#include <cstdint> +#include <vector> + using namespace llvm; /// CreateGlobalString - Make a new global variable with an initializer that @@ -30,11 +45,10 @@ GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str, unsigned AddressSpace) { Constant *StrConstant = ConstantDataArray::getString(Context, Str); Module &M = *BB->getParent()->getParent(); - GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(), - true, GlobalValue::PrivateLinkage, - StrConstant, Name, nullptr, - GlobalVariable::NotThreadLocal, - AddressSpace); + auto *GV = new GlobalVariable(M, StrConstant->getType(), true, + GlobalValue::PrivateLinkage, StrConstant, Name, + nullptr, GlobalVariable::NotThreadLocal, + AddressSpace); GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); return GV; } @@ -45,7 +59,7 @@ Type *IRBuilderBase::getCurrentFunctionReturnType() const { } Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) { - PointerType *PT = cast<PointerType>(Ptr->getType()); + auto *PT = cast<PointerType>(Ptr->getType()); if (PT->getElementType()->isIntegerTy(8)) return Ptr; @@ -386,7 +400,7 @@ CallInst *IRBuilderBase::CreateAssumption(Value *Cond) { CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask, Value *PassThru, const Twine &Name) { - PointerType *PtrTy = cast<PointerType>(Ptr->getType()); + auto *PtrTy = cast<PointerType>(Ptr->getType()); Type *DataTy = PtrTy->getElementType(); assert(DataTy->isVectorTy() && "Ptr should point to a vector"); assert(Mask && "Mask should not be all-ones (null)"); @@ -406,7 +420,7 @@ CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align, /// be accessed in memory CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align, Value *Mask) { - PointerType *PtrTy = cast<PointerType>(Ptr->getType()); + auto *PtrTy = cast<PointerType>(Ptr->getType()); Type *DataTy = PtrTy->getElementType(); assert(DataTy->isVectorTy() && "Ptr should point to a vector"); assert(Mask && "Mask should not be all-ones (null)"); @@ -520,7 +534,7 @@ static CallInst *CreateGCStatepointCallCommon( ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) { // Extract out the type of the callee. - PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType()); + auto *FuncPtrType = cast<PointerType>(ActualCallee->getType()); assert(isa<FunctionType>(FuncPtrType->getElementType()) && "actual callee must be a callable value"); @@ -531,7 +545,7 @@ static CallInst *CreateGCStatepointCallCommon( Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, ArgTypes); - std::vector<llvm::Value *> Args = + std::vector<Value *> Args = getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs, DeoptArgs, GCArgs); return createCallHelper(FnStatepoint, Args, Builder, Name); @@ -571,7 +585,7 @@ static InvokeInst *CreateGCStatepointInvokeCommon( uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) { // Extract out the type of the callee. - PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType()); + auto *FuncPtrType = cast<PointerType>(ActualInvokee->getType()); assert(isa<FunctionType>(FuncPtrType->getElementType()) && "actual callee must be a callable value"); @@ -580,7 +594,7 @@ static InvokeInst *CreateGCStatepointInvokeCommon( Function *FnStatepoint = Intrinsic::getDeclaration( M, Intrinsic::experimental_gc_statepoint, {FuncPtrType}); - std::vector<llvm::Value *> Args = + std::vector<Value *> Args = getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags, InvokeArgs, TransitionArgs, DeoptArgs, GCArgs); return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder, @@ -663,4 +677,3 @@ CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID, Function *Fn = Intrinsic::getDeclaration(M, ID, { Args.front()->getType() }); return createCallHelper(Fn, Args, this, Name, FMFSource); } - |