From e3e1da20d4a97085c805f7d115bd8168f49b1348 Mon Sep 17 00:00:00 2001 From: Jeremy Morse Date: Thu, 14 Oct 2021 10:58:33 +0100 Subject: [PATCH] Follow up to a3936a6c19c, correctly select LiveDebugValues implementation Some functions get opted out of instruction referencing if they're being compiled with no optimisations, however the LiveDebugValues pass picks one implementation and then sticks with it through the rest of compilation. This leads to a segfault if we encounter a function that doesn't use instr-ref (because it's optnone, for example), but we've already decided to use InstrRefBasedLDV which expects to be passed a DomTree. Solution: keep both implementations around in the pass, and pick whichever one is appropriate to the current function. --- .../LiveDebugValues/LiveDebugValues.cpp | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp index a6b2f19a0444..fe9eb6dd6e9e 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp @@ -60,10 +60,7 @@ public: static char ID; LiveDebugValues(); - ~LiveDebugValues() { - if (TheImpl) - delete TheImpl; - } + ~LiveDebugValues() {} /// Calculate the liveness information for the given machine function. bool runOnMachineFunction(MachineFunction &MF) override; @@ -79,7 +76,8 @@ public: } private: - LDVImpl *TheImpl; + std::unique_ptr InstrRefImpl; + std::unique_ptr VarLocImpl; TargetPassConfig *TPC; MachineDominatorTree MDT; }; @@ -94,7 +92,9 @@ INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, /// Default construct and initialize the pass. LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) { initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry()); - TheImpl = nullptr; + InstrRefImpl = + std::unique_ptr(llvm::makeInstrRefBasedLiveDebugValues()); + VarLocImpl = std::unique_ptr(llvm::makeVarLocBasedLiveDebugValues()); } bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { @@ -102,19 +102,14 @@ bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { // Allow the user to force selection of InstrRef LDV. InstrRefBased |= ForceInstrRefLDV; - if (!TheImpl) { - TPC = getAnalysisIfAvailable(); - - if (InstrRefBased) - TheImpl = llvm::makeInstrRefBasedLiveDebugValues(); - else - TheImpl = llvm::makeVarLocBasedLiveDebugValues(); - } + TPC = getAnalysisIfAvailable(); + LDVImpl *TheImpl = &*VarLocImpl; MachineDominatorTree *DomTree = nullptr; if (InstrRefBased) { DomTree = &MDT; MDT.calculate(MF); + TheImpl = &*InstrRefImpl; } return TheImpl->ExtendRanges(MF, DomTree, TPC, InputBBLimit,