[llvm] r279905 - [InstructionSelect] Do not abort when the target wants to fall back.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 26 19:38:24 PDT 2016


Author: qcolombet
Date: Fri Aug 26 21:38:24 2016
New Revision: 279905

URL: http://llvm.org/viewvc/llvm-project?rev=279905&view=rev
Log:
[InstructionSelect] Do not abort when the target wants to fall back.

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelect.h
    llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelect.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelect.h?rev=279905&r1=279904&r2=279905&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelect.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelect.h Fri Aug 26 21:38:24 2016
@@ -30,6 +30,8 @@ public:
   static char ID;
   const char *getPassName() const override { return "InstructionSelect"; }
 
+  void getAnalysisUsage(AnalysisUsage &AU) const override;
+
   MachineFunctionProperties getRequiredProperties() const override {
     return MachineFunctionProperties()
         .set(MachineFunctionProperties::Property::IsSSA)

Modified: llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp?rev=279905&r1=279904&r2=279905&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp Fri Aug 26 21:38:24 2016
@@ -16,6 +16,7 @@
 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
 #include "llvm/CodeGen/GlobalISel/MachineLegalizer.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/Function.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -26,14 +27,23 @@
 using namespace llvm;
 
 char InstructionSelect::ID = 0;
-INITIALIZE_PASS(InstructionSelect, DEBUG_TYPE,
-                "Select target instructions out of generic instructions",
-                false, false);
+INITIALIZE_PASS_BEGIN(InstructionSelect, DEBUG_TYPE,
+                      "Select target instructions out of generic instructions",
+                      false, false)
+INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
+INITIALIZE_PASS_END(InstructionSelect, DEBUG_TYPE,
+                    "Select target instructions out of generic instructions",
+                    false, false)
 
 InstructionSelect::InstructionSelect() : MachineFunctionPass(ID) {
   initializeInstructionSelectPass(*PassRegistry::getPassRegistry());
 }
 
+void InstructionSelect::getAnalysisUsage(AnalysisUsage &AU) const {
+  AU.addRequired<TargetPassConfig>();
+  MachineFunctionPass::getAnalysisUsage(AU);
+}
+
 static void reportSelectionError(const MachineInstr &MI, const Twine &Message) {
   const MachineFunction &MF = *MI.getParent()->getParent();
   std::string ErrStorage;
@@ -50,6 +60,7 @@ bool InstructionSelect::runOnMachineFunc
 
   DEBUG(dbgs() << "Selecting function: " << MF.getName() << '\n');
 
+  const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
   const InstructionSelector *ISel = MF.getSubtarget().getInstructionSelector();
   assert(ISel && "Cannot work without InstructionSelector");
 
@@ -75,19 +86,29 @@ bool InstructionSelect::runOnMachineFunc
   const size_t NumBlocks = MF.size();
 #endif
 
+  bool Failed = false;
   for (MachineBasicBlock *MBB : post_order(&MF)) {
     for (MachineBasicBlock::reverse_iterator MII = MBB->rbegin(),
                                              End = MBB->rend();
          MII != End;) {
       MachineInstr &MI = *MII++;
       DEBUG(dbgs() << "Selecting: " << MI << '\n');
-      if (!ISel->select(MI))
-        reportSelectionError(MI, "Cannot select");
-      // FIXME: It would be nice to dump all inserted instructions.  It's not
-      // obvious how, esp. considering select() can insert after MI.
+      if (!ISel->select(MI)) {
+        if (TPC.isGlobalISelAbortEnabled())
+          // FIXME: It would be nice to dump all inserted instructions.  It's
+          // not
+          // obvious how, esp. considering select() can insert after MI.
+          reportSelectionError(MI, "Cannot select");
+        Failed = true;
+        break;
+      }
     }
   }
 
+  if (!TPC.isGlobalISelAbortEnabled() && (Failed || MF.size() == NumBlocks)) {
+    MF.getProperties().set(MachineFunctionProperties::Property::FailedISel);
+    return false;
+  }
   assert(MF.size() == NumBlocks && "Inserting blocks is not supported yet");
 
   // Now that selection is complete, there are no more generic vregs.




More information about the llvm-commits mailing list