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/CodeGen/MachineBasicBlock.h" 12 #include "llvm/CodeGen/MachineFrameInfo.h" 13 #include "llvm/CodeGen/MachineFunctionPass.h" 14 #include "llvm/CodeGen/Passes.h" 15 #include "llvm/InitializePasses.h" 16 #include "llvm/Pass.h" 17 #include "llvm/Support/CommandLine.h" 18 #include "llvm/Target/TargetMachine.h" 19 20 /// \file LiveDebugValues.cpp 21 /// 22 /// The LiveDebugValues pass extends the range of variable locations 23 /// (specified by DBG_VALUE instructions) from single blocks to successors 24 /// and any other code locations where the variable location is valid. 25 /// There are currently two implementations: the "VarLoc" implementation 26 /// explicitly tracks the location of a variable, while the "InstrRef" 27 /// implementation tracks the values defined by instructions through locations. 28 /// 29 /// This file implements neither; it merely registers the pass, allows the 30 /// user to pick which implementation will be used to propagate variable 31 /// locations. 32 33 #define DEBUG_TYPE "livedebugvalues" 34 35 using namespace llvm; 36 37 static cl::opt<bool> 38 ForceInstrRefLDV("force-instr-ref-livedebugvalues", cl::Hidden, 39 cl::desc("Use instruction-ref based LiveDebugValues with " 40 "normal DBG_VALUE inputs"), 41 cl::init(false)); 42 43 // Options to prevent pathological compile-time behavior. If InputBBLimit and 44 // InputDbgValueLimit are both exceeded, range extension is disabled. 45 static cl::opt<unsigned> InputBBLimit( 46 "livedebugvalues-input-bb-limit", 47 cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"), 48 cl::init(10000), cl::Hidden); 49 static cl::opt<unsigned> InputDbgValueLimit( 50 "livedebugvalues-input-dbg-value-limit", 51 cl::desc( 52 "Maximum input DBG_VALUE insts supported by debug range extension"), 53 cl::init(50000), cl::Hidden); 54 55 /// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or 56 /// InstrRefBasedLDV to perform location propagation, via the LDVImpl 57 /// base class. 58 class LiveDebugValues : public MachineFunctionPass { 59 public: 60 static char ID; 61 62 LiveDebugValues(); 63 ~LiveDebugValues() { 64 if (TheImpl) 65 delete TheImpl; 66 } 67 68 /// Calculate the liveness information for the given machine function. 69 bool runOnMachineFunction(MachineFunction &MF) override; 70 71 MachineFunctionProperties getRequiredProperties() const override { 72 return MachineFunctionProperties().set( 73 MachineFunctionProperties::Property::NoVRegs); 74 } 75 76 void getAnalysisUsage(AnalysisUsage &AU) const override { 77 AU.setPreservesCFG(); 78 MachineFunctionPass::getAnalysisUsage(AU); 79 } 80 81 private: 82 LDVImpl *TheImpl; 83 TargetPassConfig *TPC; 84 MachineDominatorTree MDT; 85 }; 86 87 char LiveDebugValues::ID = 0; 88 89 char &llvm::LiveDebugValuesID = LiveDebugValues::ID; 90 91 INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, 92 false) 93 94 /// Default construct and initialize the pass. 95 LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) { 96 initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry()); 97 TheImpl = nullptr; 98 } 99 100 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { 101 bool InstrRefBased = MF.useDebugInstrRef(); 102 // Allow the user to force selection of InstrRef LDV. 103 InstrRefBased |= ForceInstrRefLDV; 104 105 if (!TheImpl) { 106 TPC = getAnalysisIfAvailable<TargetPassConfig>(); 107 108 if (InstrRefBased) 109 TheImpl = llvm::makeInstrRefBasedLiveDebugValues(); 110 else 111 TheImpl = llvm::makeVarLocBasedLiveDebugValues(); 112 } 113 114 MachineDominatorTree *DomTree = nullptr; 115 if (InstrRefBased) { 116 DomTree = &MDT; 117 MDT.calculate(MF); 118 } 119 120 return TheImpl->ExtendRanges(MF, DomTree, TPC, InputBBLimit, 121 InputDbgValueLimit); 122 } 123