Skip to content

Commit c23608b

Browse files
authored
[DebugInfo][RemoveDIs] Don't pointlessly scan funcs for debug-info (#79327)
The utility functions this patch modifies are part of cleanly transitioning from a context where we use dbg.value intrinsics to one where we use DPValue objects to record debug-info, and back again. However, this is a waste of time in non-debug builds (i.e. no -g on the command line). We still have to call the function on all blocks though to set the IsNewDbgInfoFormat flag. To reduce the overhead of this, test whether there's any debug-info in the function by checking whether the function has a DISubprogram, and pass a flag down to the utility functions indicating whether they can skip the scan. It feels a bit dumb to me now that we're scanning and setting a flag in a load of blocks when we don't have to -- however it's been really valuable during development for working out where spurious dbg.value intrinsics leak into a RemoveDIs context. Happily we'll be able to just delete this flag entirely when RemoveDIs lands and sticks, and the conversion routines will eventually be pushed down into the debug-info autoupgrade path.
1 parent 3ed98cb commit c23608b

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
8181
/// intrinsics into DPMarker / DPValue records. Deletes all dbg.values in
8282
/// the process and sets IsNewDbgInfoFormat = true. Only takes effect if
8383
/// the UseNewDbgInfoFormat LLVM command line option is given.
84-
void convertToNewDbgValues();
84+
/// \param HasNoDebugInfo Flag indicating the scan of instructions should be
85+
/// skipped as the function is known to have no debug-info.
86+
void convertToNewDbgValues(bool HasNoDebugInfo = false);
8587

8688
/// Convert variable location debugging information stored in DPMarkers and
8789
/// DPValues into the dbg.value intrinsic representation. Sets
8890
/// IsNewDbgInfoFormat = false.
89-
void convertFromNewDbgValues();
91+
/// \param HasNoDebugInfo Flag indicating the scan of instructions should be
92+
/// skipped as the function is known to have no debug-info.
93+
void convertFromNewDbgValues(bool HasNoDebugInfo = false);
9094

9195
/// Ensure the block is in "old" dbg.value format (\p NewFlag == false) or
9296
/// in the new format (\p NewFlag == true), converting to the desired format

llvm/lib/IR/BasicBlock.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ DPMarker *BasicBlock::createMarker(InstListType::iterator It) {
6060
return DPM;
6161
}
6262

63-
void BasicBlock::convertToNewDbgValues() {
63+
void BasicBlock::convertToNewDbgValues(bool HasNoDebugInfo) {
6464
// Is the command line option set?
6565
if (!UseNewDbgInfoFormat)
6666
return;
6767

6868
IsNewDbgInfoFormat = true;
6969

70+
// If the caller knows there's no debug-info in this function, do nothing.
71+
if (HasNoDebugInfo)
72+
return;
73+
7074
// Iterate over all instructions in the instruction list, collecting dbg.value
7175
// instructions and converting them to DPValues. Once we find a "real"
7276
// instruction, attach all those DPValues to a DPMarker in that instruction.
@@ -93,10 +97,14 @@ void BasicBlock::convertToNewDbgValues() {
9397
}
9498
}
9599

96-
void BasicBlock::convertFromNewDbgValues() {
100+
void BasicBlock::convertFromNewDbgValues(bool HasNoDebugInfo) {
97101
invalidateOrders();
98102
IsNewDbgInfoFormat = false;
99103

104+
// If the caller knows there's no debug-info in this function, do nothing.
105+
if (HasNoDebugInfo)
106+
return;
107+
100108
// Iterate over the block, finding instructions annotated with DPMarkers.
101109
// Convert any attached DPValues to dbg.values and insert ahead of the
102110
// instruction.

llvm/lib/IR/Function.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ static cl::opt<unsigned> NonGlobalValueMaxNameSize(
8383

8484
void Function::convertToNewDbgValues() {
8585
IsNewDbgInfoFormat = true;
86+
bool HasNoDebugInfo = getSubprogram() == nullptr;
8687
for (auto &BB : *this) {
87-
BB.convertToNewDbgValues();
88+
BB.convertToNewDbgValues(HasNoDebugInfo);
8889
}
8990
}
9091

9192
void Function::convertFromNewDbgValues() {
9293
IsNewDbgInfoFormat = false;
94+
bool HasNoDebugInfo = getSubprogram() == nullptr;
9395
for (auto &BB : *this) {
94-
BB.convertFromNewDbgValues();
96+
BB.convertFromNewDbgValues(HasNoDebugInfo);
9597
}
9698
}
9799

0 commit comments

Comments
 (0)