1 /* Intrinsic functions of Andes NDS32 cpu for GNU compiler
2 Copyright (C) 2012-2015 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"
30 #include "double-int.h"
37 #include "stor-layout.h"
42 #include "hard-reg-set.h"
43 #include "insn-config.h" /* Required by recog.h. */
44 #include "conditions.h"
46 #include "insn-attr.h" /* For DFA state_t. */
47 #include "insn-codes.h" /* For CODE_FOR_xxx. */
48 #include "reload.h" /* For push_reload(). */
54 #include "diagnostic-core.h"
55 #include "dominance.h"
61 #include "cfgcleanup.h"
63 #include "basic-block.h"
66 #include "tm-constrs.h"
67 #include "optabs.h" /* For GEN_FCN. */
69 #include "target-def.h"
70 #include "langhooks.h" /* For add_builtin_function(). */
74 /* ------------------------------------------------------------------------ */
76 /* Function to expand builtin function for
77 '[(unspec_volatile [(reg)])]'. */
79 nds32_expand_builtin_null_ftype_reg (enum insn_code icode
,
83 ops[0] <--> value0 <--> arg0 */
84 struct expand_operand ops
[1];
88 /* Grab the incoming arguments and extract its rtx. */
89 arg0
= CALL_EXPR_ARG (exp
, 0);
90 value0
= expand_normal (arg0
);
92 /* Create operands. */
93 create_input_operand (&ops
[0], value0
, TYPE_MODE (TREE_TYPE (arg0
)));
95 /* Emit new instruction. */
96 if (!maybe_expand_insn (icode
, 1, ops
))
97 error ("invalid argument to built-in function");
102 /* Function to expand builtin function for
103 '[(set (reg) (unspec_volatile [(imm)]))]'. */
105 nds32_expand_builtin_reg_ftype_imm (enum insn_code icode
,
106 tree exp
, rtx target
)
109 ops[0] <--> target <--> exp
110 ops[1] <--> value0 <--> arg0 */
111 struct expand_operand ops
[2];
115 /* Grab the incoming arguments and extract its rtx. */
116 arg0
= CALL_EXPR_ARG (exp
, 0);
117 value0
= expand_normal (arg0
);
119 /* Create operands. */
120 create_output_operand (&ops
[0], target
, TYPE_MODE (TREE_TYPE (exp
)));
121 create_input_operand (&ops
[1], value0
, TYPE_MODE (TREE_TYPE (arg0
)));
123 /* Emit new instruction. */
124 if (!maybe_expand_insn (icode
, 2, ops
))
125 error ("invalid argument to built-in function");
130 /* Function to expand builtin function for
131 '[(unspec_volatile [(reg) (imm)])]' pattern. */
133 nds32_expand_builtin_null_ftype_reg_imm (enum insn_code icode
,
134 tree exp
, rtx target
)
137 ops[0] <--> value0 <--> arg0
138 ops[1] <--> value1 <--> arg1 */
139 struct expand_operand ops
[2];
143 /* Grab the incoming arguments and extract its rtx. */
144 arg0
= CALL_EXPR_ARG (exp
, 0);
145 arg1
= CALL_EXPR_ARG (exp
, 1);
146 value0
= expand_normal (arg0
);
147 value1
= expand_normal (arg1
);
149 /* Create operands. */
150 create_input_operand (&ops
[0], value0
, TYPE_MODE (TREE_TYPE (arg0
)));
151 create_input_operand (&ops
[1], value1
, TYPE_MODE (TREE_TYPE (arg1
)));
153 /* Emit new instruction. */
154 if (!maybe_expand_insn (icode
, 2, ops
))
155 error ("invalid argument to built-in function");
160 /* ------------------------------------------------------------------------ */
163 nds32_init_builtins_impl (void)
165 tree pointer_type_node
= build_pointer_type (integer_type_node
);
167 tree void_ftype_void
= build_function_type (void_type_node
,
170 tree void_ftype_pint
= build_function_type_list (void_type_node
,
174 tree int_ftype_int
= build_function_type_list (integer_type_node
,
178 tree void_ftype_int_int
= build_function_type_list (void_type_node
,
184 add_builtin_function ("__builtin_nds32_isync", void_ftype_pint
,
186 BUILT_IN_MD
, NULL
, NULL_TREE
);
187 add_builtin_function ("__builtin_nds32_isb", void_ftype_void
,
189 BUILT_IN_MD
, NULL
, NULL_TREE
);
191 /* Register Transfer. */
192 add_builtin_function ("__builtin_nds32_mfsr", int_ftype_int
,
194 BUILT_IN_MD
, NULL
, NULL_TREE
);
195 add_builtin_function ("__builtin_nds32_mfusr", int_ftype_int
,
197 BUILT_IN_MD
, NULL
, NULL_TREE
);
198 add_builtin_function ("__builtin_nds32_mtsr", void_ftype_int_int
,
200 BUILT_IN_MD
, NULL
, NULL_TREE
);
201 add_builtin_function ("__builtin_nds32_mtusr", void_ftype_int_int
,
203 BUILT_IN_MD
, NULL
, NULL_TREE
);
206 add_builtin_function ("__builtin_nds32_setgie_en", void_ftype_void
,
207 NDS32_BUILTIN_SETGIE_EN
,
208 BUILT_IN_MD
, NULL
, NULL_TREE
);
209 add_builtin_function ("__builtin_nds32_setgie_dis", void_ftype_void
,
210 NDS32_BUILTIN_SETGIE_DIS
,
211 BUILT_IN_MD
, NULL
, NULL_TREE
);
216 nds32_expand_builtin_impl (tree exp
,
218 rtx subtarget ATTRIBUTE_UNUSED
,
219 machine_mode mode ATTRIBUTE_UNUSED
,
220 int ignore ATTRIBUTE_UNUSED
)
222 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
224 int fcode
= DECL_FUNCTION_CODE (fndecl
);
229 case NDS32_BUILTIN_ISYNC
:
230 return nds32_expand_builtin_null_ftype_reg
231 (CODE_FOR_unspec_volatile_isync
, exp
, target
);
232 case NDS32_BUILTIN_ISB
:
233 /* Since there are no result and operands for isb instruciton,
234 we can simply emit this rtx. */
235 emit_insn (gen_unspec_volatile_isb ());
238 /* Register Transfer. */
239 case NDS32_BUILTIN_MFSR
:
240 return nds32_expand_builtin_reg_ftype_imm
241 (CODE_FOR_unspec_volatile_mfsr
, exp
, target
);
242 case NDS32_BUILTIN_MFUSR
:
243 return nds32_expand_builtin_reg_ftype_imm
244 (CODE_FOR_unspec_volatile_mfusr
, exp
, target
);
245 case NDS32_BUILTIN_MTSR
:
246 return nds32_expand_builtin_null_ftype_reg_imm
247 (CODE_FOR_unspec_volatile_mtsr
, exp
, target
);
248 case NDS32_BUILTIN_MTUSR
:
249 return nds32_expand_builtin_null_ftype_reg_imm
250 (CODE_FOR_unspec_volatile_mtusr
, exp
, target
);
253 case NDS32_BUILTIN_SETGIE_EN
:
254 /* Since there are no result and operands for setgie.e instruciton,
255 we can simply emit this rtx. */
256 emit_insn (gen_unspec_volatile_setgie_en ());
258 case NDS32_BUILTIN_SETGIE_DIS
:
259 /* Since there are no result and operands for setgie.d instruciton,
260 we can simply emit this rtx. */
261 emit_insn (gen_unspec_volatile_setgie_dis ());
271 /* ------------------------------------------------------------------------ */