[llvm] r346721 - [MachineOutliner][NFC] Simplify isMBBSafeToOutlineFrom check in AArch64 outliner

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 12 16:32:09 PST 2018


Author: paquette
Date: Mon Nov 12 16:32:09 2018
New Revision: 346721

URL: http://llvm.org/viewvc/llvm-project?rev=346721&view=rev
Log:
[MachineOutliner][NFC] Simplify isMBBSafeToOutlineFrom check in AArch64 outliner

Turns out it's way simpler to do this check with one LRU. Instead of
maintaining two, just keep one. Check if each of the registers is available,
and then check if it's a live out from the block. If it's a live out, but
available in the block, we know we're in an unsafe case.

Modified:
    llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp

Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp?rev=346721&r1=346720&r2=346721&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp Mon Nov 12 16:32:09 2018
@@ -5292,26 +5292,26 @@ bool AArch64InstrInfo::isMBBSafeToOutlin
   // a flag.
   assert(MBB.getParent()->getRegInfo().tracksLiveness() &&
          "Suitable Machine Function for outlining must track liveness");
-  LiveRegUnits ModifiedRegUnits(getRegisterInfo());
-  LiveRegUnits UsedRegUnits(getRegisterInfo());
-  ModifiedRegUnits.addLiveOuts(MBB);
-  UsedRegUnits.addLiveOuts(MBB);
-  const TargetRegisterInfo *TRI = &getRegisterInfo();
+  LiveRegUnits LRU(getRegisterInfo());
 
   std::for_each(MBB.rbegin(), MBB.rend(),
-                [&ModifiedRegUnits, &UsedRegUnits, &TRI](MachineInstr &MI) {
-                  LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits,
-                                                    UsedRegUnits, TRI);
-                });
-
-  // If one of these registers is live out of the MBB, but not modified in the
-  // MBB, then we can't outline.
-  if ((ModifiedRegUnits.available(AArch64::W16) &&
-       !UsedRegUnits.available(AArch64::W16)) ||
-      (ModifiedRegUnits.available(AArch64::W17) &&
-       !UsedRegUnits.available(AArch64::W17)) ||
-      (ModifiedRegUnits.available(AArch64::NZCV) &&
-       !UsedRegUnits.available(AArch64::NZCV)))
+                [&LRU](MachineInstr &MI) { LRU.accumulate(MI); });
+
+  // Check if each of the unsafe registers are available...
+  bool W16AvailableInBlock = LRU.available(AArch64::W16);
+  bool W17AvailableInBlock = LRU.available(AArch64::W17);
+  bool NZCVAvailableInBlock = LRU.available(AArch64::NZCV);
+
+  // Now, add the live outs to the set.
+  LRU.addLiveOuts(MBB);
+
+  // If any of these registers is available in the MBB, but also a live out of
+  // the block, then we know outlining is unsafe.
+  if (W16AvailableInBlock && !LRU.available(AArch64::W16))
+    return false;
+  if (W17AvailableInBlock && !LRU.available(AArch64::W17))
+    return false;
+  if (NZCVAvailableInBlock && !LRU.available(AArch64::NZCV))
     return false;
 
   // Check if there's a call inside this MachineBasicBlock. If there is, then
@@ -5319,8 +5319,7 @@ bool AArch64InstrInfo::isMBBSafeToOutlin
   if (any_of(MBB, [](MachineInstr &MI) { return MI.isCall(); }))
     Flags |= MachineOutlinerMBBFlags::HasCalls;
 
-  if (!ModifiedRegUnits.available(AArch64::LR) ||
-      !UsedRegUnits.available(AArch64::LR))
+  if (!LRU.available(AArch64::LR))
     Flags |= MachineOutlinerMBBFlags::LRUnavailableSomewhere;
 
   return true;




More information about the llvm-commits mailing list