Skip to content

Commit 0503385

Browse files
committed
Address the comments
1 parent a246cfe commit 0503385

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

llvm/lib/Target/AArch64/AArch64SLSHardening.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace {
4040
// indexes in SLSBLRThunks array.
4141
typedef uint32_t ThunksSet;
4242

43-
struct SLSBLRThunkInserter : ThunkInserter<SLSBLRThunkInserter, ThunksSet> {
43+
struct SLSHardeningInserter : ThunkInserter<SLSHardeningInserter, ThunksSet> {
4444
public:
4545
const char *getThunkPrefix() { return SLSBLRNamePrefix; }
4646
bool mayUseThunk(const MachineFunction &MF) {
@@ -91,9 +91,9 @@ static void insertSpeculationBarrier(const AArch64Subtarget *ST,
9191
BuildMI(MBB, MBBI, DL, TII->get(BarrierOpc));
9292
}
9393

94-
ThunksSet SLSBLRThunkInserter::insertThunks(MachineModuleInfo &MMI,
95-
MachineFunction &MF,
96-
ThunksSet ExistingThunks) {
94+
ThunksSet SLSHardeningInserter::insertThunks(MachineModuleInfo &MMI,
95+
MachineFunction &MF,
96+
ThunksSet ExistingThunks) {
9797
const AArch64Subtarget *ST = &MF.getSubtarget<AArch64Subtarget>();
9898

9999
for (auto &MBB : MF) {
@@ -121,8 +121,8 @@ static bool isBLR(const MachineInstr &MI) {
121121
return false;
122122
}
123123

124-
bool SLSBLRThunkInserter::hardenReturnsAndBRs(MachineModuleInfo &MMI,
125-
MachineBasicBlock &MBB) {
124+
bool SLSHardeningInserter::hardenReturnsAndBRs(MachineModuleInfo &MMI,
125+
MachineBasicBlock &MBB) {
126126
const AArch64Subtarget *ST =
127127
&MBB.getParent()->getSubtarget<AArch64Subtarget>();
128128
bool Modified = false;
@@ -188,7 +188,7 @@ unsigned getThunkIndex(Register Reg) {
188188
llvm_unreachable("Unexpected register");
189189
}
190190

191-
void SLSBLRThunkInserter::populateThunk(MachineFunction &MF) {
191+
void SLSHardeningInserter::populateThunk(MachineFunction &MF) {
192192
// FIXME: How to better communicate Register number, rather than through
193193
// name and lookup table?
194194
assert(MF.getName().starts_with(getThunkPrefix()));
@@ -235,10 +235,9 @@ void SLSBLRThunkInserter::populateThunk(MachineFunction &MF) {
235235
Entry->end(), DebugLoc(), true /*AlwaysUseISBDSB*/);
236236
}
237237

238-
void SLSBLRThunkInserter::convertBLRToBL(MachineModuleInfo &MMI,
239-
MachineBasicBlock &MBB,
240-
MachineBasicBlock::instr_iterator MBBI,
241-
ThunksSet &Thunks) {
238+
void SLSHardeningInserter::convertBLRToBL(
239+
MachineModuleInfo &MMI, MachineBasicBlock &MBB,
240+
MachineBasicBlock::instr_iterator MBBI, ThunksSet &Thunks) {
242241
// Transform a BLR to a BL as follows:
243242
// Before:
244243
// |-----------------------------|
@@ -264,7 +263,6 @@ void SLSBLRThunkInserter::convertBLRToBL(MachineModuleInfo &MMI,
264263
// | barrierInsts |
265264
// |-----------------------------|
266265
//
267-
// The __llvm_slsblr_thunk_xN thunks are created by the SLSBLRThunkInserter.
268266
// This function merely needs to transform BLR xN into BL
269267
// __llvm_slsblr_thunk_xN.
270268
//
@@ -346,9 +344,9 @@ void SLSBLRThunkInserter::convertBLRToBL(MachineModuleInfo &MMI,
346344
MBB.erase(MBBI);
347345
}
348346

349-
bool SLSBLRThunkInserter::hardenBLRs(MachineModuleInfo &MMI,
350-
MachineBasicBlock &MBB,
351-
ThunksSet &Thunks) {
347+
bool SLSHardeningInserter::hardenBLRs(MachineModuleInfo &MMI,
348+
MachineBasicBlock &MBB,
349+
ThunksSet &Thunks) {
352350
bool Modified = false;
353351
MachineBasicBlock::instr_iterator MBBI = MBB.instr_begin(),
354352
E = MBB.instr_end();
@@ -365,7 +363,7 @@ bool SLSBLRThunkInserter::hardenBLRs(MachineModuleInfo &MMI,
365363
}
366364

367365
namespace {
368-
class AArch64SLSHardening : public ThunkInserterPass<SLSBLRThunkInserter> {
366+
class AArch64SLSHardening : public ThunkInserterPass<SLSHardeningInserter> {
369367
public:
370368
static char ID;
371369

llvm/test/CodeGen/AArch64/speculation-hardening-sls-blr.mir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# RUN: -stop-after aarch64-sls-hardening -o - %s \
44
# RUN: | FileCheck %s --check-prefixes=CHECK \
55
# RUN: --implicit-check-not=__llvm_slsblr_thunk_x7
6+
# RUN: llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu \
7+
# RUN: -start-before aarch64-sls-hardening \
8+
# RUN: -asm-verbose=0 -o - %s \
9+
# RUN: | FileCheck %s --check-prefixes=ASM \
10+
# RUN: --implicit-check-not=__llvm_slsblr_thunk_x7
611

712
# Check that the BLR SLS hardening transforms a BLR into a BL with operands as
813
# expected.
@@ -42,3 +47,13 @@ body: |
4247
...
4348

4449
# CHECK: name: __llvm_slsblr_thunk_x8
50+
#
51+
# CHECK: $x16 = ORRXrs $xzr, $x8, 0
52+
# CHECK-NEXT: BR $x16
53+
# CHECK-NEXT: SpeculationBarrierISBDSBEndBB
54+
55+
# ASM-LABEL: __llvm_slsblr_thunk_x8:
56+
# ASM-NEXT: mov x16, x8
57+
# ASM-NEXT: br x16
58+
# ASM-NEXT: dsb sy
59+
# ASM-NEXT: isb

0 commit comments

Comments
 (0)