gcc/ada/
[official-gcc.git] / gcc / config / nds32 / nds32-intrinsic.c
blob4c45e96d5f7b8c03aca9c4cc58c0f00b9dd17958
1 /* Intrinsic functions of Andes NDS32 cpu for GNU compiler
2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
3 Contributed by Andes Technology Corporation.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* ------------------------------------------------------------------------ */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "stor-layout.h"
29 #include "varasm.h"
30 #include "calls.h"
31 #include "rtl.h"
32 #include "regs.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h" /* Required by recog.h. */
35 #include "conditions.h"
36 #include "output.h"
37 #include "insn-attr.h" /* For DFA state_t. */
38 #include "insn-codes.h" /* For CODE_FOR_xxx. */
39 #include "reload.h" /* For push_reload(). */
40 #include "flags.h"
41 #include "hashtab.h"
42 #include "hash-set.h"
43 #include "vec.h"
44 #include "machmode.h"
45 #include "input.h"
46 #include "function.h"
47 #include "expr.h"
48 #include "recog.h"
49 #include "diagnostic-core.h"
50 #include "dominance.h"
51 #include "cfg.h"
52 #include "cfgrtl.h"
53 #include "cfganal.h"
54 #include "lcm.h"
55 #include "cfgbuild.h"
56 #include "cfgcleanup.h"
57 #include "predict.h"
58 #include "basic-block.h"
59 #include "df.h"
60 #include "tm_p.h"
61 #include "tm-constrs.h"
62 #include "optabs.h" /* For GEN_FCN. */
63 #include "target.h"
64 #include "target-def.h"
65 #include "langhooks.h" /* For add_builtin_function(). */
66 #include "ggc.h"
67 #include "builtins.h"
69 /* ------------------------------------------------------------------------ */
71 /* Function to expand builtin function for
72 '[(unspec_volatile [(reg)])]'. */
73 static rtx
74 nds32_expand_builtin_null_ftype_reg (enum insn_code icode,
75 tree exp, rtx target)
77 /* Mapping:
78 ops[0] <--> value0 <--> arg0 */
79 struct expand_operand ops[1];
80 tree arg0;
81 rtx value0;
83 /* Grab the incoming arguments and extract its rtx. */
84 arg0 = CALL_EXPR_ARG (exp, 0);
85 value0 = expand_normal (arg0);
87 /* Create operands. */
88 create_input_operand (&ops[0], value0, TYPE_MODE (TREE_TYPE (arg0)));
90 /* Emit new instruction. */
91 if (!maybe_expand_insn (icode, 1, ops))
92 error ("invalid argument to built-in function");
94 return target;
97 /* Function to expand builtin function for
98 '[(set (reg) (unspec_volatile [(imm)]))]'. */
99 static rtx
100 nds32_expand_builtin_reg_ftype_imm (enum insn_code icode,
101 tree exp, rtx target)
103 /* Mapping:
104 ops[0] <--> target <--> exp
105 ops[1] <--> value0 <--> arg0 */
106 struct expand_operand ops[2];
107 tree arg0;
108 rtx value0;
110 /* Grab the incoming arguments and extract its rtx. */
111 arg0 = CALL_EXPR_ARG (exp, 0);
112 value0 = expand_normal (arg0);
114 /* Create operands. */
115 create_output_operand (&ops[0], target, TYPE_MODE (TREE_TYPE (exp)));
116 create_input_operand (&ops[1], value0, TYPE_MODE (TREE_TYPE (arg0)));
118 /* Emit new instruction. */
119 if (!maybe_expand_insn (icode, 2, ops))
120 error ("invalid argument to built-in function");
122 return target;
125 /* Function to expand builtin function for
126 '[(unspec_volatile [(reg) (imm)])]' pattern. */
127 static rtx
128 nds32_expand_builtin_null_ftype_reg_imm (enum insn_code icode,
129 tree exp, rtx target)
131 /* Mapping:
132 ops[0] <--> value0 <--> arg0
133 ops[1] <--> value1 <--> arg1 */
134 struct expand_operand ops[2];
135 tree arg0, arg1;
136 rtx value0, value1;
138 /* Grab the incoming arguments and extract its rtx. */
139 arg0 = CALL_EXPR_ARG (exp, 0);
140 arg1 = CALL_EXPR_ARG (exp, 1);
141 value0 = expand_normal (arg0);
142 value1 = expand_normal (arg1);
144 /* Create operands. */
145 create_input_operand (&ops[0], value0, TYPE_MODE (TREE_TYPE (arg0)));
146 create_input_operand (&ops[1], value1, TYPE_MODE (TREE_TYPE (arg1)));
148 /* Emit new instruction. */
149 if (!maybe_expand_insn (icode, 2, ops))
150 error ("invalid argument to built-in function");
152 return target;
155 /* ------------------------------------------------------------------------ */
157 void
158 nds32_init_builtins_impl (void)
160 tree pointer_type_node = build_pointer_type (integer_type_node);
162 tree void_ftype_void = build_function_type (void_type_node,
163 void_list_node);
165 tree void_ftype_pint = build_function_type_list (void_type_node,
166 pointer_type_node,
167 NULL_TREE);
169 tree int_ftype_int = build_function_type_list (integer_type_node,
170 integer_type_node,
171 NULL_TREE);
173 tree void_ftype_int_int = build_function_type_list (void_type_node,
174 integer_type_node,
175 integer_type_node,
176 NULL_TREE);
178 /* Cache. */
179 add_builtin_function ("__builtin_nds32_isync", void_ftype_pint,
180 NDS32_BUILTIN_ISYNC,
181 BUILT_IN_MD, NULL, NULL_TREE);
182 add_builtin_function ("__builtin_nds32_isb", void_ftype_void,
183 NDS32_BUILTIN_ISB,
184 BUILT_IN_MD, NULL, NULL_TREE);
186 /* Register Transfer. */
187 add_builtin_function ("__builtin_nds32_mfsr", int_ftype_int,
188 NDS32_BUILTIN_MFSR,
189 BUILT_IN_MD, NULL, NULL_TREE);
190 add_builtin_function ("__builtin_nds32_mfusr", int_ftype_int,
191 NDS32_BUILTIN_MFUSR,
192 BUILT_IN_MD, NULL, NULL_TREE);
193 add_builtin_function ("__builtin_nds32_mtsr", void_ftype_int_int,
194 NDS32_BUILTIN_MTSR,
195 BUILT_IN_MD, NULL, NULL_TREE);
196 add_builtin_function ("__builtin_nds32_mtusr", void_ftype_int_int,
197 NDS32_BUILTIN_MTUSR,
198 BUILT_IN_MD, NULL, NULL_TREE);
200 /* Interrupt. */
201 add_builtin_function ("__builtin_nds32_setgie_en", void_ftype_void,
202 NDS32_BUILTIN_SETGIE_EN,
203 BUILT_IN_MD, NULL, NULL_TREE);
204 add_builtin_function ("__builtin_nds32_setgie_dis", void_ftype_void,
205 NDS32_BUILTIN_SETGIE_DIS,
206 BUILT_IN_MD, NULL, NULL_TREE);
211 nds32_expand_builtin_impl (tree exp,
212 rtx target,
213 rtx subtarget ATTRIBUTE_UNUSED,
214 machine_mode mode ATTRIBUTE_UNUSED,
215 int ignore ATTRIBUTE_UNUSED)
217 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
219 int fcode = DECL_FUNCTION_CODE (fndecl);
221 switch (fcode)
223 /* Cache. */
224 case NDS32_BUILTIN_ISYNC:
225 return nds32_expand_builtin_null_ftype_reg
226 (CODE_FOR_unspec_volatile_isync, exp, target);
227 case NDS32_BUILTIN_ISB:
228 /* Since there are no result and operands for isb instruciton,
229 we can simply emit this rtx. */
230 emit_insn (gen_unspec_volatile_isb ());
231 return target;
233 /* Register Transfer. */
234 case NDS32_BUILTIN_MFSR:
235 return nds32_expand_builtin_reg_ftype_imm
236 (CODE_FOR_unspec_volatile_mfsr, exp, target);
237 case NDS32_BUILTIN_MFUSR:
238 return nds32_expand_builtin_reg_ftype_imm
239 (CODE_FOR_unspec_volatile_mfusr, exp, target);
240 case NDS32_BUILTIN_MTSR:
241 return nds32_expand_builtin_null_ftype_reg_imm
242 (CODE_FOR_unspec_volatile_mtsr, exp, target);
243 case NDS32_BUILTIN_MTUSR:
244 return nds32_expand_builtin_null_ftype_reg_imm
245 (CODE_FOR_unspec_volatile_mtusr, exp, target);
247 /* Interrupt. */
248 case NDS32_BUILTIN_SETGIE_EN:
249 /* Since there are no result and operands for setgie.e instruciton,
250 we can simply emit this rtx. */
251 emit_insn (gen_unspec_volatile_setgie_en ());
252 return target;
253 case NDS32_BUILTIN_SETGIE_DIS:
254 /* Since there are no result and operands for setgie.d instruciton,
255 we can simply emit this rtx. */
256 emit_insn (gen_unspec_volatile_setgie_dis ());
257 return target;
259 default:
260 gcc_unreachable ();
263 return NULL_RTX;
266 /* ------------------------------------------------------------------------ */