CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment

Work toward making ~MCCVInlineLineTableFragment trivial.
This commit is contained in:
Fangrui Song
2025-06-29 18:56:02 -07:00
parent 9a6e0688b0
commit e47d4010d3
3 changed files with 12 additions and 3 deletions

View File

@@ -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 @@ private:
/// 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

View File

@@ -492,8 +492,8 @@ public:
/// 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 @@ public:
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;

View File

@@ -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);