LLVM 24.0.0git
LiveDebugValues.cpp
Go to the documentation of this file.
1//===- LiveDebugValues.cpp - Tracking Debug Value MIs ---------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "LiveDebugValues.h"
10
15#include "llvm/CodeGen/Passes.h"
18#include "llvm/Pass.h"
22
23/// \file LiveDebugValues.cpp
24///
25/// The LiveDebugValues pass extends the range of variable locations
26/// (specified by DBG_VALUE instructions) from single blocks to successors
27/// and any other code locations where the variable location is valid.
28/// There are currently two implementations: the "VarLoc" implementation
29/// explicitly tracks the location of a variable, while the "InstrRef"
30/// implementation tracks the values defined by instructions through locations.
31///
32/// This file implements neither; it merely registers the pass, allows the
33/// user to pick which implementation will be used to propagate variable
34/// locations.
35
36#define DEBUG_TYPE "livedebugvalues"
37
38using namespace llvm;
39
40static cl::opt<bool>
41 ForceInstrRefLDV("force-instr-ref-livedebugvalues", cl::Hidden,
42 cl::desc("Use instruction-ref based LiveDebugValues with "
43 "normal DBG_VALUE inputs"),
44 cl::init(false));
45
47 "experimental-debug-variable-locations",
48 cl::desc("Use experimental new value-tracking variable locations"));
49
50// Options to prevent pathological compile-time behavior. If InputBBLimit and
51// InputDbgValueLimit are both exceeded, range extension is disabled.
53 "livedebugvalues-input-bb-limit",
54 cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"),
55 cl::init(10000), cl::Hidden);
57 "livedebugvalues-input-dbg-value-limit",
59 "Maximum input DBG_VALUE insts supported by debug range extension"),
60 cl::init(50000), cl::Hidden);
61
62namespace {
63/// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or
64/// InstrRefBasedLDV to perform location propagation, via the LDVImpl
65/// base class.
66class LiveDebugValuesLegacy : public MachineFunctionPass {
67public:
68 static char ID;
69
70 LiveDebugValuesLegacy();
71 ~LiveDebugValuesLegacy() override = default;
72
73 /// Calculate the liveness information for the given machine function.
74 bool runOnMachineFunction(MachineFunction &MF) override;
75
76 void getAnalysisUsage(AnalysisUsage &AU) const override {
77 AU.setPreservesCFG();
80 }
81};
82
83struct LiveDebugValues {
84 LiveDebugValues();
85 ~LiveDebugValues() = default;
86 bool run(MachineFunction &MF, bool ShouldEmitDebugEntryValues);
87
88private:
89 std::unique_ptr<LDVImpl> InstrRefImpl;
90 std::unique_ptr<LDVImpl> VarLocImpl;
92};
93} // namespace
94
95char LiveDebugValuesLegacy::ID = 0;
96
97char &llvm::LiveDebugValuesID = LiveDebugValuesLegacy::ID;
98
99INITIALIZE_PASS(LiveDebugValuesLegacy, DEBUG_TYPE, "Live DEBUG_VALUE analysis",
100 false, false)
101
102/// Default construct and initialize the pass.
103LiveDebugValuesLegacy::LiveDebugValuesLegacy() : MachineFunctionPass(ID) {}
104
105LiveDebugValues::LiveDebugValues() {
106 InstrRefImpl =
107 std::unique_ptr<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues());
108 VarLocImpl = std::unique_ptr<LDVImpl>(llvm::makeVarLocBasedLiveDebugValues());
109}
110
111PreservedAnalyses
114 if (!LiveDebugValues().run(MF, ShouldEmitDebugEntryValues))
115 return PreservedAnalyses::all();
117 PA.preserveSet<CFGAnalyses>();
118 return PA;
119}
120
122 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
123 OS << MapClassName2PassName(name());
124 if (ShouldEmitDebugEntryValues)
125 OS << "<emit-debug-entry-values>";
126}
127
128bool LiveDebugValuesLegacy::runOnMachineFunction(MachineFunction &MF) {
129 auto *TPC = &getAnalysis<TargetPassConfig>();
130 return LiveDebugValues().run(
132}
133
134bool LiveDebugValues::run(MachineFunction &MF,
135 bool ShouldEmitDebugEntryValues) {
136 bool InstrRefBased = MF.useDebugInstrRef();
137 // Allow the user to force selection of InstrRef LDV.
138 InstrRefBased |= ForceInstrRefLDV;
139
140 LDVImpl *TheImpl = &*VarLocImpl;
141
142 MachineDominatorTree *DomTree = nullptr;
143 if (InstrRefBased) {
144 DomTree = &MDT;
145 MDT.recalculate(MF);
146 TheImpl = &*InstrRefImpl;
147 }
148
149 return TheImpl->ExtendRanges(MF, DomTree, ShouldEmitDebugEntryValues,
151}
152
154 // Enable by default on x86_64, disable if explicitly turned off on cmdline.
155 if (T.getArch() == llvm::Triple::x86_64 &&
157 return true;
158
159 // Enable if explicitly requested on command line.
161}
#define DEBUG_TYPE
static cl::opt< unsigned > InputBBLimit("livedebugvalues-input-bb-limit", cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"), cl::init(10000), cl::Hidden)
static cl::opt< bool > ForceInstrRefLDV("force-instr-ref-livedebugvalues", cl::Hidden, cl::desc("Use instruction-ref based LiveDebugValues with " "normal DBG_VALUE inputs"), cl::init(false))
static cl::opt< unsigned > InputDbgValueLimit("livedebugvalues-input-dbg-value-limit", cl::desc("Maximum input DBG_VALUE insts supported by debug range extension"), cl::init(50000), cl::Hidden)
static cl::opt< cl::boolOrDefault > ValueTrackingVariableLocations("experimental-debug-variable-locations", cl::desc("Use experimental new value-tracking variable locations"))
#define T
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static const char * name
Target-Independent Code Generator Pass Configuration Options pass.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:275
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
virtual bool ExtendRanges(MachineFunction &MF, MachineDominatorTree *DomTree, bool ShouldEmitDebugEntryValues, unsigned InputBBLimit, unsigned InputDbgValLimit)=0
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
TargetOptions Options
LLVM_ABI bool ShouldEmitDebugEntryValues() const
NOTE: There are targets that still do not support the debug entry values production.
Target-Independent Code Generator Pass Configuration Options.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
initializer< Ty > init(const Ty &Val)
DXILDebugInfoMap run(Module &M)
This is an optimization pass for GlobalISel generic memory operations.
LDVImpl * makeInstrRefBasedLiveDebugValues()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI char & LiveDebugValuesID
LiveDebugValues pass.
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LDVImpl * makeVarLocBasedLiveDebugValues()
bool debuginfoShouldUseDebugInstrRef(const Triple &T)