xref: /dflybsd-src/contrib/gcc-4.7/gcc/internal-fn.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Internal functions.
2*e4b17023SJohn Marino    Copyright (C) 2011 Free Software Foundation, Inc.
3*e4b17023SJohn Marino 
4*e4b17023SJohn Marino This file is part of GCC.
5*e4b17023SJohn Marino 
6*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
7*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
8*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
9*e4b17023SJohn Marino version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14*e4b17023SJohn Marino for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
17*e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
18*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino #include "config.h"
21*e4b17023SJohn Marino #include "system.h"
22*e4b17023SJohn Marino #include "coretypes.h"
23*e4b17023SJohn Marino #include "internal-fn.h"
24*e4b17023SJohn Marino #include "tree.h"
25*e4b17023SJohn Marino #include "expr.h"
26*e4b17023SJohn Marino #include "optabs.h"
27*e4b17023SJohn Marino #include "gimple.h"
28*e4b17023SJohn Marino 
29*e4b17023SJohn Marino /* The names of each internal function, indexed by function number.  */
30*e4b17023SJohn Marino const char *const internal_fn_name_array[] = {
31*e4b17023SJohn Marino #define DEF_INTERNAL_FN(CODE, FLAGS) #CODE,
32*e4b17023SJohn Marino #include "internal-fn.def"
33*e4b17023SJohn Marino #undef DEF_INTERNAL_FN
34*e4b17023SJohn Marino   "<invalid-fn>"
35*e4b17023SJohn Marino };
36*e4b17023SJohn Marino 
37*e4b17023SJohn Marino /* The ECF_* flags of each internal function, indexed by function number.  */
38*e4b17023SJohn Marino const int internal_fn_flags_array[] = {
39*e4b17023SJohn Marino #define DEF_INTERNAL_FN(CODE, FLAGS) FLAGS,
40*e4b17023SJohn Marino #include "internal-fn.def"
41*e4b17023SJohn Marino #undef DEF_INTERNAL_FN
42*e4b17023SJohn Marino   0
43*e4b17023SJohn Marino };
44*e4b17023SJohn Marino 
45*e4b17023SJohn Marino /* ARRAY_TYPE is an array of vector modes.  Return the associated insn
46*e4b17023SJohn Marino    for load-lanes-style optab OPTAB.  The insn must exist.  */
47*e4b17023SJohn Marino 
48*e4b17023SJohn Marino static enum insn_code
get_multi_vector_move(tree array_type,convert_optab optab)49*e4b17023SJohn Marino get_multi_vector_move (tree array_type, convert_optab optab)
50*e4b17023SJohn Marino {
51*e4b17023SJohn Marino   enum insn_code icode;
52*e4b17023SJohn Marino   enum machine_mode imode;
53*e4b17023SJohn Marino   enum machine_mode vmode;
54*e4b17023SJohn Marino 
55*e4b17023SJohn Marino   gcc_assert (TREE_CODE (array_type) == ARRAY_TYPE);
56*e4b17023SJohn Marino   imode = TYPE_MODE (array_type);
57*e4b17023SJohn Marino   vmode = TYPE_MODE (TREE_TYPE (array_type));
58*e4b17023SJohn Marino 
59*e4b17023SJohn Marino   icode = convert_optab_handler (optab, imode, vmode);
60*e4b17023SJohn Marino   gcc_assert (icode != CODE_FOR_nothing);
61*e4b17023SJohn Marino   return icode;
62*e4b17023SJohn Marino }
63*e4b17023SJohn Marino 
64*e4b17023SJohn Marino /* Expand LOAD_LANES call STMT.  */
65*e4b17023SJohn Marino 
66*e4b17023SJohn Marino static void
expand_LOAD_LANES(gimple stmt)67*e4b17023SJohn Marino expand_LOAD_LANES (gimple stmt)
68*e4b17023SJohn Marino {
69*e4b17023SJohn Marino   struct expand_operand ops[2];
70*e4b17023SJohn Marino   tree type, lhs, rhs;
71*e4b17023SJohn Marino   rtx target, mem;
72*e4b17023SJohn Marino 
73*e4b17023SJohn Marino   lhs = gimple_call_lhs (stmt);
74*e4b17023SJohn Marino   rhs = gimple_call_arg (stmt, 0);
75*e4b17023SJohn Marino   type = TREE_TYPE (lhs);
76*e4b17023SJohn Marino 
77*e4b17023SJohn Marino   target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
78*e4b17023SJohn Marino   mem = expand_normal (rhs);
79*e4b17023SJohn Marino 
80*e4b17023SJohn Marino   gcc_assert (MEM_P (mem));
81*e4b17023SJohn Marino   PUT_MODE (mem, TYPE_MODE (type));
82*e4b17023SJohn Marino 
83*e4b17023SJohn Marino   create_output_operand (&ops[0], target, TYPE_MODE (type));
84*e4b17023SJohn Marino   create_fixed_operand (&ops[1], mem);
85*e4b17023SJohn Marino   expand_insn (get_multi_vector_move (type, vec_load_lanes_optab), 2, ops);
86*e4b17023SJohn Marino }
87*e4b17023SJohn Marino 
88*e4b17023SJohn Marino /* Expand STORE_LANES call STMT.  */
89*e4b17023SJohn Marino 
90*e4b17023SJohn Marino static void
expand_STORE_LANES(gimple stmt)91*e4b17023SJohn Marino expand_STORE_LANES (gimple stmt)
92*e4b17023SJohn Marino {
93*e4b17023SJohn Marino   struct expand_operand ops[2];
94*e4b17023SJohn Marino   tree type, lhs, rhs;
95*e4b17023SJohn Marino   rtx target, reg;
96*e4b17023SJohn Marino 
97*e4b17023SJohn Marino   lhs = gimple_call_lhs (stmt);
98*e4b17023SJohn Marino   rhs = gimple_call_arg (stmt, 0);
99*e4b17023SJohn Marino   type = TREE_TYPE (rhs);
100*e4b17023SJohn Marino 
101*e4b17023SJohn Marino   target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
102*e4b17023SJohn Marino   reg = expand_normal (rhs);
103*e4b17023SJohn Marino 
104*e4b17023SJohn Marino   gcc_assert (MEM_P (target));
105*e4b17023SJohn Marino   PUT_MODE (target, TYPE_MODE (type));
106*e4b17023SJohn Marino 
107*e4b17023SJohn Marino   create_fixed_operand (&ops[0], target);
108*e4b17023SJohn Marino   create_input_operand (&ops[1], reg, TYPE_MODE (type));
109*e4b17023SJohn Marino   expand_insn (get_multi_vector_move (type, vec_store_lanes_optab), 2, ops);
110*e4b17023SJohn Marino }
111*e4b17023SJohn Marino 
112*e4b17023SJohn Marino /* Routines to expand each internal function, indexed by function number.
113*e4b17023SJohn Marino    Each routine has the prototype:
114*e4b17023SJohn Marino 
115*e4b17023SJohn Marino        expand_<NAME> (gimple stmt)
116*e4b17023SJohn Marino 
117*e4b17023SJohn Marino    where STMT is the statement that performs the call. */
118*e4b17023SJohn Marino static void (*const internal_fn_expanders[]) (gimple) = {
119*e4b17023SJohn Marino #define DEF_INTERNAL_FN(CODE, FLAGS) expand_##CODE,
120*e4b17023SJohn Marino #include "internal-fn.def"
121*e4b17023SJohn Marino #undef DEF_INTERNAL_FN
122*e4b17023SJohn Marino   0
123*e4b17023SJohn Marino };
124*e4b17023SJohn Marino 
125*e4b17023SJohn Marino /* Expand STMT, which is a call to internal function FN.  */
126*e4b17023SJohn Marino 
127*e4b17023SJohn Marino void
expand_internal_call(gimple stmt)128*e4b17023SJohn Marino expand_internal_call (gimple stmt)
129*e4b17023SJohn Marino {
130*e4b17023SJohn Marino   internal_fn_expanders[(int) gimple_call_internal_fn (stmt)] (stmt);
131*e4b17023SJohn Marino }
132