1 /* Auxiliary functions for pipeline descriptions pattern of Andes
2 NDS32 cpu for GNU compiler
3 Copyright (C) 2012-2018 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
));
370 if (!TARGET_BIG_ENDIAN
)
371 return REGNO (def_reg
) == REGNO (use_reg
) + 1;
373 return REGNO (def_reg
) == REGNO (use_reg
);
376 if (GET_CODE (def_reg
) == SUBREG
)
378 if (!reg_overlap_p (def_reg
, use_reg
))
381 if (!TARGET_BIG_ENDIAN
)
382 return SUBREG_BYTE (def_reg
) == 4;
384 return SUBREG_BYTE (def_reg
) == 0;
390 /* Check if INSN is a bpick insn consuming DEF_REG. */
392 bpick_ra_rb_dep_p (rtx insn
, rtx def_reg
)
394 rtx ior_rtx
= SET_SRC (PATTERN (insn
));
395 rtx and1_rtx
= XEXP (ior_rtx
, 0);
396 rtx and2_rtx
= XEXP (ior_rtx
, 1);
397 rtx reg1_0
= XEXP (and1_rtx
, 0);
398 rtx reg1_1
= XEXP (and1_rtx
, 1);
399 rtx reg2_0
= XEXP (and2_rtx
, 0);
400 rtx reg2_1
= XEXP (and2_rtx
, 1);
402 if (GET_CODE (reg1_0
) == NOT
)
404 if (rtx_equal_p (reg1_0
, reg2_0
))
405 return reg_overlap_p (def_reg
, reg1_1
)
406 || reg_overlap_p (def_reg
, reg2_1
);
408 if (rtx_equal_p (reg1_0
, reg2_1
))
409 return reg_overlap_p (def_reg
, reg1_1
)
410 || reg_overlap_p (def_reg
, reg2_0
);
413 if (GET_CODE (reg1_1
) == NOT
)
415 if (rtx_equal_p (reg1_1
, reg2_0
))
416 return reg_overlap_p (def_reg
, reg1_0
)
417 || reg_overlap_p (def_reg
, reg2_1
);
419 if (rtx_equal_p (reg1_1
, reg2_1
))
420 return reg_overlap_p (def_reg
, reg1_0
)
421 || reg_overlap_p (def_reg
, reg2_0
);
424 if (GET_CODE (reg2_0
) == NOT
)
426 if (rtx_equal_p (reg2_0
, reg1_0
))
427 return reg_overlap_p (def_reg
, reg2_1
)
428 || reg_overlap_p (def_reg
, reg1_1
);
430 if (rtx_equal_p (reg2_0
, reg1_1
))
431 return reg_overlap_p (def_reg
, reg2_1
)
432 || reg_overlap_p (def_reg
, reg1_0
);
435 if (GET_CODE (reg2_1
) == NOT
)
437 if (rtx_equal_p (reg2_1
, reg1_0
))
438 return reg_overlap_p (def_reg
, reg2_0
)
439 || reg_overlap_p (def_reg
, reg1_1
);
441 if (rtx_equal_p (reg2_1
, reg1_1
))
442 return reg_overlap_p (def_reg
, reg2_0
)
443 || reg_overlap_p (def_reg
, reg1_0
);
448 } // namespace scheduling
451 /* ------------------------------------------------------------------------ */
453 using namespace nds32
;
454 using namespace nds32::scheduling
;
456 namespace { // anonymous namespace
458 /* Check the dependency between the producer defining DEF_REG and CONSUMER
459 requiring input operand at II. */
461 n7_consumed_by_ii_dep_p (rtx_insn
*consumer
, rtx def_reg
)
465 switch (get_attr_type (consumer
))
469 if (movd44_even_dep_p (consumer
, def_reg
))
472 use_rtx
= SET_SRC (PATTERN (consumer
));
476 use_rtx
= SET_SRC (PATTERN (consumer
));
480 use_rtx
= extract_mac_non_acc_rtx (consumer
);
483 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
484 results, the quotient and the remainder. It requires two micro-
485 operations in order to write two registers. We have to check the
486 dependency from the producer to the first micro-operation. */
488 if (divmod_p (consumer
))
489 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
491 use_rtx
= SET_SRC (PATTERN (consumer
));
495 /* ADDR_IN_bi_Ra, ADDR_IN_!bi */
496 if (post_update_insn_p (consumer
))
497 use_rtx
= extract_base_reg (consumer
);
499 use_rtx
= extract_mem_rtx (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
);
509 if (reg_overlap_p (def_reg
, use_rtx
))
512 /* ST_bi, ST_!bi_RI */
513 if (!post_update_insn_p (consumer
)
514 && !immed_offset_p (extract_mem_rtx (consumer
)))
517 use_rtx
= SET_SRC (PATTERN (consumer
));
520 case TYPE_LOAD_MULTIPLE
:
521 use_rtx
= extract_base_reg (consumer
);
524 case TYPE_STORE_MULTIPLE
:
526 use_rtx
= extract_base_reg (consumer
);
527 if (reg_overlap_p (def_reg
, use_rtx
))
531 use_rtx
= extract_nth_access_rtx (consumer
, 0);
535 use_rtx
= PATTERN (consumer
);
542 if (reg_overlap_p (def_reg
, use_rtx
))
548 /* Check the dependency between the producer defining DEF_REG and CONSUMER
549 requiring input operand at AG (II). */
551 n8_consumed_by_addr_in_p (rtx_insn
*consumer
, rtx def_reg
)
555 switch (get_attr_type (consumer
))
558 use_rtx
= extract_branch_target_rtx (consumer
);
562 if (load_single_p (consumer
))
563 use_rtx
= extract_mem_rtx (consumer
);
565 use_rtx
= extract_base_reg (consumer
);
569 if (store_single_p (consumer
)
570 && (!post_update_insn_p (consumer
)
571 || immed_offset_p (extract_mem_rtx (consumer
))))
572 use_rtx
= extract_mem_rtx (consumer
);
574 use_rtx
= extract_base_reg (consumer
);
577 case TYPE_LOAD_MULTIPLE
:
578 case TYPE_STORE_MULTIPLE
:
579 use_rtx
= extract_base_reg (consumer
);
586 return reg_overlap_p (def_reg
, use_rtx
);
589 /* Check the dependency between the producer defining DEF_REG and CONSUMER
590 requiring input operand at EX. */
592 n8_consumed_by_ex_p (rtx_insn
*consumer
, rtx def_reg
)
596 switch (get_attr_type (consumer
))
599 if (movd44_even_dep_p (consumer
, def_reg
))
602 use_rtx
= SET_SRC (PATTERN (consumer
));
606 use_rtx
= SET_SRC (PATTERN (consumer
));
610 use_rtx
= extract_mac_non_acc_rtx (consumer
);
613 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
614 results, the quotient and the remainder. It requires two micro-
615 operations in order to write two registers. We have to check the
616 dependency from the producer to the first micro-operation. */
618 if (divmod_p (consumer
))
619 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
621 use_rtx
= SET_SRC (PATTERN (consumer
));
625 use_rtx
= extract_branch_condition_rtx (consumer
);
629 /* exclude ST_!bi_RR */
630 if (!post_update_insn_p (consumer
)
631 && !immed_offset_p (extract_mem_rtx (consumer
)))
634 use_rtx
= SET_SRC (PATTERN (consumer
));
637 case TYPE_STORE_MULTIPLE
:
638 use_rtx
= extract_nth_access_rtx (consumer
, 0);
645 return reg_overlap_p (def_reg
, use_rtx
);
648 /* Check the dependency between the producer defining DEF_REG and CONSUMER
649 requiring input operand at AG (II). */
651 e8_consumed_by_addr_in_p (rtx_insn
*consumer
, rtx def_reg
)
653 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
656 /* Check the dependency between the producer defining DEF_REG and CONSUMER
657 requiring input operand at EX. */
659 e8_consumed_by_ex_p (rtx_insn
*consumer
, rtx def_reg
)
663 switch (get_attr_type (consumer
))
667 use_rtx
= SET_SRC (PATTERN (consumer
));
674 case TYPE_STORE_MULTIPLE
:
675 return n8_consumed_by_ex_p (consumer
, def_reg
);
681 return reg_overlap_p (def_reg
, use_rtx
);
684 /* Check the dependency between the producer defining DEF_REG and CONSUMER
685 requiring input operand at EX. */
687 n9_2r1w_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
691 switch (get_attr_type (consumer
))
694 if (movd44_even_dep_p (consumer
, def_reg
))
697 use_rtx
= SET_SRC (PATTERN (consumer
));
702 use_rtx
= SET_SRC (PATTERN (consumer
));
706 use_rtx
= extract_shift_reg (consumer
);
710 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
713 use_rtx
= PATTERN (consumer
);
717 if (divmod_p (consumer
))
718 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
720 use_rtx
= SET_SRC (PATTERN (consumer
));
724 if (GET_CODE (PATTERN (consumer
)) == SET
)
725 use_rtx
= SET_SRC (PATTERN (consumer
));
731 /* ADDR_IN_bi_Ra, ADDR_IN_!bi */
732 if (post_update_insn_p (consumer
))
733 use_rtx
= extract_base_reg (consumer
);
735 use_rtx
= extract_mem_rtx (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
);
745 if (reg_overlap_p (def_reg
, use_rtx
))
748 /* exclude ST_!bi_RR */
749 if (!post_update_insn_p (consumer
)
750 && !immed_offset_p (extract_mem_rtx (consumer
)))
753 use_rtx
= SET_SRC (PATTERN (consumer
));
756 case TYPE_LOAD_MULTIPLE
:
757 use_rtx
= extract_base_reg (consumer
);
760 case TYPE_STORE_MULTIPLE
:
762 use_rtx
= extract_base_reg (consumer
);
763 if (reg_overlap_p (def_reg
, use_rtx
))
767 use_rtx
= extract_nth_access_rtx (consumer
, 0);
771 use_rtx
= PATTERN (consumer
);
778 if (reg_overlap_p (def_reg
, use_rtx
))
784 /* Check the dependency between the producer defining DEF_REG and CONSUMER
785 requiring input operand at EX. */
787 n9_3r2w_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
791 switch (get_attr_type (consumer
))
796 use_rtx
= SET_SRC (PATTERN (consumer
));
800 use_rtx
= extract_shift_reg (consumer
);
804 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
807 use_rtx
= extract_mac_non_acc_rtx (consumer
);
810 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
811 results, the quotient and the remainder. In 2R1W configuration,
812 it requires two micro-operations in order to write two registers.
813 We have to check the dependency from the producer to the first
816 if (divmod_p (consumer
))
817 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
819 use_rtx
= SET_SRC (PATTERN (consumer
));
823 if (GET_CODE (PATTERN (consumer
)) == SET
)
824 use_rtx
= SET_SRC (PATTERN (consumer
));
831 use_rtx
= extract_mem_rtx (consumer
);
834 case TYPE_LOAD_MULTIPLE
:
835 case TYPE_STORE_MULTIPLE
:
836 use_rtx
= extract_base_reg (consumer
);
840 use_rtx
= PATTERN (consumer
);
847 if (reg_overlap_p (def_reg
, use_rtx
))
853 /* Check the dependency between the producer defining DEF_REG and CONSUMER
854 requiring input operand at EX. */
856 n10_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
860 switch (get_attr_type (consumer
))
873 use_rtx
= SET_SRC (PATTERN (consumer
));
877 use_rtx
= extract_shift_reg (consumer
);
881 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
885 use_rtx
= extract_mac_non_acc_rtx (consumer
);
888 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
889 results, the quotient and the remainder. */
891 if (divmod_p (consumer
))
892 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
894 use_rtx
= SET_SRC (PATTERN (consumer
));
898 return wext_odd_dep_p (consumer
, def_reg
);
901 return bpick_ra_rb_dep_p (consumer
, def_reg
);
904 if (GET_CODE (PATTERN (consumer
)) == SET
)
905 use_rtx
= SET_SRC (PATTERN (consumer
));
912 use_rtx
= extract_mem_rtx (consumer
);
915 case TYPE_LOAD_MULTIPLE
:
916 case TYPE_STORE_MULTIPLE
:
917 use_rtx
= extract_base_reg (consumer
);
921 use_rtx
= PATTERN (consumer
);
928 if (reg_overlap_p (def_reg
, use_rtx
))
934 /* Check the dependency between the producer defining DEF_REG and CONSUMER
935 requiring input operand at EX. */
937 gw_consumed_by_ex_dep_p (rtx_insn
*consumer
, rtx def_reg
)
941 switch (get_attr_type (consumer
))
954 use_rtx
= SET_SRC (PATTERN (consumer
));
958 use_rtx
= extract_shift_reg (consumer
);
962 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
966 use_rtx
= extract_mac_non_acc_rtx (consumer
);
969 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
970 results, the quotient and the remainder. We have to check the
971 dependency from the producer to the first micro-operation. */
973 if (divmod_p (consumer
))
974 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
976 use_rtx
= SET_SRC (PATTERN (consumer
));
980 return wext_odd_dep_p (consumer
, def_reg
);
983 return bpick_ra_rb_dep_p (consumer
, def_reg
);
986 if (GET_CODE (PATTERN (consumer
)) == SET
)
987 use_rtx
= SET_SRC (PATTERN (consumer
));
994 use_rtx
= extract_mem_rtx (consumer
);
997 case TYPE_LOAD_MULTIPLE
:
998 case TYPE_STORE_MULTIPLE
:
999 use_rtx
= extract_base_reg (consumer
);
1003 use_rtx
= PATTERN (consumer
);
1010 if (reg_overlap_p (def_reg
, use_rtx
))
1016 /* Check dependencies from any stages to ALU_E1 (E1). This is a helper
1017 function of n13_consumed_by_e1_dep_p (). */
1019 n13_alu_e1_insn_dep_reg_p (rtx_insn
*alu_e1_insn
, rtx def_reg
)
1021 rtx unspec_rtx
, operand_ra
, operand_rb
;
1022 rtx src_rtx
, dst_rtx
;
1024 switch (INSN_CODE (alu_e1_insn
))
1026 /* BSP and BSE are supported by built-in functions, the corresponding
1027 patterns are formed by UNSPEC RTXs. We have to handle them
1029 case CODE_FOR_unspec_bsp
:
1030 case CODE_FOR_unspec_bse
:
1031 unspec_rtx
= SET_SRC (parallel_element (alu_e1_insn
, 0));
1032 gcc_assert (GET_CODE (unspec_rtx
) == UNSPEC
);
1034 operand_ra
= XVECEXP (unspec_rtx
, 0, 0);
1035 operand_rb
= XVECEXP (unspec_rtx
, 0, 1);
1037 if (rtx_equal_p (def_reg
, operand_ra
)
1038 || rtx_equal_p (def_reg
, operand_rb
))
1043 /* Unlink general ALU instructions, MOVD44 requires operands at E1. */
1044 case CODE_FOR_move_di
:
1045 case CODE_FOR_move_df
:
1046 src_rtx
= SET_SRC (PATTERN (alu_e1_insn
));
1047 dst_rtx
= SET_DEST (PATTERN (alu_e1_insn
));
1049 if (REG_P (dst_rtx
) && REG_P (src_rtx
)
1050 && rtx_equal_p (src_rtx
, def_reg
))
1060 /* Check the dependency between the producer defining DEF_REG and CONSUMER
1061 requiring input operand at E1. Because the address generation unti is
1062 at E1, the address input should be ready at E1. Note that the branch
1063 target is also a kind of addresses, so we have to check it. */
1065 n13_consumed_by_e1_dep_p (rtx_insn
*consumer
, rtx def_reg
)
1069 switch (get_attr_type (consumer
))
1073 return n13_alu_e1_insn_dep_reg_p (consumer
, def_reg
);
1076 return pbsada_insn_ra_rb_dep_reg_p (consumer
, def_reg
);
1080 use_rtx
= SET_SRC (PATTERN (consumer
));
1084 use_rtx
= extract_mac_non_acc_rtx (consumer
);
1088 if (divmod_p (consumer
))
1089 use_rtx
= SET_SRC (parallel_element (consumer
, 0));
1091 use_rtx
= SET_SRC (PATTERN (consumer
));
1095 if (GET_CODE (PATTERN (consumer
)) == SET
)
1096 use_rtx
= SET_SRC (PATTERN (consumer
));
1102 use_rtx
= extract_branch_target_rtx (consumer
);
1107 use_rtx
= extract_mem_rtx (consumer
);
1110 case TYPE_LOAD_MULTIPLE
:
1111 case TYPE_STORE_MULTIPLE
:
1112 use_rtx
= extract_base_reg (consumer
);
1119 if (reg_overlap_p (def_reg
, use_rtx
))
1125 /* Check the dependency between the producer defining DEF_REG and CONSUMER
1126 requiring input operand at E2. */
1128 n13_consumed_by_e2_dep_p (rtx_insn
*consumer
, rtx def_reg
)
1132 switch (get_attr_type (consumer
))
1136 use_rtx
= SET_SRC (PATTERN (consumer
));
1139 case TYPE_ALU_SHIFT
:
1140 use_rtx
= extract_shift_reg (consumer
);
1144 return pbsada_insn_rt_dep_reg_p (consumer
, def_reg
);
1146 case TYPE_STORE_MULTIPLE
:
1147 use_rtx
= extract_nth_access_rtx (consumer
, 0);
1151 use_rtx
= extract_branch_condition_rtx (consumer
);
1158 if (reg_overlap_p (def_reg
, use_rtx
))
1163 } // anonymous namespace
1165 /* ------------------------------------------------------------------------ */
1167 /* Guard functions for N7 core. */
1170 nds32_n7_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1172 if (post_update_insn_p (producer
))
1175 rtx def_reg
= SET_DEST (PATTERN (producer
));
1177 return n7_consumed_by_ii_dep_p (consumer
, def_reg
);
1181 nds32_n7_last_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1183 /* If PRODUCER is a post-update LMW insn, the last micro-operation updates
1184 the base register and the result is ready in II stage, so we don't need
1185 to handle that case in this guard function and the corresponding bypass
1187 if (post_update_insn_p (producer
))
1190 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1192 if (last_def_reg
== NULL_RTX
)
1195 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1197 return n7_consumed_by_ii_dep_p (consumer
, last_def_reg
);
1200 /* Guard functions for N8 core. */
1203 nds32_n8_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1205 if (post_update_insn_p (producer
))
1208 rtx def_reg
= SET_DEST (PATTERN (producer
));
1210 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
1214 nds32_n8_load_bi_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1216 if (!post_update_insn_p (producer
))
1219 rtx def_reg
= SET_DEST (PATTERN (producer
));
1221 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
1225 nds32_n8_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1227 if (post_update_insn_p (producer
))
1230 rtx def_reg
= SET_DEST (PATTERN (producer
));
1232 return n8_consumed_by_ex_p (consumer
, def_reg
);
1236 nds32_n8_ex_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1240 switch (get_attr_type (producer
))
1243 if (movd44_insn_p (producer
))
1244 def_reg
= extract_movd44_odd_reg (producer
);
1246 def_reg
= SET_DEST (PATTERN (producer
));
1251 def_reg
= SET_DEST (PATTERN (producer
));
1255 if (divmod_p (producer
))
1256 def_reg
= SET_DEST (parallel_element (producer
, 1));
1258 def_reg
= SET_DEST (PATTERN (producer
));
1263 case TYPE_LOAD_MULTIPLE
:
1264 case TYPE_STORE_MULTIPLE
:
1265 if (!post_update_insn_p (producer
))
1268 def_reg
= extract_base_reg (producer
);
1275 return n8_consumed_by_addr_in_p (consumer
, def_reg
);
1279 nds32_n8_last_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1281 /* If PRODUCER is a post-update LMW insn, the last micro-operation updates
1282 the base register and the result is ready in EX stage, so we don't need
1283 to handle that case in this guard function and the corresponding bypass
1285 if (post_update_insn_p (producer
))
1288 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1290 if (last_def_reg
== NULL_RTX
)
1293 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1295 return n8_consumed_by_addr_in_p (consumer
, last_def_reg
);
1299 nds32_n8_last_load_two_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1303 /* If PRODUCER is a post-update insn, there is an additional one micro-
1304 operation inserted in the end, so the last memory access operation should
1305 be handled by this guard function and the corresponding bypass rule. */
1306 if (post_update_insn_p (producer
))
1309 rtx last_two_def_reg
= extract_nth_access_reg (producer
, index
);
1311 if (last_two_def_reg
== NULL_RTX
)
1314 gcc_assert (REG_P (last_two_def_reg
)
1315 || GET_CODE (last_two_def_reg
) == SUBREG
);
1317 return n8_consumed_by_addr_in_p (consumer
, last_two_def_reg
);
1321 nds32_n8_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1323 /* If PRODUCER is a post-update LMW insn, the last micro-operation updates
1324 the base register and the result is ready in EX stage, so we don't need
1325 to handle that case in this guard function and the corresponding bypass
1327 if (post_update_insn_p (producer
))
1330 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1332 if (last_def_reg
== NULL_RTX
)
1335 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1337 return n8_consumed_by_ex_p (consumer
, last_def_reg
);
1340 /* Guard functions for E8 cores. */
1343 nds32_e8_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1345 rtx def_reg
= SET_DEST (PATTERN (producer
));
1347 return e8_consumed_by_addr_in_p (consumer
, def_reg
);
1351 nds32_e8_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1353 rtx def_reg
= SET_DEST (PATTERN (producer
));
1355 return e8_consumed_by_ex_p (consumer
, def_reg
);
1359 nds32_e8_ex_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1363 switch (get_attr_type (producer
))
1366 /* No data hazards if AGEN's input is produced by MOVI or SETHI. */
1367 if (GET_CODE (PATTERN (producer
)) == SET
)
1369 rtx dest
= SET_DEST (PATTERN (producer
));
1370 rtx src
= SET_SRC (PATTERN (producer
));
1372 if ((REG_P (dest
) || GET_CODE (dest
) == SUBREG
)
1373 && (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == HIGH
))
1377 def_reg
= SET_DEST (PATTERN (producer
));
1382 def_reg
= SET_DEST (PATTERN (producer
));
1386 if (divmod_p (producer
))
1388 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1389 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1391 return (e8_consumed_by_addr_in_p (consumer
, def_reg1
)
1392 || e8_consumed_by_addr_in_p (consumer
, def_reg2
));
1395 def_reg
= SET_DEST (PATTERN (producer
));
1400 case TYPE_LOAD_MULTIPLE
:
1401 case TYPE_STORE_MULTIPLE
:
1402 if (!post_update_insn_p (producer
))
1405 def_reg
= extract_base_reg (producer
);
1412 return e8_consumed_by_addr_in_p (consumer
, def_reg
);
1416 nds32_e8_last_load_to_ii_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1418 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1420 if (last_def_reg
== NULL_RTX
)
1423 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1425 return e8_consumed_by_addr_in_p (consumer
, last_def_reg
);
1429 nds32_e8_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1431 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1433 if (last_def_reg
== NULL_RTX
)
1436 gcc_assert (REG_P (last_def_reg
) || GET_CODE (last_def_reg
) == SUBREG
);
1438 return e8_consumed_by_ex_p (consumer
, last_def_reg
);
1441 /* Guard functions for N9 cores. */
1443 /* Check dependencies from MM to EX. */
1445 nds32_n9_2r1w_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1449 switch (get_attr_type (producer
))
1453 if (post_update_insn_p (producer
))
1456 def_reg
= SET_DEST (PATTERN (producer
));
1461 def_reg
= SET_DEST (PATTERN (producer
));
1468 return n9_2r1w_consumed_by_ex_dep_p (consumer
, def_reg
);
1471 /* Check dependencies from MM to EX. */
1473 nds32_n9_3r2w_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1477 switch (get_attr_type (producer
))
1482 def_reg
= SET_DEST (PATTERN (producer
));
1485 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1486 results, the quotient and the remainder. We have to handle them
1489 if (divmod_p (producer
))
1491 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1492 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1494 return (n9_3r2w_consumed_by_ex_dep_p (consumer
, def_reg1
)
1495 || n9_3r2w_consumed_by_ex_dep_p (consumer
, def_reg2
));
1498 def_reg
= SET_DEST (PATTERN (producer
));
1505 return n9_3r2w_consumed_by_ex_dep_p (consumer
, def_reg
);
1508 /* Check dependencies from LMW(N, N) to EX. */
1510 nds32_n9_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1512 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1514 if (nds32_register_ports_config
== REG_PORT_2R1W
)
1516 /* The base-update micro operation occupies the last cycle. */
1517 if (post_update_insn_p (producer
))
1520 /* When the base register is in the list of a load multiple insn and the
1521 access order of the base register is not the last one, we need an
1522 additional micro operation to commit the load result to the base
1523 register -- we can treat the base register as the last defined
1526 size_t n_elems
= parallel_elements (producer
);
1527 rtx base_reg
= extract_base_reg (producer
);
1529 for (i
= 0; i
< n_elems
; ++i
)
1531 rtx load_rtx
= extract_nth_access_rtx (producer
, i
);
1532 rtx list_element
= SET_DEST (load_rtx
);
1534 if (rtx_equal_p (base_reg
, list_element
) && i
!= n_elems
- 1)
1536 last_def_reg
= base_reg
;
1541 return n9_2r1w_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1544 return n9_3r2w_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1547 /* Guard functions for N10 cores. */
1549 /* Check dependencies from EX to EX (ADDR_OUT -> ADDR_IN). */
1551 nds32_n10_ex_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1553 gcc_assert (get_attr_type (producer
) == TYPE_FLOAD
1554 || get_attr_type (producer
) == TYPE_FSTORE
);
1555 gcc_assert (get_attr_type (consumer
) == TYPE_FLOAD
1556 || get_attr_type (consumer
) == TYPE_FSTORE
);
1558 if (!post_update_insn_p (producer
))
1561 return reg_overlap_p (extract_base_reg (producer
),
1562 extract_mem_rtx (consumer
));
1565 /* Check dependencies from MM to EX. */
1567 nds32_n10_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1571 switch (get_attr_type (producer
))
1579 case TYPE_DALUROUND
:
1582 def_reg
= SET_DEST (PATTERN (producer
));
1585 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1586 results, the quotient and the remainder. We have to handle them
1589 if (divmod_p (producer
))
1591 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1592 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1594 return (n10_consumed_by_ex_dep_p (consumer
, def_reg1
)
1595 || n10_consumed_by_ex_dep_p (consumer
, def_reg2
));
1598 def_reg
= SET_DEST (PATTERN (producer
));
1605 return n10_consumed_by_ex_dep_p (consumer
, def_reg
);
1608 /* Check dependencies from LMW(N, N) to EX. */
1610 nds32_n10_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1612 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1614 return n10_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1617 /* Guard functions for Graywolf cores. */
1619 /* Check dependencies from EX to EX (ADDR_OUT -> ADDR_IN). */
1621 nds32_gw_ex_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1623 return nds32_n10_ex_to_ex_p (producer
, consumer
);
1626 /* Check dependencies from MM to EX. */
1628 nds32_gw_mm_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1632 switch (get_attr_type (producer
))
1640 case TYPE_DALUROUND
:
1643 def_reg
= SET_DEST (PATTERN (producer
));
1646 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1647 results, the quotient and the remainder. We have to handle them
1650 if (divmod_p (producer
))
1652 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1653 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1655 return (gw_consumed_by_ex_dep_p (consumer
, def_reg1
)
1656 || gw_consumed_by_ex_dep_p (consumer
, def_reg2
));
1659 def_reg
= SET_DEST (PATTERN (producer
));
1666 return gw_consumed_by_ex_dep_p (consumer
, def_reg
);
1669 /* Check dependencies from LMW(N, N) to EX. */
1671 nds32_gw_last_load_to_ex_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1673 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1675 return gw_consumed_by_ex_dep_p (consumer
, last_def_reg
);
1678 /* Guard functions for N12/N13 cores. */
1680 /* Check dependencies from E2 to E1. */
1682 nds32_n13_e2_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1686 switch (get_attr_type (producer
))
1688 /* Only post-update load/store instructions are considered. These
1689 instructions produces address output at E2. */
1692 case TYPE_LOAD_MULTIPLE
:
1693 case TYPE_STORE_MULTIPLE
:
1694 if (!post_update_insn_p (producer
))
1697 def_reg
= extract_base_reg (producer
);
1701 case TYPE_ALU_SHIFT
:
1706 def_reg
= SET_DEST (PATTERN (producer
));
1713 /* Some special instructions, divmodsi4 and udivmodsi4, produce two
1714 results, the quotient and the remainder. We have to handle them
1716 if (divmod_p (producer
))
1718 rtx def_reg1
= SET_DEST (parallel_element (producer
, 0));
1719 rtx def_reg2
= SET_DEST (parallel_element (producer
, 1));
1721 return (n13_consumed_by_e1_dep_p (consumer
, def_reg1
)
1722 || n13_consumed_by_e1_dep_p (consumer
, def_reg2
));
1725 def_reg
= SET_DEST (PATTERN (producer
));
1732 return n13_consumed_by_e1_dep_p (consumer
, def_reg
);
1735 /* Check dependencies from Load-Store Unit (E3) to E1. */
1737 nds32_n13_load_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1739 rtx def_reg
= SET_DEST (PATTERN (producer
));
1741 gcc_assert (get_attr_type (producer
) == TYPE_LOAD
);
1742 gcc_assert (REG_P (def_reg
) || GET_CODE (def_reg
) == SUBREG
);
1744 return n13_consumed_by_e1_dep_p (consumer
, def_reg
);
1747 /* Check dependencies from Load-Store Unit (E3) to E2. */
1749 nds32_n13_load_to_e2_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1751 rtx def_reg
= SET_DEST (PATTERN (producer
));
1753 gcc_assert (get_attr_type (producer
) == TYPE_LOAD
);
1754 gcc_assert (REG_P (def_reg
) || GET_CODE (def_reg
) == SUBREG
);
1756 return n13_consumed_by_e2_dep_p (consumer
, def_reg
);
1759 /* Check dependencies from LMW(N, N) to E1. */
1761 nds32_n13_last_load_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1763 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1765 return n13_consumed_by_e1_dep_p (consumer
, last_def_reg
);
1768 /* Check dependencies from LMW(N, N) to E2. */
1770 nds32_n13_last_load_to_e2_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1772 rtx last_def_reg
= extract_nth_access_reg (producer
, -1);
1774 return n13_consumed_by_e2_dep_p (consumer
, last_def_reg
);
1777 /* Check dependencies from LMW(N, N-1) to E2. */
1779 nds32_n13_last_two_load_to_e1_p (rtx_insn
*producer
, rtx_insn
*consumer
)
1781 rtx last_two_def_reg
= extract_nth_access_reg (producer
, -2);
1783 if (last_two_def_reg
== NULL_RTX
)
1786 return n13_consumed_by_e1_dep_p (consumer
, last_two_def_reg
);
1788 /* ------------------------------------------------------------------------ */