Skip to content

Commit 121a49d

Browse files
committed
[LiveDebugValues] Add switches for using instr-ref variable locations
This patch adds the -Xclang option "-fexperimental-debug-variable-locations" and same LLVM CodeGen option, to pick which variable location tracking solution to use. Right now all the switch does is pick which LiveDebugValues implementation to use, the normal VarLoc one or the instruction referencing one in rGae6f78824031. Over time, the aim is to add fragments of support in aid of the value-tracking RFC: http://lists.llvm.org/pipermail/llvm-dev/2020-February/139440.html also controlled by this command line switch. That will slowly move variable locations to be defined by an instruction calculating a value, and a DBG_INSTR_REF instruction referring to that value. Thus, this is going to grow into a "use the new kind of variable locations" switch, rather than just "use the new LiveDebugValues implementation". Differential Revision: https://reviews.llvm.org/D83048
1 parent 0d2fe90 commit 121a49d

File tree

9 files changed

+52
-5
lines changed

9 files changed

+52
-5
lines changed

Diff for: clang/include/clang/Basic/CodeGenOptions.def

+3
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ ENUM_CODEGENOPT(DebuggerTuning, llvm::DebuggerKind, 2,
325325
/// emitted.
326326
VALUE_CODEGENOPT(DwarfVersion, 3, 0)
327327

328+
/// Whether to use experimental new variable location tracking.
329+
CODEGENOPT(ValueTrackingVariableLocations, 1, 0)
330+
328331
/// Whether we should emit CodeView debug information. It's possible to emit
329332
/// CodeView and DWARF into the same object.
330333
CODEGENOPT(EmitCodeView, 1, 0)

Diff for: clang/include/clang/Driver/Options.td

+3
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,9 @@ def fdebug_pass_manager : Flag<["-"], "fdebug-pass-manager">,
38703870
HelpText<"Prints debug information for the new pass manager">;
38713871
def fno_debug_pass_manager : Flag<["-"], "fno-debug-pass-manager">,
38723872
HelpText<"Disables debug printing for the new pass manager">;
3873+
def fexperimental_debug_variable_locations : Flag<["-"],
3874+
"fexperimental-debug-variable-locations">,
3875+
HelpText<"Use experimental new value-tracking variable locations">;
38733876
// The driver option takes the key as a parameter to the -msign-return-address=
38743877
// and -mbranch-protection= options, but CC1 has a separate option so we
38753878
// don't have to parse the parameter twice.

Diff for: clang/lib/CodeGen/BackendUtil.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ static void initTargetOptions(DiagnosticsEngine &Diags,
520520
Options.EmitAddrsig = CodeGenOpts.Addrsig;
521521
Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
522522
Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
523+
Options.ValueTrackingVariableLocations =
524+
CodeGenOpts.ValueTrackingVariableLocations;
523525
Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;
524526

525527
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;

Diff for: clang/lib/Frontend/CompilerInvocation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,9 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
835835
llvm::is_contained(DebugEntryValueArchs, T.getArch()))
836836
Opts.EmitCallSiteInfo = true;
837837

838+
Opts.ValueTrackingVariableLocations =
839+
Args.hasArg(OPT_fexperimental_debug_variable_locations);
840+
838841
Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
839842
Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
840843
Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);

Diff for: clang/test/Driver/debug-var-experimental-switch.c

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %clang -Xclang -fexperimental-debug-variable-locations -fsyntax-only -disable-llvm-passes %s
2+
int main() {}

Diff for: llvm/include/llvm/CodeGen/CommandFlags.h

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ bool getEmitCallSiteInfo();
116116

117117
bool getEnableDebugEntryValues();
118118

119+
bool getValueTrackingVariableLocations();
120+
119121
bool getForceDwarfFrameSection();
120122

121123
bool getXRayOmitFunctionIndex();

Diff for: llvm/include/llvm/Target/TargetOptions.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ namespace llvm {
126126
EmitStackSizeSection(false), EnableMachineOutliner(false),
127127
SupportsDefaultOutlining(false), EmitAddrsig(false),
128128
EmitCallSiteInfo(false), SupportsDebugEntryValues(false),
129-
EnableDebugEntryValues(false), ForceDwarfFrameSection(false),
130-
XRayOmitFunctionIndex(false),
129+
EnableDebugEntryValues(false), ValueTrackingVariableLocations(false),
130+
ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false),
131131
FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
132132

133133
/// DisableFramePointerElim - This returns true if frame pointer elimination
@@ -285,6 +285,11 @@ namespace llvm {
285285
/// production.
286286
bool ShouldEmitDebugEntryValues() const;
287287

288+
// When set to true, use experimental new debug variable location tracking,
289+
// which seeks to follow the values of variables rather than their location,
290+
// post isel.
291+
unsigned ValueTrackingVariableLocations : 1;
292+
288293
/// Emit DWARF debug frame section.
289294
unsigned ForceDwarfFrameSection : 1;
290295

Diff for: llvm/lib/CodeGen/CommandFlags.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ CGOPT(bool, EnableStackSizeSection)
8585
CGOPT(bool, EnableAddrsig)
8686
CGOPT(bool, EmitCallSiteInfo)
8787
CGOPT(bool, EnableDebugEntryValues)
88+
CGOPT(bool, ValueTrackingVariableLocations)
8889
CGOPT(bool, ForceDwarfFrameSection)
8990
CGOPT(bool, XRayOmitFunctionIndex)
9091

@@ -400,6 +401,12 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
400401
cl::init(false));
401402
CGBINDOPT(EnableDebugEntryValues);
402403

404+
static cl::opt<bool> ValueTrackingVariableLocations(
405+
"experimental-debug-variable-locations",
406+
cl::desc("Use experimental new value-tracking variable locations"),
407+
cl::init(false));
408+
CGBINDOPT(ValueTrackingVariableLocations);
409+
403410
static cl::opt<bool> ForceDwarfFrameSection(
404411
"force-dwarf-frame-section",
405412
cl::desc("Always emit a debug frame section."), cl::init(false));
@@ -475,6 +482,7 @@ TargetOptions codegen::InitTargetOptionsFromCodeGenFlags() {
475482
Options.EmitAddrsig = getEnableAddrsig();
476483
Options.EmitCallSiteInfo = getEmitCallSiteInfo();
477484
Options.EnableDebugEntryValues = getEnableDebugEntryValues();
485+
Options.ValueTrackingVariableLocations = getValueTrackingVariableLocations();
478486
Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
479487
Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
480488

Diff for: llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/CodeGen/Passes.h"
1515
#include "llvm/InitializePasses.h"
1616
#include "llvm/Pass.h"
17+
#include "llvm/Target/TargetMachine.h"
1718

1819
/// \file LiveDebugValues.cpp
1920
///
@@ -40,7 +41,10 @@ class LiveDebugValues : public MachineFunctionPass {
4041
static char ID;
4142

4243
LiveDebugValues();
43-
~LiveDebugValues() { delete TheImpl; }
44+
~LiveDebugValues() {
45+
if (TheImpl)
46+
delete TheImpl;
47+
}
4448

4549
/// Calculate the liveness information for the given machine function.
4650
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -57,6 +61,7 @@ class LiveDebugValues : public MachineFunctionPass {
5761

5862
private:
5963
LDVImpl *TheImpl;
64+
TargetPassConfig *TPC;
6065
};
6166

6267
char LiveDebugValues::ID = 0;
@@ -69,10 +74,24 @@ INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false,
6974
/// Default construct and initialize the pass.
7075
LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
7176
initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
72-
TheImpl = llvm::makeVarLocBasedLiveDebugValues();
77+
TheImpl = nullptr;
7378
}
7479

7580
bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
76-
auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
81+
if (!TheImpl) {
82+
TPC = getAnalysisIfAvailable<TargetPassConfig>();
83+
84+
bool InstrRefBased = false;
85+
if (TPC) {
86+
auto &TM = TPC->getTM<TargetMachine>();
87+
InstrRefBased = TM.Options.ValueTrackingVariableLocations;
88+
}
89+
90+
if (InstrRefBased)
91+
TheImpl = llvm::makeInstrRefBasedLiveDebugValues();
92+
else
93+
TheImpl = llvm::makeVarLocBasedLiveDebugValues();
94+
}
95+
7796
return TheImpl->ExtendRanges(MF, TPC);
7897
}

0 commit comments

Comments
 (0)