From: Eugene Zelenko Date: Fri, 2 Dec 2016 22:00:59 +0000 (+0000) Subject: [IR] Fix some Clang-tidy modernize-use-equals-delete and Include What You Use warning... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6c59c9663f7085714c8d741f113e5b1211528a9;p=platform%2Fupstream%2Fllvm.git [IR] Fix some Clang-tidy modernize-use-equals-delete and Include What You Use warnings; other minor fixes (NFC). llvm-svn: 288540 --- diff --git a/llvm/include/llvm/IR/Constant.h b/llvm/include/llvm/IR/Constant.h index 3c5fe55..99c970e 100644 --- a/llvm/include/llvm/IR/Constant.h +++ b/llvm/include/llvm/IR/Constant.h @@ -15,11 +15,12 @@ #define LLVM_IR_CONSTANT_H #include "llvm/IR/User.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" namespace llvm { - class APInt; - template class SmallVectorImpl; +class APInt; /// This is an important base class in LLVM. It provides the common facilities /// of all constant values in an LLVM program. A constant is a value that is @@ -39,8 +40,6 @@ namespace llvm { /// don't have to worry about the lifetime of the objects. /// @brief LLVM Constant Representation class Constant : public User { - void operator=(const Constant &) = delete; - Constant(const Constant &) = delete; void anchor() override; protected: @@ -48,6 +47,9 @@ protected: : User(ty, vty, Ops, NumOps) {} public: + void operator=(const Constant &) = delete; + Constant(const Constant &) = delete; + /// Return true if this is the value that would be returned by getNullValue. bool isNullValue() const; @@ -159,6 +161,6 @@ public: } }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_CONSTANT_H diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index ded18d1..cbefa3f 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -24,21 +24,29 @@ #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/Constant.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/OperandTraits.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include +#include +#include namespace llvm { class ArrayType; class IntegerType; -class StructType; class PointerType; -class VectorType; class SequentialType; - -struct ConstantExprKeyType; +class StructType; +class VectorType; template struct ConstantAggrKeyType; /// Base class for constants with no operands. @@ -47,21 +55,25 @@ template struct ConstantAggrKeyType; /// Since they can be in use by unrelated modules (and are never based on /// GlobalValues), it never makes sense to RAUW them. class ConstantData : public Constant { + friend class Constant; + void anchor() override; - void *operator new(size_t, unsigned) = delete; - ConstantData() = delete; - ConstantData(const ConstantData &) = delete; - friend class Constant; Value *handleOperandChangeImpl(Value *From, Value *To) { llvm_unreachable("Constant data does not have operands!"); } protected: explicit ConstantData(Type *Ty, ValueTy VT) : Constant(Ty, VT, nullptr, 0) {} + void *operator new(size_t s) { return User::operator new(s, 0); } public: + ConstantData() = delete; + ConstantData(const ConstantData &) = delete; + + void *operator new(size_t, unsigned) = delete; + /// Methods to support type inquiry through isa, cast, and dyn_cast. static bool classof(const Value *V) { return V->getValueID() >= ConstantDataFirstVal && @@ -74,15 +86,18 @@ public: /// represents both boolean and integral constants. /// @brief Class for constant integers. class ConstantInt final : public ConstantData { - void anchor() override; - ConstantInt(const ConstantInt &) = delete; - ConstantInt(IntegerType *Ty, const APInt& V); + friend class Constant; + APInt Val; - friend class Constant; + ConstantInt(IntegerType *Ty, const APInt& V); + + void anchor() override; void destroyConstantImpl(); public: + ConstantInt(const ConstantInt &) = delete; + static ConstantInt *getTrue(LLVMContext &Context); static ConstantInt *getFalse(LLVMContext &Context); static Constant *getTrue(Type *Ty); @@ -248,21 +263,22 @@ public: } }; - //===----------------------------------------------------------------------===// /// ConstantFP - Floating Point Values [float, double] /// class ConstantFP final : public ConstantData { - APFloat Val; - void anchor() override; - ConstantFP(const ConstantFP &) = delete; - friend class Constant; - void destroyConstantImpl(); + + APFloat Val; ConstantFP(Type *Ty, const APFloat& V); + void anchor() override; + void destroyConstantImpl(); + public: + ConstantFP(const ConstantFP &) = delete; + /// Floating point negation must be implemented with f(x) = -0.0 - x. This /// method returns the negative zero constant for floating point or vector /// floating point types; for all other types, it returns the null value. @@ -309,6 +325,7 @@ public: FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored); return isExactlyValue(FV); } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Value *V) { return V->getValueID() == ConstantFPVal; @@ -319,15 +336,16 @@ public: /// All zero aggregate value /// class ConstantAggregateZero final : public ConstantData { - ConstantAggregateZero(const ConstantAggregateZero &) = delete; - friend class Constant; - void destroyConstantImpl(); explicit ConstantAggregateZero(Type *Ty) : ConstantData(Ty, ConstantAggregateZeroVal) {} + void destroyConstantImpl(); + public: + ConstantAggregateZero(const ConstantAggregateZero &) = delete; + static ConstantAggregateZero *get(Type *Ty); /// If this CAZ has array or vector type, return a zero with the right element @@ -393,11 +411,12 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantAggregate, Constant) class ConstantArray final : public ConstantAggregate { friend struct ConstantAggrKeyType; friend class Constant; - void destroyConstantImpl(); - Value *handleOperandChangeImpl(Value *From, Value *To); ConstantArray(ArrayType *T, ArrayRef Val); + void destroyConstantImpl(); + Value *handleOperandChangeImpl(Value *From, Value *To); + public: // ConstantArray accessors static Constant *get(ArrayType *T, ArrayRef V); @@ -424,11 +443,12 @@ public: class ConstantStruct final : public ConstantAggregate { friend struct ConstantAggrKeyType; friend class Constant; - void destroyConstantImpl(); - Value *handleOperandChangeImpl(Value *From, Value *To); ConstantStruct(StructType *T, ArrayRef Val); + void destroyConstantImpl(); + Value *handleOperandChangeImpl(Value *From, Value *To); + public: // ConstantStruct accessors static Constant *get(StructType *T, ArrayRef V); @@ -464,18 +484,18 @@ public: } }; - //===----------------------------------------------------------------------===// /// Constant Vector Declarations /// class ConstantVector final : public ConstantAggregate { friend struct ConstantAggrKeyType; friend class Constant; - void destroyConstantImpl(); - Value *handleOperandChangeImpl(Value *From, Value *To); ConstantVector(VectorType *T, ArrayRef Val); + void destroyConstantImpl(); + Value *handleOperandChangeImpl(Value *From, Value *To); + public: // ConstantVector accessors static Constant *get(ArrayRef V); @@ -507,15 +527,16 @@ public: /// A constant pointer value that points to null /// class ConstantPointerNull final : public ConstantData { - ConstantPointerNull(const ConstantPointerNull &) = delete; - friend class Constant; - void destroyConstantImpl(); explicit ConstantPointerNull(PointerType *T) : ConstantData(T, Value::ConstantPointerNullVal) {} + void destroyConstantImpl(); + public: + ConstantPointerNull(const ConstantPointerNull &) = delete; + /// Static factory methods - Return objects of the specified value static ConstantPointerNull *get(PointerType *T); @@ -542,6 +563,8 @@ public: /// class ConstantDataSequential : public ConstantData { friend class LLVMContextImpl; + friend class Constant; + /// A pointer to the bytes underlying this constant (which is owned by the /// uniquing StringMap). const char *DataElements; @@ -551,9 +574,7 @@ class ConstantDataSequential : public ConstantData { /// element array of i8, or a 1-element array of i32. They'll both end up in /// the same StringMap bucket, linked up. ConstantDataSequential *Next; - ConstantDataSequential(const ConstantDataSequential &) = delete; - friend class Constant; void destroyConstantImpl(); protected: @@ -564,6 +585,8 @@ protected: static Constant *getImpl(StringRef Bytes, Type *Ty); public: + ConstantDataSequential(const ConstantDataSequential &) = delete; + /// Return true if a ConstantDataSequential can be formed with a vector or /// array of the specified element type. /// ConstantDataArray only works with normal float and int types that are @@ -639,6 +662,7 @@ public: return V->getValueID() == ConstantDataArrayVal || V->getValueID() == ConstantDataVectorVal; } + private: const char *getElementPointer(unsigned Elt) const; }; @@ -650,18 +674,23 @@ private: /// stores all of the elements of the constant as densely packed data, instead /// of as Value*'s. class ConstantDataArray final : public ConstantDataSequential { - void *operator new(size_t, unsigned) = delete; - ConstantDataArray(const ConstantDataArray &) = delete; - void anchor() override; friend class ConstantDataSequential; + explicit ConstantDataArray(Type *ty, const char *Data) : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {} + /// Allocate space for exactly zero operands. void *operator new(size_t s) { return User::operator new(s, 0); } + void anchor() override; + public: + ConstantDataArray(const ConstantDataArray &) = delete; + + void *operator new(size_t, unsigned) = delete; + /// get() constructors - Return a constant with array type with an element /// count and element type matching the ArrayRef passed in. Note that this /// can return a ConstantAggregateZero object. @@ -708,18 +737,23 @@ public: /// stores all of the elements of the constant as densely packed data, instead /// of as Value*'s. class ConstantDataVector final : public ConstantDataSequential { - void *operator new(size_t, unsigned) = delete; - ConstantDataVector(const ConstantDataVector &) = delete; - void anchor() override; friend class ConstantDataSequential; + explicit ConstantDataVector(Type *ty, const char *Data) : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {} + // allocate space for exactly zero operands. void *operator new(size_t s) { return User::operator new(s, 0); } + void anchor() override; + public: + ConstantDataVector(const ConstantDataVector &) = delete; + + void *operator new(size_t, unsigned) = delete; + /// get() constructors - Return a constant with vector type with an element /// count and element type matching the ArrayRef passed in. Note that this /// can return a ConstantAggregateZero object. @@ -764,15 +798,16 @@ public: /// A constant token which is empty /// class ConstantTokenNone final : public ConstantData { - ConstantTokenNone(const ConstantTokenNone &) = delete; - friend class Constant; - void destroyConstantImpl(); explicit ConstantTokenNone(LLVMContext &Context) : ConstantData(Type::getTokenTy(Context), ConstantTokenNoneVal) {} + void destroyConstantImpl(); + public: + ConstantTokenNone(const ConstantTokenNone &) = delete; + /// Return the ConstantTokenNone. static ConstantTokenNone *get(LLVMContext &Context); @@ -785,15 +820,18 @@ public: /// The address of a basic block. /// class BlockAddress final : public Constant { - void *operator new(size_t, unsigned) = delete; - void *operator new(size_t s) { return User::operator new(s, 2); } + friend class Constant; + BlockAddress(Function *F, BasicBlock *BB); - friend class Constant; + void *operator new(size_t s) { return User::operator new(s, 2); } + void destroyConstantImpl(); Value *handleOperandChangeImpl(Value *From, Value *To); public: + void *operator new(size_t, unsigned) = delete; + /// Return a BlockAddress for the specified function and basic block. static BlockAddress *get(Function *F, BasicBlock *BB); @@ -825,7 +863,6 @@ struct OperandTraits : DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value) - //===----------------------------------------------------------------------===// /// A constant value that is initialized with an expression using /// other constant values. @@ -835,8 +872,8 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value) /// maintained in the Value::SubclassData field. class ConstantExpr : public Constant { friend struct ConstantExprKeyType; - friend class Constant; + void destroyConstantImpl(); Value *handleOperandChangeImpl(Value *From, Value *To); @@ -920,39 +957,51 @@ public: static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); } static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); } + static Constant *getNSWAdd(Constant *C1, Constant *C2) { return getAdd(C1, C2, false, true); } + static Constant *getNUWAdd(Constant *C1, Constant *C2) { return getAdd(C1, C2, true, false); } + static Constant *getNSWSub(Constant *C1, Constant *C2) { return getSub(C1, C2, false, true); } + static Constant *getNUWSub(Constant *C1, Constant *C2) { return getSub(C1, C2, true, false); } + static Constant *getNSWMul(Constant *C1, Constant *C2) { return getMul(C1, C2, false, true); } + static Constant *getNUWMul(Constant *C1, Constant *C2) { return getMul(C1, C2, true, false); } + static Constant *getNSWShl(Constant *C1, Constant *C2) { return getShl(C1, C2, false, true); } + static Constant *getNUWShl(Constant *C1, Constant *C2) { return getShl(C1, C2, true, false); } + static Constant *getExactSDiv(Constant *C1, Constant *C2) { return getSDiv(C1, C2, true); } + static Constant *getExactUDiv(Constant *C1, Constant *C2) { return getUDiv(C1, C2, true); } + static Constant *getExactAShr(Constant *C1, Constant *C2) { return getAShr(C1, C2, true); } + static Constant *getExactLShr(Constant *C1, Constant *C2) { return getLShr(C1, C2, true); } @@ -1207,14 +1256,15 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant) /// LangRef.html#undefvalues for details. /// class UndefValue final : public ConstantData { - UndefValue(const UndefValue &) = delete; - friend class Constant; - void destroyConstantImpl(); explicit UndefValue(Type *T) : ConstantData(T, UndefValueVal) {} + void destroyConstantImpl(); + public: + UndefValue(const UndefValue &) = delete; + /// Static factory methods - Return an 'undef' object of the specified type. static UndefValue *get(Type *T); @@ -1242,6 +1292,6 @@ public: } }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_CONSTANTS_H diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index e6e26c8..e9b3bad 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -18,18 +18,29 @@ #ifndef LLVM_IR_FUNCTION_H #define LLVM_IR_FUNCTION_H +#include "llvm/ADT/ilist_node.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/Argument.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/GlobalObject.h" +#include "llvm/IR/Intrinsics.h" #include "llvm/IR/OperandTraits.h" +#include "llvm/IR/SymbolTableListTraits.h" +#include "llvm/IR/Value.h" #include "llvm/Support/Compiler.h" +#include +#include +#include +#include +#include namespace llvm { template class Optional; +class AssemblyAnnotationWriter; class FunctionType; class LLVMContext; class DISubprogram; @@ -88,10 +99,8 @@ private: if (hasLazyArguments()) BuildLazyArguments(); } - void BuildLazyArguments() const; - Function(const Function&) = delete; - void operator=(const Function&) = delete; + void BuildLazyArguments() const; /// Function ctor - If the (optional) Module argument is specified, the /// function is automatically inserted into the end of the function list for @@ -101,13 +110,15 @@ private: const Twine &N = "", Module *M = nullptr); public: + Function(const Function&) = delete; + void operator=(const Function&) = delete; + ~Function() override; + static Function *Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N = "", Module *M = nullptr) { return new Function(Ty, Linkage, N, M); } - ~Function() override; - // Provide fast operand accessors. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); /// Returns the type of the ret val. @@ -489,12 +500,14 @@ public: CheckLazyArguments(); return ArgumentList; } + static ArgumentListType Function::*getSublistAccess(Argument*) { return &Function::ArgumentList; } const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } BasicBlockListType &getBasicBlockList() { return BasicBlocks; } + static BasicBlockListType Function::*getSublistAccess(BasicBlock*) { return &Function::BasicBlocks; } @@ -538,6 +551,7 @@ public: CheckLazyArguments(); return ArgumentList.begin(); } + arg_iterator arg_end() { CheckLazyArguments(); return ArgumentList.end(); @@ -550,7 +564,6 @@ public: iterator_range args() { return make_range(arg_begin(), arg_end()); } - iterator_range args() const { return make_range(arg_begin(), arg_end()); } @@ -671,6 +684,6 @@ struct OperandTraits : public HungoffOperandTraits<3> {}; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(Function, Value) -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_FUNCTION_H diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index 25d4316..46c785a 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -18,19 +18,30 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/PointerUnion.h" -#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/ilist_node.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/Constant.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" +#include +#include +#include +#include +#include +#include #include +#include namespace llvm { -class LLVMContext; class Module; class ModuleSlotTracker; @@ -69,6 +80,7 @@ protected: : SubclassID(ID), Storage(Storage), SubclassData16(0), SubclassData32(0) { static_assert(sizeof(*this) == 8, "Metdata fields poorly packed"); } + ~Metadata() = default; /// \brief Default handling of a changed operand, which asserts. @@ -263,6 +275,7 @@ private: public: ReplaceableMetadataImpl(LLVMContext &Context) : Context(Context), NextIndex(0) {} + ~ReplaceableMetadataImpl() { assert(UseMap.empty() && "Cannot destroy in-use replaceable metadata"); } @@ -325,6 +338,7 @@ protected: : Metadata(ID, Uniqued), ReplaceableMetadataImpl(V->getContext()), V(V) { assert(V && "Expected valid value"); } + ~ValueAsMetadata() = default; public: @@ -378,6 +392,7 @@ public: static ConstantAsMetadata *get(Constant *C) { return ValueAsMetadata::getConstant(C); } + static ConstantAsMetadata *getIfExists(Constant *C) { return ValueAsMetadata::getConstantIfExists(C); } @@ -403,6 +418,7 @@ public: static LocalAsMetadata *get(Value *Local) { return ValueAsMetadata::getLocal(Local); } + static LocalAsMetadata *getIfExists(Value *Local) { return ValueAsMetadata::getLocalIfExists(Local); } @@ -463,6 +479,7 @@ public: namespace mdconst { namespace detail { + template T &make(); template struct HasDereference { typedef char Yes[1]; @@ -484,6 +501,7 @@ template struct IsValidReference { static const bool value = std::is_base_of::value && std::is_convertible::value; }; + } // end namespace detail /// \brief Check whether Metadata has a Value. @@ -568,14 +586,14 @@ dyn_extract_or_null(Y &&MD) { class MDString : public Metadata { friend class StringMapEntry; - MDString(const MDString &) = delete; - MDString &operator=(MDString &&) = delete; - MDString &operator=(const MDString &) = delete; - StringMapEntry *Entry; MDString() : Metadata(MDStringKind, Uniqued), Entry(nullptr) {} public: + MDString(const MDString &) = delete; + MDString &operator=(MDString &&) = delete; + MDString &operator=(const MDString &) = delete; + static MDString *get(LLVMContext &Context, StringRef Str); static MDString *get(LLVMContext &Context, const char *Str) { return get(Context, Str ? StringRef(Str) : StringRef()); @@ -634,15 +652,18 @@ struct DenseMapInfo { return AAMDNodes(DenseMapInfo::getEmptyKey(), nullptr, nullptr); } + static inline AAMDNodes getTombstoneKey() { return AAMDNodes(DenseMapInfo::getTombstoneKey(), nullptr, nullptr); } + static unsigned getHashValue(const AAMDNodes &Val) { return DenseMapInfo::getHashValue(Val.TBAA) ^ DenseMapInfo::getHashValue(Val.Scope) ^ DenseMapInfo::getHashValue(Val.NoAlias); } + static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS) { return LHS == RHS; } @@ -656,15 +677,14 @@ struct DenseMapInfo { /// /// In particular, this is used by \a MDNode. class MDOperand { + Metadata *MD = nullptr; + +public: + MDOperand() = default; MDOperand(MDOperand &&) = delete; MDOperand(const MDOperand &) = delete; MDOperand &operator=(MDOperand &&) = delete; MDOperand &operator=(const MDOperand &) = delete; - - Metadata *MD; - -public: - MDOperand() : MD(nullptr) {} ~MDOperand() { untrack(); } Metadata *get() const { return MD; } @@ -691,6 +711,7 @@ private: MetadataTracking::track(MD); } } + void untrack() { assert(static_cast(this) == &MD && "Expected same address"); if (MD) @@ -715,13 +736,6 @@ template <> struct simplify_type { class ContextAndReplaceableUses { PointerUnion Ptr; - ContextAndReplaceableUses() = delete; - ContextAndReplaceableUses(ContextAndReplaceableUses &&) = delete; - ContextAndReplaceableUses(const ContextAndReplaceableUses &) = delete; - ContextAndReplaceableUses &operator=(ContextAndReplaceableUses &&) = delete; - ContextAndReplaceableUses & - operator=(const ContextAndReplaceableUses &) = delete; - public: ContextAndReplaceableUses(LLVMContext &Context) : Ptr(&Context) {} ContextAndReplaceableUses( @@ -729,6 +743,12 @@ public: : Ptr(ReplaceableUses.release()) { assert(getReplaceableUses() && "Expected non-null replaceable uses"); } + ContextAndReplaceableUses() = delete; + ContextAndReplaceableUses(ContextAndReplaceableUses &&) = delete; + ContextAndReplaceableUses(const ContextAndReplaceableUses &) = delete; + ContextAndReplaceableUses &operator=(ContextAndReplaceableUses &&) = delete; + ContextAndReplaceableUses & + operator=(const ContextAndReplaceableUses &) = delete; ~ContextAndReplaceableUses() { delete getReplaceableUses(); } operator LLVMContext &() { return getContext(); } @@ -737,11 +757,13 @@ public: bool hasReplaceableUses() const { return Ptr.is(); } + LLVMContext &getContext() const { if (hasReplaceableUses()) return getReplaceableUses()->getContext(); return *Ptr.get(); } + ReplaceableMetadataImpl *getReplaceableUses() const { if (hasReplaceableUses()) return Ptr.get(); @@ -809,10 +831,6 @@ class MDNode : public Metadata { friend class ReplaceableMetadataImpl; friend class LLVMContextImpl; - MDNode(const MDNode &) = delete; - void operator=(const MDNode &) = delete; - void *operator new(size_t) = delete; - unsigned NumOperands; unsigned NumUnresolved; @@ -847,6 +865,10 @@ protected: } public: + MDNode(const MDNode &) = delete; + void operator=(const MDNode &) = delete; + void *operator new(size_t) = delete; + static inline MDTuple *get(LLVMContext &Context, ArrayRef MDs); static inline MDTuple *getIfExists(LLVMContext &Context, ArrayRef MDs); @@ -1002,9 +1024,11 @@ public: op_iterator op_begin() const { return const_cast(this)->mutable_begin(); } + op_iterator op_end() const { return const_cast(this)->mutable_end(); } + op_range operands() const { return op_range(op_begin(), op_end()); } const MDOperand &getOperand(unsigned I) const { @@ -1054,6 +1078,7 @@ class MDTuple : public MDNode { : MDNode(C, MDTupleKind, Storage, Vals) { setHash(Hash); } + ~MDTuple() { dropAllReferences(); } void setHash(unsigned Hash) { SubclassData32 = Hash; } @@ -1074,6 +1099,7 @@ public: static MDTuple *get(LLVMContext &Context, ArrayRef MDs) { return getImpl(Context, MDs, Uniqued); } + static MDTuple *getIfExists(LLVMContext &Context, ArrayRef MDs) { return getImpl(Context, MDs, Uniqued, /* ShouldCreate */ false); } @@ -1106,12 +1132,15 @@ public: MDTuple *MDNode::get(LLVMContext &Context, ArrayRef MDs) { return MDTuple::get(Context, MDs); } + MDTuple *MDNode::getIfExists(LLVMContext &Context, ArrayRef MDs) { return MDTuple::getIfExists(Context, MDs); } + MDTuple *MDNode::getDistinct(LLVMContext &Context, ArrayRef MDs) { return MDTuple::getDistinct(Context, MDs); } + TempMDTuple MDNode::getTemporary(LLVMContext &Context, ArrayRef MDs) { return MDTuple::getTemporary(Context, MDs); @@ -1133,16 +1162,20 @@ class TypedMDOperandIterator public: TypedMDOperandIterator() = default; explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {} + T *operator*() const { return cast_or_null(*I); } + TypedMDOperandIterator &operator++() { ++I; return *this; } + TypedMDOperandIterator operator++(int) { TypedMDOperandIterator Temp(*this); ++I; return Temp; } + bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; } bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; } }; @@ -1213,16 +1246,16 @@ class DistinctMDOperandPlaceholder : public Metadata { Metadata **Use = nullptr; - DistinctMDOperandPlaceholder() = delete; - DistinctMDOperandPlaceholder(DistinctMDOperandPlaceholder &&) = delete; - DistinctMDOperandPlaceholder(const DistinctMDOperandPlaceholder &) = delete; - public: explicit DistinctMDOperandPlaceholder(unsigned ID) : Metadata(DistinctMDOperandPlaceholderKind, Distinct) { SubclassData32 = ID; } + DistinctMDOperandPlaceholder() = delete; + DistinctMDOperandPlaceholder(DistinctMDOperandPlaceholder &&) = delete; + DistinctMDOperandPlaceholder(const DistinctMDOperandPlaceholder &) = delete; + ~DistinctMDOperandPlaceholder() { if (Use) *Use = nullptr; @@ -1249,7 +1282,6 @@ public: class NamedMDNode : public ilist_node { friend class LLVMContextImpl; friend class Module; - NamedMDNode(const NamedMDNode &) = delete; std::string Name; Module *Parent; @@ -1262,30 +1294,35 @@ class NamedMDNode : public ilist_node { template class op_iterator_impl : public std::iterator { - const NamedMDNode *Node; - unsigned Idx; + const NamedMDNode *Node = nullptr; + unsigned Idx = 0; + op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) { } friend class NamedMDNode; public: - op_iterator_impl() : Node(nullptr), Idx(0) { } + op_iterator_impl() = default; bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; } bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; } + op_iterator_impl &operator++() { ++Idx; return *this; } + op_iterator_impl operator++(int) { op_iterator_impl tmp(*this); operator++(); return tmp; } + op_iterator_impl &operator--() { --Idx; return *this; } + op_iterator_impl operator--(int) { op_iterator_impl tmp(*this); operator--(); @@ -1296,6 +1333,9 @@ class NamedMDNode : public ilist_node { }; public: + NamedMDNode(const NamedMDNode &) = delete; + ~NamedMDNode(); + /// \brief Drop all references and remove the node from parent module. void eraseFromParent(); @@ -1304,8 +1344,6 @@ public: /// Drop all references to this node's operands. void clearOperands(); - ~NamedMDNode(); - /// \brief Get the module that holds this named metadata collection. inline Module *getParent() { return Parent; } inline const Module *getParent() const { return Parent; } @@ -1339,6 +1377,6 @@ public: } }; -} // end llvm namespace +} // end namespace llvm #endif // LLVM_IR_METADATA_H diff --git a/llvm/include/llvm/IR/User.h b/llvm/include/llvm/IR/User.h index c628c82..e6fe974 100644 --- a/llvm/include/llvm/IR/User.h +++ b/llvm/include/llvm/IR/User.h @@ -21,8 +21,15 @@ #include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/IR/Use.h" #include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" +#include +#include +#include +#include namespace llvm { @@ -36,9 +43,9 @@ template struct OperandTraits; class User : public Value { - User(const User &) = delete; template friend struct HungoffOperandTraits; + virtual void anchor(); LLVM_ATTRIBUTE_ALWAYS_INLINE inline static void * @@ -87,8 +94,9 @@ protected: void growHungoffUses(unsigned N, bool IsPhi = false); public: - ~User() override { - } + User(const User &) = delete; + ~User() override = default; + /// \brief Free memory allocated for User and Use objects. void operator delete(void *Usr); /// \brief Placement delete - required by std, but never called. @@ -99,6 +107,7 @@ public: void operator delete(void*, unsigned, bool) { llvm_unreachable("Constructor throws?"); } + protected: template static Use &OpFrom(const U *that) { return Idx < 0 @@ -111,6 +120,7 @@ protected: template const Use &Op() const { return OpFrom(this); } + private: Use *&getHungOffOperands() { return *(reinterpret_cast(this) - 1); } @@ -123,6 +133,7 @@ private: "Setting operand list only required for hung off uses"); getHungOffOperands() = NewList; } + public: Use *getOperandList() { return HasHungOffUses ? getHungOffOperands() : getIntrusiveOperands(); @@ -130,10 +141,12 @@ public: const Use *getOperandList() const { return const_cast(this)->getOperandList(); } + Value *getOperand(unsigned i) const { assert(i < NumUserOperands && "getOperand() out of range!"); return getOperandList()[i]; } + void setOperand(unsigned i, Value *Val) { assert(i < NumUserOperands && "setOperand() out of range!"); assert((!isa((const Value*)this) || @@ -141,6 +154,7 @@ public: "Cannot mutate a constant with setOperand!"); getOperandList()[i] = Val; } + const Use &getOperandUse(unsigned i) const { assert(i < NumUserOperands && "getOperandUse() out of range!"); return getOperandList()[i]; @@ -267,6 +281,6 @@ template<> struct simplify_type { } }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_USER_H diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h index bb67352..b5c1b85 100644 --- a/llvm/include/llvm/IR/Value.h +++ b/llvm/include/llvm/IR/Value.h @@ -18,12 +18,14 @@ #include "llvm/IR/Use.h" #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/Casting.h" +#include "llvm-c/Types.h" +#include +#include namespace llvm { class APInt; class Argument; -class AssemblyAnnotationWriter; class BasicBlock; class Constant; class ConstantData; @@ -41,12 +43,10 @@ class Instruction; class LLVMContext; class Module; class ModuleSlotTracker; +class raw_ostream; class StringRef; class Twine; class Type; -class ValueHandleBase; -class ValueSymbolTable; -class raw_ostream; template class StringMapEntry; typedef StringMapEntry ValueName; @@ -77,6 +77,7 @@ class Value { const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast) unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this? + protected: /// \brief Hold subclass data that can be dropped. /// @@ -134,6 +135,7 @@ private: U = U->getNext(); return *this; } + use_iterator_impl operator++(int) { // Postincrement auto tmp = *this; ++*this; @@ -160,7 +162,7 @@ private: friend class Value; public: - user_iterator_impl() {} + user_iterator_impl() = default; bool operator==(const user_iterator_impl &x) const { return UI == x.UI; } bool operator!=(const user_iterator_impl &x) const { return !operator==(x); } @@ -172,6 +174,7 @@ private: ++UI; return *this; } + user_iterator_impl operator++(int) { // Postincrement auto tmp = *this; ++*this; @@ -192,12 +195,12 @@ private: Use &getUse() const { return *UI; } }; - void operator=(const Value &) = delete; - Value(const Value &) = delete; - protected: Value(Type *Ty, unsigned scid); + public: + Value(const Value &) = delete; + void operator=(const Value &) = delete; virtual ~Value(); /// \brief Support for debugging, callable in GDB: V->dump() @@ -252,7 +255,6 @@ public: /// \param Name The new name; or "" if the value's name should be removed. void setName(const Twine &Name); - /// \brief Transfer the name from V to this value. /// /// After taking V's name, sets V's name to empty. @@ -788,11 +790,14 @@ template <> struct isa_impl { template<> class PointerLikeTypeTraits { typedef Value* PT; + public: static inline void *getAsVoidPointer(PT P) { return P; } + static inline PT getFromVoidPointer(void *P) { return static_cast(P); } + enum { NumLowBitsAvailable = 2 }; }; @@ -818,6 +823,6 @@ inline LLVMValueRef *wrap(const Value **Vals) { return reinterpret_cast(const_cast(Vals)); } -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_VALUE_H