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 /* ------------------------------------------------------------------------ */
25 #include "coretypes.h"
28 #include "stor-layout.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h" /* Required by recog.h. */
35 #include "conditions.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(). */
49 #include "diagnostic-core.h"
50 #include "dominance.h"
56 #include "cfgcleanup.h"
58 #include "basic-block.h"
61 #include "tm-constrs.h"
62 #include "optabs.h" /* For GEN_FCN. */
64 #include "target-def.h"
65 #include "langhooks.h" /* For add_builtin_function(). */
69 /* ------------------------------------------------------------------------ */
71 /* Function to expand builtin function for
72 '[(unspec_volatile [(reg)])]'. */
74 nds32_expand_builtin_null_ftype_reg (enum insn_code icode
,
78 ops[0] <--> value0 <--> arg0 */
79 struct expand_operand ops
[1];
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");
97 /* Function to expand builtin function for
98 '[(set (reg) (unspec_volatile [(imm)]))]'. */
100 nds32_expand_builtin_reg_ftype_imm (enum insn_code icode
,
101 tree exp
, rtx target
)
104 ops[0] <--> target <--> exp
105 ops[1] <--> value0 <--> arg0 */
106 struct expand_operand ops
[2];
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");
125 /* Function to expand builtin function for
126 '[(unspec_volatile [(reg) (imm)])]' pattern. */
128 nds32_expand_builtin_null_ftype_reg_imm (enum insn_code icode
,
129 tree exp
, rtx target
)
132 ops[0] <--> value0 <--> arg0
133 ops[1] <--> value1 <--> arg1 */
134 struct expand_operand ops
[2];
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");
155 /* ------------------------------------------------------------------------ */
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
,
165 tree void_ftype_pint
= build_function_type_list (void_type_node
,
169 tree int_ftype_int
= build_function_type_list (integer_type_node
,
173 tree void_ftype_int_int
= build_function_type_list (void_type_node
,
179 add_builtin_function ("__builtin_nds32_isync", void_ftype_pint
,
181 BUILT_IN_MD
, NULL
, NULL_TREE
);
182 add_builtin_function ("__builtin_nds32_isb", void_ftype_void
,
184 BUILT_IN_MD
, NULL
, NULL_TREE
);
186 /* Register Transfer. */
187 add_builtin_function ("__builtin_nds32_mfsr", int_ftype_int
,
189 BUILT_IN_MD
, NULL
, NULL_TREE
);
190 add_builtin_function ("__builtin_nds32_mfusr", int_ftype_int
,
192 BUILT_IN_MD
, NULL
, NULL_TREE
);
193 add_builtin_function ("__builtin_nds32_mtsr", void_ftype_int_int
,
195 BUILT_IN_MD
, NULL
, NULL_TREE
);
196 add_builtin_function ("__builtin_nds32_mtusr", void_ftype_int_int
,
198 BUILT_IN_MD
, NULL
, NULL_TREE
);
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
,
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
);
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 ());
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
);
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 ());
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 ());
266 /* ------------------------------------------------------------------------ */