2013-11-20 Jan-Benedict Glaw <jbglaw@lug-owl.de>
[official-gcc.git] / gcc / internal-fn.c
blob867747041ae360347859b97dedc3b2b0c7289149
1 /* Internal functions.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "internal-fn.h"
24 #include "tree.h"
25 #include "stor-layout.h"
26 #include "expr.h"
27 #include "optabs.h"
28 #include "gimple.h"
30 /* The names of each internal function, indexed by function number. */
31 const char *const internal_fn_name_array[] = {
32 #define DEF_INTERNAL_FN(CODE, FLAGS) #CODE,
33 #include "internal-fn.def"
34 #undef DEF_INTERNAL_FN
35 "<invalid-fn>"
38 /* The ECF_* flags of each internal function, indexed by function number. */
39 const int internal_fn_flags_array[] = {
40 #define DEF_INTERNAL_FN(CODE, FLAGS) FLAGS,
41 #include "internal-fn.def"
42 #undef DEF_INTERNAL_FN
46 /* ARRAY_TYPE is an array of vector modes. Return the associated insn
47 for load-lanes-style optab OPTAB. The insn must exist. */
49 static enum insn_code
50 get_multi_vector_move (tree array_type, convert_optab optab)
52 enum insn_code icode;
53 enum machine_mode imode;
54 enum machine_mode vmode;
56 gcc_assert (TREE_CODE (array_type) == ARRAY_TYPE);
57 imode = TYPE_MODE (array_type);
58 vmode = TYPE_MODE (TREE_TYPE (array_type));
60 icode = convert_optab_handler (optab, imode, vmode);
61 gcc_assert (icode != CODE_FOR_nothing);
62 return icode;
65 /* Expand LOAD_LANES call STMT. */
67 static void
68 expand_LOAD_LANES (gimple stmt)
70 struct expand_operand ops[2];
71 tree type, lhs, rhs;
72 rtx target, mem;
74 lhs = gimple_call_lhs (stmt);
75 rhs = gimple_call_arg (stmt, 0);
76 type = TREE_TYPE (lhs);
78 target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
79 mem = expand_normal (rhs);
81 gcc_assert (MEM_P (mem));
82 PUT_MODE (mem, TYPE_MODE (type));
84 create_output_operand (&ops[0], target, TYPE_MODE (type));
85 create_fixed_operand (&ops[1], mem);
86 expand_insn (get_multi_vector_move (type, vec_load_lanes_optab), 2, ops);
89 /* Expand STORE_LANES call STMT. */
91 static void
92 expand_STORE_LANES (gimple stmt)
94 struct expand_operand ops[2];
95 tree type, lhs, rhs;
96 rtx target, reg;
98 lhs = gimple_call_lhs (stmt);
99 rhs = gimple_call_arg (stmt, 0);
100 type = TREE_TYPE (rhs);
102 target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
103 reg = expand_normal (rhs);
105 gcc_assert (MEM_P (target));
106 PUT_MODE (target, TYPE_MODE (type));
108 create_fixed_operand (&ops[0], target);
109 create_input_operand (&ops[1], reg, TYPE_MODE (type));
110 expand_insn (get_multi_vector_move (type, vec_store_lanes_optab), 2, ops);
113 static void
114 expand_ANNOTATE (gimple stmt ATTRIBUTE_UNUSED)
116 gcc_unreachable ();
119 /* This should get expanded in adjust_simduid_builtins. */
121 static void
122 expand_GOMP_SIMD_LANE (gimple stmt ATTRIBUTE_UNUSED)
124 gcc_unreachable ();
127 /* This should get expanded in adjust_simduid_builtins. */
129 static void
130 expand_GOMP_SIMD_VF (gimple stmt ATTRIBUTE_UNUSED)
132 gcc_unreachable ();
135 /* This should get expanded in adjust_simduid_builtins. */
137 static void
138 expand_GOMP_SIMD_LAST_LANE (gimple stmt ATTRIBUTE_UNUSED)
140 gcc_unreachable ();
143 /* This should get expanded in the sanopt pass. */
145 static void
146 expand_UBSAN_NULL (gimple stmt ATTRIBUTE_UNUSED)
148 gcc_unreachable ();
151 /* Routines to expand each internal function, indexed by function number.
152 Each routine has the prototype:
154 expand_<NAME> (gimple stmt)
156 where STMT is the statement that performs the call. */
157 static void (*const internal_fn_expanders[]) (gimple) = {
158 #define DEF_INTERNAL_FN(CODE, FLAGS) expand_##CODE,
159 #include "internal-fn.def"
160 #undef DEF_INTERNAL_FN
164 /* Expand STMT, which is a call to internal function FN. */
166 void
167 expand_internal_call (gimple stmt)
169 internal_fn_expanders[(int) gimple_call_internal_fn (stmt)] (stmt);