]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/nds32/nds32-predicates.c
c0576212e7d69aecb6a925b3ce49a7b4c923f7c2
1 /* Predicate functions of Andes NDS32 cpu for GNU compiler
2 Copyright (C) 2012-2014 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"
28 #include "stor-layout.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h" /* Required by recog.h. */
35 #include "conditions.h"
37 #include "insn-attr.h" /* For DFA state_t. */
38 #include "insn-codes.h" /* For CODE_FOR_xxx. */
39 #include "reload.h" /* For push_reload(). */
49 #include "diagnostic-core.h"
52 #include "tm-constrs.h"
53 #include "optabs.h" /* For GEN_FCN. */
55 #include "target-def.h"
56 #include "langhooks.h" /* For add_builtin_function(). */
60 /* ------------------------------------------------------------------------ */
62 /* A subroutine that checks multiple load and store
63 using consecutive registers.
64 OP is a parallel rtx we would like to check.
65 LOAD_P indicates whether we are checking load operation.
66 PAR_INDEX is starting element of parallel rtx.
67 FIRST_ELT_REGNO is used to tell starting register number.
68 COUNT helps us to check consecutive register numbers. */
70 nds32_consecutive_registers_load_store_p (rtx op
,
82 for (i
= 0; i
< count
; i
++)
84 /* Pick up each element from parallel rtx. */
85 elt
= XVECEXP (op
, 0, i
+ par_index
);
87 /* If this element is not a 'set' rtx, return false immediately. */
88 if (GET_CODE (elt
) != SET
)
91 /* Pick up reg and mem of this element. */
92 elt_reg
= load_p
? SET_DEST (elt
) : SET_SRC (elt
);
93 elt_mem
= load_p
? SET_SRC (elt
) : SET_DEST (elt
);
95 /* If elt_reg is not a expected reg rtx, return false. */
96 if (GET_CODE (elt_reg
) != REG
|| GET_MODE (elt_reg
) != SImode
)
98 /* If elt_mem is not a expected mem rtx, return false. */
99 if (GET_CODE (elt_mem
) != MEM
|| GET_MODE (elt_mem
) != SImode
)
102 /* The consecutive registers should be in (Rb,Rb+1...Re) order. */
103 check_regno
= first_elt_regno
+ i
;
105 /* If the register number is not continuous, return false. */
106 if (REGNO (elt_reg
) != (unsigned int) check_regno
)
113 /* Function to check whether the OP is a valid load/store operation.
114 This is a helper function for the predicates:
115 'nds32_load_multiple_operation' and 'nds32_store_multiple_operation'
116 in predicates.md file.
118 The OP is supposed to be a parallel rtx.
119 For each element within this parallel rtx:
120 (set (reg) (mem addr)) is the form for load operation.
121 (set (mem addr) (reg)) is the form for store operation.
122 We have to extract reg and mem of every element and
123 check if the information is valid for multiple load/store operation. */
125 nds32_valid_multiple_load_store (rtx op
, bool load_p
)
131 /* Get the counts of elements in the parallel rtx. */
132 count
= XVECLEN (op
, 0);
133 /* Pick up the first element. */
134 elt
= XVECEXP (op
, 0, 0);
136 /* Perform some quick check for the first element in the parallel rtx. */
137 if (GET_CODE (elt
) != SET
142 /* Pick up regno of first element for further detail checking.
143 Note that the form is different between load and store operation. */
146 if (GET_CODE (SET_DEST (elt
)) != REG
147 || GET_CODE (SET_SRC (elt
)) != MEM
)
150 first_elt_regno
= REGNO (SET_DEST (elt
));
154 if (GET_CODE (SET_SRC (elt
)) != REG
155 || GET_CODE (SET_DEST (elt
)) != MEM
)
158 first_elt_regno
= REGNO (SET_SRC (elt
));
161 /* Perform detail check for each element.
162 Refer to nds32-multiple.md for more information
163 about following checking.
164 The starting element of parallel rtx is index 0. */
165 if (!nds32_consecutive_registers_load_store_p (op
, load_p
, 0,
170 /* Pass all test, this is a valid rtx. */
174 /* Function to check whether the OP is a valid stack push/pop operation.
175 For a valid stack operation, it must satisfy following conditions:
176 1. Consecutive registers push/pop operations.
177 2. Valid $fp/$gp/$lp push/pop operations.
178 3. The last element must be stack adjustment rtx.
179 See the prologue/epilogue implementation for details. */
181 nds32_valid_stack_push_pop_p (rtx op
, bool push_p
)
187 int save_fp
, save_gp
, save_lp
;
193 /* Get the counts of elements in the parallel rtx. */
194 total_count
= XVECLEN (op
, 0);
196 /* Perform some quick check for that every element should be 'set'. */
197 for (index
= 0; index
< total_count
; index
++)
199 elt
= XVECEXP (op
, 0, index
);
200 if (GET_CODE (elt
) != SET
)
204 /* For push operation, the parallel rtx looks like:
205 (parallel [(set (mem (plus (reg:SI SP_REGNUM) (const_int -32)))
207 (set (mem (plus (reg:SI SP_REGNUM) (const_int -28)))
210 (set (mem (plus (reg:SI SP_REGNUM) (const_int -16)))
212 (set (mem (plus (reg:SI SP_REGNUM) (const_int -12)))
214 (set (mem (plus (reg:SI SP_REGNUM) (const_int -8)))
216 (set (mem (plus (reg:SI SP_REGNUM) (const_int -4)))
218 (set (reg:SI SP_REGNUM)
219 (plus (reg:SI SP_REGNUM) (const_int -32)))])
221 For pop operation, the parallel rtx looks like:
222 (parallel [(set (reg:SI Rb)
223 (mem (reg:SI SP_REGNUM)))
225 (mem (plus (reg:SI SP_REGNUM) (const_int 4))))
228 (mem (plus (reg:SI SP_REGNUM) (const_int 16))))
229 (set (reg:SI FP_REGNUM)
230 (mem (plus (reg:SI SP_REGNUM) (const_int 20))))
231 (set (reg:SI GP_REGNUM)
232 (mem (plus (reg:SI SP_REGNUM) (const_int 24))))
233 (set (reg:SI LP_REGNUM)
234 (mem (plus (reg:SI SP_REGNUM) (const_int 28))))
235 (set (reg:SI SP_REGNUM)
236 (plus (reg:SI SP_REGNUM) (const_int 32)))]) */
238 /* 1. Consecutive registers push/pop operations.
239 We need to calculate how many registers should be consecutive.
240 The $sp adjustment rtx, $fp push rtx, $gp push rtx,
241 and $lp push rtx are excluded. */
243 /* Detect whether we have $fp, $gp, or $lp in the parallel rtx. */
244 save_fp
= reg_mentioned_p (gen_rtx_REG (SImode
, FP_REGNUM
), op
);
245 save_gp
= reg_mentioned_p (gen_rtx_REG (SImode
, GP_REGNUM
), op
);
246 save_lp
= reg_mentioned_p (gen_rtx_REG (SImode
, LP_REGNUM
), op
);
247 /* Exclude last $sp adjustment rtx. */
248 rest_count
= total_count
- 1;
249 /* Exclude $fp, $gp, and $lp if they are in the parallel rtx. */
259 elt
= XVECEXP (op
, 0, 0);
260 /* Pick up register element. */
261 elt_reg
= push_p
? SET_SRC (elt
) : SET_DEST (elt
);
262 first_regno
= REGNO (elt_reg
);
264 /* The 'push' operation is a kind of store operation.
265 The 'pop' operation is a kind of load operation.
266 Pass corresponding false/true as second argument (bool load_p).
267 The par_index is supposed to start with index 0. */
268 if (!nds32_consecutive_registers_load_store_p (op
,
269 !push_p
? true : false,
276 /* 2. Valid $fp/$gp/$lp push/pop operations.
277 Remember to set start index for checking them. */
279 /* The rest_count is the start index for checking $fp/$gp/$lp. */
281 /* If index < 0, this parallel rtx is definitely
282 not a valid stack push/pop operation. */
286 /* Check $fp/$gp/$lp one by one.
287 We use 'push_p' to pick up reg rtx and mem rtx. */
290 elt
= XVECEXP (op
, 0, index
);
291 elt_mem
= push_p
? SET_DEST (elt
) : SET_SRC (elt
);
292 elt_reg
= push_p
? SET_SRC (elt
) : SET_DEST (elt
);
295 if (GET_CODE (elt_mem
) != MEM
296 || GET_CODE (elt_reg
) != REG
297 || REGNO (elt_reg
) != FP_REGNUM
)
302 elt
= XVECEXP (op
, 0, index
);
303 elt_mem
= push_p
? SET_DEST (elt
) : SET_SRC (elt
);
304 elt_reg
= push_p
? SET_SRC (elt
) : SET_DEST (elt
);
307 if (GET_CODE (elt_mem
) != MEM
308 || GET_CODE (elt_reg
) != REG
309 || REGNO (elt_reg
) != GP_REGNUM
)
314 elt
= XVECEXP (op
, 0, index
);
315 elt_mem
= push_p
? SET_DEST (elt
) : SET_SRC (elt
);
316 elt_reg
= push_p
? SET_SRC (elt
) : SET_DEST (elt
);
319 if (GET_CODE (elt_mem
) != MEM
320 || GET_CODE (elt_reg
) != REG
321 || REGNO (elt_reg
) != LP_REGNUM
)
325 /* 3. The last element must be stack adjustment rtx.
326 Its form of rtx should be:
327 (set (reg:SI SP_REGNUM)
328 (plus (reg:SI SP_REGNUM) (const_int X)))
329 The X could be positive or negative value. */
331 /* Pick up the last element. */
332 elt
= XVECEXP (op
, 0, total_count
- 1);
334 /* Extract its destination and source rtx. */
335 elt_reg
= SET_DEST (elt
);
336 elt_plus
= SET_SRC (elt
);
338 /* Check this is (set (stack_reg) (plus stack_reg const)) pattern. */
339 if (GET_CODE (elt_reg
) != REG
340 || GET_CODE (elt_plus
) != PLUS
341 || REGNO (elt_reg
) != SP_REGNUM
)
344 /* Pass all test, this is a valid rtx. */
348 /* Function to check if 'bclr' instruction can be used with IVAL. */
350 nds32_can_use_bclr_p (int ival
)
354 /* Calculate the number of 1-bit of (~ival), if there is only one 1-bit,
355 it means the original ival has only one 0-bit,
356 So it is ok to perform 'bclr' operation. */
358 one_bit_count
= popcount_hwi ((unsigned HOST_WIDE_INT
) (~ival
));
360 /* 'bclr' is a performance extension instruction. */
361 return (TARGET_PERF_EXT
&& (one_bit_count
== 1));
364 /* Function to check if 'bset' instruction can be used with IVAL. */
366 nds32_can_use_bset_p (int ival
)
370 /* Caculate the number of 1-bit of ival, if there is only one 1-bit,
371 it is ok to perform 'bset' operation. */
373 one_bit_count
= popcount_hwi ((unsigned HOST_WIDE_INT
) (ival
));
375 /* 'bset' is a performance extension instruction. */
376 return (TARGET_PERF_EXT
&& (one_bit_count
== 1));
379 /* Function to check if 'btgl' instruction can be used with IVAL. */
381 nds32_can_use_btgl_p (int ival
)
385 /* Caculate the number of 1-bit of ival, if there is only one 1-bit,
386 it is ok to perform 'btgl' operation. */
388 one_bit_count
= popcount_hwi ((unsigned HOST_WIDE_INT
) (ival
));
390 /* 'btgl' is a performance extension instruction. */
391 return (TARGET_PERF_EXT
&& (one_bit_count
== 1));
394 /* Function to check if 'bitci' instruction can be used with IVAL. */
396 nds32_can_use_bitci_p (int ival
)
398 /* If we are using V3 ISA, we have 'bitci' instruction.
399 Try to see if we can present 'andi' semantic with
400 such 'bit-clear-immediate' operation.
401 For example, 'andi $r0,$r0,0xfffffffc' can be
402 presented with 'bitci $r0,$r0,3'. */
403 return (TARGET_ISA_V3
405 && satisfies_constraint_Iu15 (gen_int_mode (~ival
, SImode
)));
408 /* ------------------------------------------------------------------------ */