Skip to content

Commit 20bb9fe

Browse files
committed
[LiveDebugValues] Install an implementation-picking LiveDebugValues pass
This patch renames the current LiveDebugValues class to "VarLocBasedLDV" and removes the pass-registration code from it. It creates a separate LiveDebugValues class that deals with pass registration and management, that calls through to VarLocBasedLDV::ExtendRanges when runOnMachineFunction is called. This is done through the "LDVImpl" abstract class, so that a future patch can install the new instruction-referencing LiveDebugValues implementation and have it picked at runtime. No functional change is intended, just shuffling responsibilities. Differential Revision: https://reviews.llvm.org/D83046
1 parent e7d9182 commit 20bb9fe

File tree

4 files changed

+180
-87
lines changed

4 files changed

+180
-87
lines changed

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ add_llvm_component_library(LLVMCodeGen
182182
WinEHPrepare.cpp
183183
XRayInstrumentation.cpp
184184

185+
LiveDebugValues/LiveDebugValues.cpp
185186
LiveDebugValues/VarLocBasedImpl.cpp
186187

187188
ADDITIONAL_HEADER_DIRS
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===- LiveDebugValues.cpp - Tracking Debug Value MIs ---------*- C++ -*---===//
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 "llvm/CodeGen/MachineFunction.h"
10+
#include "llvm/CodeGen/TargetPassConfig.h"
11+
12+
namespace llvm {
13+
14+
// Inline namespace for types / symbols shared between different
15+
// LiveDebugValues implementations.
16+
inline namespace SharedLiveDebugValues {
17+
18+
// Expose a base class for LiveDebugValues interfaces to inherit from. This
19+
// allows the generic LiveDebugValues pass handles to call into the
20+
// implementation.
21+
class LDVImpl {
22+
public:
23+
virtual bool ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) = 0;
24+
virtual ~LDVImpl() {}
25+
};
26+
27+
} // namespace SharedLiveDebugValues
28+
29+
// Factory functions for LiveDebugValues implementations.
30+
extern LDVImpl *makeVarLocBasedLiveDebugValues();
31+
} // namespace llvm

0 commit comments

Comments
 (0)