summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/DebugInfo.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-28 23:48:02 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-28 23:48:02 +0000
commit9c3b89448a0b7c6b122e80b36d287317e75d6ac3 (patch)
tree9bafc9930696c88e6827b974b5271bfe670a7950 /llvm/lib/IR/DebugInfo.cpp
parentdb962e2afb6d23acb8c4509b0ee431eb267e7a85 (diff)
downloadbcm5719-llvm-9c3b89448a0b7c6b122e80b36d287317e75d6ac3.tar.gz
bcm5719-llvm-9c3b89448a0b7c6b122e80b36d287317e75d6ac3.zip
DebugInfo: Use TempMDNode in DIDescriptor::replaceAllUsesWith()
Start using `TempMDNode` in `DIDescriptor::replaceAllUsesWith()` (effectively `std::unique_ptr<MDNode, MDNode::deleteTemporary>`). Besides making ownership more explicit, this prepares for when `DIDescriptor` refers to nodes that are *not* `MDTuple`. The old logic for "replacing" a node with itself used `MDNode::get()` to return a new (uniqued) `MDTuple`, while the new logic just defers to `MDNode::replaceWithUniqued()` (which also typically saves an allocation and RAUW traffic by mutating the temporary in place). llvm-svn: 230879
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 6590661311a..8e996148955 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -376,35 +376,31 @@ bool DIDescriptor::isExpression() const {
// Simple Descriptor Constructors and other Methods
//===----------------------------------------------------------------------===//
-void DIDescriptor::replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D) {
-
+void DIDescriptor::replaceAllUsesWith(LLVMContext &, DIDescriptor D) {
assert(DbgNode && "Trying to replace an unverified type!");
+ assert(DbgNode->isTemporary() && "Expected temporary node");
+ TempMDNode Temp(get());
// Since we use a TrackingVH for the node, its easy for clients to manufacture
// legitimate situations where they want to replaceAllUsesWith() on something
// which, due to uniquing, has merged with the source. We shield clients from
// this detail by allowing a value to be replaced with replaceAllUsesWith()
// itself.
- const MDNode *DN = D;
- if (DbgNode == DN) {
- SmallVector<Metadata *, 10> Ops(DbgNode->op_begin(), DbgNode->op_end());
- DN = MDNode::get(VMContext, Ops);
+ if (Temp.get() == D.get()) {
+ DbgNode = MDNode::replaceWithUniqued(std::move(Temp));
+ return;
}
- assert(DbgNode->isTemporary() && "Expected temporary node");
- auto *Node = const_cast<MDNode *>(DbgNode);
- Node->replaceAllUsesWith(const_cast<MDNode *>(DN));
- MDNode::deleteTemporary(Node);
- DbgNode = DN;
+ Temp->replaceAllUsesWith(D.get());
+ DbgNode = D.get();
}
void DIDescriptor::replaceAllUsesWith(MDNode *D) {
assert(DbgNode && "Trying to replace an unverified type!");
assert(DbgNode != D && "This replacement should always happen");
assert(DbgNode->isTemporary() && "Expected temporary node");
- auto *Node = const_cast<MDNode *>(DbgNode);
+ TempMDNode Node(get());
Node->replaceAllUsesWith(D);
- MDNode::deleteTemporary(Node);
}
bool DICompileUnit::Verify() const {
OpenPOWER on IntegriCloud