[llvm] b90cba1 - [NFC][RemoveDIs] Shuffle header inclusions for "new" debug-info

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 05:35:03 PST 2023


Author: Jeremy Morse
Date: 2023-11-09T13:19:05Z
New Revision: b90cba10f9ca3115ccd90f17295367aedfdc6260

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

LOG: [NFC][RemoveDIs] Shuffle header inclusions for "new" debug-info

BasicBlock.h and Instruction.h will eventually need to include
DebugProgramInstruction.h so that debug-info attached to instructions can
be enumerated and cloned. Originally including it made compiling clang
much slower, I think I've pinned that down as being the inclusion of
DebugInfoMetadata.h causing ~every LLVM translation unit to parse
all the debug-info classes.

This patch avoids that by shifting some functions into the cpp file rather
than the header, and restores the inclusion of DebugProgramInstruction.h in
BasicBlock.h so that the rest of the RemoveDIs functionality can land.

Added: 
    

Modified: 
    llvm/include/llvm/IR/BasicBlock.h
    llvm/include/llvm/IR/DebugProgramInstruction.h
    llvm/lib/IR/DebugProgramInstruction.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h
index a6d66d1a02b8349..aede5e6c69464ab 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -20,6 +20,7 @@
 #include "llvm/ADT/iterator.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/IR/Instruction.h"
+#include "llvm/IR/DebugProgramInstruction.h"
 #include "llvm/IR/SymbolTableListTraits.h"
 #include "llvm/IR/Value.h"
 #include <cassert>

diff  --git a/llvm/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h
index fef4bb642bf3616..3b5414ecd27d738 100644
--- a/llvm/include/llvm/IR/DebugProgramInstruction.h
+++ b/llvm/include/llvm/IR/DebugProgramInstruction.h
@@ -50,10 +50,8 @@
 #include "llvm/ADT/ilist_node.h"
 #include "llvm/ADT/ilist.h"
 #include "llvm/ADT/iterator.h"
-#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/IR/DebugLoc.h"
-#include <cstdint>
-#include <utility>
 
 namespace llvm {
 
@@ -186,11 +184,7 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
 
   void setExpression(DIExpression *NewExpr) { Expression = NewExpr; }
 
-  unsigned getNumVariableLocationOps() const {
-    if (hasArgList())
-      return cast<DIArgList>(getRawLocation())->getArgs().size();
-    return 1;
-  }
+  unsigned getNumVariableLocationOps() const;
 
   bool hasArgList() const { return isa<DIArgList>(getRawLocation()); }
   /// Returns true if this DPValue has no empty MDNodes in its location list.
@@ -204,23 +198,8 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
   DebugLoc getDebugLoc() const { return DbgLoc; }
   void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
 
-  void setKillLocation() {
-    // TODO: When/if we remove duplicate values from DIArgLists, we don't need
-    // this set anymore.
-    SmallPtrSet<Value *, 4> RemovedValues;
-    for (Value *OldValue : location_ops()) {
-      if (!RemovedValues.insert(OldValue).second)
-        continue;
-      Value *Poison = PoisonValue::get(OldValue->getType());
-      replaceVariableLocationOp(OldValue, Poison);
-    }
-  }
-
-  bool isKillLocation() const {
-    return (getNumVariableLocationOps() == 0 &&
-            !getExpression()->isComplex()) ||
-           any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
-  }
+  void setKillLocation();
+  bool isKillLocation() const;
 
   DILocalVariable *getVariable() const { return Variable; }
 

diff  --git a/llvm/lib/IR/DebugProgramInstruction.cpp b/llvm/lib/IR/DebugProgramInstruction.cpp
index 3f39bae983253d0..c307cd42a6336da 100644
--- a/llvm/lib/IR/DebugProgramInstruction.cpp
+++ b/llvm/lib/IR/DebugProgramInstruction.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DebugProgramInstruction.h"
 #include "llvm/IR/DIBuilder.h"
 #include "llvm/IR/IntrinsicInst.h"
@@ -64,6 +65,12 @@ iterator_range<DPValue::location_op_iterator> DPValue::location_ops() const {
           location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
 }
 
+unsigned DPValue::getNumVariableLocationOps() const {
+  if (hasArgList())
+    return cast<DIArgList>(getRawLocation())->getArgs().size();
+  return 1;
+}
+
 Value *DPValue::getVariableLocationOp(unsigned OpIdx) const {
   auto *MD = getRawLocation();
   if (!MD)
@@ -150,6 +157,24 @@ void DPValue::addVariableLocationOps(ArrayRef<Value *> NewValues,
   setRawLocation(DIArgList::get(getVariableLocationOp(0)->getContext(), MDs));
 }
 
+void DPValue::setKillLocation() {
+  // TODO: When/if we remove duplicate values from DIArgLists, we don't need
+  // this set anymore.
+  SmallPtrSet<Value *, 4> RemovedValues;
+  for (Value *OldValue : location_ops()) {
+    if (!RemovedValues.insert(OldValue).second)
+      continue;
+    Value *Poison = PoisonValue::get(OldValue->getType());
+    replaceVariableLocationOp(OldValue, Poison);
+  }
+}
+
+bool DPValue::isKillLocation() const {
+  return (getNumVariableLocationOps() == 0 &&
+          !getExpression()->isComplex()) ||
+         any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
+}
+
 std::optional<uint64_t> DPValue::getFragmentSizeInBits() const {
   if (auto Fragment = getExpression()->getFragmentInfo())
     return Fragment->SizeInBits;


        


More information about the llvm-commits mailing list