mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
IR: Allow temporary nodes to become uniqued or distinct
Add `MDNode::replaceWithUniqued()` and `MDNode::replaceWithDistinct()`, which mutate temporary nodes to become uniqued or distinct. On uniquing collisions, the unique version is returned and the node is deleted. This takes advantage of temporary nodes being folded back in, and should let me clean up some awkward logic in `MapMetadata()`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -744,6 +744,24 @@ public:
|
||||
Context.getReplaceableUses()->replaceAllUsesWith(MD);
|
||||
}
|
||||
|
||||
/// \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
|
||||
replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N);
|
||||
|
||||
/// \brief Replace a temporary node with a distinct one.
|
||||
///
|
||||
/// 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
|
||||
replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N);
|
||||
|
||||
protected:
|
||||
/// \brief Set an operand.
|
||||
///
|
||||
@@ -788,6 +806,30 @@ public:
|
||||
static MDNode *getMostGenericRange(MDNode *A, MDNode *B);
|
||||
};
|
||||
|
||||
template <class NodeTy>
|
||||
typename std::enable_if<std::is_base_of<UniquableMDNode, NodeTy>::value,
|
||||
NodeTy *>::type
|
||||
MDNode::replaceWithUniqued(std::unique_ptr<NodeTy, TempMDNodeDeleter> Node) {
|
||||
// Try to uniquify in place.
|
||||
UniquableMDNode *UniquedNode = Node->uniquify();
|
||||
if (UniquedNode == Node.get()) {
|
||||
Node->makeUniqued();
|
||||
return Node.release();
|
||||
}
|
||||
|
||||
// Collision, so RAUW instead.
|
||||
Node->replaceAllUsesWith(UniquedNode);
|
||||
return cast<NodeTy>(UniquedNode);
|
||||
}
|
||||
|
||||
template <class NodeTy>
|
||||
typename std::enable_if<std::is_base_of<UniquableMDNode, 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
|
||||
@@ -844,6 +886,19 @@ private:
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user