Skip to content

Commit b564036

Browse files
authored
[MachineCombiner][NFC] Split target-dependent patterns
We split target-dependent MachineCombiner patterns into their target folder. This makes MachineCombiner much more target-independent. Reviewers: davemgreen, asavonic, rotateright, RKSimon, lukel97, LuoYuanke, topperc, mshockwave, asi-sc Reviewed By: topperc, mshockwave Pull Request: #87991
1 parent 53003e3 commit b564036

File tree

12 files changed

+642
-602
lines changed

12 files changed

+642
-602
lines changed

llvm/include/llvm/CodeGen/MachineCombinerPattern.h

Lines changed: 10 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -16,172 +16,24 @@
1616

1717
namespace llvm {
1818

19+
/// The combiner's goal may differ based on which pattern it is attempting
20+
/// to optimize.
21+
enum class CombinerObjective {
22+
MustReduceDepth, // The data dependency chain must be improved.
23+
MustReduceRegisterPressure, // The register pressure must be reduced.
24+
Default // The critical path must not be lengthened.
25+
};
26+
1927
/// These are instruction patterns matched by the machine combiner pass.
20-
enum class MachineCombinerPattern {
28+
enum MachineCombinerPattern : unsigned {
2129
// These are commutative variants for reassociating a computation chain. See
2230
// the comments before getMachineCombinerPatterns() in TargetInstrInfo.cpp.
2331
REASSOC_AX_BY,
2432
REASSOC_AX_YB,
2533
REASSOC_XA_BY,
2634
REASSOC_XA_YB,
2735

28-
// These are patterns matched by the PowerPC to reassociate FMA chains.
29-
REASSOC_XY_AMM_BMM,
30-
REASSOC_XMM_AMM_BMM,
31-
32-
// These are patterns matched by the PowerPC to reassociate FMA and FSUB to
33-
// reduce register pressure.
34-
REASSOC_XY_BCA,
35-
REASSOC_XY_BAC,
36-
37-
// These are patterns used to reduce the length of dependence chain.
38-
SUBADD_OP1,
39-
SUBADD_OP2,
40-
41-
// These are multiply-add patterns matched by the AArch64 machine combiner.
42-
MULADDW_OP1,
43-
MULADDW_OP2,
44-
MULSUBW_OP1,
45-
MULSUBW_OP2,
46-
MULADDWI_OP1,
47-
MULSUBWI_OP1,
48-
MULADDX_OP1,
49-
MULADDX_OP2,
50-
MULSUBX_OP1,
51-
MULSUBX_OP2,
52-
MULADDXI_OP1,
53-
MULSUBXI_OP1,
54-
// NEON integers vectors
55-
MULADDv8i8_OP1,
56-
MULADDv8i8_OP2,
57-
MULADDv16i8_OP1,
58-
MULADDv16i8_OP2,
59-
MULADDv4i16_OP1,
60-
MULADDv4i16_OP2,
61-
MULADDv8i16_OP1,
62-
MULADDv8i16_OP2,
63-
MULADDv2i32_OP1,
64-
MULADDv2i32_OP2,
65-
MULADDv4i32_OP1,
66-
MULADDv4i32_OP2,
67-
68-
MULSUBv8i8_OP1,
69-
MULSUBv8i8_OP2,
70-
MULSUBv16i8_OP1,
71-
MULSUBv16i8_OP2,
72-
MULSUBv4i16_OP1,
73-
MULSUBv4i16_OP2,
74-
MULSUBv8i16_OP1,
75-
MULSUBv8i16_OP2,
76-
MULSUBv2i32_OP1,
77-
MULSUBv2i32_OP2,
78-
MULSUBv4i32_OP1,
79-
MULSUBv4i32_OP2,
80-
81-
MULADDv4i16_indexed_OP1,
82-
MULADDv4i16_indexed_OP2,
83-
MULADDv8i16_indexed_OP1,
84-
MULADDv8i16_indexed_OP2,
85-
MULADDv2i32_indexed_OP1,
86-
MULADDv2i32_indexed_OP2,
87-
MULADDv4i32_indexed_OP1,
88-
MULADDv4i32_indexed_OP2,
89-
90-
MULSUBv4i16_indexed_OP1,
91-
MULSUBv4i16_indexed_OP2,
92-
MULSUBv8i16_indexed_OP1,
93-
MULSUBv8i16_indexed_OP2,
94-
MULSUBv2i32_indexed_OP1,
95-
MULSUBv2i32_indexed_OP2,
96-
MULSUBv4i32_indexed_OP1,
97-
MULSUBv4i32_indexed_OP2,
98-
99-
// Floating Point
100-
FMULADDH_OP1,
101-
FMULADDH_OP2,
102-
FMULSUBH_OP1,
103-
FMULSUBH_OP2,
104-
FMULADDS_OP1,
105-
FMULADDS_OP2,
106-
FMULSUBS_OP1,
107-
FMULSUBS_OP2,
108-
FMULADDD_OP1,
109-
FMULADDD_OP2,
110-
FMULSUBD_OP1,
111-
FMULSUBD_OP2,
112-
FNMULSUBH_OP1,
113-
FNMULSUBS_OP1,
114-
FNMULSUBD_OP1,
115-
FMLAv1i32_indexed_OP1,
116-
FMLAv1i32_indexed_OP2,
117-
FMLAv1i64_indexed_OP1,
118-
FMLAv1i64_indexed_OP2,
119-
FMLAv4f16_OP1,
120-
FMLAv4f16_OP2,
121-
FMLAv8f16_OP1,
122-
FMLAv8f16_OP2,
123-
FMLAv2f32_OP2,
124-
FMLAv2f32_OP1,
125-
FMLAv2f64_OP1,
126-
FMLAv2f64_OP2,
127-
FMLAv4i16_indexed_OP1,
128-
FMLAv4i16_indexed_OP2,
129-
FMLAv8i16_indexed_OP1,
130-
FMLAv8i16_indexed_OP2,
131-
FMLAv2i32_indexed_OP1,
132-
FMLAv2i32_indexed_OP2,
133-
FMLAv2i64_indexed_OP1,
134-
FMLAv2i64_indexed_OP2,
135-
FMLAv4f32_OP1,
136-
FMLAv4f32_OP2,
137-
FMLAv4i32_indexed_OP1,
138-
FMLAv4i32_indexed_OP2,
139-
FMLSv1i32_indexed_OP2,
140-
FMLSv1i64_indexed_OP2,
141-
FMLSv4f16_OP1,
142-
FMLSv4f16_OP2,
143-
FMLSv8f16_OP1,
144-
FMLSv8f16_OP2,
145-
FMLSv2f32_OP1,
146-
FMLSv2f32_OP2,
147-
FMLSv2f64_OP1,
148-
FMLSv2f64_OP2,
149-
FMLSv4i16_indexed_OP1,
150-
FMLSv4i16_indexed_OP2,
151-
FMLSv8i16_indexed_OP1,
152-
FMLSv8i16_indexed_OP2,
153-
FMLSv2i32_indexed_OP1,
154-
FMLSv2i32_indexed_OP2,
155-
FMLSv2i64_indexed_OP1,
156-
FMLSv2i64_indexed_OP2,
157-
FMLSv4f32_OP1,
158-
FMLSv4f32_OP2,
159-
FMLSv4i32_indexed_OP1,
160-
FMLSv4i32_indexed_OP2,
161-
162-
FMULv2i32_indexed_OP1,
163-
FMULv2i32_indexed_OP2,
164-
FMULv2i64_indexed_OP1,
165-
FMULv2i64_indexed_OP2,
166-
FMULv4i16_indexed_OP1,
167-
FMULv4i16_indexed_OP2,
168-
FMULv4i32_indexed_OP1,
169-
FMULv4i32_indexed_OP2,
170-
FMULv8i16_indexed_OP1,
171-
FMULv8i16_indexed_OP2,
172-
173-
// RISCV FMADD, FMSUB, FNMSUB patterns
174-
FMADD_AX,
175-
FMADD_XA,
176-
FMSUB,
177-
FNMSUB,
178-
SHXADD_ADD_SLLI_OP1,
179-
SHXADD_ADD_SLLI_OP2,
180-
181-
// X86 VNNI
182-
DPWSSD,
183-
184-
FNMADD,
36+
TARGET_PATTERN_START
18537
};
18638

18739
} // end namespace llvm

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/Uniformity.h"
2020
#include "llvm/CodeGen/MIRFormatter.h"
2121
#include "llvm/CodeGen/MachineBasicBlock.h"
22+
#include "llvm/CodeGen/MachineCombinerPattern.h"
2223
#include "llvm/CodeGen/MachineCycleAnalysis.h"
2324
#include "llvm/CodeGen/MachineFunction.h"
2425
#include "llvm/CodeGen/MachineInstr.h"
@@ -61,7 +62,6 @@ class TargetRegisterClass;
6162
class TargetRegisterInfo;
6263
class TargetSchedModel;
6364
class TargetSubtargetInfo;
64-
enum class MachineCombinerPattern;
6565
enum class MachineTraceStrategy;
6666

6767
template <class T> class SmallVectorImpl;
@@ -1191,10 +1191,9 @@ class TargetInstrInfo : public MCInstrInfo {
11911191
/// faster sequence.
11921192
/// \param Root - Instruction that could be combined with one of its operands
11931193
/// \param Patterns - Vector of possible combination patterns
1194-
virtual bool
1195-
getMachineCombinerPatterns(MachineInstr &Root,
1196-
SmallVectorImpl<MachineCombinerPattern> &Patterns,
1197-
bool DoRegPressureReduce) const;
1194+
virtual bool getMachineCombinerPatterns(MachineInstr &Root,
1195+
SmallVectorImpl<unsigned> &Patterns,
1196+
bool DoRegPressureReduce) const;
11981197

11991198
/// Return true if target supports reassociation of instructions in machine
12001199
/// combiner pass to reduce register pressure for a given BB.
@@ -1206,13 +1205,17 @@ class TargetInstrInfo : public MCInstrInfo {
12061205

12071206
/// Fix up the placeholder we may add in genAlternativeCodeSequence().
12081207
virtual void
1209-
finalizeInsInstrs(MachineInstr &Root, MachineCombinerPattern &P,
1208+
finalizeInsInstrs(MachineInstr &Root, unsigned &Pattern,
12101209
SmallVectorImpl<MachineInstr *> &InsInstrs) const {}
12111210

12121211
/// Return true when a code sequence can improve throughput. It
12131212
/// should be called only for instructions in loops.
12141213
/// \param Pattern - combiner pattern
1215-
virtual bool isThroughputPattern(MachineCombinerPattern Pattern) const;
1214+
virtual bool isThroughputPattern(unsigned Pattern) const;
1215+
1216+
/// Return the objective of a combiner pattern.
1217+
/// \param Pattern - combiner pattern
1218+
virtual CombinerObjective getCombinerObjective(unsigned Pattern) const;
12161219

12171220
/// Return true if the input \P Inst is part of a chain of dependent ops
12181221
/// that are suitable for reassociation, otherwise return false.
@@ -1256,7 +1259,7 @@ class TargetInstrInfo : public MCInstrInfo {
12561259
/// \param InstIdxForVirtReg - map of virtual register to instruction in
12571260
/// InsInstr that defines it
12581261
virtual void genAlternativeCodeSequence(
1259-
MachineInstr &Root, MachineCombinerPattern Pattern,
1262+
MachineInstr &Root, unsigned Pattern,
12601263
SmallVectorImpl<MachineInstr *> &InsInstrs,
12611264
SmallVectorImpl<MachineInstr *> &DelInstrs,
12621265
DenseMap<unsigned, unsigned> &InstIdxForVirtReg) const;
@@ -1270,8 +1273,7 @@ class TargetInstrInfo : public MCInstrInfo {
12701273

12711274
/// Attempt to reassociate \P Root and \P Prev according to \P Pattern to
12721275
/// reduce critical path length.
1273-
void reassociateOps(MachineInstr &Root, MachineInstr &Prev,
1274-
MachineCombinerPattern Pattern,
1276+
void reassociateOps(MachineInstr &Root, MachineInstr &Prev, unsigned Pattern,
12751277
SmallVectorImpl<MachineInstr *> &InsInstrs,
12761278
SmallVectorImpl<MachineInstr *> &DelInstrs,
12771279
DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const;
@@ -1281,8 +1283,7 @@ class TargetInstrInfo : public MCInstrInfo {
12811283
/// (new root opcode, new prev opcode) that must be used to reassociate \P
12821284
/// Root and \P Prev accoring to \P Pattern.
12831285
std::pair<unsigned, unsigned>
1284-
getReassociationOpcodes(MachineCombinerPattern Pattern,
1285-
const MachineInstr &Root,
1286+
getReassociationOpcodes(unsigned Pattern, const MachineInstr &Root,
12861287
const MachineInstr &Prev) const;
12871288

12881289
/// The limit on resource length extension we accept in MachineCombiner Pass.

0 commit comments

Comments
 (0)