[llvm] r279904 - [MachineLegalize] 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:21 PDT 2016


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

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

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

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

Modified: llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp?rev=279904&r1=279903&r2=279904&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp Fri Aug 26 21:38:21 2016
@@ -92,7 +92,9 @@ void MachineLegalizeHelper::extractParts
 MachineLegalizeHelper::LegalizeResult
 MachineLegalizeHelper::narrowScalar(MachineInstr &MI, unsigned TypeIdx,
                                     LLT NarrowTy) {
-  assert(TypeIdx == 0 && "don't know how to handle secondary types yet");
+  // FIXME: Don't know how to handle secondary types yet.
+  if (TypeIdx != 0)
+    return UnableToLegalize;
   switch (MI.getOpcode()) {
   default:
     return UnableToLegalize;
@@ -290,7 +292,9 @@ MachineLegalizeHelper::lower(MachineInst
 MachineLegalizeHelper::LegalizeResult
 MachineLegalizeHelper::fewerElementsVector(MachineInstr &MI, unsigned TypeIdx,
                                            LLT NarrowTy) {
-  assert(TypeIdx == 0 && "don't know how to handle secondary types yet");
+  // FIXME: Don't know how to handle secondary types yet.
+  if (TypeIdx != 0)
+    return UnableToLegalize;
   switch (MI.getOpcode()) {
   default:
     return UnableToLegalize;

Modified: llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp?rev=279904&r1=279903&r2=279904&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp Fri Aug 26 21:38:21 2016
@@ -14,9 +14,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/GlobalISel/MachineLegalizePass.h"
-#include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/GlobalISel/MachineLegalizeHelper.h"
 #include "llvm/CodeGen/GlobalISel/MachineLegalizer.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Target/TargetSubtargetInfo.h"
 
@@ -25,14 +26,23 @@
 using namespace llvm;
 
 char MachineLegalizePass::ID = 0;
-INITIALIZE_PASS(MachineLegalizePass, DEBUG_TYPE,
-                "Legalize the Machine IR a function's Machine IR", false,
-                false)
+INITIALIZE_PASS_BEGIN(MachineLegalizePass, DEBUG_TYPE,
+                      "Legalize the Machine IR a function's Machine IR", false,
+                      false)
+INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
+INITIALIZE_PASS_END(MachineLegalizePass, DEBUG_TYPE,
+                    "Legalize the Machine IR a function's Machine IR", false,
+                    false)
 
 MachineLegalizePass::MachineLegalizePass() : MachineFunctionPass(ID) {
   initializeMachineLegalizePassPass(*PassRegistry::getPassRegistry());
 }
 
+void MachineLegalizePass::getAnalysisUsage(AnalysisUsage &AU) const {
+  AU.addRequired<TargetPassConfig>();
+  MachineFunctionPass::getAnalysisUsage(AU);
+}
+
 void MachineLegalizePass::init(MachineFunction &MF) {
 }
 
@@ -43,6 +53,7 @@ bool MachineLegalizePass::runOnMachineFu
     return false;
   DEBUG(dbgs() << "Legalize Machine IR for: " << MF.getName() << '\n');
   init(MF);
+  const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
   const MachineLegalizer &Legalizer = *MF.getSubtarget().getMachineLegalizer();
   MachineLegalizeHelper Helper(MF);
 
@@ -69,6 +80,11 @@ bool MachineLegalizePass::runOnMachineFu
       // Error out if we couldn't legalize this instruction. We may want to fall
       // back to DAG ISel instead in the future.
       if (Res == MachineLegalizeHelper::UnableToLegalize) {
+        if (!TPC.isGlobalISelAbortEnabled()) {
+          MF.getProperties().set(
+              MachineFunctionProperties::Property::FailedISel);
+          return false;
+        }
         std::string Msg;
         raw_string_ostream OS(Msg);
         OS << "unable to legalize instruction: ";




More information about the llvm-commits mailing list