[llvm] e3e1da2 - Follow up to a3936a6c19c, correctly select LiveDebugValues implementation

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 14 03:35:39 PDT 2021


Author: Jeremy Morse
Date: 2021-10-14T11:28:53+01:00
New Revision: e3e1da20d4a97085c805f7d115bd8168f49b1348

URL: https://github.com/llvm/llvm-project/commit/e3e1da20d4a97085c805f7d115bd8168f49b1348
DIFF: https://github.com/llvm/llvm-project/commit/e3e1da20d4a97085c805f7d115bd8168f49b1348.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp
index a6b2f19a0444a..fe9eb6dd6e9ee 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp
@@ -60,10 +60,7 @@ class LiveDebugValues : public MachineFunctionPass {
   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 @@ class LiveDebugValues : public MachineFunctionPass {
   }
 
 private:
-  LDVImpl *TheImpl;
+  std::unique_ptr<LDVImpl> InstrRefImpl;
+  std::unique_ptr<LDVImpl> 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<LDVImpl>(llvm::makeInstrRefBasedLiveDebugValues());
+  VarLocImpl = std::unique_ptr<LDVImpl>(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<TargetPassConfig>();
-
-    if (InstrRefBased)
-      TheImpl = llvm::makeInstrRefBasedLiveDebugValues();
-    else
-      TheImpl = llvm::makeVarLocBasedLiveDebugValues();
-  }
+  TPC = getAnalysisIfAvailable<TargetPassConfig>();
+  LDVImpl *TheImpl = &*VarLocImpl;
 
   MachineDominatorTree *DomTree = nullptr;
   if (InstrRefBased) {
     DomTree = &MDT;
     MDT.calculate(MF);
+    TheImpl = &*InstrRefImpl;
   }
 
   return TheImpl->ExtendRanges(MF, DomTree, TPC, InputBBLimit,


        


More information about the llvm-commits mailing list