[PATCH] D101571: [GlobalISel] Use an empty LostDebugLocObserver when building with NDEBUG.

Amara Emerson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 29 14:32:11 PDT 2021


aemerson created this revision.
aemerson added reviewers: dsanders, paquette.
aemerson added a project: LLVM.
Herald added subscribers: hiraditya, rovka.
aemerson requested review of this revision.

Since this is an assertion-like feature, it shouldn't be run without NDEBUG. Saves a small amount of compile time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101571

Files:
  llvm/include/llvm/CodeGen/GlobalISel/LostDebugLocObserver.h
  llvm/lib/CodeGen/GlobalISel/Legalizer.cpp


Index: llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
+++ llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
@@ -339,7 +339,11 @@
     AuxObservers.push_back(CSEInfo);
   }
   assert(!CSEInfo || !errorToBool(CSEInfo->verify()));
+#ifndef NDEBUG
   LostDebugLocObserver LocObserver(DEBUG_TYPE);
+#else
+  NullLostDebugLocObserver LocObserver;
+#endif
   if (VerifyDebugLocs > DebugLocVerifyLevel::None)
     AuxObservers.push_back(&LocObserver);
 
Index: llvm/include/llvm/CodeGen/GlobalISel/LostDebugLocObserver.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/LostDebugLocObserver.h
+++ llvm/include/llvm/CodeGen/GlobalISel/LostDebugLocObserver.h
@@ -16,16 +16,17 @@
 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
 
 namespace llvm {
-class LostDebugLocObserver : public GISelChangeObserver {
+class LostDebugLocObserver : public GISelChangeObserver{
   StringRef DebugType;
   SmallSet<DebugLoc, 4> LostDebugLocs;
   SmallPtrSet<MachineInstr *, 4> PotentialMIsForDebugLocs;
   unsigned NumLostDebugLocs = 0;
 
 public:
+  LostDebugLocObserver() = default;
   LostDebugLocObserver(StringRef DebugType) : DebugType(DebugType) {}
 
-  unsigned getNumLostDebugLocs() const { return NumLostDebugLocs; }
+  virtual unsigned getNumLostDebugLocs() const { return NumLostDebugLocs; }
 
   /// Call this to indicate that it's a good point to assess whether locations
   /// have been lost. Typically this will be when a logical change has been
@@ -35,16 +36,31 @@
   /// CheckDebugLocs is false, it will just reset ready for the next checkpoint
   /// without checking anything. This can be helpful to limit the detection to
   /// easy-to-fix portions of an algorithm before allowing more difficult ones.
-  void checkpoint(bool CheckDebugLocs = true);
+  virtual void checkpoint(bool CheckDebugLocs = true);
 
-  void createdInstr(MachineInstr &MI) override;
-  void erasingInstr(MachineInstr &MI) override;
-  void changingInstr(MachineInstr &MI) override;
-  void changedInstr(MachineInstr &MI) override;
+  virtual void createdInstr(MachineInstr &MI) override;
+  virtual void erasingInstr(MachineInstr &MI) override;
+  virtual void changingInstr(MachineInstr &MI) override;
+  virtual void changedInstr(MachineInstr &MI) override;
 
 private:
   void analyzeDebugLocations();
 };
 
+/// This is an empty observer that can be installed when assertions are
+/// disabled, to save compile time without requiring more intrusive ifdefs at
+/// the user call sites.
+class NullLostDebugLocObserver : public LostDebugLocObserver {
+public:
+  NullLostDebugLocObserver() = default;
+  virtual unsigned getNumLostDebugLocs() const override { return 0; }
+  virtual void checkpoint(bool CheckDebugLocs = true) override {}
+
+  virtual void createdInstr(MachineInstr &MI) override {}
+  virtual void erasingInstr(MachineInstr &MI) override {}
+  virtual void changingInstr(MachineInstr &MI) override {}
+  virtual void changedInstr(MachineInstr &MI) override {}
+};
+
 } // namespace llvm
 #endif // LLVM_CODEGEN_GLOBALISEL_LOSTDEBUGLOCOBSERVER_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101571.341644.patch
Type: text/x-patch
Size: 3208 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210429/cbbfbab4/attachment.bin>


More information about the llvm-commits mailing list