@@ -241,6 +241,14 @@ void llvm::AArch64PAuth::checkAuthenticatedRegister(
241
241
const AArch64InstrInfo *TII = Subtarget.getInstrInfo ();
242
242
DebugLoc DL = MBBI->getDebugLoc ();
243
243
244
+ // All terminator instructions should be grouped at the end of the machine
245
+ // basic block, with no non-terminator instructions between them. Depending on
246
+ // the method requested, we will insert some regular instructions, maybe
247
+ // followed by a conditional branch instruction, which is a terminator, before
248
+ // MBBI. Thus, MBBI is expected to be the first terminator of its MBB.
249
+ assert (MBBI->isTerminator () && MBBI == MBB.getFirstTerminator () &&
250
+ " MBBI should be the first terminator in MBB" );
251
+
244
252
// First, handle the methods not requiring creating extra MBBs.
245
253
switch (Method) {
246
254
default :
@@ -257,33 +265,24 @@ void llvm::AArch64PAuth::checkAuthenticatedRegister(
257
265
258
266
// Control flow has to be changed, so arrange new MBBs.
259
267
260
- // At now, at least an AUT* instruction is expected before MBBI
261
- assert (MBBI != MBB.begin () &&
262
- " Cannot insert the check at the very beginning of MBB" );
263
- // The block to insert check into.
264
- MachineBasicBlock *CheckBlock = &MBB;
265
- // The remaining part of the original MBB that is executed on success.
266
- MachineBasicBlock *SuccessBlock = MBB.splitAt (*std::prev (MBBI));
267
-
268
268
// The block that explicitly generates a break-point exception on failure.
269
269
MachineBasicBlock *BreakBlock =
270
270
MF.CreateMachineBasicBlock (MBB.getBasicBlock ());
271
271
MF.push_back (BreakBlock);
272
- MBB.splitSuccessor (SuccessBlock, BreakBlock);
272
+ MBB.addSuccessor ( BreakBlock);
273
273
274
- assert (CheckBlock->getFallThrough () == SuccessBlock);
275
274
BuildMI (BreakBlock, DL, TII->get (AArch64::BRK)).addImm (BrkImm);
276
275
277
276
switch (Method) {
278
277
case AuthCheckMethod::None:
279
278
case AuthCheckMethod::DummyLoad:
280
279
llvm_unreachable (" Should be handled above" );
281
280
case AuthCheckMethod::HighBitsNoTBI:
282
- BuildMI (CheckBlock , DL, TII->get (AArch64::EORXrs), TmpReg)
281
+ BuildMI (MBB, MBBI , DL, TII->get (AArch64::EORXrs), TmpReg)
283
282
.addReg (AuthenticatedReg)
284
283
.addReg (AuthenticatedReg)
285
284
.addImm (1 );
286
- BuildMI (CheckBlock , DL, TII->get (AArch64::TBNZX))
285
+ BuildMI (MBB, MBBI , DL, TII->get (AArch64::TBNZX))
287
286
.addReg (TmpReg)
288
287
.addImm (62 )
289
288
.addMBB (BreakBlock);
@@ -292,16 +291,16 @@ void llvm::AArch64PAuth::checkAuthenticatedRegister(
292
291
assert (AuthenticatedReg == AArch64::LR &&
293
292
" XPACHint mode is only compatible with checking the LR register" );
294
293
assert (UseIKey && " XPACHint mode is only compatible with I-keys" );
295
- BuildMI (CheckBlock , DL, TII->get (AArch64::ORRXrs), TmpReg)
294
+ BuildMI (MBB, MBBI , DL, TII->get (AArch64::ORRXrs), TmpReg)
296
295
.addReg (AArch64::XZR)
297
296
.addReg (AArch64::LR)
298
297
.addImm (0 );
299
- BuildMI (CheckBlock , DL, TII->get (AArch64::XPACLRI));
300
- BuildMI (CheckBlock , DL, TII->get (AArch64::SUBSXrs), AArch64::XZR)
298
+ BuildMI (MBB, MBBI , DL, TII->get (AArch64::XPACLRI));
299
+ BuildMI (MBB, MBBI , DL, TII->get (AArch64::SUBSXrs), AArch64::XZR)
301
300
.addReg (TmpReg)
302
301
.addReg (AArch64::LR)
303
302
.addImm (0 );
304
- BuildMI (CheckBlock , DL, TII->get (AArch64::Bcc))
303
+ BuildMI (MBB, MBBI , DL, TII->get (AArch64::Bcc))
305
304
.addImm (AArch64CC::NE)
306
305
.addMBB (BreakBlock);
307
306
return ;
0 commit comments