Skip to content

Commit ee7ca0d

Browse files
authored
Make CombinerHelper methods const (llvm#119529)
There are a number of backends (specifically AArch64, AMDGPU, Mips, and RISCV) which contain a “TODO: make CombinerHelper methods const” comment. This PR does just that and makes all of the CombinerHelper methods const, removes the TODO comments and makes the associated instances const. This change makes some sense because the CombinerHelper class simply modifies the state of _other_ objects to which it holds pointers or references. Note that AMDGPU contains an identical comment for an instance of AMDGPUCombinerHelper (a subclass of CombinerHelper). I deliberately haven’t modified the methods of that class in order to limit the scope of the change. I’m happy to do so either now or as a follow-up.
1 parent eb1b9fc commit ee7ca0d

16 files changed

+643
-554
lines changed

llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h

+309-262
Large diffs are not rendered by default.

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

+295-246
Large diffs are not rendered by default.

llvm/lib/CodeGen/GlobalISel/CombinerHelperArtifacts.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
using namespace llvm;
3030

3131
bool CombinerHelper::matchMergeXAndUndef(const MachineInstr &MI,
32-
BuildFnTy &MatchInfo) {
32+
BuildFnTy &MatchInfo) const {
3333
const GMerge *Merge = cast<GMerge>(&MI);
3434

3535
Register Dst = Merge->getReg(0);
@@ -58,7 +58,7 @@ bool CombinerHelper::matchMergeXAndUndef(const MachineInstr &MI,
5858
}
5959

6060
bool CombinerHelper::matchMergeXAndZero(const MachineInstr &MI,
61-
BuildFnTy &MatchInfo) {
61+
BuildFnTy &MatchInfo) const {
6262
const GMerge *Merge = cast<GMerge>(&MI);
6363

6464
Register Dst = Merge->getReg(0);

llvm/lib/CodeGen/GlobalISel/CombinerHelperCasts.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
using namespace llvm;
2727

2828
bool CombinerHelper::matchSextOfTrunc(const MachineOperand &MO,
29-
BuildFnTy &MatchInfo) {
29+
BuildFnTy &MatchInfo) const {
3030
GSext *Sext = cast<GSext>(getDefIgnoringCopies(MO.getReg(), MRI));
3131
GTrunc *Trunc = cast<GTrunc>(getDefIgnoringCopies(Sext->getSrcReg(), MRI));
3232

@@ -59,7 +59,7 @@ bool CombinerHelper::matchSextOfTrunc(const MachineOperand &MO,
5959
}
6060

6161
bool CombinerHelper::matchZextOfTrunc(const MachineOperand &MO,
62-
BuildFnTy &MatchInfo) {
62+
BuildFnTy &MatchInfo) const {
6363
GZext *Zext = cast<GZext>(getDefIgnoringCopies(MO.getReg(), MRI));
6464
GTrunc *Trunc = cast<GTrunc>(getDefIgnoringCopies(Zext->getSrcReg(), MRI));
6565

@@ -94,7 +94,7 @@ bool CombinerHelper::matchZextOfTrunc(const MachineOperand &MO,
9494
}
9595

9696
bool CombinerHelper::matchNonNegZext(const MachineOperand &MO,
97-
BuildFnTy &MatchInfo) {
97+
BuildFnTy &MatchInfo) const {
9898
GZext *Zext = cast<GZext>(MRI.getVRegDef(MO.getReg()));
9999

100100
Register Dst = Zext->getReg(0);
@@ -116,7 +116,7 @@ bool CombinerHelper::matchNonNegZext(const MachineOperand &MO,
116116

117117
bool CombinerHelper::matchTruncateOfExt(const MachineInstr &Root,
118118
const MachineInstr &ExtMI,
119-
BuildFnTy &MatchInfo) {
119+
BuildFnTy &MatchInfo) const {
120120
const GTrunc *Trunc = cast<GTrunc>(&Root);
121121
const GExtOp *Ext = cast<GExtOp>(&ExtMI);
122122

@@ -179,7 +179,7 @@ bool CombinerHelper::isCastFree(unsigned Opcode, LLT ToTy, LLT FromTy) const {
179179

180180
bool CombinerHelper::matchCastOfSelect(const MachineInstr &CastMI,
181181
const MachineInstr &SelectMI,
182-
BuildFnTy &MatchInfo) {
182+
BuildFnTy &MatchInfo) const {
183183
const GExtOrTruncOp *Cast = cast<GExtOrTruncOp>(&CastMI);
184184
const GSelect *Select = cast<GSelect>(&SelectMI);
185185

@@ -211,7 +211,7 @@ bool CombinerHelper::matchCastOfSelect(const MachineInstr &CastMI,
211211

212212
bool CombinerHelper::matchExtOfExt(const MachineInstr &FirstMI,
213213
const MachineInstr &SecondMI,
214-
BuildFnTy &MatchInfo) {
214+
BuildFnTy &MatchInfo) const {
215215
const GExtOp *First = cast<GExtOp>(&FirstMI);
216216
const GExtOp *Second = cast<GExtOp>(&SecondMI);
217217

@@ -275,7 +275,7 @@ bool CombinerHelper::matchExtOfExt(const MachineInstr &FirstMI,
275275

276276
bool CombinerHelper::matchCastOfBuildVector(const MachineInstr &CastMI,
277277
const MachineInstr &BVMI,
278-
BuildFnTy &MatchInfo) {
278+
BuildFnTy &MatchInfo) const {
279279
const GExtOrTruncOp *Cast = cast<GExtOrTruncOp>(&CastMI);
280280
const GBuildVector *BV = cast<GBuildVector>(&BVMI);
281281

@@ -315,7 +315,7 @@ bool CombinerHelper::matchCastOfBuildVector(const MachineInstr &CastMI,
315315

316316
bool CombinerHelper::matchNarrowBinop(const MachineInstr &TruncMI,
317317
const MachineInstr &BinopMI,
318-
BuildFnTy &MatchInfo) {
318+
BuildFnTy &MatchInfo) const {
319319
const GTrunc *Trunc = cast<GTrunc>(&TruncMI);
320320
const GBinOp *BinOp = cast<GBinOp>(&BinopMI);
321321

@@ -339,7 +339,7 @@ bool CombinerHelper::matchNarrowBinop(const MachineInstr &TruncMI,
339339
}
340340

341341
bool CombinerHelper::matchCastOfInteger(const MachineInstr &CastMI,
342-
APInt &MatchInfo) {
342+
APInt &MatchInfo) const {
343343
const GExtOrTruncOp *Cast = cast<GExtOrTruncOp>(&CastMI);
344344

345345
APInt Input = getIConstantFromReg(Cast->getSrcReg(), MRI);

llvm/lib/CodeGen/GlobalISel/CombinerHelperCompares.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace llvm;
2929
bool CombinerHelper::constantFoldICmp(const GICmp &ICmp,
3030
const GIConstant &LHSCst,
3131
const GIConstant &RHSCst,
32-
BuildFnTy &MatchInfo) {
32+
BuildFnTy &MatchInfo) const {
3333
if (LHSCst.getKind() != GIConstant::GIConstantKind::Scalar)
3434
return false;
3535

@@ -60,7 +60,7 @@ bool CombinerHelper::constantFoldICmp(const GICmp &ICmp,
6060
bool CombinerHelper::constantFoldFCmp(const GFCmp &FCmp,
6161
const GFConstant &LHSCst,
6262
const GFConstant &RHSCst,
63-
BuildFnTy &MatchInfo) {
63+
BuildFnTy &MatchInfo) const {
6464
if (LHSCst.getKind() != GFConstant::GFConstantKind::Scalar)
6565
return false;
6666

@@ -89,7 +89,7 @@ bool CombinerHelper::constantFoldFCmp(const GFCmp &FCmp,
8989
}
9090

9191
bool CombinerHelper::matchCanonicalizeICmp(const MachineInstr &MI,
92-
BuildFnTy &MatchInfo) {
92+
BuildFnTy &MatchInfo) const {
9393
const GICmp *Cmp = cast<GICmp>(&MI);
9494

9595
Register Dst = Cmp->getReg(0);
@@ -114,7 +114,7 @@ bool CombinerHelper::matchCanonicalizeICmp(const MachineInstr &MI,
114114
}
115115

116116
bool CombinerHelper::matchCanonicalizeFCmp(const MachineInstr &MI,
117-
BuildFnTy &MatchInfo) {
117+
BuildFnTy &MatchInfo) const {
118118
const GFCmp *Cmp = cast<GFCmp>(&MI);
119119

120120
Register Dst = Cmp->getReg(0);

llvm/lib/CodeGen/GlobalISel/CombinerHelperVectorOps.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using namespace llvm;
3131
using namespace MIPatternMatch;
3232

3333
bool CombinerHelper::matchExtractVectorElement(MachineInstr &MI,
34-
BuildFnTy &MatchInfo) {
34+
BuildFnTy &MatchInfo) const {
3535
GExtractVectorElement *Extract = cast<GExtractVectorElement>(&MI);
3636

3737
Register Dst = Extract->getReg(0);
@@ -89,7 +89,7 @@ bool CombinerHelper::matchExtractVectorElement(MachineInstr &MI,
8989
}
9090

9191
bool CombinerHelper::matchExtractVectorElementWithDifferentIndices(
92-
const MachineOperand &MO, BuildFnTy &MatchInfo) {
92+
const MachineOperand &MO, BuildFnTy &MatchInfo) const {
9393
MachineInstr *Root = getDefIgnoringCopies(MO.getReg(), MRI);
9494
GExtractVectorElement *Extract = cast<GExtractVectorElement>(Root);
9595

@@ -146,7 +146,8 @@ bool CombinerHelper::matchExtractVectorElementWithDifferentIndices(
146146
}
147147

148148
bool CombinerHelper::matchExtractVectorElementWithBuildVector(
149-
const MachineInstr &MI, const MachineInstr &MI2, BuildFnTy &MatchInfo) {
149+
const MachineInstr &MI, const MachineInstr &MI2,
150+
BuildFnTy &MatchInfo) const {
150151
const GExtractVectorElement *Extract = cast<GExtractVectorElement>(&MI);
151152
const GBuildVector *Build = cast<GBuildVector>(&MI2);
152153

@@ -185,7 +186,7 @@ bool CombinerHelper::matchExtractVectorElementWithBuildVector(
185186
}
186187

187188
bool CombinerHelper::matchExtractVectorElementWithBuildVectorTrunc(
188-
const MachineOperand &MO, BuildFnTy &MatchInfo) {
189+
const MachineOperand &MO, BuildFnTy &MatchInfo) const {
189190
MachineInstr *Root = getDefIgnoringCopies(MO.getReg(), MRI);
190191
GExtractVectorElement *Extract = cast<GExtractVectorElement>(Root);
191192

@@ -252,7 +253,8 @@ bool CombinerHelper::matchExtractVectorElementWithBuildVectorTrunc(
252253
}
253254

254255
bool CombinerHelper::matchExtractVectorElementWithShuffleVector(
255-
const MachineInstr &MI, const MachineInstr &MI2, BuildFnTy &MatchInfo) {
256+
const MachineInstr &MI, const MachineInstr &MI2,
257+
BuildFnTy &MatchInfo) const {
256258
const GExtractVectorElement *Extract = cast<GExtractVectorElement>(&MI);
257259
const GShuffleVector *Shuffle = cast<GShuffleVector>(&MI2);
258260

@@ -338,7 +340,7 @@ bool CombinerHelper::matchExtractVectorElementWithShuffleVector(
338340
}
339341

340342
bool CombinerHelper::matchInsertVectorElementOOB(MachineInstr &MI,
341-
BuildFnTy &MatchInfo) {
343+
BuildFnTy &MatchInfo) const {
342344
GInsertVectorElement *Insert = cast<GInsertVectorElement>(&MI);
343345

344346
Register Dst = Insert->getReg(0);
@@ -361,7 +363,7 @@ bool CombinerHelper::matchInsertVectorElementOOB(MachineInstr &MI,
361363
}
362364

363365
bool CombinerHelper::matchAddOfVScale(const MachineOperand &MO,
364-
BuildFnTy &MatchInfo) {
366+
BuildFnTy &MatchInfo) const {
365367
GAdd *Add = cast<GAdd>(MRI.getVRegDef(MO.getReg()));
366368
GVScale *LHSVScale = cast<GVScale>(MRI.getVRegDef(Add->getLHSReg()));
367369
GVScale *RHSVScale = cast<GVScale>(MRI.getVRegDef(Add->getRHSReg()));
@@ -380,7 +382,7 @@ bool CombinerHelper::matchAddOfVScale(const MachineOperand &MO,
380382
}
381383

382384
bool CombinerHelper::matchMulOfVScale(const MachineOperand &MO,
383-
BuildFnTy &MatchInfo) {
385+
BuildFnTy &MatchInfo) const {
384386
GMul *Mul = cast<GMul>(MRI.getVRegDef(MO.getReg()));
385387
GVScale *LHSVScale = cast<GVScale>(MRI.getVRegDef(Mul->getLHSReg()));
386388

@@ -401,7 +403,7 @@ bool CombinerHelper::matchMulOfVScale(const MachineOperand &MO,
401403
}
402404

403405
bool CombinerHelper::matchSubOfVScale(const MachineOperand &MO,
404-
BuildFnTy &MatchInfo) {
406+
BuildFnTy &MatchInfo) const {
405407
GSub *Sub = cast<GSub>(MRI.getVRegDef(MO.getReg()));
406408
GVScale *RHSVScale = cast<GVScale>(MRI.getVRegDef(Sub->getRHSReg()));
407409

@@ -421,7 +423,7 @@ bool CombinerHelper::matchSubOfVScale(const MachineOperand &MO,
421423
}
422424

423425
bool CombinerHelper::matchShlOfVScale(const MachineOperand &MO,
424-
BuildFnTy &MatchInfo) {
426+
BuildFnTy &MatchInfo) const {
425427
GShl *Shl = cast<GShl>(MRI.getVRegDef(MO.getReg()));
426428
GVScale *LHSVScale = cast<GVScale>(MRI.getVRegDef(Shl->getSrcReg()));
427429

llvm/lib/Target/AArch64/GISel/AArch64O0PreLegalizerCombiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ namespace {
4141

4242
class AArch64O0PreLegalizerCombinerImpl : public Combiner {
4343
protected:
44-
// TODO: Make CombinerHelper methods const.
45-
mutable CombinerHelper Helper;
44+
const CombinerHelper Helper;
4645
const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig;
4746
const AArch64Subtarget &STI;
4847

llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ void applyCombineMulCMLT(MachineInstr &MI, MachineRegisterInfo &MRI,
440440

441441
class AArch64PostLegalizerCombinerImpl : public Combiner {
442442
protected:
443-
// TODO: Make CombinerHelper methods const.
444-
mutable CombinerHelper Helper;
443+
const CombinerHelper Helper;
445444
const AArch64PostLegalizerCombinerImplRuleConfig &RuleConfig;
446445
const AArch64Subtarget &STI;
447446

llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1243,8 +1243,7 @@ void applyExtMulToMULL(MachineInstr &MI, MachineRegisterInfo &MRI,
12431243

12441244
class AArch64PostLegalizerLoweringImpl : public Combiner {
12451245
protected:
1246-
// TODO: Make CombinerHelper methods const.
1247-
mutable CombinerHelper Helper;
1246+
const CombinerHelper Helper;
12481247
const AArch64PostLegalizerLoweringImplRuleConfig &RuleConfig;
12491248
const AArch64Subtarget &STI;
12501249

llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ void applyPushAddSubExt(MachineInstr &MI, MachineRegisterInfo &MRI,
605605
}
606606

607607
bool tryToSimplifyUADDO(MachineInstr &MI, MachineIRBuilder &B,
608-
CombinerHelper &Helper, GISelChangeObserver &Observer) {
608+
const CombinerHelper &Helper,
609+
GISelChangeObserver &Observer) {
609610
// Try simplify G_UADDO with 8 or 16 bit operands to wide G_ADD and TBNZ if
610611
// result is only used in the no-overflow case. It is restricted to cases
611612
// where we know that the high-bits of the operands are 0. If there's an
@@ -720,8 +721,7 @@ bool tryToSimplifyUADDO(MachineInstr &MI, MachineIRBuilder &B,
720721

721722
class AArch64PreLegalizerCombinerImpl : public Combiner {
722723
protected:
723-
// TODO: Make CombinerHelper methods const.
724-
mutable CombinerHelper Helper;
724+
const CombinerHelper Helper;
725725
const AArch64PreLegalizerCombinerImplRuleConfig &RuleConfig;
726726
const AArch64Subtarget &STI;
727727

llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ class AMDGPURegBankCombinerImpl : public Combiner {
4848
const RegisterBankInfo &RBI;
4949
const TargetRegisterInfo &TRI;
5050
const SIInstrInfo &TII;
51-
// TODO: Make CombinerHelper methods const.
52-
mutable CombinerHelper Helper;
51+
const CombinerHelper Helper;
5352

5453
public:
5554
AMDGPURegBankCombinerImpl(

llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class MipsPostLegalizerCombinerImpl : public Combiner {
4343
protected:
4444
const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig;
4545
const MipsSubtarget &STI;
46-
// TODO: Make CombinerHelper methods const.
47-
mutable CombinerHelper Helper;
46+
const CombinerHelper Helper;
4847

4948
public:
5049
MipsPostLegalizerCombinerImpl(

llvm/lib/Target/Mips/MipsPreLegalizerCombiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ struct MipsPreLegalizerCombinerInfo : public CombinerInfo {
3737
class MipsPreLegalizerCombinerImpl : public Combiner {
3838
protected:
3939
const MipsSubtarget &STI;
40-
// TODO: Make CombinerHelper methods const.
41-
mutable CombinerHelper Helper;
40+
const CombinerHelper Helper;
4241

4342
public:
4443
MipsPreLegalizerCombinerImpl(MachineFunction &MF, CombinerInfo &CInfo,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ namespace {
3838

3939
class RISCVO0PreLegalizerCombinerImpl : public Combiner {
4040
protected:
41-
// TODO: Make CombinerHelper methods const.
42-
mutable CombinerHelper Helper;
41+
const CombinerHelper Helper;
4342
const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig;
4443
const RISCVSubtarget &STI;
4544

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ namespace {
4444

4545
class RISCVPostLegalizerCombinerImpl : public Combiner {
4646
protected:
47-
// TODO: Make CombinerHelper methods const.
48-
mutable CombinerHelper Helper;
47+
const CombinerHelper Helper;
4948
const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig;
5049
const RISCVSubtarget &STI;
5150

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ namespace {
4040

4141
class RISCVPreLegalizerCombinerImpl : public Combiner {
4242
protected:
43-
// TODO: Make CombinerHelper methods const.
44-
mutable CombinerHelper Helper;
43+
const CombinerHelper Helper;
4544
const RISCVPreLegalizerCombinerImplRuleConfig &RuleConfig;
4645
const RISCVSubtarget &STI;
4746

0 commit comments

Comments
 (0)