Make CombinerHelper methods const (#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.
This commit is contained in:
committed by
GitHub
parent
eb1b9fca9c
commit
ee7ca0ddda
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@
|
||||
using namespace llvm;
|
||||
|
||||
bool CombinerHelper::matchMergeXAndUndef(const MachineInstr &MI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GMerge *Merge = cast<GMerge>(&MI);
|
||||
|
||||
Register Dst = Merge->getReg(0);
|
||||
@@ -58,7 +58,7 @@ bool CombinerHelper::matchMergeXAndUndef(const MachineInstr &MI,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchMergeXAndZero(const MachineInstr &MI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GMerge *Merge = cast<GMerge>(&MI);
|
||||
|
||||
Register Dst = Merge->getReg(0);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
using namespace llvm;
|
||||
|
||||
bool CombinerHelper::matchSextOfTrunc(const MachineOperand &MO,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GSext *Sext = cast<GSext>(getDefIgnoringCopies(MO.getReg(), MRI));
|
||||
GTrunc *Trunc = cast<GTrunc>(getDefIgnoringCopies(Sext->getSrcReg(), MRI));
|
||||
|
||||
@@ -59,7 +59,7 @@ bool CombinerHelper::matchSextOfTrunc(const MachineOperand &MO,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchZextOfTrunc(const MachineOperand &MO,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GZext *Zext = cast<GZext>(getDefIgnoringCopies(MO.getReg(), MRI));
|
||||
GTrunc *Trunc = cast<GTrunc>(getDefIgnoringCopies(Zext->getSrcReg(), MRI));
|
||||
|
||||
@@ -94,7 +94,7 @@ bool CombinerHelper::matchZextOfTrunc(const MachineOperand &MO,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchNonNegZext(const MachineOperand &MO,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GZext *Zext = cast<GZext>(MRI.getVRegDef(MO.getReg()));
|
||||
|
||||
Register Dst = Zext->getReg(0);
|
||||
@@ -116,7 +116,7 @@ bool CombinerHelper::matchNonNegZext(const MachineOperand &MO,
|
||||
|
||||
bool CombinerHelper::matchTruncateOfExt(const MachineInstr &Root,
|
||||
const MachineInstr &ExtMI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GTrunc *Trunc = cast<GTrunc>(&Root);
|
||||
const GExtOp *Ext = cast<GExtOp>(&ExtMI);
|
||||
|
||||
@@ -179,7 +179,7 @@ bool CombinerHelper::isCastFree(unsigned Opcode, LLT ToTy, LLT FromTy) const {
|
||||
|
||||
bool CombinerHelper::matchCastOfSelect(const MachineInstr &CastMI,
|
||||
const MachineInstr &SelectMI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GExtOrTruncOp *Cast = cast<GExtOrTruncOp>(&CastMI);
|
||||
const GSelect *Select = cast<GSelect>(&SelectMI);
|
||||
|
||||
@@ -211,7 +211,7 @@ bool CombinerHelper::matchCastOfSelect(const MachineInstr &CastMI,
|
||||
|
||||
bool CombinerHelper::matchExtOfExt(const MachineInstr &FirstMI,
|
||||
const MachineInstr &SecondMI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GExtOp *First = cast<GExtOp>(&FirstMI);
|
||||
const GExtOp *Second = cast<GExtOp>(&SecondMI);
|
||||
|
||||
@@ -275,7 +275,7 @@ bool CombinerHelper::matchExtOfExt(const MachineInstr &FirstMI,
|
||||
|
||||
bool CombinerHelper::matchCastOfBuildVector(const MachineInstr &CastMI,
|
||||
const MachineInstr &BVMI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GExtOrTruncOp *Cast = cast<GExtOrTruncOp>(&CastMI);
|
||||
const GBuildVector *BV = cast<GBuildVector>(&BVMI);
|
||||
|
||||
@@ -315,7 +315,7 @@ bool CombinerHelper::matchCastOfBuildVector(const MachineInstr &CastMI,
|
||||
|
||||
bool CombinerHelper::matchNarrowBinop(const MachineInstr &TruncMI,
|
||||
const MachineInstr &BinopMI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GTrunc *Trunc = cast<GTrunc>(&TruncMI);
|
||||
const GBinOp *BinOp = cast<GBinOp>(&BinopMI);
|
||||
|
||||
@@ -339,7 +339,7 @@ bool CombinerHelper::matchNarrowBinop(const MachineInstr &TruncMI,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchCastOfInteger(const MachineInstr &CastMI,
|
||||
APInt &MatchInfo) {
|
||||
APInt &MatchInfo) const {
|
||||
const GExtOrTruncOp *Cast = cast<GExtOrTruncOp>(&CastMI);
|
||||
|
||||
APInt Input = getIConstantFromReg(Cast->getSrcReg(), MRI);
|
||||
|
||||
@@ -29,7 +29,7 @@ using namespace llvm;
|
||||
bool CombinerHelper::constantFoldICmp(const GICmp &ICmp,
|
||||
const GIConstant &LHSCst,
|
||||
const GIConstant &RHSCst,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
if (LHSCst.getKind() != GIConstant::GIConstantKind::Scalar)
|
||||
return false;
|
||||
|
||||
@@ -60,7 +60,7 @@ bool CombinerHelper::constantFoldICmp(const GICmp &ICmp,
|
||||
bool CombinerHelper::constantFoldFCmp(const GFCmp &FCmp,
|
||||
const GFConstant &LHSCst,
|
||||
const GFConstant &RHSCst,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
if (LHSCst.getKind() != GFConstant::GFConstantKind::Scalar)
|
||||
return false;
|
||||
|
||||
@@ -89,7 +89,7 @@ bool CombinerHelper::constantFoldFCmp(const GFCmp &FCmp,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchCanonicalizeICmp(const MachineInstr &MI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GICmp *Cmp = cast<GICmp>(&MI);
|
||||
|
||||
Register Dst = Cmp->getReg(0);
|
||||
@@ -114,7 +114,7 @@ bool CombinerHelper::matchCanonicalizeICmp(const MachineInstr &MI,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchCanonicalizeFCmp(const MachineInstr &MI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GFCmp *Cmp = cast<GFCmp>(&MI);
|
||||
|
||||
Register Dst = Cmp->getReg(0);
|
||||
|
||||
@@ -31,7 +31,7 @@ using namespace llvm;
|
||||
using namespace MIPatternMatch;
|
||||
|
||||
bool CombinerHelper::matchExtractVectorElement(MachineInstr &MI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GExtractVectorElement *Extract = cast<GExtractVectorElement>(&MI);
|
||||
|
||||
Register Dst = Extract->getReg(0);
|
||||
@@ -89,7 +89,7 @@ bool CombinerHelper::matchExtractVectorElement(MachineInstr &MI,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchExtractVectorElementWithDifferentIndices(
|
||||
const MachineOperand &MO, BuildFnTy &MatchInfo) {
|
||||
const MachineOperand &MO, BuildFnTy &MatchInfo) const {
|
||||
MachineInstr *Root = getDefIgnoringCopies(MO.getReg(), MRI);
|
||||
GExtractVectorElement *Extract = cast<GExtractVectorElement>(Root);
|
||||
|
||||
@@ -146,7 +146,8 @@ bool CombinerHelper::matchExtractVectorElementWithDifferentIndices(
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchExtractVectorElementWithBuildVector(
|
||||
const MachineInstr &MI, const MachineInstr &MI2, BuildFnTy &MatchInfo) {
|
||||
const MachineInstr &MI, const MachineInstr &MI2,
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GExtractVectorElement *Extract = cast<GExtractVectorElement>(&MI);
|
||||
const GBuildVector *Build = cast<GBuildVector>(&MI2);
|
||||
|
||||
@@ -185,7 +186,7 @@ bool CombinerHelper::matchExtractVectorElementWithBuildVector(
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchExtractVectorElementWithBuildVectorTrunc(
|
||||
const MachineOperand &MO, BuildFnTy &MatchInfo) {
|
||||
const MachineOperand &MO, BuildFnTy &MatchInfo) const {
|
||||
MachineInstr *Root = getDefIgnoringCopies(MO.getReg(), MRI);
|
||||
GExtractVectorElement *Extract = cast<GExtractVectorElement>(Root);
|
||||
|
||||
@@ -252,7 +253,8 @@ bool CombinerHelper::matchExtractVectorElementWithBuildVectorTrunc(
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchExtractVectorElementWithShuffleVector(
|
||||
const MachineInstr &MI, const MachineInstr &MI2, BuildFnTy &MatchInfo) {
|
||||
const MachineInstr &MI, const MachineInstr &MI2,
|
||||
BuildFnTy &MatchInfo) const {
|
||||
const GExtractVectorElement *Extract = cast<GExtractVectorElement>(&MI);
|
||||
const GShuffleVector *Shuffle = cast<GShuffleVector>(&MI2);
|
||||
|
||||
@@ -338,7 +340,7 @@ bool CombinerHelper::matchExtractVectorElementWithShuffleVector(
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchInsertVectorElementOOB(MachineInstr &MI,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GInsertVectorElement *Insert = cast<GInsertVectorElement>(&MI);
|
||||
|
||||
Register Dst = Insert->getReg(0);
|
||||
@@ -361,7 +363,7 @@ bool CombinerHelper::matchInsertVectorElementOOB(MachineInstr &MI,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchAddOfVScale(const MachineOperand &MO,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GAdd *Add = cast<GAdd>(MRI.getVRegDef(MO.getReg()));
|
||||
GVScale *LHSVScale = cast<GVScale>(MRI.getVRegDef(Add->getLHSReg()));
|
||||
GVScale *RHSVScale = cast<GVScale>(MRI.getVRegDef(Add->getRHSReg()));
|
||||
@@ -380,7 +382,7 @@ bool CombinerHelper::matchAddOfVScale(const MachineOperand &MO,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchMulOfVScale(const MachineOperand &MO,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GMul *Mul = cast<GMul>(MRI.getVRegDef(MO.getReg()));
|
||||
GVScale *LHSVScale = cast<GVScale>(MRI.getVRegDef(Mul->getLHSReg()));
|
||||
|
||||
@@ -401,7 +403,7 @@ bool CombinerHelper::matchMulOfVScale(const MachineOperand &MO,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchSubOfVScale(const MachineOperand &MO,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GSub *Sub = cast<GSub>(MRI.getVRegDef(MO.getReg()));
|
||||
GVScale *RHSVScale = cast<GVScale>(MRI.getVRegDef(Sub->getRHSReg()));
|
||||
|
||||
@@ -421,7 +423,7 @@ bool CombinerHelper::matchSubOfVScale(const MachineOperand &MO,
|
||||
}
|
||||
|
||||
bool CombinerHelper::matchShlOfVScale(const MachineOperand &MO,
|
||||
BuildFnTy &MatchInfo) {
|
||||
BuildFnTy &MatchInfo) const {
|
||||
GShl *Shl = cast<GShl>(MRI.getVRegDef(MO.getReg()));
|
||||
GVScale *LHSVScale = cast<GVScale>(MRI.getVRegDef(Shl->getSrcReg()));
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ namespace {
|
||||
|
||||
class AArch64O0PreLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig;
|
||||
const AArch64Subtarget &STI;
|
||||
|
||||
|
||||
@@ -440,8 +440,7 @@ void applyCombineMulCMLT(MachineInstr &MI, MachineRegisterInfo &MRI,
|
||||
|
||||
class AArch64PostLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
const AArch64PostLegalizerCombinerImplRuleConfig &RuleConfig;
|
||||
const AArch64Subtarget &STI;
|
||||
|
||||
|
||||
@@ -1243,8 +1243,7 @@ void applyExtMulToMULL(MachineInstr &MI, MachineRegisterInfo &MRI,
|
||||
|
||||
class AArch64PostLegalizerLoweringImpl : public Combiner {
|
||||
protected:
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
const AArch64PostLegalizerLoweringImplRuleConfig &RuleConfig;
|
||||
const AArch64Subtarget &STI;
|
||||
|
||||
|
||||
@@ -605,7 +605,8 @@ void applyPushAddSubExt(MachineInstr &MI, MachineRegisterInfo &MRI,
|
||||
}
|
||||
|
||||
bool tryToSimplifyUADDO(MachineInstr &MI, MachineIRBuilder &B,
|
||||
CombinerHelper &Helper, GISelChangeObserver &Observer) {
|
||||
const CombinerHelper &Helper,
|
||||
GISelChangeObserver &Observer) {
|
||||
// Try simplify G_UADDO with 8 or 16 bit operands to wide G_ADD and TBNZ if
|
||||
// result is only used in the no-overflow case. It is restricted to cases
|
||||
// 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,
|
||||
|
||||
class AArch64PreLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
const AArch64PreLegalizerCombinerImplRuleConfig &RuleConfig;
|
||||
const AArch64Subtarget &STI;
|
||||
|
||||
|
||||
@@ -48,8 +48,7 @@ protected:
|
||||
const RegisterBankInfo &RBI;
|
||||
const TargetRegisterInfo &TRI;
|
||||
const SIInstrInfo &TII;
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
|
||||
public:
|
||||
AMDGPURegBankCombinerImpl(
|
||||
|
||||
@@ -43,8 +43,7 @@ class MipsPostLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig;
|
||||
const MipsSubtarget &STI;
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
|
||||
public:
|
||||
MipsPostLegalizerCombinerImpl(
|
||||
|
||||
@@ -37,8 +37,7 @@ public:
|
||||
class MipsPreLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
const MipsSubtarget &STI;
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
|
||||
public:
|
||||
MipsPreLegalizerCombinerImpl(MachineFunction &MF, CombinerInfo &CInfo,
|
||||
|
||||
@@ -38,8 +38,7 @@ namespace {
|
||||
|
||||
class RISCVO0PreLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig;
|
||||
const RISCVSubtarget &STI;
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ namespace {
|
||||
|
||||
class RISCVPostLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig;
|
||||
const RISCVSubtarget &STI;
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ namespace {
|
||||
|
||||
class RISCVPreLegalizerCombinerImpl : public Combiner {
|
||||
protected:
|
||||
// TODO: Make CombinerHelper methods const.
|
||||
mutable CombinerHelper Helper;
|
||||
const CombinerHelper Helper;
|
||||
const RISCVPreLegalizerCombinerImplRuleConfig &RuleConfig;
|
||||
const RISCVSubtarget &STI;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user