Skip to content

Commit f7d7bd9

Browse files
GlobalISel: Stop using TPC to check if GlobalISelAbort is enabled
New pass manager does not use TargetPassConfig. GlobalISel requires TargetPassConfig to reportGISelFailure, and it only actual use is to check if GlobalISelAbort is enabled. TargetPassConfig uses TargetMachine to check if GlobalISelAbort is enabled, but TargetMachine is also available from MachineFunction.
1 parent 135ddf1 commit f7d7bd9

File tree

10 files changed

+37
-45
lines changed

10 files changed

+37
-45
lines changed

llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class LLVM_ABI InstructionSelector : public GIMatchTableExecutor {
3535
/// !isPreISelGenericOpcode(I.getOpcode())
3636
virtual bool select(MachineInstr &I) = 0;
3737

38-
// FIXME: Eliminate dependency on TargetPassConfig for NewPM transition
39-
const TargetPassConfig *TPC = nullptr;
40-
4138
MachineOptimizationRemarkEmitter *MORE = nullptr;
4239

4340
/// Note: InstructionSelect does not track changed instructions.

llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class RegBankSelect : public MachineFunctionPass {
511511
Mode OptMode;
512512

513513
/// Current target configuration. Controls how the pass handles errors.
514-
const TargetPassConfig *TPC;
514+
bool GlobalISelAbortNotEnabled;
515515

516516
/// Assign the register bank of each operand of \p MI.
517517
/// \return True on success, false otherwise.

llvm/include/llvm/CodeGen/GlobalISel/Utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,22 @@ LLVM_ABI bool canReplaceReg(Register DstReg, Register SrcReg,
152152
LLVM_ABI bool isTriviallyDead(const MachineInstr &MI,
153153
const MachineRegisterInfo &MRI);
154154

155+
LLVM_ABI bool isGlobalISelAbortEnabled(MachineFunction &MF);
156+
155157
/// Report an ISel error as a missed optimization remark to the LLVMContext's
156158
/// diagnostic stream. Set the FailedISel MachineFunction property.
157159
LLVM_ABI void reportGISelFailure(MachineFunction &MF,
158-
const TargetPassConfig &TPC,
159160
MachineOptimizationRemarkEmitter &MORE,
160161
MachineOptimizationRemarkMissed &R);
161162

162163
LLVM_ABI void reportGISelFailure(MachineFunction &MF,
163-
const TargetPassConfig &TPC,
164164
MachineOptimizationRemarkEmitter &MORE,
165165
const char *PassName, StringRef Msg,
166166
const MachineInstr &MI);
167167

168168
/// Report an ISel warning as a missed optimization remark to the LLVMContext's
169169
/// diagnostic stream.
170170
LLVM_ABI void reportGISelWarning(MachineFunction &MF,
171-
const TargetPassConfig &TPC,
172171
MachineOptimizationRemarkEmitter &MORE,
173172
MachineOptimizationRemarkMissed &R);
174173

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,16 @@ INITIALIZE_PASS_END(IRTranslator, DEBUG_TYPE, "IRTranslator LLVM IR -> MI",
111111
false, false)
112112

113113
static void reportTranslationError(MachineFunction &MF,
114-
const TargetPassConfig &TPC,
115114
OptimizationRemarkEmitter &ORE,
116115
OptimizationRemarkMissed &R) {
117116
MF.getProperties().setFailedISel();
118117

119118
// Print the function name explicitly if we don't have a debug location (which
120119
// makes the diagnostic less useful) or if we're going to emit a raw error.
121-
if (!R.getLocation().isValid() || TPC.isGlobalISelAbortEnabled())
120+
if (!R.getLocation().isValid() || isGlobalISelAbortEnabled(MF))
122121
R << (" (in function: " + MF.getName() + ")").str();
123122

124-
if (TPC.isGlobalISelAbortEnabled())
123+
if (isGlobalISelAbortEnabled(MF))
125124
report_fatal_error(Twine(R.getMsg()));
126125
else
127126
ORE.emit(R);
@@ -242,7 +241,7 @@ ArrayRef<Register> IRTranslator::getOrCreateVRegs(const Value &Val) {
242241
MF->getFunction().getSubprogram(),
243242
&MF->getFunction().getEntryBlock());
244243
R << "unable to translate constant: " << ore::NV("Type", Val.getType());
245-
reportTranslationError(*MF, *TPC, *ORE, R);
244+
reportTranslationError(*MF, *ORE, R);
246245
return *VRegs;
247246
}
248247
}
@@ -279,7 +278,7 @@ Align IRTranslator::getMemOpAlign(const Instruction &I) {
279278

280279
OptimizationRemarkMissed R("gisel-irtranslator", "", &I);
281280
R << "unable to translate memop: " << ore::NV("Opcode", &I);
282-
reportTranslationError(*MF, *TPC, *ORE, R);
281+
reportTranslationError(*MF, *ORE, R);
283282
return Align(1);
284283
}
285284

@@ -4147,7 +4146,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
41474146
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
41484147
F.getSubprogram(), &F.getEntryBlock());
41494148
R << "unable to translate in big endian mode";
4150-
reportTranslationError(*MF, *TPC, *ORE, R);
4149+
reportTranslationError(*MF, *ORE, R);
41514150
return false;
41524151
}
41534152

@@ -4191,7 +4190,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
41914190
F.getSubprogram(), &F.getEntryBlock());
41924191
R << "unable to lower function: "
41934192
<< ore::NV("Prototype", F.getFunctionType());
4194-
reportTranslationError(*MF, *TPC, *ORE, R);
4193+
reportTranslationError(*MF, *ORE, R);
41954194
return false;
41964195
}
41974196

@@ -4214,7 +4213,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
42144213
F.getSubprogram(), &F.getEntryBlock());
42154214
R << "unable to lower arguments: "
42164215
<< ore::NV("Prototype", F.getFunctionType());
4217-
reportTranslationError(*MF, *TPC, *ORE, R);
4216+
reportTranslationError(*MF, *ORE, R);
42184217
return false;
42194218
}
42204219

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

4268-
reportTranslationError(*MF, *TPC, *ORE, R);
4267+
reportTranslationError(*MF, *ORE, R);
42694268
return false;
42704269
}
42714270

42724271
if (!finalizeBasicBlock(*BB, MBB)) {
42734272
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
42744273
BB->getTerminator()->getDebugLoc(), BB);
42754274
R << "unable to translate basic block";
4276-
reportTranslationError(*MF, *TPC, *ORE, R);
4275+
reportTranslationError(*MF, *ORE, R);
42774276
return false;
42784277
}
42794278
}

llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
137137
return false;
138138

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

142141
// FIXME: Properly override OptLevel in TargetMachine. See OptLevelChanger
143142
CodeGenOptLevel OldOptLevel = OptLevel;
@@ -159,7 +158,6 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) {
159158
LLVM_DEBUG(dbgs() << "Selecting function: " << MF.getName() << '\n');
160159
assert(ISel && "Cannot work without InstructionSelector");
161160

162-
const TargetPassConfig &TPC = *ISel->TPC;
163161
CodeGenCoverage CoverageInfo;
164162
ISel->setupMF(MF, VT, &CoverageInfo, PSI, BFI);
165163

@@ -177,8 +175,8 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) {
177175
// property check already is.
178176
if (!DisableGISelLegalityCheck)
179177
if (const MachineInstr *MI = machineFunctionIsIllegal(MF)) {
180-
reportGISelFailure(MF, TPC, MORE, "gisel-select",
181-
"instruction is not legal", *MI);
178+
reportGISelFailure(MF, MORE, "gisel-select", "instruction is not legal",
179+
*MI);
182180
return false;
183181
}
184182
// FIXME: We could introduce new blocks and will need to fix the outer loop.
@@ -215,8 +213,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) {
215213
if (!selectInstr(MI)) {
216214
LLVM_DEBUG(dbgs() << "Selection failed!\n";
217215
MIIMaintainer.reportFullyCreatedInstrs());
218-
reportGISelFailure(MF, TPC, MORE, "gisel-select", "cannot select",
219-
MI);
216+
reportGISelFailure(MF, MORE, "gisel-select", "cannot select", MI);
220217
return false;
221218
}
222219
LLVM_DEBUG(MIIMaintainer.reportFullyCreatedInstrs());
@@ -279,7 +276,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) {
279276

280277
const TargetRegisterClass *RC = MRI.getRegClassOrNull(VReg);
281278
if (!RC) {
282-
reportGISelFailure(MF, TPC, MORE, "gisel-select",
279+
reportGISelFailure(MF, MORE, "gisel-select",
283280
"VReg has no regclass after selection", *MI);
284281
return false;
285282
}
@@ -288,7 +285,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) {
288285
if (Ty.isValid() &&
289286
TypeSize::isKnownGT(Ty.getSizeInBits(), TRI.getRegSizeInBits(*RC))) {
290287
reportGISelFailure(
291-
MF, TPC, MORE, "gisel-select",
288+
MF, MORE, "gisel-select",
292289
"VReg's low-level type and register class have different sizes", *MI);
293290
return false;
294291
}
@@ -299,7 +296,7 @@ bool InstructionSelect::selectMachineFunction(MachineFunction &MF) {
299296
MF.getFunction().getSubprogram(),
300297
/*MBB=*/nullptr);
301298
R << "inserting blocks is not supported yet";
302-
reportGISelFailure(MF, TPC, MORE, R);
299+
reportGISelFailure(MF, MORE, R);
303300
return false;
304301
}
305302
#endif

llvm/lib/CodeGen/GlobalISel/Legalizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ bool Legalizer::runOnMachineFunction(MachineFunction &MF) {
348348
*MIRBuilder, VT);
349349

350350
if (Result.FailedOn) {
351-
reportGISelFailure(MF, TPC, MORE, "gisel-legalize",
351+
reportGISelFailure(MF, MORE, "gisel-legalize",
352352
"unable to legalize instruction", *Result.FailedOn);
353353
return false;
354354
}
@@ -360,7 +360,7 @@ bool Legalizer::runOnMachineFunction(MachineFunction &MF) {
360360
R << "lost "
361361
<< ore::NV("NumLostDebugLocs", LocObserver.getNumLostDebugLocs())
362362
<< " debug locations during pass";
363-
reportGISelWarning(MF, TPC, MORE, R);
363+
reportGISelWarning(MF, MORE, R);
364364
// Example remark:
365365
// --- !Missed
366366
// Pass: gisel-legalize

llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void RegBankSelect::init(MachineFunction &MF) {
8383
assert(RBI && "Cannot work without RegisterBankInfo");
8484
MRI = &MF.getRegInfo();
8585
TRI = MF.getSubtarget().getRegisterInfo();
86-
TPC = &getAnalysis<TargetPassConfig>();
86+
GlobalISelAbortNotEnabled = !isGlobalISelAbortEnabled(MF);
8787
if (OptMode != Mode::Fast) {
8888
MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
8989
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
@@ -308,7 +308,7 @@ const RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping(
308308
RepairPts.emplace_back(std::move(RepairPt));
309309
}
310310
}
311-
if (!BestMapping && !TPC->isGlobalISelAbortEnabled()) {
311+
if (!BestMapping && GlobalISelAbortNotEnabled) {
312312
// If none of the mapping worked that means they are all impossible.
313313
// Thus, pick the first one and set an impossible repairing point.
314314
// It will trigger the failed isel mode.
@@ -708,7 +708,7 @@ bool RegBankSelect::assignRegisterBanks(MachineFunction &MF) {
708708
continue;
709709

710710
if (!assignInstr(MI)) {
711-
reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect",
711+
reportGISelFailure(MF, *MORE, "gisel-regbankselect",
712712
"unable to map instruction", MI);
713713
return false;
714714
}
@@ -722,7 +722,7 @@ bool RegBankSelect::checkFunctionIsLegal(MachineFunction &MF) const {
722722
#ifndef NDEBUG
723723
if (!DisableGISelLegalityCheck) {
724724
if (const MachineInstr *MI = machineFunctionIsIllegal(MF)) {
725-
reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect",
725+
reportGISelFailure(MF, *MORE, "gisel-regbankselect",
726726
"instruction is not legal", *MI);
727727
return false;
728728
}

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,9 @@ bool llvm::isTriviallyDead(const MachineInstr &MI,
234234

235235
static void reportGISelDiagnostic(DiagnosticSeverity Severity,
236236
MachineFunction &MF,
237-
const TargetPassConfig &TPC,
238237
MachineOptimizationRemarkEmitter &MORE,
239238
MachineOptimizationRemarkMissed &R) {
240-
bool IsFatal = Severity == DS_Error &&
241-
TPC.isGlobalISelAbortEnabled();
239+
bool IsFatal = Severity == DS_Error && isGlobalISelAbortEnabled(MF);
242240
// Print the function name explicitly if we don't have a debug location (which
243241
// makes the diagnostic less useful) or if we're going to emit a raw error.
244242
if (!R.getLocation().isValid() || IsFatal)
@@ -250,30 +248,34 @@ static void reportGISelDiagnostic(DiagnosticSeverity Severity,
250248
MORE.emit(R);
251249
}
252250

253-
void llvm::reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC,
251+
bool llvm::isGlobalISelAbortEnabled(MachineFunction &MF) {
252+
return MF.getTarget().Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
253+
}
254+
255+
void llvm::reportGISelWarning(MachineFunction &MF,
254256
MachineOptimizationRemarkEmitter &MORE,
255257
MachineOptimizationRemarkMissed &R) {
256-
reportGISelDiagnostic(DS_Warning, MF, TPC, MORE, R);
258+
reportGISelDiagnostic(DS_Warning, MF, MORE, R);
257259
}
258260

259-
void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
261+
void llvm::reportGISelFailure(MachineFunction &MF,
260262
MachineOptimizationRemarkEmitter &MORE,
261263
MachineOptimizationRemarkMissed &R) {
262264
MF.getProperties().setFailedISel();
263-
reportGISelDiagnostic(DS_Error, MF, TPC, MORE, R);
265+
reportGISelDiagnostic(DS_Error, MF, MORE, R);
264266
}
265267

266-
void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
268+
void llvm::reportGISelFailure(MachineFunction &MF,
267269
MachineOptimizationRemarkEmitter &MORE,
268270
const char *PassName, StringRef Msg,
269271
const MachineInstr &MI) {
270272
MachineOptimizationRemarkMissed R(PassName, "GISelFailure: ",
271273
MI.getDebugLoc(), MI.getParent());
272274
R << Msg;
273275
// Printing MI is expensive; only do it if expensive remarks are enabled.
274-
if (TPC.isGlobalISelAbortEnabled() || MORE.allowExtraAnalysis(PassName))
276+
if (isGlobalISelAbortEnabled(MF) || MORE.allowExtraAnalysis(PassName))
275277
R << ": " << ore::MNV("Inst", MI);
276-
reportGISelFailure(MF, TPC, MORE, R);
278+
reportGISelFailure(MF, MORE, R);
277279
}
278280

279281
unsigned llvm::getInverseGMinMaxOpcode(unsigned MinMaxOpc) {

llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ bool RISCVInstructionSelector::selectAddr(MachineInstr &MI,
15691569

15701570
switch (TM.getCodeModel()) {
15711571
default: {
1572-
reportGISelFailure(*MF, *TPC, *MORE, getName(),
1572+
reportGISelFailure(*MF, *MORE, getName(),
15731573
"Unsupported code model for lowering", MI);
15741574
return false;
15751575
}

llvm/unittests/CodeGen/GlobalISel/InstructionSelectTest.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ TEST_F(AArch64GISelMITest, TestInstructionSelectErase) {
5959
GTEST_SKIP();
6060

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

6463
EraseMockInstructionSelector ISel;
65-
ISel.TPC = TPC.get();
6664
for (auto &MI : *EntryMBB) {
6765
ISel.MIs.push_back(&MI);
6866
}

0 commit comments

Comments
 (0)