[PATCH] D79949: [WIP][Example] Drop out-of-scope variable locations
Orlando Cazalet-Hyams via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 14 10:16:53 PDT 2020
Orlando created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
I have no intention of this code landing. It's a quick prototype I made for https://bugs.llvm.org/show_bug.cgi?id=45889.
This "feature" is enabled by default and you can turn it off with the llvm flag `-disable-thing`.
NOTE: This is based on top of the not-yet-landed D79571 <https://reviews.llvm.org/D79571>
https://reviews.llvm.org/D79949
Files:
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -86,6 +86,10 @@
#define DEBUG_TYPE "dwarfdebug"
STATISTIC(NumCSParams, "Number of dbg call site params created");
+STATISTIC(XXX_ExcludedRanges, "XXX Num DBG_VALUE ranges outside of the var scope");
+STATISTIC(XXX_ExcludeChecks, "XXX Range broken, exit checks");
+
+static cl::opt<bool> DisableThing("disable-thing", cl::init(false));
static cl::opt<bool>
DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
@@ -1623,6 +1627,69 @@
// open ranges and check if its location is valid for a single value
// location.
if (EI->isDbgValue()) {
+ // Return true if the var loc range being evaluated lives entirely outside
+ // its scope.
+ auto RangeExistsOutsideScope = [&]() -> bool {
+ XXX_ExcludeChecks++;
+ auto MBB = Instr->getParent();
+ auto DL = Instr->getDebugLoc();
+ LexicalScope *InstrScope = LScopes.findLexicalScope(DL);
+ // Scope doesn't exist?
+ if (!InstrScope)
+ return false;
+
+ DbgValueHistoryMap::EntryIndex EndIndex = EI->getEndIndex();
+ if (EndIndex == DbgValueHistoryMap::NoEntry)
+ // FIXME: I didn't want to think too hard about what to do here.
+ return false;
+ const DbgValueHistoryMap::Entry& End = Entries[EndIndex];
+ auto *EndInstr = End.getInstr();
+ // Make sure we're only looking in the same BB.
+ if (EndInstr->getParent() != Instr->getParent())
+ return false;
+
+ // FIXME: Is this necessary?
+ auto &LSRange = InstrScope->getRanges();
+ if (LSRange.size() == 0)
+ return false;
+
+ // Scan forwards; return false if we find any instruction which lives in
+ // a scope dominated by our DBG_VALUE's scope.
+ MachineBasicBlock::const_iterator Next(Instr);
+ MachineBasicBlock::const_iterator RangeEndInstr(EndInstr);
+ for (++Next; Next != MBB->end(); ++Next) {
+ auto NextDL = Next->getDebugLoc();
+ if (!NextDL)
+ // We don't know anything about this instr, let's just bail.
+ return false;
+ LexicalScope *NextScope = LScopes.findLexicalScope(NextDL);
+ if (!NextScope)
+ // We don't know anything about this instr, let's just bail.
+ return false;
+ // scope(Next) is child of scope(Instr) so do not omit this range.
+ if (InstrScope->dominates(NextScope))
+ // FIXME: This is too restrictive. If the range end is a DBG_VALUE
+ // in a scope dominated by Instr we'll exit here. Maybe we need
+ // a check like the one below (Next==RangeEndInstr) at the top
+ // of this loop?
+ // if(!End.isClobber() && Next==RangeEndInstr)
+ // return true;
+ return false;
+ if (Next == RangeEndInstr) {
+ XXX_ExcludedRanges++;
+ // We've got all the way to the range end without touching a
+ // dominated scope.
+ return true;
+ }
+ }
+
+ XXX_ExcludedRanges++;
+ return true;
+ };
+
+ if (!DisableThing && RangeExistsOutsideScope())
+ continue;
+
// Do not add undef debug values, as they are redundant information in
// the location list entries. An undef debug results in an empty location
// description. If there are any non-undef fragments then padding pieces
@@ -1654,7 +1721,7 @@
LLVM_DEBUG(dbgs() << "Omitting location list entry with empty range.\n");
continue;
}
-
+
SmallVector<DbgValueLoc, 4> Values;
for (auto &R : OpenRanges)
Values.push_back(R.second);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79949.264017.patch
Type: text/x-patch
Size: 3883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200514/f104ec45/attachment.bin>
More information about the llvm-commits
mailing list