• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//==- RISCVSchedRocket32.td - Rocket Scheduling 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 simpler per-operand machine model.
11// This works with MachineScheduler. See MCSchedule.h for details.
12
13// Rocket machine model for scheduling and other instruction cost heuristics.
14def Rocket32Model : SchedMachineModel {
15  let MicroOpBufferSize = 0; // Explicitly set to zero since Rocket is in-order.
16  let IssueWidth = 1;        // 1 micro-ops are dispatched per cycle.
17  let LoadLatency = 3;
18  let MispredictPenalty = 3;
19  let CompleteModel = 1;
20}
21
22//===----------------------------------------------------------------------===//
23// Define each kind of processor resource and number available.
24
25// Modeling each pipeline as a ProcResource using the BufferSize = 0 since
26// Rocket is in-order.
27
28let BufferSize = 0 in {
29def Rocket32UnitALU        : ProcResource<1>; // Int ALU
30def Rocket32UnitIMul       : ProcResource<1>; // Int Multiply
31def Rocket32UnitMem        : ProcResource<1>; // Load/Store
32def Rocket32UnitB          : ProcResource<1>; // Branch
33
34def Rocket32UnitFPALU      : ProcResource<1>; // FP ALU
35}
36
37let BufferSize = 1 in {
38def Rocket32UnitIDiv       : ProcResource<1>; // Int Division
39def Rocket32UnitFPDivSqrt  : ProcResource<1>; // FP Divide/Sqrt'
40}
41
42//===----------------------------------------------------------------------===//
43// Subtarget-specific SchedWrite types which both map the ProcResources and
44// set the latency.
45
46let SchedModel = Rocket32Model in {
47
48def : WriteRes<WriteJmp, [Rocket32UnitB]>;
49def : WriteRes<WriteJal, [Rocket32UnitB]>;
50def : WriteRes<WriteJalr, [Rocket32UnitB]>;
51def : WriteRes<WriteJmpReg, [Rocket32UnitB]>;
52
53def : WriteRes<WriteIALU, [Rocket32UnitALU]>;
54def : WriteRes<WriteShift, [Rocket32UnitALU]>;
55
56// Multiplies on Rocket differ by implementation; placeholder until
57// we can determine how to read from command line
58def : WriteRes<WriteIMul, [Rocket32UnitIMul]> { let Latency = 4; }
59
60// 32-bit divides have worse case latency of 34 cycle
61def : WriteRes<WriteIDiv, [Rocket32UnitIDiv]> {
62  let Latency = 34;
63  let ResourceCycles = [34];
64}
65
66// Memory
67def : WriteRes<WriteSTB, [Rocket32UnitMem]>;
68def : WriteRes<WriteSTH, [Rocket32UnitMem]>;
69def : WriteRes<WriteSTW, [Rocket32UnitMem]>;
70def : WriteRes<WriteFST32, [Rocket32UnitMem]>;
71def : WriteRes<WriteFST64, [Rocket32UnitMem]>;
72
73let Latency = 3 in {
74def : WriteRes<WriteLDB, [Rocket32UnitMem]>;
75def : WriteRes<WriteLDH, [Rocket32UnitMem]>;
76def : WriteRes<WriteCSR, [Rocket32UnitALU]>;
77}
78
79let Latency = 2 in {
80def : WriteRes<WriteLDW, [Rocket32UnitMem]>;
81def : WriteRes<WriteFLD32, [Rocket32UnitMem]>;
82def : WriteRes<WriteFLD64, [Rocket32UnitMem]>;
83
84def : WriteRes<WriteAtomicW, [Rocket32UnitMem]>;
85def : WriteRes<WriteAtomicLDW, [Rocket32UnitMem]>;
86}
87
88def : WriteRes<WriteAtomicSTW, [Rocket32UnitMem]>;
89
90// Most FP single precision operations are 4 cycles
91def : WriteRes<WriteFALU32, [Rocket32UnitFPALU]> { let Latency = 4; }
92
93// Most FP double precision operations are 6 cycles
94def : WriteRes<WriteFALU64, [Rocket32UnitFPALU]> { let Latency = 6; }
95
96let Latency = 2 in {
97def : WriteRes<WriteFCvtI32ToF32, [Rocket32UnitFPALU]>;
98def : WriteRes<WriteFCvtI32ToF64, [Rocket32UnitFPALU]>;
99def : WriteRes<WriteFCvtF32ToI32, [Rocket32UnitFPALU]>;
100def : WriteRes<WriteFCvtF64ToI32, [Rocket32UnitFPALU]>;
101def : WriteRes<WriteFCvtF32ToF64, [Rocket32UnitFPALU]>;
102def : WriteRes<WriteFCvtF64ToF32, [Rocket32UnitFPALU]>;
103
104def : WriteRes<WriteFClass32, [Rocket32UnitFPALU]>;
105def : WriteRes<WriteFClass64, [Rocket32UnitFPALU]>;
106def : WriteRes<WriteFCmp32, [Rocket32UnitFPALU]>;
107def : WriteRes<WriteFCmp64, [Rocket32UnitFPALU]>;
108def : WriteRes<WriteFMovF32ToI32, [Rocket32UnitFPALU]>;
109def : WriteRes<WriteFMovI32ToF32, [Rocket32UnitFPALU]>;
110}
111
112let Latency = 5 in {
113def : WriteRes<WriteFMul32, [Rocket32UnitFPALU]>;
114def : WriteRes<WriteFMulAdd32, [Rocket32UnitFPALU]>;
115def : WriteRes<WriteFMulSub32, [Rocket32UnitFPALU]>;
116}
117
118let Latency = 7 in {
119def : WriteRes<WriteFMul64, [Rocket32UnitFPALU]>;
120def : WriteRes<WriteFMulAdd64, [Rocket32UnitFPALU]>;
121def : WriteRes<WriteFMulSub64, [Rocket32UnitFPALU]>;
122}
123
124// FP Divide unit on Rocket is not pipelined, so set resource cycles to latency
125let Latency = 20, ResourceCycles = [20] in {
126def : WriteRes<WriteFDiv32, [Rocket32UnitFPDivSqrt]>;
127def : WriteRes<WriteFDiv64, [Rocket32UnitFPDivSqrt]>;
128}
129
130// FP Sqrt unit on Rocket is not pipelined, so set resource cycles to latency
131def : WriteRes<WriteFSqrt32, [Rocket32UnitFPDivSqrt]> { let Latency = 20;
132                                                        let ResourceCycles = [20];}
133def : WriteRes<WriteFSqrt64, [Rocket32UnitFPDivSqrt]> { let Latency = 25;
134                                                        let ResourceCycles = [25];}
135
136def : WriteRes<WriteNop, []>;
137
138def : InstRW<[WriteIALU], (instrs COPY)>;
139
140let Unsupported = 1 in {
141def : WriteRes<WriteIALU32, []>;
142def : WriteRes<WriteShift32, []>;
143def : WriteRes<WriteIMul32, []>;
144def : WriteRes<WriteIDiv32, []>;
145def : WriteRes<WriteSTD, []>;
146def : WriteRes<WriteLDWU, []>;
147def : WriteRes<WriteLDD, []>;
148def : WriteRes<WriteAtomicD, []>;
149def : WriteRes<WriteAtomicLDD, []>;
150def : WriteRes<WriteAtomicSTD, []>;
151def : WriteRes<WriteFCvtI64ToF32, []>;
152def : WriteRes<WriteFCvtI64ToF64, []>;
153def : WriteRes<WriteFCvtF64ToI64, []>;
154def : WriteRes<WriteFCvtF32ToI64, []>;
155def : WriteRes<WriteFMovI64ToF64, []>;
156def : WriteRes<WriteFMovF64ToI64, []>;
157}
158
159//===----------------------------------------------------------------------===//
160// Subtarget-specific SchedRead types with cycles.
161// Dummy definitions for RocketCore.
162def : ReadAdvance<ReadJmp, 0>;
163def : ReadAdvance<ReadJalr, 0>;
164def : ReadAdvance<ReadCSR, 0>;
165def : ReadAdvance<ReadStoreData, 0>;
166def : ReadAdvance<ReadMemBase, 0>;
167def : ReadAdvance<ReadIALU, 0>;
168def : ReadAdvance<ReadIALU32, 0>;
169def : ReadAdvance<ReadShift, 0>;
170def : ReadAdvance<ReadShift32, 0>;
171def : ReadAdvance<ReadIDiv, 0>;
172def : ReadAdvance<ReadIDiv32, 0>;
173def : ReadAdvance<ReadIMul, 0>;
174def : ReadAdvance<ReadIMul32, 0>;
175def : ReadAdvance<ReadAtomicWA, 0>;
176def : ReadAdvance<ReadAtomicWD, 0>;
177def : ReadAdvance<ReadAtomicDA, 0>;
178def : ReadAdvance<ReadAtomicDD, 0>;
179def : ReadAdvance<ReadAtomicLDW, 0>;
180def : ReadAdvance<ReadAtomicLDD, 0>;
181def : ReadAdvance<ReadAtomicSTW, 0>;
182def : ReadAdvance<ReadAtomicSTD, 0>;
183def : ReadAdvance<ReadFALU32, 0>;
184def : ReadAdvance<ReadFALU64, 0>;
185def : ReadAdvance<ReadFMul32, 0>;
186def : ReadAdvance<ReadFMulAdd32, 0>;
187def : ReadAdvance<ReadFMulSub32, 0>;
188def : ReadAdvance<ReadFMul64, 0>;
189def : ReadAdvance<ReadFMulAdd64, 0>;
190def : ReadAdvance<ReadFMulSub64, 0>;
191def : ReadAdvance<ReadFDiv32, 0>;
192def : ReadAdvance<ReadFDiv64, 0>;
193def : ReadAdvance<ReadFSqrt32, 0>;
194def : ReadAdvance<ReadFSqrt64, 0>;
195def : ReadAdvance<ReadFCmp32, 0>;
196def : ReadAdvance<ReadFCmp64, 0>;
197def : ReadAdvance<ReadFCvtF32ToI32, 0>;
198def : ReadAdvance<ReadFCvtF32ToI64, 0>;
199def : ReadAdvance<ReadFCvtF64ToI32, 0>;
200def : ReadAdvance<ReadFCvtF64ToI64, 0>;
201def : ReadAdvance<ReadFCvtI32ToF32, 0>;
202def : ReadAdvance<ReadFCvtI32ToF64, 0>;
203def : ReadAdvance<ReadFCvtI64ToF32, 0>;
204def : ReadAdvance<ReadFCvtI64ToF64, 0>;
205def : ReadAdvance<ReadFCvtF32ToF64, 0>;
206def : ReadAdvance<ReadFCvtF64ToF32, 0>;
207def : ReadAdvance<ReadFMovF32ToI32, 0>;
208def : ReadAdvance<ReadFMovI32ToF32, 0>;
209def : ReadAdvance<ReadFMovF64ToI64, 0>;
210def : ReadAdvance<ReadFMovI64ToF64, 0>;
211def : ReadAdvance<ReadFClass32, 0>;
212def : ReadAdvance<ReadFClass64, 0>;
213}
214