[MachineLegalize] Do not abort when the target wants to fall back.
authorQuentin Colombet <qcolombet@apple.com>
Sat, 27 Aug 2016 02:38:21 +0000 (02:38 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Sat, 27 Aug 2016 02:38:21 +0000 (02:38 +0000)
llvm-svn: 279904

llvm/include/llvm/CodeGen/GlobalISel/MachineLegalizePass.h
llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
llvm/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp

index 5863913..ccdc05a 100644 (file)
@@ -43,6 +43,8 @@ public:
     return "MachineLegalizePass";
   }
 
+  void getAnalysisUsage(AnalysisUsage &AU) const override;
+
   MachineFunctionProperties getRequiredProperties() const override {
     return MachineFunctionProperties().set(
         MachineFunctionProperties::Property::IsSSA);
index 2ed76ee..b6ec2b8 100644 (file)
@@ -92,7 +92,9 @@ void MachineLegalizeHelper::extractParts(unsigned Reg, LLT Ty, int NumParts,
 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(MachineInstr &MI, unsigned TypeIdx, LLT Ty) {
 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;
index 33d050b..ba56eb0 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #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"
 
 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::runOnMachineFunction(MachineFunction &MF) {
     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::runOnMachineFunction(MachineFunction &MF) {
       // 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: ";