always define STACK_GROWS_DOWNWARD
[official-gcc.git] / gcc / config / nvptx / nvptx.h
blob502e43d6fd117566a1f370fc063b06b9d031519c
1 /* Target Definitions 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 #ifndef GCC_NVPTX_H
22 #define GCC_NVPTX_H
24 /* Run-time Target. */
26 #define STARTFILE_SPEC "%{mmainkernel:crt0.o}"
28 #define TARGET_CPU_CPP_BUILTINS() \
29 do \
30 { \
31 builtin_assert ("machine=nvptx"); \
32 builtin_assert ("cpu=nvptx"); \
33 builtin_define ("__nvptx__"); \
34 } while (0)
36 /* Avoid the default in ../../gcc.c, which adds "-pthread", which is not
37 supported for nvptx. */
38 #define GOMP_SELF_SPECS ""
40 /* Storage Layout. */
42 #define BITS_BIG_ENDIAN 0
43 #define BYTES_BIG_ENDIAN 0
44 #define WORDS_BIG_ENDIAN 0
46 /* Chosen such that we won't have to deal with multi-word subregs. */
47 #define UNITS_PER_WORD 8
49 #define PARM_BOUNDARY 8
50 #define STACK_BOUNDARY 64
51 #define FUNCTION_BOUNDARY 32
52 #define BIGGEST_ALIGNMENT 64
53 #define STRICT_ALIGNMENT 1
55 /* Copied from elf.h and other places. We'd otherwise use
56 BIGGEST_ALIGNMENT and fail a number of testcases. */
57 #define MAX_OFILE_ALIGNMENT (32768 * 8)
59 /* Type Layout. */
61 #define DEFAULT_SIGNED_CHAR 1
63 #define SHORT_TYPE_SIZE 16
64 #define INT_TYPE_SIZE 32
65 #define LONG_TYPE_SIZE (TARGET_ABI64 ? 64 : 32)
66 #define LONG_LONG_TYPE_SIZE 64
67 #define FLOAT_TYPE_SIZE 32
68 #define DOUBLE_TYPE_SIZE 64
69 #define LONG_DOUBLE_TYPE_SIZE 64
71 #undef SIZE_TYPE
72 #define SIZE_TYPE (TARGET_ABI64 ? "long unsigned int" : "unsigned int")
73 #undef PTRDIFF_TYPE
74 #define PTRDIFF_TYPE (TARGET_ABI64 ? "long int" : "int")
76 #define POINTER_SIZE (TARGET_ABI64 ? 64 : 32)
78 #define Pmode (TARGET_ABI64 ? DImode : SImode)
80 /* Registers. Since ptx is a virtual target, we just define a few
81 hard registers for special purposes and leave pseudos unallocated. */
83 #define FIRST_PSEUDO_REGISTER 16
84 #define FIXED_REGISTERS \
85 { 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }
86 #define CALL_USED_REGISTERS \
87 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
89 #define HARD_REGNO_NREGS(regno, mode) 1
90 #define CANNOT_CHANGE_MODE_CLASS(M1, M2, CLS) ((CLS) == RETURN_REG)
91 #define HARD_REGNO_MODE_OK(REG, MODE) nvptx_hard_regno_mode_ok (REG, MODE)
93 /* Register Classes. */
95 enum reg_class
97 NO_REGS,
98 RETURN_REG,
99 ALL_REGS,
100 LIM_REG_CLASSES
103 #define N_REG_CLASSES (int) LIM_REG_CLASSES
105 #define REG_CLASS_NAMES { \
106 "RETURN_REG", \
107 "NO_REGS", \
108 "ALL_REGS" }
110 #define REG_CLASS_CONTENTS \
112 /* NO_REGS. */ \
113 { 0x0000 }, \
114 /* RETURN_REG. */ \
115 { 0x0008 }, \
116 /* ALL_REGS. */ \
117 { 0xFFFF }, \
120 #define GENERAL_REGS ALL_REGS
122 #define REGNO_REG_CLASS(R) ((R) == 4 ? RETURN_REG : ALL_REGS)
124 #define BASE_REG_CLASS ALL_REGS
125 #define INDEX_REG_CLASS NO_REGS
127 #define REGNO_OK_FOR_BASE_P(X) true
128 #define REGNO_OK_FOR_INDEX_P(X) false
130 #define CLASS_MAX_NREGS(class, mode) \
131 ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
133 #define MODES_TIEABLE_P(M1, M2) false
135 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
136 if (GET_MODE_CLASS (MODE) == MODE_INT \
137 && GET_MODE_SIZE (MODE) < GET_MODE_SIZE (SImode)) \
139 (MODE) = SImode; \
142 /* Address spaces. */
143 #define ADDR_SPACE_GLOBAL 1
144 #define ADDR_SPACE_SHARED 3
145 #define ADDR_SPACE_CONST 4
146 #define ADDR_SPACE_LOCAL 5
147 #define ADDR_SPACE_PARAM 101
149 /* Stack and Calling. */
151 #define STARTING_FRAME_OFFSET 0
152 #define FRAME_GROWS_DOWNWARD 0
153 #define STACK_GROWS_DOWNWARD 1
155 #define STACK_POINTER_REGNUM 1
156 #define HARD_FRAME_POINTER_REGNUM 2
157 #define NVPTX_PUNNING_BUFFER_REGNUM 3
158 #define NVPTX_RETURN_REGNUM 4
159 #define FRAME_POINTER_REGNUM 15
160 #define ARG_POINTER_REGNUM 14
161 #define RETURN_ADDR_REGNO 13
163 #define STATIC_CHAIN_REGNUM 12
164 #define OUTGOING_ARG_POINTER_REGNUM 11
165 #define OUTGOING_STATIC_CHAIN_REGNUM 10
167 #define FIRST_PARM_OFFSET(FNDECL) 0
168 #define PUSH_ARGS_REVERSED 1
170 #define ACCUMULATE_OUTGOING_ARGS 1
172 #ifdef HOST_WIDE_INT
173 struct nvptx_args {
174 union tree_node *fntype;
175 /* Number of arguments passed in registers so far. */
176 int count;
177 /* Offset into the stdarg area so far. */
178 HOST_WIDE_INT off;
180 #endif
182 #define CUMULATIVE_ARGS struct nvptx_args
184 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
185 do { (CUM).fntype = (FNTYPE); (CUM).count = 0; (CUM).off = 0; } while (0)
187 #define FUNCTION_ARG_REGNO_P(r) 0
189 #define DEFAULT_PCC_STRUCT_RETURN 0
191 #define FUNCTION_PROFILER(file, labelno) \
192 fatal_error (input_location, \
193 "profiling is not yet implemented for this architecture")
195 #define TRAMPOLINE_SIZE 32
196 #define TRAMPOLINE_ALIGNMENT 256
198 /* We don't run reload, so this isn't actually used, but it still needs to be
199 defined. Showing an argp->fp elimination also stops
200 expand_builtin_setjmp_receiver from generating invalid insns. */
201 #define ELIMINABLE_REGS \
203 { FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
204 { ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM} \
207 /* Define the offset between two registers, one to be eliminated, and the other
208 its replacement, at the start of a routine. */
210 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
211 ((OFFSET) = 0)
213 /* Addressing Modes. */
215 #define MAX_REGS_PER_ADDRESS 1
217 #define LEGITIMATE_PIC_OPERAND_P(X) 1
220 struct nvptx_pseudo_info
222 int true_size;
223 int renumber;
226 #if defined HOST_WIDE_INT
227 struct GTY(()) machine_function
229 rtx_expr_list *call_args;
230 rtx start_call;
231 tree funtype;
232 bool has_call_with_varargs;
233 bool has_call_with_sc;
234 struct GTY((skip)) nvptx_pseudo_info *pseudos;
235 HOST_WIDE_INT outgoing_stdarg_size;
236 int ret_reg_mode;
237 int punning_buffer_size;
239 #endif
241 /* Costs. */
243 #define NO_FUNCTION_CSE 1
244 #define SLOW_BYTE_ACCESS 0
245 #define BRANCH_COST(speed_p, predictable_p) 6
247 /* Assembler Format. */
249 #undef ASM_DECLARE_FUNCTION_NAME
250 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
251 nvptx_declare_function_name (FILE, NAME, DECL)
253 #undef ASM_DECLARE_FUNCTION_SIZE
254 #define ASM_DECLARE_FUNCTION_SIZE(STREAM, NAME, DECL) \
255 nvptx_function_end (STREAM)
257 #define DWARF2_ASM_LINE_DEBUG_INFO 1
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"
264 #define ASM_OUTPUT_COMMON(stream, name, size, rounded)
265 #define ASM_OUTPUT_LOCAL(stream, name, size, rounded)
267 #define REGISTER_NAMES \
269 "%hr0", "%outargs", "%hfp", "%punbuffer", "%retval", "%retval_in", "%hr6", "%hr7", \
270 "%hr8", "%hr9", "%hr10", "%hr11", "%hr12", "%hr13", "%argp", "%frame" \
273 #define DBX_REGISTER_NUMBER(N) N
275 #define TEXT_SECTION_ASM_OP ""
276 #define DATA_SECTION_ASM_OP ""
278 #undef ASM_GENERATE_INTERNAL_LABEL
279 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
280 do \
282 char *__p; \
283 __p = stpcpy (&(LABEL)[1], PREFIX); \
284 (LABEL)[0] = '$'; \
285 sprint_ul (__p, (unsigned long) (NUM)); \
287 while (0)
289 #define ASM_OUTPUT_ALIGN(FILE, POWER) \
290 do \
292 (void) (FILE); \
293 (void) (POWER); \
295 while (0)
297 #define ASM_OUTPUT_SKIP(FILE, N) \
298 nvptx_output_skip (FILE, N)
300 #undef ASM_OUTPUT_ASCII
301 #define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \
302 nvptx_output_ascii (FILE, STR, LENGTH);
304 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
305 nvptx_declare_object_name (FILE, NAME, DECL)
307 #undef ASM_OUTPUT_ALIGNED_DECL_COMMON
308 #define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \
309 do \
311 fprintf (FILE, "// BEGIN%s VAR DEF: ", \
312 TREE_PUBLIC (DECL) ? " GLOBAL" : ""); \
313 assemble_name_raw (FILE, NAME); \
314 fputc ('\n', FILE); \
315 const char *sec = nvptx_section_for_decl (DECL); \
316 fprintf (FILE, ".visible%s.align %d .b8 ", sec, \
317 (ALIGN) / BITS_PER_UNIT); \
318 assemble_name ((FILE), (NAME)); \
319 if ((SIZE) > 0) \
320 fprintf (FILE, "[" HOST_WIDE_INT_PRINT_DEC"]", (SIZE)); \
321 fprintf (FILE, ";\n"); \
323 while (0)
325 #undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
326 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
327 do \
329 fprintf (FILE, "// BEGIN VAR DEF: "); \
330 assemble_name_raw (FILE, NAME); \
331 fputc ('\n', FILE); \
332 const char *sec = nvptx_section_for_decl (DECL); \
333 fprintf (FILE, ".visible%s.align %d .b8 ", sec, \
334 (ALIGN) / BITS_PER_UNIT); \
335 assemble_name ((FILE), (NAME)); \
336 if ((SIZE) > 0) \
337 fprintf (FILE, "[" HOST_WIDE_INT_PRINT_DEC"]", (SIZE)); \
338 fprintf (FILE, ";\n"); \
340 while (0)
342 #define CASE_VECTOR_PC_RELATIVE flag_pic
343 #define JUMP_TABLES_IN_TEXT_SECTION flag_pic
345 #define ADDR_VEC_ALIGN(VEC) (JUMP_TABLES_IN_TEXT_SECTION ? 5 : 2)
347 /* Misc. */
349 #define DWARF2_DEBUGGING_INFO 1
351 #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
352 ((VALUE) = GET_MODE_BITSIZE ((MODE)), 2)
353 #define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
354 ((VALUE) = GET_MODE_BITSIZE ((MODE)), 2)
356 #define NO_DOT_IN_LABEL
357 #define ASM_COMMENT_START "//"
359 #define STORE_FLAG_VALUE -1
360 #define FLOAT_STORE_FLAG_VALUE(MODE) REAL_VALUE_ATOF("1.0", (MODE))
362 #define CASE_VECTOR_MODE SImode
363 #define MOVE_MAX 4
364 #define MOVE_RATIO(SPEED) 4
365 #define TRULY_NOOP_TRUNCATION(outprec, inprec) 1
366 #define FUNCTION_MODE QImode
367 #define HAS_INIT_SECTION 1
369 /* The C++ front end insists to link against libstdc++ -- which we don't build.
370 Tell it to instead link against the innocuous libgcc. */
371 #define LIBSTDCXX "gcc"
373 #endif /* GCC_NVPTX_H */