summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 23:13:14 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 23:13:14 +0000
commit2bc00f4a383549386c471db17cacb08cc9e53a0d (patch)
treec6f5472bea9573cc14b64f22d2fa4d2837df42b9 /llvm
parent93e983e70796b047d4a798d23b536ba7ef111565 (diff)
downloadbcm5719-llvm-2bc00f4a383549386c471db17cacb08cc9e53a0d.tar.gz
bcm5719-llvm-2bc00f4a383549386c471db17cacb08cc9e53a0d.zip
IR: Merge UniquableMDNode back into MDNode, NFC
As pointed out in r226501, the distinction between `MDNode` and `UniquableMDNode` is confusing. When we need subclasses of `MDNode` that don't use all its functionality it might make sense to break it apart again, but until then this makes the code clearer. llvm-svn: 226520
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/IR/Metadata.def27
-rw-r--r--llvm/include/llvm/IR/Metadata.h162
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp4
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp2
-rw-r--r--llvm/lib/IR/AsmWriter.cpp9
-rw-r--r--llvm/lib/IR/DIBuilder.cpp4
-rw-r--r--llvm/lib/IR/LLVMContextImpl.cpp2
-rw-r--r--llvm/lib/IR/LLVMContextImpl.h2
-rw-r--r--llvm/lib/IR/Metadata.cpp77
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp28
10 files changed, 142 insertions, 175 deletions
diff --git a/llvm/include/llvm/IR/Metadata.def b/llvm/include/llvm/IR/Metadata.def
index 57cd773373e..11705dd3beb 100644
--- a/llvm/include/llvm/IR/Metadata.def
+++ b/llvm/include/llvm/IR/Metadata.def
@@ -12,8 +12,8 @@
//===----------------------------------------------------------------------===//
#if !(defined HANDLE_METADATA || defined HANDLE_METADATA_LEAF || \
- defined HANDLE_METADATA_BRANCH || defined HANDLE_UNIQUABLE_LEAF || \
- defined HANDLE_UNIQUABLE_BRANCH)
+ defined HANDLE_METADATA_BRANCH || defined HANDLE_MDNODE_LEAF || \
+ defined HANDLE_MDNODE_BRANCH)
#error "Missing macro definition of HANDLE_METADATA*"
#endif
@@ -32,27 +32,26 @@
#define HANDLE_METADATA_BRANCH(CLASS) HANDLE_METADATA(CLASS)
#endif
-// Handler for leaf nodes under UniquableMDNode.
-#ifndef HANDLE_UNIQUABLE_LEAF
-#define HANDLE_UNIQUABLE_LEAF(CLASS) HANDLE_METADATA_LEAF(CLASS)
+// Handler for leaf nodes under MDNode.
+#ifndef HANDLE_MDNODE_LEAF
+#define HANDLE_MDNODE_LEAF(CLASS) HANDLE_METADATA_LEAF(CLASS)
#endif
-// Handler for non-leaf nodes under UniquableMDNode.
-#ifndef HANDLE_UNIQUABLE_BRANCH
-#define HANDLE_UNIQUABLE_BRANCH(CLASS) HANDLE_METADATA_BRANCH(CLASS)
+// Handler for non-leaf nodes under MDNode.
+#ifndef HANDLE_MDNODE_BRANCH
+#define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_METADATA_BRANCH(CLASS)
#endif
HANDLE_METADATA_LEAF(MDString)
HANDLE_METADATA_BRANCH(ValueAsMetadata)
HANDLE_METADATA_LEAF(ConstantAsMetadata)
HANDLE_METADATA_LEAF(LocalAsMetadata)
-HANDLE_METADATA_BRANCH(MDNode)
-HANDLE_UNIQUABLE_BRANCH(UniquableMDNode)
-HANDLE_UNIQUABLE_LEAF(MDTuple)
-HANDLE_UNIQUABLE_LEAF(MDLocation)
+HANDLE_MDNODE_BRANCH(MDNode)
+HANDLE_MDNODE_LEAF(MDTuple)
+HANDLE_MDNODE_LEAF(MDLocation)
#undef HANDLE_METADATA
#undef HANDLE_METADATA_LEAF
#undef HANDLE_METADATA_BRANCH
-#undef HANDLE_UNIQUABLE_LEAF
-#undef HANDLE_UNIQUABLE_BRANCH
+#undef HANDLE_MDNODE_LEAF
+#undef HANDLE_MDNODE_BRANCH
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index 449403f2a5e..7a5474efa49 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -165,8 +165,8 @@ public:
/// \brief Resolve all uses of this.
///
/// Resolve all uses of this, turning off RAUW permanently. If \c
- /// ResolveUsers, call \a UniquableMDNode::resolve() on any users whose last
- /// operand is resolved.
+ /// ResolveUsers, call \a MDNode::resolve() on any users whose last operand
+ /// is resolved.
void resolveAllUses(bool ResolveUsers = true);
private:
@@ -655,15 +655,30 @@ struct TempMDNodeDeleter {
inline void operator()(MDNode *Node) const;
};
-#define HANDLE_UNIQUABLE_LEAF(CLASS) \
+#define HANDLE_MDNODE_LEAF(CLASS) \
typedef std::unique_ptr<CLASS, TempMDNodeDeleter> Temp##CLASS;
-#define HANDLE_UNIQUABLE_BRANCH(CLASS) HANDLE_UNIQUABLE_LEAF(CLASS)
+#define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS)
#include "llvm/IR/Metadata.def"
-//===----------------------------------------------------------------------===//
-/// \brief Tuple of metadata.
+/// \brief Metadata node.
+///
+/// Metadata nodes can be uniqued, like constants, or distinct. Temporary
+/// metadata nodes (with full support for RAUW) can be used to delay uniquing
+/// until forward references are known. The basic metadata node is an \a
+/// MDTuple.
+///
+/// There is limited support for RAUW at construction time. At construction
+/// time, if any operand is a temporary node (or an unresolved uniqued node,
+/// which indicates a transitive temporary operand), the node itself will be
+/// unresolved. As soon as all operands become resolved, it will drop RAUW
+/// support permanently.
+///
+/// If an unresolved node is part of a cycle, \a resolveCycles() needs
+/// to be called on some member of the cycle once all temporary nodes have been
+/// replaced.
class MDNode : public Metadata {
friend class ReplaceableMetadataImpl;
+ friend class LLVMContextImpl;
MDNode(const MDNode &) LLVM_DELETED_FUNCTION;
void operator=(const MDNode &) LLVM_DELETED_FUNCTION;
@@ -745,13 +760,20 @@ public:
Context.getReplaceableUses()->replaceAllUsesWith(MD);
}
+ /// \brief Resolve cycles.
+ ///
+ /// Once all forward declarations have been resolved, force cycles to be
+ /// resolved.
+ ///
+ /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
+ void resolveCycles();
+
/// \brief Replace a temporary node with a uniqued one.
///
/// Create a uniqued version of \c N -- in place, if possible -- and return
/// it. Takes ownership of the temporary node.
template <class T>
- static typename std::enable_if<std::is_base_of<UniquableMDNode, T>::value,
- T *>::type
+ static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N);
/// \brief Replace a temporary node with a distinct one.
@@ -759,8 +781,7 @@ public:
/// Create a distinct version of \c N -- in place, if possible -- and return
/// it. Takes ownership of the temporary node.
template <class T>
- static typename std::enable_if<std::is_base_of<UniquableMDNode, T>::value,
- T *>::type
+ static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N);
protected:
@@ -769,6 +790,35 @@ protected:
/// Sets the operand directly, without worrying about uniquing.
void setOperand(unsigned I, Metadata *New);
+ void storeDistinctInContext();
+ template <class T, class StoreT>
+ static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
+
+private:
+ void handleChangedOperand(void *Ref, Metadata *New);
+
+ void resolve();
+ void resolveAfterOperandChange(Metadata *Old, Metadata *New);
+ void decrementUnresolvedOperandCount();
+ unsigned countUnresolvedOperands() const;
+
+ /// \brief Mutate this to be "uniqued".
+ ///
+ /// Mutate this so that \a isUniqued().
+ /// \pre \a isTemporary().
+ /// \pre already added to uniquing set.
+ void makeUniqued();
+
+ /// \brief Mutate this to be "distinct".
+ ///
+ /// Mutate this so that \a isDistinct().
+ /// \pre \a isTemporary().
+ void makeDistinct();
+
+ void deleteAsSubclass();
+ MDNode *uniquify();
+ void eraseFromStore();
+
public:
typedef const MDOperand *op_iterator;
typedef iterator_range<op_iterator> op_range;
@@ -807,11 +857,10 @@ public:
};
template <class NodeTy>
-typename std::enable_if<std::is_base_of<UniquableMDNode, NodeTy>::value,
- NodeTy *>::type
+typename std::enable_if<std::is_base_of<MDNode, NodeTy>::value, NodeTy *>::type
MDNode::replaceWithUniqued(std::unique_ptr<NodeTy, TempMDNodeDeleter> Node) {
// Try to uniquify in place.
- UniquableMDNode *UniquedNode = Node->uniquify();
+ MDNode *UniquedNode = Node->uniquify();
if (UniquedNode == Node.get()) {
Node->makeUniqued();
return Node.release();
@@ -823,98 +872,23 @@ MDNode::replaceWithUniqued(std::unique_ptr<NodeTy, TempMDNodeDeleter> Node) {
}
template <class NodeTy>
-typename std::enable_if<std::is_base_of<UniquableMDNode, NodeTy>::value,
- NodeTy *>::type
+typename std::enable_if<std::is_base_of<MDNode, NodeTy>::value, NodeTy *>::type
MDNode::replaceWithDistinct(std::unique_ptr<NodeTy, TempMDNodeDeleter> Node) {
Node->makeDistinct();
return Node.release();
}
-/// \brief Uniquable metadata node.
-///
-/// A uniquable metadata node. This contains the basic functionality
-/// for implementing sub-types of \a MDNode that can be uniqued like
-/// constants.
-///
-/// There is limited support for RAUW at construction time. At construction
-/// time, if any operand is a temporary node (or an unresolved uniqued node,
-/// which indicates a transitive temporary operand), the node itself will be
-/// unresolved. As soon as all operands become resolved, it will drop RAUW
-/// support permanently.
-///
-/// If an unresolved node is part of a cycle, \a resolveCycles() needs
-/// to be called on some member of the cycle once all temporary nodes have been
-/// replaced.
-class UniquableMDNode : public MDNode {
- friend class ReplaceableMetadataImpl;
- friend class MDNode;
- friend class LLVMContextImpl;
-
-protected:
- /// \brief Create a new node.
- ///
- /// If \c AllowRAUW, then if any operands are unresolved support RAUW. RAUW
- /// will be dropped once all operands have been resolved (or if \a
- /// resolveCycles() is called).
- UniquableMDNode(LLVMContext &C, unsigned ID, StorageType Storage,
- ArrayRef<Metadata *> Vals);
- ~UniquableMDNode() {}
-
- void storeDistinctInContext();
- template <class T, class StoreT>
- static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
-
-public:
- static bool classof(const Metadata *MD) {
- return MD->getMetadataID() == MDTupleKind ||
- MD->getMetadataID() == MDLocationKind;
- }
-
- /// \brief Resolve cycles.
- ///
- /// Once all forward declarations have been resolved, force cycles to be
- /// resolved.
- ///
- /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
- void resolveCycles();
-
-private:
- void handleChangedOperand(void *Ref, Metadata *New);
-
- void resolve();
- void resolveAfterOperandChange(Metadata *Old, Metadata *New);
- void decrementUnresolvedOperandCount();
- unsigned countUnresolvedOperands() const;
-
- /// \brief Mutate this to be "uniqued".
- ///
- /// Mutate this so that \a isUniqued().
- /// \pre \a isTemporary().
- /// \pre already added to uniquing set.
- void makeUniqued();
-
- /// \brief Mutate this to be "distinct".
- ///
- /// Mutate this so that \a isDistinct().
- /// \pre \a isTemporary().
- void makeDistinct();
-
- void deleteAsSubclass();
- UniquableMDNode *uniquify();
- void eraseFromStore();
-};
-
/// \brief Tuple of metadata.
///
/// This is the simple \a MDNode arbitrary tuple. Nodes are uniqued by
/// default based on their operands.
-class MDTuple : public UniquableMDNode {
+class MDTuple : public MDNode {
friend class LLVMContextImpl;
- friend class UniquableMDNode;
+ friend class MDNode;
MDTuple(LLVMContext &C, StorageType Storage, unsigned Hash,
ArrayRef<Metadata *> Vals)
- : UniquableMDNode(C, MDTupleKind, Storage, Vals) {
+ : MDNode(C, MDTupleKind, Storage, Vals) {
setHash(Hash);
}
~MDTuple() { dropAllReferences(); }
@@ -979,9 +953,9 @@ void TempMDNodeDeleter::operator()(MDNode *Node) const {
/// \brief Debug location.
///
/// A debug location in source code, used for debug info and otherwise.
-class MDLocation : public UniquableMDNode {
+class MDLocation : public MDNode {
friend class LLVMContextImpl;
- friend class UniquableMDNode;
+ friend class MDNode;
MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, ArrayRef<Metadata *> MDs);
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 421a2bcbaba..7696f537840 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -148,8 +148,8 @@ bool LLParser::ValidateEndOfModule() {
// Resolve metadata cycles.
for (auto &N : NumberedMetadata)
- if (auto *U = cast_or_null<UniquableMDNode>(N))
- U->resolveCycles();
+ if (N && !N->isResolved())
+ N->resolveCycles();
// Look for intrinsic functions and CallInst that need to be upgraded
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index c158d356a16..f8625e1034f 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -572,7 +572,7 @@ void BitcodeReaderMDValueList::tryToResolveCycles() {
// Resolve any cycles.
for (auto &MD : MDValuePtrs) {
- auto *N = dyn_cast_or_null<UniquableMDNode>(MD);
+ auto *N = dyn_cast_or_null<MDNode>(MD);
if (!N)
continue;
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index e2ea36d7d2a..d9165437ec7 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1311,16 +1311,15 @@ static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
const Module *Context) {
assert(!Node->isTemporary() && "Unexpected forward declaration");
- auto *Uniquable = cast<UniquableMDNode>(Node);
- if (Uniquable->isDistinct())
+ if (Node->isDistinct())
Out << "distinct ";
- switch (Uniquable->getMetadataID()) {
+ switch (Node->getMetadataID()) {
default:
llvm_unreachable("Expected uniquable MDNode");
-#define HANDLE_UNIQUABLE_LEAF(CLASS) \
+#define HANDLE_MDNODE_LEAF(CLASS) \
case Metadata::CLASS##Kind: \
- write##CLASS(Out, cast<CLASS>(Uniquable), TypePrinter, Machine, Context); \
+ write##CLASS(Out, cast<CLASS>(Node), TypePrinter, Machine, Context); \
break;
#include "llvm/IR/Metadata.def"
}
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index fdc0b1bb97b..eb686aa4bec 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -105,8 +105,8 @@ void DIBuilder::finalize() {
// Now that all temp nodes have been replaced or deleted, resolve remaining
// cycles.
for (const auto &N : UnresolvedNodes)
- if (N)
- cast<UniquableMDNode>(N)->resolveCycles();
+ if (N && !N->isResolved())
+ N->resolveCycles();
UnresolvedNodes.clear();
// Can't handle unresolved nodes anymore.
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 2fa6780e569..0c50a120d5d 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -90,7 +90,7 @@ LLVMContextImpl::~LLVMContextImpl() {
Pair.second->dropUse();
// Destroy MDNodes.
- for (UniquableMDNode *I : DistinctMDNodes)
+ for (MDNode *I : DistinctMDNodes)
I->deleteAsSubclass();
for (MDTuple *I : MDTuples)
delete I;
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 729e48be083..092104f6d0e 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -320,7 +320,7 @@ public:
// aren't in the MDNodeSet, but they're still shared between objects, so no
// one object can destroy them. This set allows us to at least destroy them
// on Context destruction.
- SmallPtrSet<UniquableMDNode *, 1> DistinctMDNodes;
+ SmallPtrSet<MDNode *, 1> DistinctMDNodes;
DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 8253a4e6a96..0310ee776c9 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -228,8 +228,8 @@ void ReplaceableMetadataImpl::resolveAllUses(bool ResolveUsers) {
if (Owner.is<MetadataAsValue *>())
continue;
- // Resolve UniquableMDNodes that point at this.
- auto *OwnerMD = dyn_cast<UniquableMDNode>(Owner.get<Metadata *>());
+ // Resolve MDNodes that point at this.
+ auto *OwnerMD = dyn_cast<MDNode>(Owner.get<Metadata *>());
if (!OwnerMD)
continue;
if (OwnerMD->isResolved())
@@ -406,17 +406,7 @@ MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
if (isTemporary())
this->Context.makeReplaceable(
make_unique<ReplaceableMetadataImpl>(Context));
-}
-
-static bool isOperandUnresolved(Metadata *Op) {
- if (auto *N = dyn_cast_or_null<MDNode>(Op))
- return !N->isResolved();
- return false;
-}
-UniquableMDNode::UniquableMDNode(LLVMContext &C, unsigned ID,
- StorageType Storage, ArrayRef<Metadata *> Vals)
- : MDNode(C, ID, Storage, Vals) {
if (!isUniqued())
return;
@@ -425,18 +415,24 @@ UniquableMDNode::UniquableMDNode(LLVMContext &C, unsigned ID,
if (!NumUnresolved)
return;
- this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(C));
+ this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context));
SubclassData32 = NumUnresolved;
}
-unsigned UniquableMDNode::countUnresolvedOperands() const {
+static bool isOperandUnresolved(Metadata *Op) {
+ if (auto *N = dyn_cast_or_null<MDNode>(Op))
+ return !N->isResolved();
+ return false;
+}
+
+unsigned MDNode::countUnresolvedOperands() const {
unsigned NumUnresolved = 0;
for (const auto &Op : operands())
NumUnresolved += unsigned(isOperandUnresolved(Op));
return NumUnresolved;
}
-void UniquableMDNode::makeUniqued() {
+void MDNode::makeUniqued() {
assert(isTemporary() && "Expected this to be temporary");
assert(!isResolved() && "Expected this to be unresolved");
@@ -450,7 +446,7 @@ void UniquableMDNode::makeUniqued() {
assert(isUniqued() && "Expected this to be uniqued");
}
-void UniquableMDNode::makeDistinct() {
+void MDNode::makeDistinct() {
assert(isTemporary() && "Expected this to be temporary");
assert(!isResolved() && "Expected this to be unresolved");
@@ -463,7 +459,7 @@ void UniquableMDNode::makeDistinct() {
assert(isResolved() && "Expected this to be resolved");
}
-void UniquableMDNode::resolve() {
+void MDNode::resolve() {
assert(isUniqued() && "Expected this to be uniqued");
assert(!isResolved() && "Expected this to be unresolved");
@@ -476,7 +472,7 @@ void UniquableMDNode::resolve() {
Uses->resolveAllUses();
}
-void UniquableMDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {
+void MDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {
assert(SubclassData32 != 0 && "Expected unresolved operands");
// Check if an operand was resolved.
@@ -488,13 +484,13 @@ void UniquableMDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {
decrementUnresolvedOperandCount();
}
-void UniquableMDNode::decrementUnresolvedOperandCount() {
+void MDNode::decrementUnresolvedOperandCount() {
if (!--SubclassData32)
// Last unresolved operand has just been resolved.
resolve();
}
-void UniquableMDNode::resolveCycles() {
+void MDNode::resolveCycles() {
if (isResolved())
return;
@@ -503,7 +499,7 @@ void UniquableMDNode::resolveCycles() {
// Resolve all operands.
for (const auto &Op : operands()) {
- auto *N = dyn_cast_or_null<UniquableMDNode>(Op);
+ auto *N = dyn_cast_or_null<MDNode>(Op);
if (!N)
continue;
@@ -521,14 +517,13 @@ void MDTuple::recalculateHash() {
void MDNode::dropAllReferences() {
for (unsigned I = 0, E = NumOperands; I != E; ++I)
setOperand(I, nullptr);
- if (auto *N = dyn_cast<UniquableMDNode>(this))
- if (!N->isResolved()) {
- N->Context.getReplaceableUses()->resolveAllUses(/* ResolveUsers */ false);
- (void)N->Context.takeReplaceableUses();
- }
+ if (!isResolved()) {
+ Context.getReplaceableUses()->resolveAllUses(/* ResolveUsers */ false);
+ (void)Context.takeReplaceableUses();
+ }
}
-void UniquableMDNode::handleChangedOperand(void *Ref, Metadata *New) {
+void MDNode::handleChangedOperand(void *Ref, Metadata *New) {
unsigned Op = static_cast<MDOperand *>(Ref) - op_begin();
assert(Op < getNumOperands() && "Expected valid operand");
@@ -577,11 +572,11 @@ void UniquableMDNode::handleChangedOperand(void *Ref, Metadata *New) {
storeDistinctInContext();
}
-void UniquableMDNode::deleteAsSubclass() {
+void MDNode::deleteAsSubclass() {
switch (getMetadataID()) {
default:
- llvm_unreachable("Invalid subclass of UniquableMDNode");
-#define HANDLE_UNIQUABLE_LEAF(CLASS) \
+ llvm_unreachable("Invalid subclass of MDNode");
+#define HANDLE_MDNODE_LEAF(CLASS) \
case CLASS##Kind: \
delete cast<CLASS>(this); \
break;
@@ -605,7 +600,7 @@ static T *uniquifyImpl(T *N, DenseSet<T *, InfoT> &Store) {
return N;
}
-UniquableMDNode *UniquableMDNode::uniquify() {
+MDNode *MDNode::uniquify() {
// Recalculate hash, if necessary.
switch (getMetadataID()) {
default:
@@ -618,19 +613,19 @@ UniquableMDNode *UniquableMDNode::uniquify() {
// Try to insert into uniquing store.
switch (getMetadataID()) {
default:
- llvm_unreachable("Invalid subclass of UniquableMDNode");
-#define HANDLE_UNIQUABLE_LEAF(CLASS) \
+ llvm_unreachable("Invalid subclass of MDNode");
+#define HANDLE_MDNODE_LEAF(CLASS) \
case CLASS##Kind: \
return uniquifyImpl(cast<CLASS>(this), getContext().pImpl->CLASS##s);
#include "llvm/IR/Metadata.def"
}
}
-void UniquableMDNode::eraseFromStore() {
+void MDNode::eraseFromStore() {
switch (getMetadataID()) {
default:
- llvm_unreachable("Invalid subclass of UniquableMDNode");
-#define HANDLE_UNIQUABLE_LEAF(CLASS) \
+ llvm_unreachable("Invalid subclass of MDNode");
+#define HANDLE_MDNODE_LEAF(CLASS) \
case CLASS##Kind: \
getContext().pImpl->CLASS##s.erase(cast<CLASS>(this)); \
break;
@@ -639,7 +634,7 @@ void UniquableMDNode::eraseFromStore() {
}
template <class T, class StoreT>
-T *UniquableMDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
+T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
switch (Storage) {
case Uniqued:
Store.insert(N);
@@ -673,7 +668,7 @@ MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, ArrayRef<Metadata *> MDs)
- : UniquableMDNode(C, MDLocationKind, Storage, MDs) {
+ : MDNode(C, MDLocationKind, Storage, MDs) {
assert((MDs.size() == 1 || MDs.size() == 2) &&
"Expected a scope and optional inlined-at");
@@ -727,10 +722,10 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
void MDNode::deleteTemporary(MDNode *N) {
assert(N->isTemporary() && "Expected temporary node");
- cast<UniquableMDNode>(N)->deleteAsSubclass();
+ N->deleteAsSubclass();
}
-void UniquableMDNode::storeDistinctInContext() {
+void MDNode::storeDistinctInContext() {
assert(isResolved() && "Expected resolved nodes");
Storage = Distinct;
if (auto *T = dyn_cast<MDTuple>(this))
@@ -747,7 +742,7 @@ void MDNode::replaceOperandWith(unsigned I, Metadata *New) {
return;
}
- cast<UniquableMDNode>(this)->handleChangedOperand(mutable_begin() + I, New);
+ handleChangedOperand(mutable_begin() + I, New);
}
void MDNode::setOperand(unsigned I, Metadata *New) {
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 7c676749fbc..20ce27823fb 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -192,11 +192,11 @@ static TempMDLocation cloneMDLocation(const MDLocation *Node) {
Node->getInlinedAt());
}
-static TempUniquableMDNode cloneMDNode(const UniquableMDNode *Node) {
+static TempMDNode cloneMDNode(const MDNode *Node) {
switch (Node->getMetadataID()) {
default:
- llvm_unreachable("Invalid UniquableMDNode subclass");
-#define HANDLE_UNIQUABLE_LEAF(CLASS) \
+ llvm_unreachable("Invalid MDNode subclass");
+#define HANDLE_MDNODE_LEAF(CLASS) \
case Metadata::CLASS##Kind: \
return clone##CLASS(cast<CLASS>(Node));
#include "llvm/IR/Metadata.def"
@@ -209,9 +209,8 @@ static TempUniquableMDNode cloneMDNode(const UniquableMDNode *Node) {
/// Assumes that \c NewNode is already a clone of \c OldNode.
///
/// \pre \c NewNode is a clone of \c OldNode.
-static bool remap(const UniquableMDNode *OldNode, UniquableMDNode *NewNode,
- ValueToValueMapTy &VM, RemapFlags Flags,
- ValueMapTypeRemapper *TypeMapper,
+static bool remap(const MDNode *OldNode, MDNode *NewNode, ValueToValueMapTy &VM,
+ RemapFlags Flags, ValueMapTypeRemapper *TypeMapper,
ValueMaterializer *Materializer) {
assert(OldNode->getNumOperands() == NewNode->getNumOperands() &&
"Expected nodes to match");
@@ -240,13 +239,13 @@ static bool remap(const UniquableMDNode *OldNode, UniquableMDNode *NewNode,
/// \brief Map a distinct MDNode.
///
/// Distinct nodes are not uniqued, so they must always recreated.
-static Metadata *mapDistinctNode(const UniquableMDNode *Node,
- ValueToValueMapTy &VM, RemapFlags Flags,
+static Metadata *mapDistinctNode(const MDNode *Node, ValueToValueMapTy &VM,
+ RemapFlags Flags,
ValueMapTypeRemapper *TypeMapper,
ValueMaterializer *Materializer) {
assert(Node->isDistinct() && "Expected distinct node");
- UniquableMDNode *NewMD = MDNode::replaceWithDistinct(cloneMDNode(Node));
+ MDNode *NewMD = MDNode::replaceWithDistinct(cloneMDNode(Node));
remap(Node, NewMD, VM, Flags, TypeMapper, Materializer);
return NewMD;
}
@@ -254,8 +253,8 @@ static Metadata *mapDistinctNode(const UniquableMDNode *Node,
/// \brief Map a uniqued MDNode.
///
/// Uniqued nodes may not need to be recreated (they may map to themselves).
-static Metadata *mapUniquedNode(const UniquableMDNode *Node,
- ValueToValueMapTy &VM, RemapFlags Flags,
+static Metadata *mapUniquedNode(const MDNode *Node, ValueToValueMapTy &VM,
+ RemapFlags Flags,
ValueMapTypeRemapper *TypeMapper,
ValueMaterializer *Materializer) {
assert(Node->isUniqued() && "Expected uniqued node");
@@ -304,7 +303,7 @@ static Metadata *MapMetadataImpl(const Metadata *MD, ValueToValueMapTy &VM,
return nullptr;
}
- const UniquableMDNode *Node = cast<UniquableMDNode>(MD);
+ const MDNode *Node = cast<MDNode>(MD);
assert(Node->isResolved() && "Unexpected unresolved node");
// If this is a module-level metadata and we know that nothing at the
@@ -323,8 +322,9 @@ Metadata *llvm::MapMetadata(const Metadata *MD, ValueToValueMapTy &VM,
ValueMaterializer *Materializer) {
Metadata *NewMD = MapMetadataImpl(MD, VM, Flags, TypeMapper, Materializer);
if (NewMD && NewMD != MD)
- if (auto *N = dyn_cast<UniquableMDNode>(NewMD))
- N->resolveCycles();
+ if (auto *N = dyn_cast<MDNode>(NewMD))
+ if (!N->isResolved())
+ N->resolveCycles();
return NewMD;
}
OpenPOWER on IntegriCloud