diff --git a/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h b/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h index 569407963695e..483afb426fa10 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h @@ -35,9 +35,6 @@ class LLVM_ABI InstructionSelector : public GIMatchTableExecutor { /// !isPreISelGenericOpcode(I.getOpcode()) virtual bool select(MachineInstr &I) = 0; - // FIXME: Eliminate dependency on TargetPassConfig for NewPM transition - const TargetPassConfig *TPC = nullptr; - MachineOptimizationRemarkEmitter *MORE = nullptr; /// Note: InstructionSelect does not track changed instructions. diff --git a/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h b/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h index 076c70d21bbdf..6fd7e6b882d35 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h @@ -511,7 +511,7 @@ class RegBankSelect : public MachineFunctionPass { Mode OptMode; /// Current target configuration. Controls how the pass handles errors. - const TargetPassConfig *TPC; + bool GlobalISelAbortNotEnabled; /// Assign the register bank of each operand of \p MI. /// \return True on success, false otherwise. diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h index e1aa8eceefd3f..952be33fa6c13 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h @@ -152,15 +152,15 @@ LLVM_ABI bool canReplaceReg(Register DstReg, Register SrcReg, LLVM_ABI bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI); +LLVM_ABI bool isGlobalISelAbortEnabled(MachineFunction &MF); + /// Report an ISel error as a missed optimization remark to the LLVMContext's /// diagnostic stream. Set the FailedISel MachineFunction property. LLVM_ABI void reportGISelFailure(MachineFunction &MF, - const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R); LLVM_ABI void reportGISelFailure(MachineFunction &MF, - const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, const char *PassName, StringRef Msg, const MachineInstr &MI); @@ -168,7 +168,6 @@ LLVM_ABI void reportGISelFailure(MachineFunction &MF, /// Report an ISel warning as a missed optimization remark to the LLVMContext's /// diagnostic stream. LLVM_ABI void reportGISelWarning(MachineFunction &MF, - const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R); diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index e0665d99a891d..4ee47825156d3 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -111,17 +111,16 @@ INITIALIZE_PASS_END(IRTranslator, DEBUG_TYPE, "IRTranslator LLVM IR -> MI", false, false) static void reportTranslationError(MachineFunction &MF, - const TargetPassConfig &TPC, OptimizationRemarkEmitter &ORE, OptimizationRemarkMissed &R) { MF.getProperties().setFailedISel(); // Print the function name explicitly if we don't have a debug location (which // makes the diagnostic less useful) or if we're going to emit a raw error. - if (!R.getLocation().isValid() || TPC.isGlobalISelAbortEnabled()) + if (!R.getLocation().isValid() || isGlobalISelAbortEnabled(MF)) R << (" (in function: " + MF.getName() + ")").str(); - if (TPC.isGlobalISelAbortEnabled()) + if (isGlobalISelAbortEnabled(MF)) report_fatal_error(Twine(R.getMsg())); else ORE.emit(R); @@ -242,7 +241,7 @@ ArrayRef IRTranslator::getOrCreateVRegs(const Value &Val) { MF->getFunction().getSubprogram(), &MF->getFunction().getEntryBlock()); R << "unable to translate constant: " << ore::NV("Type", Val.getType()); - reportTranslationError(*MF, *TPC, *ORE, R); + reportTranslationError(*MF, *ORE, R); return *VRegs; } } @@ -279,7 +278,7 @@ Align IRTranslator::getMemOpAlign(const Instruction &I) { OptimizationRemarkMissed R("gisel-irtranslator", "", &I); R << "unable to translate memop: " << ore::NV("Opcode", &I); - reportTranslationError(*MF, *TPC, *ORE, R); + reportTranslationError(*MF, *ORE, R); return Align(1); } @@ -4147,7 +4146,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure", F.getSubprogram(), &F.getEntryBlock()); R << "unable to translate in big endian mode"; - reportTranslationError(*MF, *TPC, *ORE, R); + reportTranslationError(*MF, *ORE, R); return false; } @@ -4191,7 +4190,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { F.getSubprogram(), &F.getEntryBlock()); R << "unable to lower function: " << ore::NV("Prototype", F.getFunctionType()); - reportTranslationError(*MF, *TPC, *ORE, R); + reportTranslationError(*MF, *ORE, R); return false; } @@ -4214,7 +4213,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { F.getSubprogram(), &F.getEntryBlock()); R << "unable to lower arguments: " << ore::NV("Prototype", F.getFunctionType()); - reportTranslationError(*MF, *TPC, *ORE, R); + reportTranslationError(*MF, *ORE, R); return false; } @@ -4265,7 +4264,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { R << ": '" << InstStrStorage << "'"; } - reportTranslationError(*MF, *TPC, *ORE, R); + reportTranslationError(*MF, *ORE, R); return false; } @@ -4273,7 +4272,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure", BB->getTerminator()->getDebugLoc(), BB); R << "unable to translate basic block"; - reportTranslationError(*MF, *TPC, *ORE, R); + reportTranslationError(*MF, *ORE, R); return false; } } diff --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp index 2dd22c8a7e8ba..1d281ab83aacc 100644 --- a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -137,7 +137,6 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) { return false; ISel = MF.getSubtarget().getInstructionSelector(); - ISel->TPC = &getAnalysis(); // FIXME: Properly override OptLevel in TargetMachine. See OptLevelChanger CodeGenOptLevel OldOptLevel = OptLevel; @@ -159,7 +158,6 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) { LLVM_DEBUG(dbgs() << "Selecting function: " << MF.getName() << '\n'); assert(ISel && "Cannot work without InstructionSelector"); - const TargetPassConfig &TPC = *ISel->TPC; CodeGenCoverage CoverageInfo; ISel->setupMF(MF, VT, &CoverageInfo, PSI, BFI); @@ -177,8 +175,8 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) { // property check already is. if (!DisableGISelLegalityCheck) if (const MachineInstr *MI = machineFunctionIsIllegal(MF)) { - reportGISelFailure(MF, TPC, MORE, "gisel-select", - "instruction is not legal", *MI); + reportGISelFailure(MF, MORE, "gisel-select", "instruction is not legal", + *MI); return false; } // FIXME: We could introduce new blocks and will need to fix the outer loop. @@ -215,8 +213,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) { if (!selectInstr(MI)) { LLVM_DEBUG(dbgs() << "Selection failed!\n"; MIIMaintainer.reportFullyCreatedInstrs()); - reportGISelFailure(MF, TPC, MORE, "gisel-select", "cannot select", - MI); + reportGISelFailure(MF, MORE, "gisel-select", "cannot select", MI); return false; } LLVM_DEBUG(MIIMaintainer.reportFullyCreatedInstrs()); @@ -279,7 +276,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) { const TargetRegisterClass *RC = MRI.getRegClassOrNull(VReg); if (!RC) { - reportGISelFailure(MF, TPC, MORE, "gisel-select", + reportGISelFailure(MF, MORE, "gisel-select", "VReg has no regclass after selection", *MI); return false; } @@ -288,7 +285,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) { if (Ty.isValid() && TypeSize::isKnownGT(Ty.getSizeInBits(), TRI.getRegSizeInBits(*RC))) { reportGISelFailure( - MF, TPC, MORE, "gisel-select", + MF, MORE, "gisel-select", "VReg's low-level type and register class have different sizes", *MI); return false; } @@ -299,7 +296,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) { MF.getFunction().getSubprogram(), /*MBB=*/nullptr); R << "inserting blocks is not supported yet"; - reportGISelFailure(MF, TPC, MORE, R); + reportGISelFailure(MF, MORE, R); return false; } #endif diff --git a/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp b/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp index aef16b5f33af4..0f0656aaa4f45 100644 --- a/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp +++ b/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp @@ -348,7 +348,7 @@ bool Legalizer::runOnMachineFunction(MachineFunction &MF) { *MIRBuilder, VT); if (Result.FailedOn) { - reportGISelFailure(MF, TPC, MORE, "gisel-legalize", + reportGISelFailure(MF, MORE, "gisel-legalize", "unable to legalize instruction", *Result.FailedOn); return false; } @@ -360,7 +360,7 @@ bool Legalizer::runOnMachineFunction(MachineFunction &MF) { R << "lost " << ore::NV("NumLostDebugLocs", LocObserver.getNumLostDebugLocs()) << " debug locations during pass"; - reportGISelWarning(MF, TPC, MORE, R); + reportGISelWarning(MF, MORE, R); // Example remark: // --- !Missed // Pass: gisel-legalize diff --git a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp index bcb4f1c551cfd..a9c7afc5ed77b 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp @@ -83,7 +83,7 @@ void RegBankSelect::init(MachineFunction &MF) { assert(RBI && "Cannot work without RegisterBankInfo"); MRI = &MF.getRegInfo(); TRI = MF.getSubtarget().getRegisterInfo(); - TPC = &getAnalysis(); + GlobalISelAbortNotEnabled = !isGlobalISelAbortEnabled(MF); if (OptMode != Mode::Fast) { MBFI = &getAnalysis().getMBFI(); MBPI = &getAnalysis().getMBPI(); @@ -308,7 +308,7 @@ const RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping( RepairPts.emplace_back(std::move(RepairPt)); } } - if (!BestMapping && !TPC->isGlobalISelAbortEnabled()) { + if (!BestMapping && GlobalISelAbortNotEnabled) { // If none of the mapping worked that means they are all impossible. // Thus, pick the first one and set an impossible repairing point. // It will trigger the failed isel mode. @@ -708,7 +708,7 @@ bool RegBankSelect::assignRegisterBanks(MachineFunction &MF) { continue; if (!assignInstr(MI)) { - reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect", + reportGISelFailure(MF, *MORE, "gisel-regbankselect", "unable to map instruction", MI); return false; } @@ -722,7 +722,7 @@ bool RegBankSelect::checkFunctionIsLegal(MachineFunction &MF) const { #ifndef NDEBUG if (!DisableGISelLegalityCheck) { if (const MachineInstr *MI = machineFunctionIsIllegal(MF)) { - reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect", + reportGISelFailure(MF, *MORE, "gisel-regbankselect", "instruction is not legal", *MI); return false; } diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp index e8954a3d9899b..544e202b9f541 100644 --- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp +++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp @@ -234,11 +234,9 @@ bool llvm::isTriviallyDead(const MachineInstr &MI, static void reportGISelDiagnostic(DiagnosticSeverity Severity, MachineFunction &MF, - const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R) { - bool IsFatal = Severity == DS_Error && - TPC.isGlobalISelAbortEnabled(); + bool IsFatal = Severity == DS_Error && isGlobalISelAbortEnabled(MF); // Print the function name explicitly if we don't have a debug location (which // makes the diagnostic less useful) or if we're going to emit a raw error. if (!R.getLocation().isValid() || IsFatal) @@ -250,20 +248,24 @@ static void reportGISelDiagnostic(DiagnosticSeverity Severity, MORE.emit(R); } -void llvm::reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC, +bool llvm::isGlobalISelAbortEnabled(MachineFunction &MF) { + return MF.getTarget().Options.GlobalISelAbort == GlobalISelAbortMode::Enable; +} + +void llvm::reportGISelWarning(MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R) { - reportGISelDiagnostic(DS_Warning, MF, TPC, MORE, R); + reportGISelDiagnostic(DS_Warning, MF, MORE, R); } -void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, +void llvm::reportGISelFailure(MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R) { MF.getProperties().setFailedISel(); - reportGISelDiagnostic(DS_Error, MF, TPC, MORE, R); + reportGISelDiagnostic(DS_Error, MF, MORE, R); } -void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, +void llvm::reportGISelFailure(MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, const char *PassName, StringRef Msg, const MachineInstr &MI) { @@ -271,9 +273,9 @@ void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, MI.getDebugLoc(), MI.getParent()); R << Msg; // Printing MI is expensive; only do it if expensive remarks are enabled. - if (TPC.isGlobalISelAbortEnabled() || MORE.allowExtraAnalysis(PassName)) + if (isGlobalISelAbortEnabled(MF) || MORE.allowExtraAnalysis(PassName)) R << ": " << ore::MNV("Inst", MI); - reportGISelFailure(MF, TPC, MORE, R); + reportGISelFailure(MF, MORE, R); } unsigned llvm::getInverseGMinMaxOpcode(unsigned MinMaxOpc) { diff --git a/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp b/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp index 3d5a55c631301..1e5d0a4297465 100644 --- a/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp +++ b/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp @@ -1569,7 +1569,7 @@ bool RISCVInstructionSelector::selectAddr(MachineInstr &MI, switch (TM.getCodeModel()) { default: { - reportGISelFailure(*MF, *TPC, *MORE, getName(), + reportGISelFailure(*MF, *MORE, getName(), "Unsupported code model for lowering", MI); return false; } diff --git a/llvm/unittests/CodeGen/GlobalISel/InstructionSelectTest.cpp b/llvm/unittests/CodeGen/GlobalISel/InstructionSelectTest.cpp index 7fbccf7160e17..223798342b3ee 100644 --- a/llvm/unittests/CodeGen/GlobalISel/InstructionSelectTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/InstructionSelectTest.cpp @@ -59,10 +59,8 @@ TEST_F(AArch64GISelMITest, TestInstructionSelectErase) { GTEST_SKIP(); legacy::PassManager PM; - std::unique_ptr TPC(TM->createPassConfig(PM)); EraseMockInstructionSelector ISel; - ISel.TPC = TPC.get(); for (auto &MI : *EntryMBB) { ISel.MIs.push_back(&MI); }