diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.h')
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.h | 225 |
1 files changed, 141 insertions, 84 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.h b/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.h index 1c7d8746d242..05fd1814e2dc 100644 --- a/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.h +++ b/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.h @@ -57,27 +57,7 @@ class Type; class Value; class ValueHandleBase; -struct DenseMapAPIntKeyInfo { - static inline APInt getEmptyKey() { - APInt V(nullptr, 0); - V.U.VAL = 0; - return V; - } - - static inline APInt getTombstoneKey() { - APInt V(nullptr, 0); - V.U.VAL = 1; - return V; - } - - static unsigned getHashValue(const APInt &Key) { - return static_cast<unsigned>(hash_value(Key)); - } - - static bool isEqual(const APInt &LHS, const APInt &RHS) { - return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS; - } -}; +using DenseMapAPIntKeyInfo = DenseMapInfo<APInt>; struct DenseMapAPFloatKeyInfo { static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); } @@ -366,6 +346,36 @@ template <> struct MDNodeKeyImpl<DISubrange> { } }; +template <> struct MDNodeKeyImpl<DIGenericSubrange> { + Metadata *CountNode; + Metadata *LowerBound; + Metadata *UpperBound; + Metadata *Stride; + + MDNodeKeyImpl(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound, + Metadata *Stride) + : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound), + Stride(Stride) {} + MDNodeKeyImpl(const DIGenericSubrange *N) + : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()), + UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {} + + bool isKeyOf(const DIGenericSubrange *RHS) const { + return (CountNode == RHS->getRawCountNode()) && + (LowerBound == RHS->getRawLowerBound()) && + (UpperBound == RHS->getRawUpperBound()) && + (Stride == RHS->getRawStride()); + } + + unsigned getHashValue() const { + auto *MD = dyn_cast_or_null<ConstantAsMetadata>(CountNode); + if (CountNode && MD) + return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(), + LowerBound, UpperBound, Stride); + return hash_combine(CountNode, LowerBound, UpperBound, Stride); + } +}; + template <> struct MDNodeKeyImpl<DIEnumerator> { APInt Value; MDString *Name; @@ -417,6 +427,37 @@ template <> struct MDNodeKeyImpl<DIBasicType> { } }; +template <> struct MDNodeKeyImpl<DIStringType> { + unsigned Tag; + MDString *Name; + Metadata *StringLength; + Metadata *StringLengthExp; + uint64_t SizeInBits; + uint32_t AlignInBits; + unsigned Encoding; + + MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *StringLength, + Metadata *StringLengthExp, uint64_t SizeInBits, + uint32_t AlignInBits, unsigned Encoding) + : Tag(Tag), Name(Name), StringLength(StringLength), + StringLengthExp(StringLengthExp), SizeInBits(SizeInBits), + AlignInBits(AlignInBits), Encoding(Encoding) {} + MDNodeKeyImpl(const DIStringType *N) + : Tag(N->getTag()), Name(N->getRawName()), + StringLength(N->getRawStringLength()), + StringLengthExp(N->getRawStringLengthExp()), + SizeInBits(N->getSizeInBits()), AlignInBits(N->getAlignInBits()), + Encoding(N->getEncoding()) {} + + bool isKeyOf(const DIStringType *RHS) const { + return Tag == RHS->getTag() && Name == RHS->getRawName() && + SizeInBits == RHS->getSizeInBits() && + AlignInBits == RHS->getAlignInBits() && + Encoding == RHS->getEncoding(); + } + unsigned getHashValue() const { return hash_combine(Tag, Name, Encoding); } +}; + template <> struct MDNodeKeyImpl<DIDerivedType> { unsigned Tag; MDString *Name; @@ -525,6 +566,9 @@ template <> struct MDNodeKeyImpl<DICompositeType> { MDString *Identifier; Metadata *Discriminator; Metadata *DataLocation; + Metadata *Associated; + Metadata *Allocated; + Metadata *Rank; MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, @@ -532,13 +576,15 @@ template <> struct MDNodeKeyImpl<DICompositeType> { Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator, - Metadata *DataLocation) + Metadata *DataLocation, Metadata *Associated, + Metadata *Allocated, Metadata *Rank) : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits), AlignInBits(AlignInBits), Flags(Flags), Elements(Elements), RuntimeLang(RuntimeLang), VTableHolder(VTableHolder), TemplateParams(TemplateParams), Identifier(Identifier), - Discriminator(Discriminator), DataLocation(DataLocation) {} + Discriminator(Discriminator), DataLocation(DataLocation), + Associated(Associated), Allocated(Allocated), Rank(Rank) {} MDNodeKeyImpl(const DICompositeType *N) : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), Scope(N->getRawScope()), @@ -549,7 +595,9 @@ template <> struct MDNodeKeyImpl<DICompositeType> { TemplateParams(N->getRawTemplateParams()), Identifier(N->getRawIdentifier()), Discriminator(N->getRawDiscriminator()), - DataLocation(N->getRawDataLocation()) {} + DataLocation(N->getRawDataLocation()), + Associated(N->getRawAssociated()), Allocated(N->getRawAllocated()), + Rank(N->getRawRank()) {} bool isKeyOf(const DICompositeType *RHS) const { return Tag == RHS->getTag() && Name == RHS->getRawName() && @@ -564,7 +612,9 @@ template <> struct MDNodeKeyImpl<DICompositeType> { TemplateParams == RHS->getRawTemplateParams() && Identifier == RHS->getRawIdentifier() && Discriminator == RHS->getRawDiscriminator() && - DataLocation == RHS->getRawDataLocation(); + DataLocation == RHS->getRawDataLocation() && + Associated == RHS->getRawAssociated() && + Allocated == RHS->getRawAllocated() && Rank == RHS->getRawRank(); } unsigned getHashValue() const { @@ -841,25 +891,28 @@ template <> struct MDNodeKeyImpl<DIModule> { MDString *IncludePath; MDString *APINotesFile; unsigned LineNo; + bool IsDecl; MDNodeKeyImpl(Metadata *File, Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, MDString *IncludePath, - MDString *APINotesFile, unsigned LineNo) + MDString *APINotesFile, unsigned LineNo, bool IsDecl) : File(File), Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros), IncludePath(IncludePath), - APINotesFile(APINotesFile), LineNo(LineNo) {} + APINotesFile(APINotesFile), LineNo(LineNo), IsDecl(IsDecl) {} MDNodeKeyImpl(const DIModule *N) : File(N->getRawFile()), Scope(N->getRawScope()), Name(N->getRawName()), ConfigurationMacros(N->getRawConfigurationMacros()), IncludePath(N->getRawIncludePath()), - APINotesFile(N->getRawAPINotesFile()), LineNo(N->getLineNo()) {} + APINotesFile(N->getRawAPINotesFile()), LineNo(N->getLineNo()), + IsDecl(N->getIsDecl()) {} bool isKeyOf(const DIModule *RHS) const { return Scope == RHS->getRawScope() && Name == RHS->getRawName() && ConfigurationMacros == RHS->getRawConfigurationMacros() && IncludePath == RHS->getRawIncludePath() && APINotesFile == RHS->getRawAPINotesFile() && - File == RHS->getRawFile() && LineNo == RHS->getLineNo(); + File == RHS->getRawFile() && LineNo == RHS->getLineNo() && + IsDecl == RHS->getIsDecl(); } unsigned getHashValue() const { @@ -1204,72 +1257,55 @@ template <class NodeTy> struct MDNodeInfo { #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>; #include "llvm/IR/Metadata.def" -/// Map-like storage for metadata attachments. -class MDAttachmentMap { - SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments; - +/// Multimap-like storage for metadata attachments. +class MDAttachments { public: - bool empty() const { return Attachments.empty(); } - size_t size() const { return Attachments.size(); } - - /// Get a particular attachment (if any). - MDNode *lookup(unsigned ID) const; - - /// Set an attachment to a particular node. - /// - /// Set the \c ID attachment to \c MD, replacing the current attachment at \c - /// ID (if anyway). - void set(unsigned ID, MDNode &MD); - - /// Remove an attachment. - /// - /// Remove the attachment at \c ID, if any. - bool erase(unsigned ID); - - /// Copy out all the attachments. - /// - /// Copies all the current attachments into \c Result, sorting by attachment - /// ID. This function does \em not clear \c Result. - void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; - - /// Erase matching attachments. - /// - /// Erases all attachments matching the \c shouldRemove predicate. - template <class PredTy> void remove_if(PredTy shouldRemove) { - Attachments.erase(llvm::remove_if(Attachments, shouldRemove), - Attachments.end()); - } -}; - -/// Multimap-like storage for metadata attachments for globals. This differs -/// from MDAttachmentMap in that it allows multiple attachments per metadata -/// kind. -class MDGlobalAttachmentMap { struct Attachment { unsigned MDKind; TrackingMDNodeRef Node; }; + +private: SmallVector<Attachment, 1> Attachments; public: bool empty() const { return Attachments.empty(); } - - /// Appends all attachments with the given ID to \c Result in insertion order. - /// If the global has no attachments with the given ID, or if ID is invalid, - /// leaves Result unchanged. - void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const; + size_t size() const { return Attachments.size(); } /// Returns the first attachment with the given ID or nullptr if no such /// attachment exists. MDNode *lookup(unsigned ID) const; - void insert(unsigned ID, MDNode &MD); - bool erase(unsigned ID); + /// Appends all attachments with the given ID to \c Result in insertion order. + /// If the global has no attachments with the given ID, or if ID is invalid, + /// leaves Result unchanged. + void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const; /// Appends all attachments for the global to \c Result, sorting by attachment /// ID. Attachments with the same ID appear in insertion order. This function /// does \em not clear \c Result. void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; + + /// Set an attachment to a particular node. + /// + /// Set the \c ID attachment to \c MD, replacing the current attachments at \c + /// ID (if anyway). + void set(unsigned ID, MDNode *MD); + + /// Adds an attachment to a particular node. + void insert(unsigned ID, MDNode &MD); + + /// Remove attachments with the given ID. + /// + /// Remove the attachments at \c ID, if any. + bool erase(unsigned ID); + + /// Erase matching attachments. + /// + /// Erases all attachments matching the \c shouldRemove predicate. + template <class PredTy> void remove_if(PredTy shouldRemove) { + llvm::erase_if(Attachments, shouldRemove); + } }; class LLVMContextImpl { @@ -1289,7 +1325,26 @@ public: std::unique_ptr<DiagnosticHandler> DiagHandler; bool RespectDiagnosticFilters = false; bool DiagnosticsHotnessRequested = false; - uint64_t DiagnosticsHotnessThreshold = 0; + /// The minimum hotness value a diagnostic needs in order to be included in + /// optimization diagnostics. + /// + /// The threshold is an Optional value, which maps to one of the 3 states: + /// 1). 0 => threshold disabled. All emarks will be printed. + /// 2). positive int => manual threshold by user. Remarks with hotness exceed + /// threshold will be printed. + /// 3). None => 'auto' threshold by user. The actual value is not + /// available at command line, but will be synced with + /// hotness threhold from profile summary during + /// compilation. + /// + /// State 1 and 2 are considered as terminal states. State transition is + /// only allowed from 3 to 2, when the threshold is first synced with profile + /// summary. This ensures that the threshold is set only once and stays + /// constant. + /// + /// If threshold option is not specified, it is disabled (0) by default. + Optional<uint64_t> DiagnosticsHotnessThreshold = 0; + /// The specialized remark streamer used by LLVM's OptimizationRemarkEmitter. std::unique_ptr<LLVMRemarkStreamer> LLVMRS; @@ -1342,10 +1397,15 @@ public: DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants; - StringMap<ConstantDataSequential*> CDSConstants; + DenseMap<Type *, std::unique_ptr<PoisonValue>> PVConstants; + + StringMap<std::unique_ptr<ConstantDataSequential>> CDSConstants; DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *> BlockAddresses; + + DenseMap<const GlobalValue *, DSOLocalEquivalent *> DSOLocalEquivalents; + ConstantUniqueMap<ConstantExpr> ExprConstants; ConstantUniqueMap<InlineAsm> InlineAsms; @@ -1358,7 +1418,7 @@ public: // Basic type instances. Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, DoubleTy, MetadataTy, TokenTy; - Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; + Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy, X86_AMXTy; IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; BumpPtrAllocator Alloc; @@ -1387,11 +1447,8 @@ public: /// CustomMDKindNames - Map to hold the metadata string to ID mapping. StringMap<unsigned> CustomMDKindNames; - /// Collection of per-instruction metadata used in this context. - DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata; - - /// Collection of per-GlobalObject metadata used in this context. - DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata; + /// Collection of metadata used in this context. + DenseMap<const Value *, MDAttachments> ValueMetadata; /// Collection of per-GlobalObject sections used in this context. DenseMap<const GlobalObject *, StringRef> GlobalObjectSections; |