summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorWolfgang Pieb <Wolfgang.Pieb@sony.com>2018-12-11 21:13:53 +0000
committerWolfgang Pieb <Wolfgang.Pieb@sony.com>2018-12-11 21:13:53 +0000
commitac874c48ca1071d853a819bf93fe0b95c1122e90 (patch)
tree90972b1c4517fc8f6d00bba69b25135f8000a6ee /llvm/lib/CodeGen
parent79c994d9767212c97f87846c7cd76e678f889052 (diff)
downloadbcm5719-llvm-ac874c48ca1071d853a819bf93fe0b95c1122e90.tar.gz
bcm5719-llvm-ac874c48ca1071d853a819bf93fe0b95c1122e90.zip
[Debuginfo] Prevent CodeGenPrepare from dropping debuginfo references.
This fixes PR39845. CodeGenPrepare employs a transactional model when performing optimizations, i.e. it changes the IR to attempt an optimization and rolls back the change when it finds the change inadequate. It is during the rollback that references to locals were dropped from debug value intrinsics. This patch reinstates debuginfo references during rollbacks. Reviewers: aprantl, vsk Differential Revision: https://reviews.llvm.org/D55396 llvm-svn: 348896
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index d9f0ae38e3a..392e8bc0db4 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2362,6 +2362,8 @@ class TypePromotionTransaction {
/// Keep track of the original uses (pair Instruction, Index).
SmallVector<InstructionAndIdx, 4> OriginalUses;
+ /// Keep track of the debug users.
+ SmallVector<DbgValueInst *, 1> DbgValues;
using use_iterator = SmallVectorImpl<InstructionAndIdx>::iterator;
@@ -2375,6 +2377,10 @@ class TypePromotionTransaction {
Instruction *UserI = cast<Instruction>(U.getUser());
OriginalUses.push_back(InstructionAndIdx(UserI, U.getOperandNo()));
}
+ // Record the debug uses separately. They are not in the instruction's
+ // use list, but they are replaced by RAUW.
+ findDbgValues(DbgValues, Inst);
+
// Now, we can replace the uses.
Inst->replaceAllUsesWith(New);
}
@@ -2387,6 +2393,15 @@ class TypePromotionTransaction {
UseIt != EndIt; ++UseIt) {
UseIt->Inst->setOperand(UseIt->Idx, Inst);
}
+ // RAUW has replaced all original uses with references to the new value,
+ // including the debug uses. Since we are undoing the replacements,
+ // the original debug uses must also be reinstated to maintain the
+ // correctness and utility of debug value instructions.
+ for (auto *DVI: DbgValues) {
+ LLVMContext &Ctx = Inst->getType()->getContext();
+ auto *MV = MetadataAsValue::get(Ctx, ValueAsMetadata::get(Inst));
+ DVI->setOperand(0, MV);
+ }
}
};
OpenPOWER on IntegriCloud