[llvm] e47d401 - CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 29 18:56:07 PDT 2025


Author: Fangrui Song
Date: 2025-06-29T18:56:02-07:00
New Revision: e47d4010d34119c2b4a28e7609fde35449a8b437

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

LOG: CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment

Work toward making ~MCCVInlineLineTableFragment trivial.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCCodeView.h
    llvm/include/llvm/MC/MCFragment.h
    llvm/lib/MC/MCCodeView.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCCodeView.h b/llvm/include/llvm/MC/MCCodeView.h
index 2a57e04b2c88c..3219a2ec061cb 100644
--- a/llvm/include/llvm/MC/MCCodeView.h
+++ b/llvm/include/llvm/MC/MCCodeView.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include <deque>
 #include <map>
 #include <vector>
 
@@ -268,6 +269,9 @@ class CodeViewContext {
   /// Indicate whether we have already laid out the checksum table addresses or
   /// not.
   bool ChecksumOffsetsAssigned = false;
+
+  /// Storage of MCCVDefRangeFragment::Ranges.
+  std::deque<std::pair<const MCSymbol *, const MCSymbol *>> DefRangeStorage;
 };
 
 } // end namespace llvm

diff  --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h
index 7bb090d0c57a1..2affa85c744ba 100644
--- a/llvm/include/llvm/MC/MCFragment.h
+++ b/llvm/include/llvm/MC/MCFragment.h
@@ -492,8 +492,8 @@ class MCCVInlineLineTableFragment : public MCFragment {
 
 /// Fragment representing the .cv_def_range directive.
 class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
-  SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 2> Ranges;
-  SmallString<32> FixedSizePortion;
+  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
+  StringRef FixedSizePortion;
 
   /// CodeViewContext has the real knowledge about this format, so let it access
   /// our members.
@@ -510,7 +510,7 @@ class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
     return Ranges;
   }
 
-  StringRef getFixedSizePortion() const { return FixedSizePortion.str(); }
+  StringRef getFixedSizePortion() const { return FixedSizePortion; }
 
   static bool classof(const MCFragment *F) {
     return F->getKind() == MCFragment::FT_CVDefRange;

diff  --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp
index 1407bc52e1c46..e05374783d2b4 100644
--- a/llvm/lib/MC/MCCodeView.cpp
+++ b/llvm/lib/MC/MCCodeView.cpp
@@ -444,6 +444,11 @@ MCFragment *CodeViewContext::emitDefRange(
     StringRef FixedSizePortion) {
   // Create and insert a fragment into the current section that will be encoded
   // later.
+  FixedSizePortion = MCCtx->allocateString(FixedSizePortion);
+  auto Pos = DefRangeStorage.size();
+  llvm::append_range(DefRangeStorage, Ranges);
+  if (!Ranges.empty())
+    Ranges = {&DefRangeStorage[Pos], Ranges.size()};
   auto *F =
       MCCtx->allocFragment<MCCVDefRangeFragment>(Ranges, FixedSizePortion);
   OS.insert(F);


        


More information about the llvm-commits mailing list