summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Metadata.cpp
diff options
context:
space:
mode:
authorPetar Jovanovic <petar.jovanovic@mips.com>2018-01-30 16:42:04 +0000
committerPetar Jovanovic <petar.jovanovic@mips.com>2018-01-30 16:42:04 +0000
commit9208e8fbf65d885b55dda55097e7235dfe9c5c8f (patch)
treec196349de9677072dbf3523e34832c840ff44a49 /llvm/lib/IR/Metadata.cpp
parentb36fbbc3ec9fe0e1636c16d38083c65aefbafa7e (diff)
downloadbcm5719-llvm-9208e8fbf65d885b55dda55097e7235dfe9c5c8f.tar.gz
bcm5719-llvm-9208e8fbf65d885b55dda55097e7235dfe9c5c8f.zip
[DeadArgumentElimination] Preserve llvm.dbg.values's first argument
When removing return value Dead Argument Elimination pass clobbers first llvm.dbg.value’s argument for live arguments of that function by replacing it with nullptr. In the next pass it will be deleted, so debug location about those arguments are lost. This change fixes it. Patch by Djordje Todorovic. Differential Revision: https://reviews.llvm.org/D42541 llvm-svn: 323784
Diffstat (limited to 'llvm/lib/IR/Metadata.cpp')
-rw-r--r--llvm/lib/IR/Metadata.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index a148ab65fc8..4f49312dfc4 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -329,12 +329,20 @@ bool ReplaceableMetadataImpl::isReplaceable(const Metadata &MD) {
return dyn_cast<ValueAsMetadata>(&MD);
}
-static Function *getLocalFunction(Value *V) {
+static DISubprogram *getLocalFunctionMetadata(Value *V) {
assert(V && "Expected value");
- if (auto *A = dyn_cast<Argument>(V))
- return A->getParent();
- if (BasicBlock *BB = cast<Instruction>(V)->getParent())
- return BB->getParent();
+ if (auto *A = dyn_cast<Argument>(V)) {
+ if (auto *Fn = A->getParent())
+ return Fn->getSubprogram();
+ return nullptr;
+ }
+
+ if (BasicBlock *BB = cast<Instruction>(V)->getParent()) {
+ if (auto *Fn = BB->getParent())
+ return Fn->getSubprogram();
+ return nullptr;
+ }
+
return nullptr;
}
@@ -410,9 +418,9 @@ void ValueAsMetadata::handleRAUW(Value *From, Value *To) {
delete MD;
return;
}
- if (getLocalFunction(From) && getLocalFunction(To) &&
- getLocalFunction(From) != getLocalFunction(To)) {
- // Function changed.
+ if (getLocalFunctionMetadata(From) && getLocalFunctionMetadata(To) &&
+ getLocalFunctionMetadata(From) != getLocalFunctionMetadata(To)) {
+ // DISubprogram changed.
MD->replaceAllUsesWith(nullptr);
delete MD;
return;
OpenPOWER on IntegriCloud