From 890324873ff92deed4e021cb4a892a7e94711cb9 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 4 Feb 2015 22:08:30 +0000 Subject: [PATCH] IR: Reduce boilerplate in DenseMapInfo overrides, NFC Minimize the boilerplate required for the `MDNode` subclass `DenseMapInfo<>` overrides in `LLVMContextImpl`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228212 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/LLVMContextImpl.h | 154 ++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 91 deletions(-) diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index facc6241f8d..ee6c93bfd6d 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -179,7 +179,7 @@ protected: : RawOps(Ops), Hash(calculateHash(Ops)) {} template - MDNodeOpsKey(NodeTy *N, unsigned Offset = 0) + MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0) : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {} template @@ -208,125 +208,97 @@ public: unsigned getHash() const { return Hash; } }; +template struct MDNodeKeyImpl; +template struct MDNodeInfo; + /// \brief DenseMapInfo for MDTuple. /// /// Note that we don't need the is-function-local bit, since that's implicit in /// the operands. -struct MDTupleInfo { - struct KeyTy : MDNodeOpsKey { - KeyTy(ArrayRef Ops) : MDNodeOpsKey(Ops) {} - KeyTy(MDTuple *N) : MDNodeOpsKey(N) {} +template <> struct MDNodeKeyImpl : MDNodeOpsKey { + MDNodeKeyImpl(ArrayRef Ops) : MDNodeOpsKey(Ops) {} + MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {} - bool operator==(const MDTuple *RHS) const { - if (RHS == getEmptyKey() || RHS == getTombstoneKey()) - return false; - return compareOps(RHS); - } + bool operator==(const MDTuple *RHS) const { return compareOps(RHS); } - static unsigned calculateHash(MDTuple *N) { - return MDNodeOpsKey::calculateHash(N); - } - }; - static inline MDTuple *getEmptyKey() { - return DenseMapInfo::getEmptyKey(); - } - static inline MDTuple *getTombstoneKey() { - return DenseMapInfo::getTombstoneKey(); - } - static unsigned getHashValue(const KeyTy &Key) { return Key.getHash(); } - static unsigned getHashValue(const MDTuple *U) { return U->getHash(); } - static bool isEqual(const KeyTy &LHS, const MDTuple *RHS) { - return LHS == RHS; - } - static bool isEqual(const MDTuple *LHS, const MDTuple *RHS) { - return LHS == RHS; + unsigned getHashValue() const { return getHash(); } + + static unsigned calculateHash(MDTuple *N) { + return MDNodeOpsKey::calculateHash(N); } }; /// \brief DenseMapInfo for MDLocation. -struct MDLocationInfo { - struct KeyTy { - unsigned Line; - unsigned Column; - Metadata *Scope; - Metadata *InlinedAt; +template <> struct MDNodeKeyImpl { + unsigned Line; + unsigned Column; + Metadata *Scope; + Metadata *InlinedAt; - KeyTy(unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt) - : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {} + MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, + Metadata *InlinedAt) + : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {} - KeyTy(const MDLocation *L) - : Line(L->getLine()), Column(L->getColumn()), Scope(L->getScope()), - InlinedAt(L->getInlinedAt()) {} + MDNodeKeyImpl(const MDLocation *L) + : Line(L->getLine()), Column(L->getColumn()), Scope(L->getScope()), + InlinedAt(L->getInlinedAt()) {} - bool operator==(const MDLocation *RHS) const { - if (RHS == getEmptyKey() || RHS == getTombstoneKey()) - return false; - return Line == RHS->getLine() && Column == RHS->getColumn() && - Scope == RHS->getScope() && InlinedAt == RHS->getInlinedAt(); - } - }; - static inline MDLocation *getEmptyKey() { - return DenseMapInfo::getEmptyKey(); - } - static inline MDLocation *getTombstoneKey() { - return DenseMapInfo::getTombstoneKey(); - } - static unsigned getHashValue(const KeyTy &Key) { - return hash_combine(Key.Line, Key.Column, Key.Scope, Key.InlinedAt); + bool operator==(const MDLocation *RHS) const { + return Line == RHS->getLine() && Column == RHS->getColumn() && + Scope == RHS->getScope() && InlinedAt == RHS->getInlinedAt(); } - static unsigned getHashValue(const MDLocation *U) { - return getHashValue(KeyTy(U)); - } - static bool isEqual(const KeyTy &LHS, const MDLocation *RHS) { - return LHS == RHS; - } - static bool isEqual(const MDLocation *LHS, const MDLocation *RHS) { - return LHS == RHS; + unsigned getHashValue() const { + return hash_combine(Line, Column, Scope, InlinedAt); } }; /// \brief DenseMapInfo for GenericDebugNode. -struct GenericDebugNodeInfo { - struct KeyTy : MDNodeOpsKey { - unsigned Tag; - StringRef Header; - KeyTy(unsigned Tag, StringRef Header, ArrayRef DwarfOps) - : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} - KeyTy(GenericDebugNode *N) - : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {} - - bool operator==(const GenericDebugNode *RHS) const { - if (RHS == getEmptyKey() || RHS == getTombstoneKey()) - return false; - return Tag == RHS->getTag() && Header == RHS->getHeader() && - compareOps(RHS, 1); - } +template <> struct MDNodeKeyImpl : MDNodeOpsKey { + unsigned Tag; + StringRef Header; + MDNodeKeyImpl(unsigned Tag, StringRef Header, ArrayRef DwarfOps) + : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} + MDNodeKeyImpl(const GenericDebugNode *N) + : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {} - static unsigned calculateHash(GenericDebugNode *N) { - return MDNodeOpsKey::calculateHash(N, 1); - } - }; - static inline GenericDebugNode *getEmptyKey() { - return DenseMapInfo::getEmptyKey(); + bool operator==(const GenericDebugNode *RHS) const { + return Tag == RHS->getTag() && Header == RHS->getHeader() && + compareOps(RHS, 1); } - static inline GenericDebugNode *getTombstoneKey() { - return DenseMapInfo::getTombstoneKey(); + + unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); } + + static unsigned calculateHash(GenericDebugNode *N) { + return MDNodeOpsKey::calculateHash(N, 1); + } +}; + +/// \brief DenseMapInfo for MDNode subclasses. +template struct MDNodeInfo { + typedef MDNodeKeyImpl KeyTy; + static inline NodeTy *getEmptyKey() { + return DenseMapInfo::getEmptyKey(); } - static unsigned getHashValue(const KeyTy &Key) { - return hash_combine(Key.getHash(), Key.Tag, Key.Header); + static inline NodeTy *getTombstoneKey() { + return DenseMapInfo::getTombstoneKey(); } - static unsigned getHashValue(const GenericDebugNode *U) { - return hash_combine(U->getHash(), U->getTag(), U->getHeader()); + static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); } + static unsigned getHashValue(const NodeTy *N) { + return KeyTy(N).getHashValue(); } - static bool isEqual(const KeyTy &LHS, const GenericDebugNode *RHS) { + static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) { + if (RHS == getEmptyKey() || RHS == getTombstoneKey()) + return false; return LHS == RHS; } - static bool isEqual(const GenericDebugNode *LHS, - const GenericDebugNode *RHS) { + static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) { return LHS == RHS; } }; +#define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo CLASS##Info; +#include "llvm/IR/Metadata.def" + class LLVMContextImpl { public: /// OwnedModules - The set of modules instantiated in this context, and which -- 2.34.1