[llvm] r226520 - IR: Merge UniquableMDNode back into MDNode, NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jan 19 15:13:14 PST 2015
Author: dexonsmith
Date: Mon Jan 19 17:13:14 2015
New Revision: 226520
URL: http://llvm.org/viewvc/llvm-project?rev=226520&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/IR/Metadata.def
llvm/trunk/include/llvm/IR/Metadata.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/IR/AsmWriter.cpp
llvm/trunk/lib/IR/DIBuilder.cpp
llvm/trunk/lib/IR/LLVMContextImpl.cpp
llvm/trunk/lib/IR/LLVMContextImpl.h
llvm/trunk/lib/IR/Metadata.cpp
llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
Modified: llvm/trunk/include/llvm/IR/Metadata.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.def?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Metadata.def (original)
+++ llvm/trunk/include/llvm/IR/Metadata.def Mon Jan 19 17:13:14 2015
@@ -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
Modified: llvm/trunk/include/llvm/IR/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Metadata.h (original)
+++ llvm/trunk/include/llvm/IR/Metadata.h Mon Jan 19 17:13:14 2015
@@ -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_p
}
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()(MDNod
/// \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);
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Jan 19 17:13:14 2015
@@ -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; )
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Jan 19 17:13:14 2015
@@ -572,7 +572,7 @@ void BitcodeReaderMDValueList::tryToReso
// 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;
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Mon Jan 19 17:13:14 2015
@@ -1311,16 +1311,15 @@ static void WriteMDNodeBodyInternal(raw_
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"
}
Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Mon Jan 19 17:13:14 2015
@@ -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.
Modified: llvm/trunk/lib/IR/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.cpp?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.cpp Mon Jan 19 17:13:14 2015
@@ -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;
Modified: llvm/trunk/lib/IR/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.h Mon Jan 19 17:13:14 2015
@@ -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;
Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Mon Jan 19 17:13:14 2015
@@ -228,8 +228,8 @@ void ReplaceableMetadataImpl::resolveAll
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, uns
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(LLVMCon
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::resolveAfterOperan
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::handleChangedOpera
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
return N;
}
-UniquableMDNode *UniquableMDNode::uniquify() {
+MDNode *MDNode::uniquify() {
// Recalculate hash, if necessary.
switch (getMetadataID()) {
default:
@@ -618,19 +613,19 @@ UniquableMDNode *UniquableMDNode::uniqui
// 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 &C
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(LLVMCont
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
return;
}
- cast<UniquableMDNode>(this)->handleChangedOperand(mutable_begin() + I, New);
+ handleChangedOperand(mutable_begin() + I, New);
}
void MDNode::setOperand(unsigned I, Metadata *New) {
Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=226520&r1=226519&r2=226520&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Mon Jan 19 17:13:14 2015
@@ -192,11 +192,11 @@ static TempMDLocation cloneMDLocation(co
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(c
/// 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
/// \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 U
/// \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 M
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 Metada
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;
}
More information about the llvm-commits
mailing list