Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
571 changes: 309 additions & 262 deletions llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h

Large diffs are not rendered by default.

541 changes: 295 additions & 246 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelperArtifacts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelperCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelperCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
22 changes: 12 additions & 10 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelperVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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()));
Expand All @@ -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()));

Expand All @@ -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()));

Expand All @@ -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()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class AMDGPURegBankCombinerImpl : public Combiner {
const RegisterBankInfo &RBI;
const TargetRegisterInfo &TRI;
const SIInstrInfo &TII;
// TODO: Make CombinerHelper methods const.
mutable CombinerHelper Helper;
const CombinerHelper Helper;

public:
AMDGPURegBankCombinerImpl(
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Mips/MipsPreLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ struct MipsPreLegalizerCombinerInfo : public CombinerInfo {
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,
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/RISCV/GISel/RISCVO0PreLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/RISCV/GISel/RISCVPostLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/RISCV/GISel/RISCVPreLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading