| 1 |
/* Target Definitions for NVPTX. |
| 2 |
Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Bernd Schmidt <[email protected]> |
| 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 |
|
| 24 |
#ifndef NVPTX_OPTS_H |
| 25 |
#include "config/nvptx/nvptx-opts.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
/* Run-time Target. */ |
| 29 |
|
| 30 |
/* Use '--with-arch' for default '-misa'. */ |
| 31 |
#define OPTION_DEFAULT_SPECS \ |
| 32 |
{ "arch", "%{!misa=*:-misa=%(VALUE)}" }, \ |
| 33 |
|
| 34 |
/* Assembler supports '-v' option; handle similar to |
| 35 |
'../../gcc.cc:asm_options', 'HAVE_GNU_AS'. */ |
| 36 |
#define ASM_SPEC "%{v}" |
| 37 |
|
| 38 |
#define STARTFILE_SPEC "%{mmainkernel:crt0.o%s}" |
| 39 |
|
| 40 |
#define TARGET_CPU_CPP_BUILTINS() nvptx_cpu_cpp_builtins () |
| 41 |
|
| 42 |
/* Avoid the default in ../../gcc.cc, which adds "-pthread", which is not |
| 43 |
supported for nvptx. */ |
| 44 |
#define GOMP_SELF_SPECS "" |
| 45 |
|
| 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 |
|
| 55 |
/* Alignments in bits. */ |
| 56 |
#define PARM_BOUNDARY 32 |
| 57 |
#define STACK_BOUNDARY 128 |
| 58 |
#define FUNCTION_BOUNDARY 32 |
| 59 |
#define BIGGEST_ALIGNMENT 128 |
| 60 |
#define STRICT_ALIGNMENT 1 |
| 61 |
|
| 62 |
#define MAX_STACK_ALIGNMENT (1024 * 8) |
| 63 |
|
| 64 |
#define DATA_ALIGNMENT nvptx_data_alignment |
| 65 |
|
| 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 TARGET_SUPPORTS_WIDE_INT 1 |
| 79 |
|
| 80 |
#define MAX_FIXED_MODE_SIZE 128 |
| 81 |
|
| 82 |
#undef SIZE_TYPE |
| 83 |
#define SIZE_TYPE (TARGET_ABI64 ? "long unsigned int" : "unsigned int") |
| 84 |
#undef PTRDIFF_TYPE |
| 85 |
#define PTRDIFF_TYPE (TARGET_ABI64 ? "long int" : "int") |
| 86 |
|
| 87 |
#define POINTER_SIZE (TARGET_ABI64 ? 64 : 32) |
| 88 |
#define Pmode (TARGET_ABI64 ? DImode : SImode) |
| 89 |
#define STACK_SIZE_MODE Pmode |
| 90 |
|
| 91 |
/* We always have to maintain the '-msoft-stack' pointer, but the PTX "native" |
| 92 |
stack pointer is handled implicitly at function level. */ |
| 93 |
#define STACK_SAVEAREA_MODE(LEVEL) \ |
| 94 |
(TARGET_SOFT_STACK ? Pmode \ |
| 95 |
: (LEVEL == SAVE_FUNCTION ? VOIDmode \ |
| 96 |
: Pmode)) |
| 97 |
|
| 98 |
#include "nvptx-gen.h" |
| 99 |
|
| 100 |
/* There are no 'TARGET_PTX_3_1' and smaller conditionals: our baseline is |
| 101 |
PTX ISA Version 3.1. */ |
| 102 |
#define TARGET_PTX_4_1 (ptx_version_option >= PTX_VERSION_4_1) |
| 103 |
#define TARGET_PTX_4_2 (ptx_version_option >= PTX_VERSION_4_2) |
| 104 |
#define TARGET_PTX_5_0 (ptx_version_option >= PTX_VERSION_5_0) |
| 105 |
#define TARGET_PTX_6_0 (ptx_version_option >= PTX_VERSION_6_0) |
| 106 |
#define TARGET_PTX_6_3 (ptx_version_option >= PTX_VERSION_6_3) |
| 107 |
#define TARGET_PTX_7_0 (ptx_version_option >= PTX_VERSION_7_0) |
| 108 |
#define TARGET_PTX_7_3 (ptx_version_option >= PTX_VERSION_7_3) |
| 109 |
#define TARGET_PTX_7_8 (ptx_version_option >= PTX_VERSION_7_8) |
| 110 |
|
| 111 |
/* Registers. Since ptx is a virtual target, we just define a few |
| 112 |
hard registers for special purposes and leave pseudos unallocated. |
| 113 |
We have to have some available hard registers, to keep gcc setup |
| 114 |
happy. */ |
| 115 |
#define FIRST_PSEUDO_REGISTER 16 |
| 116 |
#define FIXED_REGISTERS { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
| 117 |
#define CALL_USED_REGISTERS { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } |
| 118 |
|
| 119 |
/* Register Classes. */ |
| 120 |
enum reg_class { NO_REGS, ALL_REGS, LIM_REG_CLASSES }; |
| 121 |
#define REG_CLASS_NAMES { "NO_REGS", "ALL_REGS" } |
| 122 |
#define REG_CLASS_CONTENTS { { 0x0000 }, { 0xFFFF } } |
| 123 |
#define N_REG_CLASSES (int) LIM_REG_CLASSES |
| 124 |
|
| 125 |
#define GENERAL_REGS ALL_REGS |
| 126 |
#define REGNO_REG_CLASS(R) ((void)(R), ALL_REGS) |
| 127 |
#define BASE_REG_CLASS ALL_REGS |
| 128 |
#define INDEX_REG_CLASS NO_REGS |
| 129 |
|
| 130 |
#define REGNO_OK_FOR_BASE_P(X) true |
| 131 |
#define REGNO_OK_FOR_INDEX_P(X) false |
| 132 |
|
| 133 |
#define CLASS_MAX_NREGS(class, mode) \ |
| 134 |
((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD) |
| 135 |
|
| 136 |
#define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \ |
| 137 |
if ((MODE) == QImode || (MODE) == HImode) \ |
| 138 |
{ \ |
| 139 |
(MODE) = SImode; \ |
| 140 |
(void)(UNSIGNEDP); \ |
| 141 |
(void)(TYPE); \ |
| 142 |
} |
| 143 |
|
| 144 |
/* Stack and Calling. */ |
| 145 |
|
| 146 |
#define FRAME_GROWS_DOWNWARD 0 |
| 147 |
#define STACK_GROWS_DOWNWARD 1 |
| 148 |
|
| 149 |
#define NVPTX_RETURN_REGNUM 0 |
| 150 |
#define STACK_POINTER_REGNUM 1 |
| 151 |
#define FRAME_POINTER_REGNUM 2 |
| 152 |
#define ARG_POINTER_REGNUM 3 |
| 153 |
#define STATIC_CHAIN_REGNUM 4 |
| 154 |
/* This register points to the shared memory location with the current warp's |
| 155 |
soft stack pointer (__nvptx_stacks[tid.y]). */ |
| 156 |
#define SOFTSTACK_SLOT_REGNUM 5 |
| 157 |
/* This register is used to save the previous value of the soft stack pointer |
| 158 |
in the prologue and restore it when returning. */ |
| 159 |
#define SOFTSTACK_PREV_REGNUM 6 |
| 160 |
|
| 161 |
#define REGISTER_NAMES \ |
| 162 |
{ \ |
| 163 |
"%value", "%stack", "%frame", "%args", \ |
| 164 |
"%chain", "%sspslot", "%sspprev", "%hr7", \ |
| 165 |
"%hr8", "%hr9", "%hr10", "%hr11", "%hr12", "%hr13", "%hr14", "%hr15" \ |
| 166 |
} |
| 167 |
|
| 168 |
#define FIRST_PARM_OFFSET(FNDECL) ((void)(FNDECL), 0) |
| 169 |
#define PUSH_ARGS_REVERSED 1 |
| 170 |
#define ACCUMULATE_OUTGOING_ARGS 1 |
| 171 |
|
| 172 |
/* Avoid using the argument pointer for frame-related things. */ |
| 173 |
#define FRAME_POINTER_CFA_OFFSET(FNDECL) ((void)(FNDECL), 0) |
| 174 |
|
| 175 |
#ifdef HOST_WIDE_INT |
| 176 |
struct nvptx_args { |
| 177 |
tree fntype; |
| 178 |
/* Number of arguments passed in registers so far. */ |
| 179 |
int count; |
| 180 |
}; |
| 181 |
#endif |
| 182 |
|
| 183 |
#define CUMULATIVE_ARGS struct nvptx_args |
| 184 |
|
| 185 |
#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \ |
| 186 |
((CUM).fntype = (FNTYPE), (CUM).count = 0, (void)0) |
| 187 |
|
| 188 |
#define FUNCTION_ARG_REGNO_P(r) 0 |
| 189 |
|
| 190 |
#define DEFAULT_PCC_STRUCT_RETURN 0 |
| 191 |
|
| 192 |
#define FUNCTION_PROFILER(file, labelno) \ |
| 193 |
fatal_error (input_location, \ |
| 194 |
"profiling is not yet implemented for this architecture") |
| 195 |
|
| 196 |
#define TRAMPOLINE_SIZE 32 |
| 197 |
#define TRAMPOLINE_ALIGNMENT 256 |
| 198 |
|
| 199 |
/* We don't run reload, so this isn't actually used, but it still needs to be |
| 200 |
defined. Showing an argp->fp elimination also stops |
| 201 |
expand_builtin_setjmp_receiver from generating invalid insns. */ |
| 202 |
#define ELIMINABLE_REGS \ |
| 203 |
{ \ |
| 204 |
{ ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM} \ |
| 205 |
} |
| 206 |
|
| 207 |
/* Define the offset between two registers, one to be eliminated, and the other |
| 208 |
its replacement, at the start of a routine. */ |
| 209 |
|
| 210 |
#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \ |
| 211 |
((OFFSET) = 0) |
| 212 |
|
| 213 |
/* Addressing Modes. */ |
| 214 |
|
| 215 |
#define MAX_REGS_PER_ADDRESS 1 |
| 216 |
|
| 217 |
#define LEGITIMATE_PIC_OPERAND_P(X) 1 |
| 218 |
|
| 219 |
|
| 220 |
#if defined HOST_WIDE_INT |
| 221 |
struct GTY(()) machine_function |
| 222 |
{ |
| 223 |
rtx_expr_list *call_args; /* Arg list for the current call. */ |
| 224 |
bool doing_call; /* Within a CALL_ARGS ... CALL_ARGS_END sequence. */ |
| 225 |
bool is_variadic; /* This call is variadic */ |
| 226 |
bool has_variadic; /* Current function has a variadic call. */ |
| 227 |
bool has_chain; /* Current function has outgoing static chain. */ |
| 228 |
bool has_softstack; /* Current function has a soft stack frame. */ |
| 229 |
bool has_simtreg; /* Current function has an OpenMP SIMD region. */ |
| 230 |
int num_args; /* Number of args of current call. */ |
| 231 |
int return_mode; /* Return mode of current fn. |
| 232 |
(machine_mode not defined yet.) */ |
| 233 |
rtx axis_predicate[2]; /* Neutering predicates. */ |
| 234 |
int axis_dim[2]; /* Maximum number of threads on each axis, dim[0] is |
| 235 |
vector_length, dim[1] is num_workers. */ |
| 236 |
bool axis_dim_init_p; |
| 237 |
rtx bcast_partition; /* Register containing the size of each |
| 238 |
vector's partition of share-memory used to |
| 239 |
broadcast state. */ |
| 240 |
rtx red_partition; /* Similar to bcast_partition, except for vector |
| 241 |
reductions. */ |
| 242 |
rtx sync_bar; /* Synchronization barrier ID for vectors. */ |
| 243 |
rtx unisimt_master; /* 'Master lane index' for -muniform-simt. */ |
| 244 |
rtx unisimt_predicate; /* Predicate for -muniform-simt. */ |
| 245 |
rtx unisimt_outside_simt_predicate; /* Predicate for -muniform-simt. */ |
| 246 |
rtx unisimt_location; /* Mask location for -muniform-simt. */ |
| 247 |
/* The following two fields hold the maximum size resp. alignment required |
| 248 |
for per-lane storage in OpenMP SIMD regions. */ |
| 249 |
unsigned HOST_WIDE_INT simt_stack_size; |
| 250 |
unsigned HOST_WIDE_INT simt_stack_align; |
| 251 |
}; |
| 252 |
#endif |
| 253 |
|
| 254 |
/* Costs. */ |
| 255 |
|
| 256 |
#define NO_FUNCTION_CSE 1 |
| 257 |
#define SLOW_BYTE_ACCESS 0 |
| 258 |
#define BRANCH_COST(speed_p, predictable_p) 6 |
| 259 |
|
| 260 |
/* Assembler Format. */ |
| 261 |
|
| 262 |
#undef ASM_DECLARE_FUNCTION_NAME |
| 263 |
#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ |
| 264 |
nvptx_declare_function_name (FILE, NAME, DECL) |
| 265 |
|
| 266 |
#undef ASM_DECLARE_FUNCTION_SIZE |
| 267 |
#define ASM_DECLARE_FUNCTION_SIZE(STREAM, NAME, DECL) \ |
| 268 |
nvptx_function_end (STREAM) |
| 269 |
|
| 270 |
#define DWARF2_ASM_LINE_DEBUG_INFO 1 |
| 271 |
|
| 272 |
#undef ASM_APP_ON |
| 273 |
#define ASM_APP_ON "\t// #APP \n" |
| 274 |
#undef ASM_APP_OFF |
| 275 |
#define ASM_APP_OFF "\t// #NO_APP \n" |
| 276 |
|
| 277 |
#define DEBUGGER_REGNO(N) N |
| 278 |
|
| 279 |
#undef ASM_GENERATE_INTERNAL_LABEL |
| 280 |
#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \ |
| 281 |
do \ |
| 282 |
{ \ |
| 283 |
char *__p; \ |
| 284 |
__p = stpcpy (&(LABEL)[1], PREFIX); \ |
| 285 |
(LABEL)[0] = '$'; \ |
| 286 |
sprint_ul (__p, (unsigned long) (NUM)); \ |
| 287 |
} \ |
| 288 |
while (0) |
| 289 |
|
| 290 |
#define ASM_OUTPUT_ALIGN(FILE, POWER) \ |
| 291 |
do \ |
| 292 |
{ \ |
| 293 |
(void) (FILE); \ |
| 294 |
(void) (POWER); \ |
| 295 |
} \ |
| 296 |
while (0) |
| 297 |
|
| 298 |
#define ASM_OUTPUT_SKIP(FILE, N) \ |
| 299 |
nvptx_output_skip (FILE, N) |
| 300 |
|
| 301 |
#undef ASM_OUTPUT_ASCII |
| 302 |
#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \ |
| 303 |
nvptx_output_ascii (FILE, STR, LENGTH); |
| 304 |
|
| 305 |
#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \ |
| 306 |
nvptx_declare_object_name (FILE, NAME, DECL) |
| 307 |
|
| 308 |
#undef ASM_OUTPUT_ALIGNED_DECL_COMMON |
| 309 |
#define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \ |
| 310 |
nvptx_output_aligned_decl (FILE, NAME, DECL, SIZE, ALIGN) |
| 311 |
|
| 312 |
#undef ASM_OUTPUT_ALIGNED_DECL_LOCAL |
| 313 |
#define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \ |
| 314 |
nvptx_output_aligned_decl (FILE, NAME, DECL, SIZE, ALIGN) |
| 315 |
|
| 316 |
#define CASE_VECTOR_PC_RELATIVE flag_pic |
| 317 |
#define JUMP_TABLES_IN_TEXT_SECTION flag_pic |
| 318 |
|
| 319 |
#define ADDR_VEC_ALIGN(VEC) (JUMP_TABLES_IN_TEXT_SECTION ? 5 : 2) |
| 320 |
|
| 321 |
/* Misc. */ |
| 322 |
|
| 323 |
#define DWARF2_LINENO_DEBUGGING_INFO 1 |
| 324 |
|
| 325 |
#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \ |
| 326 |
((VALUE) = GET_MODE_BITSIZE ((MODE)), 2) |
| 327 |
#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \ |
| 328 |
((VALUE) = GET_MODE_BITSIZE ((MODE)), 2) |
| 329 |
|
| 330 |
#define SUPPORTS_WEAK 1 |
| 331 |
|
| 332 |
#define MAKE_DECL_ONE_ONLY(DECL) \ |
| 333 |
(DECL_WEAK (DECL) = 1) |
| 334 |
|
| 335 |
/* The documentation states that ASM_OUTPUT_DEF_FROM_DECLS is used in |
| 336 |
preference to ASM_OUTPUT_DEF if the tree nodes are available. However, we |
| 337 |
need the tree nodes to emit the prototype, so at this point it's not clear |
| 338 |
how we can support ASM_OUTPUT_DEF. Still, we need to define it, or |
| 339 |
ASM_OUTPUT_DEF_FROM_DECLS is ignored. For now, assert, and once we run |
| 340 |
into it possibly improve by somehow emitting the prototype elsewhere, or |
| 341 |
emitting a reasonable error message. */ |
| 342 |
#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \ |
| 343 |
do \ |
| 344 |
{ \ |
| 345 |
(void) (FILE); \ |
| 346 |
(void) (LABEL1); \ |
| 347 |
(void) (LABEL2); \ |
| 348 |
gcc_unreachable (); \ |
| 349 |
} \ |
| 350 |
while (0) |
| 351 |
#define ASM_OUTPUT_DEF_FROM_DECLS(STREAM, NAME, VALUE) \ |
| 352 |
nvptx_asm_output_def_from_decls (STREAM, NAME, VALUE) |
| 353 |
|
| 354 |
/* ..., but also override other macros to avoid 'gcc/defaults.h'-initialization |
| 355 |
due to that dummy 'ASM_OUTPUT_DEF'. */ |
| 356 |
#define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) TARGET_SUPPORTS_ALIASES |
| 357 |
#define TARGET_SUPPORTS_ALIASES (nvptx_alias != 0) |
| 358 |
|
| 359 |
#define NO_DOT_IN_LABEL |
| 360 |
#define ASM_COMMENT_START "//" |
| 361 |
|
| 362 |
#define STORE_FLAG_VALUE 1 |
| 363 |
#define FLOAT_STORE_FLAG_VALUE(MODE) REAL_VALUE_ATOF("1.0", (MODE)) |
| 364 |
|
| 365 |
#define CASE_VECTOR_MODE SImode |
| 366 |
#define MOVE_MAX 8 |
| 367 |
#define MOVE_RATIO(SPEED) 4 |
| 368 |
#define FUNCTION_MODE QImode |
| 369 |
|
| 370 |
/* Implement global constructor, destructor support in a conceptually simpler |
| 371 |
way than using 'collect2' (the program): implement the respective |
| 372 |
functionality in the nvptx-tools 'ld'. This however still requires the |
| 373 |
compiler-side effects corresponding to 'USE_COLLECT2': the global |
| 374 |
constructor, destructor support functions need to have external linkage, and |
| 375 |
therefore names that are "unique across the whole link". Use |
| 376 |
'!targetm.have_ctors_dtors' to achieve this (..., and thus don't need to |
| 377 |
provide 'targetm.asm_out.constructor', 'targetm.asm_out.destructor'). */ |
| 378 |
#define TARGET_HAVE_CTORS_DTORS false |
| 379 |
|
| 380 |
/* See 'libgcc/config/nvptx/crt0.c' for wrapping of 'main'. */ |
| 381 |
#define HAS_INIT_SECTION |
| 382 |
|
| 383 |
/* The default doesn't fly ('internal compiler error: in simplify_subreg' when |
| 384 |
'dw2_assemble_integer' -> 'assemble_integer' attempts to simplify |
| 385 |
'(minus:DI (symbol_ref:DI ("$LEHB0")) (symbol_ref:DI ("$LFB3")))', for |
| 386 |
example. Just emit something; it's not getting used, anyway. */ |
| 387 |
#define ASM_OUTPUT_DWARF_DELTA(STREAM, SIZE, LABEL1, LABEL2) \ |
| 388 |
do \ |
| 389 |
{ \ |
| 390 |
fprintf (STREAM, "%s[%d]: ", targetm.asm_out.byte_op, SIZE); \ |
| 391 |
const char *label1 = LABEL1; \ |
| 392 |
assemble_name_raw (STREAM, label1 ? label1 : "*nil"); \ |
| 393 |
fprintf (STREAM, " - "); \ |
| 394 |
const char *label2 = LABEL2; \ |
| 395 |
assemble_name_raw (STREAM, label2 ? label2 : "*nil"); \ |
| 396 |
} \ |
| 397 |
while (0) |
| 398 |
|
| 399 |
#endif /* GCC_NVPTX_H */ |