]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/nvptx/nvptx.h
Update copyright years.
[thirdparty/gcc.git] / gcc / config / nvptx / nvptx.h
CommitLineData
738f2522 1/* Target Definitions for NVPTX.
a945c346 2 Copyright (C) 2014-2024 Free Software Foundation, Inc.
738f2522
BS
3 Contributed by Bernd Schmidt <bernds@codesourcery.com>
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21#ifndef GCC_NVPTX_H
22#define GCC_NVPTX_H
23
53ceb8b5
CP
24#ifndef NVPTX_OPTS_H
25#include "config/nvptx/nvptx-opts.h"
26#endif
27
738f2522
BS
28/* Run-time Target. */
29
108b99b6
TS
30/* Use '--with-arch' for default '-misa'. */
31#define OPTION_DEFAULT_SPECS \
32 { "arch", "%{!misa=*:-misa=%(VALUE)}" }, \
33
84072a26
TS
34/* Assembler supports '-v' option; handle similar to
35 '../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */
36#define ASM_SPEC "%{v}"
37
dda43e1e 38#define STARTFILE_SPEC "%{mmainkernel:crt0.o%s}"
738f2522 39
3c496e92 40#define TARGET_CPU_CPP_BUILTINS() nvptx_cpu_cpp_builtins ()
738f2522 41
e53b6e56 42/* Avoid the default in ../../gcc.cc, which adds "-pthread", which is not
8747dd6e
TS
43 supported for nvptx. */
44#define GOMP_SELF_SPECS ""
45
738f2522
BS
46/* Storage Layout. */
47
48#define BITS_BIG_ENDIAN 0
49#define BYTES_BIG_ENDIAN 0
50#define WORDS_BIG_ENDIAN 0
51
52/* Chosen such that we won't have to deal with multi-word subregs. */
53#define UNITS_PER_WORD 8
54
44eba92d
NS
55/* Alignments in bits. */
56#define PARM_BOUNDARY 32
3717fbe3 57#define STACK_BOUNDARY 128
738f2522 58#define FUNCTION_BOUNDARY 32
3717fbe3 59#define BIGGEST_ALIGNMENT 128
738f2522
BS
60#define STRICT_ALIGNMENT 1
61
18c05628
NS
62#define MAX_STACK_ALIGNMENT (1024 * 8)
63
3717fbe3
TV
64#define DATA_ALIGNMENT nvptx_data_alignment
65
738f2522
BS
66/* Copied from elf.h and other places. We'd otherwise use
67 BIGGEST_ALIGNMENT and fail a number of testcases. */
68#define MAX_OFILE_ALIGNMENT (32768 * 8)
69
70/* Type Layout. */
71
72#define DEFAULT_SIGNED_CHAR 1
73
74#define SHORT_TYPE_SIZE 16
75#define INT_TYPE_SIZE 32
76#define LONG_TYPE_SIZE (TARGET_ABI64 ? 64 : 32)
77#define LONG_LONG_TYPE_SIZE 64
78#define FLOAT_TYPE_SIZE 32
79#define DOUBLE_TYPE_SIZE 64
80#define LONG_DOUBLE_TYPE_SIZE 64
a9000e1e 81#define TARGET_SUPPORTS_WIDE_INT 1
738f2522
BS
82
83#undef SIZE_TYPE
84#define SIZE_TYPE (TARGET_ABI64 ? "long unsigned int" : "unsigned int")
85#undef PTRDIFF_TYPE
86#define PTRDIFF_TYPE (TARGET_ABI64 ? "long int" : "int")
87
88#define POINTER_SIZE (TARGET_ABI64 ? 64 : 32)
738f2522 89#define Pmode (TARGET_ABI64 ? DImode : SImode)
5012919d 90#define STACK_SIZE_MODE Pmode
738f2522 91
d59d13c8 92#include "nvptx-gen.h"
53ceb8b5 93
57f971f9 94#define TARGET_PTX_6_0 (ptx_version_option >= PTX_VERSION_6_0)
2a158640 95#define TARGET_PTX_6_3 (ptx_version_option >= PTX_VERSION_6_3)
eede2498 96#define TARGET_PTX_7_0 (ptx_version_option >= PTX_VERSION_7_0)
2a158640 97
738f2522 98/* Registers. Since ptx is a virtual target, we just define a few
a2e2a4e4
NS
99 hard registers for special purposes and leave pseudos unallocated.
100 We have to have some available hard registers, to keep gcc setup
bd5d4b65 101 happy. */
a2e2a4e4 102#define FIRST_PSEUDO_REGISTER 16
5012919d 103#define FIXED_REGISTERS { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
a2e2a4e4 104#define CALL_USED_REGISTERS { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
738f2522 105
738f2522 106/* Register Classes. */
a2e2a4e4
NS
107enum reg_class { NO_REGS, ALL_REGS, LIM_REG_CLASSES };
108#define REG_CLASS_NAMES { "NO_REGS", "ALL_REGS" }
109#define REG_CLASS_CONTENTS { { 0x0000 }, { 0xFFFF } }
738f2522
BS
110#define N_REG_CLASSES (int) LIM_REG_CLASSES
111
738f2522 112#define GENERAL_REGS ALL_REGS
bd5d4b65 113#define REGNO_REG_CLASS(R) ((void)(R), ALL_REGS)
738f2522
BS
114#define BASE_REG_CLASS ALL_REGS
115#define INDEX_REG_CLASS NO_REGS
116
117#define REGNO_OK_FOR_BASE_P(X) true
118#define REGNO_OK_FOR_INDEX_P(X) false
119
120#define CLASS_MAX_NREGS(class, mode) \
121 ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
122
738f2522 123#define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
bd5d4b65 124 if ((MODE) == QImode || (MODE) == HImode) \
738f2522
BS
125 { \
126 (MODE) = SImode; \
bd5d4b65
NS
127 (void)(UNSIGNEDP); \
128 (void)(TYPE); \
738f2522
BS
129 }
130
738f2522
BS
131/* Stack and Calling. */
132
738f2522 133#define FRAME_GROWS_DOWNWARD 0
62f9f30b 134#define STACK_GROWS_DOWNWARD 1
738f2522 135
a2e2a4e4 136#define NVPTX_RETURN_REGNUM 0
738f2522 137#define STACK_POINTER_REGNUM 1
a2e2a4e4
NS
138#define FRAME_POINTER_REGNUM 2
139#define ARG_POINTER_REGNUM 3
140#define STATIC_CHAIN_REGNUM 4
5012919d
AM
141/* This register points to the shared memory location with the current warp's
142 soft stack pointer (__nvptx_stacks[tid.y]). */
143#define SOFTSTACK_SLOT_REGNUM 5
144/* This register is used to save the previous value of the soft stack pointer
145 in the prologue and restore it when returning. */
146#define SOFTSTACK_PREV_REGNUM 6
738f2522 147
bd5d4b65
NS
148#define REGISTER_NAMES \
149 { \
5012919d
AM
150 "%value", "%stack", "%frame", "%args", \
151 "%chain", "%sspslot", "%sspprev", "%hr7", \
a2e2a4e4 152 "%hr8", "%hr9", "%hr10", "%hr11", "%hr12", "%hr13", "%hr14", "%hr15" \
bd5d4b65
NS
153 }
154
01be5855 155#define FIRST_PARM_OFFSET(FNDECL) ((void)(FNDECL), 0)
738f2522 156#define PUSH_ARGS_REVERSED 1
738f2522
BS
157#define ACCUMULATE_OUTGOING_ARGS 1
158
01be5855
NS
159/* Avoid using the argument pointer for frame-related things. */
160#define FRAME_POINTER_CFA_OFFSET(FNDECL) ((void)(FNDECL), 0)
161
738f2522
BS
162#ifdef HOST_WIDE_INT
163struct nvptx_args {
01be5855 164 tree fntype;
738f2522
BS
165 /* Number of arguments passed in registers so far. */
166 int count;
738f2522
BS
167};
168#endif
169
170#define CUMULATIVE_ARGS struct nvptx_args
171
172#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
bd5d4b65 173 ((CUM).fntype = (FNTYPE), (CUM).count = 0, (void)0)
738f2522
BS
174
175#define FUNCTION_ARG_REGNO_P(r) 0
176
177#define DEFAULT_PCC_STRUCT_RETURN 0
178
179#define FUNCTION_PROFILER(file, labelno) \
40fecdd6
JM
180 fatal_error (input_location, \
181 "profiling is not yet implemented for this architecture")
738f2522
BS
182
183#define TRAMPOLINE_SIZE 32
184#define TRAMPOLINE_ALIGNMENT 256
185\f
186/* We don't run reload, so this isn't actually used, but it still needs to be
187 defined. Showing an argp->fp elimination also stops
188 expand_builtin_setjmp_receiver from generating invalid insns. */
189#define ELIMINABLE_REGS \
190 { \
bd5d4b65 191 { ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM} \
738f2522
BS
192 }
193
194/* Define the offset between two registers, one to be eliminated, and the other
195 its replacement, at the start of a routine. */
196
197#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
198 ((OFFSET) = 0)
199\f
200/* Addressing Modes. */
201
202#define MAX_REGS_PER_ADDRESS 1
203
204#define LEGITIMATE_PIC_OPERAND_P(X) 1
205\f
206
738f2522
BS
207#if defined HOST_WIDE_INT
208struct GTY(()) machine_function
209{
44c068ae
NS
210 rtx_expr_list *call_args; /* Arg list for the current call. */
211 bool doing_call; /* Within a CALL_ARGS ... CALL_ARGS_END sequence. */
721cdcd1
MP
212 bool is_variadic; /* This call is variadic */
213 bool has_variadic; /* Current function has a variadic call. */
44c068ae 214 bool has_chain; /* Current function has outgoing static chain. */
5012919d 215 bool has_softstack; /* Current function has a soft stack frame. */
0c6b03b5 216 bool has_simtreg; /* Current function has an OpenMP SIMD region. */
44c068ae
NS
217 int num_args; /* Number of args of current call. */
218 int return_mode; /* Return mode of current fn.
219 (machine_mode not defined yet.) */
220 rtx axis_predicate[2]; /* Neutering predicates. */
0d06e8c7
TV
221 int axis_dim[2]; /* Maximum number of threads on each axis, dim[0] is
222 vector_length, dim[1] is num_workers. */
223 bool axis_dim_init_p;
0024c320
TV
224 rtx bcast_partition; /* Register containing the size of each
225 vector's partition of share-memory used to
226 broadcast state. */
f881693c
TV
227 rtx red_partition; /* Similar to bcast_partition, except for vector
228 reductions. */
0024c320 229 rtx sync_bar; /* Synchronization barrier ID for vectors. */
5012919d
AM
230 rtx unisimt_master; /* 'Master lane index' for -muniform-simt. */
231 rtx unisimt_predicate; /* Predicate for -muniform-simt. */
f07178ca 232 rtx unisimt_outside_simt_predicate; /* Predicate for -muniform-simt. */
0c6b03b5
AM
233 rtx unisimt_location; /* Mask location for -muniform-simt. */
234 /* The following two fields hold the maximum size resp. alignment required
235 for per-lane storage in OpenMP SIMD regions. */
236 unsigned HOST_WIDE_INT simt_stack_size;
237 unsigned HOST_WIDE_INT simt_stack_align;
738f2522
BS
238};
239#endif
240\f
241/* Costs. */
242
243#define NO_FUNCTION_CSE 1
244#define SLOW_BYTE_ACCESS 0
245#define BRANCH_COST(speed_p, predictable_p) 6
246\f
247/* Assembler Format. */
248
249#undef ASM_DECLARE_FUNCTION_NAME
250#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
251 nvptx_declare_function_name (FILE, NAME, DECL)
252
253#undef ASM_DECLARE_FUNCTION_SIZE
254#define ASM_DECLARE_FUNCTION_SIZE(STREAM, NAME, DECL) \
255 nvptx_function_end (STREAM)
256
257#define DWARF2_ASM_LINE_DEBUG_INFO 1
258
259#undef ASM_APP_ON
260#define ASM_APP_ON "\t// #APP \n"
261#undef ASM_APP_OFF
262#define ASM_APP_OFF "\t// #NO_APP \n"
263
ca60bd93 264#define DEBUGGER_REGNO(N) N
738f2522
BS
265
266#define TEXT_SECTION_ASM_OP ""
267#define DATA_SECTION_ASM_OP ""
268
269#undef ASM_GENERATE_INTERNAL_LABEL
270#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
271 do \
272 { \
273 char *__p; \
274 __p = stpcpy (&(LABEL)[1], PREFIX); \
275 (LABEL)[0] = '$'; \
276 sprint_ul (__p, (unsigned long) (NUM)); \
277 } \
278 while (0)
279
e0dd6391
TS
280#define ASM_OUTPUT_ALIGN(FILE, POWER) \
281 do \
282 { \
283 (void) (FILE); \
284 (void) (POWER); \
285 } \
286 while (0)
287
738f2522
BS
288#define ASM_OUTPUT_SKIP(FILE, N) \
289 nvptx_output_skip (FILE, N)
e0dd6391 290
738f2522
BS
291#undef ASM_OUTPUT_ASCII
292#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \
293 nvptx_output_ascii (FILE, STR, LENGTH);
294
295#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
296 nvptx_declare_object_name (FILE, NAME, DECL)
297
298#undef ASM_OUTPUT_ALIGNED_DECL_COMMON
299#define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \
69823d76 300 nvptx_output_aligned_decl (FILE, NAME, DECL, SIZE, ALIGN)
738f2522
BS
301
302#undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
303#define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
69823d76 304 nvptx_output_aligned_decl (FILE, NAME, DECL, SIZE, ALIGN)
738f2522
BS
305
306#define CASE_VECTOR_PC_RELATIVE flag_pic
307#define JUMP_TABLES_IN_TEXT_SECTION flag_pic
308
309#define ADDR_VEC_ALIGN(VEC) (JUMP_TABLES_IN_TEXT_SECTION ? 5 : 2)
310
311/* Misc. */
312
c9665100 313#define DWARF2_LINENO_DEBUGGING_INFO 1
738f2522
BS
314
315#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
316 ((VALUE) = GET_MODE_BITSIZE ((MODE)), 2)
317#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
318 ((VALUE) = GET_MODE_BITSIZE ((MODE)), 2)
319
0766660b 320#define SUPPORTS_WEAK 1
f8b15e17 321
9837f62f
TS
322#define MAKE_DECL_ONE_ONLY(DECL) \
323 (DECL_WEAK (DECL) = 1)
324
f8b15e17
TV
325/* The documentation states that ASM_OUTPUT_DEF_FROM_DECLS is used in
326 preference to ASM_OUTPUT_DEF if the tree nodes are available. However, we
327 need the tree nodes to emit the prototype, so at this point it's not clear
328 how we can support ASM_OUTPUT_DEF. Still, we need to define it, or
329 ASM_OUTPUT_DEF_FROM_DECLS is ignored. For now, assert, and once we run
330 into it possibly improve by somehow emitting the prototype elsewhere, or
331 emitting a reasonable error message. */
332#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
333 do \
334 { \
08de0652
JBG
335 (void) (FILE); \
336 (void) (LABEL1); \
337 (void) (LABEL2); \
f8b15e17
TV
338 gcc_unreachable (); \
339 } \
340 while (0)
341#define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, NAME, VALUE) \
342 nvptx_asm_output_def_from_decls (STREAM, NAME, VALUE)
343
537e2cc3
TS
344/* ..., but also override other macros to avoid 'gcc/defaults.h'-initialization
345 due to that dummy 'ASM_OUTPUT_DEF'. */
346#define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) TARGET_SUPPORTS_ALIASES
347#define TARGET_SUPPORTS_ALIASES (nvptx_alias != 0)
348
738f2522
BS
349#define NO_DOT_IN_LABEL
350#define ASM_COMMENT_START "//"
351
beed3f8f 352#define STORE_FLAG_VALUE 1
738f2522
BS
353#define FLOAT_STORE_FLAG_VALUE(MODE) REAL_VALUE_ATOF("1.0", (MODE))
354
355#define CASE_VECTOR_MODE SImode
9251aec6 356#define MOVE_MAX 8
738f2522 357#define MOVE_RATIO(SPEED) 4
738f2522
BS
358#define FUNCTION_MODE QImode
359#define HAS_INIT_SECTION 1
360
d94fae04
TS
361/* The C++ front end insists to link against libstdc++ -- which we don't build.
362 Tell it to instead link against the innocuous libgcc. */
363#define LIBSTDCXX "gcc"
364
738f2522 365#endif /* GCC_NVPTX_H */