Skip to content

Commit 25b6a15

Browse files
GlobalISel: Stop using TPC to check if GlobalISelAbort is enabled (llvm#169917)
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 47d66bf commit 25b6a15

File tree

10 files changed

+36
-47
lines changed

10 files changed

+36
-47
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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,6 @@ class RegBankSelect : public MachineFunctionPass {
510510
/// Optimization mode of the pass.
511511
Mode OptMode;
512512

513-
/// Current target configuration. Controls how the pass handles errors.
514-
const TargetPassConfig *TPC;
515-
516513
/// Assign the register bank of each operand of \p MI.
517514
/// \return True on success, false otherwise.
518515
bool assignInstr(MachineInstr &MI);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,17 @@ LLVM_ABI bool isTriviallyDead(const MachineInstr &MI,
155155
/// Report an ISel error as a missed optimization remark to the LLVMContext's
156156
/// diagnostic stream. Set the FailedISel MachineFunction property.
157157
LLVM_ABI void reportGISelFailure(MachineFunction &MF,
158-
const TargetPassConfig &TPC,
159158
MachineOptimizationRemarkEmitter &MORE,
160159
MachineOptimizationRemarkMissed &R);
161160

162161
LLVM_ABI void reportGISelFailure(MachineFunction &MF,
163-
const TargetPassConfig &TPC,
164162
MachineOptimizationRemarkEmitter &MORE,
165163
const char *PassName, StringRef Msg,
166164
const MachineInstr &MI);
167165

168166
/// Report an ISel warning as a missed optimization remark to the LLVMContext's
169167
/// diagnostic stream.
170168
LLVM_ABI void reportGISelWarning(MachineFunction &MF,
171-
const TargetPassConfig &TPC,
172169
MachineOptimizationRemarkEmitter &MORE,
173170
MachineOptimizationRemarkMissed &R);
174171

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,18 @@ 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();
117+
bool IsGlobalISelAbortEnabled =
118+
MF.getTarget().Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
118119

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

124-
if (TPC.isGlobalISelAbortEnabled())
125+
if (IsGlobalISelAbortEnabled)
125126
report_fatal_error(Twine(R.getMsg()));
126127
else
127128
ORE.emit(R);
@@ -242,7 +243,7 @@ ArrayRef<Register> IRTranslator::getOrCreateVRegs(const Value &Val) {
242243
MF->getFunction().getSubprogram(),
243244
&MF->getFunction().getEntryBlock());
244245
R << "unable to translate constant: " << ore::NV("Type", Val.getType());
245-
reportTranslationError(*MF, *TPC, *ORE, R);
246+
reportTranslationError(*MF, *ORE, R);
246247
return *VRegs;
247248
}
248249
}
@@ -279,7 +280,7 @@ Align IRTranslator::getMemOpAlign(const Instruction &I) {
279280

280281
OptimizationRemarkMissed R("gisel-irtranslator", "", &I);
281282
R << "unable to translate memop: " << ore::NV("Opcode", &I);
282-
reportTranslationError(*MF, *TPC, *ORE, R);
283+
reportTranslationError(*MF, *ORE, R);
283284
return Align(1);
284285
}
285286

@@ -4147,7 +4148,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
41474148
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
41484149
F.getSubprogram(), &F.getEntryBlock());
41494150
R << "unable to translate in big endian mode";
4150-
reportTranslationError(*MF, *TPC, *ORE, R);
4151+
reportTranslationError(*MF, *ORE, R);
41514152
return false;
41524153
}
41534154

@@ -4191,7 +4192,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
41914192
F.getSubprogram(), &F.getEntryBlock());
41924193
R << "unable to lower function: "
41934194
<< ore::NV("Prototype", F.getFunctionType());
4194-
reportTranslationError(*MF, *TPC, *ORE, R);
4195+
reportTranslationError(*MF, *ORE, R);
41954196
return false;
41964197
}
41974198

@@ -4214,7 +4215,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
42144215
F.getSubprogram(), &F.getEntryBlock());
42154216
R << "unable to lower arguments: "
42164217
<< ore::NV("Prototype", F.getFunctionType());
4217-
reportTranslationError(*MF, *TPC, *ORE, R);
4218+
reportTranslationError(*MF, *ORE, R);
42184219
return false;
42194220
}
42204221

@@ -4265,15 +4266,15 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
42654266
R << ": '" << InstStrStorage << "'";
42664267
}
42674268

4268-
reportTranslationError(*MF, *TPC, *ORE, R);
4269+
reportTranslationError(*MF, *ORE, R);
42694270
return false;
42704271
}
42714272

42724273
if (!finalizeBasicBlock(*BB, MBB)) {
42734274
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
42744275
BB->getTerminator()->getDebugLoc(), BB);
42754276
R << "unable to translate basic block";
4276-
reportTranslationError(*MF, *TPC, *ORE, R);
4277+
reportTranslationError(*MF, *ORE, R);
42774278
return false;
42784279
}
42794280
}

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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/Support/Debug.h"
4040
#include "llvm/Support/ErrorHandling.h"
4141
#include "llvm/Support/raw_ostream.h"
42+
#include "llvm/Target/TargetMachine.h"
4243
#include <algorithm>
4344
#include <cassert>
4445
#include <cstdint>
@@ -83,7 +84,6 @@ void RegBankSelect::init(MachineFunction &MF) {
8384
assert(RBI && "Cannot work without RegisterBankInfo");
8485
MRI = &MF.getRegInfo();
8586
TRI = MF.getSubtarget().getRegisterInfo();
86-
TPC = &getAnalysis<TargetPassConfig>();
8787
if (OptMode != Mode::Fast) {
8888
MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
8989
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
@@ -308,7 +308,8 @@ const RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping(
308308
RepairPts.emplace_back(std::move(RepairPt));
309309
}
310310
}
311-
if (!BestMapping && !TPC->isGlobalISelAbortEnabled()) {
311+
if (!BestMapping && MI.getMF()->getTarget().Options.GlobalISelAbort !=
312+
GlobalISelAbortMode::Enable) {
312313
// If none of the mapping worked that means they are all impossible.
313314
// Thus, pick the first one and set an impossible repairing point.
314315
// It will trigger the failed isel mode.
@@ -708,7 +709,7 @@ bool RegBankSelect::assignRegisterBanks(MachineFunction &MF) {
708709
continue;
709710

710711
if (!assignInstr(MI)) {
711-
reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect",
712+
reportGISelFailure(MF, *MORE, "gisel-regbankselect",
712713
"unable to map instruction", MI);
713714
return false;
714715
}
@@ -722,7 +723,7 @@ bool RegBankSelect::checkFunctionIsLegal(MachineFunction &MF) const {
722723
#ifndef NDEBUG
723724
if (!DisableGISelLegalityCheck) {
724725
if (const MachineInstr *MI = machineFunctionIsIllegal(MF)) {
725-
reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect",
726+
reportGISelFailure(MF, *MORE, "gisel-regbankselect",
726727
"instruction is not legal", *MI);
727728
return false;
728729
}

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ 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 IsGlobalISelAbortEnabled =
240+
MF.getTarget().Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
241+
bool IsFatal = Severity == DS_Error && IsGlobalISelAbortEnabled;
242242
// Print the function name explicitly if we don't have a debug location (which
243243
// makes the diagnostic less useful) or if we're going to emit a raw error.
244244
if (!R.getLocation().isValid() || IsFatal)
@@ -250,30 +250,31 @@ static void reportGISelDiagnostic(DiagnosticSeverity Severity,
250250
MORE.emit(R);
251251
}
252252

253-
void llvm::reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC,
253+
void llvm::reportGISelWarning(MachineFunction &MF,
254254
MachineOptimizationRemarkEmitter &MORE,
255255
MachineOptimizationRemarkMissed &R) {
256-
reportGISelDiagnostic(DS_Warning, MF, TPC, MORE, R);
256+
reportGISelDiagnostic(DS_Warning, MF, MORE, R);
257257
}
258258

259-
void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
259+
void llvm::reportGISelFailure(MachineFunction &MF,
260260
MachineOptimizationRemarkEmitter &MORE,
261261
MachineOptimizationRemarkMissed &R) {
262262
MF.getProperties().setFailedISel();
263-
reportGISelDiagnostic(DS_Error, MF, TPC, MORE, R);
263+
reportGISelDiagnostic(DS_Error, MF, MORE, R);
264264
}
265265

266-
void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
266+
void llvm::reportGISelFailure(MachineFunction &MF,
267267
MachineOptimizationRemarkEmitter &MORE,
268268
const char *PassName, StringRef Msg,
269269
const MachineInstr &MI) {
270270
MachineOptimizationRemarkMissed R(PassName, "GISelFailure: ",
271271
MI.getDebugLoc(), MI.getParent());
272272
R << Msg;
273273
// Printing MI is expensive; only do it if expensive remarks are enabled.
274-
if (TPC.isGlobalISelAbortEnabled() || MORE.allowExtraAnalysis(PassName))
274+
if (MF.getTarget().Options.GlobalISelAbort == GlobalISelAbortMode::Enable ||
275+
MORE.allowExtraAnalysis(PassName))
275276
R << ": " << ore::MNV("Inst", MI);
276-
reportGISelFailure(MF, TPC, MORE, R);
277+
reportGISelFailure(MF, MORE, R);
277278
}
278279

279280
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)