Skip to content

Commit 7a38618

Browse files
[AArch64] Allow BTI mnemonics in the HINT space with BTI disabled
Summary: It is important to emit HINT instructions instead of BTI ones when BTI is disabled. This allows compatibility with other assemblers (e.g. GAS). Still, developers of assembly code will want to write code that is compatible with both pre- and post-BTI CPUs. They could use HINT mnemonics, but the new mnemonics are a lot more readable (e.g. bti c instead of hint rust-lang#34), and they will result in the same encodings. So, while LLVM should not *emit* the new mnemonics when BTI is disabled, this patch will at least make LLVM *accept* assembly code that uses them. Reviewers: pbarrio, tamas.petz, ostannard Reviewed By: pbarrio, ostannard Subscribers: ostannard, kristof.beyls, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D81257
1 parent cb2d8b3 commit 7a38618

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

+6
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,12 @@ def : InstAlias<"sevl", (HINT 0b101)>;
726726
def : InstAlias<"dgh", (HINT 0b110)>;
727727
def : InstAlias<"esb", (HINT 0b10000)>, Requires<[HasRAS]>;
728728
def : InstAlias<"csdb", (HINT 20)>;
729+
// In order to be able to write readable assembly, LLVM should accept assembly
730+
// inputs that use Branch Target Indentification mnemonics, even with BTI disabled.
731+
// However, in order to be compatible with other assemblers (e.g. GAS), LLVM
732+
// should not emit these mnemonics unless BTI is enabled.
733+
def : InstAlias<"bti", (HINT 32), 0>;
734+
def : InstAlias<"bti $op", (HINT btihint_op:$op), 0>;
729735
def : InstAlias<"bti", (HINT 32)>, Requires<[HasBTI]>;
730736
def : InstAlias<"bti $op", (HINT btihint_op:$op)>, Requires<[HasBTI]>;
731737

llvm/test/MC/AArch64/armv8.5a-bti.s

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=+bti < %s | FileCheck %s
2-
// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=+v8.5a < %s | FileCheck %s
3-
// RUN: not llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=-bti < %s 2>&1 | FileCheck %s --check-prefix=NOBTI
1+
// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=+bti < %s | FileCheck %s
2+
// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=+v8.5a < %s | FileCheck %s
3+
// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding -mattr=-bti < %s | FileCheck %s --check-prefix=NOBTI
44

55
bti
66
bti c
@@ -12,14 +12,10 @@ bti jc
1212
// CHECK: bti j // encoding: [0x9f,0x24,0x03,0xd5]
1313
// CHECK: bti jc // encoding: [0xdf,0x24,0x03,0xd5]
1414

15-
// NOBTI: instruction requires: bti
16-
// NOBTI-NEXT: bti
17-
// NOBTI: instruction requires: bti
18-
// NOBTI-NEXT: bti
19-
// NOBTI: instruction requires: bti
20-
// NOBTI-NEXT: bti
21-
// NOBTI: instruction requires: bti
22-
// NOBTI-NEXT: bti
15+
// NOBTI: hint #32 // encoding: [0x1f,0x24,0x03,0xd5]
16+
// NOBTI: hint #34 // encoding: [0x5f,0x24,0x03,0xd5]
17+
// NOBTI: hint #36 // encoding: [0x9f,0x24,0x03,0xd5]
18+
// NOBTI: hint #38 // encoding: [0xdf,0x24,0x03,0xd5]
2319

2420
hint #32
2521
hint #34

0 commit comments

Comments
 (0)