forked from OSchip/llvm-project
IR: Move MDNode clone() methods from ValueMapper to MDNode, NFC
Now that the clone methods used by `MapMetadata()` don't do any remapping (and return a temporary), they make more sense as member functions on `MDNode` (and subclasses). llvm-svn: 226541
This commit is contained in:
parent
8a07e7f657
commit
03e0583a2d
|
@ -722,6 +722,9 @@ public:
|
||||||
static inline TempMDTuple getTemporary(LLVMContext &Context,
|
static inline TempMDTuple getTemporary(LLVMContext &Context,
|
||||||
ArrayRef<Metadata *> MDs);
|
ArrayRef<Metadata *> MDs);
|
||||||
|
|
||||||
|
/// \brief Create a (temporary) clone of this.
|
||||||
|
TempMDNode clone() const;
|
||||||
|
|
||||||
/// \brief Deallocate a node created by getTemporary.
|
/// \brief Deallocate a node created by getTemporary.
|
||||||
///
|
///
|
||||||
/// The node must not have any users.
|
/// The node must not have any users.
|
||||||
|
@ -898,6 +901,11 @@ class MDTuple : public MDNode {
|
||||||
static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
||||||
StorageType Storage, bool ShouldCreate = true);
|
StorageType Storage, bool ShouldCreate = true);
|
||||||
|
|
||||||
|
TempMDTuple cloneImpl() const {
|
||||||
|
return getTemporary(getContext(),
|
||||||
|
SmallVector<Metadata *, 4>(op_begin(), op_end()));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \brief Get the hash, if any.
|
/// \brief Get the hash, if any.
|
||||||
unsigned getHash() const { return SubclassData32; }
|
unsigned getHash() const { return SubclassData32; }
|
||||||
|
@ -926,6 +934,9 @@ public:
|
||||||
return TempMDTuple(getImpl(Context, MDs, Temporary));
|
return TempMDTuple(getImpl(Context, MDs, Temporary));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Return a (temporary) clone of this.
|
||||||
|
TempMDTuple clone() const { return cloneImpl(); }
|
||||||
|
|
||||||
static bool classof(const Metadata *MD) {
|
static bool classof(const Metadata *MD) {
|
||||||
return MD->getMetadataID() == MDTupleKind;
|
return MD->getMetadataID() == MDTupleKind;
|
||||||
}
|
}
|
||||||
|
@ -965,6 +976,11 @@ class MDLocation : public MDNode {
|
||||||
Metadata *InlinedAt, StorageType Storage,
|
Metadata *InlinedAt, StorageType Storage,
|
||||||
bool ShouldCreate = true);
|
bool ShouldCreate = true);
|
||||||
|
|
||||||
|
TempMDLocation cloneImpl() const {
|
||||||
|
return getTemporary(getContext(), getLine(), getColumn(), getScope(),
|
||||||
|
getInlinedAt());
|
||||||
|
}
|
||||||
|
|
||||||
// Disallow replacing operands.
|
// Disallow replacing operands.
|
||||||
void replaceOperandWith(unsigned I, Metadata *New) LLVM_DELETED_FUNCTION;
|
void replaceOperandWith(unsigned I, Metadata *New) LLVM_DELETED_FUNCTION;
|
||||||
|
|
||||||
|
@ -991,6 +1007,9 @@ public:
|
||||||
getImpl(Context, Line, Column, Scope, InlinedAt, Temporary));
|
getImpl(Context, Line, Column, Scope, InlinedAt, Temporary));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Return a (temporary) clone of this.
|
||||||
|
TempMDLocation clone() const { return cloneImpl(); }
|
||||||
|
|
||||||
unsigned getLine() const { return SubclassData32; }
|
unsigned getLine() const { return SubclassData32; }
|
||||||
unsigned getColumn() const { return SubclassData16; }
|
unsigned getColumn() const { return SubclassData16; }
|
||||||
Metadata *getScope() const { return getOperand(0); }
|
Metadata *getScope() const { return getOperand(0); }
|
||||||
|
@ -1054,6 +1073,12 @@ class GenericDwarfNode : public DwarfNode {
|
||||||
StorageType Storage,
|
StorageType Storage,
|
||||||
bool ShouldCreate = true);
|
bool ShouldCreate = true);
|
||||||
|
|
||||||
|
TempGenericDwarfNode cloneImpl() const {
|
||||||
|
return getTemporary(
|
||||||
|
getContext(), getTag(), getHeader(),
|
||||||
|
SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end()));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
unsigned getHash() const { return SubclassData32; }
|
unsigned getHash() const { return SubclassData32; }
|
||||||
|
|
||||||
|
@ -1081,6 +1106,9 @@ public:
|
||||||
getImpl(Context, Tag, Header, DwarfOps, Temporary));
|
getImpl(Context, Tag, Header, DwarfOps, Temporary));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Return a (temporary) clone of this.
|
||||||
|
TempGenericDwarfNode clone() const { return cloneImpl(); }
|
||||||
|
|
||||||
unsigned getTag() const { return SubclassData16; }
|
unsigned getTag() const { return SubclassData16; }
|
||||||
MDString *getHeader() const { return cast_or_null<MDString>(getOperand(0)); }
|
MDString *getHeader() const { return cast_or_null<MDString>(getOperand(0)); }
|
||||||
|
|
||||||
|
|
|
@ -418,6 +418,17 @@ MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
|
||||||
this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context));
|
this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TempMDNode MDNode::clone() const {
|
||||||
|
switch (getMetadataID()) {
|
||||||
|
default:
|
||||||
|
llvm_unreachable("Invalid MDNode subclass");
|
||||||
|
#define HANDLE_MDNODE_LEAF(CLASS) \
|
||||||
|
case CLASS##Kind: \
|
||||||
|
return cast<CLASS>(this)->cloneImpl();
|
||||||
|
#include "llvm/IR/Metadata.def"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool isOperandUnresolved(Metadata *Op) {
|
static bool isOperandUnresolved(Metadata *Op) {
|
||||||
if (auto *N = dyn_cast_or_null<MDNode>(Op))
|
if (auto *N = dyn_cast_or_null<MDNode>(Op))
|
||||||
return !N->isResolved();
|
return !N->isResolved();
|
||||||
|
|
|
@ -180,37 +180,6 @@ static Metadata *mapMetadataOp(Metadata *Op, ValueToValueMapTy &VM,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TempMDTuple cloneMDTuple(const MDTuple *Node) {
|
|
||||||
SmallVector<Metadata *, 4> Elts;
|
|
||||||
Elts.append(Node->op_begin(), Node->op_end());
|
|
||||||
return MDTuple::getTemporary(Node->getContext(), Elts);
|
|
||||||
}
|
|
||||||
|
|
||||||
static TempMDLocation cloneMDLocation(const MDLocation *Node) {
|
|
||||||
return MDLocation::getTemporary(Node->getContext(), Node->getLine(),
|
|
||||||
Node->getColumn(), Node->getScope(),
|
|
||||||
Node->getInlinedAt());
|
|
||||||
}
|
|
||||||
|
|
||||||
static TempGenericDwarfNode
|
|
||||||
cloneGenericDwarfNode(const GenericDwarfNode *Node) {
|
|
||||||
SmallVector<Metadata *, 4> DwarfOps;
|
|
||||||
DwarfOps.append(Node->dwarf_op_begin(), Node->dwarf_op_end());
|
|
||||||
return GenericDwarfNode::getTemporary(Node->getContext(), Node->getTag(),
|
|
||||||
Node->getHeader(), DwarfOps);
|
|
||||||
}
|
|
||||||
|
|
||||||
static TempMDNode cloneMDNode(const MDNode *Node) {
|
|
||||||
switch (Node->getMetadataID()) {
|
|
||||||
default:
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Remap nodes.
|
/// \brief Remap nodes.
|
||||||
///
|
///
|
||||||
/// Insert \c NewNode in the value map, and then remap \c OldNode's operands.
|
/// Insert \c NewNode in the value map, and then remap \c OldNode's operands.
|
||||||
|
@ -253,7 +222,7 @@ static Metadata *mapDistinctNode(const MDNode *Node, ValueToValueMapTy &VM,
|
||||||
ValueMaterializer *Materializer) {
|
ValueMaterializer *Materializer) {
|
||||||
assert(Node->isDistinct() && "Expected distinct node");
|
assert(Node->isDistinct() && "Expected distinct node");
|
||||||
|
|
||||||
MDNode *NewMD = MDNode::replaceWithDistinct(cloneMDNode(Node));
|
MDNode *NewMD = MDNode::replaceWithDistinct(Node->clone());
|
||||||
remap(Node, NewMD, VM, Flags, TypeMapper, Materializer);
|
remap(Node, NewMD, VM, Flags, TypeMapper, Materializer);
|
||||||
return NewMD;
|
return NewMD;
|
||||||
}
|
}
|
||||||
|
@ -268,8 +237,7 @@ static Metadata *mapUniquedNode(const MDNode *Node, ValueToValueMapTy &VM,
|
||||||
assert(Node->isUniqued() && "Expected uniqued node");
|
assert(Node->isUniqued() && "Expected uniqued node");
|
||||||
|
|
||||||
// Create a temporary node upfront in case we have a metadata cycle.
|
// Create a temporary node upfront in case we have a metadata cycle.
|
||||||
auto ClonedMD = cloneMDNode(Node);
|
auto ClonedMD = Node->clone();
|
||||||
|
|
||||||
if (!remap(Node, ClonedMD.get(), VM, Flags, TypeMapper, Materializer))
|
if (!remap(Node, ClonedMD.get(), VM, Flags, TypeMapper, Materializer))
|
||||||
// No operands changed, so use the identity mapping.
|
// No operands changed, so use the identity mapping.
|
||||||
return mapToSelf(VM, Node);
|
return mapToSelf(VM, Node);
|
||||||
|
|
Loading…
Reference in New Issue