From 5e60bcdeafdc15ba979aa42897f32dd2439757f4 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Sat, 27 Aug 2016 02:38:21 +0000 Subject: [PATCH] [MachineLegalize] Do not abort when the target wants to fall back. llvm-svn: 279904 --- .../llvm/CodeGen/GlobalISel/MachineLegalizePass.h | 2 ++ .../CodeGen/GlobalISel/MachineLegalizeHelper.cpp | 8 ++++++-- .../lib/CodeGen/GlobalISel/MachineLegalizePass.cpp | 24 ++++++++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineLegalizePass.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineLegalizePass.h index 5863913..ccdc05a 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/MachineLegalizePass.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineLegalizePass.h @@ -43,6 +43,8 @@ public: return "MachineLegalizePass"; } + void getAnalysisUsage(AnalysisUsage &AU) const override; + MachineFunctionProperties getRequiredProperties() const override { return MachineFunctionProperties().set( MachineFunctionProperties::Property::IsSSA); diff --git a/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp b/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp index 2ed76ee..b6ec2b8 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp @@ -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; diff --git a/llvm/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp b/llvm/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp index 33d050b..ba56eb0 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineLegalizePass.cpp @@ -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(); + 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(); 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: "; -- 2.7.4