From deaf695138e91e6abc5b29f89a142a71eb13bfea Mon Sep 17 00:00:00 2001 From: Eugene Zelenko Date: Fri, 17 Feb 2017 00:00:09 +0000 Subject: [PATCH] [IR] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). llvm-svn: 295383 --- llvm/include/llvm/IR/Attributes.h | 51 +++++++++-------- llvm/include/llvm/IR/Comdat.h | 6 +- llvm/include/llvm/IR/InlineAsm.h | 24 ++++---- llvm/include/llvm/IR/Metadata.h | 13 ++--- llvm/include/llvm/IR/SymbolTableListTraits.h | 28 +++++---- llvm/include/llvm/IR/TrackingMDRef.h | 17 ++++-- llvm/include/llvm/IR/TypeFinder.h | 14 ++--- llvm/include/llvm/IR/UseListOrder.h | 7 +-- llvm/include/llvm/IR/ValueSymbolTable.h | 45 ++++++++------- llvm/lib/IR/Attributes.cpp | 60 +++++++++++++------- llvm/lib/IR/Comdat.cpp | 8 ++- llvm/lib/IR/InlineAsm.cpp | 49 ++++++++-------- llvm/lib/IR/Metadata.cpp | 39 +++++++++++-- llvm/lib/IR/TypeFinder.cpp | 13 ++++- llvm/lib/IR/ValueSymbolTable.cpp | 5 +- 15 files changed, 228 insertions(+), 151 deletions(-) diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index 15783858dd32..c1a377787563 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -1,4 +1,4 @@ -//===-- llvm/Attributes.h - Container for Attributes ------------*- C++ -*-===// +//===- llvm/Attributes.h - Container for Attributes -------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -18,14 +18,17 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/FoldingSet.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/Optional.h" -#include "llvm/Support/Compiler.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm-c/Types.h" #include #include +#include #include #include +#include namespace llvm { @@ -33,7 +36,6 @@ class AttrBuilder; class AttributeImpl; class AttributeSetImpl; class AttributeSetNode; -class Constant; template struct DenseMapInfo; class Function; class LLVMContext; @@ -73,11 +75,12 @@ public: }; private: - AttributeImpl *pImpl; + AttributeImpl *pImpl = nullptr; + Attribute(AttributeImpl *A) : pImpl(A) {} public: - Attribute() : pImpl(nullptr) {} + Attribute() = default; //===--------------------------------------------------------------------===// // Attribute Construction @@ -211,30 +214,31 @@ private: friend class AttrBuilder; friend class AttributeSetImpl; friend class AttributeSetNode; + template friend struct DenseMapInfo; /// \brief The attributes that we are managing. This can be null to represent /// the empty attributes list. - AttributeSetImpl *pImpl; + AttributeSetImpl *pImpl = nullptr; /// \brief The attributes for the specified index are returned. AttributeSetNode *getAttributes(unsigned Index) const; /// \brief Create an AttributeSet with the specified parameters in it. static AttributeSet get(LLVMContext &C, - ArrayRef > Attrs); + ArrayRef> Attrs); static AttributeSet get(LLVMContext &C, ArrayRef > Attrs); + AttributeSetNode*>> Attrs); static AttributeSet getImpl(LLVMContext &C, ArrayRef > Attrs); + AttributeSetNode*>> Attrs); explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {} public: - AttributeSet() : pImpl(nullptr) {} + AttributeSet() = default; //===--------------------------------------------------------------------===// // AttributeSet Construction and Mutation @@ -424,15 +428,18 @@ template<> struct DenseMapInfo { Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; return AttributeSet(reinterpret_cast(Val)); } + static inline AttributeSet getTombstoneKey() { uintptr_t Val = static_cast(-2); Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; return AttributeSet(reinterpret_cast(Val)); } + static unsigned getHashValue(AttributeSet AS) { return (unsigned((uintptr_t)AS.pImpl) >> 4) ^ (unsigned((uintptr_t)AS.pImpl) >> 9); } + static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; } }; @@ -445,19 +452,15 @@ template<> struct DenseMapInfo { class AttrBuilder { std::bitset Attrs; std::map TargetDepAttrs; - uint64_t Alignment; - uint64_t StackAlignment; - uint64_t DerefBytes; - uint64_t DerefOrNullBytes; - uint64_t AllocSizeArgs; + uint64_t Alignment = 0; + uint64_t StackAlignment = 0; + uint64_t DerefBytes = 0; + uint64_t DerefOrNullBytes = 0; + uint64_t AllocSizeArgs = 0; public: - AttrBuilder() - : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0), - DerefOrNullBytes(0), AllocSizeArgs(0) {} - AttrBuilder(const Attribute &A) - : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0), - DerefOrNullBytes(0), AllocSizeArgs(0) { + AttrBuilder() = default; + AttrBuilder(const Attribute &A) { addAttribute(A); } AttrBuilder(AttributeSet AS, unsigned Idx); @@ -562,8 +565,8 @@ public: typedef std::pair td_type; typedef std::map::iterator td_iterator; typedef std::map::const_iterator td_const_iterator; - typedef llvm::iterator_range td_range; - typedef llvm::iterator_range td_const_range; + typedef iterator_range td_range; + typedef iterator_range td_const_range; td_iterator td_begin() { return TargetDepAttrs.begin(); } td_iterator td_end() { return TargetDepAttrs.end(); } @@ -600,4 +603,4 @@ void mergeAttributesForInlining(Function &Caller, const Function &Callee); } // end llvm namespace -#endif +#endif // LLVM_IR_ATTRIBUTES_H diff --git a/llvm/include/llvm/IR/Comdat.h b/llvm/include/llvm/IR/Comdat.h index f4a391c31ae2..fa87093ca50a 100644 --- a/llvm/include/llvm/IR/Comdat.h +++ b/llvm/include/llvm/IR/Comdat.h @@ -1,4 +1,4 @@ -//===-- llvm/IR/Comdat.h - Comdat definitions -------------------*- C++ -*-===// +//===- llvm/IR/Comdat.h - Comdat definitions --------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -51,8 +51,8 @@ private: Comdat(); // Points to the map in Module. - StringMapEntry *Name; - SelectionKind SK; + StringMapEntry *Name = nullptr; + SelectionKind SK = Any; }; inline raw_ostream &operator<<(raw_ostream &OS, const Comdat &C) { diff --git a/llvm/include/llvm/IR/InlineAsm.h b/llvm/include/llvm/IR/InlineAsm.h index f95509b9b09a..5d2f72d211ff 100644 --- a/llvm/include/llvm/IR/InlineAsm.h +++ b/llvm/include/llvm/IR/InlineAsm.h @@ -1,4 +1,4 @@ -//===-- llvm/InlineAsm.h - Class to represent inline asm strings-*- C++ -*-===// +//===- llvm/InlineAsm.h - Class to represent inline asm strings -*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -102,12 +102,14 @@ public: /// input constraint is required to match it (e.g. "0"). The value is the /// constraint number that matches this one (for example, if this is /// constraint #0 and constraint #4 has the value "0", this will be 4). - signed char MatchingInput; + signed char MatchingInput = -1; + /// Code - The constraint code, either the register name (in braces) or the /// constraint letter/number. ConstraintCodeVector Codes; + /// Default constructor. - SubConstraintInfo() : MatchingInput(-1) {} + SubConstraintInfo() = default; }; typedef std::vector SubConstraintInfoVector; @@ -117,17 +119,17 @@ public: struct ConstraintInfo { /// Type - The basic type of the constraint: input/output/clobber /// - ConstraintPrefix Type; + ConstraintPrefix Type = isInput; /// isEarlyClobber - "&": output operand writes result before inputs are all /// read. This is only ever set for an output operand. - bool isEarlyClobber; + bool isEarlyClobber = false; /// MatchingInput - If this is not -1, this is an output constraint where an /// input constraint is required to match it (e.g. "0"). The value is the /// constraint number that matches this one (for example, if this is /// constraint #0 and constraint #4 has the value "0", this will be 4). - signed char MatchingInput; + signed char MatchingInput = -1; /// hasMatchingInput - Return true if this is an output constraint that has /// a matching input constraint. @@ -135,30 +137,30 @@ public: /// isCommutative - This is set to true for a constraint that is commutative /// with the next operand. - bool isCommutative; + bool isCommutative = false; /// isIndirect - True if this operand is an indirect operand. This means /// that the address of the source or destination is present in the call /// instruction, instead of it being returned or passed in explicitly. This /// is represented with a '*' in the asm string. - bool isIndirect; + bool isIndirect = false; /// Code - The constraint code, either the register name (in braces) or the /// constraint letter/number. ConstraintCodeVector Codes; /// isMultipleAlternative - '|': has multiple-alternative constraints. - bool isMultipleAlternative; + bool isMultipleAlternative = false; /// multipleAlternatives - If there are multiple alternative constraints, /// this array will contain them. Otherwise it will be empty. SubConstraintInfoVector multipleAlternatives; /// The currently selected alternative constraint index. - unsigned currentAlternativeIndex; + unsigned currentAlternativeIndex = 0; /// Default constructor. - ConstraintInfo(); + ConstraintInfo() = default; /// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the /// fields in this structure. If the constraint string is not understood, diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index 46c785a1c05d..0647e4253d3c 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -269,12 +269,11 @@ public: private: LLVMContext &Context; - uint64_t NextIndex; + uint64_t NextIndex = 0; SmallDenseMap, 4> UseMap; public: - ReplaceableMetadataImpl(LLVMContext &Context) - : Context(Context), NextIndex(0) {} + ReplaceableMetadataImpl(LLVMContext &Context) : Context(Context) {} ~ReplaceableMetadataImpl() { assert(UseMap.empty() && "Cannot destroy in-use replaceable metadata"); @@ -586,8 +585,9 @@ dyn_extract_or_null(Y &&MD) { class MDString : public Metadata { friend class StringMapEntry; - StringMapEntry *Entry; - MDString() : Metadata(MDStringKind, Uniqued), Entry(nullptr) {} + StringMapEntry *Entry = nullptr; + + MDString() : Metadata(MDStringKind, Uniqued) {} public: MDString(const MDString &) = delete; @@ -1062,7 +1062,6 @@ public: static MDNode *getMostGenericRange(MDNode *A, MDNode *B); static MDNode *getMostGenericAliasScope(MDNode *A, MDNode *B); static MDNode *getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B); - }; /// \brief Tuple of metadata. @@ -1284,7 +1283,7 @@ class NamedMDNode : public ilist_node { friend class Module; std::string Name; - Module *Parent; + Module *Parent = nullptr; void *Operands; // SmallVector void setParent(Module *M) { Parent = M; } diff --git a/llvm/include/llvm/IR/SymbolTableListTraits.h b/llvm/include/llvm/IR/SymbolTableListTraits.h index 5c6d58affd7a..49a5fb21297d 100644 --- a/llvm/include/llvm/IR/SymbolTableListTraits.h +++ b/llvm/include/llvm/IR/SymbolTableListTraits.h @@ -1,4 +1,4 @@ -//===-- llvm/SymbolTableListTraits.h - Traits for iplist --------*- C++ -*-===// +//===- llvm/SymbolTableListTraits.h - Traits for iplist ---------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -26,8 +26,19 @@ #define LLVM_IR_SYMBOLTABLELISTTRAITS_H #include "llvm/ADT/ilist.h" +#include "llvm/ADT/simple_ilist.h" +#include namespace llvm { + +class Argument; +class BasicBlock; +class Function; +class GlobalAlias; +class GlobalIFunc; +class GlobalVariable; +class Instruction; +class Module; class ValueSymbolTable; /// Template metafunction to get the parent type for a symbol table list. @@ -35,14 +46,7 @@ class ValueSymbolTable; /// Implementations create a typedef called \c type so that we only need a /// single template parameter for the list and traits. template struct SymbolTableListParentType {}; -class Argument; -class BasicBlock; -class Function; -class Instruction; -class GlobalVariable; -class GlobalAlias; -class GlobalIFunc; -class Module; + #define DEFINE_SYMBOL_TABLE_PARENT_TYPE(NODE, PARENT) \ template <> struct SymbolTableListParentType { typedef PARENT type; }; DEFINE_SYMBOL_TABLE_PARENT_TYPE(Instruction, BasicBlock) @@ -67,7 +71,7 @@ class SymbolTableListTraits : public ilist_alloc_traits { typename SymbolTableListParentType::type ItemParentClass; public: - SymbolTableListTraits() {} + SymbolTableListTraits() = default; private: /// getListOwner - Return the object that owns this list. If this is a list @@ -109,6 +113,6 @@ template class SymbolTableList : public iplist_impl, SymbolTableListTraits> {}; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_SYMBOLTABLELISTTRAITS_H diff --git a/llvm/include/llvm/IR/TrackingMDRef.h b/llvm/include/llvm/IR/TrackingMDRef.h index fe513a8f9795..12b196432006 100644 --- a/llvm/include/llvm/IR/TrackingMDRef.h +++ b/llvm/include/llvm/IR/TrackingMDRef.h @@ -15,6 +15,8 @@ #define LLVM_IR_TRACKINGMDREF_H #include "llvm/IR/Metadata.h" +#include +#include namespace llvm { @@ -22,14 +24,15 @@ namespace llvm { /// /// This class behaves like \a TrackingVH, but for metadata. class TrackingMDRef { - Metadata *MD; + Metadata *MD = nullptr; public: - TrackingMDRef() : MD(nullptr) {} + TrackingMDRef() = default; explicit TrackingMDRef(Metadata *MD) : MD(MD) { track(); } TrackingMDRef(TrackingMDRef &&X) : MD(X.MD) { retrack(X); } TrackingMDRef(const TrackingMDRef &X) : MD(X.MD) { track(); } + TrackingMDRef &operator=(TrackingMDRef &&X) { if (&X == this) return *this; @@ -39,6 +42,7 @@ public: retrack(X); return *this; } + TrackingMDRef &operator=(const TrackingMDRef &X) { if (&X == this) return *this; @@ -48,6 +52,7 @@ public: track(); return *this; } + ~TrackingMDRef() { untrack(); } Metadata *get() const { return MD; } @@ -80,10 +85,12 @@ private: if (MD) MetadataTracking::track(MD); } + void untrack() { if (MD) MetadataTracking::untrack(MD); } + void retrack(TrackingMDRef &X) { assert(MD == X.MD && "Expected values to match"); if (X.MD) { @@ -101,15 +108,17 @@ template class TypedTrackingMDRef { TrackingMDRef Ref; public: - TypedTrackingMDRef() {} + TypedTrackingMDRef() = default; explicit TypedTrackingMDRef(T *MD) : Ref(static_cast(MD)) {} TypedTrackingMDRef(TypedTrackingMDRef &&X) : Ref(std::move(X.Ref)) {} TypedTrackingMDRef(const TypedTrackingMDRef &X) : Ref(X.Ref) {} + TypedTrackingMDRef &operator=(TypedTrackingMDRef &&X) { Ref = std::move(X.Ref); return *this; } + TypedTrackingMDRef &operator=(const TypedTrackingMDRef &X) { Ref = X.Ref; return *this; @@ -162,4 +171,4 @@ template struct simplify_type> { } // end namespace llvm -#endif +#endif // LLVM_IR_TRACKINGMDREF_H diff --git a/llvm/include/llvm/IR/TypeFinder.h b/llvm/include/llvm/IR/TypeFinder.h index 046f85caec9d..48c4f1161aa1 100644 --- a/llvm/include/llvm/IR/TypeFinder.h +++ b/llvm/include/llvm/IR/TypeFinder.h @@ -1,4 +1,4 @@ -//===-- llvm/IR/TypeFinder.h - Class to find used struct types --*- C++ -*-===// +//===- llvm/IR/TypeFinder.h - Class to find used struct types ---*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,8 +15,7 @@ #define LLVM_IR_TYPEFINDER_H #include "llvm/ADT/DenseSet.h" -#include "llvm/IR/Metadata.h" -#include "llvm/IR/Type.h" +#include #include namespace llvm { @@ -24,6 +23,7 @@ namespace llvm { class MDNode; class Module; class StructType; +class Type; class Value; /// TypeFinder - Walk over a module, identifying all of the types that are @@ -36,10 +36,10 @@ class TypeFinder { DenseSet VisitedTypes; std::vector StructTypes; - bool OnlyNamed; + bool OnlyNamed = false; public: - TypeFinder() : OnlyNamed(false) {} + TypeFinder() = default; void run(const Module &M, bool onlyNamed); void clear(); @@ -77,6 +77,6 @@ private: void incorporateMDNode(const MDNode *V); }; -} // end llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_TYPEFINDER_H diff --git a/llvm/include/llvm/IR/UseListOrder.h b/llvm/include/llvm/IR/UseListOrder.h index efff208295b6..ebe99223facd 100644 --- a/llvm/include/llvm/IR/UseListOrder.h +++ b/llvm/include/llvm/IR/UseListOrder.h @@ -20,20 +20,19 @@ namespace llvm { -class Module; class Function; class Value; /// \brief Structure to hold a use-list order. struct UseListOrder { - const Value *V; - const Function *F; + const Value *V = nullptr; + const Function *F = nullptr; std::vector Shuffle; UseListOrder(const Value *V, const Function *F, size_t ShuffleSize) : V(V), F(F), Shuffle(ShuffleSize) {} - UseListOrder() : V(nullptr), F(nullptr) {} + UseListOrder() = default; UseListOrder(UseListOrder &&) = default; UseListOrder &operator=(UseListOrder &&) = default; }; diff --git a/llvm/include/llvm/IR/ValueSymbolTable.h b/llvm/include/llvm/IR/ValueSymbolTable.h index 61a12db403ea..9e86751dae6f 100644 --- a/llvm/include/llvm/IR/ValueSymbolTable.h +++ b/llvm/include/llvm/IR/ValueSymbolTable.h @@ -1,4 +1,4 @@ -//===-- llvm/ValueSymbolTable.h - Implement a Value Symtab ------*- C++ -*-===// +//===- llvm/ValueSymbolTable.h - Implement a Value Symtab -------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,31 +15,36 @@ #define LLVM_IR_VALUESYMBOLTABLE_H #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/Value.h" -#include "llvm/Support/DataTypes.h" +#include namespace llvm { - template class SymbolTableListTraits; - template class SmallString; - class BasicBlock; - class Function; - class NamedMDNode; - class Module; - class StringRef; + +class Argument; +class BasicBlock; +class Function; +class GlobalAlias; +class GlobalIFunc; +class GlobalVariable; +class Instruction; +template class SmallString; +template class SymbolTableListTraits; /// This class provides a symbol table of name/value pairs. It is essentially /// a std::map but has a controlled interface provided by /// LLVM as well as ensuring uniqueness of names. /// class ValueSymbolTable { - friend class Value; friend class SymbolTableListTraits; friend class SymbolTableListTraits; - friend class SymbolTableListTraits; friend class SymbolTableListTraits; - friend class SymbolTableListTraits; friend class SymbolTableListTraits; friend class SymbolTableListTraits; + friend class SymbolTableListTraits; + friend class SymbolTableListTraits; + friend class Value; + /// @name Types /// @{ public: @@ -55,14 +60,14 @@ public: /// @} /// @name Constructors /// @{ -public: - ValueSymbolTable() : vmap(0), LastUnique(0) {} + + ValueSymbolTable() : vmap(0) {} ~ValueSymbolTable(); /// @} /// @name Accessors /// @{ -public: + /// This method finds the value with the given \p Name in the /// the symbol table. /// @returns the value associated with the \p Name @@ -84,7 +89,7 @@ public: /// @} /// @name Iteration /// @{ -public: + /// @brief Get an iterator that from the beginning of the symbol table. inline iterator begin() { return vmap.begin(); } @@ -122,13 +127,13 @@ private: /// @} /// @name Internal Data /// @{ -private: + ValueMap vmap; ///< The map that holds the symbol table. - mutable uint32_t LastUnique; ///< Counter for tracking unique names + mutable uint32_t LastUnique = 0; ///< Counter for tracking unique names /// @} }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_IR_VALUESYMBOLTABLE_H diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 2c1bc2b66aa6..92cb6dee6315 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1,4 +1,4 @@ -//===-- Attributes.cpp - Implement AttributesList -------------------------===// +//===- Attributes.cpp - Implement AttributesList --------------------------===// // // The LLVM Compiler Infrastructure // @@ -13,19 +13,35 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/Attributes.h" -#include "llvm/IR/Function.h" #include "AttributeImpl.h" +#include "AttributeSetNode.h" #include "LLVMContextImpl.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/FoldingSet.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/LLVMContext.h" #include "llvm/IR/Type.h" -#include "llvm/Support/Atomic.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/Mutex.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include +#include +#include +#include +#include +#include +#include +#include + using namespace llvm; //===----------------------------------------------------------------------===// @@ -411,9 +427,12 @@ bool Attribute::operator<(Attribute A) const { //===----------------------------------------------------------------------===// // Pin the vtables to this file. -AttributeImpl::~AttributeImpl() {} +AttributeImpl::~AttributeImpl() = default; + void EnumAttributeImpl::anchor() {} + void IntAttributeImpl::anchor() {} + void StringAttributeImpl::anchor() {} bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const { @@ -593,7 +612,7 @@ LLVM_DUMP_METHOD void AttributeSetImpl::dump() const { AttributeSet AttributeSet::getImpl(LLVMContext &C, - ArrayRef > Attrs) { + ArrayRef> Attrs) { LLVMContextImpl *pImpl = C.pImpl; FoldingSetNodeID ID; AttributeSetImpl::Profile(ID, Attrs); @@ -616,7 +635,7 @@ AttributeSet::getImpl(LLVMContext &C, } AttributeSet AttributeSet::get(LLVMContext &C, - ArrayRef > Attrs){ + ArrayRef> Attrs) { // If there are no attributes then return a null AttributesList pointer. if (Attrs.empty()) return AttributeSet(); @@ -635,7 +654,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes // list. SmallVector, 8> AttrPairVec; - for (ArrayRef >::iterator I = Attrs.begin(), + for (ArrayRef>::iterator I = Attrs.begin(), E = Attrs.end(); I != E; ) { unsigned Index = I->first; SmallVector AttrVec; @@ -652,7 +671,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef > Attrs) { + AttributeSetNode*>> Attrs) { // If there are no attributes then return a null AttributesList pointer. if (Attrs.empty()) return AttributeSet(); @@ -760,7 +779,7 @@ AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, StringRef Kind, StringRef Value) const { - llvm::AttrBuilder B; + AttrBuilder B; B.addAttribute(Kind, Value); return addAttributes(C, Index, AttributeSet::get(C, Index, B)); } @@ -937,7 +956,7 @@ AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index, AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const { - llvm::AttrBuilder B; + AttrBuilder B; B.addDereferenceableAttr(Bytes); return addAttributes(C, Index, AttributeSet::get(C, Index, B)); } @@ -945,7 +964,7 @@ AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index AttributeSet AttributeSet::addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const { - llvm::AttrBuilder B; + AttrBuilder B; B.addDereferenceableOrNullAttr(Bytes); return addAttributes(C, Index, AttributeSet::get(C, Index, B)); } @@ -954,7 +973,7 @@ AttributeSet AttributeSet::addAllocSizeAttr(LLVMContext &C, unsigned Index, unsigned ElemSizeArg, const Optional &NumElemsArg) { - llvm::AttrBuilder B; + AttrBuilder B; B.addAllocSizeAttr(ElemSizeArg, NumElemsArg); return addAttributes(C, Index, AttributeSet::get(C, Index, B)); } @@ -970,7 +989,7 @@ LLVMContext &AttributeSet::getContext() const { AttributeSet AttributeSet::getParamAttributes(unsigned Index) const { return pImpl && hasAttributes(Index) ? AttributeSet::get(pImpl->getContext(), - ArrayRef >( + ArrayRef>( std::make_pair(Index, getAttributes(Index)))) : AttributeSet(); } @@ -978,7 +997,7 @@ AttributeSet AttributeSet::getParamAttributes(unsigned Index) const { AttributeSet AttributeSet::getRetAttributes() const { return pImpl && hasAttributes(ReturnIndex) ? AttributeSet::get(pImpl->getContext(), - ArrayRef >( + ArrayRef>( std::make_pair(ReturnIndex, getAttributes(ReturnIndex)))) : AttributeSet(); @@ -987,7 +1006,7 @@ AttributeSet AttributeSet::getRetAttributes() const { AttributeSet AttributeSet::getFnAttributes() const { return pImpl && hasAttributes(FunctionIndex) ? AttributeSet::get(pImpl->getContext(), - ArrayRef >( + ArrayRef>( std::make_pair(FunctionIndex, getAttributes(FunctionIndex)))) : AttributeSet(); @@ -1139,9 +1158,7 @@ LLVM_DUMP_METHOD void AttributeSet::dump() const { // AttrBuilder Method Implementations //===----------------------------------------------------------------------===// -AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index) - : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0), - DerefOrNullBytes(0), AllocSizeArgs(0) { +AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index) { AttributeSetImpl *pImpl = AS.pImpl; if (!pImpl) return; @@ -1514,7 +1531,6 @@ bool AttributeFuncs::areInlineCompatible(const Function &Caller, return hasCompatibleFnAttrs(Caller, Callee); } - void AttributeFuncs::mergeAttributesForInlining(Function &Caller, const Function &Callee) { mergeFnAttrs(Caller, Callee); diff --git a/llvm/lib/IR/Comdat.cpp b/llvm/lib/IR/Comdat.cpp index fc1b48d1c190..e27ecad0a884 100644 --- a/llvm/lib/IR/Comdat.cpp +++ b/llvm/lib/IR/Comdat.cpp @@ -1,4 +1,4 @@ -//===-- Comdat.cpp - Implement Metadata classes --------------------------===// +//===- Comdat.cpp - Implement Metadata classes ----------------------------===// // // The LLVM Compiler Infrastructure // @@ -11,12 +11,14 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/Comdat.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/IR/Comdat.h" + using namespace llvm; Comdat::Comdat(Comdat &&C) : Name(C.Name), SK(C.SK) {} -Comdat::Comdat() : Name(nullptr), SK(Comdat::Any) {} +Comdat::Comdat() = default; StringRef Comdat::getName() const { return Name->first(); } diff --git a/llvm/lib/IR/InlineAsm.cpp b/llvm/lib/IR/InlineAsm.cpp index 5a9118571040..8feeeb65d445 100644 --- a/llvm/lib/IR/InlineAsm.cpp +++ b/llvm/lib/IR/InlineAsm.cpp @@ -1,4 +1,4 @@ -//===-- InlineAsm.cpp - Implement the InlineAsm class ---------------------===// +//===- InlineAsm.cpp - Implement the InlineAsm class ----------------------===// // // The LLVM Compiler Infrastructure // @@ -11,28 +11,23 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/InlineAsm.h" #include "ConstantsContext.h" #include "LLVMContextImpl.h" +#include "llvm/ADT/StringRef.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/InlineAsm.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include +#include #include +#include +#include + using namespace llvm; -// Implement the first virtual method in this class in this file so the -// InlineAsm vtable is emitted here. -InlineAsm::~InlineAsm() { -} - -InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString, - StringRef Constraints, bool hasSideEffects, - bool isAlignStack, AsmDialect asmDialect) { - InlineAsmKeyType Key(AsmString, Constraints, FTy, hasSideEffects, - isAlignStack, asmDialect); - LLVMContextImpl *pImpl = FTy->getContext().pImpl; - return pImpl->InlineAsms.getOrCreate(PointerType::getUnqual(FTy), Key); -} - InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString, const std::string &constraints, bool hasSideEffects, bool isAlignStack, AsmDialect asmDialect) @@ -40,12 +35,24 @@ InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString, AsmString(asmString), Constraints(constraints), FTy(FTy), HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack), Dialect(asmDialect) { - // Do various checks on the constraint string and type. assert(Verify(getFunctionType(), constraints) && "Function type not legal for constraints!"); } +// Implement the first virtual method in this class in this file so the +// InlineAsm vtable is emitted here. +InlineAsm::~InlineAsm() = default; + +InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString, + StringRef Constraints, bool hasSideEffects, + bool isAlignStack, AsmDialect asmDialect) { + InlineAsmKeyType Key(AsmString, Constraints, FTy, hasSideEffects, + isAlignStack, asmDialect); + LLVMContextImpl *pImpl = FTy->getContext().pImpl; + return pImpl->InlineAsms.getOrCreate(PointerType::getUnqual(FTy), Key); +} + void InlineAsm::destroyConstant() { getType()->getContext().pImpl->InlineAsms.remove(this); delete this; @@ -55,14 +62,6 @@ FunctionType *InlineAsm::getFunctionType() const { return FTy; } -///Default constructor. -InlineAsm::ConstraintInfo::ConstraintInfo() : - Type(isInput), isEarlyClobber(false), - MatchingInput(-1), isCommutative(false), - isIndirect(false), isMultipleAlternative(false), - currentAlternativeIndex(0) { -} - /// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the /// fields in this structure. If the constraint string is not understood, /// return true, otherwise return false. diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 77787edd964b..ec96b0fcc936 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -11,20 +11,50 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/Metadata.h" #include "LLVMContextImpl.h" #include "MetadataImpl.h" #include "SymbolTableListTraitsImpl.h" -#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.h" #include "llvm/IR/ConstantRange.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalObject.h" +#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" +#include "llvm/IR/TrackingMDRef.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" #include "llvm/IR/ValueHandle.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" +#include +#include +#include +#include +#include +#include +#include +#include using namespace llvm; @@ -1027,8 +1057,7 @@ static SmallVector &getNMDOps(void *Operands) { } NamedMDNode::NamedMDNode(const Twine &N) - : Name(N.str()), Parent(nullptr), - Operands(new SmallVector()) {} + : Name(N.str()), Operands(new SmallVector()) {} NamedMDNode::~NamedMDNode() { dropAllReferences(); @@ -1446,7 +1475,7 @@ void GlobalObject::addTypeMetadata(unsigned Offset, Metadata *TypeID) { addMetadata( LLVMContext::MD_type, *MDTuple::get(getContext(), - {llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + {ConstantAsMetadata::get(llvm::ConstantInt::get( Type::getInt64Ty(getContext()), Offset)), TypeID})); } diff --git a/llvm/lib/IR/TypeFinder.cpp b/llvm/lib/IR/TypeFinder.cpp index dc4c1cffb20c..a178b9ec0f09 100644 --- a/llvm/lib/IR/TypeFinder.cpp +++ b/llvm/lib/IR/TypeFinder.cpp @@ -1,4 +1,4 @@ -//===-- TypeFinder.cpp - Implement the TypeFinder class -------------------===// +//===- TypeFinder.cpp - Implement the TypeFinder class --------------------===// // // The LLVM Compiler Infrastructure // @@ -11,13 +11,22 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/TypeFinder.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/TypeFinder.h" +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include + using namespace llvm; void TypeFinder::run(const Module &M, bool onlyNamed) { diff --git a/llvm/lib/IR/ValueSymbolTable.cpp b/llvm/lib/IR/ValueSymbolTable.cpp index 1eb2498d8acd..0c3946c8661e 100644 --- a/llvm/lib/IR/ValueSymbolTable.cpp +++ b/llvm/lib/IR/ValueSymbolTable.cpp @@ -1,4 +1,4 @@ -//===-- ValueSymbolTable.cpp - Implement the ValueSymbolTable class -------===// +//===- ValueSymbolTable.cpp - Implement the ValueSymbolTable class --------===// // // The LLVM Compiler Infrastructure // @@ -11,10 +11,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/ValueSymbolTable.h" #include "llvm/ADT/SmallString.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" +#include "llvm/IR/ValueSymbolTable.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h"