Skip to content

Commit 1b41599

Browse files
authored
[MC][AArch64][ARM][X86] Push target-dependent assembler flags into targets (#139844)
The .syntax unified directive and .codeX/.code X directives are, other than some simple common printing code, exclusively implemented in the targets themselves. Thus, remove the corresponding MCAF_* flags and reimplement the directives solely within the targets. This avoids exposing all targets to all other targets' flags. Since MCAF_SubsectionsViaSymbols is all that remains, convert it to its own function like other directives, simplifying its implementation. Note that, on X86, we now always need a target streamer when parsing assembly, as it's now used for directives that aren't COFF-specific. It still does not however need to do anything when producing a non-COFF object file, so this commit does not introduce any new target streamers. There is some churn in test output, and corresponding UTC regex changes, due to comments no longer being flushed by these various directives (and EmitEOL is not exposed outside MCAsmStreamer.cpp so we couldn't do so even if we wanted to), but that was a bit odd to be doing anyway. This is motivated by Morello LLVM, which adds yet another assembler flag to distinguish A64 and C64 instruction sets, but did not update every switch and so emits warnings during the build. Rather than fix those warnings it seems better to instead make the problem not exist in the first place via this change.
1 parent 5fa985e commit 1b41599

38 files changed

+136
-195
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,6 @@ class MCAsmBackend {
213213
/// Give backend an opportunity to finish layout after relaxation
214214
virtual void finishLayout(MCAssembler const &Asm) const {}
215215

216-
/// Handle any target-specific assembler flags. By default, do nothing.
217-
virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
218-
219216
/// Generate the compact unwind encoding for the CFI instructions.
220217
virtual uint64_t generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI,
221218
const MCContext *Ctxt) const {

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,6 @@ class MCAsmInfo {
166166
const char *InlineAsmStart;
167167
const char *InlineAsmEnd;
168168

169-
/// These are assembly directives that tells the assembler to interpret the
170-
/// following instructions differently. Defaults to ".code16", ".code32",
171-
/// ".code64".
172-
const char *Code16Directive;
173-
const char *Code32Directive;
174-
const char *Code64Directive;
175-
176169
/// Which dialect of an assembler variant to use. Defaults to 0
177170
unsigned AssemblerDialect = 0;
178171

@@ -544,9 +537,6 @@ class MCAsmInfo {
544537

545538
const char *getInlineAsmStart() const { return InlineAsmStart; }
546539
const char *getInlineAsmEnd() const { return InlineAsmEnd; }
547-
const char *getCode16Directive() const { return Code16Directive; }
548-
const char *getCode32Directive() const { return Code32Directive; }
549-
const char *getCode64Directive() const { return Code64Directive; }
550540
unsigned getAssemblerDialect() const { return AssemblerDialect; }
551541
bool doesAllowAtInName() const { return AllowAtInName; }
552542
void setAllowAtInName(bool V) { AllowAtInName = V; }

llvm/include/llvm/MC/MCDirectives.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ enum MCSymbolAttr {
5050
MCSA_Memtag, ///< .memtag (ELF)
5151
};
5252

53-
enum MCAssemblerFlag {
54-
MCAF_SyntaxUnified, ///< .syntax (ARM/ELF)
55-
MCAF_SubsectionsViaSymbols, ///< .subsections_via_symbols (MachO)
56-
MCAF_Code16, ///< .code16 (X86) / .code 16 (ARM)
57-
MCAF_Code32, ///< .code32 (X86) / .code 32 (ARM)
58-
MCAF_Code64 ///< .code64 (X86)
59-
};
60-
6153
enum MCDataRegionType {
6254
MCDR_DataRegion, ///< .data_region
6355
MCDR_DataRegionJT8, ///< .data_region jt8

llvm/include/llvm/MC/MCELFStreamer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class MCELFStreamer : public MCObjectStreamer {
5353
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
5454
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
5555
uint64_t Offset) override;
56-
void emitAssemblerFlag(MCAssemblerFlag Flag) override;
5756
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
5857
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
5958
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ class ARMTargetStreamer : public MCTargetStreamer {
169169

170170
virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
171171

172+
virtual void emitSyntaxUnified();
173+
174+
virtual void emitCode16();
175+
virtual void emitCode32();
176+
172177
// Note in the output that the specified \p Symbol is a Thumb mode function.
173178
virtual void emitThumbFunc(MCSymbol *Symbol);
174179
virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
@@ -471,8 +476,8 @@ class MCStreamer {
471476

472477
virtual void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
473478

474-
/// Note in the output the specified \p Flag.
475-
virtual void emitAssemblerFlag(MCAssemblerFlag Flag);
479+
/// Emit a .subsection_via_symbols directive.
480+
virtual void emitSubsectionsViaSymbols();
476481

477482
/// Emit the given list \p Options of strings as linker
478483
/// options into the output.

llvm/include/llvm/MC/MCWasmStreamer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class MCWasmStreamer : public MCObjectStreamer {
4444
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
4545
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
4646
uint64_t Offset) override;
47-
void emitAssemblerFlag(MCAssemblerFlag Flag) override;
4847
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
4948
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
5049
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,

llvm/include/llvm/MC/MCWinCOFFStreamer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class MCWinCOFFStreamer : public MCObjectStreamer {
4545
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override;
4646
void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
4747
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
48-
void emitAssemblerFlag(MCAssemblerFlag Flag) override;
4948
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
5049
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
5150
void beginCOFFSymbolDef(MCSymbol const *Symbol) override;

llvm/lib/MC/MCAsmInfo.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ MCAsmInfo::MCAsmInfo() {
4848
LinkerPrivateGlobalPrefix = "";
4949
InlineAsmStart = "APP";
5050
InlineAsmEnd = "NO_APP";
51-
Code16Directive = ".code16";
52-
Code32Directive = ".code32";
53-
Code64Directive = ".code64";
5451
ZeroDirective = "\t.zero\t";
5552
AsciiDirective = "\t.ascii\t";
5653
AscizDirective = "\t.asciz\t";

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class MCAsmStreamer final : public MCStreamer {
182182

183183
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
184184

185-
void emitAssemblerFlag(MCAssemblerFlag Flag) override;
185+
void emitSubsectionsViaSymbols() override;
186186
void emitLinkerOptions(ArrayRef<std::string> Options) override;
187187
void emitDataRegion(MCDataRegionType Kind) override;
188188
void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
@@ -597,15 +597,8 @@ void MCAsmStreamer::emitGNUAttribute(unsigned Tag, unsigned Value) {
597597
OS << "\t.gnu_attribute " << Tag << ", " << Value << "\n";
598598
}
599599

600-
void MCAsmStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
601-
switch (Flag) {
602-
case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
603-
case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
604-
case MCAF_Code16: OS << '\t'<< MAI->getCode16Directive();break;
605-
case MCAF_Code32: OS << '\t'<< MAI->getCode32Directive();break;
606-
case MCAF_Code64: OS << '\t'<< MAI->getCode64Directive();break;
607-
}
608-
EmitEOL();
600+
void MCAsmStreamer::emitSubsectionsViaSymbols() {
601+
OS << ".subsections_via_symbols\n";
609602
}
610603

611604
void MCAsmStreamer::emitLinkerOptions(ArrayRef<std::string> Options) {

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ void MCELFStreamer::emitLabelAtPos(MCSymbol *S, SMLoc Loc, MCDataFragment &F,
8484
Symbol->setType(ELF::STT_TLS);
8585
}
8686

87-
void MCELFStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
88-
// Let the target do whatever target specific stuff it needs to do.
89-
getAssembler().getBackend().handleAssemblerFlag(Flag);
90-
}
91-
9287
// If bundle alignment is used and there are any instructions in the section, it
9388
// needs to be aligned to at least the bundle size.
9489
static void setSectionAlignmentForBundling(const MCAssembler &Assembler,

0 commit comments

Comments
 (0)