LiveDebugValues.cpp 4.7 KB

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