[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / lib / CodeGen / LiveDebugValues / LiveDebugValues.cpp
blob2913506853aa403931511a90bfb9c5f89d17d364
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 //===----------------------------------------------------------------------===//
9 #include "LiveDebugValues.h"
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"
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.
33 #define DEBUG_TYPE "livedebugvalues"
35 using namespace llvm;
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));
43 static cl::opt<cl::boolOrDefault> ValueTrackingVariableLocations(
44 "experimental-debug-variable-locations",
45 cl::desc("Use experimental new value-tracking variable locations"));
47 // Options to prevent pathological compile-time behavior. If InputBBLimit and
48 // InputDbgValueLimit are both exceeded, range extension is disabled.
49 static cl::opt<unsigned> InputBBLimit(
50 "livedebugvalues-input-bb-limit",
51 cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"),
52 cl::init(10000), cl::Hidden);
53 static cl::opt<unsigned> InputDbgValueLimit(
54 "livedebugvalues-input-dbg-value-limit",
55 cl::desc(
56 "Maximum input DBG_VALUE insts supported by debug range extension"),
57 cl::init(50000), cl::Hidden);
59 namespace {
60 /// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or
61 /// InstrRefBasedLDV to perform location propagation, via the LDVImpl
62 /// base class.
63 class LiveDebugValues : public MachineFunctionPass {
64 public:
65 static char ID;
67 LiveDebugValues();
68 ~LiveDebugValues() {}
70 /// Calculate the liveness information for the given machine function.
71 bool runOnMachineFunction(MachineFunction &MF) override;
73 MachineFunctionProperties getRequiredProperties() const override {
74 return MachineFunctionProperties().set(
75 MachineFunctionProperties::Property::NoVRegs);
78 void getAnalysisUsage(AnalysisUsage &AU) const override {
79 AU.setPreservesCFG();
80 MachineFunctionPass::getAnalysisUsage(AU);
83 private:
84 std::unique_ptr<LDVImpl> InstrRefImpl;
85 std::unique_ptr<LDVImpl> VarLocImpl;
86 TargetPassConfig *TPC;
87 MachineDominatorTree MDT;
89 } // namespace
91 char LiveDebugValues::ID = 0;
93 char &llvm::LiveDebugValuesID = LiveDebugValues::ID;
95 INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false,
96 false)
98 /// Default construct and initialize the pass.
99 LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
100 initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
101 InstrRefImpl =
102 std::unique_ptr<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues());
103 VarLocImpl = std::unique_ptr<LDVImpl>(llvm::makeVarLocBasedLiveDebugValues());
106 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
107 bool InstrRefBased = MF.useDebugInstrRef();
108 // Allow the user to force selection of InstrRef LDV.
109 InstrRefBased |= ForceInstrRefLDV;
111 TPC = getAnalysisIfAvailable<TargetPassConfig>();
112 LDVImpl *TheImpl = &*VarLocImpl;
114 MachineDominatorTree *DomTree = nullptr;
115 if (InstrRefBased) {
116 DomTree = &MDT;
117 MDT.calculate(MF);
118 TheImpl = &*InstrRefImpl;
121 return TheImpl->ExtendRanges(MF, DomTree, TPC, InputBBLimit,
122 InputDbgValueLimit);
125 bool llvm::debuginfoShouldUseDebugInstrRef(const Triple &T) {
126 // Enable by default on x86_64, disable if explicitly turned off on cmdline.
127 if (T.getArch() == llvm::Triple::x86_64 &&
128 ValueTrackingVariableLocations != cl::boolOrDefault::BOU_FALSE)
129 return true;
131 // Otherwise: enable if explicitly requestedo n command line.
132 return ValueTrackingVariableLocations == cl::boolOrDefault::BOU_TRUE;