[llvm] 66cd8ec - MCCodeView: replace the MCAsmLayout parameter with MCAssembler
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 17:08:43 PDT 2024
Author: Fangrui Song
Date: 2024-07-01T17:08:38-07:00
New Revision: 66cd8ec4c08252ebc73c82e4883a8da247ed146b
URL: https://github.com/llvm/llvm-project/commit/66cd8ec4c08252ebc73c82e4883a8da247ed146b
DIFF: https://github.com/llvm/llvm-project/commit/66cd8ec4c08252ebc73c82e4883a8da247ed146b.diff
LOG: MCCodeView: replace the MCAsmLayout parameter with MCAssembler
Added:
Modified:
llvm/include/llvm/MC/MCCodeView.h
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCCodeView.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCCodeView.h b/llvm/include/llvm/MC/MCCodeView.h
index b1d8fe37a3188..30923274ea72d 100644
--- a/llvm/include/llvm/MC/MCCodeView.h
+++ b/llvm/include/llvm/MC/MCCodeView.h
@@ -22,7 +22,7 @@
#include <vector>
namespace llvm {
-class MCAsmLayout;
+class MCAssembler;
class MCCVDefRangeFragment;
class MCCVInlineLineTableFragment;
class MCDataFragment;
@@ -199,7 +199,7 @@ class CodeViewContext {
const MCSymbol *FnEndSym);
/// Encodes the binary annotations once we have a layout.
- void encodeInlineLineTable(MCAsmLayout &Layout,
+ void encodeInlineLineTable(const MCAssembler &Asm,
MCCVInlineLineTableFragment &F);
MCFragment *
@@ -207,7 +207,7 @@ class CodeViewContext {
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
StringRef FixedSizePortion);
- void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F);
+ void encodeDefRange(const MCAssembler &Asm, MCCVDefRangeFragment &F);
/// Emits the string table substream.
void emitStringTable(MCObjectStreamer &OS);
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 6da48155ac9ac..f820cc9eef7fe 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -1288,13 +1288,13 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCDwarfCallFrameFragment &DF) {
bool MCAssembler::relaxCVInlineLineTable(MCCVInlineLineTableFragment &F) {
unsigned OldSize = F.getContents().size();
- getContext().getCVContext().encodeInlineLineTable(*Layout, F);
+ getContext().getCVContext().encodeInlineLineTable(*this, F);
return OldSize != F.getContents().size();
}
bool MCAssembler::relaxCVDefRange(MCCVDefRangeFragment &F) {
unsigned OldSize = F.getContents().size();
- getContext().getCVContext().encodeDefRange(*Layout, F);
+ getContext().getCVContext().encodeDefRange(*this, F);
return OldSize != F.getContents().size();
}
diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp
index a47a07b71be7e..792a132d6fb86 100644
--- a/llvm/lib/MC/MCCodeView.cpp
+++ b/llvm/lib/MC/MCCodeView.cpp
@@ -16,7 +16,6 @@
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/DebugInfo/CodeView/Line.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
-#include "llvm/MC/MCAsmLayout.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectStreamer.h"
@@ -465,17 +464,16 @@ MCFragment *CodeViewContext::emitDefRange(
return F;
}
-static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin,
+static unsigned computeLabelDiff(const MCAssembler &Asm, const MCSymbol *Begin,
const MCSymbol *End) {
- MCContext &Ctx = Layout.getAssembler().getContext();
+ MCContext &Ctx = Asm.getContext();
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
const MCExpr *BeginRef = MCSymbolRefExpr::create(Begin, Variant, Ctx),
*EndRef = MCSymbolRefExpr::create(End, Variant, Ctx);
const MCExpr *AddrDelta =
MCBinaryExpr::create(MCBinaryExpr::Sub, EndRef, BeginRef, Ctx);
int64_t Result;
- bool Success =
- AddrDelta->evaluateKnownAbsolute(Result, Layout.getAssembler());
+ bool Success = AddrDelta->evaluateKnownAbsolute(Result, Asm);
assert(Success && "failed to evaluate label
diff erence as absolute");
(void)Success;
assert(Result >= 0 && "negative label
diff erence requested");
@@ -483,7 +481,7 @@ static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin,
return unsigned(Result);
}
-void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout,
+void CodeViewContext::encodeInlineLineTable(const MCAssembler &Asm,
MCCVInlineLineTableFragment &Frag) {
size_t LocBegin;
size_t LocEnd;
@@ -550,7 +548,7 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout,
// We've hit a cv_loc not attributed to this inline call site. Use this
// label to end the PC range.
if (HaveOpenRange) {
- unsigned Length = computeLabelDiff(Layout, LastLabel, Loc.getLabel());
+ unsigned Length = computeLabelDiff(Asm, LastLabel, Loc.getLabel());
compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer);
compressAnnotation(Length, Buffer);
LastLabel = Loc.getLabel();
@@ -580,7 +578,7 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout,
int LineDelta = CurSourceLoc.Line - LastSourceLoc.Line;
unsigned EncodedLineDelta = encodeSignedNumber(LineDelta);
- unsigned CodeDelta = computeLabelDiff(Layout, LastLabel, Loc.getLabel());
+ unsigned CodeDelta = computeLabelDiff(Asm, LastLabel, Loc.getLabel());
if (EncodedLineDelta < 0x8 && CodeDelta <= 0xf) {
// The ChangeCodeOffsetAndLineOffset combination opcode is used when the
// encoded line delta uses 3 or fewer set bits and the code offset fits
@@ -606,23 +604,23 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout,
assert(HaveOpenRange);
unsigned EndSymLength =
- computeLabelDiff(Layout, LastLabel, Frag.getFnEndSym());
+ computeLabelDiff(Asm, LastLabel, Frag.getFnEndSym());
unsigned LocAfterLength = ~0U;
ArrayRef<MCCVLoc> LocAfter = getLinesForExtent(LocEnd, LocEnd + 1);
if (!LocAfter.empty()) {
// Only try to compute this
diff erence if we're in the same section.
const MCCVLoc &Loc = LocAfter[0];
if (&Loc.getLabel()->getSection() == &LastLabel->getSection())
- LocAfterLength = computeLabelDiff(Layout, LastLabel, Loc.getLabel());
+ LocAfterLength = computeLabelDiff(Asm, LastLabel, Loc.getLabel());
}
compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer);
compressAnnotation(std::min(EndSymLength, LocAfterLength), Buffer);
}
-void CodeViewContext::encodeDefRange(MCAsmLayout &Layout,
+void CodeViewContext::encodeDefRange(const MCAssembler &Asm,
MCCVDefRangeFragment &Frag) {
- MCContext &Ctx = Layout.getAssembler().getContext();
+ MCContext &Ctx = Asm.getContext();
SmallVectorImpl<char> &Contents = Frag.getContents();
Contents.clear();
SmallVectorImpl<MCFixup> &Fixups = Frag.getFixups();
@@ -634,8 +632,8 @@ void CodeViewContext::encodeDefRange(MCAsmLayout &Layout,
const MCSymbol *LastLabel = nullptr;
for (std::pair<const MCSymbol *, const MCSymbol *> Range : Frag.getRanges()) {
unsigned GapSize =
- LastLabel ? computeLabelDiff(Layout, LastLabel, Range.first) : 0;
- unsigned RangeSize = computeLabelDiff(Layout, Range.first, Range.second);
+ LastLabel ? computeLabelDiff(Asm, LastLabel, Range.first) : 0;
+ unsigned RangeSize = computeLabelDiff(Asm, Range.first, Range.second);
GapAndRangeSizes.push_back({GapSize, RangeSize});
LastLabel = Range.second;
}
More information about the llvm-commits
mailing list