Skip to content

Commit 174110b

Browse files
authored
[CodeGen][NPM] Port LiveDebugValues to NPM (#131563)
1 parent 3c2731c commit 174110b

File tree

9 files changed

+100
-20
lines changed

9 files changed

+100
-20
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===- llvm/CodeGen/LiveDebugValuesPass.h -----------------------*- 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+
#ifndef LLVM_CODEGEN_LIVEDEBUGVALUESPASS_H
10+
#define LLVM_CODEGEN_LIVEDEBUGVALUESPASS_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class LiveDebugValuesPass : public PassInfoMixin<LiveDebugValuesPass> {
17+
const bool ShouldEmitDebugEntryValues;
18+
19+
public:
20+
LiveDebugValuesPass(bool ShouldEmitDebugEntryValues)
21+
: ShouldEmitDebugEntryValues(ShouldEmitDebugEntryValues) {}
22+
23+
PreservedAnalyses run(MachineFunction &MF,
24+
MachineFunctionAnalysisManager &MFAM);
25+
26+
void printPipeline(raw_ostream &OS,
27+
function_ref<StringRef(StringRef)> MapClassName2PassName);
28+
};
29+
30+
} // namespace llvm
31+
32+
#endif // LLVM_CODEGEN_LIVEDEBUGVALUESPASS_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void initializeLegacyLICMPassPass(PassRegistry &);
153153
void initializeLegalizerPass(PassRegistry &);
154154
void initializeGISelCSEAnalysisWrapperPassPass(PassRegistry &);
155155
void initializeGISelKnownBitsAnalysisPass(PassRegistry &);
156-
void initializeLiveDebugValuesPass(PassRegistry &);
156+
void initializeLiveDebugValuesLegacyPass(PassRegistry &);
157157
void initializeLiveDebugVariablesWrapperLegacyPass(PassRegistry &);
158158
void initializeLiveIntervalsWrapperPassPass(PassRegistry &);
159159
void initializeLiveRangeShrinkPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/CodeGen/InterleavedAccess.h"
4646
#include "llvm/CodeGen/InterleavedLoadCombine.h"
4747
#include "llvm/CodeGen/JMCInstrumenter.h"
48+
#include "llvm/CodeGen/LiveDebugValuesPass.h"
4849
#include "llvm/CodeGen/LiveIntervals.h"
4950
#include "llvm/CodeGen/LocalStackSlotAllocation.h"
5051
#include "llvm/CodeGen/LowerEmuTLS.h"
@@ -1002,7 +1003,8 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::addMachinePasses(
10021003
addPass(FuncletLayoutPass());
10031004

10041005
addPass(StackMapLivenessPass());
1005-
addPass(LiveDebugValuesPass());
1006+
addPass(LiveDebugValuesPass(
1007+
getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues()));
10061008
addPass(MachineSanitizerBinaryMetadata());
10071009

10081010
if (TM.Options.EnableMachineOutliner &&

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
214214
},
215215
"enable-tail-merge")
216216

217+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
218+
"live-debug-values", "LiveDebugValuesPass",
219+
[](bool ShouldEmitDebugEntryValues) {
220+
return LiveDebugValuesPass(ShouldEmitDebugEntryValues);
221+
},
222+
[](StringRef Params) {
223+
return parseSinglePassOption(Params, "emit-debug-entry-values",
224+
"LiveDebugValuesPass");
225+
},
226+
"emit-debug-entry-values")
227+
217228
MACHINE_FUNCTION_PASS_WITH_PARAMS(
218229
"machine-sink", "MachineSinkingPass",
219230
[](bool EnableSinkAndFold) {
@@ -278,7 +289,6 @@ DUMMY_MACHINE_FUNCTION_PASS("instruction-select", InstructionSelectPass)
278289
DUMMY_MACHINE_FUNCTION_PASS("irtranslator", IRTranslatorPass)
279290
DUMMY_MACHINE_FUNCTION_PASS("kcfi", MachineKCFIPass)
280291
DUMMY_MACHINE_FUNCTION_PASS("legalizer", LegalizerPass)
281-
DUMMY_MACHINE_FUNCTION_PASS("livedebugvalues", LiveDebugValuesPass)
282292
DUMMY_MACHINE_FUNCTION_PASS("lrshrink", LiveRangeShrinkPass)
283293
DUMMY_MACHINE_FUNCTION_PASS("machine-combiner", MachineCombinerPass)
284294
DUMMY_MACHINE_FUNCTION_PASS("static-data-splitter", StaticDataSplitter)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
5858
initializeInterleavedLoadCombinePass(Registry);
5959
initializeInterleavedAccessPass(Registry);
6060
initializeJMCInstrumenterPass(Registry);
61-
initializeLiveDebugValuesPass(Registry);
61+
initializeLiveDebugValuesLegacyPass(Registry);
6262
initializeLiveDebugVariablesWrapperLegacyPass(Registry);
6363
initializeLiveIntervalsWrapperPassPass(Registry);
6464
initializeLiveRangeShrinkPass(Registry);

llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "LiveDebugValues.h"
1010

11+
#include "llvm/CodeGen/LiveDebugValuesPass.h"
1112
#include "llvm/CodeGen/MachineDominators.h"
1213
#include "llvm/CodeGen/MachineFunction.h"
1314
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -63,50 +64,82 @@ namespace {
6364
/// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or
6465
/// InstrRefBasedLDV to perform location propagation, via the LDVImpl
6566
/// base class.
66-
class LiveDebugValues : public MachineFunctionPass {
67+
class LiveDebugValuesLegacy : public MachineFunctionPass {
6768
public:
6869
static char ID;
6970

70-
LiveDebugValues();
71-
~LiveDebugValues() = default;
71+
LiveDebugValuesLegacy();
72+
~LiveDebugValuesLegacy() = default;
7273

7374
/// Calculate the liveness information for the given machine function.
7475
bool runOnMachineFunction(MachineFunction &MF) override;
7576

7677
void getAnalysisUsage(AnalysisUsage &AU) const override {
7778
AU.setPreservesCFG();
79+
AU.addRequired<TargetPassConfig>();
7880
MachineFunctionPass::getAnalysisUsage(AU);
7981
}
82+
};
83+
84+
struct LiveDebugValues {
85+
LiveDebugValues();
86+
~LiveDebugValues() = default;
87+
bool run(MachineFunction &MF, bool ShouldEmitDebugEntryValues);
8088

8189
private:
8290
std::unique_ptr<LDVImpl> InstrRefImpl;
8391
std::unique_ptr<LDVImpl> VarLocImpl;
84-
TargetPassConfig *TPC = nullptr;
8592
MachineDominatorTree MDT;
8693
};
8794
} // namespace
8895

89-
char LiveDebugValues::ID = 0;
96+
char LiveDebugValuesLegacy::ID = 0;
9097

91-
char &llvm::LiveDebugValuesID = LiveDebugValues::ID;
98+
char &llvm::LiveDebugValuesID = LiveDebugValuesLegacy::ID;
9299

93-
INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false,
94-
false)
100+
INITIALIZE_PASS(LiveDebugValuesLegacy, DEBUG_TYPE, "Live DEBUG_VALUE analysis",
101+
false, false)
95102

96103
/// Default construct and initialize the pass.
97-
LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
98-
initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
104+
LiveDebugValuesLegacy::LiveDebugValuesLegacy() : MachineFunctionPass(ID) {
105+
initializeLiveDebugValuesLegacyPass(*PassRegistry::getPassRegistry());
106+
}
107+
108+
LiveDebugValues::LiveDebugValues() {
99109
InstrRefImpl =
100110
std::unique_ptr<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues());
101111
VarLocImpl = std::unique_ptr<LDVImpl>(llvm::makeVarLocBasedLiveDebugValues());
102112
}
103113

104-
bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
114+
PreservedAnalyses
115+
LiveDebugValuesPass::run(MachineFunction &MF,
116+
MachineFunctionAnalysisManager &MFAM) {
117+
if (!LiveDebugValues().run(MF, ShouldEmitDebugEntryValues))
118+
return PreservedAnalyses::all();
119+
auto PA = getMachineFunctionPassPreservedAnalyses();
120+
PA.preserveSet<CFGAnalyses>();
121+
return PA;
122+
}
123+
124+
void LiveDebugValuesPass::printPipeline(
125+
raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
126+
OS << MapClassName2PassName(name());
127+
if (ShouldEmitDebugEntryValues)
128+
OS << "<emit-debug-entry-values>";
129+
}
130+
131+
bool LiveDebugValuesLegacy::runOnMachineFunction(MachineFunction &MF) {
132+
auto *TPC = &getAnalysis<TargetPassConfig>();
133+
return LiveDebugValues().run(
134+
MF, TPC->getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues());
135+
}
136+
137+
bool LiveDebugValues::run(MachineFunction &MF,
138+
bool ShouldEmitDebugEntryValues) {
105139
bool InstrRefBased = MF.useDebugInstrRef();
106140
// Allow the user to force selection of InstrRef LDV.
107141
InstrRefBased |= ForceInstrRefLDV;
108142

109-
TPC = getAnalysisIfAvailable<TargetPassConfig>();
110143
LDVImpl *TheImpl = &*VarLocImpl;
111144

112145
MachineDominatorTree *DomTree = nullptr;
@@ -116,10 +149,8 @@ bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
116149
TheImpl = &*InstrRefImpl;
117150
}
118151

119-
return TheImpl->ExtendRanges(
120-
MF, DomTree,
121-
TPC->getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues(),
122-
InputBBLimit, InputDbgValueLimit);
152+
return TheImpl->ExtendRanges(MF, DomTree, ShouldEmitDebugEntryValues,
153+
InputBBLimit, InputDbgValueLimit);
123154
}
124155

125156
bool llvm::debuginfoShouldUseDebugInstrRef(const Triple &T) {

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
#include "llvm/CodeGen/InterleavedAccess.h"
106106
#include "llvm/CodeGen/InterleavedLoadCombine.h"
107107
#include "llvm/CodeGen/JMCInstrumenter.h"
108+
#include "llvm/CodeGen/LiveDebugValuesPass.h"
108109
#include "llvm/CodeGen/LiveDebugVariables.h"
109110
#include "llvm/CodeGen/LiveIntervals.h"
110111
#include "llvm/CodeGen/LiveRegMatrix.h"

llvm/test/CodeGen/ARM/dbg-range-extension.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -mtriple=arm-eabi -run-pass=livedebugvalues %s -o - | FileCheck %s
2+
# RUN: llc -mtriple=arm-eabi -passes=live-debug-values %s -o - | FileCheck %s
23
#
34
# Check that the debug information for variables are propagated into the correct blocks.
45
#

llvm/test/DebugInfo/AArch64/compiler-gen-bbs-livedebugvalues.mir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# RUN: llc -o - %s -O0 -regalloc=fast -run-pass=livedebugvalues | \
22
# RUN: FileCheck %s -implicit-check-not=DBG_VALUE
3+
4+
# RUN: llc -o - %s -O0 -regalloc=fast -passes=live-debug-values | \
5+
# RUN: FileCheck %s -implicit-check-not=DBG_VALUE
36
--- |
47
target triple = "arm64-apple-ios12.1.0"
58

0 commit comments

Comments
 (0)