[llvm] [clang-tools-extra] [clang] [DebugInfo][RemoveDIs] Add a DPValue implementation for instcombine sinking (PR #77930)
Stephen Tozer via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 25 05:37:45 PST 2024
================
@@ -4266,19 +4285,140 @@ bool InstCombinerImpl::tryToSinkInstruction(Instruction *I,
// Perform salvaging without the clones, then sink the clones.
if (!DIIClones.empty()) {
- // RemoveDIs: pass in empty vector of DPValues until we get to instrumenting
- // this pass.
- SmallVector<DPValue *, 1> DummyDPValues;
- salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, DummyDPValues);
+ salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, {});
// The clones are in reverse order of original appearance, reverse again to
// maintain the original order.
for (auto &DIIClone : llvm::reverse(DIIClones)) {
DIIClone->insertBefore(&*InsertPos);
LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n');
}
}
+}
- return true;
+void InstCombinerImpl::tryToSinkInstructionDPValues(
+ Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
+ BasicBlock *DestBlock, SmallVectorImpl<DPValue *> &DPValues) {
+ // Implementation of tryToSinkInstructionDbgValues, but for the DPValue of
+ // variable assignments rather than dbg.values.
+
+ // Fetch all DPValues not already in the destination.
+ SmallVector<DPValue *, 2> DPValuesToSalvage;
+ for (auto &DPV : DPValues)
+ if (DPV->getParent() != DestBlock)
+ DPValuesToSalvage.push_back(DPV);
+
+ // Fetch a second collection, of DPValues in the source block that we're going
+ // to sink.
+ SmallVector<DPValue *> DPValuesToSink;
+ for (DPValue *DPV : DPValuesToSalvage)
+ if (DPV->getParent() == SrcBlock)
+ DPValuesToSink.push_back(DPV);
+
+ // Sort DPValues according to their position in the block. This is a partial
----------------
SLTozer wrote:
I actually thinking about the performance of removing all the filtermap/duplicate detection logic and just iterating over getDbgValueRange() to determine whether A or B comes first when they're attached to the same instruction - I submitted a quick test to the compile time tracker[0] though and it looks like it's neutral for most cases and a slowdown in the bad case (testing specifically with RemoveDIs enabled), so I'm happy with this approach.
[0] http://llvm-compile-time-tracker.com/compare.php?from=319280746b199b35c49798383b6dd4c01286c5ff&to=c29a7ff328a4148aabd7e147f2bfc04e9801fcb6&stat=instructions:u
https://github.com/llvm/llvm-project/pull/77930
More information about the cfe-commits
mailing list