Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions llvm/include/llvm/CodeGen/GlobalISel/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,22 @@ 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);

/// 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);

Expand Down
19 changes: 9 additions & 10 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -242,7 +241,7 @@ ArrayRef<Register> 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;
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -4265,15 +4264,15 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
R << ": '" << InstStrStorage << "'";
}

reportTranslationError(*MF, *TPC, *ORE, R);
reportTranslationError(*MF, *ORE, R);
return false;
}

if (!finalizeBasicBlock(*BB, MBB)) {
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;
}
}
Expand Down
15 changes: 6 additions & 9 deletions llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
return false;

ISel = MF.getSubtarget().getInstructionSelector();
ISel->TPC = &getAnalysis<TargetPassConfig>();

// FIXME: Properly override OptLevel in TargetMachine. See OptLevelChanger
CodeGenOptLevel OldOptLevel = OptLevel;
Expand All @@ -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);

Expand All @@ -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.
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void RegBankSelect::init(MachineFunction &MF) {
assert(RBI && "Cannot work without RegisterBankInfo");
MRI = &MF.getRegInfo();
TRI = MF.getSubtarget().getRegisterInfo();
TPC = &getAnalysis<TargetPassConfig>();
GlobalISelAbortNotEnabled = !isGlobalISelAbortEnabled(MF);
if (OptMode != Mode::Fast) {
MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
22 changes: 12 additions & 10 deletions llvm/lib/CodeGen/GlobalISel/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -250,30 +248,34 @@ 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) {
MachineOptimizationRemarkMissed R(PassName, "GISelFailure: ",
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) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions llvm/unittests/CodeGen/GlobalISel/InstructionSelectTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ TEST_F(AArch64GISelMITest, TestInstructionSelectErase) {
GTEST_SKIP();

legacy::PassManager PM;
std::unique_ptr<TargetPassConfig> TPC(TM->createPassConfig(PM));

EraseMockInstructionSelector ISel;
ISel.TPC = TPC.get();
for (auto &MI : *EntryMBB) {
ISel.MIs.push_back(&MI);
}
Expand Down