LLVM  15.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"
21 
22 /// \file LiveDebugValues.cpp
23 ///
24 /// The LiveDebugValues pass extends the range of variable locations
25 /// (specified by DBG_VALUE instructions) from single blocks to successors
26 /// and any other code locations where the variable location is valid.
27 /// There are currently two implementations: the "VarLoc" implementation
28 /// explicitly tracks the location of a variable, while the "InstrRef"
29 /// implementation tracks the values defined by instructions through locations.
30 ///
31 /// This file implements neither; it merely registers the pass, allows the
32 /// user to pick which implementation will be used to propagate variable
33 /// locations.
34 
35 #define DEBUG_TYPE "livedebugvalues"
36 
37 using namespace llvm;
38 
39 static cl::opt<bool>
40  ForceInstrRefLDV("force-instr-ref-livedebugvalues", cl::Hidden,
41  cl::desc("Use instruction-ref based LiveDebugValues with "
42  "normal DBG_VALUE inputs"),
43  cl::init(false));
44 
46  "experimental-debug-variable-locations",
47  cl::desc("Use experimental new value-tracking variable locations"));
48 
49 // Options to prevent pathological compile-time behavior. If InputBBLimit and
50 // InputDbgValueLimit are both exceeded, range extension is disabled.
52  "livedebugvalues-input-bb-limit",
53  cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"),
54  cl::init(10000), cl::Hidden);
56  "livedebugvalues-input-dbg-value-limit",
57  cl::desc(
58  "Maximum input DBG_VALUE insts supported by debug range extension"),
59  cl::init(50000), cl::Hidden);
60 
61 namespace {
62 /// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or
63 /// InstrRefBasedLDV to perform location propagation, via the LDVImpl
64 /// base class.
65 class LiveDebugValues : public MachineFunctionPass {
66 public:
67  static char ID;
68 
70  ~LiveDebugValues() = default;
71 
72  /// Calculate the liveness information for the given machine function.
73  bool runOnMachineFunction(MachineFunction &MF) override;
74 
75  MachineFunctionProperties getRequiredProperties() const override {
78  }
79 
80  void getAnalysisUsage(AnalysisUsage &AU) const override {
81  AU.setPreservesCFG();
83  }
84 
85 private:
86  std::unique_ptr<LDVImpl> InstrRefImpl;
87  std::unique_ptr<LDVImpl> VarLocImpl;
88  TargetPassConfig *TPC;
90 };
91 } // namespace
92 
93 char LiveDebugValues::ID = 0;
94 
96 
97 INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false,
98  false)
99 
100 /// Default construct and initialize the pass.
103  InstrRefImpl =
104  std::unique_ptr<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues());
105  VarLocImpl = std::unique_ptr<LDVImpl>(llvm::makeVarLocBasedLiveDebugValues());
106 }
107 
108 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
109  bool InstrRefBased = MF.useDebugInstrRef();
110  // Allow the user to force selection of InstrRef LDV.
111  InstrRefBased |= ForceInstrRefLDV;
112 
113  TPC = getAnalysisIfAvailable<TargetPassConfig>();
114  LDVImpl *TheImpl = &*VarLocImpl;
115 
116  MachineDominatorTree *DomTree = nullptr;
117  if (InstrRefBased) {
118  DomTree = &MDT;
119  MDT.calculate(MF);
120  TheImpl = &*InstrRefImpl;
121  }
122 
123  return TheImpl->ExtendRanges(MF, DomTree, TPC, InputBBLimit,
125 }
126 
128  // Enable by default on x86_64, disable if explicitly turned off on cmdline.
129  if (T.getArch() == llvm::Triple::x86_64 &&
131  return true;
132 
133  // Enable if explicitly requested on command line.
135 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::SharedLiveDebugValues::LDVImpl
Definition: LiveDebugValues.h:25
T
llvm::initializeLiveDebugValuesPass
void initializeLiveDebugValuesPass(PassRegistry &)
llvm::cl::BOU_FALSE
@ BOU_FALSE
Definition: CommandLine.h:611
Pass.h
llvm::MachineFunction::useDebugInstrRef
bool useDebugInstrRef() const
Returns true if the function's variable locations should be tracked with instruction referencing.
Definition: MachineFunction.cpp:1262
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:139
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
llvm::MachineFunctionProperties
Properties which a MachineFunction may have at a given point in time.
Definition: MachineFunction.h:111
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:103
LiveDebugValues
Definition: InstrRefBasedImpl.h:30
DEBUG_TYPE
#define DEBUG_TYPE
Definition: LiveDebugValues.cpp:35
CommandLine.h
llvm::LiveDebugValuesID
char & LiveDebugValuesID
LiveDebugValues pass.
Definition: LiveDebugValues.cpp:95
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineFunctionProperties::set
MachineFunctionProperties & set(Property P)
Definition: MachineFunction.h:180
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:127
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
TargetPassConfig.h
MachineFunctionPass.h
llvm::makeInstrRefBasedLiveDebugValues
LDVImpl * makeInstrRefBasedLiveDebugValues()
Definition: InstrRefBasedImpl.cpp:3315
llvm::MachineFunction
Definition: MachineFunction.h:241
Triple.h
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:263
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:611
INITIALIZE_PASS
INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, false) LiveDebugValues
Default construct and initialize the pass.
Definition: LiveDebugValues.cpp:97
llvm::MachineDominatorTree::calculate
void calculate(MachineFunction &F)
Definition: MachineDominators.cpp:59
llvm::cl::desc
Definition: CommandLine.h:405
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:2295
InitializePasses.h
MachineDominators.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37