https://github.com/optimisan updated https://github.com/llvm/llvm-project/pull/131563
>From be6e70fa3feb46b4a92f0f9719976c6efec8a28c Mon Sep 17 00:00:00 2001 From: Akshat Oke <akshat....@amd.com> Date: Wed, 12 Mar 2025 09:31:58 +0000 Subject: [PATCH] [CodeGen][NPM] Port LiveDebugValues to NPM --- .../llvm/CodeGen/LiveDebugValuesPass.h | 30 +++++++++ llvm/include/llvm/InitializePasses.h | 2 +- llvm/include/llvm/Passes/CodeGenPassBuilder.h | 4 +- .../llvm/Passes/MachinePassRegistry.def | 12 +++- llvm/lib/CodeGen/CodeGen.cpp | 2 +- .../LiveDebugValues/LiveDebugValues.cpp | 63 ++++++++++++++----- llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/test/CodeGen/ARM/dbg-range-extension.mir | 1 + .../compiler-gen-bbs-livedebugvalues.mir | 3 + 9 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 llvm/include/llvm/CodeGen/LiveDebugValuesPass.h diff --git a/llvm/include/llvm/CodeGen/LiveDebugValuesPass.h b/llvm/include/llvm/CodeGen/LiveDebugValuesPass.h new file mode 100644 index 0000000000000..023a699360688 --- /dev/null +++ b/llvm/include/llvm/CodeGen/LiveDebugValuesPass.h @@ -0,0 +1,30 @@ +//===- llvm/CodeGen/LiveDebugValuesPass.h --------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CODEGEN_LIVEDEBUGVALUESPASS_H +#define LLVM_CODEGEN_LIVEDEBUGVALUESPASS_H + +#include "llvm/CodeGen/MachinePassManager.h" + +namespace llvm { + +class LiveDebugValuesPass : public PassInfoMixin<LiveDebugValuesPass> { + bool ShouldEmitDebugEntryValues; + +public: + LiveDebugValuesPass(bool ShouldEmitDebugEntryValues) + : ShouldEmitDebugEntryValues(ShouldEmitDebugEntryValues) {} + PreservedAnalyses run(MachineFunction &MF, + MachineFunctionAnalysisManager &MFAM); + void printPipeline(raw_ostream &OS, + function_ref<StringRef(StringRef)> MapClassName2PassName); +}; + +} // namespace llvm + +#endif // LLVM_CODEGEN_LIVEDEBUGVALUESPASS_H diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 460c7eb3ebe24..e820277724393 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -153,7 +153,7 @@ void initializeLegacyLICMPassPass(PassRegistry &); void initializeLegalizerPass(PassRegistry &); void initializeGISelCSEAnalysisWrapperPassPass(PassRegistry &); void initializeGISelKnownBitsAnalysisPass(PassRegistry &); -void initializeLiveDebugValuesPass(PassRegistry &); +void initializeLiveDebugValuesLegacyPass(PassRegistry &); void initializeLiveDebugVariablesWrapperLegacyPass(PassRegistry &); void initializeLiveIntervalsWrapperPassPass(PassRegistry &); void initializeLiveRangeShrinkPass(PassRegistry &); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 571b363fadfc2..bdb81cf77cfd1 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -45,6 +45,7 @@ #include "llvm/CodeGen/InterleavedAccess.h" #include "llvm/CodeGen/InterleavedLoadCombine.h" #include "llvm/CodeGen/JMCInstrumenter.h" +#include "llvm/CodeGen/LiveDebugValuesPass.h" #include "llvm/CodeGen/LiveIntervals.h" #include "llvm/CodeGen/LocalStackSlotAllocation.h" #include "llvm/CodeGen/LowerEmuTLS.h" @@ -1002,7 +1003,8 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::addMachinePasses( addPass(FuncletLayoutPass()); addPass(StackMapLivenessPass()); - addPass(LiveDebugValuesPass()); + addPass(LiveDebugValuesPass( + getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues())); addPass(MachineSanitizerBinaryMetadata()); if (TM.Options.EnableMachineOutliner && diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def index d3320ef82098c..956304560b683 100644 --- a/llvm/include/llvm/Passes/MachinePassRegistry.def +++ b/llvm/include/llvm/Passes/MachinePassRegistry.def @@ -214,6 +214,17 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS( }, "enable-tail-merge") +MACHINE_FUNCTION_PASS_WITH_PARAMS( + "live-debug-values", "LiveDebugValuesPass", + [](bool ShouldEmitDebugEntryValues) { + return LiveDebugValuesPass(ShouldEmitDebugEntryValues); + }, + [](StringRef Params) { + return parseSinglePassOption(Params, "emit-debug-entry-values", + "LiveDebugValuesPass"); + }, + "emit-debug-entry-values") + MACHINE_FUNCTION_PASS_WITH_PARAMS( "machine-sink", "MachineSinkingPass", [](bool EnableSinkAndFold) { @@ -278,7 +289,6 @@ DUMMY_MACHINE_FUNCTION_PASS("instruction-select", InstructionSelectPass) DUMMY_MACHINE_FUNCTION_PASS("irtranslator", IRTranslatorPass) DUMMY_MACHINE_FUNCTION_PASS("kcfi", MachineKCFIPass) DUMMY_MACHINE_FUNCTION_PASS("legalizer", LegalizerPass) -DUMMY_MACHINE_FUNCTION_PASS("livedebugvalues", LiveDebugValuesPass) DUMMY_MACHINE_FUNCTION_PASS("lrshrink", LiveRangeShrinkPass) DUMMY_MACHINE_FUNCTION_PASS("machine-combiner", MachineCombinerPass) DUMMY_MACHINE_FUNCTION_PASS("static-data-splitter", StaticDataSplitter) diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index 6da72c83f985a..9544151bc7771 100644 --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -58,7 +58,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) { initializeInterleavedLoadCombinePass(Registry); initializeInterleavedAccessPass(Registry); initializeJMCInstrumenterPass(Registry); - initializeLiveDebugValuesPass(Registry); + initializeLiveDebugValuesLegacyPass(Registry); initializeLiveDebugVariablesWrapperLegacyPass(Registry); initializeLiveIntervalsWrapperPassPass(Registry); initializeLiveRangeShrinkPass(Registry); diff --git a/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp index 484143a03fca1..654e8eb022900 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp @@ -8,6 +8,7 @@ #include "LiveDebugValues.h" +#include "llvm/CodeGen/LiveDebugValuesPass.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" @@ -63,12 +64,12 @@ namespace { /// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or /// InstrRefBasedLDV to perform location propagation, via the LDVImpl /// base class. -class LiveDebugValues : public MachineFunctionPass { +class LiveDebugValuesLegacy : public MachineFunctionPass { public: static char ID; - LiveDebugValues(); - ~LiveDebugValues() = default; + LiveDebugValuesLegacy(); + ~LiveDebugValuesLegacy() = default; /// Calculate the liveness information for the given machine function. bool runOnMachineFunction(MachineFunction &MF) override; @@ -77,36 +78,68 @@ class LiveDebugValues : public MachineFunctionPass { AU.setPreservesCFG(); MachineFunctionPass::getAnalysisUsage(AU); } +}; + +struct LiveDebugValues { + LiveDebugValues(); + ~LiveDebugValues() = default; + bool run(MachineFunction &MF, bool ShouldEmitDebugEntryValues); private: std::unique_ptr<LDVImpl> InstrRefImpl; std::unique_ptr<LDVImpl> VarLocImpl; - TargetPassConfig *TPC = nullptr; MachineDominatorTree MDT; }; } // namespace -char LiveDebugValues::ID = 0; +char LiveDebugValuesLegacy::ID = 0; -char &llvm::LiveDebugValuesID = LiveDebugValues::ID; +char &llvm::LiveDebugValuesID = LiveDebugValuesLegacy::ID; -INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, - false) +INITIALIZE_PASS(LiveDebugValuesLegacy, DEBUG_TYPE, "Live DEBUG_VALUE analysis", + false, false) /// Default construct and initialize the pass. -LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) { - initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry()); +LiveDebugValuesLegacy::LiveDebugValuesLegacy() : MachineFunctionPass(ID) { + initializeLiveDebugValuesLegacyPass(*PassRegistry::getPassRegistry()); +} + +LiveDebugValues::LiveDebugValues() { InstrRefImpl = std::unique_ptr<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues()); VarLocImpl = std::unique_ptr<LDVImpl>(llvm::makeVarLocBasedLiveDebugValues()); } -bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { +PreservedAnalyses +LiveDebugValuesPass::run(MachineFunction &MF, + MachineFunctionAnalysisManager &MFAM) { + if (!LiveDebugValues().run(MF, ShouldEmitDebugEntryValues)) + return PreservedAnalyses::all(); + auto PA = getMachineFunctionPassPreservedAnalyses(); + PA.preserveSet<CFGAnalyses>(); + return PA; +} + +void LiveDebugValuesPass::printPipeline( + raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) { + OS << MapClassName2PassName(name()); + if (ShouldEmitDebugEntryValues) + OS << "<emit-debug-entry-values>"; +} + +bool LiveDebugValuesLegacy::runOnMachineFunction(MachineFunction &MF) { + auto *TPC = getAnalysisIfAvailable<TargetPassConfig>(); + assert(TPC && "TargetPassConfig must be available"); + return LiveDebugValues().run( + MF, TPC->getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues()); +} + +bool LiveDebugValues::run(MachineFunction &MF, + bool ShouldEmitDebugEntryValues) { bool InstrRefBased = MF.useDebugInstrRef(); // Allow the user to force selection of InstrRef LDV. InstrRefBased |= ForceInstrRefLDV; - TPC = getAnalysisIfAvailable<TargetPassConfig>(); LDVImpl *TheImpl = &*VarLocImpl; MachineDominatorTree *DomTree = nullptr; @@ -116,10 +149,8 @@ bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { TheImpl = &*InstrRefImpl; } - return TheImpl->ExtendRanges( - MF, DomTree, - TPC->getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues(), - InputBBLimit, InputDbgValueLimit); + return TheImpl->ExtendRanges(MF, DomTree, ShouldEmitDebugEntryValues, + InputBBLimit, InputDbgValueLimit); } bool llvm::debuginfoShouldUseDebugInstrRef(const Triple &T) { diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 7dfff2479d3cf..cd18d015d8eac 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -104,6 +104,7 @@ #include "llvm/CodeGen/InterleavedAccess.h" #include "llvm/CodeGen/InterleavedLoadCombine.h" #include "llvm/CodeGen/JMCInstrumenter.h" +#include "llvm/CodeGen/LiveDebugValuesPass.h" #include "llvm/CodeGen/LiveDebugVariables.h" #include "llvm/CodeGen/LiveIntervals.h" #include "llvm/CodeGen/LiveRegMatrix.h" diff --git a/llvm/test/CodeGen/ARM/dbg-range-extension.mir b/llvm/test/CodeGen/ARM/dbg-range-extension.mir index 04bfc1d8f09a8..2a71eed43cef1 100644 --- a/llvm/test/CodeGen/ARM/dbg-range-extension.mir +++ b/llvm/test/CodeGen/ARM/dbg-range-extension.mir @@ -1,4 +1,5 @@ # RUN: llc -mtriple=arm-eabi -run-pass=livedebugvalues %s -o - | FileCheck %s +# RUN: llc -mtriple=arm-eabi -passes=live-debug-values %s -o - | FileCheck %s # # Check that the debug information for variables are propagated into the correct blocks. # diff --git a/llvm/test/DebugInfo/AArch64/compiler-gen-bbs-livedebugvalues.mir b/llvm/test/DebugInfo/AArch64/compiler-gen-bbs-livedebugvalues.mir index 54dc9360d5b49..d97ef2214f054 100644 --- a/llvm/test/DebugInfo/AArch64/compiler-gen-bbs-livedebugvalues.mir +++ b/llvm/test/DebugInfo/AArch64/compiler-gen-bbs-livedebugvalues.mir @@ -1,5 +1,8 @@ # RUN: llc -o - %s -O0 -regalloc=fast -run-pass=livedebugvalues | \ # RUN: FileCheck %s -implicit-check-not=DBG_VALUE + +# RUN: llc -o - %s -O0 -regalloc=fast -passes=live-debug-values | \ +# RUN: FileCheck %s -implicit-check-not=DBG_VALUE --- | target triple = "arm64-apple-ios12.1.0" _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits