@@ -268,6 +268,47 @@ INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
268
268
INITIALIZE_PASS_END(MachineSinking, DEBUG_TYPE,
269
269
" Machine code sinking" , false , false )
270
270
271
+ // / Return true if a target defined block prologue instruction interferes
272
+ // / with a sink candidate.
273
+ static bool blockPrologueInterferes(const MachineBasicBlock *BB,
274
+ MachineBasicBlock::const_iterator End,
275
+ const MachineInstr &MI,
276
+ const TargetRegisterInfo *TRI,
277
+ const TargetInstrInfo *TII,
278
+ const MachineRegisterInfo *MRI) {
279
+ if (BB->begin () == End)
280
+ return false ; // no prologue
281
+ for (MachineBasicBlock::const_iterator PI = BB->getFirstNonPHI (); PI != End;
282
+ ++PI) {
283
+ // Only check target defined prologue instructions
284
+ if (!TII->isBasicBlockPrologue (*PI))
285
+ continue ;
286
+ for (auto &MO : MI.operands ()) {
287
+ if (!MO.isReg ())
288
+ continue ;
289
+ Register Reg = MO.getReg ();
290
+ if (!Reg)
291
+ continue ;
292
+ if (MO.isUse ()) {
293
+ if (Reg.isPhysical () &&
294
+ (TII->isIgnorableUse (MO) || (MRI && MRI->isConstantPhysReg (Reg))))
295
+ continue ;
296
+ if (PI->modifiesRegister (Reg, TRI))
297
+ return true ;
298
+ } else {
299
+ if (PI->readsRegister (Reg, TRI))
300
+ return true ;
301
+ // Check for interference with non-dead defs
302
+ auto *DefOp = PI->findRegisterDefOperand (Reg, false , true , TRI);
303
+ if (DefOp && !DefOp->isDead ())
304
+ return true ;
305
+ }
306
+ }
307
+ }
308
+
309
+ return false ;
310
+ }
311
+
271
312
bool MachineSinking::PerformTrivialForwardCoalescing (MachineInstr &MI,
272
313
MachineBasicBlock *MBB) {
273
314
if (!MI.isCopy ())
@@ -1298,45 +1339,6 @@ bool MachineSinking::SinkIntoCycle(MachineCycle *Cycle, MachineInstr &I) {
1298
1339
return true ;
1299
1340
}
1300
1341
1301
- // / Return true if a target defined block prologue instruction interferes
1302
- // / with a sink candidate.
1303
- static bool blockPrologueInterferes (MachineBasicBlock *BB,
1304
- MachineBasicBlock::iterator End,
1305
- MachineInstr &MI,
1306
- const TargetRegisterInfo *TRI,
1307
- const TargetInstrInfo *TII,
1308
- const MachineRegisterInfo *MRI) {
1309
- if (BB->begin () == End)
1310
- return false ; // no prologue
1311
- for (MachineBasicBlock::iterator PI = BB->getFirstNonPHI (); PI != End; ++PI) {
1312
- // Only check target defined prologue instructions
1313
- if (!TII->isBasicBlockPrologue (*PI))
1314
- continue ;
1315
- for (auto &MO : MI.operands ()) {
1316
- if (!MO.isReg ())
1317
- continue ;
1318
- Register Reg = MO.getReg ();
1319
- if (!Reg)
1320
- continue ;
1321
- if (MO.isUse ()) {
1322
- if (Reg.isPhysical () &&
1323
- (TII->isIgnorableUse (MO) || (MRI && MRI->isConstantPhysReg (Reg))))
1324
- continue ;
1325
- if (PI->modifiesRegister (Reg, TRI))
1326
- return true ;
1327
- } else {
1328
- if (PI->readsRegister (Reg, TRI))
1329
- return true ;
1330
- // Check for interference with non-dead defs
1331
- auto *DefOp = PI->findRegisterDefOperand (Reg, false , true , TRI);
1332
- if (DefOp && !DefOp->isDead ())
1333
- return true ;
1334
- }
1335
- }
1336
- }
1337
- return false ;
1338
- }
1339
-
1340
1342
// / SinkInstruction - Determine whether it is safe to sink the specified machine
1341
1343
// / instruction out of its current block into a successor.
1342
1344
bool MachineSinking::SinkInstruction (MachineInstr &MI, bool &SawStore,
0 commit comments