Skip to content

Commit 9e3b128

Browse files
zyedidiaGeorgeARM
authored andcommitted
[AArch64] Emit .arch and .arch_extension during assembly to textual asm (llvm#138433)
This patch ensures that when assembling to text (`-filetype asm`), `.arch` and `.arch_extension` directives are preserved in the output. This prevents errors related to unavailable extensions in the assembly output (see llvm#117221 for an example). Fixes llvm#117221.
1 parent 30a5310 commit 9e3b128

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7189,9 +7189,9 @@ static SMLoc incrementLoc(SMLoc L, int Offset) {
71897189
bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
71907190
SMLoc CurLoc = getLoc();
71917191

7192+
StringRef Name = getParser().parseStringToEndOfStatement().trim();
71927193
StringRef Arch, ExtensionString;
7193-
std::tie(Arch, ExtensionString) =
7194-
getParser().parseStringToEndOfStatement().trim().split('+');
7194+
std::tie(Arch, ExtensionString) = Name.split('+');
71957195

71967196
const AArch64::ArchInfo *ArchInfo = AArch64::parseArch(Arch);
71977197
if (!ArchInfo)
@@ -7238,6 +7238,8 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
72387238
}
72397239
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
72407240
setAvailableFeatures(Features);
7241+
7242+
getTargetStreamer().emitDirectiveArch(Name);
72417243
return false;
72427244
}
72437245

@@ -7246,12 +7248,13 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
72467248
bool AArch64AsmParser::parseDirectiveArchExtension(SMLoc L) {
72477249
SMLoc ExtLoc = getLoc();
72487250

7249-
StringRef Name = getParser().parseStringToEndOfStatement().trim();
7251+
StringRef FullName = getParser().parseStringToEndOfStatement().trim();
72507252

72517253
if (parseEOL())
72527254
return true;
72537255

72547256
bool EnableFeature = true;
7257+
StringRef Name = FullName;
72557258
if (Name.starts_with_insensitive("no")) {
72567259
EnableFeature = false;
72577260
Name = Name.substr(2);
@@ -7271,6 +7274,8 @@ bool AArch64AsmParser::parseDirectiveArchExtension(SMLoc L) {
72717274
STI.ClearFeatureBitsTransitively(It->Features);
72727275
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
72737276
setAvailableFeatures(Features);
7277+
7278+
getTargetStreamer().emitDirectiveArchExtension(FullName);
72747279
return false;
72757280
}
72767281

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer {
5555
OS << "\t.variant_pcs\t" << Symbol->getName() << "\n";
5656
}
5757

58+
void emitDirectiveArch(StringRef Name) override {
59+
OS << "\t.arch\t" << Name << "\n";
60+
}
61+
62+
void emitDirectiveArchExtension(StringRef Name) override {
63+
OS << "\t.arch_extension\t" << Name << "\n";
64+
}
65+
5866
void emitARM64WinCFIAllocStack(unsigned Size) override {
5967
OS << "\t.seh_stackalloc\t" << Size << "\n";
6068
}

llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class AArch64TargetStreamer : public MCTargetStreamer {
5555
/// Callback used to implement the .variant_pcs directive.
5656
virtual void emitDirectiveVariantPCS(MCSymbol *Symbol) {};
5757

58+
virtual void emitDirectiveArch(StringRef Name) {};
59+
virtual void emitDirectiveArchExtension(StringRef Name) {};
60+
5861
virtual void emitARM64WinCFIAllocStack(unsigned Size) {}
5962
virtual void emitARM64WinCFISaveR19R20X(int Offset) {}
6063
virtual void emitARM64WinCFISaveFPLR(int Offset) {}

llvm/test/MC/AArch64/arch_directive.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# RUN: llvm-mc -assemble -triple=aarch64- %s | FileCheck %s
2+
# CHECK: .text
3+
# CHECK-NEXT: .arch armv8-a+lse
4+
# CHECK-NEXT: cas x0, x1, [x2]
5+
# CHECK-NEXT: .arch armv8-a
6+
# CHECK-NEXT: .arch_extension lse
7+
# CHECK-NEXT: cas x0, x1, [x2]
8+
# CHECK-NEXT: .arch_extension nolse
9+
.text
10+
.arch armv8-a+lse
11+
cas x0, x1, [x2]
12+
.arch armv8-a
13+
.arch_extension lse
14+
cas x0, x1, [x2]
15+
.arch_extension nolse

0 commit comments

Comments
 (0)