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 18 /// \file LiveDebugValues.cpp 19 /// 20 /// The LiveDebugValues pass extends the range of variable locations 21 /// (specified by DBG_VALUE instructions) from single blocks to successors 22 /// and any other code locations where the variable location is valid. 23 /// There are currently two implementations: the "VarLoc" implementation 24 /// explicitly tracks the location of a variable, while the "InstrRef" 25 /// implementation tracks the values defined by instructions through locations. 26 /// 27 /// This file implements neither; it merely registers the pass, allows the 28 /// user to pick which implementation will be used to propagate variable 29 /// locations. 30 31 #define DEBUG_TYPE "livedebugvalues" 32 33 using namespace llvm; 34 35 /// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or 36 /// InstrRefBasedLDV to perform location propagation, via the LDVImpl 37 /// base class. 38 class LiveDebugValues : public MachineFunctionPass { 39 public: 40 static char ID; 41 42 LiveDebugValues(); 43 ~LiveDebugValues() { delete TheImpl; } 44 45 /// Calculate the liveness information for the given machine function. 46 bool runOnMachineFunction(MachineFunction &MF) override; 47 48 MachineFunctionProperties getRequiredProperties() const override { 49 return MachineFunctionProperties().set( 50 MachineFunctionProperties::Property::NoVRegs); 51 } 52 53 void getAnalysisUsage(AnalysisUsage &AU) const override { 54 AU.setPreservesCFG(); 55 MachineFunctionPass::getAnalysisUsage(AU); 56 } 57 58 private: 59 LDVImpl *TheImpl; 60 }; 61 62 char LiveDebugValues::ID = 0; 63 64 char &llvm::LiveDebugValuesID = LiveDebugValues::ID; 65 66 INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, 67 false) 68 69 /// Default construct and initialize the pass. 70 LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) { 71 initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry()); 72 TheImpl = llvm::makeVarLocBasedLiveDebugValues(); 73 } 74 75 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { 76 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>(); 77 return TheImpl->ExtendRanges(MF, TPC); 78 } 79