Skip to content

Commit 31d8a99

Browse files
committed
[RISCV] Use TableGen-based macro fusion
We convert LUIADDI macro fusion to TableGen. For test, I added `MacroFusions` to `SiFive7Model`.
1 parent f4cd61c commit 31d8a99

13 files changed

+44
-121
lines changed

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
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/RISCVMCTargetDesc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ std::unique_ptr<MCObjectTargetWriter> createRISCVELFObjectWriter(uint8_t OSABI,
4848
#define GET_INSTRINFO_MC_HELPER_DECLS
4949
#include "RISCVGenInstrInfo.inc"
5050

51+
#define GET_MACRO_FUSION_ENUM
52+
#include "RISCVGenMacroFusion.inc"
53+
5154
#define GET_SUBTARGETINFO_ENUM
5255
#include "RISCVGenSubtargetInfo.inc"
5356

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

Lines changed: 1 addition & 1 deletion
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.hasMacroFusion(RISCV::LUIADDI);
240240
RISCVMatInt::InstSeq TmpSeq;
241241
generateInstSeqImpl(ShiftedVal, STI, TmpSeq);
242242

llvm/lib/Target/RISCV/RISCV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ include "GISel/RISCVRegisterBanks.td"
3434
// RISC-V Scheduling Models
3535
//===----------------------------------------------------------------------===//
3636

37+
include "RISCVMacroFusion.td"
3738
include "RISCVSchedRocket.td"
3839
include "RISCVSchedSiFive7.td"
3940
include "RISCVSchedSyntacoreSCR1.td"

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -971,10 +971,6 @@ def TuneDLenFactor2
971971
: SubtargetFeature<"dlen-factor-2", "DLenFactor2", "true",
972972
"Vector unit DLEN(data path width) is half of VLEN">;
973973

974-
def TuneLUIADDIFusion
975-
: SubtargetFeature<"lui-addi-fusion", "HasLUIADDIFusion",
976-
"true", "Enable LUI+ADDI macrofusion">;
977-
978974
def TuneNoDefaultUnroll
979975
: SubtargetFeature<"no-default-unroll", "EnableDefaultUnroll", "false",
980976
"Disable default unroll preference.">;
@@ -993,8 +989,7 @@ def TuneSiFive7 : SubtargetFeature<"sifive7", "RISCVProcFamily", "SiFive7",
993989
TuneShortForwardBranchOpt]>;
994990

995991
def TuneVentanaVeyron : SubtargetFeature<"ventana-veyron", "RISCVProcFamily", "VentanaVeyron",
996-
"Ventana-Veyron Series processors",
997-
[TuneLUIADDIFusion]>;
992+
"Ventana-Veyron Series processors">;
998993

999994
// Assume that lock-free native-width atomics are available, even if the target
1000995
// and operating system combination would not usually provide them. The user

llvm/lib/Target/RISCV/RISCVMacroFusion.cpp

Lines changed: 0 additions & 69 deletions
This file was deleted.

llvm/lib/Target/RISCV/RISCVMacroFusion.h

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//==----- RISCVMacroFusion.td - Macro Fusion Definitions -----*- tablegen -*-=//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// ===---------------------------------------------------------------------===//
10+
// The following definitions describe the macro fusion predicators.
11+
12+
def LUIADDI: SimpleFusion<CheckOpcode<[LUI]>, CheckOpcode<[ADDI, ADDIW]>>;

llvm/lib/Target/RISCV/RISCVSchedSiFive7.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def SiFive7Model : SchedMachineModel {
200200
HasStdExtZcmt, HasStdExtZknd, HasStdExtZkne,
201201
HasStdExtZknh, HasStdExtZksed, HasStdExtZksh,
202202
HasStdExtZkr];
203+
let MacroFusions = [LUIADDI];
203204
}
204205

205206
// The SiFive7 microarchitecture has three pipelines: A, B, V.

llvm/lib/Target/RISCV/RISCVSubtarget.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#include "GISel/RISCVRegisterBankInfo.h"
1717
#include "RISCV.h"
1818
#include "RISCVFrameLowering.h"
19-
#include "RISCVMacroFusion.h"
2019
#include "RISCVTargetMachine.h"
20+
#include "llvm/CodeGen/MacroFusion.h"
21+
#include "llvm/CodeGen/ScheduleDAGMutation.h"
2122
#include "llvm/MC/TargetRegistry.h"
2223
#include "llvm/Support/ErrorHandling.h"
2324

@@ -29,11 +30,16 @@ using namespace llvm;
2930
#define GET_SUBTARGETINFO_CTOR
3031
#include "RISCVGenSubtargetInfo.inc"
3132

32-
namespace llvm::RISCVTuneInfoTable {
33+
namespace llvm {
34+
#define GET_RISCV_MACRO_FUSION_PRED_IMPL
35+
#include "RISCVGenMacroFusion.inc"
36+
37+
namespace RISCVTuneInfoTable {
3338

3439
#define GET_RISCVTuneInfoTable_IMPL
3540
#include "RISCVGenSearchableTables.inc"
36-
} // namespace llvm::RISCVTuneInfoTable
41+
} // namespace RISCVTuneInfoTable
42+
} // namespace llvm
3743

3844
static cl::opt<bool> EnableSubRegLiveness("riscv-enable-subreg-liveness",
3945
cl::init(true), cl::Hidden);
@@ -183,7 +189,7 @@ bool RISCVSubtarget::enableSubRegLiveness() const {
183189

184190
void RISCVSubtarget::getPostRAMutations(
185191
std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
186-
Mutations.push_back(createRISCVMacroFusionDAGMutation());
192+
Mutations.push_back(createMacroFusionDAGMutation(getMacroFusions()));
187193
}
188194

189195
/// Enable use of alias analysis during code generation (during MI

0 commit comments

Comments
 (0)