LLVM  17.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 
11 #include "llvm/ADT/Triple.h"
15 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/InitializePasses.h"
18 #include "llvm/Pass.h"
19 #include "llvm/PassRegistry.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 
38 using namespace llvm;
39 
40 static 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",
58  cl::desc(
59  "Maximum input DBG_VALUE insts supported by debug range extension"),
60  cl::init(50000), cl::Hidden);
61 
62 namespace {
63 /// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or
64 /// InstrRefBasedLDV to perform location propagation, via the LDVImpl
65 /// base class.
66 class LiveDebugValues : public MachineFunctionPass {
67 public:
68  static char ID;
69 
71  ~LiveDebugValues() = 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();
79  }
80 
81 private:
82  std::unique_ptr<LDVImpl> InstrRefImpl;
83  std::unique_ptr<LDVImpl> VarLocImpl;
84  TargetPassConfig *TPC;
86 };
87 } // namespace
88 
89 char LiveDebugValues::ID = 0;
90 
92 
93 INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false,
94  false)
95 
96 /// Default construct and initialize the pass.
99  InstrRefImpl =
100  std::unique_ptr<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues());
101  VarLocImpl = std::unique_ptr<LDVImpl>(llvm::makeVarLocBasedLiveDebugValues());
102 }
103 
104 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
105  // Except for Wasm, all targets should be only using physical register at this
106  // point. Wasm only use virtual registers throught its pipeline, but its
107  // virtual registers don't participate in this LiveDebugValues analysis; only
108  // its target indices do.
112 
113  bool InstrRefBased = MF.useDebugInstrRef();
114  // Allow the user to force selection of InstrRef LDV.
115  InstrRefBased |= ForceInstrRefLDV;
116 
117  TPC = getAnalysisIfAvailable<TargetPassConfig>();
118  LDVImpl *TheImpl = &*VarLocImpl;
119 
120  MachineDominatorTree *DomTree = nullptr;
121  if (InstrRefBased) {
122  DomTree = &MDT;
123  MDT.calculate(MF);
124  TheImpl = &*InstrRefImpl;
125  }
126 
127  return TheImpl->ExtendRanges(MF, DomTree, TPC, InputBBLimit,
129 }
130 
132  // Enable by default on x86_64, disable if explicitly turned off on cmdline.
133  if (T.getArch() == llvm::Triple::x86_64 &&
135  return true;
136 
137  // Enable if explicitly requested on command line.
139 }
llvm::MachineFunctionProperties::hasProperty
bool hasProperty(Property P) const
Definition: MachineFunction.h:193
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::SharedLiveDebugValues::LDVImpl
Definition: LiveDebugValues.h:25
T
llvm::initializeLiveDebugValuesPass
void initializeLiveDebugValuesPass(PassRegistry &)
llvm::cl::BOU_FALSE
@ BOU_FALSE
Definition: CommandLine.h:629
Pass.h
llvm::MachineFunction::useDebugInstrRef
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
Definition: MachineFunction.cpp:1216
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:138
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
llvm::SharedLiveDebugValues::LDVImpl::ExtendRanges
virtual bool ExtendRanges(MachineFunction &MF, MachineDominatorTree *DomTree, TargetPassConfig *TPC, unsigned InputBBLimit, unsigned InputDbgValLimit)=0
PassRegistry.h
ValueTrackingVariableLocations
static cl::opt< cl::boolOrDefault > ValueTrackingVariableLocations("experimental-debug-variable-locations", cl::desc("Use experimental new value-tracking variable locations"))
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:167
LiveDebugValues
Definition: InstrRefBasedImpl.h:31
DEBUG_TYPE
#define DEBUG_TYPE
Definition: LiveDebugValues.cpp:36
CommandLine.h
llvm::LiveDebugValuesID
char & LiveDebugValuesID
LiveDebugValues pass.
Definition: LiveDebugValues.cpp:91
TargetMachine.h
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:24
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineFunction::getProperties
const MachineFunctionProperties & getProperties() const
Get the function properties.
Definition: MachineFunction.h:763
InputDbgValueLimit
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)
ForceInstrRefLDV
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))
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineFunctionProperties::Property::NoVRegs
@ NoVRegs
Passes.h
llvm::TargetPassConfig
Target-Independent Code Generator Pass Configuration Options.
Definition: TargetPassConfig.h:84
llvm::cl::opt< bool >
llvm::debuginfoShouldUseDebugInstrRef
bool debuginfoShouldUseDebugInstrRef(const Triple &T)
Definition: LiveDebugValues.cpp:131
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
TargetPassConfig.h
MachineFunctionPass.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::makeInstrRefBasedLiveDebugValues
LDVImpl * makeInstrRefBasedLiveDebugValues()
Definition: InstrRefBasedImpl.cpp:3818
llvm::MachineFunction
Definition: MachineFunction.h:258
Triple.h
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:265
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:668
InputBBLimit
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)
LiveDebugValues.h
llvm::cl::BOU_TRUE
@ BOU_TRUE
Definition: CommandLine.h:629
INITIALIZE_PASS
INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, false) LiveDebugValues
Default construct and initialize the pass.
Definition: LiveDebugValues.cpp:93
llvm::MachineDominatorTree::calculate
void calculate(MachineFunction &F)
Definition: MachineDominators.cpp:59
llvm::TargetMachine::getTargetTriple
const Triple & getTargetTriple() const
Definition: TargetMachine.h:127
llvm::cl::desc
Definition: CommandLine.h:411
llvm::MachineDominatorTree
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Definition: MachineDominators.h:51
MachineFunction.h
llvm::makeVarLocBasedLiveDebugValues
LDVImpl * makeVarLocBasedLiveDebugValues()
Definition: VarLocBasedImpl.cpp:2400
llvm::Triple::isWasm
bool isWasm() const
Tests whether the target is wasm (32- and 64-bit).
Definition: Triple.h:921
InitializePasses.h
MachineDominators.h