diff options
author | Akshat Oke <Akshat.Oke@amd.com> | 2025-03-24 11:34:45 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-24 11:34:45 +0530 |
commit | 174110bf3c3b5dc6efa466392f740bb6e9e9acf6 (patch) | |
tree | 783ea35cf4e0c7d755a98a34c01a4fcddc632b6e /llvm/lib | |
parent | 3c2731ce46f01a984a9cc1807207de8d333bc350 (diff) | |
download | llvm-174110bf3c3b5dc6efa466392f740bb6e9e9acf6.zip llvm-174110bf3c3b5dc6efa466392f740bb6e9e9acf6.tar.gz llvm-174110bf3c3b5dc6efa466392f740bb6e9e9acf6.tar.bz2 |
[CodeGen][NPM] Port LiveDebugValues to NPM (#131563)
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/CodeGen.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp | 63 | ||||
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 1 |
3 files changed, 49 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index 6da72c8..9544151 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 484143a..b655375 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,50 +64,82 @@ 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; void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesCFG(); + AU.addRequired<TargetPassConfig>(); 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 = &getAnalysis<TargetPassConfig>(); + 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 e2ef542..1b37e4a4 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -105,6 +105,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" |