-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[AArch64] Emit .arch and .arch_extension during assembly to textual asm #138433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When assembling to text, this patch ensures that .arch and .arch_extension directives are preserved in the output. This prevents errors related to unavailable extensions in the assembly output.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mc @llvm/pr-subscribers-backend-aarch64 Author: Zachary Yedidia (zyedidia) ChangesThis patch ensures that when assembling to text ( Fixes #117221. Full diff: https://github.com/llvm/llvm-project/pull/138433.diff 4 Files Affected:
diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index 28b4cbb5efed8..87c7923101e7d 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -7152,9 +7152,9 @@ static SMLoc incrementLoc(SMLoc L, int Offset) {
bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
SMLoc CurLoc = getLoc();
+ StringRef Name = getParser().parseStringToEndOfStatement().trim();
StringRef Arch, ExtensionString;
- std::tie(Arch, ExtensionString) =
- getParser().parseStringToEndOfStatement().trim().split('+');
+ std::tie(Arch, ExtensionString) = Name.split('+');
const AArch64::ArchInfo *ArchInfo = AArch64::parseArch(Arch);
if (!ArchInfo)
@@ -7201,6 +7201,8 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
}
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
setAvailableFeatures(Features);
+
+ getTargetStreamer().emitDirectiveArch(Name);
return false;
}
@@ -7234,6 +7236,8 @@ bool AArch64AsmParser::parseDirectiveArchExtension(SMLoc L) {
STI.ClearFeatureBitsTransitively(It->Features);
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
setAvailableFeatures(Features);
+
+ getTargetStreamer().emitDirectiveArchExtension(Name);
return false;
}
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
index b12a12436db81..411a9da5e4362 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
@@ -55,6 +55,14 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer {
OS << "\t.variant_pcs\t" << Symbol->getName() << "\n";
}
+ void emitDirectiveArch(StringRef Name) override {
+ OS << "\t.arch\t" << Name << "\n";
+ }
+
+ void emitDirectiveArchExtension(StringRef Name) override {
+ OS << "\t.arch_extension\t" << Name << "\n";
+ }
+
void emitARM64WinCFIAllocStack(unsigned Size) override {
OS << "\t.seh_stackalloc\t" << Size << "\n";
}
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h
index 43e099f919999..d0f857243fed1 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h
@@ -55,6 +55,9 @@ class AArch64TargetStreamer : public MCTargetStreamer {
/// Callback used to implement the .variant_pcs directive.
virtual void emitDirectiveVariantPCS(MCSymbol *Symbol) {};
+ virtual void emitDirectiveArch(StringRef Name) {};
+ virtual void emitDirectiveArchExtension(StringRef Name) {};
+
virtual void emitARM64WinCFIAllocStack(unsigned Size) {}
virtual void emitARM64WinCFISaveR19R20X(int Offset) {}
virtual void emitARM64WinCFISaveFPLR(int Offset) {}
diff --git a/llvm/test/MC/AArch64/arch_directive.s b/llvm/test/MC/AArch64/arch_directive.s
new file mode 100644
index 0000000000000..dd4edf43924b9
--- /dev/null
+++ b/llvm/test/MC/AArch64/arch_directive.s
@@ -0,0 +1,13 @@
+# RUN: llvm-mc -assemble -triple=aarch64- %s | FileCheck %s
+# CHECK: .text
+# CHECK-NEXT: .arch armv8-a+lse
+# CHECK-NEXT: cas x0, x1, [x2]
+# CHECK-NEXT: .arch armv8-a
+# CHECK-NEXT: .arch_extension lse
+# CHECK-NEXT: cas x0, x1, [x2]
+.text
+.arch armv8-a+lse
+cas x0, x1, [x2]
+.arch armv8-a
+.arch_extension lse
+cas x0, x1, [x2]
|
@@ -7234,6 +7236,8 @@ bool AArch64AsmParser::parseDirectiveArchExtension(SMLoc L) { | |||
STI.ClearFeatureBitsTransitively(It->Features); | |||
FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits()); | |||
setAvailableFeatures(Features); | |||
|
|||
getTargetStreamer().emitDirectiveArchExtension(Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, as Name
might have been updated on (new) line 7222. This would be clear with a .arch_extension nolse
test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching that. I have updated the code so that it emits the full name from before the no
prefix is stripped, along with a test. Let me know if you'd like further changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please wait for one of the tagged reviewers to also chime in, they're all at Arm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too.
I guess this can in theory affect ARM as well, although the .arch+ is likely not well supported in ARM either.
@zyedidia Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…sm (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.
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 #117221 for an example).Fixes #117221.