1 /* Subroutines used for calculate rtx costs of Andes NDS32 cpu for GNU compiler
2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 Contributed by Andes Technology Corporation.
5 This file is part of GCC.
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.
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.
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/>. */
21 /* ------------------------------------------------------------------------ */
25 #include "coretypes.h"
31 #include "stor-layout.h"
35 #include "insn-config.h" /* Required by recog.h. */
36 #include "conditions.h"
38 #include "insn-attr.h" /* For DFA state_t. */
39 #include "insn-codes.h" /* For CODE_FOR_xxx. */
40 #include "reload.h" /* For push_reload(). */
42 #include "insn-config.h"
50 #include "diagnostic-core.h"
55 #include "cfgcleanup.h"
57 #include "tm-constrs.h"
58 #include "optabs.h" /* For GEN_FCN. */
60 #include "langhooks.h" /* For add_builtin_function(). */
63 /* ------------------------------------------------------------------------ */
66 nds32_rtx_costs_impl (rtx x
,
67 machine_mode mode ATTRIBUTE_UNUSED
,
69 int opno ATTRIBUTE_UNUSED
,
73 int code
= GET_CODE (x
);
75 /* According to 'speed', goto suitable cost model section. */
77 goto performance_cost
;
83 /* This is section for performance cost model. */
85 /* In gcc/rtl.h, the default value of COSTS_N_INSNS(N) is N*4.
86 We treat it as 4-cycle cost for each instruction
87 under performance consideration. */
91 /* For 'SET' rtx, we need to return false
92 so that it can recursively calculate costs. */
96 /* Used in combine.c as a marker. */
101 *total
= COSTS_N_INSNS (1);
108 *total
= COSTS_N_INSNS (7);
112 *total
= COSTS_N_INSNS (1);
120 /* This is section for size cost model. */
122 /* In gcc/rtl.h, the default value of COSTS_N_INSNS(N) is N*4.
123 We treat it as 4-byte cost for each instruction
124 under code size consideration. */
128 /* For 'SET' rtx, we need to return false
129 so that it can recursively calculate costs. */
133 /* Used in combine.c as a marker. */
138 /* All instructions involving constant operation
139 need to be considered for cost evaluation. */
140 if (outer_code
== SET
)
142 /* (set X imm5s), use movi55, 2-byte cost.
143 (set X imm20s), use movi, 4-byte cost.
144 (set X BIG_INT), use sethi/ori, 8-byte cost. */
145 if (satisfies_constraint_Is05 (x
))
146 *total
= COSTS_N_INSNS (1) - 2;
147 else if (satisfies_constraint_Is20 (x
))
148 *total
= COSTS_N_INSNS (1);
150 *total
= COSTS_N_INSNS (2);
152 else if (outer_code
== PLUS
|| outer_code
== MINUS
)
154 /* Possible addi333/subi333 or subi45/addi45, 2-byte cost.
155 General case, cost 1 instruction with 4-byte. */
156 if (satisfies_constraint_Iu05 (x
))
157 *total
= COSTS_N_INSNS (1) - 2;
159 *total
= COSTS_N_INSNS (1);
161 else if (outer_code
== ASHIFT
)
163 /* Possible slli333, 2-byte cost.
164 General case, cost 1 instruction with 4-byte. */
165 if (satisfies_constraint_Iu03 (x
))
166 *total
= COSTS_N_INSNS (1) - 2;
168 *total
= COSTS_N_INSNS (1);
170 else if (outer_code
== ASHIFTRT
|| outer_code
== LSHIFTRT
)
172 /* Possible srai45 or srli45, 2-byte cost.
173 General case, cost 1 instruction with 4-byte. */
174 if (satisfies_constraint_Iu05 (x
))
175 *total
= COSTS_N_INSNS (1) - 2;
177 *total
= COSTS_N_INSNS (1);
181 /* For other cases, simply set it 4-byte cost. */
182 *total
= COSTS_N_INSNS (1);
187 /* It requires high part and low part processing, set it 8-byte cost. */
188 *total
= COSTS_N_INSNS (2);
192 /* For other cases, generally we set it 4-byte cost
193 and stop resurively traversing. */
194 *total
= COSTS_N_INSNS (1);
202 nds32_address_cost_impl (rtx address
,
203 machine_mode mode ATTRIBUTE_UNUSED
,
204 addr_space_t as ATTRIBUTE_UNUSED
,
210 code
= GET_CODE (address
);
212 /* According to 'speed', goto suitable cost model section. */
214 goto performance_cost
;
219 /* This is section for performance cost model. */
221 /* FALLTHRU, currently we use same cost model as size_cost. */
224 /* This is section for size cost model. */
231 /* We encourage that rtx contains
232 POST_MODIFY/POST_INC/POST_DEC behavior. */
236 /* We can have gp-relative load/store for symbol_ref.
237 Have it 4-byte cost. */
238 return COSTS_N_INSNS (1);
241 /* It is supposed to be the pattern (const (plus symbol_ref const_int)).
242 Have it 4-byte cost. */
243 return COSTS_N_INSNS (1);
246 /* Simply return 4-byte costs. */
247 return COSTS_N_INSNS (1);
250 /* We do not need to check if the address is a legitimate address,
251 because this hook is never called with an invalid address.
252 But we better check the range of
253 const_int value for cost, if it exists. */
254 plus0
= XEXP (address
, 0);
255 plus1
= XEXP (address
, 1);
257 if (REG_P (plus0
) && CONST_INT_P (plus1
))
259 /* If it is possible to be lwi333/swi333 form,
260 make it 2-byte cost. */
261 if (satisfies_constraint_Iu05 (plus1
))
262 return (COSTS_N_INSNS (1) - 2);
264 return COSTS_N_INSNS (1);
267 /* For other 'plus' situation, make it cost 4-byte. */
268 return COSTS_N_INSNS (1);
274 return COSTS_N_INSNS (4);
277 /* ------------------------------------------------------------------------ */