diff options
Diffstat (limited to 'include/llvm/IR')
| -rw-r--r-- | include/llvm/IR/Attributes.h | 7 | ||||
| -rw-r--r-- | include/llvm/IR/Attributes.td | 2 | ||||
| -rw-r--r-- | include/llvm/IR/BasicBlock.h | 15 | ||||
| -rw-r--r-- | include/llvm/IR/ConstantRange.h | 9 | ||||
| -rw-r--r-- | include/llvm/IR/DerivedUser.h | 12 | ||||
| -rw-r--r-- | include/llvm/IR/InstrTypes.h | 4 | ||||
| -rw-r--r-- | include/llvm/IR/Instruction.h | 7 | ||||
| -rw-r--r-- | include/llvm/IR/Instructions.h | 34 | ||||
| -rw-r--r-- | include/llvm/IR/IntrinsicsAMDGPU.td | 27 | ||||
| -rw-r--r-- | include/llvm/IR/IntrinsicsX86.td | 80 | ||||
| -rw-r--r-- | include/llvm/IR/Metadata.h | 63 | ||||
| -rw-r--r-- | include/llvm/IR/ModuleSummaryIndexYAML.h | 2 | ||||
| -rw-r--r-- | include/llvm/IR/Operator.h | 9 | ||||
| -rw-r--r-- | include/llvm/IR/PatternMatch.h | 209 | ||||
| -rw-r--r-- | include/llvm/IR/Statepoint.h | 3 | ||||
| -rw-r--r-- | include/llvm/IR/Value.h | 7 |
16 files changed, 256 insertions, 234 deletions
diff --git a/include/llvm/IR/Attributes.h b/include/llvm/IR/Attributes.h index 0e8adda82cbe..0cab8bbb8ead 100644 --- a/include/llvm/IR/Attributes.h +++ b/include/llvm/IR/Attributes.h @@ -622,7 +622,8 @@ public: // AttributeList Introspection //===--------------------------------------------------------------------===// - typedef const AttributeSet *iterator; + using iterator = const AttributeSet *; + iterator begin() const; iterator end() const; @@ -830,8 +831,8 @@ bool areInlineCompatible(const Function &Caller, const Function &Callee); /// \brief Merge caller's and callee's attributes. void mergeAttributesForInlining(Function &Caller, const Function &Callee); -} // end AttributeFuncs namespace +} // end namespace AttributeFuncs -} // end llvm namespace +} // end namespace llvm #endif // LLVM_IR_ATTRIBUTES_H diff --git a/include/llvm/IR/Attributes.td b/include/llvm/IR/Attributes.td index 75867a6e5833..616387816bf8 100644 --- a/include/llvm/IR/Attributes.td +++ b/include/llvm/IR/Attributes.td @@ -214,3 +214,5 @@ def : MergeRule<"setAND<UnsafeFPMathAttr>">; def : MergeRule<"setOR<NoImplicitFloatAttr>">; def : MergeRule<"setOR<NoJumpTablesAttr>">; def : MergeRule<"adjustCallerSSPLevel">; +def : MergeRule<"adjustCallerStackProbes">; +def : MergeRule<"adjustCallerStackProbeSize">; diff --git a/include/llvm/IR/BasicBlock.h b/include/llvm/IR/BasicBlock.h index 23f838b640e0..7a35afcbafc3 100644 --- a/include/llvm/IR/BasicBlock.h +++ b/include/llvm/IR/BasicBlock.h @@ -1,4 +1,4 @@ -//===-- llvm/BasicBlock.h - Represent a basic block in the VM ---*- C++ -*-===// +//===- llvm/BasicBlock.h - Represent a basic block in the VM ----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -18,13 +18,17 @@ #include "llvm/ADT/Twine.h" #include "llvm/ADT/ilist.h" #include "llvm/ADT/ilist_node.h" +#include "llvm/ADT/iterator.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/SymbolTableListTraits.h" #include "llvm/IR/Value.h" #include "llvm/Support/CBindingWrapping.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include <cassert> #include <cstddef> +#include <iterator> namespace llvm { @@ -294,9 +298,9 @@ public: return *this; } }; - typedef phi_iterator_impl<> phi_iterator; - typedef phi_iterator_impl<const PHINode, BasicBlock::const_iterator> - const_phi_iterator; + using phi_iterator = phi_iterator_impl<>; + using const_phi_iterator = + phi_iterator_impl<const PHINode, BasicBlock::const_iterator>; /// Returns a range that iterates over the phis in the basic block. /// @@ -391,6 +395,9 @@ public: static_cast<const BasicBlock *>(this)->getLandingPadInst()); } + /// \brief Return true if it is legal to hoist instructions into this block. + bool isLegalToHoistInto() const; + private: /// \brief Increment the internal refcount of the number of BlockAddresses /// referencing this BasicBlock by \p Amt. diff --git a/include/llvm/IR/ConstantRange.h b/include/llvm/IR/ConstantRange.h index 6a50a8801f86..ff6495e7f075 100644 --- a/include/llvm/IR/ConstantRange.h +++ b/include/llvm/IR/ConstantRange.h @@ -34,11 +34,14 @@ #include "llvm/ADT/APInt.h" #include "llvm/IR/InstrTypes.h" -#include "llvm/Support/DataTypes.h" +#include "llvm/IR/Instruction.h" +#include "llvm/Support/Compiler.h" +#include <cstdint> namespace llvm { class MDNode; +class raw_ostream; /// This class represents a range of values. class LLVM_NODISCARD ConstantRange { @@ -330,6 +333,6 @@ inline raw_ostream &operator<<(raw_ostream &OS, const ConstantRange &CR) { /// E.g. if RangeMD is !{i32 0, i32 10, i32 15, i32 20} then return [0, 20). ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD); -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_CONSTANTRANGE_H diff --git a/include/llvm/IR/DerivedUser.h b/include/llvm/IR/DerivedUser.h index 4d681e0db611..67c483d3c497 100644 --- a/include/llvm/IR/DerivedUser.h +++ b/include/llvm/IR/DerivedUser.h @@ -1,4 +1,4 @@ -//===-- DerivedUser.h - Base for non-IR Users -------------------*- C++ -*-===// +//===- DerivedUser.h - Base for non-IR Users --------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -14,6 +14,9 @@ namespace llvm { +class Type; +class Use; + /// Extension point for the Value hierarchy. All classes outside of lib/IR /// that wish to inherit from User should instead inherit from DerivedUser /// instead. Inheriting from this class is discouraged. @@ -24,10 +27,11 @@ namespace llvm { /// its use/def list machinery. class DerivedUser : public User { protected: - typedef void (*DeleteValueTy)(DerivedUser *); + using DeleteValueTy = void (*)(DerivedUser *); private: - friend Value; + friend class Value; + DeleteValueTy DeleteValue; public: @@ -36,6 +40,6 @@ public: : User(Ty, VK, U, NumOps), DeleteValue(DeleteValue) {} }; -} // namespace llvm +} // end namespace llvm #endif // LLVM_IR_DERIVEDUSER_H diff --git a/include/llvm/IR/InstrTypes.h b/include/llvm/IR/InstrTypes.h index b3c6644c7e81..76524b412456 100644 --- a/include/llvm/IR/InstrTypes.h +++ b/include/llvm/IR/InstrTypes.h @@ -322,14 +322,14 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value) //===----------------------------------------------------------------------===// class BinaryOperator : public Instruction { + void AssertOK(); + protected: BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty, const Twine &Name, Instruction *InsertBefore); BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd); - void init(BinaryOps iType); - // Note: Instruction needs to be a friend here to call cloneImpl. friend class Instruction; diff --git a/include/llvm/IR/Instruction.h b/include/llvm/IR/Instruction.h index 00c431834e31..d8db29e15886 100644 --- a/include/llvm/IR/Instruction.h +++ b/include/llvm/IR/Instruction.h @@ -152,9 +152,14 @@ public: return getOpcode() == AShr; } + /// Determine if the Opcode is and/or/xor. + static inline bool isBitwiseLogicOp(unsigned Opcode) { + return Opcode == And || Opcode == Or || Opcode == Xor; + } + /// Return true if this is and/or/xor. inline bool isBitwiseLogicOp() const { - return getOpcode() == And || getOpcode() == Or || getOpcode() == Xor; + return isBitwiseLogicOp(getOpcode()); } /// Determine if the OpCode is one of the CastInst instructions. diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index b3032f54aa42..e1620b3e7df5 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -1243,6 +1243,16 @@ public: /// vectors of floating point values. The operands must be identical types. /// Represents a floating point comparison operator. class FCmpInst: public CmpInst { + void AssertOK() { + assert(getPredicate() <= FCmpInst::LAST_FCMP_PREDICATE && + "Invalid FCmp predicate value"); + assert(getOperand(0)->getType() == getOperand(1)->getType() && + "Both operands to FCmp instruction are not of the same type!"); + // Check that the operands are the right type + assert(getOperand(0)->getType()->isFPOrFPVectorTy() && + "Invalid operand types for FCmp instruction"); + } + protected: // Note: Instruction needs to be a friend here to call cloneImpl. friend class Instruction; @@ -1261,13 +1271,7 @@ public: ) : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS, RHS, NameStr, InsertBefore) { - assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && - "Invalid FCmp predicate value"); - assert(getOperand(0)->getType() == getOperand(1)->getType() && - "Both operands to FCmp instruction are not of the same type!"); - // Check that the operands are the right type - assert(getOperand(0)->getType()->isFPOrFPVectorTy() && - "Invalid operand types for FCmp instruction"); + AssertOK(); } /// Constructor with insert-at-end semantics. @@ -1280,13 +1284,7 @@ public: ) : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS, RHS, NameStr, &InsertAtEnd) { - assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && - "Invalid FCmp predicate value"); - assert(getOperand(0)->getType() == getOperand(1)->getType() && - "Both operands to FCmp instruction are not of the same type!"); - // Check that the operands are the right type - assert(getOperand(0)->getType()->isFPOrFPVectorTy() && - "Invalid operand types for FCmp instruction"); + AssertOK(); } /// Constructor with no-insertion semantics @@ -1297,13 +1295,7 @@ public: const Twine &NameStr = "" ///< Name of the instruction ) : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS, RHS, NameStr) { - assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && - "Invalid FCmp predicate value"); - assert(getOperand(0)->getType() == getOperand(1)->getType() && - "Both operands to FCmp instruction are not of the same type!"); - // Check that the operands are the right type - assert(getOperand(0)->getType()->isFPOrFPVectorTy() && - "Invalid operand types for FCmp instruction"); + AssertOK(); } /// @returns true if the predicate of this instruction is EQ or NE. diff --git a/include/llvm/IR/IntrinsicsAMDGPU.td b/include/llvm/IR/IntrinsicsAMDGPU.td index 8017223c4ab0..4e0529a32d29 100644 --- a/include/llvm/IR/IntrinsicsAMDGPU.td +++ b/include/llvm/IR/IntrinsicsAMDGPU.td @@ -475,6 +475,33 @@ class AMDGPUBufferStore : Intrinsic < def int_amdgcn_buffer_store_format : AMDGPUBufferStore; def int_amdgcn_buffer_store : AMDGPUBufferStore; +def int_amdgcn_tbuffer_load : Intrinsic < + [llvm_any_ty], // overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32 + [llvm_v4i32_ty, // rsrc(SGPR) + llvm_i32_ty, // vindex(VGPR) + llvm_i32_ty, // voffset(VGPR) + llvm_i32_ty, // soffset(SGPR) + llvm_i32_ty, // offset(imm) + llvm_i32_ty, // dfmt(imm) + llvm_i32_ty, // nfmt(imm) + llvm_i1_ty, // glc(imm) + llvm_i1_ty], // slc(imm) + []>; + +def int_amdgcn_tbuffer_store : Intrinsic < + [], + [llvm_any_ty, // vdata(VGPR), overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32 + llvm_v4i32_ty, // rsrc(SGPR) + llvm_i32_ty, // vindex(VGPR) + llvm_i32_ty, // voffset(VGPR) + llvm_i32_ty, // soffset(SGPR) + llvm_i32_ty, // offset(imm) + llvm_i32_ty, // dfmt(imm) + llvm_i32_ty, // nfmt(imm) + llvm_i1_ty, // glc(imm) + llvm_i1_ty], // slc(imm) + []>; + class AMDGPUBufferAtomic : Intrinsic < [llvm_i32_ty], [llvm_i32_ty, // vdata(VGPR) diff --git a/include/llvm/IR/IntrinsicsX86.td b/include/llvm/IR/IntrinsicsX86.td index 1c466e73eb1b..80c528768dc7 100644 --- a/include/llvm/IR/IntrinsicsX86.td +++ b/include/llvm/IR/IntrinsicsX86.td @@ -5420,86 +5420,6 @@ let TargetPrefix = "x86" in { def int_x86_avx512_vcomi_ss : GCCBuiltin<"__builtin_ia32_vcomiss">, Intrinsic<[llvm_i32_ty], [llvm_v4f32_ty, llvm_v4f32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>; - - def int_x86_avx512_mask_cmp_b_512: - Intrinsic<[llvm_i64_ty], [llvm_v64i8_ty, llvm_v64i8_ty, llvm_i32_ty, - llvm_i64_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_w_512: - Intrinsic<[llvm_i32_ty], [llvm_v32i16_ty, llvm_v32i16_ty, llvm_i32_ty, - llvm_i32_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_d_512: - Intrinsic<[llvm_i16_ty], [llvm_v16i32_ty, llvm_v16i32_ty, llvm_i32_ty, - llvm_i16_ty], [IntrNoMem ]>; - def int_x86_avx512_mask_cmp_q_512: - Intrinsic<[llvm_i8_ty], [llvm_v8i64_ty, llvm_v8i64_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - - def int_x86_avx512_mask_ucmp_b_512: - Intrinsic<[llvm_i64_ty], [llvm_v64i8_ty, llvm_v64i8_ty, llvm_i32_ty, - llvm_i64_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_w_512: - Intrinsic<[llvm_i32_ty], [llvm_v32i16_ty, llvm_v32i16_ty, llvm_i32_ty, - llvm_i32_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_d_512: - Intrinsic<[llvm_i16_ty], [llvm_v16i32_ty, llvm_v16i32_ty, llvm_i32_ty, - llvm_i16_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_q_512: - Intrinsic<[llvm_i8_ty], [llvm_v8i64_ty, llvm_v8i64_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - - // 256-bit - def int_x86_avx512_mask_cmp_b_256: - Intrinsic<[llvm_i32_ty], [llvm_v32i8_ty, llvm_v32i8_ty, llvm_i32_ty, - llvm_i32_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_w_256: - Intrinsic<[llvm_i16_ty], [llvm_v16i16_ty, llvm_v16i16_ty, llvm_i32_ty, - llvm_i16_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_d_256: - Intrinsic<[llvm_i8_ty], [llvm_v8i32_ty, llvm_v8i32_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_q_256: - Intrinsic<[llvm_i8_ty], [llvm_v4i64_ty, llvm_v4i64_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - - def int_x86_avx512_mask_ucmp_b_256: - Intrinsic<[llvm_i32_ty], [llvm_v32i8_ty, llvm_v32i8_ty, llvm_i32_ty, - llvm_i32_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_w_256: - Intrinsic<[llvm_i16_ty], [llvm_v16i16_ty, llvm_v16i16_ty, llvm_i32_ty, - llvm_i16_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_d_256: - Intrinsic<[llvm_i8_ty], [llvm_v8i32_ty, llvm_v8i32_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_q_256: - Intrinsic<[llvm_i8_ty], [llvm_v4i64_ty, llvm_v4i64_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - - // 128-bit - def int_x86_avx512_mask_cmp_b_128: - Intrinsic<[llvm_i16_ty], [llvm_v16i8_ty, llvm_v16i8_ty, llvm_i32_ty, - llvm_i16_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_w_128: - Intrinsic<[llvm_i8_ty], [llvm_v8i16_ty, llvm_v8i16_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_d_128: - Intrinsic<[llvm_i8_ty], [llvm_v4i32_ty, llvm_v4i32_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - def int_x86_avx512_mask_cmp_q_128: - Intrinsic<[llvm_i8_ty], [llvm_v2i64_ty, llvm_v2i64_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - - def int_x86_avx512_mask_ucmp_b_128: - Intrinsic<[llvm_i16_ty], [llvm_v16i8_ty, llvm_v16i8_ty, llvm_i32_ty, - llvm_i16_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_w_128: - Intrinsic<[llvm_i8_ty], [llvm_v8i16_ty, llvm_v8i16_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_d_128: - Intrinsic<[llvm_i8_ty], [llvm_v4i32_ty, llvm_v4i32_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; - def int_x86_avx512_mask_ucmp_q_128: - Intrinsic<[llvm_i8_ty], [llvm_v2i64_ty, llvm_v2i64_ty, llvm_i32_ty, - llvm_i8_ty], [IntrNoMem]>; } // Compress, Expand diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index d538c2595393..80ed44be43eb 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -45,6 +45,8 @@ namespace llvm { class Module; class ModuleSlotTracker; +class raw_ostream; +class Type; enum LLVMConstants : uint32_t { DEBUG_METADATA_VERSION = 3 // Current debug info version number. @@ -67,8 +69,8 @@ protected: unsigned char Storage; // TODO: expose remaining bits to subclasses. - unsigned short SubclassData16; - unsigned SubclassData32; + unsigned short SubclassData16 = 0; + unsigned SubclassData32 = 0; public: enum MetadataKind { @@ -78,7 +80,7 @@ public: protected: Metadata(unsigned ID, StorageType Storage) - : SubclassID(ID), Storage(Storage), SubclassData16(0), SubclassData32(0) { + : SubclassID(ID), Storage(Storage) { static_assert(sizeof(*this) == 8, "Metadata fields poorly packed"); } @@ -183,6 +185,7 @@ public: static MetadataAsValue *get(LLVMContext &Context, Metadata *MD); static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD); + Metadata *getMetadata() const { return MD; } static bool classof(const Value *V) { @@ -257,7 +260,7 @@ public: /// \brief Check whether metadata is replaceable. static bool isReplaceable(const Metadata &MD); - typedef PointerUnion<MetadataAsValue *, Metadata *> OwnerTy; + using OwnerTy = PointerUnion<MetadataAsValue *, Metadata *>; private: /// \brief Track a reference to metadata for an owner. @@ -275,7 +278,7 @@ class ReplaceableMetadataImpl { friend class MetadataTracking; public: - typedef MetadataTracking::OwnerTy OwnerTy; + using OwnerTy = MetadataTracking::OwnerTy; private: LLVMContext &Context; @@ -352,17 +355,21 @@ protected: public: static ValueAsMetadata *get(Value *V); + static ConstantAsMetadata *getConstant(Value *C) { return cast<ConstantAsMetadata>(get(C)); } + static LocalAsMetadata *getLocal(Value *Local) { return cast<LocalAsMetadata>(get(Local)); } static ValueAsMetadata *getIfExists(Value *V); + static ConstantAsMetadata *getConstantIfExists(Value *C) { return cast_or_null<ConstantAsMetadata>(getIfExists(C)); } + static LocalAsMetadata *getLocalIfExists(Value *Local) { return cast_or_null<LocalAsMetadata>(getIfExists(Local)); } @@ -491,8 +498,8 @@ namespace detail { template <class T> T &make(); template <class T, class Result> struct HasDereference { - typedef char Yes[1]; - typedef char No[2]; + using Yes = char[1]; + using No = char[2]; template <size_t N> struct SFINAE {}; template <class U, class V> @@ -613,7 +620,7 @@ public: unsigned getLength() const { return (unsigned)getString().size(); } - typedef StringRef::iterator iterator; + using iterator = StringRef::iterator; /// \brief Pointer to the first byte of the string. iterator begin() const { return getString().begin(); } @@ -730,12 +737,14 @@ private: }; template <> struct simplify_type<MDOperand> { - typedef Metadata *SimpleType; + using SimpleType = Metadata *; + static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); } }; template <> struct simplify_type<const MDOperand> { - typedef Metadata *SimpleType; + using SimpleType = Metadata *; + static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); } }; @@ -817,7 +826,7 @@ struct TempMDNodeDeleter { }; #define HANDLE_MDNODE_LEAF(CLASS) \ - typedef std::unique_ptr<CLASS, TempMDNodeDeleter> Temp##CLASS; + using Temp##CLASS = std::unique_ptr<CLASS, TempMDNodeDeleter>; #define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS) #include "llvm/IR/Metadata.def" @@ -847,6 +856,10 @@ class MDNode : public Metadata { ContextAndReplaceableUses Context; protected: + MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, + ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None); + ~MDNode() = default; + void *operator new(size_t Size, unsigned NumOps); void operator delete(void *Mem); @@ -860,16 +873,13 @@ protected: llvm_unreachable("Constructor throws?"); } - MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, - ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None); - ~MDNode() = default; - void dropAllReferences(); MDOperand *mutable_begin() { return mutable_end() - NumOperands; } MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); } - typedef iterator_range<MDOperand *> mutable_op_range; + using mutable_op_range = iterator_range<MDOperand *>; + mutable_op_range mutable_operands() { return mutable_op_range(mutable_begin(), mutable_end()); } @@ -1028,8 +1038,8 @@ private: static void dispatchResetHash(NodeTy *, std::false_type) {} public: - typedef const MDOperand *op_iterator; - typedef iterator_range<op_iterator> op_range; + using op_iterator = const MDOperand *; + using op_range = iterator_range<op_iterator>; op_iterator op_begin() const { return const_cast<MDNode *>(this)->mutable_begin(); @@ -1227,13 +1237,14 @@ public: T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); } // FIXME: Fix callers and remove condition on N. - typedef TypedMDOperandIterator<T> iterator; + using iterator = TypedMDOperandIterator<T>; + iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); } iterator end() const { return N ? iterator(N->op_end()) : iterator(); } }; #define HANDLE_METADATA(CLASS) \ - typedef MDTupleTypedArrayWrapper<CLASS> CLASS##Array; + using CLASS##Array = MDTupleTypedArrayWrapper<CLASS>; #include "llvm/IR/Metadata.def" /// Placeholder metadata for operands of distinct MDNodes. @@ -1304,12 +1315,12 @@ class NamedMDNode : public ilist_node<NamedMDNode> { template<class T1, class T2> class op_iterator_impl : public std::iterator<std::bidirectional_iterator_tag, T2> { + friend class NamedMDNode; + const NamedMDNode *Node = nullptr; unsigned Idx = 0; - op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) { } - - friend class NamedMDNode; + op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {} public: op_iterator_impl() = default; @@ -1371,11 +1382,13 @@ public: // --------------------------------------------------------------------------- // Operand Iterator interface... // - typedef op_iterator_impl<MDNode *, MDNode> op_iterator; + using op_iterator = op_iterator_impl<MDNode *, MDNode>; + op_iterator op_begin() { return op_iterator(this, 0); } op_iterator op_end() { return op_iterator(this, getNumOperands()); } - typedef op_iterator_impl<const MDNode *, MDNode> const_op_iterator; + using const_op_iterator = op_iterator_impl<const MDNode *, MDNode>; + const_op_iterator op_begin() const { return const_op_iterator(this, 0); } const_op_iterator op_end() const { return const_op_iterator(this, getNumOperands()); } diff --git a/include/llvm/IR/ModuleSummaryIndexYAML.h b/include/llvm/IR/ModuleSummaryIndexYAML.h index 8950c527cc18..5d7b8b997d37 100644 --- a/include/llvm/IR/ModuleSummaryIndexYAML.h +++ b/include/llvm/IR/ModuleSummaryIndexYAML.h @@ -188,7 +188,7 @@ template <> struct MappingTraits<FunctionSummaryYaml> { LLVM_YAML_IS_STRING_MAP(TypeIdSummary) LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummaryYaml) -LLVM_YAML_IS_SEQUENCE_VECTOR(std::string) +LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string) namespace llvm { namespace yaml { diff --git a/include/llvm/IR/Operator.h b/include/llvm/IR/Operator.h index 6eb5998478c6..c7f4697e93e7 100644 --- a/include/llvm/IR/Operator.h +++ b/include/llvm/IR/Operator.h @@ -328,8 +328,15 @@ public: return I->getType()->isFPOrFPVectorTy() || I->getOpcode() == Instruction::FCmp; } + + static inline bool classof(const ConstantExpr *CE) { + return CE->getType()->isFPOrFPVectorTy() || + CE->getOpcode() == Instruction::FCmp; + } + static inline bool classof(const Value *V) { - return isa<Instruction>(V) && classof(cast<Instruction>(V)); + return (isa<Instruction>(V) && classof(cast<Instruction>(V))) || + (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V))); } }; diff --git a/include/llvm/IR/PatternMatch.h b/include/llvm/IR/PatternMatch.h index 015a17e8e7ca..9e9c8ac75d2a 100644 --- a/include/llvm/IR/PatternMatch.h +++ b/include/llvm/IR/PatternMatch.h @@ -167,10 +167,8 @@ inline match_combine_or<match_zero, match_neg_zero> m_AnyZero() { struct match_nan { template <typename ITy> bool match(ITy *V) { - if (const auto *C = dyn_cast<ConstantFP>(V)) { - const APFloat &APF = C->getValueAPF(); - return APF.isNaN(); - } + if (const auto *C = dyn_cast<ConstantFP>(V)) + return C->isNaN(); return false; } }; @@ -419,7 +417,8 @@ inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; } //===----------------------------------------------------------------------===// // Matcher for any binary operator. // -template <typename LHS_t, typename RHS_t> struct AnyBinaryOp_match { +template <typename LHS_t, typename RHS_t, bool Commutable = false> +struct AnyBinaryOp_match { LHS_t L; RHS_t R; @@ -427,7 +426,9 @@ template <typename LHS_t, typename RHS_t> struct AnyBinaryOp_match { template <typename OpTy> bool match(OpTy *V) { if (auto *I = dyn_cast<BinaryOperator>(V)) - return L.match(I->getOperand(0)) && R.match(I->getOperand(1)); + return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) || + (Commutable && R.match(I->getOperand(0)) && + L.match(I->getOperand(1))); return false; } }; @@ -441,7 +442,8 @@ inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) { // Matchers for specific binary operators. // -template <typename LHS_t, typename RHS_t, unsigned Opcode> +template <typename LHS_t, typename RHS_t, unsigned Opcode, + bool Commutable = false> struct BinaryOp_match { LHS_t L; RHS_t R; @@ -451,11 +453,15 @@ struct BinaryOp_match { template <typename OpTy> bool match(OpTy *V) { if (V->getValueID() == Value::InstructionVal + Opcode) { auto *I = cast<BinaryOperator>(V); - return L.match(I->getOperand(0)) && R.match(I->getOperand(1)); + return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) || + (Commutable && R.match(I->getOperand(0)) && + L.match(I->getOperand(1))); } if (auto *CE = dyn_cast<ConstantExpr>(V)) - return CE->getOpcode() == Opcode && L.match(CE->getOperand(0)) && - R.match(CE->getOperand(1)); + return CE->getOpcode() == Opcode && + ((L.match(CE->getOperand(0)) && R.match(CE->getOperand(1))) || + (Commutable && R.match(CE->getOperand(0)) && + L.match(CE->getOperand(1)))); return false; } }; @@ -660,47 +666,87 @@ m_NUWShl(const LHS &L, const RHS &R) { } //===----------------------------------------------------------------------===// -// Class that matches two different binary ops. +// Class that matches a group of binary opcodes. // -template <typename LHS_t, typename RHS_t, unsigned Opc1, unsigned Opc2> -struct BinOp2_match { +template <typename LHS_t, typename RHS_t, typename Predicate> +struct BinOpPred_match : Predicate { LHS_t L; RHS_t R; - BinOp2_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {} + BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {} template <typename OpTy> bool match(OpTy *V) { - if (V->getValueID() == Value::InstructionVal + Opc1 || - V->getValueID() == Value::InstructionVal + Opc2) { - auto *I = cast<BinaryOperator>(V); - return L.match(I->getOperand(0)) && R.match(I->getOperand(1)); - } + if (auto *I = dyn_cast<Instruction>(V)) + return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) && + R.match(I->getOperand(1)); if (auto *CE = dyn_cast<ConstantExpr>(V)) - return (CE->getOpcode() == Opc1 || CE->getOpcode() == Opc2) && - L.match(CE->getOperand(0)) && R.match(CE->getOperand(1)); + return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) && + R.match(CE->getOperand(1)); return false; } }; -/// \brief Matches LShr or AShr. +struct is_shift_op { + bool isOpType(unsigned Opcode) { return Instruction::isShift(Opcode); } +}; + +struct is_right_shift_op { + bool isOpType(unsigned Opcode) { + return Opcode == Instruction::LShr || Opcode == Instruction::AShr; + } +}; + +struct is_logical_shift_op { + bool isOpType(unsigned Opcode) { + return Opcode == Instruction::LShr || Opcode == Instruction::Shl; + } +}; + +struct is_bitwiselogic_op { + bool isOpType(unsigned Opcode) { + return Instruction::isBitwiseLogicOp(Opcode); + } +}; + +struct is_idiv_op { + bool isOpType(unsigned Opcode) { + return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv; + } +}; + +/// \brief Matches shift operations. template <typename LHS, typename RHS> -inline BinOp2_match<LHS, RHS, Instruction::LShr, Instruction::AShr> -m_Shr(const LHS &L, const RHS &R) { - return BinOp2_match<LHS, RHS, Instruction::LShr, Instruction::AShr>(L, R); +inline BinOpPred_match<LHS, RHS, is_shift_op> m_Shift(const LHS &L, + const RHS &R) { + return BinOpPred_match<LHS, RHS, is_shift_op>(L, R); } -/// \brief Matches LShr or Shl. +/// \brief Matches logical shift operations. template <typename LHS, typename RHS> -inline BinOp2_match<LHS, RHS, Instruction::LShr, Instruction::Shl> +inline BinOpPred_match<LHS, RHS, is_right_shift_op> m_Shr(const LHS &L, + const RHS &R) { + return BinOpPred_match<LHS, RHS, is_right_shift_op>(L, R); +} + +/// \brief Matches logical shift operations. +template <typename LHS, typename RHS> +inline BinOpPred_match<LHS, RHS, is_logical_shift_op> m_LogicalShift(const LHS &L, const RHS &R) { - return BinOp2_match<LHS, RHS, Instruction::LShr, Instruction::Shl>(L, R); + return BinOpPred_match<LHS, RHS, is_logical_shift_op>(L, R); } -/// \brief Matches UDiv and SDiv. +/// \brief Matches bitwise logic operations. template <typename LHS, typename RHS> -inline BinOp2_match<LHS, RHS, Instruction::SDiv, Instruction::UDiv> -m_IDiv(const LHS &L, const RHS &R) { - return BinOp2_match<LHS, RHS, Instruction::SDiv, Instruction::UDiv>(L, R); +inline BinOpPred_match<LHS, RHS, is_bitwiselogic_op> +m_BitwiseLogic(const LHS &L, const RHS &R) { + return BinOpPred_match<LHS, RHS, is_bitwiselogic_op>(L, R); +} + +/// \brief Matches integer division operations. +template <typename LHS, typename RHS> +inline BinOpPred_match<LHS, RHS, is_idiv_op> m_IDiv(const LHS &L, + const RHS &R) { + return BinOpPred_match<LHS, RHS, is_idiv_op>(L, R); } //===----------------------------------------------------------------------===// @@ -726,7 +772,8 @@ template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) { // Matchers for CmpInst classes // -template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy> +template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy, + bool Commutable = false> struct CmpClass_match { PredicateTy &Predicate; LHS_t L; @@ -737,7 +784,9 @@ struct CmpClass_match { template <typename OpTy> bool match(OpTy *V) { if (auto *I = dyn_cast<Class>(V)) - if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) { + if ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) || + (Commutable && R.match(I->getOperand(0)) && + L.match(I->getOperand(1)))) { Predicate = I->getPredicate(); return true; } @@ -897,10 +946,7 @@ template <typename LHS_t> struct not_match { private: bool isAllOnes(Value *V) { - return (isa<ConstantInt>(V) || isa<ConstantDataVector>(V) || - // FIXME: Remove CV. - isa<ConstantVector>(V)) && - cast<Constant>(V)->isAllOnesValue(); + return isa<Constant>(V) && cast<Constant>(V)->isAllOnesValue(); } }; @@ -1002,7 +1048,8 @@ inline brc_match<Cond_t> m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F) { // Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y). // -template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t> +template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t, + bool Commutable = false> struct MaxMin_match { LHS_t L; RHS_t R; @@ -1032,7 +1079,8 @@ struct MaxMin_match { if (!Pred_t::match(Pred)) return false; // It does! Bind the operands. - return L.match(LHS) && R.match(RHS); + return (L.match(LHS) && R.match(RHS)) || + (Commutable && R.match(LHS) && L.match(RHS)); } }; @@ -1376,89 +1424,78 @@ template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) { // /// \brief Matches a BinaryOperator with LHS and RHS in either order. -template<typename LHS, typename RHS> -inline match_combine_or<AnyBinaryOp_match<LHS, RHS>, - AnyBinaryOp_match<RHS, LHS>> -m_c_BinOp(const LHS &L, const RHS &R) { - return m_CombineOr(m_BinOp(L, R), m_BinOp(R, L)); +template <typename LHS, typename RHS> +inline AnyBinaryOp_match<LHS, RHS, true> m_c_BinOp(const LHS &L, const RHS &R) { + return AnyBinaryOp_match<LHS, RHS, true>(L, R); } /// \brief Matches an ICmp with a predicate over LHS and RHS in either order. /// Does not swap the predicate. -template<typename LHS, typename RHS> -inline match_combine_or<CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>, - CmpClass_match<RHS, LHS, ICmpInst, ICmpInst::Predicate>> +template <typename LHS, typename RHS> +inline CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true> m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return m_CombineOr(m_ICmp(Pred, L, R), m_ICmp(Pred, R, L)); + return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>(Pred, L, + R); } /// \brief Matches a Add with LHS and RHS in either order. -template<typename LHS, typename RHS> -inline match_combine_or<BinaryOp_match<LHS, RHS, Instruction::Add>, - BinaryOp_match<RHS, LHS, Instruction::Add>> -m_c_Add(const LHS &L, const RHS &R) { - return m_CombineOr(m_Add(L, R), m_Add(R, L)); +template <typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::Add, true> m_c_Add(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::Add, true>(L, R); } /// \brief Matches a Mul with LHS and RHS in either order. -template<typename LHS, typename RHS> -inline match_combine_or<BinaryOp_match<LHS, RHS, Instruction::Mul>, - BinaryOp_match<RHS, LHS, Instruction::Mul>> -m_c_Mul(const LHS &L, const RHS &R) { - return m_CombineOr(m_Mul(L, R), m_Mul(R, L)); +template <typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::Mul, true> m_c_Mul(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::Mul, true>(L, R); } /// \brief Matches an And with LHS and RHS in either order. -template<typename LHS, typename RHS> -inline match_combine_or<BinaryOp_match<LHS, RHS, Instruction::And>, - BinaryOp_match<RHS, LHS, Instruction::And>> -m_c_And(const LHS &L, const RHS &R) { - return m_CombineOr(m_And(L, R), m_And(R, L)); +template <typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::And, true> m_c_And(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::And, true>(L, R); } /// \brief Matches an Or with LHS and RHS in either order. -template<typename LHS, typename RHS> -inline match_combine_or<BinaryOp_match<LHS, RHS, Instruction::Or>, - BinaryOp_match<RHS, LHS, Instruction::Or>> -m_c_Or(const LHS &L, const RHS &R) { - return m_CombineOr(m_Or(L, R), m_Or(R, L)); +template <typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::Or, true> m_c_Or(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::Or, true>(L, R); } /// \brief Matches an Xor with LHS and RHS in either order. -template<typename LHS, typename RHS> -inline match_combine_or<BinaryOp_match<LHS, RHS, Instruction::Xor>, - BinaryOp_match<RHS, LHS, Instruction::Xor>> -m_c_Xor(const LHS &L, const RHS &R) { - return m_CombineOr(m_Xor(L, R), m_Xor(R, L)); +template <typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::Xor, true> m_c_Xor(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::Xor, true>(L, R); } /// Matches an SMin with LHS and RHS in either order. template <typename LHS, typename RHS> -inline match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty>, - MaxMin_match<ICmpInst, RHS, LHS, smin_pred_ty>> +inline MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true> m_c_SMin(const LHS &L, const RHS &R) { - return m_CombineOr(m_SMin(L, R), m_SMin(R, L)); + return MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true>(L, R); } /// Matches an SMax with LHS and RHS in either order. template <typename LHS, typename RHS> -inline match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty>, - MaxMin_match<ICmpInst, RHS, LHS, smax_pred_ty>> +inline MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty, true> m_c_SMax(const LHS &L, const RHS &R) { - return m_CombineOr(m_SMax(L, R), m_SMax(R, L)); + return MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty, true>(L, R); } /// Matches a UMin with LHS and RHS in either order. template <typename LHS, typename RHS> -inline match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty>, - MaxMin_match<ICmpInst, RHS, LHS, umin_pred_ty>> +inline MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty, true> m_c_UMin(const LHS &L, const RHS &R) { - return m_CombineOr(m_UMin(L, R), m_UMin(R, L)); + return MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty, true>(L, R); } /// Matches a UMax with LHS and RHS in either order. template <typename LHS, typename RHS> -inline match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty>, - MaxMin_match<ICmpInst, RHS, LHS, umax_pred_ty>> +inline MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty, true> m_c_UMax(const LHS &L, const RHS &R) { - return m_CombineOr(m_UMax(L, R), m_UMax(R, L)); + return MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty, true>(L, R); } } // end namespace PatternMatch diff --git a/include/llvm/IR/Statepoint.h b/include/llvm/IR/Statepoint.h index 265e7eb348bf..630f30667272 100644 --- a/include/llvm/IR/Statepoint.h +++ b/include/llvm/IR/Statepoint.h @@ -62,7 +62,10 @@ bool isStatepoint(const Value *V); bool isStatepoint(const Value &V); bool isGCRelocate(ImmutableCallSite CS); +bool isGCRelocate(const Value *V); + bool isGCResult(ImmutableCallSite CS); +bool isGCResult(const Value *V); /// Analogous to CallSiteBase, this provides most of the actual /// functionality for Statepoint and ImmutableStatepoint. It is diff --git a/include/llvm/IR/Value.h b/include/llvm/IR/Value.h index ccd40e576584..9e4914973edf 100644 --- a/include/llvm/IR/Value.h +++ b/include/llvm/IR/Value.h @@ -49,8 +49,9 @@ template<typename ValueTy> class StringMapEntry; class StringRef; class Twine; class Type; +class User; -using ValueName = StringMapEntry<Value*>; +using ValueName = StringMapEntry<Value *>; //===----------------------------------------------------------------------===// // Value Class @@ -212,7 +213,7 @@ protected: public: Value(const Value &) = delete; - void operator=(const Value &) = delete; + Value &operator=(const Value &) = delete; /// Delete a pointer to a generic Value. void deleteValue(); @@ -660,7 +661,7 @@ struct ValueDeleter { void operator()(Value *V) { V->deleteValue(); } }; /// Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>. /// Those don't work because Value and Instruction's destructors are protected, /// aren't virtual, and won't destroy the complete object. -typedef std::unique_ptr<Value, ValueDeleter> unique_value; +using unique_value = std::unique_ptr<Value, ValueDeleter>; inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) { V.print(OS); |
