diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-24 20:36:25 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-24 20:36:25 +0000 |
commit | cbc28dc549ca03e6db3b6b0c7d373cc44487032c (patch) | |
tree | d159dea196ff1de17cd0b6f3291de1e8c70a0e6c /llvm/lib/IR/LLVMContextImpl.h | |
parent | cfbfe6f29cb9f66766fe0851062ca239a8299acb (diff) | |
download | bcm5719-llvm-cbc28dc549ca03e6db3b6b0c7d373cc44487032c.tar.gz bcm5719-llvm-cbc28dc549ca03e6db3b6b0c7d373cc44487032c.zip |
IR: Extract set logic from Instruction attachments, NFC
Extract the set logic for metadata attachments from `Instruction` so it
can be reused for `Function` (PR23340).
This data structure makes a `SmallVector<>` look (a little) like a map,
just doing the bare minimum to support the `Instruction` (and soon,
`Function`) metadata API.
llvm-svn: 235769
Diffstat (limited to 'llvm/lib/IR/LLVMContextImpl.h')
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.h | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index 0ca8e354808..a13afdd9b35 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -852,6 +852,44 @@ template <class NodeTy> struct MDNodeInfo { #define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info; #include "llvm/IR/Metadata.def" +/// \brief Map-like storage for metadata attachments. +class MDAttachmentMap { + SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments; + +public: + bool empty() const { return Attachments.empty(); } + size_t size() const { return Attachments.size(); } + + /// \brief Get a particular attachment (if any). + MDNode *lookup(unsigned ID) const; + + /// \brief 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); + + /// \brief Remove an attachment. + /// + /// Remove the attachment at \c ID, if any. + void erase(unsigned ID); + + /// \brief 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; + + /// \brief Erase matching attachments. + /// + /// Erases all attachments matching the \c shouldRemove predicate. + template <class PredTy> void remove_if(PredTy shouldRemove) { + Attachments.erase( + std::remove_if(Attachments.begin(), Attachments.end(), shouldRemove), + Attachments.end()); + } +}; + class LLVMContextImpl { public: /// OwnedModules - The set of modules instantiated in this context, and which @@ -952,9 +990,7 @@ public: StringMap<unsigned> CustomMDKindNames; /// Collection of per-instruction metadata used in this context. - DenseMap<const Instruction *, - SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2>> - InstructionMetadata; + DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata; /// DiscriminatorTable - This table maps file:line locations to an /// integer representing the next DWARF path discriminator to assign to |