Skip to content

Commit c7e9adf

Browse files
committed
Make CombinerHelper methods const
There are a number of backends (specifically AArch64, AMDGPU, Mips, and RISCV) which contain a “TOD”: make CombinerHelper methods const” comment. This PR does just that and makes all of the CombinerHelper methods const, removes the TODO comment and makes the associated instance const. This change makes some sense because CombinerHelper simply modifies 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 796a1cf commit c7e9adf

16 files changed

+643
-554
lines changed

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

Lines changed: 309 additions & 262 deletions
Large diffs are not rendered by default.

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 295 additions & 246 deletions
Large diffs are not rendered by default.

llvm/lib/CodeGen/GlobalISel/CombinerHelperArtifacts.cpp

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 9 deletions
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

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

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

@@ -212,7 +212,7 @@ bool CombinerHelper::matchCastOfSelect(const MachineInstr &CastMI,
212212

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

@@ -276,7 +276,7 @@ bool CombinerHelper::matchExtOfExt(const MachineInstr &FirstMI,
276276

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

@@ -316,7 +316,7 @@ bool CombinerHelper::matchCastOfBuildVector(const MachineInstr &CastMI,
316316

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

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

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

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

llvm/lib/CodeGen/GlobalISel/CombinerHelperCompares.cpp

Lines changed: 4 additions & 4 deletions
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

Lines changed: 12 additions & 10 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

0 commit comments

Comments
 (0)