* config/nvptx/nvptx.h (struct machine_function): Add comment.
[official-gcc.git] / gcc / config / nvptx / nvptx.c
blob57830c33f372bce472d04a3b9020ed2945b650b2
1 /* Target code for NVPTX.
2 Copyright (C) 2014-2015 Free Software Foundation, Inc.
3 Contributed by Bernd Schmidt <bernds@codesourcery.com>
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 #include "config.h"
22 #include <sstream>
23 #include "system.h"
24 #include "coretypes.h"
25 #include "backend.h"
26 #include "cfghooks.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "df.h"
30 #include "alias.h"
31 #include "insn-flags.h"
32 #include "output.h"
33 #include "insn-attr.h"
34 #include "insn-codes.h"
35 #include "flags.h"
36 #include "insn-config.h"
37 #include "expmed.h"
38 #include "dojump.h"
39 #include "explow.h"
40 #include "calls.h"
41 #include "emit-rtl.h"
42 #include "varasm.h"
43 #include "stmt.h"
44 #include "expr.h"
45 #include "regs.h"
46 #include "optabs.h"
47 #include "recog.h"
48 #include "timevar.h"
49 #include "tm_p.h"
50 #include "tm-preds.h"
51 #include "tm-constrs.h"
52 #include "langhooks.h"
53 #include "dbxout.h"
54 #include "target.h"
55 #include "diagnostic.h"
56 #include "cfgrtl.h"
57 #include "stor-layout.h"
58 #include "builtins.h"
59 #include "omp-low.h"
60 #include "gomp-constants.h"
62 /* This file should be included last. */
63 #include "target-def.h"
65 /* Record the function decls we've written, and the libfuncs and function
66 decls corresponding to them. */
67 static std::stringstream func_decls;
69 struct declared_libfunc_hasher : ggc_cache_ptr_hash<rtx_def>
71 static hashval_t hash (rtx x) { return htab_hash_pointer (x); }
72 static bool equal (rtx a, rtx b) { return a == b; }
75 static GTY((cache))
76 hash_table<declared_libfunc_hasher> *declared_libfuncs_htab;
78 struct tree_hasher : ggc_cache_ptr_hash<tree_node>
80 static hashval_t hash (tree t) { return htab_hash_pointer (t); }
81 static bool equal (tree a, tree b) { return a == b; }
84 static GTY((cache)) hash_table<tree_hasher> *declared_fndecls_htab;
85 static GTY((cache)) hash_table<tree_hasher> *needed_fndecls_htab;
87 /* Allocate a new, cleared machine_function structure. */
89 static struct machine_function *
90 nvptx_init_machine_status (void)
92 struct machine_function *p = ggc_cleared_alloc<machine_function> ();
93 p->ret_reg_mode = VOIDmode;
94 return p;
97 /* Implement TARGET_OPTION_OVERRIDE. */
99 static void
100 nvptx_option_override (void)
102 init_machine_status = nvptx_init_machine_status;
103 /* Gives us a predictable order, which we need especially for variables. */
104 flag_toplevel_reorder = 1;
105 /* Assumes that it will see only hard registers. */
106 flag_var_tracking = 0;
107 write_symbols = NO_DEBUG;
108 debug_info_level = DINFO_LEVEL_NONE;
110 declared_fndecls_htab = hash_table<tree_hasher>::create_ggc (17);
111 needed_fndecls_htab = hash_table<tree_hasher>::create_ggc (17);
112 declared_libfuncs_htab
113 = hash_table<declared_libfunc_hasher>::create_ggc (17);
116 /* Return the mode to be used when declaring a ptx object for OBJ.
117 For objects with subparts such as complex modes this is the mode
118 of the subpart. */
120 machine_mode
121 nvptx_underlying_object_mode (rtx obj)
123 if (GET_CODE (obj) == SUBREG)
124 obj = SUBREG_REG (obj);
125 machine_mode mode = GET_MODE (obj);
126 if (mode == TImode)
127 return DImode;
128 if (COMPLEX_MODE_P (mode))
129 return GET_MODE_INNER (mode);
130 return mode;
133 /* Return a ptx type for MODE. If PROMOTE, then use .u32 for QImode to
134 deal with ptx ideosyncracies. */
136 const char *
137 nvptx_ptx_type_from_mode (machine_mode mode, bool promote)
139 switch (mode)
141 case BLKmode:
142 return ".b8";
143 case BImode:
144 return ".pred";
145 case QImode:
146 if (promote)
147 return ".u32";
148 else
149 return ".u8";
150 case HImode:
151 return ".u16";
152 case SImode:
153 return ".u32";
154 case DImode:
155 return ".u64";
157 case SFmode:
158 return ".f32";
159 case DFmode:
160 return ".f64";
162 default:
163 gcc_unreachable ();
167 /* Return the number of pieces to use when dealing with a pseudo of *PMODE.
168 Alter *PMODE if we return a number greater than one. */
170 static int
171 maybe_split_mode (machine_mode *pmode)
173 machine_mode mode = *pmode;
175 if (COMPLEX_MODE_P (mode))
177 *pmode = GET_MODE_INNER (mode);
178 return 2;
180 else if (mode == TImode)
182 *pmode = DImode;
183 return 2;
185 return 1;
188 /* Like maybe_split_mode, but only return whether or not the mode
189 needs to be split. */
190 static bool
191 nvptx_split_reg_p (machine_mode mode)
193 if (COMPLEX_MODE_P (mode))
194 return true;
195 if (mode == TImode)
196 return true;
197 return false;
200 #define PASS_IN_REG_P(MODE, TYPE) \
201 ((GET_MODE_CLASS (MODE) == MODE_INT \
202 || GET_MODE_CLASS (MODE) == MODE_FLOAT \
203 || ((GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
204 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT) \
205 && !AGGREGATE_TYPE_P (TYPE))) \
206 && (MODE) != TImode)
208 #define RETURN_IN_REG_P(MODE) \
209 ((GET_MODE_CLASS (MODE) == MODE_INT \
210 || GET_MODE_CLASS (MODE) == MODE_FLOAT) \
211 && GET_MODE_SIZE (MODE) <= 8)
213 /* Perform a mode promotion for a function argument with MODE. Return
214 the promoted mode. */
216 static machine_mode
217 arg_promotion (machine_mode mode)
219 if (mode == QImode || mode == HImode)
220 return SImode;
221 return mode;
224 /* Write the declaration of a function arg of TYPE to S. I is the index
225 of the argument, MODE its mode. NO_ARG_TYPES is true if this is for
226 a decl with zero TYPE_ARG_TYPES, i.e. an old-style C decl. */
228 static int
229 write_one_arg (std::stringstream &s, tree type, int i, machine_mode mode,
230 bool no_arg_types)
232 if (!PASS_IN_REG_P (mode, type))
233 mode = Pmode;
235 int count = maybe_split_mode (&mode);
237 if (count == 2)
239 write_one_arg (s, NULL_TREE, i, mode, false);
240 write_one_arg (s, NULL_TREE, i + 1, mode, false);
241 return i + 1;
244 if (no_arg_types && !AGGREGATE_TYPE_P (type))
246 if (mode == SFmode)
247 mode = DFmode;
248 mode = arg_promotion (mode);
251 if (i > 0)
252 s << ", ";
253 s << ".param" << nvptx_ptx_type_from_mode (mode, false) << " %in_ar"
254 << (i + 1) << (mode == QImode || mode == HImode ? "[1]" : "");
255 if (mode == BLKmode)
256 s << "[" << int_size_in_bytes (type) << "]";
257 return i;
260 /* Look for attributes in ATTRS that would indicate we must write a function
261 as a .entry kernel rather than a .func. Return true if one is found. */
263 static bool
264 write_as_kernel (tree attrs)
266 return (lookup_attribute ("kernel", attrs) != NULL_TREE
267 || lookup_attribute ("omp target entrypoint", attrs) != NULL_TREE);
270 /* Write a function decl for DECL to S, where NAME is the name to be used.
271 This includes ptx .visible or .extern specifiers, .func or .kernel, and
272 argument and return types. */
274 static void
275 nvptx_write_function_decl (std::stringstream &s, const char *name, const_tree decl)
277 tree fntype = TREE_TYPE (decl);
278 tree result_type = TREE_TYPE (fntype);
279 tree args = TYPE_ARG_TYPES (fntype);
280 tree attrs = DECL_ATTRIBUTES (decl);
281 bool kernel = write_as_kernel (attrs);
282 bool is_main = strcmp (name, "main") == 0;
283 bool args_from_decl = false;
285 /* We get:
286 NULL in TYPE_ARG_TYPES, for old-style functions
287 NULL in DECL_ARGUMENTS, for builtin functions without another
288 declaration.
289 So we have to pick the best one we have. */
290 if (args == 0)
292 args = DECL_ARGUMENTS (decl);
293 args_from_decl = true;
296 if (DECL_EXTERNAL (decl))
297 s << ".extern ";
298 else if (TREE_PUBLIC (decl))
299 s << ".visible ";
301 if (kernel)
302 s << ".entry ";
303 else
304 s << ".func ";
306 /* Declare the result. */
307 bool return_in_mem = false;
308 if (TYPE_MODE (result_type) != VOIDmode)
310 machine_mode mode = TYPE_MODE (result_type);
311 if (!RETURN_IN_REG_P (mode))
312 return_in_mem = true;
313 else
315 mode = arg_promotion (mode);
316 s << "(.param" << nvptx_ptx_type_from_mode (mode, false)
317 << " %out_retval)";
321 if (name[0] == '*')
322 s << (name + 1);
323 else
324 s << name;
326 /* Declare argument types. */
327 if ((args != NULL_TREE
328 && !(TREE_CODE (args) == TREE_LIST
329 && TREE_VALUE (args) == void_type_node))
330 || is_main
331 || return_in_mem
332 || DECL_STATIC_CHAIN (decl))
334 s << "(";
335 int i = 0;
336 bool any_args = false;
337 if (return_in_mem)
339 s << ".param.u" << GET_MODE_BITSIZE (Pmode) << " %in_ar1";
340 i++;
342 while (args != NULL_TREE)
344 tree type = args_from_decl ? TREE_TYPE (args) : TREE_VALUE (args);
345 machine_mode mode = TYPE_MODE (type);
347 if (mode != VOIDmode)
349 i = write_one_arg (s, type, i, mode,
350 TYPE_ARG_TYPES (fntype) == 0);
351 any_args = true;
352 i++;
354 args = TREE_CHAIN (args);
356 if (stdarg_p (fntype))
358 gcc_assert (i > 0);
359 s << ", .param.u" << GET_MODE_BITSIZE (Pmode) << " %in_argp";
361 if (DECL_STATIC_CHAIN (decl))
363 if (i > 0)
364 s << ", ";
365 s << ".reg.u" << GET_MODE_BITSIZE (Pmode)
366 << reg_names [STATIC_CHAIN_REGNUM];
368 if (!any_args && is_main)
369 s << ".param.u32 %argc, .param.u" << GET_MODE_BITSIZE (Pmode)
370 << " %argv";
371 s << ")";
375 /* Walk either ARGTYPES or ARGS if the former is null, and write out part of
376 the function header to FILE. If WRITE_COPY is false, write reg
377 declarations, otherwise write the copy from the incoming argument to that
378 reg. RETURN_IN_MEM indicates whether to start counting arg numbers at 1
379 instead of 0. */
381 static void
382 walk_args_for_param (FILE *file, tree argtypes, tree args, bool write_copy,
383 bool return_in_mem)
385 int i;
387 bool args_from_decl = false;
388 if (argtypes == 0)
389 args_from_decl = true;
390 else
391 args = argtypes;
393 for (i = return_in_mem ? 1 : 0; args != NULL_TREE; args = TREE_CHAIN (args))
395 tree type = args_from_decl ? TREE_TYPE (args) : TREE_VALUE (args);
396 machine_mode mode = TYPE_MODE (type);
398 if (mode == VOIDmode)
399 break;
401 if (!PASS_IN_REG_P (mode, type))
402 mode = Pmode;
404 int count = maybe_split_mode (&mode);
405 if (count == 1)
407 if (argtypes == NULL && !AGGREGATE_TYPE_P (type))
409 if (mode == SFmode)
410 mode = DFmode;
414 mode = arg_promotion (mode);
415 while (count-- > 0)
417 i++;
418 if (write_copy)
419 fprintf (file, "\tld.param%s %%ar%d, [%%in_ar%d];\n",
420 nvptx_ptx_type_from_mode (mode, false), i, i);
421 else
422 fprintf (file, "\t.reg%s %%ar%d;\n",
423 nvptx_ptx_type_from_mode (mode, false), i);
428 /* Write a .func or .kernel declaration (not a definition) along with
429 a helper comment for use by ld. S is the stream to write to, DECL
430 the decl for the function with name NAME. */
432 static void
433 write_function_decl_and_comment (std::stringstream &s, const char *name, const_tree decl)
435 s << "// BEGIN";
436 if (TREE_PUBLIC (decl))
437 s << " GLOBAL";
438 s << " FUNCTION DECL: ";
439 if (name[0] == '*')
440 s << (name + 1);
441 else
442 s << name;
443 s << "\n";
444 nvptx_write_function_decl (s, name, decl);
445 s << ";\n";
448 /* Check NAME for special function names and redirect them by returning a
449 replacement. This applies to malloc, free and realloc, for which we
450 want to use libgcc wrappers, and call, which triggers a bug in ptxas. */
452 static const char *
453 nvptx_name_replacement (const char *name)
455 if (strcmp (name, "call") == 0)
456 return "__nvptx_call";
457 if (strcmp (name, "malloc") == 0)
458 return "__nvptx_malloc";
459 if (strcmp (name, "free") == 0)
460 return "__nvptx_free";
461 if (strcmp (name, "realloc") == 0)
462 return "__nvptx_realloc";
463 return name;
466 /* If DECL is a FUNCTION_DECL, check the hash table to see if we
467 already encountered it, and if not, insert it and write a ptx
468 declarations that will be output at the end of compilation. */
470 static bool
471 nvptx_record_fndecl (tree decl, bool force = false)
473 if (decl == NULL_TREE || TREE_CODE (decl) != FUNCTION_DECL
474 || !DECL_EXTERNAL (decl))
475 return true;
477 if (!force && TYPE_ARG_TYPES (TREE_TYPE (decl)) == NULL_TREE)
478 return false;
480 tree *slot = declared_fndecls_htab->find_slot (decl, INSERT);
481 if (*slot == NULL)
483 *slot = decl;
484 const char *name = get_fnname_from_decl (decl);
485 name = nvptx_name_replacement (name);
486 write_function_decl_and_comment (func_decls, name, decl);
488 return true;
491 /* Record that we need to emit a ptx decl for DECL. Either do it now, or
492 record it for later in case we have no argument information at this
493 point. */
495 void
496 nvptx_record_needed_fndecl (tree decl)
498 if (nvptx_record_fndecl (decl))
499 return;
501 tree *slot = needed_fndecls_htab->find_slot (decl, INSERT);
502 if (*slot == NULL)
503 *slot = decl;
506 /* Implement ASM_DECLARE_FUNCTION_NAME. Writes the start of a ptx
507 function, including local var decls and copies from the arguments to
508 local regs. */
510 void
511 nvptx_declare_function_name (FILE *file, const char *name, const_tree decl)
513 tree fntype = TREE_TYPE (decl);
514 tree result_type = TREE_TYPE (fntype);
516 name = nvptx_name_replacement (name);
518 std::stringstream s;
519 write_function_decl_and_comment (s, name, decl);
520 s << "// BEGIN";
521 if (TREE_PUBLIC (decl))
522 s << " GLOBAL";
523 s << " FUNCTION DEF: ";
525 if (name[0] == '*')
526 s << (name + 1);
527 else
528 s << name;
529 s << "\n";
531 nvptx_write_function_decl (s, name, decl);
532 fprintf (file, "%s", s.str().c_str());
534 bool return_in_mem = (TYPE_MODE (result_type) != VOIDmode
535 && !RETURN_IN_REG_P (TYPE_MODE (result_type)));
537 fprintf (file, "\n{\n");
539 /* Ensure all arguments that should live in a register have one
540 declared. We'll emit the copies below. */
541 walk_args_for_param (file, TYPE_ARG_TYPES (fntype), DECL_ARGUMENTS (decl),
542 false, return_in_mem);
543 if (return_in_mem)
544 fprintf (file, "\t.reg.u%d %%ar1;\n", GET_MODE_BITSIZE (Pmode));
546 /* C++11 ABI causes us to return a reference to the passed in
547 pointer for return_in_mem. */
548 if (cfun->machine->ret_reg_mode != VOIDmode)
550 machine_mode mode = arg_promotion
551 ((machine_mode)cfun->machine->ret_reg_mode);
552 fprintf (file, "\t.reg%s %%retval;\n",
553 nvptx_ptx_type_from_mode (mode, false));
556 if (stdarg_p (fntype))
557 fprintf (file, "\t.reg.u%d %%argp;\n", GET_MODE_BITSIZE (Pmode));
559 fprintf (file, "\t.reg.u%d %s;\n", GET_MODE_BITSIZE (Pmode),
560 reg_names[OUTGOING_STATIC_CHAIN_REGNUM]);
562 /* Declare the pseudos we have as ptx registers. */
563 int maxregs = max_reg_num ();
564 for (int i = LAST_VIRTUAL_REGISTER + 1; i < maxregs; i++)
566 if (regno_reg_rtx[i] != const0_rtx)
568 machine_mode mode = PSEUDO_REGNO_MODE (i);
569 int count = maybe_split_mode (&mode);
570 if (count > 1)
572 while (count-- > 0)
573 fprintf (file, "\t.reg%s %%r%d$%d;\n",
574 nvptx_ptx_type_from_mode (mode, true),
575 i, count);
577 else
578 fprintf (file, "\t.reg%s %%r%d;\n",
579 nvptx_ptx_type_from_mode (mode, true),
584 /* The only reason we might be using outgoing args is if we call a stdargs
585 function. Allocate the space for this. If we called varargs functions
586 without passing any variadic arguments, we'll see a reference to outargs
587 even with a zero outgoing_args_size. */
588 HOST_WIDE_INT sz = crtl->outgoing_args_size;
589 if (sz == 0)
590 sz = 1;
591 if (cfun->machine->has_call_with_varargs)
592 fprintf (file, "\t.reg.u%d %%outargs;\n"
593 "\t.local.align 8 .b8 %%outargs_ar[" HOST_WIDE_INT_PRINT_DEC"];\n",
594 BITS_PER_WORD, sz);
595 if (cfun->machine->punning_buffer_size > 0)
596 fprintf (file, "\t.reg.u%d %%punbuffer;\n"
597 "\t.local.align 8 .b8 %%punbuffer_ar[%d];\n",
598 BITS_PER_WORD, cfun->machine->punning_buffer_size);
600 /* Declare a local variable for the frame. */
601 sz = get_frame_size ();
602 if (sz > 0 || cfun->machine->has_call_with_sc)
604 int alignment = crtl->stack_alignment_needed / BITS_PER_UNIT;
606 fprintf (file, "\t.reg.u%d %%frame;\n"
607 "\t.local.align %d .b8 %%farray[" HOST_WIDE_INT_PRINT_DEC"];\n",
608 BITS_PER_WORD, alignment, sz == 0 ? 1 : sz);
609 fprintf (file, "\tcvta.local.u%d %%frame, %%farray;\n",
610 BITS_PER_WORD);
613 if (cfun->machine->has_call_with_varargs)
614 fprintf (file, "\tcvta.local.u%d %%outargs, %%outargs_ar;\n",
615 BITS_PER_WORD);
616 if (cfun->machine->punning_buffer_size > 0)
617 fprintf (file, "\tcvta.local.u%d %%punbuffer, %%punbuffer_ar;\n",
618 BITS_PER_WORD);
620 /* Now emit any copies necessary for arguments. */
621 walk_args_for_param (file, TYPE_ARG_TYPES (fntype), DECL_ARGUMENTS (decl),
622 true, return_in_mem);
623 if (return_in_mem)
624 fprintf (file, "\tld.param.u%d %%ar1, [%%in_ar1];\n",
625 GET_MODE_BITSIZE (Pmode));
626 if (stdarg_p (fntype))
627 fprintf (file, "\tld.param.u%d %%argp, [%%in_argp];\n",
628 GET_MODE_BITSIZE (Pmode));
631 /* Output a return instruction. Also copy the return value to its outgoing
632 location. */
634 const char *
635 nvptx_output_return (void)
637 machine_mode mode = (machine_mode)cfun->machine->ret_reg_mode;
639 if (mode != VOIDmode)
641 mode = arg_promotion (mode);
642 fprintf (asm_out_file, "\tst.param%s\t[%%out_retval], %%retval;\n",
643 nvptx_ptx_type_from_mode (mode, false));
646 return "ret;";
649 /* Construct a function declaration from a call insn. This can be
650 necessary for two reasons - either we have an indirect call which
651 requires a .callprototype declaration, or we have a libcall
652 generated by emit_library_call for which no decl exists. */
654 static void
655 write_func_decl_from_insn (std::stringstream &s, rtx result, rtx pat,
656 rtx callee)
658 bool callprototype = register_operand (callee, Pmode);
659 const char *name = "_";
660 if (!callprototype)
662 name = XSTR (callee, 0);
663 name = nvptx_name_replacement (name);
664 s << "// BEGIN GLOBAL FUNCTION DECL: " << name << "\n";
666 s << (callprototype ? "\t.callprototype\t" : "\t.extern .func ");
668 if (result != NULL_RTX)
670 s << "(.param";
671 s << nvptx_ptx_type_from_mode (arg_promotion (GET_MODE (result)),
672 false);
673 s << " ";
674 if (callprototype)
675 s << "_";
676 else
677 s << "%out_retval";
678 s << ")";
681 s << name;
683 int arg_end = XVECLEN (pat, 0);
685 if (1 < arg_end)
687 const char *comma = "";
688 s << " (";
689 for (int i = 1; i < arg_end; i++)
691 rtx t = XEXP (XVECEXP (pat, 0, i), 0);
692 machine_mode mode = GET_MODE (t);
693 int count = maybe_split_mode (&mode);
695 while (count--)
697 s << comma << ".param";
698 s << nvptx_ptx_type_from_mode (mode, false);
699 s << " ";
700 if (callprototype)
701 s << "_";
702 else
703 s << "%arg" << i - 1;
704 if (mode == QImode || mode == HImode)
705 s << "[1]";
706 comma = ", ";
709 s << ")";
711 s << ";\n";
714 /* Terminate a function by writing a closing brace to FILE. */
716 void
717 nvptx_function_end (FILE *file)
719 fprintf (file, "\t}\n");
722 /* Decide whether we can make a sibling call to a function. For ptx, we
723 can't. */
725 static bool
726 nvptx_function_ok_for_sibcall (tree, tree)
728 return false;
731 /* Return Dynamic ReAlignment Pointer RTX. For PTX there isn't any. */
733 static rtx
734 nvptx_get_drap_rtx (void)
736 return NULL_RTX;
739 /* Implement the TARGET_CALL_ARGS hook. Record information about one
740 argument to the next call. */
742 static void
743 nvptx_call_args (rtx arg, tree funtype)
745 if (cfun->machine->start_call == NULL_RTX)
747 cfun->machine->call_args = NULL;
748 cfun->machine->funtype = funtype;
749 cfun->machine->start_call = const0_rtx;
751 if (arg == pc_rtx)
752 return;
754 rtx_expr_list *args_so_far = cfun->machine->call_args;
755 if (REG_P (arg))
756 cfun->machine->call_args = alloc_EXPR_LIST (VOIDmode, arg, args_so_far);
759 /* Implement the corresponding END_CALL_ARGS hook. Clear and free the
760 information we recorded. */
762 static void
763 nvptx_end_call_args (void)
765 cfun->machine->start_call = NULL_RTX;
766 free_EXPR_LIST_list (&cfun->machine->call_args);
769 /* Emit the sequence for a call to ADDRESS, setting RETVAL. Keep
770 track of whether calls involving static chains or varargs were seen
771 in the current function.
772 For libcalls, maintain a hash table of decls we have seen, and
773 record a function decl for later when encountering a new one. */
775 void
776 nvptx_expand_call (rtx retval, rtx address)
778 int nargs = 0;
779 rtx callee = XEXP (address, 0);
780 rtx pat, t;
781 rtvec vec;
782 bool external_decl = false;
783 rtx varargs = NULL_RTX;
784 tree decl_type = NULL_TREE;
786 for (t = cfun->machine->call_args; t; t = XEXP (t, 1))
787 nargs++;
789 if (!call_insn_operand (callee, Pmode))
791 callee = force_reg (Pmode, callee);
792 address = change_address (address, QImode, callee);
795 if (GET_CODE (callee) == SYMBOL_REF)
797 tree decl = SYMBOL_REF_DECL (callee);
798 if (decl != NULL_TREE)
800 decl_type = TREE_TYPE (decl);
801 if (DECL_STATIC_CHAIN (decl))
802 cfun->machine->has_call_with_sc = true;
803 if (DECL_EXTERNAL (decl))
804 external_decl = true;
808 if (cfun->machine->funtype
809 /* It's possible to construct testcases where we call a variable.
810 See compile/20020129-1.c. stdarg_p will crash so avoid calling it
811 in such a case. */
812 && (TREE_CODE (cfun->machine->funtype) == FUNCTION_TYPE
813 || TREE_CODE (cfun->machine->funtype) == METHOD_TYPE)
814 && stdarg_p (cfun->machine->funtype))
816 varargs = gen_reg_rtx (Pmode);
817 if (Pmode == DImode)
818 emit_move_insn (varargs, stack_pointer_rtx);
819 else
820 emit_move_insn (varargs, stack_pointer_rtx);
821 cfun->machine->has_call_with_varargs = true;
823 vec = rtvec_alloc (nargs + 1 + (varargs ? 1 : 0));
824 pat = gen_rtx_PARALLEL (VOIDmode, vec);
826 int vec_pos = 0;
828 rtx tmp_retval = retval;
829 t = gen_rtx_CALL (VOIDmode, address, const0_rtx);
830 if (retval != NULL_RTX)
832 if (!nvptx_register_operand (retval, GET_MODE (retval)))
833 tmp_retval = gen_reg_rtx (GET_MODE (retval));
834 t = gen_rtx_SET (tmp_retval, t);
836 XVECEXP (pat, 0, vec_pos++) = t;
838 /* Construct the call insn, including a USE for each argument pseudo
839 register. These will be used when printing the insn. */
840 for (rtx arg = cfun->machine->call_args; arg; arg = XEXP (arg, 1))
842 rtx this_arg = XEXP (arg, 0);
843 XVECEXP (pat, 0, vec_pos++) = gen_rtx_USE (VOIDmode, this_arg);
846 if (varargs)
847 XVECEXP (pat, 0, vec_pos++) = gen_rtx_USE (VOIDmode, varargs);
849 gcc_assert (vec_pos = XVECLEN (pat, 0));
851 /* If this is a libcall, decl_type is NULL. For a call to a non-libcall
852 undeclared function, we'll have an external decl without arg types.
853 In either case we have to try to construct a ptx declaration from one of
854 the calls to the function. */
855 if (!REG_P (callee)
856 && (decl_type == NULL_TREE
857 || (external_decl && TYPE_ARG_TYPES (decl_type) == NULL_TREE)))
859 rtx *slot = declared_libfuncs_htab->find_slot (callee, INSERT);
860 if (*slot == NULL)
862 *slot = callee;
863 write_func_decl_from_insn (func_decls, retval, pat, callee);
866 emit_call_insn (pat);
867 if (tmp_retval != retval)
868 emit_move_insn (retval, tmp_retval);
871 /* Implement TARGET_FUNCTION_ARG. */
873 static rtx
874 nvptx_function_arg (cumulative_args_t, machine_mode mode,
875 const_tree, bool named)
877 if (mode == VOIDmode)
878 return NULL_RTX;
880 if (named)
881 return gen_reg_rtx (mode);
882 return NULL_RTX;
885 /* Implement TARGET_FUNCTION_INCOMING_ARG. */
887 static rtx
888 nvptx_function_incoming_arg (cumulative_args_t cum_v, machine_mode mode,
889 const_tree, bool named)
891 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
892 if (mode == VOIDmode)
893 return NULL_RTX;
895 if (!named)
896 return NULL_RTX;
898 /* No need to deal with split modes here, the only case that can
899 happen is complex modes and those are dealt with by
900 TARGET_SPLIT_COMPLEX_ARG. */
901 return gen_rtx_UNSPEC (mode,
902 gen_rtvec (1, GEN_INT (1 + cum->count)),
903 UNSPEC_ARG_REG);
906 /* Implement TARGET_FUNCTION_ARG_ADVANCE. */
908 static void
909 nvptx_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
910 const_tree type ATTRIBUTE_UNUSED,
911 bool named ATTRIBUTE_UNUSED)
913 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
914 if (mode == TImode)
915 cum->count += 2;
916 else
917 cum->count++;
920 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook.
922 For nvptx, we know how to handle functions declared as stdarg: by
923 passing an extra pointer to the unnamed arguments. However, the
924 Fortran frontend can produce a different situation, where a
925 function pointer is declared with no arguments, but the actual
926 function and calls to it take more arguments. In that case, we
927 want to ensure the call matches the definition of the function. */
929 static bool
930 nvptx_strict_argument_naming (cumulative_args_t cum_v)
932 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
933 return cum->fntype == NULL_TREE || stdarg_p (cum->fntype);
936 /* Implement TARGET_FUNCTION_ARG_BOUNDARY. */
938 static unsigned int
939 nvptx_function_arg_boundary (machine_mode mode, const_tree type)
941 unsigned int boundary = type ? TYPE_ALIGN (type) : GET_MODE_BITSIZE (mode);
943 if (boundary > BITS_PER_WORD)
944 return 2 * BITS_PER_WORD;
946 if (mode == BLKmode)
948 HOST_WIDE_INT size = int_size_in_bytes (type);
949 if (size > 4)
950 return 2 * BITS_PER_WORD;
951 if (boundary < BITS_PER_WORD)
953 if (size >= 3)
954 return BITS_PER_WORD;
955 if (size >= 2)
956 return 2 * BITS_PER_UNIT;
959 return boundary;
962 /* TARGET_FUNCTION_VALUE implementation. Returns an RTX representing the place
963 where function FUNC returns or receives a value of data type TYPE. */
965 static rtx
966 nvptx_function_value (const_tree type, const_tree func ATTRIBUTE_UNUSED,
967 bool outgoing)
969 int unsignedp = TYPE_UNSIGNED (type);
970 machine_mode orig_mode = TYPE_MODE (type);
971 machine_mode mode = promote_function_mode (type, orig_mode,
972 &unsignedp, NULL_TREE, 1);
973 if (outgoing)
974 return gen_rtx_REG (mode, NVPTX_RETURN_REGNUM);
975 if (cfun->machine->start_call == NULL_RTX)
976 /* Pretend to return in a hard reg for early uses before pseudos can be
977 generated. */
978 return gen_rtx_REG (mode, NVPTX_RETURN_REGNUM);
979 return gen_reg_rtx (mode);
982 /* Implement TARGET_LIBCALL_VALUE. */
984 static rtx
985 nvptx_libcall_value (machine_mode mode, const_rtx)
987 if (cfun->machine->start_call == NULL_RTX)
988 /* Pretend to return in a hard reg for early uses before pseudos can be
989 generated. */
990 return gen_rtx_REG (mode, NVPTX_RETURN_REGNUM);
991 return gen_reg_rtx (mode);
994 /* Implement TARGET_FUNCTION_VALUE_REGNO_P. */
996 static bool
997 nvptx_function_value_regno_p (const unsigned int regno)
999 return regno == NVPTX_RETURN_REGNUM;
1002 /* Types with a mode other than those supported by the machine are passed by
1003 reference in memory. */
1005 static bool
1006 nvptx_pass_by_reference (cumulative_args_t, machine_mode mode,
1007 const_tree type, bool)
1009 return !PASS_IN_REG_P (mode, type);
1012 /* Implement TARGET_RETURN_IN_MEMORY. */
1014 static bool
1015 nvptx_return_in_memory (const_tree type, const_tree)
1017 machine_mode mode = TYPE_MODE (type);
1018 if (!RETURN_IN_REG_P (mode))
1019 return true;
1020 return false;
1023 /* Implement TARGET_PROMOTE_FUNCTION_MODE. */
1025 static machine_mode
1026 nvptx_promote_function_mode (const_tree type, machine_mode mode,
1027 int *punsignedp,
1028 const_tree funtype, int for_return)
1030 if (type == NULL_TREE)
1031 return mode;
1032 if (for_return)
1033 return promote_mode (type, mode, punsignedp);
1034 /* For K&R-style functions, try to match the language promotion rules to
1035 minimize type mismatches at assembly time. */
1036 if (TYPE_ARG_TYPES (funtype) == NULL_TREE
1037 && type != NULL_TREE
1038 && !AGGREGATE_TYPE_P (type))
1040 if (mode == SFmode)
1041 mode = DFmode;
1042 mode = arg_promotion (mode);
1045 return mode;
1048 /* Implement TARGET_STATIC_CHAIN. */
1050 static rtx
1051 nvptx_static_chain (const_tree fndecl, bool incoming_p)
1053 if (!DECL_STATIC_CHAIN (fndecl))
1054 return NULL;
1056 if (incoming_p)
1057 return gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
1058 else
1059 return gen_rtx_REG (Pmode, OUTGOING_STATIC_CHAIN_REGNUM);
1062 /* Emit a comparison COMPARE, and return the new test to be used in the
1063 jump. */
1066 nvptx_expand_compare (rtx compare)
1068 rtx pred = gen_reg_rtx (BImode);
1069 rtx cmp = gen_rtx_fmt_ee (GET_CODE (compare), BImode,
1070 XEXP (compare, 0), XEXP (compare, 1));
1071 emit_insn (gen_rtx_SET (pred, cmp));
1072 return gen_rtx_NE (BImode, pred, const0_rtx);
1075 /* When loading an operand ORIG_OP, verify whether an address space
1076 conversion to generic is required, and if so, perform it. Also
1077 check for SYMBOL_REFs for function decls and call
1078 nvptx_record_needed_fndecl as needed.
1079 Return either the original operand, or the converted one. */
1082 nvptx_maybe_convert_symbolic_operand (rtx orig_op)
1084 if (GET_MODE (orig_op) != Pmode)
1085 return orig_op;
1087 rtx op = orig_op;
1088 while (GET_CODE (op) == PLUS || GET_CODE (op) == CONST)
1089 op = XEXP (op, 0);
1090 if (GET_CODE (op) != SYMBOL_REF)
1091 return orig_op;
1093 tree decl = SYMBOL_REF_DECL (op);
1094 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1096 nvptx_record_needed_fndecl (decl);
1097 return orig_op;
1100 addr_space_t as = nvptx_addr_space_from_address (op);
1101 if (as == ADDR_SPACE_GENERIC)
1102 return orig_op;
1104 enum unspec code;
1105 code = (as == ADDR_SPACE_GLOBAL ? UNSPEC_FROM_GLOBAL
1106 : as == ADDR_SPACE_LOCAL ? UNSPEC_FROM_LOCAL
1107 : as == ADDR_SPACE_SHARED ? UNSPEC_FROM_SHARED
1108 : as == ADDR_SPACE_CONST ? UNSPEC_FROM_CONST
1109 : UNSPEC_FROM_PARAM);
1110 rtx dest = gen_reg_rtx (Pmode);
1111 emit_insn (gen_rtx_SET (dest, gen_rtx_UNSPEC (Pmode, gen_rtvec (1, orig_op),
1112 code)));
1113 return dest;
1116 /* Returns true if X is a valid address for use in a memory reference. */
1118 static bool
1119 nvptx_legitimate_address_p (machine_mode, rtx x, bool)
1121 enum rtx_code code = GET_CODE (x);
1123 switch (code)
1125 case REG:
1126 return true;
1128 case PLUS:
1129 if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1)))
1130 return true;
1131 return false;
1133 case CONST:
1134 case SYMBOL_REF:
1135 case LABEL_REF:
1136 return true;
1138 default:
1139 return false;
1143 /* Implement HARD_REGNO_MODE_OK. We barely use hard regs, but we want
1144 to ensure that the return register's mode isn't changed. */
1146 bool
1147 nvptx_hard_regno_mode_ok (int regno, machine_mode mode)
1149 if (regno != NVPTX_RETURN_REGNUM
1150 || cfun == NULL || cfun->machine->ret_reg_mode == VOIDmode)
1151 return true;
1152 return mode == cfun->machine->ret_reg_mode;
1155 /* Convert an address space AS to the corresponding ptx string. */
1157 const char *
1158 nvptx_section_from_addr_space (addr_space_t as)
1160 switch (as)
1162 case ADDR_SPACE_CONST:
1163 return ".const";
1165 case ADDR_SPACE_GLOBAL:
1166 return ".global";
1168 case ADDR_SPACE_SHARED:
1169 return ".shared";
1171 case ADDR_SPACE_GENERIC:
1172 return "";
1174 default:
1175 gcc_unreachable ();
1179 /* Determine whether DECL goes into .const or .global. */
1181 const char *
1182 nvptx_section_for_decl (const_tree decl)
1184 bool is_const = (CONSTANT_CLASS_P (decl)
1185 || TREE_CODE (decl) == CONST_DECL
1186 || TREE_READONLY (decl));
1187 if (is_const)
1188 return ".const";
1190 return ".global";
1193 /* Look for a SYMBOL_REF in ADDR and return the address space to be used
1194 for the insn referencing this address. */
1196 addr_space_t
1197 nvptx_addr_space_from_address (rtx addr)
1199 while (GET_CODE (addr) == PLUS || GET_CODE (addr) == CONST)
1200 addr = XEXP (addr, 0);
1201 if (GET_CODE (addr) != SYMBOL_REF)
1202 return ADDR_SPACE_GENERIC;
1204 tree decl = SYMBOL_REF_DECL (addr);
1205 if (decl == NULL_TREE || TREE_CODE (decl) == FUNCTION_DECL)
1206 return ADDR_SPACE_GENERIC;
1208 bool is_const = (CONSTANT_CLASS_P (decl)
1209 || TREE_CODE (decl) == CONST_DECL
1210 || TREE_READONLY (decl));
1211 if (is_const)
1212 return ADDR_SPACE_CONST;
1214 return ADDR_SPACE_GLOBAL;
1217 /* Machinery to output constant initializers. When beginning an initializer,
1218 we decide on a chunk size (which is visible in ptx in the type used), and
1219 then all initializer data is buffered until a chunk is filled and ready to
1220 be written out. */
1222 /* Used when assembling integers to ensure data is emitted in
1223 pieces whose size matches the declaration we printed. */
1224 static unsigned int decl_chunk_size;
1225 static machine_mode decl_chunk_mode;
1226 /* Used in the same situation, to keep track of the byte offset
1227 into the initializer. */
1228 static unsigned HOST_WIDE_INT decl_offset;
1229 /* The initializer part we are currently processing. */
1230 static HOST_WIDE_INT init_part;
1231 /* The total size of the object. */
1232 static unsigned HOST_WIDE_INT object_size;
1233 /* True if we found a skip extending to the end of the object. Used to
1234 assert that no data follows. */
1235 static bool object_finished;
1237 /* Write the necessary separator string to begin a new initializer value. */
1239 static void
1240 begin_decl_field (void)
1242 /* We never see decl_offset at zero by the time we get here. */
1243 if (decl_offset == decl_chunk_size)
1244 fprintf (asm_out_file, " = { ");
1245 else
1246 fprintf (asm_out_file, ", ");
1249 /* Output the currently stored chunk as an initializer value. */
1251 static void
1252 output_decl_chunk (void)
1254 begin_decl_field ();
1255 output_address (gen_int_mode (init_part, decl_chunk_mode));
1256 init_part = 0;
1259 /* Add value VAL sized SIZE to the data we're emitting, and keep writing
1260 out chunks as they fill up. */
1262 static void
1263 nvptx_assemble_value (HOST_WIDE_INT val, unsigned int size)
1265 unsigned HOST_WIDE_INT chunk_offset = decl_offset % decl_chunk_size;
1266 gcc_assert (!object_finished);
1267 while (size > 0)
1269 int this_part = size;
1270 if (chunk_offset + this_part > decl_chunk_size)
1271 this_part = decl_chunk_size - chunk_offset;
1272 HOST_WIDE_INT val_part;
1273 HOST_WIDE_INT mask = 2;
1274 mask <<= this_part * BITS_PER_UNIT - 1;
1275 val_part = val & (mask - 1);
1276 init_part |= val_part << (BITS_PER_UNIT * chunk_offset);
1277 val >>= BITS_PER_UNIT * this_part;
1278 size -= this_part;
1279 decl_offset += this_part;
1280 if (decl_offset % decl_chunk_size == 0)
1281 output_decl_chunk ();
1283 chunk_offset = 0;
1287 /* Target hook for assembling integer object X of size SIZE. */
1289 static bool
1290 nvptx_assemble_integer (rtx x, unsigned int size, int ARG_UNUSED (aligned_p))
1292 if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
1294 gcc_assert (size = decl_chunk_size);
1295 if (decl_offset % decl_chunk_size != 0)
1296 sorry ("cannot emit unaligned pointers in ptx assembly");
1297 decl_offset += size;
1298 begin_decl_field ();
1300 HOST_WIDE_INT off = 0;
1301 if (GET_CODE (x) == CONST)
1302 x = XEXP (x, 0);
1303 if (GET_CODE (x) == PLUS)
1305 off = INTVAL (XEXP (x, 1));
1306 x = XEXP (x, 0);
1308 if (GET_CODE (x) == SYMBOL_REF)
1310 nvptx_record_needed_fndecl (SYMBOL_REF_DECL (x));
1311 fprintf (asm_out_file, "generic(");
1312 output_address (x);
1313 fprintf (asm_out_file, ")");
1315 if (off != 0)
1316 fprintf (asm_out_file, " + " HOST_WIDE_INT_PRINT_DEC, off);
1317 return true;
1320 HOST_WIDE_INT val;
1321 switch (GET_CODE (x))
1323 case CONST_INT:
1324 val = INTVAL (x);
1325 break;
1326 case CONST_DOUBLE:
1327 gcc_unreachable ();
1328 break;
1329 default:
1330 gcc_unreachable ();
1333 nvptx_assemble_value (val, size);
1334 return true;
1337 /* Output SIZE zero bytes. We ignore the FILE argument since the
1338 functions we're calling to perform the output just use
1339 asm_out_file. */
1341 void
1342 nvptx_output_skip (FILE *, unsigned HOST_WIDE_INT size)
1344 if (decl_offset + size >= object_size)
1346 if (decl_offset % decl_chunk_size != 0)
1347 nvptx_assemble_value (0, decl_chunk_size);
1348 object_finished = true;
1349 return;
1352 while (size > decl_chunk_size)
1354 nvptx_assemble_value (0, decl_chunk_size);
1355 size -= decl_chunk_size;
1357 while (size-- > 0)
1358 nvptx_assemble_value (0, 1);
1361 /* Output a string STR with length SIZE. As in nvptx_output_skip we
1362 ignore the FILE arg. */
1364 void
1365 nvptx_output_ascii (FILE *, const char *str, unsigned HOST_WIDE_INT size)
1367 for (unsigned HOST_WIDE_INT i = 0; i < size; i++)
1368 nvptx_assemble_value (str[i], 1);
1371 /* Called when the initializer for a decl has been completely output through
1372 combinations of the three functions above. */
1374 static void
1375 nvptx_assemble_decl_end (void)
1377 if (decl_offset != 0)
1379 if (!object_finished && decl_offset % decl_chunk_size != 0)
1380 nvptx_assemble_value (0, decl_chunk_size);
1382 fprintf (asm_out_file, " }");
1384 fprintf (asm_out_file, ";\n");
1387 /* Start a declaration of a variable of TYPE with NAME to
1388 FILE. IS_PUBLIC says whether this will be externally visible.
1389 Here we just write the linker hint and decide on the chunk size
1390 to use. */
1392 static void
1393 init_output_initializer (FILE *file, const char *name, const_tree type,
1394 bool is_public)
1396 fprintf (file, "// BEGIN%s VAR DEF: ", is_public ? " GLOBAL" : "");
1397 assemble_name_raw (file, name);
1398 fputc ('\n', file);
1400 if (TREE_CODE (type) == ARRAY_TYPE)
1401 type = TREE_TYPE (type);
1402 int sz = int_size_in_bytes (type);
1403 if ((TREE_CODE (type) != INTEGER_TYPE
1404 && TREE_CODE (type) != ENUMERAL_TYPE
1405 && TREE_CODE (type) != REAL_TYPE)
1406 || sz < 0
1407 || sz > HOST_BITS_PER_WIDE_INT)
1408 type = ptr_type_node;
1409 decl_chunk_size = int_size_in_bytes (type);
1410 decl_chunk_mode = int_mode_for_mode (TYPE_MODE (type));
1411 decl_offset = 0;
1412 init_part = 0;
1413 object_finished = false;
1416 /* Implement TARGET_ASM_DECLARE_CONSTANT_NAME. Begin the process of
1417 writing a constant variable EXP with NAME and SIZE and its
1418 initializer to FILE. */
1420 static void
1421 nvptx_asm_declare_constant_name (FILE *file, const char *name,
1422 const_tree exp, HOST_WIDE_INT size)
1424 tree type = TREE_TYPE (exp);
1425 init_output_initializer (file, name, type, false);
1426 fprintf (file, "\t.const .align %d .u%d ",
1427 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT,
1428 decl_chunk_size * BITS_PER_UNIT);
1429 assemble_name (file, name);
1430 fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC "]",
1431 (size + decl_chunk_size - 1) / decl_chunk_size);
1432 object_size = size;
1435 /* Implement the ASM_DECLARE_OBJECT_NAME macro. Used to start writing
1436 a variable DECL with NAME to FILE. */
1438 void
1439 nvptx_declare_object_name (FILE *file, const char *name, const_tree decl)
1441 if (decl && DECL_SIZE (decl))
1443 tree type = TREE_TYPE (decl);
1444 unsigned HOST_WIDE_INT size;
1446 init_output_initializer (file, name, type, TREE_PUBLIC (decl));
1447 size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
1448 const char *section = nvptx_section_for_decl (decl);
1449 fprintf (file, "\t%s%s .align %d .u%d ",
1450 TREE_PUBLIC (decl) ? " .visible" : "", section,
1451 DECL_ALIGN (decl) / BITS_PER_UNIT,
1452 decl_chunk_size * BITS_PER_UNIT);
1453 assemble_name (file, name);
1454 if (size > 0)
1455 fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC "]",
1456 (size + decl_chunk_size - 1) / decl_chunk_size);
1457 else
1458 object_finished = true;
1459 object_size = size;
1463 /* Implement TARGET_ASM_GLOBALIZE_LABEL by doing nothing. */
1465 static void
1466 nvptx_globalize_label (FILE *, const char *)
1470 /* Implement TARGET_ASM_ASSEMBLE_UNDEFINED_DECL. Write an extern
1471 declaration only for variable DECL with NAME to FILE. */
1472 static void
1473 nvptx_assemble_undefined_decl (FILE *file, const char *name, const_tree decl)
1475 if (TREE_CODE (decl) != VAR_DECL)
1476 return;
1477 const char *section = nvptx_section_for_decl (decl);
1478 fprintf (file, "// BEGIN%s VAR DECL: ", TREE_PUBLIC (decl) ? " GLOBAL" : "");
1479 assemble_name_raw (file, name);
1480 fputs ("\n", file);
1481 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
1482 fprintf (file, ".extern %s .b8 ", section);
1483 assemble_name_raw (file, name);
1484 if (size > 0)
1485 fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC"]", size);
1486 fprintf (file, ";\n\n");
1489 /* Output INSN, which is a call to CALLEE with result RESULT. For ptx, this
1490 involves writing .param declarations and in/out copies into them. For
1491 indirect calls, also write the .callprototype. */
1493 const char *
1494 nvptx_output_call_insn (rtx_insn *insn, rtx result, rtx callee)
1496 char buf[256];
1497 static int labelno;
1498 bool needs_tgt = register_operand (callee, Pmode);
1499 rtx pat = PATTERN (insn);
1500 int arg_end = XVECLEN (pat, 0);
1501 tree decl = NULL_TREE;
1503 fprintf (asm_out_file, "\t{\n");
1504 if (result != NULL)
1505 fprintf (asm_out_file, "\t\t.param%s %%retval_in;\n",
1506 nvptx_ptx_type_from_mode (arg_promotion (GET_MODE (result)),
1507 false));
1509 /* Ensure we have a ptx declaration in the output if necessary. */
1510 if (GET_CODE (callee) == SYMBOL_REF)
1512 decl = SYMBOL_REF_DECL (callee);
1513 if (decl && DECL_EXTERNAL (decl))
1514 nvptx_record_fndecl (decl);
1517 if (needs_tgt)
1519 ASM_GENERATE_INTERNAL_LABEL (buf, "LCT", labelno);
1520 labelno++;
1521 ASM_OUTPUT_LABEL (asm_out_file, buf);
1522 std::stringstream s;
1523 write_func_decl_from_insn (s, result, pat, callee);
1524 fputs (s.str().c_str(), asm_out_file);
1527 for (int i = 1, argno = 0; i < arg_end; i++)
1529 rtx t = XEXP (XVECEXP (pat, 0, i), 0);
1530 machine_mode mode = GET_MODE (t);
1531 int count = maybe_split_mode (&mode);
1533 while (count--)
1534 fprintf (asm_out_file, "\t\t.param%s %%out_arg%d%s;\n",
1535 nvptx_ptx_type_from_mode (mode, false), argno++,
1536 mode == QImode || mode == HImode ? "[1]" : "");
1538 for (int i = 1, argno = 0; i < arg_end; i++)
1540 rtx t = XEXP (XVECEXP (pat, 0, i), 0);
1541 gcc_assert (REG_P (t));
1542 machine_mode mode = GET_MODE (t);
1543 int count = maybe_split_mode (&mode);
1545 if (count == 1)
1546 fprintf (asm_out_file, "\t\tst.param%s [%%out_arg%d], %%r%d;\n",
1547 nvptx_ptx_type_from_mode (mode, false), argno++,
1548 REGNO (t));
1549 else
1551 int n = 0;
1552 while (count--)
1553 fprintf (asm_out_file, "\t\tst.param%s [%%out_arg%d], %%r%d$%d;\n",
1554 nvptx_ptx_type_from_mode (mode, false), argno++,
1555 REGNO (t), n++);
1559 fprintf (asm_out_file, "\t\tcall ");
1560 if (result != NULL_RTX)
1561 fprintf (asm_out_file, "(%%retval_in), ");
1563 if (decl)
1565 const char *name = get_fnname_from_decl (decl);
1566 name = nvptx_name_replacement (name);
1567 assemble_name (asm_out_file, name);
1569 else
1570 output_address (callee);
1572 if (arg_end > 1 || (decl && DECL_STATIC_CHAIN (decl)))
1574 const char *comma = "";
1576 fprintf (asm_out_file, ", (");
1577 for (int i = 1, argno = 0; i < arg_end; i++)
1579 rtx t = XEXP (XVECEXP (pat, 0, i), 0);
1580 machine_mode mode = GET_MODE (t);
1581 int count = maybe_split_mode (&mode);
1583 while (count--)
1585 fprintf (asm_out_file, "%s%%out_arg%d", comma, argno++);
1586 comma = ", ";
1589 if (decl && DECL_STATIC_CHAIN (decl))
1590 fprintf (asm_out_file, "%s%s", comma,
1591 reg_names [OUTGOING_STATIC_CHAIN_REGNUM]);
1593 fprintf (asm_out_file, ")");
1596 if (needs_tgt)
1598 fprintf (asm_out_file, ", ");
1599 assemble_name (asm_out_file, buf);
1601 fprintf (asm_out_file, ";\n");
1602 if (result != NULL_RTX)
1603 return "ld.param%t0\t%0, [%%retval_in];\n\t}";
1605 return "}";
1608 /* Implement TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1610 static bool
1611 nvptx_print_operand_punct_valid_p (unsigned char c)
1613 return c == '.' || c== '#';
1616 static void nvptx_print_operand (FILE *, rtx, int);
1618 /* Subroutine of nvptx_print_operand; used to print a memory reference X to FILE. */
1620 static void
1621 nvptx_print_address_operand (FILE *file, rtx x, machine_mode)
1623 rtx off;
1624 if (GET_CODE (x) == CONST)
1625 x = XEXP (x, 0);
1626 switch (GET_CODE (x))
1628 case PLUS:
1629 off = XEXP (x, 1);
1630 output_address (XEXP (x, 0));
1631 fprintf (file, "+");
1632 output_address (off);
1633 break;
1635 case SYMBOL_REF:
1636 case LABEL_REF:
1637 output_addr_const (file, x);
1638 break;
1640 default:
1641 gcc_assert (GET_CODE (x) != MEM);
1642 nvptx_print_operand (file, x, 0);
1643 break;
1647 /* Write assembly language output for the address ADDR to FILE. */
1649 static void
1650 nvptx_print_operand_address (FILE *file, rtx addr)
1652 nvptx_print_address_operand (file, addr, VOIDmode);
1655 /* Print an operand, X, to FILE, with an optional modifier in CODE.
1657 Meaning of CODE:
1658 . -- print the predicate for the instruction or an emptry string for an
1659 unconditional one.
1660 # -- print a rounding mode for the instruction
1662 A -- print an address space identifier for a MEM
1663 c -- print an opcode suffix for a comparison operator, including a type code
1664 d -- print a CONST_INT as a vector dimension (x, y, or z)
1665 f -- print a full reg even for something that must always be split
1666 t -- print a type opcode suffix, promoting QImode to 32 bits
1667 T -- print a type size in bits
1668 u -- print a type opcode suffix without promotions. */
1670 static void
1671 nvptx_print_operand (FILE *file, rtx x, int code)
1673 rtx orig_x = x;
1674 machine_mode op_mode;
1676 if (code == '.')
1678 x = current_insn_predicate;
1679 if (x)
1681 unsigned int regno = REGNO (XEXP (x, 0));
1682 fputs ("[", file);
1683 if (GET_CODE (x) == EQ)
1684 fputs ("!", file);
1685 fputs (reg_names [regno], file);
1686 fputs ("]", file);
1688 return;
1690 else if (code == '#')
1692 fputs (".rn", file);
1693 return;
1696 enum rtx_code x_code = GET_CODE (x);
1698 switch (code)
1700 case 'A':
1702 addr_space_t as = nvptx_addr_space_from_address (XEXP (x, 0));
1703 fputs (nvptx_section_from_addr_space (as), file);
1705 break;
1707 case 'd':
1708 gcc_assert (x_code == CONST_INT);
1709 if (INTVAL (x) == 0)
1710 fputs (".x", file);
1711 else if (INTVAL (x) == 1)
1712 fputs (".y", file);
1713 else if (INTVAL (x) == 2)
1714 fputs (".z", file);
1715 else
1716 gcc_unreachable ();
1717 break;
1719 case 't':
1720 op_mode = nvptx_underlying_object_mode (x);
1721 fprintf (file, "%s", nvptx_ptx_type_from_mode (op_mode, true));
1722 break;
1724 case 'u':
1725 op_mode = nvptx_underlying_object_mode (x);
1726 fprintf (file, "%s", nvptx_ptx_type_from_mode (op_mode, false));
1727 break;
1729 case 'T':
1730 fprintf (file, "%d", GET_MODE_BITSIZE (GET_MODE (x)));
1731 break;
1733 case 'j':
1734 fprintf (file, "@");
1735 goto common;
1737 case 'J':
1738 fprintf (file, "@!");
1739 goto common;
1741 case 'c':
1742 op_mode = GET_MODE (XEXP (x, 0));
1743 switch (x_code)
1745 case EQ:
1746 fputs (".eq", file);
1747 break;
1748 case NE:
1749 if (FLOAT_MODE_P (op_mode))
1750 fputs (".neu", file);
1751 else
1752 fputs (".ne", file);
1753 break;
1754 case LE:
1755 fputs (".le", file);
1756 break;
1757 case GE:
1758 fputs (".ge", file);
1759 break;
1760 case LT:
1761 fputs (".lt", file);
1762 break;
1763 case GT:
1764 fputs (".gt", file);
1765 break;
1766 case LEU:
1767 fputs (".ls", file);
1768 break;
1769 case GEU:
1770 fputs (".hs", file);
1771 break;
1772 case LTU:
1773 fputs (".lo", file);
1774 break;
1775 case GTU:
1776 fputs (".hi", file);
1777 break;
1778 case LTGT:
1779 fputs (".ne", file);
1780 break;
1781 case UNEQ:
1782 fputs (".equ", file);
1783 break;
1784 case UNLE:
1785 fputs (".leu", file);
1786 break;
1787 case UNGE:
1788 fputs (".geu", file);
1789 break;
1790 case UNLT:
1791 fputs (".ltu", file);
1792 break;
1793 case UNGT:
1794 fputs (".gtu", file);
1795 break;
1796 case UNORDERED:
1797 fputs (".nan", file);
1798 break;
1799 case ORDERED:
1800 fputs (".num", file);
1801 break;
1802 default:
1803 gcc_unreachable ();
1805 if (FLOAT_MODE_P (op_mode)
1806 || x_code == EQ || x_code == NE
1807 || x_code == GEU || x_code == GTU
1808 || x_code == LEU || x_code == LTU)
1809 fputs (nvptx_ptx_type_from_mode (op_mode, true), file);
1810 else
1811 fprintf (file, ".s%d", GET_MODE_BITSIZE (op_mode));
1812 break;
1813 default:
1814 common:
1815 switch (x_code)
1817 case SUBREG:
1818 x = SUBREG_REG (x);
1819 /* fall through */
1821 case REG:
1822 if (HARD_REGISTER_P (x))
1823 fprintf (file, "%s", reg_names[REGNO (x)]);
1824 else
1825 fprintf (file, "%%r%d", REGNO (x));
1826 if (code != 'f' && nvptx_split_reg_p (GET_MODE (x)))
1828 gcc_assert (GET_CODE (orig_x) == SUBREG
1829 && !nvptx_split_reg_p (GET_MODE (orig_x)));
1830 fprintf (file, "$%d", SUBREG_BYTE (orig_x) / UNITS_PER_WORD);
1832 break;
1834 case MEM:
1835 fputc ('[', file);
1836 nvptx_print_address_operand (file, XEXP (x, 0), GET_MODE (x));
1837 fputc (']', file);
1838 break;
1840 case CONST_INT:
1841 output_addr_const (file, x);
1842 break;
1844 case CONST:
1845 case SYMBOL_REF:
1846 case LABEL_REF:
1847 /* We could use output_addr_const, but that can print things like
1848 "x-8", which breaks ptxas. Need to ensure it is output as
1849 "x+-8". */
1850 nvptx_print_address_operand (file, x, VOIDmode);
1851 break;
1853 case CONST_DOUBLE:
1854 long vals[2];
1855 real_to_target (vals, CONST_DOUBLE_REAL_VALUE (x), GET_MODE (x));
1856 vals[0] &= 0xffffffff;
1857 vals[1] &= 0xffffffff;
1858 if (GET_MODE (x) == SFmode)
1859 fprintf (file, "0f%08lx", vals[0]);
1860 else
1861 fprintf (file, "0d%08lx%08lx", vals[1], vals[0]);
1862 break;
1864 default:
1865 output_addr_const (file, x);
1870 /* Record replacement regs used to deal with subreg operands. */
1871 struct reg_replace
1873 rtx replacement[MAX_RECOG_OPERANDS];
1874 machine_mode mode;
1875 int n_allocated;
1876 int n_in_use;
1879 /* Allocate or reuse a replacement in R and return the rtx. */
1881 static rtx
1882 get_replacement (struct reg_replace *r)
1884 if (r->n_allocated == r->n_in_use)
1885 r->replacement[r->n_allocated++] = gen_reg_rtx (r->mode);
1886 return r->replacement[r->n_in_use++];
1889 /* Clean up subreg operands. In ptx assembly, everything is typed, and
1890 the presence of subregs would break the rules for most instructions.
1891 Replace them with a suitable new register of the right size, plus
1892 conversion copyin/copyout instructions. */
1894 static void
1895 nvptx_reorg_subreg (void)
1897 struct reg_replace qiregs, hiregs, siregs, diregs;
1898 rtx_insn *insn, *next;
1900 qiregs.n_allocated = 0;
1901 hiregs.n_allocated = 0;
1902 siregs.n_allocated = 0;
1903 diregs.n_allocated = 0;
1904 qiregs.mode = QImode;
1905 hiregs.mode = HImode;
1906 siregs.mode = SImode;
1907 diregs.mode = DImode;
1909 for (insn = get_insns (); insn; insn = next)
1911 next = NEXT_INSN (insn);
1912 if (!NONDEBUG_INSN_P (insn)
1913 || asm_noperands (PATTERN (insn)) >= 0
1914 || GET_CODE (PATTERN (insn)) == USE
1915 || GET_CODE (PATTERN (insn)) == CLOBBER)
1916 continue;
1918 qiregs.n_in_use = 0;
1919 hiregs.n_in_use = 0;
1920 siregs.n_in_use = 0;
1921 diregs.n_in_use = 0;
1922 extract_insn (insn);
1923 enum attr_subregs_ok s_ok = get_attr_subregs_ok (insn);
1925 for (int i = 0; i < recog_data.n_operands; i++)
1927 rtx op = recog_data.operand[i];
1928 if (GET_CODE (op) != SUBREG)
1929 continue;
1931 rtx inner = SUBREG_REG (op);
1933 machine_mode outer_mode = GET_MODE (op);
1934 machine_mode inner_mode = GET_MODE (inner);
1935 gcc_assert (s_ok);
1936 if (s_ok
1937 && (GET_MODE_PRECISION (inner_mode)
1938 >= GET_MODE_PRECISION (outer_mode)))
1939 continue;
1940 gcc_assert (SCALAR_INT_MODE_P (outer_mode));
1941 struct reg_replace *r = (outer_mode == QImode ? &qiregs
1942 : outer_mode == HImode ? &hiregs
1943 : outer_mode == SImode ? &siregs
1944 : &diregs);
1945 rtx new_reg = get_replacement (r);
1947 if (recog_data.operand_type[i] != OP_OUT)
1949 enum rtx_code code;
1950 if (GET_MODE_PRECISION (inner_mode)
1951 < GET_MODE_PRECISION (outer_mode))
1952 code = ZERO_EXTEND;
1953 else
1954 code = TRUNCATE;
1956 rtx pat = gen_rtx_SET (new_reg,
1957 gen_rtx_fmt_e (code, outer_mode, inner));
1958 emit_insn_before (pat, insn);
1961 if (recog_data.operand_type[i] != OP_IN)
1963 enum rtx_code code;
1964 if (GET_MODE_PRECISION (inner_mode)
1965 < GET_MODE_PRECISION (outer_mode))
1966 code = TRUNCATE;
1967 else
1968 code = ZERO_EXTEND;
1970 rtx pat = gen_rtx_SET (inner,
1971 gen_rtx_fmt_e (code, inner_mode, new_reg));
1972 emit_insn_after (pat, insn);
1974 validate_change (insn, recog_data.operand_loc[i], new_reg, false);
1979 /* PTX-specific reorganization
1980 - Compute live registers
1981 - Mark now-unused registers, so function begin doesn't declare
1982 unused registers.
1983 - Replace subregs with suitable sequences.
1986 static void
1987 nvptx_reorg (void)
1989 /* We are freeing block_for_insn in the toplev to keep compatibility
1990 with old MDEP_REORGS that are not CFG based. Recompute it now. */
1991 compute_bb_for_insn ();
1993 thread_prologue_and_epilogue_insns ();
1995 /* Compute live regs */
1996 df_clear_flags (DF_LR_RUN_DCE);
1997 df_set_flags (DF_NO_INSN_RESCAN | DF_NO_HARD_REGS);
1998 df_analyze ();
1999 regstat_init_n_sets_and_refs ();
2001 int max_regs = max_reg_num ();
2003 /* Mark unused regs as unused. */
2004 for (int i = LAST_VIRTUAL_REGISTER + 1; i < max_regs; i++)
2005 if (REG_N_SETS (i) == 0 && REG_N_REFS (i) == 0)
2006 regno_reg_rtx[i] = const0_rtx;
2008 /* Replace subregs. */
2009 nvptx_reorg_subreg ();
2011 regstat_free_n_sets_and_refs ();
2013 df_finish_pass (true);
2016 /* Handle a "kernel" attribute; arguments as in
2017 struct attribute_spec.handler. */
2019 static tree
2020 nvptx_handle_kernel_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2021 int ARG_UNUSED (flags), bool *no_add_attrs)
2023 tree decl = *node;
2025 if (TREE_CODE (decl) != FUNCTION_DECL)
2027 error ("%qE attribute only applies to functions", name);
2028 *no_add_attrs = true;
2031 else if (TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
2033 error ("%qE attribute requires a void return type", name);
2034 *no_add_attrs = true;
2037 return NULL_TREE;
2040 /* Table of valid machine attributes. */
2041 static const struct attribute_spec nvptx_attribute_table[] =
2043 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
2044 affects_type_identity } */
2045 { "kernel", 0, 0, true, false, false, nvptx_handle_kernel_attribute, false },
2046 { NULL, 0, 0, false, false, false, NULL, false }
2049 /* Limit vector alignments to BIGGEST_ALIGNMENT. */
2051 static HOST_WIDE_INT
2052 nvptx_vector_alignment (const_tree type)
2054 HOST_WIDE_INT align = tree_to_shwi (TYPE_SIZE (type));
2056 return MIN (align, BIGGEST_ALIGNMENT);
2059 /* Record a symbol for mkoffload to enter into the mapping table. */
2061 static void
2062 nvptx_record_offload_symbol (tree decl)
2064 switch (TREE_CODE (decl))
2066 case VAR_DECL:
2067 fprintf (asm_out_file, "//:VAR_MAP \"%s\"\n",
2068 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
2069 break;
2071 case FUNCTION_DECL:
2073 tree attr = get_oacc_fn_attrib (decl);
2074 tree dims = NULL_TREE;
2075 unsigned ix;
2077 if (attr)
2078 dims = TREE_VALUE (attr);
2079 fprintf (asm_out_file, "//:FUNC_MAP \"%s\"",
2080 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
2082 for (ix = 0; ix != GOMP_DIM_MAX; ix++)
2084 int size = 1;
2086 /* TODO: This check can go away once the dimension default
2087 machinery is merged to trunk. */
2088 if (dims)
2090 tree dim = TREE_VALUE (dims);
2092 if (dim)
2093 size = TREE_INT_CST_LOW (dim);
2095 gcc_assert (!TREE_PURPOSE (dims));
2096 dims = TREE_CHAIN (dims);
2099 fprintf (asm_out_file, ", %#x", size);
2102 fprintf (asm_out_file, "\n");
2104 break;
2106 default:
2107 gcc_unreachable ();
2111 /* Implement TARGET_ASM_FILE_START. Write the kinds of things ptxas expects
2112 at the start of a file. */
2114 static void
2115 nvptx_file_start (void)
2117 fputs ("// BEGIN PREAMBLE\n", asm_out_file);
2118 fputs ("\t.version\t3.1\n", asm_out_file);
2119 fputs ("\t.target\tsm_30\n", asm_out_file);
2120 fprintf (asm_out_file, "\t.address_size %d\n", GET_MODE_BITSIZE (Pmode));
2121 fputs ("// END PREAMBLE\n", asm_out_file);
2124 /* Write out the function declarations we've collected and declare storage
2125 for the broadcast buffer. */
2127 static void
2128 nvptx_file_end (void)
2130 hash_table<tree_hasher>::iterator iter;
2131 tree decl;
2132 FOR_EACH_HASH_TABLE_ELEMENT (*needed_fndecls_htab, decl, tree, iter)
2133 nvptx_record_fndecl (decl, true);
2134 fputs (func_decls.str().c_str(), asm_out_file);
2137 /* Validate compute dimensions of an OpenACC offload or routine, fill
2138 in non-unity defaults. FN_LEVEL indicates the level at which a
2139 routine might spawn a loop. It is negative for non-routines. */
2141 static bool
2142 nvptx_goacc_validate_dims (tree ARG_UNUSED (decl), int *ARG_UNUSED (dims),
2143 int ARG_UNUSED (fn_level))
2145 bool changed = false;
2147 /* TODO: Leave dimensions unaltered. Partitioned execution needs
2148 porting before filtering dimensions makes sense. */
2150 return changed;
2153 #undef TARGET_OPTION_OVERRIDE
2154 #define TARGET_OPTION_OVERRIDE nvptx_option_override
2156 #undef TARGET_ATTRIBUTE_TABLE
2157 #define TARGET_ATTRIBUTE_TABLE nvptx_attribute_table
2159 #undef TARGET_LEGITIMATE_ADDRESS_P
2160 #define TARGET_LEGITIMATE_ADDRESS_P nvptx_legitimate_address_p
2162 #undef TARGET_PROMOTE_FUNCTION_MODE
2163 #define TARGET_PROMOTE_FUNCTION_MODE nvptx_promote_function_mode
2165 #undef TARGET_FUNCTION_ARG
2166 #define TARGET_FUNCTION_ARG nvptx_function_arg
2167 #undef TARGET_FUNCTION_INCOMING_ARG
2168 #define TARGET_FUNCTION_INCOMING_ARG nvptx_function_incoming_arg
2169 #undef TARGET_FUNCTION_ARG_ADVANCE
2170 #define TARGET_FUNCTION_ARG_ADVANCE nvptx_function_arg_advance
2171 #undef TARGET_FUNCTION_ARG_BOUNDARY
2172 #define TARGET_FUNCTION_ARG_BOUNDARY nvptx_function_arg_boundary
2173 #undef TARGET_FUNCTION_ARG_ROUND_BOUNDARY
2174 #define TARGET_FUNCTION_ARG_ROUND_BOUNDARY nvptx_function_arg_boundary
2175 #undef TARGET_PASS_BY_REFERENCE
2176 #define TARGET_PASS_BY_REFERENCE nvptx_pass_by_reference
2177 #undef TARGET_FUNCTION_VALUE_REGNO_P
2178 #define TARGET_FUNCTION_VALUE_REGNO_P nvptx_function_value_regno_p
2179 #undef TARGET_FUNCTION_VALUE
2180 #define TARGET_FUNCTION_VALUE nvptx_function_value
2181 #undef TARGET_LIBCALL_VALUE
2182 #define TARGET_LIBCALL_VALUE nvptx_libcall_value
2183 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
2184 #define TARGET_FUNCTION_OK_FOR_SIBCALL nvptx_function_ok_for_sibcall
2185 #undef TARGET_GET_DRAP_RTX
2186 #define TARGET_GET_DRAP_RTX nvptx_get_drap_rtx
2187 #undef TARGET_SPLIT_COMPLEX_ARG
2188 #define TARGET_SPLIT_COMPLEX_ARG hook_bool_const_tree_true
2189 #undef TARGET_RETURN_IN_MEMORY
2190 #define TARGET_RETURN_IN_MEMORY nvptx_return_in_memory
2191 #undef TARGET_OMIT_STRUCT_RETURN_REG
2192 #define TARGET_OMIT_STRUCT_RETURN_REG true
2193 #undef TARGET_STRICT_ARGUMENT_NAMING
2194 #define TARGET_STRICT_ARGUMENT_NAMING nvptx_strict_argument_naming
2195 #undef TARGET_STATIC_CHAIN
2196 #define TARGET_STATIC_CHAIN nvptx_static_chain
2198 #undef TARGET_CALL_ARGS
2199 #define TARGET_CALL_ARGS nvptx_call_args
2200 #undef TARGET_END_CALL_ARGS
2201 #define TARGET_END_CALL_ARGS nvptx_end_call_args
2203 #undef TARGET_ASM_FILE_START
2204 #define TARGET_ASM_FILE_START nvptx_file_start
2205 #undef TARGET_ASM_FILE_END
2206 #define TARGET_ASM_FILE_END nvptx_file_end
2207 #undef TARGET_ASM_GLOBALIZE_LABEL
2208 #define TARGET_ASM_GLOBALIZE_LABEL nvptx_globalize_label
2209 #undef TARGET_ASM_ASSEMBLE_UNDEFINED_DECL
2210 #define TARGET_ASM_ASSEMBLE_UNDEFINED_DECL nvptx_assemble_undefined_decl
2211 #undef TARGET_PRINT_OPERAND
2212 #define TARGET_PRINT_OPERAND nvptx_print_operand
2213 #undef TARGET_PRINT_OPERAND_ADDRESS
2214 #define TARGET_PRINT_OPERAND_ADDRESS nvptx_print_operand_address
2215 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
2216 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P nvptx_print_operand_punct_valid_p
2217 #undef TARGET_ASM_INTEGER
2218 #define TARGET_ASM_INTEGER nvptx_assemble_integer
2219 #undef TARGET_ASM_DECL_END
2220 #define TARGET_ASM_DECL_END nvptx_assemble_decl_end
2221 #undef TARGET_ASM_DECLARE_CONSTANT_NAME
2222 #define TARGET_ASM_DECLARE_CONSTANT_NAME nvptx_asm_declare_constant_name
2223 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
2224 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
2225 #undef TARGET_ASM_NEED_VAR_DECL_BEFORE_USE
2226 #define TARGET_ASM_NEED_VAR_DECL_BEFORE_USE true
2228 #undef TARGET_MACHINE_DEPENDENT_REORG
2229 #define TARGET_MACHINE_DEPENDENT_REORG nvptx_reorg
2230 #undef TARGET_NO_REGISTER_ALLOCATION
2231 #define TARGET_NO_REGISTER_ALLOCATION true
2233 #undef TARGET_RECORD_OFFLOAD_SYMBOL
2234 #define TARGET_RECORD_OFFLOAD_SYMBOL nvptx_record_offload_symbol
2236 #undef TARGET_VECTOR_ALIGNMENT
2237 #define TARGET_VECTOR_ALIGNMENT nvptx_vector_alignment
2239 #undef TARGET_GOACC_VALIDATE_DIMS
2240 #define TARGET_GOACC_VALIDATE_DIMS nvptx_goacc_validate_dims
2242 struct gcc_target targetm = TARGET_INITIALIZER;
2244 #include "gt-nvptx.h"