Skip to content

Commit 9c641ba

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 5c26015 commit 9c641ba

File tree

10 files changed

+43
-46
lines changed

10 files changed

+43
-46
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ 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;
513+
/// Controls how the pass handles errors.
514+
bool GlobalISelAbortEnabled;
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TargetRegisterInfo;
5151
class TargetRegisterClass;
5252
class ConstantFP;
5353
class APFloat;
54+
class TargetOptions;
5455

5556
// Convenience macros for dealing with vector reduction opcodes.
5657
#define GISEL_VECREDUCE_CASES_ALL \
@@ -152,23 +153,22 @@ LLVM_ABI bool canReplaceReg(Register DstReg, Register SrcReg,
152153
LLVM_ABI bool isTriviallyDead(const MachineInstr &MI,
153154
const MachineRegisterInfo &MRI);
154155

156+
LLVM_ABI bool isGlobalISelAbortEnabled(const TargetOptions &Options);
157+
155158
/// Report an ISel error as a missed optimization remark to the LLVMContext's
156159
/// diagnostic stream. Set the FailedISel MachineFunction property.
157160
LLVM_ABI void reportGISelFailure(MachineFunction &MF,
158-
const TargetPassConfig &TPC,
159161
MachineOptimizationRemarkEmitter &MORE,
160162
MachineOptimizationRemarkMissed &R);
161163

162164
LLVM_ABI void reportGISelFailure(MachineFunction &MF,
163-
const TargetPassConfig &TPC,
164165
MachineOptimizationRemarkEmitter &MORE,
165166
const char *PassName, StringRef Msg,
166167
const MachineInstr &MI);
167168

168169
/// Report an ISel warning as a missed optimization remark to the LLVMContext's
169170
/// diagnostic stream.
170171
LLVM_ABI void reportGISelWarning(MachineFunction &MF,
171-
const TargetPassConfig &TPC,
172172
MachineOptimizationRemarkEmitter &MORE,
173173
MachineOptimizationRemarkMissed &R);
174174

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ 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() ||
121+
isGlobalISelAbortEnabled(MF.getTarget().Options))
122122
R << (" (in function: " + MF.getName() + ")").str();
123123

124-
if (TPC.isGlobalISelAbortEnabled())
124+
if (isGlobalISelAbortEnabled(MF.getTarget().Options))
125125
report_fatal_error(Twine(R.getMsg()));
126126
else
127127
ORE.emit(R);
@@ -242,7 +242,7 @@ ArrayRef<Register> IRTranslator::getOrCreateVRegs(const Value &Val) {
242242
MF->getFunction().getSubprogram(),
243243
&MF->getFunction().getEntryBlock());
244244
R << "unable to translate constant: " << ore::NV("Type", Val.getType());
245-
reportTranslationError(*MF, *TPC, *ORE, R);
245+
reportTranslationError(*MF, *ORE, R);
246246
return *VRegs;
247247
}
248248
}
@@ -279,7 +279,7 @@ Align IRTranslator::getMemOpAlign(const Instruction &I) {
279279

280280
OptimizationRemarkMissed R("gisel-irtranslator", "", &I);
281281
R << "unable to translate memop: " << ore::NV("Opcode", &I);
282-
reportTranslationError(*MF, *TPC, *ORE, R);
282+
reportTranslationError(*MF, *ORE, R);
283283
return Align(1);
284284
}
285285

@@ -4147,7 +4147,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
41474147
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
41484148
F.getSubprogram(), &F.getEntryBlock());
41494149
R << "unable to translate in big endian mode";
4150-
reportTranslationError(*MF, *TPC, *ORE, R);
4150+
reportTranslationError(*MF, *ORE, R);
41514151
return false;
41524152
}
41534153

@@ -4191,7 +4191,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
41914191
F.getSubprogram(), &F.getEntryBlock());
41924192
R << "unable to lower function: "
41934193
<< ore::NV("Prototype", F.getFunctionType());
4194-
reportTranslationError(*MF, *TPC, *ORE, R);
4194+
reportTranslationError(*MF, *ORE, R);
41954195
return false;
41964196
}
41974197

@@ -4214,7 +4214,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
42144214
F.getSubprogram(), &F.getEntryBlock());
42154215
R << "unable to lower arguments: "
42164216
<< ore::NV("Prototype", F.getFunctionType());
4217-
reportTranslationError(*MF, *TPC, *ORE, R);
4217+
reportTranslationError(*MF, *ORE, R);
42184218
return false;
42194219
}
42204220

@@ -4265,15 +4265,15 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
42654265
R << ": '" << InstStrStorage << "'";
42664266
}
42674267

4268-
reportTranslationError(*MF, *TPC, *ORE, R);
4268+
reportTranslationError(*MF, *ORE, R);
42694269
return false;
42704270
}
42714271

42724272
if (!finalizeBasicBlock(*BB, MBB)) {
42734273
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
42744274
BB->getTerminator()->getDebugLoc(), BB);
42754275
R << "unable to translate basic block";
4276-
reportTranslationError(*MF, *TPC, *ORE, R);
4276+
reportTranslationError(*MF, *ORE, R);
42774277
return false;
42784278
}
42794279
}

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,7 @@ 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>();
87+
GlobalISelAbortEnabled = isGlobalISelAbortEnabled(MF.getTarget().Options);
8788
if (OptMode != Mode::Fast) {
8889
MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
8990
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
@@ -308,7 +309,7 @@ const RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping(
308309
RepairPts.emplace_back(std::move(RepairPt));
309310
}
310311
}
311-
if (!BestMapping && !TPC->isGlobalISelAbortEnabled()) {
312+
if (!BestMapping && !GlobalISelAbortEnabled) {
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: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,10 @@ 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 =
240+
Severity == DS_Error && isGlobalISelAbortEnabled(MF.getTarget().Options);
242241
// Print the function name explicitly if we don't have a debug location (which
243242
// makes the diagnostic less useful) or if we're going to emit a raw error.
244243
if (!R.getLocation().isValid() || IsFatal)
@@ -250,30 +249,35 @@ static void reportGISelDiagnostic(DiagnosticSeverity Severity,
250249
MORE.emit(R);
251250
}
252251

253-
void llvm::reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC,
252+
bool llvm::isGlobalISelAbortEnabled(const TargetOptions &Options) {
253+
return Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
254+
}
255+
256+
void llvm::reportGISelWarning(MachineFunction &MF,
254257
MachineOptimizationRemarkEmitter &MORE,
255258
MachineOptimizationRemarkMissed &R) {
256-
reportGISelDiagnostic(DS_Warning, MF, TPC, MORE, R);
259+
reportGISelDiagnostic(DS_Warning, MF, MORE, R);
257260
}
258261

259-
void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
262+
void llvm::reportGISelFailure(MachineFunction &MF,
260263
MachineOptimizationRemarkEmitter &MORE,
261264
MachineOptimizationRemarkMissed &R) {
262265
MF.getProperties().setFailedISel();
263-
reportGISelDiagnostic(DS_Error, MF, TPC, MORE, R);
266+
reportGISelDiagnostic(DS_Error, MF, MORE, R);
264267
}
265268

266-
void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
269+
void llvm::reportGISelFailure(MachineFunction &MF,
267270
MachineOptimizationRemarkEmitter &MORE,
268271
const char *PassName, StringRef Msg,
269272
const MachineInstr &MI) {
270273
MachineOptimizationRemarkMissed R(PassName, "GISelFailure: ",
271274
MI.getDebugLoc(), MI.getParent());
272275
R << Msg;
273276
// Printing MI is expensive; only do it if expensive remarks are enabled.
274-
if (TPC.isGlobalISelAbortEnabled() || MORE.allowExtraAnalysis(PassName))
277+
if (isGlobalISelAbortEnabled(MF.getTarget().Options) ||
278+
MORE.allowExtraAnalysis(PassName))
275279
R << ": " << ore::MNV("Inst", MI);
276-
reportGISelFailure(MF, TPC, MORE, R);
280+
reportGISelFailure(MF, MORE, R);
277281
}
278282

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