]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/nds32/nds32-cost.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / nds32 / nds32-cost.c
1 /* Subroutines used for calculate rtx costs of Andes NDS32 cpu for GNU compiler
2 Copyright (C) 2012-2016 Free Software Foundation, Inc.
3 Contributed by Andes Technology Corporation.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 /* ------------------------------------------------------------------------ */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "backend.h"
27 #include "target.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "tm_p.h"
31 #include "optabs.h" /* For GEN_FCN. */
32 #include "recog.h"
33 #include "tm-constrs.h"
34
35 /* ------------------------------------------------------------------------ */
36
37 bool
38 nds32_rtx_costs_impl (rtx x,
39 machine_mode mode ATTRIBUTE_UNUSED,
40 int outer_code,
41 int opno ATTRIBUTE_UNUSED,
42 int *total,
43 bool speed)
44 {
45 int code = GET_CODE (x);
46
47 /* According to 'speed', goto suitable cost model section. */
48 if (speed)
49 goto performance_cost;
50 else
51 goto size_cost;
52
53
54 performance_cost:
55 /* This is section for performance cost model. */
56
57 /* In gcc/rtl.h, the default value of COSTS_N_INSNS(N) is N*4.
58 We treat it as 4-cycle cost for each instruction
59 under performance consideration. */
60 switch (code)
61 {
62 case SET:
63 /* For 'SET' rtx, we need to return false
64 so that it can recursively calculate costs. */
65 return false;
66
67 case USE:
68 /* Used in combine.c as a marker. */
69 *total = 0;
70 break;
71
72 case MULT:
73 *total = COSTS_N_INSNS (1);
74 break;
75
76 case DIV:
77 case UDIV:
78 case MOD:
79 case UMOD:
80 *total = COSTS_N_INSNS (7);
81 break;
82
83 default:
84 *total = COSTS_N_INSNS (1);
85 break;
86 }
87
88 return true;
89
90
91 size_cost:
92 /* This is section for size cost model. */
93
94 /* In gcc/rtl.h, the default value of COSTS_N_INSNS(N) is N*4.
95 We treat it as 4-byte cost for each instruction
96 under code size consideration. */
97 switch (code)
98 {
99 case SET:
100 /* For 'SET' rtx, we need to return false
101 so that it can recursively calculate costs. */
102 return false;
103
104 case USE:
105 /* Used in combine.c as a marker. */
106 *total = 0;
107 break;
108
109 case CONST_INT:
110 /* All instructions involving constant operation
111 need to be considered for cost evaluation. */
112 if (outer_code == SET)
113 {
114 /* (set X imm5s), use movi55, 2-byte cost.
115 (set X imm20s), use movi, 4-byte cost.
116 (set X BIG_INT), use sethi/ori, 8-byte cost. */
117 if (satisfies_constraint_Is05 (x))
118 *total = COSTS_N_INSNS (1) - 2;
119 else if (satisfies_constraint_Is20 (x))
120 *total = COSTS_N_INSNS (1);
121 else
122 *total = COSTS_N_INSNS (2);
123 }
124 else if (outer_code == PLUS || outer_code == MINUS)
125 {
126 /* Possible addi333/subi333 or subi45/addi45, 2-byte cost.
127 General case, cost 1 instruction with 4-byte. */
128 if (satisfies_constraint_Iu05 (x))
129 *total = COSTS_N_INSNS (1) - 2;
130 else
131 *total = COSTS_N_INSNS (1);
132 }
133 else if (outer_code == ASHIFT)
134 {
135 /* Possible slli333, 2-byte cost.
136 General case, cost 1 instruction with 4-byte. */
137 if (satisfies_constraint_Iu03 (x))
138 *total = COSTS_N_INSNS (1) - 2;
139 else
140 *total = COSTS_N_INSNS (1);
141 }
142 else if (outer_code == ASHIFTRT || outer_code == LSHIFTRT)
143 {
144 /* Possible srai45 or srli45, 2-byte cost.
145 General case, cost 1 instruction with 4-byte. */
146 if (satisfies_constraint_Iu05 (x))
147 *total = COSTS_N_INSNS (1) - 2;
148 else
149 *total = COSTS_N_INSNS (1);
150 }
151 else
152 {
153 /* For other cases, simply set it 4-byte cost. */
154 *total = COSTS_N_INSNS (1);
155 }
156 break;
157
158 case CONST_DOUBLE:
159 /* It requires high part and low part processing, set it 8-byte cost. */
160 *total = COSTS_N_INSNS (2);
161 break;
162
163 default:
164 /* For other cases, generally we set it 4-byte cost
165 and stop resurively traversing. */
166 *total = COSTS_N_INSNS (1);
167 break;
168 }
169
170 return true;
171 }
172
173 int
174 nds32_address_cost_impl (rtx address,
175 machine_mode mode ATTRIBUTE_UNUSED,
176 addr_space_t as ATTRIBUTE_UNUSED,
177 bool speed)
178 {
179 rtx plus0, plus1;
180 enum rtx_code code;
181
182 code = GET_CODE (address);
183
184 /* According to 'speed', goto suitable cost model section. */
185 if (speed)
186 goto performance_cost;
187 else
188 goto size_cost;
189
190 performance_cost:
191 /* This is section for performance cost model. */
192
193 /* FALLTHRU, currently we use same cost model as size_cost. */
194
195 size_cost:
196 /* This is section for size cost model. */
197
198 switch (code)
199 {
200 case POST_MODIFY:
201 case POST_INC:
202 case POST_DEC:
203 /* We encourage that rtx contains
204 POST_MODIFY/POST_INC/POST_DEC behavior. */
205 return 0;
206
207 case SYMBOL_REF:
208 /* We can have gp-relative load/store for symbol_ref.
209 Have it 4-byte cost. */
210 return COSTS_N_INSNS (1);
211
212 case CONST:
213 /* It is supposed to be the pattern (const (plus symbol_ref const_int)).
214 Have it 4-byte cost. */
215 return COSTS_N_INSNS (1);
216
217 case REG:
218 /* Simply return 4-byte costs. */
219 return COSTS_N_INSNS (1);
220
221 case PLUS:
222 /* We do not need to check if the address is a legitimate address,
223 because this hook is never called with an invalid address.
224 But we better check the range of
225 const_int value for cost, if it exists. */
226 plus0 = XEXP (address, 0);
227 plus1 = XEXP (address, 1);
228
229 if (REG_P (plus0) && CONST_INT_P (plus1))
230 {
231 /* If it is possible to be lwi333/swi333 form,
232 make it 2-byte cost. */
233 if (satisfies_constraint_Iu05 (plus1))
234 return (COSTS_N_INSNS (1) - 2);
235 else
236 return COSTS_N_INSNS (1);
237 }
238
239 /* For other 'plus' situation, make it cost 4-byte. */
240 return COSTS_N_INSNS (1);
241
242 default:
243 break;
244 }
245
246 return COSTS_N_INSNS (4);
247 }
248
249 /* ------------------------------------------------------------------------ */