Skip to content

Commit 6ebc423

Browse files
committed
MCStreamer: Move fragment-related functions to MCObjectStreamer
They are specific to MCObjectStreamer and unneeded by MCAsmStreamer. Add isObj() so that MCTargetAsmParser can determine whether the streamer is MCObjectStreamer and conditionally call newFragment.
1 parent 8ae4dee commit 6ebc423

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ class MCObjectStreamer : public MCStreamer {
8080
/// \name MCStreamer Interface
8181
/// @{
8282

83+
// Add a fragment with a variable-size tail and start a new empty fragment.
84+
void insert(MCFragment *F);
85+
86+
void addFixup(const MCExpr *Value, MCFixupKind Kind, uint32_t Offset = 0);
87+
// Add a new fragment to the current section without a variable-size tail.
88+
void newFragment();
89+
8390
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
8491
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F,
8592
uint64_t Offset);

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ class LLVM_ABI MCStreamer {
259259
bool AllowAutoPadding = false;
260260

261261
protected:
262+
bool IsObj = false;
263+
262264
// Symbol of the current epilog for which we are processing SEH directives.
263265
WinEH::FrameInfo::Epilog *CurrentWinEpilog = nullptr;
264266

@@ -310,6 +312,7 @@ class LLVM_ABI MCStreamer {
310312
virtual void reset();
311313

312314
MCContext &getContext() const { return Context; }
315+
bool isObj() const { return IsObj; }
313316

314317
// MCObjectStreamer has an MCAssembler and allows more expression folding at
315318
// parse time.
@@ -462,11 +465,6 @@ class LLVM_ABI MCStreamer {
462465

463466
MCSymbol *endSection(MCSection *Section);
464467

465-
/// Add a new fragment to the current section without a variable-size tail.
466-
void newFragment();
467-
/// Add a fragment with a variable-size tail and start a new empty fragment.
468-
void insert(MCFragment *F);
469-
470468
/// Returns the mnemonic for \p MI, if the streamer has access to a
471469
/// instruction printer and returns an empty string otherwise.
472470
virtual StringRef getMnemonic(const MCInst &MI) const { return ""; }

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ MCObjectStreamer::MCObjectStreamer(MCContext &Context,
3333
Context, std::move(TAB), std::move(Emitter), std::move(OW))),
3434
EmitEHFrame(true), EmitDebugFrame(false) {
3535
assert(Assembler->getBackendPtr() && Assembler->getEmitterPtr());
36+
IsObj = true;
3637
setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
3738
if (Context.getTargetOptions() && Context.getTargetOptions()->MCRelaxAll)
3839
Assembler->setRelaxAll(true);
@@ -46,6 +47,23 @@ MCAssembler *MCObjectStreamer::getAssemblerPtr() {
4647
return nullptr;
4748
}
4849

50+
void MCObjectStreamer::newFragment() {
51+
addFragment(getContext().allocFragment<MCFragment>());
52+
}
53+
54+
void MCObjectStreamer::insert(MCFragment *F) {
55+
assert(F->getKind() != MCFragment::FT_Data &&
56+
"F should have a variable-size tail");
57+
addFragment(F);
58+
newFragment();
59+
}
60+
61+
void MCObjectStreamer::addFixup(const MCExpr *Value, MCFixupKind Kind,
62+
uint32_t Offset) {
63+
CurFrag->addFixup(
64+
MCFixup::create(CurFrag->getFixedSize() + Offset, Value, Kind));
65+
}
66+
4967
// As a compile-time optimization, avoid allocating and evaluating an MCExpr
5068
// tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment's fixed
5169
// part.

llvm/lib/MC/MCParser/MCTargetAsmParser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
1010
#include "llvm/MC/MCContext.h"
11+
#include "llvm/MC/MCObjectStreamer.h"
1112
#include "llvm/MC/MCRegister.h"
12-
#include "llvm/MC/MCStreamer.h"
1313

1414
using namespace llvm;
1515

@@ -25,8 +25,9 @@ MCSubtargetInfo &MCTargetAsmParser::copySTI() {
2525
STI = &STICopy;
2626
// The returned STI will likely be modified. Create a new fragment to prevent
2727
// mixing STI values within a fragment.
28-
if (getStreamer().getCurrentFragment())
29-
getStreamer().newFragment();
28+
auto &S = getStreamer();
29+
if (S.isObj() && S.getCurrentFragment())
30+
static_cast<MCObjectStreamer &>(S).newFragment();
3031
return STICopy;
3132
}
3233

llvm/lib/MC/MCStreamer.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,17 +1413,6 @@ void MCStreamer::addFragment(MCFragment *F) {
14131413
Sec->curFragList()->Tail = F;
14141414
}
14151415

1416-
void MCStreamer::newFragment() {
1417-
addFragment(getContext().allocFragment<MCFragment>());
1418-
}
1419-
1420-
void MCStreamer::insert(MCFragment *F) {
1421-
assert(F->getKind() != MCFragment::FT_Data &&
1422-
"F should have a variable-size tail");
1423-
addFragment(F);
1424-
newFragment();
1425-
}
1426-
14271416
static VersionTuple
14281417
targetVersionOrMinimumSupportedOSVersion(const Triple &Target,
14291418
VersionTuple TargetVersion) {

0 commit comments

Comments
 (0)