Skip to content

Commit 1c92927

Browse files
committed
[RISCV] Use TableGen-based macro fusion
We convert existed macro fusions to TableGen. And we remove macro fusions from `TuneVentanaVeyron` bacause `Fusion` depend on `Instruction` definitions which is defined below `RISCVFeatures.td`. `ShiftedZExtFusion` is split into `ShiftedZExtHFusion` and `ShiftedZExtWFusion`. We recommend user to add fusion features when defining new processor.
1 parent c0ce4d9 commit 1c92927

14 files changed

+184
-282
lines changed

llvm/include/llvm/Target/TargetInstrPredicate.td

+34
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,34 @@ class CheckImmOperand_s<int Index, string Value> : CheckOperandBase<Index> {
152152
string ImmVal = Value;
153153
}
154154

155+
// Check that the operand at position `Index` is less than `Imm`.
156+
// If field `FunctionMapper` is a non-empty string, then function
157+
// `FunctionMapper` is applied to the operand value, and the return value is then
158+
// compared against `Imm`.
159+
class CheckImmOperandLT<int Index, int Imm> : CheckOperandBase<Index> {
160+
int ImmVal = Imm;
161+
}
162+
163+
// Check that the operand at position `Index` is less than `Imm`.
164+
// If field `FunctionMapper` is a non-empty string, then function
165+
// `FunctionMapper` is applied to the operand value, and the return value is then
166+
// compared against `Imm`.
167+
class CheckImmOperandGT<int Index, int Imm> : CheckOperandBase<Index> {
168+
int ImmVal = Imm;
169+
}
170+
171+
// Check that the operand at position `Index` is greater than or equal to `Imm`.
172+
// If field `FunctionMapper` is a non-empty string, then function
173+
// `FunctionMapper` is applied to the operand value, and the return value is then
174+
// compared against `Imm`.
175+
class CheckImmOperandGE<int Index, int Imm> : CheckNot<CheckImmOperandLT<Index, Imm>>;
176+
177+
// Check that the operand at position `Index` is less than or equal to `Imm`.
178+
// If field `FunctionMapper` is a non-empty string, then function
179+
// `FunctionMapper` is applied to the operand value, and the return value is then
180+
// compared against `Imm`.
181+
class CheckImmOperandLE<int Index, int Imm> : CheckNot<CheckImmOperandGT<Index, Imm>>;
182+
155183
// Expands to a call to `FunctionMapper` if field `FunctionMapper` is set.
156184
// Otherwise, it expands to a CheckNot<CheckInvalidRegOperand<Index>>.
157185
class CheckRegOperandSimple<int Index> : CheckOperandBase<Index>;
@@ -203,6 +231,12 @@ class CheckAll<list<MCInstPredicate> Sequence>
203231
class CheckAny<list<MCInstPredicate> Sequence>
204232
: CheckPredicateSequence<Sequence>;
205233

234+
// Check that the operand at position `Index` is in range [Start, End].
235+
// If field `FunctionMapper` is a non-empty string, then function
236+
// `FunctionMapper` is applied to the operand value, and the return value is then
237+
// compared against range [Start, End].
238+
class CheckImmOperandRange<int Index, int Start, int End>
239+
: CheckAll<[CheckImmOperandGE<Index, Start>, CheckImmOperandLE<Index, End>]>;
206240

207241
// Used to expand the body of a function predicate. See the definition of
208242
// TIIPredicate below.

llvm/lib/Target/RISCV/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(LLVM_TARGET_DEFINITIONS RISCV.td)
55
tablegen(LLVM RISCVGenAsmMatcher.inc -gen-asm-matcher)
66
tablegen(LLVM RISCVGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM RISCVGenCompressInstEmitter.inc -gen-compress-inst-emitter)
8+
tablegen(LLVM RISCVGenMacroFusion.inc -gen-macro-fusion-pred)
89
tablegen(LLVM RISCVGenDAGISel.inc -gen-dag-isel)
910
tablegen(LLVM RISCVGenDisassemblerTables.inc -gen-disassembler)
1011
tablegen(LLVM RISCVGenInstrInfo.inc -gen-instr-info)
@@ -43,7 +44,6 @@ add_llvm_target(RISCVCodeGen
4344
RISCVISelDAGToDAG.cpp
4445
RISCVISelLowering.cpp
4546
RISCVMachineFunctionInfo.cpp
46-
RISCVMacroFusion.cpp
4747
RISCVMergeBaseOffset.cpp
4848
RISCVOptWInstrs.cpp
4949
RISCVPostRAExpandPseudoInsts.cpp

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ InstSeq generateInstSeq(int64_t Val, const MCSubtargetInfo &STI) {
236236
// NOTE: We don't check for C extension to minimize differences in generated
237237
// code.
238238
bool IsShiftedCompressible =
239-
isInt<6>(ShiftedVal) && !STI.hasFeature(RISCV::TuneLUIADDIFusion);
239+
isInt<6>(ShiftedVal) && !STI.hasFeature(RISCV::LUIADDIFusion);
240240
RISCVMatInt::InstSeq TmpSeq;
241241
generateInstSeqImpl(ShiftedVal, STI, TmpSeq);
242242

llvm/lib/Target/RISCV/RISCV.td

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ include "RISCVCallingConv.td"
3030
include "RISCVInstrInfo.td"
3131
include "GISel/RISCVRegisterBanks.td"
3232

33+
//===----------------------------------------------------------------------===//
34+
// RISC-V macro fusions.
35+
//===----------------------------------------------------------------------===//
36+
37+
include "RISCVMacroFusion.td"
38+
3339
//===----------------------------------------------------------------------===//
3440
// RISC-V Scheduling Models
3541
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVFeatures.td

-24
Original file line numberDiff line numberDiff line change
@@ -985,30 +985,6 @@ def TuneDLenFactor2
985985
: SubtargetFeature<"dlen-factor-2", "DLenFactor2", "true",
986986
"Vector unit DLEN(data path width) is half of VLEN">;
987987

988-
def TuneLUIADDIFusion
989-
: SubtargetFeature<"lui-addi-fusion", "HasLUIADDIFusion",
990-
"true", "Enable LUI+ADDI macrofusion">;
991-
992-
def TuneAUIPCADDIFusion
993-
: SubtargetFeature<"auipc-addi-fusion", "HasAUIPCADDIFusion",
994-
"true", "Enable AUIPC+ADDI macrofusion">;
995-
996-
def TuneZExtHFusion
997-
: SubtargetFeature<"zexth-fusion", "HasZExtHFusion",
998-
"true", "Enable SLLI+SRLI to be fused to zero extension of halfword">;
999-
1000-
def TuneZExtWFusion
1001-
: SubtargetFeature<"zextw-fusion", "HasZExtWFusion",
1002-
"true", "Enable SLLI+SRLI to be fused to zero extension of word">;
1003-
1004-
def TuneShiftedZExtWFusion
1005-
: SubtargetFeature<"shifted-zextw-fusion", "HasShiftedZExtWFusion",
1006-
"true", "Enable SLLI+SRLI to be fused when computing (shifted) zero extension of word">;
1007-
1008-
def TuneLDADDFusion
1009-
: SubtargetFeature<"ld-add-fusion", "HasLDADDFusion",
1010-
"true", "Enable LD+ADD macrofusion.">;
1011-
1012988
def TuneNoDefaultUnroll
1013989
: SubtargetFeature<"no-default-unroll", "EnableDefaultUnroll", "false",
1014990
"Disable default unroll preference.">;

llvm/lib/Target/RISCV/RISCVMacroFusion.cpp

-210
This file was deleted.

llvm/lib/Target/RISCV/RISCVMacroFusion.h

-28
This file was deleted.

0 commit comments

Comments
 (0)