Skip to content

Commit fdbf073

Browse files
committed
Revert "[DLCov] Implement DebugLoc coverage tracking (llvm#107279)"
This reverts commit a9d93ec. Reverted due to the commit including a config in LLVM headers that is not available outside of the llvm source tree.
1 parent 262158b commit fdbf073

File tree

7 files changed

+11
-179
lines changed

7 files changed

+11
-179
lines changed

clang/lib/CodeGen/BackendUtil.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -961,22 +961,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
961961
Debugify.setOrigDIVerifyBugsReportFilePath(
962962
CodeGenOpts.DIBugsReportFilePath);
963963
Debugify.registerCallbacks(PIC, MAM);
964-
965-
#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
966-
// If we're using debug location coverage tracking, mark all the
967-
// instructions coming out of the frontend without a DebugLoc as being
968-
// compiler-generated, to prevent both those instructions and new
969-
// instructions that inherit their location from being treated as
970-
// incorrectly empty locations.
971-
for (Function &F : *TheModule) {
972-
if (!F.getSubprogram())
973-
continue;
974-
for (BasicBlock &BB : F)
975-
for (Instruction &I : BB)
976-
if (!I.getDebugLoc())
977-
I.setDebugLoc(DebugLoc::getCompilerGenerated());
978-
}
979-
#endif
980964
}
981965
// Attempt to load pass plugins and register their callbacks with PB.
982966
for (auto &PluginFN : CodeGenOpts.PassPlugins) {

llvm/docs/HowToUpdateDebugInfo.rst

-41
Original file line numberDiff line numberDiff line change
@@ -169,47 +169,6 @@ See the discussion in the section about
169169
:ref:`merging locations<WhenToMergeLocation>` for examples of when the rule for
170170
dropping locations applies.
171171

172-
.. _NewInstLocations:
173-
174-
Setting locations for new instructions
175-
--------------------------------------
176-
177-
Whenever a new instruction is created and there is no suitable location for that
178-
instruction, that instruction should be annotated accordingly. There are a set
179-
of special ``DebugLoc`` values that can be set on an instruction to annotate the
180-
reason that it does not have a valid location. These are as follows:
181-
182-
* ``DebugLoc::getCompilerGenerated()``: This indicates that the instruction is a
183-
compiler-generated instruction, i.e. it is not associated with any user source
184-
code.
185-
186-
* ``DebugLoc::getDropped()``: This indicates that the instruction has
187-
intentionally had its source location removed, according to the rules for
188-
:ref:`dropping locations<WhenToDropLocation>`; this is set automatically by
189-
``Instruction::dropLocation()``.
190-
191-
* ``DebugLoc::getUnknown()``: This indicates that the instruction does not have
192-
a known or currently knowable source location, e.g. that it is infeasible to
193-
determine the correct source location, or that the source location is
194-
ambiguous in a way that LLVM cannot currently represent.
195-
196-
* ``DebugLoc::getTemporary()``: This is used for instructions that we don't
197-
expect to be emitted (e.g. ``UnreachableInst``), and so should not need a
198-
valid location; if we ever try to emit a temporary location into an object/asm
199-
file, this indicates that something has gone wrong.
200-
201-
Where applicable, these should be used instead of leaving an instruction without
202-
an assigned location or explicitly setting the location as ``DebugLoc()``.
203-
Ordinarily these special locations are identical to an absent location, but LLVM
204-
built with coverage-tracking
205-
(``-DLLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING="COVERAGE"``) will keep track of
206-
these special locations in order to detect unintentionally-missing locations;
207-
for this reason, the most important rule is to *not* apply any of these if it
208-
isn't clear which, if any, is appropriate - an absent location can be detected
209-
and fixed, while an incorrectly annotated instruction is much harder to detect.
210-
On the other hand, if any of these clearly apply, then they should be used to
211-
prevent false positives from being flagged up.
212-
213172
Rules for updating debug values
214173
===============================
215174

llvm/include/llvm/IR/DebugLoc.h

+1-95
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_IR_DEBUGLOC_H
1515
#define LLVM_IR_DEBUGLOC_H
1616

17-
#include "llvm/Config/config.h"
1817
#include "llvm/IR/TrackingMDRef.h"
1918
#include "llvm/Support/DataTypes.h"
2019

@@ -23,73 +22,6 @@ namespace llvm {
2322
class LLVMContext;
2423
class raw_ostream;
2524
class DILocation;
26-
class Function;
27-
28-
#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
29-
// Used to represent different "kinds" of DebugLoc, expressing that the
30-
// instruction it is part of is either normal and should contain a valid
31-
// DILocation, or otherwise describing the reason why the instruction does
32-
// not contain a valid DILocation.
33-
enum class DebugLocKind : uint8_t {
34-
// The instruction is expected to contain a valid DILocation.
35-
Normal,
36-
// The instruction is compiler-generated, i.e. it is not associated with any
37-
// line in the original source.
38-
CompilerGenerated,
39-
// The instruction has intentionally had its source location removed,
40-
// typically because it was moved outside of its original control-flow and
41-
// presenting the prior source location would be misleading for debuggers
42-
// or profilers.
43-
Dropped,
44-
// The instruction does not have a known or currently knowable source
45-
// location, e.g. the attribution is ambiguous in a way that can't be
46-
// represented, or determining the correct location is complicated and
47-
// requires future developer effort.
48-
Unknown,
49-
// DebugLoc is attached to an instruction that we don't expect to be
50-
// emitted, and so can omit a valid DILocation; we don't expect to ever try
51-
// and emit these into the line table, and trying to do so is a sign that
52-
// something has gone wrong (most likely a DebugLoc leaking from a transient
53-
// compiler-generated instruction).
54-
Temporary
55-
};
56-
57-
// Extends TrackingMDNodeRef to also store a DebugLocKind, allowing Debugify
58-
// to ignore intentionally-empty DebugLocs.
59-
class DILocAndCoverageTracking : public TrackingMDNodeRef {
60-
public:
61-
DebugLocKind Kind;
62-
// Default constructor for empty DebugLocs.
63-
DILocAndCoverageTracking()
64-
: TrackingMDNodeRef(nullptr), Kind(DebugLocKind::Normal) {}
65-
// Valid or nullptr MDNode*, normal DebugLocKind.
66-
DILocAndCoverageTracking(const MDNode *Loc)
67-
: TrackingMDNodeRef(const_cast<MDNode *>(Loc)),
68-
Kind(DebugLocKind::Normal) {}
69-
DILocAndCoverageTracking(const DILocation *Loc);
70-
// Explicit DebugLocKind, which always means a nullptr MDNode*.
71-
DILocAndCoverageTracking(DebugLocKind Kind)
72-
: TrackingMDNodeRef(nullptr), Kind(Kind) {}
73-
};
74-
template <> struct simplify_type<DILocAndCoverageTracking> {
75-
using SimpleType = MDNode *;
76-
77-
static MDNode *getSimplifiedValue(DILocAndCoverageTracking &MD) {
78-
return MD.get();
79-
}
80-
};
81-
template <> struct simplify_type<const DILocAndCoverageTracking> {
82-
using SimpleType = MDNode *;
83-
84-
static MDNode *getSimplifiedValue(const DILocAndCoverageTracking &MD) {
85-
return MD.get();
86-
}
87-
};
88-
89-
using DebugLocTrackingRef = DILocAndCoverageTracking;
90-
#else
91-
using DebugLocTrackingRef = TrackingMDNodeRef;
92-
#endif // ENABLE_DEBUGLOC_COVERAGE_TRACKING
9325

9426
/// A debug info location.
9527
///
@@ -99,8 +31,7 @@ namespace llvm {
9931
/// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a
10032
/// one based on relatively opaque \a MDNode pointers.
10133
class DebugLoc {
102-
103-
DebugLocTrackingRef Loc;
34+
TrackingMDNodeRef Loc;
10435

10536
public:
10637
DebugLoc() = default;
@@ -116,31 +47,6 @@ namespace llvm {
11647
/// IR.
11748
explicit DebugLoc(const MDNode *N);
11849

119-
#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
120-
DebugLoc(DebugLocKind Kind) : Loc(Kind) {}
121-
DebugLocKind getKind() const { return Loc.Kind; }
122-
#endif
123-
124-
#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
125-
static inline DebugLoc getTemporary() {
126-
return DebugLoc(DebugLocKind::Temporary);
127-
}
128-
static inline DebugLoc getUnknown() {
129-
return DebugLoc(DebugLocKind::Unknown);
130-
}
131-
static inline DebugLoc getCompilerGenerated() {
132-
return DebugLoc(DebugLocKind::CompilerGenerated);
133-
}
134-
static inline DebugLoc getDropped() {
135-
return DebugLoc(DebugLocKind::Dropped);
136-
}
137-
#else
138-
static inline DebugLoc getTemporary() { return DebugLoc(); }
139-
static inline DebugLoc getUnknown() { return DebugLoc(); }
140-
static inline DebugLoc getCompilerGenerated() { return DebugLoc(); }
141-
static inline DebugLoc getDropped() { return DebugLoc(); }
142-
#endif // ENABLE_DEBUGLOC_COVERAGE_TRACKING
143-
14450
/// Get the underlying \a DILocation.
14551
///
14652
/// \pre !*this or \c isa<DILocation>(getAsMDNode()).

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -2098,10 +2098,6 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
20982098
}
20992099

21002100
if (!DL) {
2101-
// FIXME: We could assert that `DL.getKind() != DebugLocKind::Temporary`
2102-
// here, or otherwise record any temporary DebugLocs seen to ensure that
2103-
// transient compiler-generated instructions aren't leaking their DLs to
2104-
// other instructions.
21052101
// We have an unspecified location, which might want to be line 0.
21062102
// If we have already emitted a line-0 record, don't repeat it.
21072103
if (LastAsmLine == 0)

llvm/lib/IR/DebugInfo.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,8 @@ void Instruction::updateLocationAfterHoist() { dropLocation(); }
987987

988988
void Instruction::dropLocation() {
989989
const DebugLoc &DL = getDebugLoc();
990-
if (!DL) {
991-
setDebugLoc(DebugLoc::getDropped());
990+
if (!DL)
992991
return;
993-
}
994992

995993
// If this isn't a call, drop the location to allow a location from a
996994
// preceding instruction to propagate.
@@ -1002,7 +1000,7 @@ void Instruction::dropLocation() {
10021000
}
10031001

10041002
if (!MayLowerToCall) {
1005-
setDebugLoc(DebugLoc::getDropped());
1003+
setDebugLoc(DebugLoc());
10061004
return;
10071005
}
10081006

@@ -1021,7 +1019,7 @@ void Instruction::dropLocation() {
10211019
//
10221020
// One alternative is to set a line 0 location with the existing scope and
10231021
// inlinedAt info. The location might be sensitive to when inlining occurs.
1024-
setDebugLoc(DebugLoc::getDropped());
1022+
setDebugLoc(DebugLoc());
10251023
}
10261024

10271025
//===----------------------------------------------------------------------===//

llvm/lib/IR/DebugLoc.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
#include "llvm/IR/DebugInfo.h"
1212
using namespace llvm;
1313

14-
#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
15-
DILocAndCoverageTracking::DILocAndCoverageTracking(const DILocation *L)
16-
: TrackingMDNodeRef(const_cast<DILocation *>(L)),
17-
Kind(DebugLocKind::Normal) {}
18-
#endif // ENABLE_DEBUGLOC_COVERAGE_TRACKING
19-
2014
//===----------------------------------------------------------------------===//
2115
// DebugLoc Implementation
2216
//===----------------------------------------------------------------------===//

llvm/lib/Transforms/Utils/Debugify.cpp

+7-12
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,6 @@ bool llvm::stripDebugifyMetadata(Module &M) {
290290
return Changed;
291291
}
292292

293-
bool hasLoc(const Instruction &I) {
294-
const DILocation *Loc = I.getDebugLoc().get();
295-
#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
296-
DebugLocKind Kind = I.getDebugLoc().getKind();
297-
return Loc || Kind != DebugLocKind::Normal;
298-
#else
299-
return Loc;
300-
#endif
301-
}
302-
303293
bool llvm::collectDebugInfoMetadata(Module &M,
304294
iterator_range<Module::iterator> Functions,
305295
DebugInfoPerPass &DebugInfoBeforePass,
@@ -372,7 +362,9 @@ bool llvm::collectDebugInfoMetadata(Module &M,
372362
LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n');
373363
DebugInfoBeforePass.InstToDelete.insert({&I, &I});
374364

375-
DebugInfoBeforePass.DILocations.insert({&I, hasLoc(I)});
365+
const DILocation *Loc = I.getDebugLoc().get();
366+
bool HasLoc = Loc != nullptr;
367+
DebugInfoBeforePass.DILocations.insert({&I, HasLoc});
376368
}
377369
}
378370
}
@@ -615,7 +607,10 @@ bool llvm::checkDebugInfoMetadata(Module &M,
615607

616608
LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n');
617609

618-
DebugInfoAfterPass.DILocations.insert({&I, hasLoc(I)});
610+
const DILocation *Loc = I.getDebugLoc().get();
611+
bool HasLoc = Loc != nullptr;
612+
613+
DebugInfoAfterPass.DILocations.insert({&I, HasLoc});
619614
}
620615
}
621616
}

0 commit comments

Comments
 (0)