diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2020-07-07 17:27:09 +0800 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2020-11-28 21:13:18 +0000 |
commit | c54f4e711e7503a17a98cf08bdfeb6fecd0bc418 (patch) | |
tree | 02e48416e61d5486872ff7bfb8e7e33dddac79f0 | |
parent | 9e9c2eb329b3df4c281a2f586d87e6c81c12c6b5 (diff) | |
download | gcc-c54f4e711e7503a17a98cf08bdfeb6fecd0bc418.zip gcc-c54f4e711e7503a17a98cf08bdfeb6fecd0bc418.tar.gz gcc-c54f4e711e7503a17a98cf08bdfeb6fecd0bc418.tar.bz2 |
Added (very bad and provisional) Nvidia PTX target hook
-rw-r--r-- | gcc/config.gcc | 1 | ||||
-rw-r--r-- | gcc/config/nvptx/nvptx-protos.h | 3 | ||||
-rw-r--r-- | gcc/config/nvptx/nvptx-rust.c | 64 | ||||
-rw-r--r-- | gcc/config/nvptx/nvptx.h | 2 | ||||
-rw-r--r-- | gcc/config/nvptx/t-nvptx | 4 |
5 files changed, 74 insertions, 0 deletions
diff --git a/gcc/config.gcc b/gcc/config.gcc index fa277d0..a81f858 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -526,6 +526,7 @@ nios2-*-*) ;; nvptx-*-*) cpu_type=nvptx + rust_target_objs="nvptx-rust.o" ;; or1k*-*-*) cpu_type=or1k diff --git a/gcc/config/nvptx/nvptx-protos.h b/gcc/config/nvptx/nvptx-protos.h index 68a2e42..34e8b77 100644 --- a/gcc/config/nvptx/nvptx-protos.h +++ b/gcc/config/nvptx/nvptx-protos.h @@ -43,6 +43,9 @@ extern void nvptx_output_ascii (FILE *, const char *, unsigned HOST_WIDE_INT); extern void nvptx_register_pragmas (void); extern unsigned int nvptx_data_alignment (const_tree, unsigned int); +/* Routines implemented in nvptx-rust.c */ +extern void nvptx_rust_target_cpu_info (void); + #ifdef RTX_CODE extern void nvptx_expand_oacc_fork (unsigned); extern void nvptx_expand_oacc_join (unsigned); diff --git a/gcc/config/nvptx/nvptx-rust.c b/gcc/config/nvptx/nvptx-rust.c new file mode 100644 index 0000000..c73bb16 --- /dev/null +++ b/gcc/config/nvptx/nvptx-rust.c @@ -0,0 +1,64 @@ +/* Subroutines for the Rust front end for the Nvidia PTX architecture. + Copyright (C) 2020 Free Software Foundation, Inc. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tm_p.h" +#include "rust/rust-target.h" +#include "rust/rust-target-def.h" + +/* Implement TARGET_RUST_CPU_INFO for NVPTX targets. */ + +void nvptx_rust_target_cpu_info(void) { + if (TARGET_ABI64) + rust_add_target_info("target_arch", "nvptx64"); + else + rust_add_target_info("target_arch", "nvptx"); + + // TODO: should this also override target_os and target_vendor to be "cuda" and "nvidia"? + + // names derived from llvm + // TODO: ensure below variable and switch works + switch (ptx_isa_option) { + /* TODO: if gcc adds other sm versions (llvm has 20, 21, 32, 37, 50, 52, 53, 60, 61, 62, 70, 72, + * 75, 80 as well), add them here */ + case PTX_ISA_SM30: + rust_add_target_info("target_feature", "sm_30"); + break; + case PTX_ISA_SM35: + rust_add_target_info("target_feature", "sm_35"); + break; + default: // should this be an error? + break; + } + /* TODO: add ptx versions as separate features if gcc adds them (ptx32, 40, 41, 42, 43, 50, 60, 61, + * 63, 64, 65, 70) */ + + // NOTE: below are all gcc-derived features that do not appear in llvm. they appeared useful, so added + // TODO: ensure below variable works + if (nvptx_optimize) + rust_add_target_info("target_feature", "optimize"); + if (TARGET_SOFT_STACK) + rust_add_target_info("target_feature", "soft-stack"); + // TODO: find way to have soft-stack-reserve-local as define + if (TARGET_UNIFORM_SIMT) + rust_add_target_info("target_feature", "uniform-simt"); + if (TARGET_GOMP) + rust_add_target_info("target_feature", "gomp"); +} diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h index 17fe157..00df794 100644 --- a/gcc/config/nvptx/nvptx.h +++ b/gcc/config/nvptx/nvptx.h @@ -46,6 +46,8 @@ builtin_define ("__nvptx_unisimt__"); \ } while (0) +#define TARGET_RUST_CPU_INFO nvptx_rust_target_cpu_info + /* Avoid the default in ../../gcc.c, which adds "-pthread", which is not supported for nvptx. */ #define GOMP_SELF_SPECS "" diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx index 6c1010d..3d44548 100644 --- a/gcc/config/nvptx/t-nvptx +++ b/gcc/config/nvptx/t-nvptx @@ -10,3 +10,7 @@ mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS) MULTILIB_OPTIONS = mgomp + +nvptx-rust.o: $(srcdir)/config/nvptx/nvptx-rust.c \ + $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_COMMON_H) + $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< |