1 /* Auxiliary functions for pipeline descriptions pattern of Andes
2 NDS32 cpu for GNU compiler
3 Copyright (C) 2012-2024 Free Software Foundation, Inc.
4 Contributed by Andes Technology Corporation.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 3, or (at your
11 option) any later version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* ------------------------------------------------------------------------ */
24 #define IN_TARGET_CODE 1
28 #include "coretypes.h"
31 #include "insn-attr.h"
32 #include "insn-codes.h"
35 #include "nds32-protos.h"
37 /* ------------------------------------------------------------------------ */
40 namespace scheduling
{
42 /* Classify the memory access direction. It's unknown if the offset register
43 is not a constant value. */
44 enum memory_access_direction
48 MEM_ACCESS_DIR_UNKNOWN
51 /* A safe wrapper to the function reg_overlap_mentioned_p (). */
53 reg_overlap_p (rtx x
, rtx in
)
55 if (x
== NULL_RTX
|| in
== NULL_RTX
)
58 return static_cast <bool> (reg_overlap_mentioned_p (x
, in
));
62 /* Determine the memory access direction of a load/store insn. */
63 memory_access_direction
64 determine_access_direction (rtx_insn
*insn
)
66 int post_update_rtx_index
;
71 switch (get_attr_type (insn
))
73 case TYPE_LOAD_MULTIPLE
:
74 gcc_assert (parallel_elements (insn
) >= 2);
76 post_update_rtx_index
= find_post_update_rtx (insn
);
77 if (post_update_rtx_index
!= -1)
78 plus_rtx
= SET_SRC (parallel_element (insn
, post_update_rtx_index
));
82 [(set (reg) (mem (reg))) : index 0
83 (set (reg) (mem (plus (reg) (...)))) : index 1
85 mem_rtx
= SET_SRC (parallel_element (insn
, 1));
86 if (GET_CODE (mem_rtx
) == UNSPEC
)
87 mem_rtx
= XVECEXP (mem_rtx
, 0, 0);
88 gcc_assert (MEM_P (mem_rtx
));
89 plus_rtx
= XEXP (mem_rtx
, 0);
93 case TYPE_STORE_MULTIPLE
:
94 gcc_assert (parallel_elements (insn
) >= 2);
96 post_update_rtx_index
= find_post_update_rtx (insn
);
97 if (post_update_rtx_index
!= -1)
98 plus_rtx
= SET_SRC (parallel_element (insn
, post_update_rtx_index
));
102 [(set (mem (reg)) (reg)) : index 0
103 (set (mem (plus (reg) (...))) (reg)) : index 1
105 mem_rtx
= SET_DEST (parallel_element (insn
, 1));
106 if (GET_CODE (mem_rtx
) == UNSPEC
)
107 mem_rtx
= XVECEXP (mem_rtx
, 0, 0);
108 gcc_assert (MEM_P (mem_rtx
));
109 plus_rtx
= XEXP (mem_rtx
, 0);
115 mem_rtx
= extract_mem_rtx (insn
);
117 switch (GET_CODE (XEXP (mem_rtx
, 0)))
120 /* (mem (post_inc (...))) */
121 return MEM_ACCESS_DIR_POS
;
124 /* (mem (post_dec (...))) */
125 return MEM_ACCESS_DIR_NEG
;
128 /* (mem (plus (reg) (...))) */
129 plus_rtx
= XEXP (mem_rtx
, 0);
133 /* (mem (post_modify (reg) (plus (reg) (...)))) */
134 plus_rtx
= XEXP (XEXP (mem_rtx
, 0), 1);
146 gcc_assert (GET_CODE (plus_rtx
) == PLUS
);
148 offset_rtx
= XEXP (plus_rtx
, 1);
149 if (GET_CODE (offset_rtx
) == CONST_INT
)
151 if (INTVAL (offset_rtx
) < 0)
152 return MEM_ACCESS_DIR_NEG
;
154 return MEM_ACCESS_DIR_POS
;
157 return MEM_ACCESS_DIR_UNKNOWN
;
160 /* Return the nth load/store operation in the real micro-operation
163 extract_nth_access_rtx (rtx_insn
*insn
, int n
)
165 int n_elems
= parallel_elements (insn
);
166 int post_update_rtx_index
= find_post_update_rtx (insn
);
167 memory_access_direction direction
= determine_access_direction (insn
);
169 gcc_assert (direction
!= MEM_ACCESS_DIR_UNKNOWN
);
171 /* Reverse the order if the direction negative. */
172 if (direction
== MEM_ACCESS_DIR_NEG
)
175 if (post_update_rtx_index
!= -1)
177 if (n
>= 0 && post_update_rtx_index
<= n
)
179 else if (n
< 0 && post_update_rtx_index
>= n
+ n_elems
)
183 return parallel_element (insn
, n
);
186 /* Returns the register operated by the nth load/store operation in the real
187 micro-operation accessing order. This function assumes INSN must be a
188 multiple-word load/store insn. */
190 extract_nth_lmsw_access_reg (rtx_insn
*insn
, int n
)
192 rtx nth_rtx
= extract_nth_access_rtx (insn
, n
);
194 if (nth_rtx
== NULL_RTX
)
197 switch (get_attr_type (insn
))
199 case TYPE_LOAD_MULTIPLE
:
200 return SET_DEST (nth_rtx
);
202 case TYPE_STORE_MULTIPLE
:
203 return SET_SRC (nth_rtx
);
210 /* Returns the register operated by the nth load/store operation in the real
211 micro-operation accessing order. This function assumes INSN must be a
212 double-word load/store insn. */
214 extract_nth_ls2_access_reg (rtx_insn
*insn
, int n
)
219 if (post_update_insn_p (insn
))
221 memory_access_direction direction
= determine_access_direction (insn
);
222 gcc_assert (direction
!= MEM_ACCESS_DIR_UNKNOWN
);
224 /* Reverse the order if the direction negative. */
225 if (direction
== MEM_ACCESS_DIR_NEG
)
229 /* Handle the out-of-range case. */
233 /* Convert the index to a positive one. */
237 switch (get_attr_type (insn
))
240 reg
= SET_DEST (PATTERN (insn
));
244 reg
= SET_SRC (PATTERN (insn
));
251 gcc_assert (REG_P (reg
) || GET_CODE (reg
) == SUBREG
);
253 switch (GET_MODE (reg
))
268 return gen_lowpart (mode
, reg
);
270 return gen_highpart (mode
, reg
);
273 /* Returns the register operated by the nth load/store operation in the real
274 micro-operation accessing order. */
276 extract_nth_access_reg (rtx_insn
*insn
, int index
)
278 switch (GET_CODE (PATTERN (insn
)))
281 return extract_nth_lmsw_access_reg (insn
, index
);
284 return extract_nth_ls2_access_reg (insn
, index
);
291 /* Determine if the latency is occured when the consumer PBSADA_INSN uses the
292 value of DEF_REG in its Ra or Rb fields. */
294 pbsada_insn_ra_rb_dep_reg_p (rtx pbsada_insn
, rtx def_reg
)
296 rtx unspec_rtx
= SET_SRC (PATTERN (pbsada_insn
));
297 gcc_assert (GET_CODE (unspec_rtx
) == UNSPEC
);
299 rtx pbsada_ra
= XVECEXP (unspec_rtx
, 0, 0);
300 rtx pbsada_rb
= XVECEXP (unspec_rtx
, 0, 1);
302 if (rtx_equal_p (def_reg
, pbsada_ra
)
303 || rtx_equal_p (def_reg
, pbsada_rb
))
309 /* Determine if the latency is occured when the consumer PBSADA_INSN uses the
310 value of DEF_REG in its Rt field. */
312 pbsada_insn_rt_dep_reg_p (rtx pbsada_insn
, rtx def_reg
)
314 rtx pbsada_rt
= SET_DEST (PATTERN (pbsada_insn
));
316 if (rtx_equal_p (def_reg
, pbsada_rt
))
322 /* Check if INSN is a movd44 insn consuming DEF_REG. */
324 movd44_even_dep_p (rtx_insn
*insn
, rtx def_reg
)
326 if (!movd44_insn_p (insn
))
329 rtx use_rtx
= SET_SRC (PATTERN (insn
));
333 return rtx_equal_p (def_reg
, use_rtx
);
335 else if (GET_CODE (def_reg
) == SUBREG
336 && GET_MODE (def_reg
) == SImode
337 && rtx_equal_p (SUBREG_REG (def_reg
), use_rtx
))
339 if (TARGET_BIG_ENDIAN
&& SUBREG_BYTE (def_reg
) == 4)
342 if (!TARGET_BIG_ENDIAN
&& SUBREG_BYTE (def_reg
) == 0)
351 /* Check if INSN is a wext insn consuming DEF_REG. */
353 wext_odd_dep_p (rtx insn
, rtx def_reg
)
355 rtx shift_rtx
= XEXP (SET_SRC (PATTERN (insn
)), 0);
356 rtx use_reg
= XEXP (shift_rtx
, 0);
357 rtx pos_rtx
= XEXP (shift_rtx
, 1);
359 if (REG_P (pos_rtx
) && reg_overlap_p (def_reg
, pos_rtx
))
362 if (GET_MODE (def_reg
) == DImode
)
363 return reg_overlap_p (def_reg
, use_reg
);
365 gcc_assert (REG_P (def_reg
) || GET_CODE (def_reg
) == SUBREG
);
366 gcc_assert (REG_P (use_reg
) || GET_CODE (use_reg
) == SUBREG
);
372 if (!TARGET_BIG_ENDIAN
)
373 return REGNO (def_reg
) == REGNO (use_reg
) + 1;
375 return REGNO (def_reg
) == REGNO (use_reg
);
381 if (GET_CODE (def_reg
) == SUBREG
)
383 if (!reg_overlap_p (def_reg
, use_reg
))
386 if (GET_CODE (use_reg
) == SUBREG
)
389 if (!TARGET_BIG_ENDIAN
)
390 return SUBREG_BYTE (def_reg
) == 4;
392 return SUBREG_BYTE (def_reg
) == 0;
398 /* Check if INSN is a bpick insn consuming DEF_REG. */
400 bpick_ra_rb_dep_p (rtx insn
, rtx def_reg
)
402 rtx ior_rtx
= SET_SRC (PATTERN (insn
));
403 rtx and1_rtx
= XEXP (ior_rtx
, 0);
404 rtx and2_rtx
= XEXP (ior_rtx
, 1);
405 rtx reg1_0
= XEXP (and1_rtx
, 0);
406 rtx reg1_1
= XEXP (and1_rtx
, 1);
407 rtx reg2_0
= XEXP (and2_rtx
, 0);
408 rtx reg2_1
= XEXP (and2_rtx
, 1);
410 if (GET_CODE (reg1_0
) == NOT
)
412 if (rtx_equal_p (reg1_0
, reg2_0
))
413 return reg_overlap_p (def_reg
, reg1_1
)
414 || reg_overlap_p (def_reg
, reg2_1
);
416 if (rtx_equal_p (reg1_0
, reg2_1
))
417 return reg_overlap_p (def_reg
, reg1_1
)
418 || reg_overlap_p (def_reg
, reg2_0
);
421 if (GET_CODE (reg1_1
) == NOT
)
423 if (rtx_equal_p (reg1_1
, reg2_0
))
424 return reg_overlap_p (def_reg
, reg1_0
)
425 || reg_overlap_p (def_reg
, reg2_1
);
427 if (rtx_equal_p (reg1_1
, reg2_1
))
428 return reg_overlap_p (def_reg
, reg1_0
)
429 || reg_overlap_p (def_reg
, reg2_0
);
432 if (GET_CODE (reg2_0
) == NOT
)
434 if (rtx_equal_p (reg2_0
, reg1_0
))
435 return reg_overlap_p (def_reg
, reg2_1
)
436 || reg_overlap_p (def_reg
, reg1_1
);
438 if (rtx_equal_p (reg2_0
, reg1_1
))
439 return reg_overlap_p (def_reg
, reg2_1
)
440 || reg_overlap_p (def_reg
, reg1_0
);
443 if (GET_CODE (reg2_1
) == NOT
)
445 if (rtx_equal_p (reg2_1
, reg1_0
))
446 return reg_overlap_p (def_reg
, reg2_0
)
447 || reg_overlap_p (def_reg
, reg1_1
);
449 if (rtx_equal_p (reg2_1
, reg1_1
))
450 return reg_overlap_p (def_reg
, reg2_0
)
451 || reg_overlap_p (def_reg
, reg1_0
);
456 } // namespace scheduling
459 /* ------------------------------------------------------------------------ */
461 using namespace nds32
;
462 using namespace nds32::scheduling
;
464 namespace { // anonymous namespace
466 /* Check the dependency between the producer defining DEF_REG and CONSUMER
467 requiring input operand at II. */
469 n7_consumed_by_ii_dep_p (rtx_insn
*consumer
, rtx def_reg
)
473 switch (get_attr_type (consumer
))
477 if (movd44_even_dep_p (consumer
, def_reg
))
480 use_rtx
= SET_SRC (PATTERN (consumer
));
484 use_rtx
= SET_SRC (PATTERN (consumer
));
488 use_rtx
= extract_mac_non_acc_rtx (consumer
);
491 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
492 results, the quotient and the remainder. It requires two micro-
493 operations in order to write two registers. We have to check the
494 dependency from the producer to the first micro-operation. */
496 if (divmod_p (consumer
))
497 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
499 use_rtx
= SET_SRC (PATTERN (consumer
));
503 /* ADDR_IN_bi_Ra, ADDR_IN_!bi */
504 if (post_update_insn_p (consumer
))
505 use_rtx
= extract_base_reg (consumer
);
507 use_rtx
= extract_mem_rtx (consumer
);
511 /* ADDR_IN_bi_Ra, ADDR_IN_!bi */
512 if (post_update_insn_p (consumer
))
513 use_rtx
= extract_base_reg (consumer
);
515 use_rtx
= extract_mem_rtx (consumer
);
517 if (reg_overlap_p (def_reg
, use_rtx
))
520 /* ST_bi, ST_!bi_RI */
521 if (!post_update_insn_p (consumer
)
522 && !immed_offset_p (extract_mem_rtx (consumer
)))
525 use_rtx
= SET_SRC (PATTERN (consumer
));
528 case TYPE_LOAD_MULTIPLE
:
529 use_rtx
= extract_base_reg (consumer
);
532 case TYPE_STORE_MULTIPLE
:
534 use_rtx
= extract_base_reg (consumer
);
535 if (reg_overlap_p (def_reg
, use_rtx
))
539 use_rtx
= extract_nth_access_rtx (consumer
, 0);
543 use_rtx
= PATTERN (consumer
);
550 if (reg_overlap_p (def_reg
, use_rtx
))
556 /* Check the dependency between the producer defining DEF_REG and CONSUMER
557 requiring input operand at AG (II). */
559 n8_consumed_by_addr_in_p (rtx_insn
*consumer
, rtx def_reg
)
563 switch (get_attr_type (consumer
))
566 use_rtx
= extract_branch_target_rtx (consumer
);
570 if (load_single_p (consumer
))
571 use_rtx
= extract_mem_rtx (consumer
);
573 use_rtx
= extract_base_reg (consumer
);
577 if (store_single_p (consumer
)
578 && (!post_update_insn_p (consumer
)
579 || immed_offset_p (extract_mem_rtx (consumer
))))
580 use_rtx
= extract_mem_rtx (consumer
);
582 use_rtx
= extract_base_reg (consumer
);
585 case TYPE_LOAD_MULTIPLE
:
586 case TYPE_STORE_MULTIPLE
:
587 use_rtx
= extract_base_reg (consumer
);
594 return reg_overlap_p (def_reg
, use_rtx
);
597 /* Check the dependency between the producer defining DEF_REG and CONSUMER
598 requiring input operand at EX. */
600 n8_consumed_by_ex_p (rtx_insn
*consumer
, rtx def_reg
)
604 switch (get_attr_type (consumer
))
607 if (movd44_even_dep_p (consumer
, def_reg
))
610 use_rtx
= SET_SRC (PATTERN (consumer
));
614 use_rtx
= SET_SRC (PATTERN (consumer
));
618 use_rtx
= extract_mac_non_acc_rtx (consumer
);
621 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
622 results, the quotient and the remainder. It requires two micro-
623 operations in order to write two registers. We have to check the
624 dependency from the producer to the first micro-operation. */
626 if (divmod_p (consumer
))
627 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
629 use_rtx
= SET_SRC (PATTERN (consumer
));
633 use_rtx
= extract_branch_condition_rtx (consumer
);
637 /* exclude ST_!bi_RR */
638 if (!post_update_insn_p (consumer
)
639 && !immed_offset_p (extract_mem_rtx (consumer
)))
642 use_rtx
= SET_SRC (PATTERN (consumer
));
645 case TYPE_STORE_MULTIPLE
:
646 use_rtx
= extract_nth_access_rtx (consumer
, 0);
653 return reg_overlap_p (def_reg
, use_rtx
);
656 /* Check the dependency between the producer defining DEF_REG and CONSUMER
657 requiring input operand at AG (II). */
659 e8_consumed_by_addr_in_p (rtx_insn
*consumer
, rtx def_reg
)
661 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
664 /* Check the dependency between the producer defining DEF_REG and CONSUMER
665 requiring input operand at EX. */
667 e8_consumed_by_ex_p (rtx_insn
*consumer
, rtx def_reg
)
671 switch (get_attr_type (consumer
))
675 use_rtx
= SET_SRC (PATTERN (consumer
));
682 case TYPE_STORE_MULTIPLE
:
683 return n8_consumed_by_ex_p (consumer
, def_reg
);
689 return reg_overlap_p (def_reg
, use_rtx
);
692 /* Check the dependency between the producer defining DEF_REG and CONSUMER
693 requiring input operand at EX. */
695 n9_2r1w_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
699 switch (get_attr_type (consumer
))
702 if (movd44_even_dep_p (consumer
, def_reg
))
705 use_rtx
= SET_SRC (PATTERN (consumer
));
710 use_rtx
= SET_SRC (PATTERN (consumer
));
714 use_rtx
= extract_shift_reg (consumer
);
718 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
721 use_rtx
= PATTERN (consumer
);
725 if (divmod_p (consumer
))
726 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
728 use_rtx
= SET_SRC (PATTERN (consumer
));
732 if (GET_CODE (PATTERN (consumer
)) == SET
)
733 use_rtx
= SET_SRC (PATTERN (consumer
));
739 /* ADDR_IN_bi_Ra, ADDR_IN_!bi */
740 if (post_update_insn_p (consumer
))
741 use_rtx
= extract_base_reg (consumer
);
743 use_rtx
= extract_mem_rtx (consumer
);
747 /* ADDR_IN_bi_Ra, ADDR_IN_!bi */
748 if (post_update_insn_p (consumer
))
749 use_rtx
= extract_base_reg (consumer
);
751 use_rtx
= extract_mem_rtx (consumer
);
753 if (reg_overlap_p (def_reg
, use_rtx
))
756 /* exclude ST_!bi_RR */
757 if (!post_update_insn_p (consumer
)
758 && !immed_offset_p (extract_mem_rtx (consumer
)))
761 use_rtx
= SET_SRC (PATTERN (consumer
));
764 case TYPE_LOAD_MULTIPLE
:
765 use_rtx
= extract_base_reg (consumer
);
768 case TYPE_STORE_MULTIPLE
:
770 use_rtx
= extract_base_reg (consumer
);
771 if (reg_overlap_p (def_reg
, use_rtx
))
775 use_rtx
= extract_nth_access_rtx (consumer
, 0);
779 use_rtx
= PATTERN (consumer
);
786 if (reg_overlap_p (def_reg
, use_rtx
))
792 /* Check the dependency between the producer defining DEF_REG and CONSUMER
793 requiring input operand at EX. */
795 n9_3r2w_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
799 switch (get_attr_type (consumer
))
804 use_rtx
= SET_SRC (PATTERN (consumer
));
808 use_rtx
= extract_shift_reg (consumer
);
812 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
815 use_rtx
= extract_mac_non_acc_rtx (consumer
);
818 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
819 results, the quotient and the remainder. In 2R1W configuration,
820 it requires two micro-operations in order to write two registers.
821 We have to check the dependency from the producer to the first
824 if (divmod_p (consumer
))
825 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
827 use_rtx
= SET_SRC (PATTERN (consumer
));
831 if (GET_CODE (PATTERN (consumer
)) == SET
)
832 use_rtx
= SET_SRC (PATTERN (consumer
));
839 use_rtx
= extract_mem_rtx (consumer
);
842 case TYPE_LOAD_MULTIPLE
:
843 case TYPE_STORE_MULTIPLE
:
844 use_rtx
= extract_base_reg (consumer
);
848 use_rtx
= PATTERN (consumer
);
855 if (reg_overlap_p (def_reg
, use_rtx
))
861 /* Check the dependency between the producer defining DEF_REG and CONSUMER
862 requiring input operand at EX. */
864 n10_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
868 switch (get_attr_type (consumer
))
881 use_rtx
= SET_SRC (PATTERN (consumer
));
885 use_rtx
= extract_shift_reg (consumer
);
889 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
893 use_rtx
= extract_mac_non_acc_rtx (consumer
);
896 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
897 results, the quotient and the remainder. */
899 if (divmod_p (consumer
))
900 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
902 use_rtx
= SET_SRC (PATTERN (consumer
));
906 return wext_odd_dep_p (consumer
, def_reg
);
909 return bpick_ra_rb_dep_p (consumer
, def_reg
);
912 if (GET_CODE (PATTERN (consumer
)) == SET
)
913 use_rtx
= SET_SRC (PATTERN (consumer
));
920 use_rtx
= extract_mem_rtx (consumer
);
923 case TYPE_LOAD_MULTIPLE
:
924 case TYPE_STORE_MULTIPLE
:
925 use_rtx
= extract_base_reg (consumer
);
929 use_rtx
= PATTERN (consumer
);
936 if (reg_overlap_p (def_reg
, use_rtx
))
942 /* Check the dependency between the producer defining DEF_REG and CONSUMER
943 requiring input operand at EX. */
945 gw_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
949 switch (get_attr_type (consumer
))
962 use_rtx
= SET_SRC (PATTERN (consumer
));
966 use_rtx
= extract_shift_reg (consumer
);
970 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
974 use_rtx
= extract_mac_non_acc_rtx (consumer
);
977 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
978 results, the quotient and the remainder. We have to check the
979 dependency from the producer to the first micro-operation. */
981 if (divmod_p (consumer
))
982 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
984 use_rtx
= SET_SRC (PATTERN (consumer
));
988 return wext_odd_dep_p (consumer
, def_reg
);
991 return bpick_ra_rb_dep_p (consumer
, def_reg
);
994 if (GET_CODE (PATTERN (consumer
)) == SET
)
995 use_rtx
= SET_SRC (PATTERN (consumer
));
1002 use_rtx
= extract_mem_rtx (consumer
);
1005 case TYPE_LOAD_MULTIPLE
:
1006 case TYPE_STORE_MULTIPLE
:
1007 use_rtx
= extract_base_reg (consumer
);
1011 use_rtx
= PATTERN (consumer
);
1018 if (reg_overlap_p (def_reg
, use_rtx
))
1024 /* Check dependencies from any stages to ALU_E1 (E1). This is a helper
1025 function of n13_consumed_by_e1_dep_p (). */
1027 n13_alu_e1_insn_dep_reg_p (rtx_insn
*alu_e1_insn
, rtx def_reg
)
1029 rtx unspec_rtx
, operand_ra
, operand_rb
;
1030 rtx src_rtx
, dst_rtx
;
1032 switch (INSN_CODE (alu_e1_insn
))
1034 /* BSP and BSE are supported by built-in functions, the corresponding
1035 patterns are formed by UNSPEC RTXs. We have to handle them
1037 case CODE_FOR_unspec_bsp
:
1038 case CODE_FOR_unspec_bse
:
1039 unspec_rtx
= SET_SRC (parallel_element (alu_e1_insn
, 0));
1040 gcc_assert (GET_CODE (unspec_rtx
) == UNSPEC
);
1042 operand_ra
= XVECEXP (unspec_rtx
, 0, 0);
1043 operand_rb
= XVECEXP (unspec_rtx
, 0, 1);
1045 if (rtx_equal_p (def_reg
, operand_ra
)
1046 || rtx_equal_p (def_reg
, operand_rb
))
1051 /* Unlink general ALU instructions, MOVD44 requires operands at E1. */
1052 case CODE_FOR_move_di
:
1053 case CODE_FOR_move_df
:
1054 src_rtx
= SET_SRC (PATTERN (alu_e1_insn
));
1055 dst_rtx
= SET_DEST (PATTERN (alu_e1_insn
));
1057 if (REG_P (dst_rtx
) && REG_P (src_rtx
)
1058 && rtx_equal_p (src_rtx
, def_reg
))
1068 /* Check the dependency between the producer defining DEF_REG and CONSUMER
1069 requiring input operand at E1. Because the address generation unti is
1070 at E1, the address input should be ready at E1. Note that the branch
1071 target is also a kind of addresses, so we have to check it. */
1073 n13_consumed_by_e1_dep_p (rtx_insn
*consumer
, rtx def_reg
)
1077 switch (get_attr_type (consumer
))
1081 return n13_alu_e1_insn_dep_reg_p (consumer
, def_reg
);
1084 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
1088 use_rtx
= SET_SRC (PATTERN (consumer
));
1092 use_rtx
= extract_mac_non_acc_rtx (consumer
);
1096 if (divmod_p (consumer
))
1097 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
1099 use_rtx
= SET_SRC (PATTERN (consumer
));
1103 if (GET_CODE (PATTERN (consumer
)) == SET
)
1104 use_rtx
= SET_SRC (PATTERN (consumer
));
1110 use_rtx
= extract_branch_target_rtx (consumer
);
1115 use_rtx
= extract_mem_rtx (consumer
);
1118 case TYPE_LOAD_MULTIPLE
:
1119 case TYPE_STORE_MULTIPLE
:
1120 use_rtx
= extract_base_reg (consumer
);
1127 if (reg_overlap_p (def_reg
, use_rtx
))
1133 /* Check the dependency between the producer defining DEF_REG and CONSUMER
1134 requiring input operand at E2. */
1136 n13_consumed_by_e2_dep_p (rtx_insn
*consumer
, rtx def_reg
)
1140 switch (get_attr_type (consumer
))
1144 use_rtx
= SET_SRC (PATTERN (consumer
));
1147 case TYPE_ALU_SHIFT
:
1148 use_rtx
= extract_shift_reg (consumer
);
1152 return pbsada_insn_rt_dep_reg_p (consumer
, def_reg
);
1154 case TYPE_STORE_MULTIPLE
:
1155 use_rtx
= extract_nth_access_rtx (consumer
, 0);
1159 use_rtx
= extract_branch_condition_rtx (consumer
);
1166 if (reg_overlap_p (def_reg
, use_rtx
))
1171 } // anonymous namespace
1173 /* ------------------------------------------------------------------------ */
1175 /* Guard functions for N7 core. */
1178 nds32_n7_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1180 if (post_update_insn_p (producer
))
1183 rtx def_reg
= SET_DEST (PATTERN (producer
));
1185 return n7_consumed_by_ii_dep_p (consumer
, def_reg
);
1189 nds32_n7_last_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1191 /* If PRODUCER is a post-update LMW insn, the last micro-operation updates
1192 the base register and the result is ready in II stage, so we don't need
1193 to handle that case in this guard function and the corresponding bypass
1195 if (post_update_insn_p (producer
))
1198 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1200 if (last_def_reg
== NULL_RTX
)
1203 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1205 return n7_consumed_by_ii_dep_p (consumer
, last_def_reg
);
1208 /* Guard functions for N8 core. */
1211 nds32_n8_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1213 if (post_update_insn_p (producer
))
1216 rtx def_reg
= SET_DEST (PATTERN (producer
));
1218 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
1222 nds32_n8_load_bi_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1224 if (!post_update_insn_p (producer
))
1227 rtx def_reg
= SET_DEST (PATTERN (producer
));
1229 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
1233 nds32_n8_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1235 if (post_update_insn_p (producer
))
1238 rtx def_reg
= SET_DEST (PATTERN (producer
));
1240 return n8_consumed_by_ex_p (consumer
, def_reg
);
1244 nds32_n8_ex_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1248 switch (get_attr_type (producer
))
1251 if (movd44_insn_p (producer
))
1252 def_reg
= extract_movd44_odd_reg (producer
);
1254 def_reg
= SET_DEST (PATTERN (producer
));
1259 def_reg
= SET_DEST (PATTERN (producer
));
1263 if (divmod_p (producer
))
1264 def_reg
= SET_DEST (parallel_element (producer
, 1));
1266 def_reg
= SET_DEST (PATTERN (producer
));
1271 case TYPE_LOAD_MULTIPLE
:
1272 case TYPE_STORE_MULTIPLE
:
1273 if (!post_update_insn_p (producer
))
1276 def_reg
= extract_base_reg (producer
);
1283 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
1287 nds32_n8_last_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1289 /* If PRODUCER is a post-update LMW insn, the last micro-operation updates
1290 the base register and the result is ready in EX stage, so we don't need
1291 to handle that case in this guard function and the corresponding bypass
1293 if (post_update_insn_p (producer
))
1296 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1298 if (last_def_reg
== NULL_RTX
)
1301 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1303 return n8_consumed_by_addr_in_p (consumer
, last_def_reg
);
1307 nds32_n8_last_load_two_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1311 /* If PRODUCER is a post-update insn, there is an additional one micro-
1312 operation inserted in the end, so the last memory access operation should
1313 be handled by this guard function and the corresponding bypass rule. */
1314 if (post_update_insn_p (producer
))
1317 rtx last_two_def_reg
= extract_nth_access_reg (producer
, index
);
1319 if (last_two_def_reg
== NULL_RTX
)
1322 gcc_assert (REG_P (last_two_def_reg
)
1323 || GET_CODE (last_two_def_reg
) == SUBREG
);
1325 return n8_consumed_by_addr_in_p (consumer
, last_two_def_reg
);
1329 nds32_n8_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1331 /* If PRODUCER is a post-update LMW insn, the last micro-operation updates
1332 the base register and the result is ready in EX stage, so we don't need
1333 to handle that case in this guard function and the corresponding bypass
1335 if (post_update_insn_p (producer
))
1338 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1340 if (last_def_reg
== NULL_RTX
)
1343 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1345 return n8_consumed_by_ex_p (consumer
, last_def_reg
);
1348 /* Guard functions for E8 cores. */
1351 nds32_e8_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1353 rtx def_reg
= SET_DEST (PATTERN (producer
));
1355 return e8_consumed_by_addr_in_p (consumer
, def_reg
);
1359 nds32_e8_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1361 rtx def_reg
= SET_DEST (PATTERN (producer
));
1363 return e8_consumed_by_ex_p (consumer
, def_reg
);
1367 nds32_e8_ex_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1371 switch (get_attr_type (producer
))
1374 /* No data hazards if AGEN's input is produced by MOVI or SETHI. */
1375 if (GET_CODE (PATTERN (producer
)) == SET
)
1377 rtx dest
= SET_DEST (PATTERN (producer
));
1378 rtx src
= SET_SRC (PATTERN (producer
));
1380 if ((REG_P (dest
) || GET_CODE (dest
) == SUBREG
)
1381 && (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == HIGH
))
1385 def_reg
= SET_DEST (PATTERN (producer
));
1390 def_reg
= SET_DEST (PATTERN (producer
));
1394 if (divmod_p (producer
))
1396 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1397 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1399 return (e8_consumed_by_addr_in_p (consumer
, def_reg1
)
1400 || e8_consumed_by_addr_in_p (consumer
, def_reg2
));
1403 def_reg
= SET_DEST (PATTERN (producer
));
1408 case TYPE_LOAD_MULTIPLE
:
1409 case TYPE_STORE_MULTIPLE
:
1410 if (!post_update_insn_p (producer
))
1413 def_reg
= extract_base_reg (producer
);
1420 return e8_consumed_by_addr_in_p (consumer
, def_reg
);
1424 nds32_e8_last_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1426 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1428 if (last_def_reg
== NULL_RTX
)
1431 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1433 return e8_consumed_by_addr_in_p (consumer
, last_def_reg
);
1437 nds32_e8_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1439 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1441 if (last_def_reg
== NULL_RTX
)
1444 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1446 return e8_consumed_by_ex_p (consumer
, last_def_reg
);
1449 /* Guard functions for N9 cores. */
1451 /* Check dependencies from MM to EX. */
1453 nds32_n9_2r1w_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1457 switch (get_attr_type (producer
))
1461 if (post_update_insn_p (producer
))
1464 def_reg
= SET_DEST (PATTERN (producer
));
1469 def_reg
= SET_DEST (PATTERN (producer
));
1476 return n9_2r1w_consumed_by_ex_dep_p (consumer
, def_reg
);
1479 /* Check dependencies from MM to EX. */
1481 nds32_n9_3r2w_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1485 switch (get_attr_type (producer
))
1490 def_reg
= SET_DEST (PATTERN (producer
));
1493 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1494 results, the quotient and the remainder. We have to handle them
1497 if (divmod_p (producer
))
1499 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1500 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1502 return (n9_3r2w_consumed_by_ex_dep_p (consumer
, def_reg1
)
1503 || n9_3r2w_consumed_by_ex_dep_p (consumer
, def_reg2
));
1506 def_reg
= SET_DEST (PATTERN (producer
));
1513 return n9_3r2w_consumed_by_ex_dep_p (consumer
, def_reg
);
1516 /* Check dependencies from LMW(N, N) to EX. */
1518 nds32_n9_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1520 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1522 if (nds32_register_ports_config
== REG_PORT_2R1W
)
1524 /* The base-update micro operation occupies the last cycle. */
1525 if (post_update_insn_p (producer
))
1528 /* When the base register is in the list of a load multiple insn and the
1529 access order of the base register is not the last one, we need an
1530 additional micro operation to commit the load result to the base
1531 register -- we can treat the base register as the last defined
1534 size_t n_elems
= parallel_elements (producer
);
1535 rtx base_reg
= extract_base_reg (producer
);
1537 for (i
= 0; i
< n_elems
; ++i
)
1539 rtx load_rtx
= extract_nth_access_rtx (producer
, i
);
1540 rtx list_element
= SET_DEST (load_rtx
);
1542 if (rtx_equal_p (base_reg
, list_element
) && i
!= n_elems
- 1)
1544 last_def_reg
= base_reg
;
1549 return n9_2r1w_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1552 return n9_3r2w_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1555 /* Guard functions for N10 cores. */
1557 /* Check dependencies from EX to EX (ADDR_OUT -> ADDR_IN). */
1559 nds32_n10_ex_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1561 gcc_assert (get_attr_type (producer
) == TYPE_FLOAD
1562 || get_attr_type (producer
) == TYPE_FSTORE
);
1563 gcc_assert (get_attr_type (consumer
) == TYPE_FLOAD
1564 || get_attr_type (consumer
) == TYPE_FSTORE
);
1566 if (!post_update_insn_p (producer
))
1569 return reg_overlap_p (extract_base_reg (producer
),
1570 extract_mem_rtx (consumer
));
1573 /* Check dependencies from MM to EX. */
1575 nds32_n10_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1579 switch (get_attr_type (producer
))
1587 case TYPE_DALUROUND
:
1590 def_reg
= SET_DEST (PATTERN (producer
));
1593 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1594 results, the quotient and the remainder. We have to handle them
1597 if (divmod_p (producer
))
1599 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1600 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1602 return (n10_consumed_by_ex_dep_p (consumer
, def_reg1
)
1603 || n10_consumed_by_ex_dep_p (consumer
, def_reg2
));
1606 def_reg
= SET_DEST (PATTERN (producer
));
1613 return n10_consumed_by_ex_dep_p (consumer
, def_reg
);
1616 /* Check dependencies from LMW(N, N) to EX. */
1618 nds32_n10_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1620 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1622 return n10_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1625 /* Guard functions for Graywolf cores. */
1627 /* Check dependencies from EX to EX (ADDR_OUT -> ADDR_IN). */
1629 nds32_gw_ex_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1631 return nds32_n10_ex_to_ex_p (producer
, consumer
);
1634 /* Check dependencies from MM to EX. */
1636 nds32_gw_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1640 switch (get_attr_type (producer
))
1648 case TYPE_DALUROUND
:
1651 def_reg
= SET_DEST (PATTERN (producer
));
1654 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1655 results, the quotient and the remainder. We have to handle them
1658 if (divmod_p (producer
))
1660 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1661 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1663 return (gw_consumed_by_ex_dep_p (consumer
, def_reg1
)
1664 || gw_consumed_by_ex_dep_p (consumer
, def_reg2
));
1667 def_reg
= SET_DEST (PATTERN (producer
));
1674 return gw_consumed_by_ex_dep_p (consumer
, def_reg
);
1677 /* Check dependencies from LMW(N, N) to EX. */
1679 nds32_gw_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1681 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1683 return gw_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1686 /* Guard functions for N12/N13 cores. */
1688 /* Check dependencies from E2 to E1. */
1690 nds32_n13_e2_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1694 switch (get_attr_type (producer
))
1696 /* Only post-update load/store instructions are considered. These
1697 instructions produces address output at E2. */
1700 case TYPE_LOAD_MULTIPLE
:
1701 case TYPE_STORE_MULTIPLE
:
1702 if (!post_update_insn_p (producer
))
1705 def_reg
= extract_base_reg (producer
);
1709 case TYPE_ALU_SHIFT
:
1714 def_reg
= SET_DEST (PATTERN (producer
));
1721 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1722 results, the quotient and the remainder. We have to handle them
1724 if (divmod_p (producer
))
1726 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1727 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1729 return (n13_consumed_by_e1_dep_p (consumer
, def_reg1
)
1730 || n13_consumed_by_e1_dep_p (consumer
, def_reg2
));
1733 def_reg
= SET_DEST (PATTERN (producer
));
1740 return n13_consumed_by_e1_dep_p (consumer
, def_reg
);
1743 /* Check dependencies from Load-Store Unit (E3) to E1. */
1745 nds32_n13_load_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1747 rtx def_reg
= SET_DEST (PATTERN (producer
));
1749 gcc_assert (get_attr_type (producer
) == TYPE_LOAD
);
1750 gcc_assert (REG_P (def_reg
) || GET_CODE (def_reg
) == SUBREG
);
1752 return n13_consumed_by_e1_dep_p (consumer
, def_reg
);
1755 /* Check dependencies from Load-Store Unit (E3) to E2. */
1757 nds32_n13_load_to_e2_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1759 rtx def_reg
= SET_DEST (PATTERN (producer
));
1761 gcc_assert (get_attr_type (producer
) == TYPE_LOAD
);
1762 gcc_assert (REG_P (def_reg
) || GET_CODE (def_reg
) == SUBREG
);
1764 return n13_consumed_by_e2_dep_p (consumer
, def_reg
);
1767 /* Check dependencies from LMW(N, N) to E1. */
1769 nds32_n13_last_load_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1771 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1773 return n13_consumed_by_e1_dep_p (consumer
, last_def_reg
);
1776 /* Check dependencies from LMW(N, N) to E2. */
1778 nds32_n13_last_load_to_e2_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1780 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1782 return n13_consumed_by_e2_dep_p (consumer
, last_def_reg
);
1785 /* Check dependencies from LMW(N, N-1) to E2. */
1787 nds32_n13_last_two_load_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1789 rtx last_two_def_reg
= extract_nth_access_reg (producer
, -2);
1791 if (last_two_def_reg
== NULL_RTX
)
1794 return n13_consumed_by_e1_dep_p (consumer
, last_two_def_reg
);
1796 /* ------------------------------------------------------------------------ */