1 /* Dependency checks for instruction scheduling, shared between ARM and
4 Copyright (C) 1991-2014 Free Software Foundation, Inc.
5 Contributed by ARM Ltd.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 3, or (at your
12 option) any later version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
31 #include "c-family/c-common.h"
34 /* In ARMv8-A there's a general expectation that AESE/AESMC
35 and AESD/AESIMC sequences of the form:
40 will issue both instructions in a single cycle on super-scalar
41 implementations. This function identifies such pairs. */
44 aarch_crypto_can_dual_issue (rtx producer
, rtx consumer
)
46 rtx producer_src
, consumer_src
;
48 producer
= single_set (producer
);
49 consumer
= single_set (consumer
);
51 producer_src
= producer
? SET_SRC (producer
) : NULL
;
52 consumer_src
= consumer
? SET_SRC (consumer
) : NULL
;
54 if (producer_src
&& consumer_src
55 && GET_CODE (producer_src
) == UNSPEC
&& GET_CODE (consumer_src
) == UNSPEC
56 && ((XINT (producer_src
, 1) == UNSPEC_AESE
57 && XINT (consumer_src
, 1) == UNSPEC_AESMC
)
58 || (XINT (producer_src
, 1) == UNSPEC_AESD
59 && XINT (consumer_src
, 1) == UNSPEC_AESIMC
)))
61 unsigned int regno
= REGNO (SET_DEST (producer
));
63 return REGNO (SET_DEST (consumer
)) == regno
64 && REGNO (XVECEXP (consumer_src
, 0, 0)) == regno
;
77 /* Return TRUE if X is either an arithmetic shift left, or
78 is a multiplication by a power of two. */
80 arm_rtx_shift_left_p (rtx x
)
82 enum rtx_code code
= GET_CODE (x
);
84 if (code
== MULT
&& CONST_INT_P (XEXP (x
, 1))
85 && exact_log2 (INTVAL (XEXP (x
, 1))) > 0)
94 static rtx_code shift_rtx_codes
[] =
95 { ASHIFT
, ROTATE
, ASHIFTRT
, LSHIFTRT
,
96 ROTATERT
, ZERO_EXTEND
, SIGN_EXTEND
};
98 /* Callback function for arm_find_sub_rtx_with_code.
99 DATA is safe to treat as a SEARCH_TERM, ST. This will
100 hold a SEARCH_CODE. PATTERN is checked to see if it is an
101 RTX with that code. If it is, write SEARCH_RESULT in ST
102 and return 1. Otherwise, or if we have been passed a NULL_RTX
103 return 0. If ST.FIND_ANY_SHIFT then we are interested in
104 anything which can reasonably be described as a SHIFT RTX. */
106 arm_find_sub_rtx_with_search_term (rtx
*pattern
, void *data
)
108 search_term
*st
= (search_term
*) data
;
109 rtx_code pattern_code
;
112 gcc_assert (pattern
);
115 /* Poorly formed patterns can really ruin our day. */
116 if (*pattern
== NULL_RTX
)
119 pattern_code
= GET_CODE (*pattern
);
121 if (st
->find_any_shift
)
125 /* Left shifts might have been canonicalized to a MULT of some
126 power of two. Make sure we catch them. */
127 if (arm_rtx_shift_left_p (*pattern
))
130 for (i
= 0; i
< ARRAY_SIZE (shift_rtx_codes
); i
++)
131 if (pattern_code
== shift_rtx_codes
[i
])
135 if (pattern_code
== st
->search_code
)
139 st
->search_result
= *pattern
;
144 /* Traverse PATTERN looking for a sub-rtx with RTX_CODE CODE. */
146 arm_find_sub_rtx_with_code (rtx pattern
, rtx_code code
, bool find_any_shift
)
151 gcc_assert (pattern
!= NULL_RTX
);
152 st
.search_code
= code
;
153 st
.search_result
= NULL_RTX
;
154 st
.find_any_shift
= find_any_shift
;
155 result
= for_each_rtx (&pattern
, arm_find_sub_rtx_with_search_term
, &st
);
157 return st
.search_result
;
162 /* Traverse PATTERN looking for any sub-rtx which looks like a shift. */
164 arm_find_shift_sub_rtx (rtx pattern
)
166 return arm_find_sub_rtx_with_code (pattern
, ASHIFT
, true);
169 /* PRODUCER and CONSUMER are two potentially dependant RTX. PRODUCER
170 (possibly) contains a SET which will provide a result we can access
171 using the SET_DEST macro. We will place the RTX which would be
172 written by PRODUCER in SET_SOURCE.
173 Similarly, CONSUMER (possibly) contains a SET which has an operand
174 we can access using SET_SRC. We place this operand in
177 Return nonzero if we found the SET RTX we expected. */
179 arm_get_set_operands (rtx producer
, rtx consumer
,
180 rtx
*set_source
, rtx
*set_destination
)
182 rtx set_producer
= arm_find_sub_rtx_with_code (producer
, SET
, false);
183 rtx set_consumer
= arm_find_sub_rtx_with_code (consumer
, SET
, false);
185 if (set_producer
&& set_consumer
)
187 *set_source
= SET_DEST (set_producer
);
188 *set_destination
= SET_SRC (set_consumer
);
194 /* Return nonzero if the CONSUMER instruction (a load) does need
195 PRODUCER's value to calculate the address. */
197 arm_early_load_addr_dep (rtx producer
, rtx consumer
)
201 if (!arm_get_set_operands (producer
, consumer
, &value
, &addr
))
204 return reg_overlap_mentioned_p (value
, addr
);
207 /* Return nonzero if the CONSUMER instruction (an ALU op) does not
208 have an early register shift value or amount dependency on the
209 result of PRODUCER. */
211 arm_no_early_alu_shift_dep (rtx producer
, rtx consumer
)
216 if (!arm_get_set_operands (producer
, consumer
, &value
, &op
))
219 if ((early_op
= arm_find_shift_sub_rtx (op
)))
221 if (REG_P (early_op
))
224 return !reg_overlap_mentioned_p (value
, early_op
);
230 /* Return nonzero if the CONSUMER instruction (an ALU op) does not
231 have an early register shift value dependency on the result of
234 arm_no_early_alu_shift_value_dep (rtx producer
, rtx consumer
)
239 if (!arm_get_set_operands (producer
, consumer
, &value
, &op
))
242 if ((early_op
= arm_find_shift_sub_rtx (op
)))
243 /* We want to check the value being shifted. */
244 if (!reg_overlap_mentioned_p (value
, XEXP (early_op
, 0)))
250 /* Return nonzero if the CONSUMER (a mul or mac op) does not
251 have an early register mult dependency on the result of
254 arm_no_early_mul_dep (rtx producer
, rtx consumer
)
258 if (!arm_get_set_operands (producer
, consumer
, &value
, &op
))
261 if (GET_CODE (op
) == PLUS
|| GET_CODE (op
) == MINUS
)
263 if (GET_CODE (XEXP (op
, 0)) == MULT
)
264 return !reg_overlap_mentioned_p (value
, XEXP (op
, 0));
266 return !reg_overlap_mentioned_p (value
, XEXP (op
, 1));
272 /* Return nonzero if the CONSUMER instruction (a store) does not need
273 PRODUCER's value to calculate the address. */
276 arm_no_early_store_addr_dep (rtx producer
, rtx consumer
)
278 rtx value
= arm_find_sub_rtx_with_code (producer
, SET
, false);
279 rtx addr
= arm_find_sub_rtx_with_code (consumer
, SET
, false);
282 value
= SET_DEST (value
);
285 addr
= SET_DEST (addr
);
290 return !reg_overlap_mentioned_p (value
, addr
);
293 /* Return nonzero if the CONSUMER instruction (a store) does need
294 PRODUCER's value to calculate the address. */
297 arm_early_store_addr_dep (rtx producer
, rtx consumer
)
299 return !arm_no_early_store_addr_dep (producer
, consumer
);
302 /* Return non-zero iff the consumer (a multiply-accumulate or a
303 multiple-subtract instruction) has an accumulator dependency on the
304 result of the producer and no other dependency on that result. It
305 does not check if the producer is multiply-accumulate instruction. */
307 arm_mac_accumulator_is_result (rtx producer
, rtx consumer
)
312 producer
= PATTERN (producer
);
313 consumer
= PATTERN (consumer
);
315 if (GET_CODE (producer
) == COND_EXEC
)
316 producer
= COND_EXEC_CODE (producer
);
317 if (GET_CODE (consumer
) == COND_EXEC
)
318 consumer
= COND_EXEC_CODE (consumer
);
320 if (GET_CODE (producer
) != SET
)
323 result
= XEXP (producer
, 0);
325 if (GET_CODE (consumer
) != SET
)
328 /* Check that the consumer is of the form
329 (set (...) (plus (mult ...) (...)))
331 (set (...) (minus (...) (mult ...))). */
332 if (GET_CODE (XEXP (consumer
, 1)) == PLUS
)
334 if (GET_CODE (XEXP (XEXP (consumer
, 1), 0)) != MULT
)
337 op0
= XEXP (XEXP (XEXP (consumer
, 1), 0), 0);
338 op1
= XEXP (XEXP (XEXP (consumer
, 1), 0), 1);
339 acc
= XEXP (XEXP (consumer
, 1), 1);
341 else if (GET_CODE (XEXP (consumer
, 1)) == MINUS
)
343 if (GET_CODE (XEXP (XEXP (consumer
, 1), 1)) != MULT
)
346 op0
= XEXP (XEXP (XEXP (consumer
, 1), 1), 0);
347 op1
= XEXP (XEXP (XEXP (consumer
, 1), 1), 1);
348 acc
= XEXP (XEXP (consumer
, 1), 0);
353 return (reg_overlap_mentioned_p (result
, acc
)
354 && !reg_overlap_mentioned_p (result
, op0
)
355 && !reg_overlap_mentioned_p (result
, op1
));
358 /* Return non-zero if the consumer (a multiply-accumulate instruction)
359 has an accumulator dependency on the result of the producer (a
360 multiplication instruction) and no other dependency on that result. */
362 arm_mac_accumulator_is_mul_result (rtx producer
, rtx consumer
)
364 rtx mul
= PATTERN (producer
);
365 rtx mac
= PATTERN (consumer
);
367 rtx mac_op0
, mac_op1
, mac_acc
;
369 if (GET_CODE (mul
) == COND_EXEC
)
370 mul
= COND_EXEC_CODE (mul
);
371 if (GET_CODE (mac
) == COND_EXEC
)
372 mac
= COND_EXEC_CODE (mac
);
374 /* Check that mul is of the form (set (...) (mult ...))
375 and mla is of the form (set (...) (plus (mult ...) (...))). */
376 if ((GET_CODE (mul
) != SET
|| GET_CODE (XEXP (mul
, 1)) != MULT
)
377 || (GET_CODE (mac
) != SET
|| GET_CODE (XEXP (mac
, 1)) != PLUS
378 || GET_CODE (XEXP (XEXP (mac
, 1), 0)) != MULT
))
381 mul_result
= XEXP (mul
, 0);
382 mac_op0
= XEXP (XEXP (XEXP (mac
, 1), 0), 0);
383 mac_op1
= XEXP (XEXP (XEXP (mac
, 1), 0), 1);
384 mac_acc
= XEXP (XEXP (mac
, 1), 1);
386 return (reg_overlap_mentioned_p (mul_result
, mac_acc
)
387 && !reg_overlap_mentioned_p (mul_result
, mac_op0
)
388 && !reg_overlap_mentioned_p (mul_result
, mac_op1
));