LLVM 22.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"
19#include "llvm/PassRegistry.h"
23
24/// \file LiveDebugValues.cpp
25///
26/// The LiveDebugValues pass extends the range of variable locations
27/// (specified by DBG_VALUE instructions) from single blocks to successors
28/// and any other code locations where the variable location is valid.
29/// There are currently two implementations: the "VarLoc" implementation
30/// explicitly tracks the location of a variable, while the "InstrRef"
31/// implementation tracks the values defined by instructions through locations.
32///
33/// This file implements neither; it merely registers the pass, allows the
34/// user to pick which implementation will be used to propagate variable
35/// locations.
36
37#define DEBUG_TYPE "livedebugvalues"
38
39using namespace llvm;
40
41static cl::opt<bool>
42 ForceInstrRefLDV("force-instr-ref-livedebugvalues", cl::Hidden,
43 cl::desc("Use instruction-ref based LiveDebugValues with "
44 "normal DBG_VALUE inputs"),
45 cl::init(false));
46
48 "experimental-debug-variable-locations",
49 cl::desc("Use experimental new value-tracking variable locations"));
50
51// Options to prevent pathological compile-time behavior. If InputBBLimit and
52// InputDbgValueLimit are both exceeded, range extension is disabled.
54 "livedebugvalues-input-bb-limit",
55 cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"),
56 cl::init(10000), cl::Hidden);
58 "livedebugvalues-input-dbg-value-limit",
60 "Maximum input DBG_VALUE insts supported by debug range extension"),
61 cl::init(50000), cl::Hidden);
62
63namespace {
64/// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or
65/// InstrRefBasedLDV to perform location propagation, via the LDVImpl
66/// base class.
67class LiveDebugValuesLegacy : public MachineFunctionPass {
68public:
69 static char ID;
70
71 LiveDebugValuesLegacy();
72 ~LiveDebugValuesLegacy() = default;
73
74 /// Calculate the liveness information for the given machine function.
75 bool runOnMachineFunction(MachineFunction &MF) override;
76
77 void getAnalysisUsage(AnalysisUsage &AU) const override {
78 AU.setPreservesCFG();
81 }
82};
83
84struct LiveDebugValues {
86 ~LiveDebugValues() = default;
87 bool run(MachineFunction &MF, bool ShouldEmitDebugEntryValues);
88
89private:
90 std::unique_ptr<LDVImpl> InstrRefImpl;
91 std::unique_ptr<LDVImpl> VarLocImpl;
93};
94} // namespace
95
96char LiveDebugValuesLegacy::ID = 0;
97
98char &llvm::LiveDebugValuesID = LiveDebugValuesLegacy::ID;
99
100INITIALIZE_PASS(LiveDebugValuesLegacy, DEBUG_TYPE, "Live DEBUG_VALUE analysis",
101 false, false)
102
103/// Default construct and initialize the pass.
104LiveDebugValuesLegacy::LiveDebugValuesLegacy() : MachineFunctionPass(ID) {
106}
107
108LiveDebugValues::LiveDebugValues() {
109 InstrRefImpl =
110 std::unique_ptr<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues());
111 VarLocImpl = std::unique_ptr<LDVImpl>(llvm::makeVarLocBasedLiveDebugValues());
112}
113
117 if (!LiveDebugValues().run(MF, ShouldEmitDebugEntryValues))
118 return PreservedAnalyses::all();
120 PA.preserveSet<CFGAnalyses>();
121 return PA;
122}
123
125 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
126 OS << MapClassName2PassName(name());
127 if (ShouldEmitDebugEntryValues)
128 OS << "<emit-debug-entry-values>";
129}
130
131bool LiveDebugValuesLegacy::runOnMachineFunction(MachineFunction &MF) {
132 auto *TPC = &getAnalysis<TargetPassConfig>();
133 return LiveDebugValues().run(
135}
136
137bool LiveDebugValues::run(MachineFunction &MF,
138 bool ShouldEmitDebugEntryValues) {
139 bool InstrRefBased = MF.useDebugInstrRef();
140 // Allow the user to force selection of InstrRef LDV.
141 InstrRefBased |= ForceInstrRefLDV;
142
143 LDVImpl *TheImpl = &*VarLocImpl;
144
145 MachineDominatorTree *DomTree = nullptr;
146 if (InstrRefBased) {
147 DomTree = &MDT;
148 MDT.recalculate(MF);
149 TheImpl = &*InstrRefImpl;
150 }
151
152 return TheImpl->ExtendRanges(MF, DomTree, ShouldEmitDebugEntryValues,
154}
155
157 // Enable by default on x86_64, disable if explicitly turned off on cmdline.
158 if (T.getArch() == llvm::Triple::x86_64 &&
160 return true;
161
162 // Enable if explicitly requested on command line.
164}
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 DEBUG_TYPE
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:56
raw_pwrite_stream & OS
Target-Independent Code Generator Pass Configuration Options pass.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
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:270
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
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
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
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:83
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:47
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
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LDVImpl * makeInstrRefBasedLiveDebugValues()
LLVM_ABI char & LiveDebugValuesID
LiveDebugValues pass.
LLVM_ABI void initializeLiveDebugValuesLegacyPass(PassRegistry &)
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LDVImpl * makeVarLocBasedLiveDebugValues()
bool debuginfoShouldUseDebugInstrRef(const Triple &T)
static StringRef name()
Gets the name of the pass we are mixed into.
Definition: PassManager.h:72