[llvm] r238292 - [ShrinkWrap] Add a target hook to check whether or not

Quentin Colombet qcolombet at apple.com
Tue May 26 23:25:48 PDT 2015


Author: qcolombet
Date: Wed May 27 01:25:48 2015
New Revision: 238292

URL: http://llvm.org/viewvc/llvm-project?rev=238292&view=rev
Log:
[ShrinkWrap] Add a target hook to check whether or not
the target can handle a given basic block as prologue
or epilogue.

Related to <rdar://problem/20821487>

Modified:
    llvm/trunk/include/llvm/Target/TargetFrameLowering.h
    llvm/trunk/lib/CodeGen/ShrinkWrap.cpp

Modified: llvm/trunk/include/llvm/Target/TargetFrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetFrameLowering.h?rev=238292&r1=238291&r2=238292&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetFrameLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetFrameLowering.h Wed May 27 01:25:48 2015
@@ -257,6 +257,30 @@ public:
     llvm_unreachable("Call Frame Pseudo Instructions do not exist on this "
                      "target!");
   }
+
+  /// Check whether or not the given \p MBB can be used as a prologue
+  /// for the target.
+  /// The prologue will be inserted first in this basic block.
+  /// This method is used by the shrink-wrapping pass to decide if
+  /// \p MBB will be correctly handled by the target.
+  /// As soon as the target enable shrink-wrapping without overriding
+  /// this method, we assume that each basic block is a valid
+  /// prologue.
+  virtual bool canUseAsPrologue(const MachineBasicBlock &MBB) const {
+    return true;
+  }
+
+  /// Check whether or not the given \p MBB can be used as a epilogue
+  /// for the target.
+  /// The epilogue will be inserted before the first terminator of that block.
+  /// This method is used by the shrink-wrapping pass to decide if
+  /// \p MBB will be correctly handled by the target.
+  /// As soon as the target enable shrink-wrapping without overriding
+  /// this method, we assume that each basic block is a valid
+  /// epilogue.
+  virtual bool canUseAsEpilogue(const MachineBasicBlock &MBB) const {
+    return true;
+  }
 };
 
 } // End llvm namespace

Modified: llvm/trunk/lib/CodeGen/ShrinkWrap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ShrinkWrap.cpp?rev=238292&r1=238291&r2=238292&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ShrinkWrap.cpp (original)
+++ llvm/trunk/lib/CodeGen/ShrinkWrap.cpp Wed May 27 01:25:48 2015
@@ -62,6 +62,8 @@
 // To know about callee-saved.
 #include "llvm/CodeGen/RegisterClassInfo.h"
 #include "llvm/Support/Debug.h"
+// To query the target about frame lowering.
+#include "llvm/Target/TargetFrameLowering.h"
 // To know about frame setup operation.
 #include "llvm/Target/TargetInstrInfo.h"
 // To access TargetInstrInfo.
@@ -338,6 +340,7 @@ bool ShrinkWrap::runOnMachineFunction(Ma
   DEBUG(dbgs() << "\n ** Results **\nFrequency of the Entry: " << EntryFreq
                << '\n');
 
+  const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
   do {
     DEBUG(dbgs() << "Shrink wrap candidates (#, Name, Freq):\nSave: "
                  << Save->getNumber() << ' ' << Save->getName() << ' '
@@ -345,13 +348,15 @@ bool ShrinkWrap::runOnMachineFunction(Ma
                  << Restore->getNumber() << ' ' << Restore->getName() << ' '
                  << MBFI->getBlockFreq(Restore).getFrequency() << '\n');
 
-    bool IsSaveCheap;
-    if ((IsSaveCheap = EntryFreq >= MBFI->getBlockFreq(Save).getFrequency()) &&
-        EntryFreq >= MBFI->getBlockFreq(Restore).getFrequency())
+    bool IsSaveCheap, TargetCanUseSaveAsPrologue = false;
+    if (((IsSaveCheap = EntryFreq >= MBFI->getBlockFreq(Save).getFrequency()) &&
+         EntryFreq >= MBFI->getBlockFreq(Restore).getFrequency()) &&
+        ((TargetCanUseSaveAsPrologue = TFI->canUseAsPrologue(*Save)) &&
+         TFI->canUseAsEpilogue(*Restore)))
       break;
-    DEBUG(dbgs() << "New points are too expensive\n");
+    DEBUG(dbgs() << "New points are too expensive or invalid for the target\n");
     MachineBasicBlock *NewBB;
-    if (!IsSaveCheap) {
+    if (!IsSaveCheap || !TargetCanUseSaveAsPrologue) {
       Save = FindIDom<>(*Save, Save->predecessors(), *MDT);
       if (!Save)
         break;





More information about the llvm-commits mailing list