Add the nvptx port.

* configure.ac: Handle nvptx-*-*.
	* configure: Regenerate.

	gcc/
	* config/nvptx/nvptx.c: New file.
	* config/nvptx/nvptx.h: New file.
	* config/nvptx/nvptx-protos.h: New file.
	* config/nvptx/nvptx.md: New file.
	* config/nvptx/t-nvptx: New file.
	* config/nvptx/nvptx.opt: New file.
	* common/config/nvptx/nvptx-common.c: New file.
	* config.gcc: Handle nvptx-*-*.

	libgcc/
	* config.host: Handle nvptx-*-*.
	* shared-object.mk (as-flags-$o): Define.
	($(base)$(objext), $(base)_s$(objext)): Use it instead of
	-xassembler-with-cpp.
	* static-object.mk: Identical changes.
	* config/nvptx/t-nvptx: New file.
	* config/nvptx/crt0.s: New file.
	* config/nvptx/free.asm: New file.
	* config/nvptx/malloc.asm: New file.
	* config/nvptx/realloc.c: New file.

From-SVN: r217295
This commit is contained in:
Bernd Schmidt 2014-11-10 16:12:42 +00:00 committed by Bernd Schmidt
parent c81b4a0e83
commit 738f25224b
22 changed files with 4260 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2014-11-06 Bernd Schmidt <bernds@codesourcery.com>
* configure.ac: Handle nvptx-*-*.
* configure: Regenerate.
2014-11-06 Prachi Godbole <prachi.godbole@imgtec.com>
* MAINTAINERS (Write After Approval): Add myself.

4
configure vendored
View File

@ -3779,6 +3779,10 @@ case "${target}" in
mips*-*-*)
noconfigdirs="$noconfigdirs gprof"
;;
nvptx*-*-*)
# nvptx is just a compiler
noconfigdirs="$noconfigdirs target-libssp target-libstdc++-v3 target-libobjc"
;;
sh-*-* | sh64-*-*)
case "${target}" in
sh*-*-elf)

View File

@ -1138,6 +1138,10 @@ case "${target}" in
mips*-*-*)
noconfigdirs="$noconfigdirs gprof"
;;
nvptx*-*-*)
# nvptx is just a compiler
noconfigdirs="$noconfigdirs target-libssp target-libstdc++-v3 target-libobjc"
;;
sh-*-* | sh64-*-*)
case "${target}" in
sh*-*-elf)

View File

@ -1,3 +1,14 @@
2014-11-10 Bernd Schmidt <bernds@codesourcery.com>
* config/nvptx/nvptx.c: New file.
* config/nvptx/nvptx.h: New file.
* config/nvptx/nvptx-protos.h: New file.
* config/nvptx/nvptx.md: New file.
* config/nvptx/t-nvptx: New file.
* config/nvptx/nvptx.opt: New file.
* common/config/nvptx/nvptx-common.c: New file.
* config.gcc: Handle nvptx-*-*.
2014-11-10 Richard Biener <rguenther@suse.de>
* tree-ssa-operands.c (finalize_ssa_uses): Properly put

View File

@ -0,0 +1,38 @@
/* NVPTX common hooks.
Copyright (C) 2014 Free Software Foundation, Inc.
Contributed by Bernd Schmidt <bernds@codesourcery.com>
This file is part of GCC.
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 "diagnostic-core.h"
#include "tm.h"
#include "tm_p.h"
#include "common/common-target.h"
#include "common/common-target-def.h"
#include "opts.h"
#include "flags.h"
#undef TARGET_HAVE_NAMED_SECTIONS
#define TARGET_HAVE_NAMED_SECTIONS false
#undef TARGET_DEFAULT_TARGET_FLAGS
#define TARGET_DEFAULT_TARGET_FLAGS MASK_ABI64
struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;

View File

@ -422,6 +422,9 @@ nios2-*-*)
cpu_type=nios2
extra_options="${extra_options} g.opt"
;;
nvptx-*-*)
cpu_type=nvptx
;;
powerpc*-*-*)
cpu_type=rs6000
extra_headers="ppc-asm.h altivec.h spe.h ppu_intrinsics.h paired.h spu2vmx.h vec_types.h si2vmx.h htmintrin.h htmxlintrin.h"
@ -2153,6 +2156,10 @@ nios2-*-*)
;;
esac
;;
nvptx-*)
tm_file="${tm_file} newlib-stdint.h"
tmake_file="nvptx/t-nvptx"
;;
pdp11-*-*)
tm_file="${tm_file} newlib-stdint.h"
use_gcc_stdint=wrap

View File

@ -0,0 +1,46 @@
/* Prototypes for exported functions defined in nvptx.c.
Copyright (C) 2014 Free Software Foundation, Inc.
Contributed by Bernd Schmidt <bernds@codesourcery.com>
This file is part of GCC.
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/>. */
#ifndef GCC_NVPTX_PROTOS_H
#define GCC_NVPTX_PROTOS_H
extern void nvptx_declare_function_name (FILE *, const char *, const_tree decl);
extern void nvptx_declare_object_name (FILE *file, const char *name,
const_tree decl);
extern void nvptx_record_needed_fndecl (tree decl);
extern void nvptx_function_end (FILE *);
extern void nvptx_output_skip (FILE *, unsigned HOST_WIDE_INT);
extern void nvptx_output_ascii (FILE *, const char *, unsigned HOST_WIDE_INT);
extern void nvptx_register_pragmas (void);
extern const char *nvptx_section_for_decl (const_tree);
#ifdef RTX_CODE
extern void nvptx_expand_call (rtx, rtx);
extern rtx nvptx_expand_compare (rtx);
extern const char *nvptx_ptx_type_from_mode (machine_mode, bool);
extern const char *nvptx_output_call_insn (rtx_insn *, rtx, rtx);
extern const char *nvptx_output_return (void);
extern machine_mode nvptx_underlying_object_mode (rtx);
extern const char *nvptx_section_from_addr_space (addr_space_t);
extern bool nvptx_hard_regno_mode_ok (int, machine_mode);
extern addr_space_t nvptx_addr_space_from_address (rtx);
extern rtx nvptx_maybe_convert_symbolic_operand (rtx);
#endif
#endif

2120
gcc/config/nvptx/nvptx.c Normal file

File diff suppressed because it is too large Load Diff

356
gcc/config/nvptx/nvptx.h Normal file
View File

@ -0,0 +1,356 @@
/* Target Definitions for NVPTX.
Copyright (C) 2014 Free Software Foundation, Inc.
Contributed by Bernd Schmidt <bernds@codesourcery.com>
This file is part of GCC.
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/>. */
#ifndef GCC_NVPTX_H
#define GCC_NVPTX_H
/* Run-time Target. */
#define STARTFILE_SPEC "%{mmainkernel:crt0.o}"
#define TARGET_CPU_CPP_BUILTINS() \
do \
{ \
builtin_assert ("machine=nvptx"); \
builtin_assert ("cpu=nvptx"); \
builtin_define ("__nvptx__"); \
} while (0)
/* Storage Layout. */
#define BITS_BIG_ENDIAN 0
#define BYTES_BIG_ENDIAN 0
#define WORDS_BIG_ENDIAN 0
/* Chosen such that we won't have to deal with multi-word subregs. */
#define UNITS_PER_WORD 8
#define PARM_BOUNDARY 8
#define STACK_BOUNDARY 64
#define FUNCTION_BOUNDARY 32
#define BIGGEST_ALIGNMENT 64
#define STRICT_ALIGNMENT 1
/* Copied from elf.h and other places. We'd otherwise use
BIGGEST_ALIGNMENT and fail a number of testcases. */
#define MAX_OFILE_ALIGNMENT (32768 * 8)
/* Type Layout. */
#define DEFAULT_SIGNED_CHAR 1
#define SHORT_TYPE_SIZE 16
#define INT_TYPE_SIZE 32
#define LONG_TYPE_SIZE (TARGET_ABI64 ? 64 : 32)
#define LONG_LONG_TYPE_SIZE 64
#define FLOAT_TYPE_SIZE 32
#define DOUBLE_TYPE_SIZE 64
#define LONG_DOUBLE_TYPE_SIZE 64
#undef SIZE_TYPE
#define SIZE_TYPE (TARGET_ABI64 ? "long unsigned int" : "unsigned int")
#undef PTRDIFF_TYPE
#define PTRDIFF_TYPE (TARGET_ABI64 ? "long int" : "int")
#define POINTER_SIZE (TARGET_ABI64 ? 64 : 32)
#define Pmode (TARGET_ABI64 ? DImode : SImode)
/* Registers. Since ptx is a virtual target, we just define a few
hard registers for special purposes and leave pseudos unallocated. */
#define FIRST_PSEUDO_REGISTER 16
#define FIXED_REGISTERS \
{ 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }
#define CALL_USED_REGISTERS \
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
#define HARD_REGNO_NREGS(regno, mode) 1
#define CANNOT_CHANGE_MODE_CLASS(M1, M2, CLS) ((CLS) == RETURN_REG)
#define HARD_REGNO_MODE_OK(REG, MODE) nvptx_hard_regno_mode_ok (REG, MODE)
/* Register Classes. */
enum reg_class
{
NO_REGS,
RETURN_REG,
ALL_REGS,
LIM_REG_CLASSES
};
#define N_REG_CLASSES (int) LIM_REG_CLASSES
#define REG_CLASS_NAMES { \
"RETURN_REG", \
"NO_REGS", \
"ALL_REGS" }
#define REG_CLASS_CONTENTS \
{ \
/* NO_REGS. */ \
{ 0x0000 }, \
/* RETURN_REG. */ \
{ 0x0008 }, \
/* ALL_REGS. */ \
{ 0xFFFF }, \
}
#define GENERAL_REGS ALL_REGS
#define REGNO_REG_CLASS(R) ((R) == 4 ? RETURN_REG : ALL_REGS)
#define BASE_REG_CLASS ALL_REGS
#define INDEX_REG_CLASS NO_REGS
#define REGNO_OK_FOR_BASE_P(X) true
#define REGNO_OK_FOR_INDEX_P(X) false
#define CLASS_MAX_NREGS(class, mode) \
((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
#define MODES_TIEABLE_P(M1, M2) false
#define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
if (GET_MODE_CLASS (MODE) == MODE_INT \
&& GET_MODE_SIZE (MODE) < GET_MODE_SIZE (SImode)) \
{ \
(MODE) = SImode; \
}
/* Address spaces. */
#define ADDR_SPACE_GLOBAL 1
#define ADDR_SPACE_SHARED 3
#define ADDR_SPACE_CONST 4
#define ADDR_SPACE_LOCAL 5
#define ADDR_SPACE_PARAM 101
/* Stack and Calling. */
#define STARTING_FRAME_OFFSET 0
#define FRAME_GROWS_DOWNWARD 0
#define STACK_GROWS_DOWNWARD
#define STACK_POINTER_REGNUM 1
#define HARD_FRAME_POINTER_REGNUM 2
#define NVPTX_PUNNING_BUFFER_REGNUM 3
#define NVPTX_RETURN_REGNUM 4
#define FRAME_POINTER_REGNUM 15
#define ARG_POINTER_REGNUM 14
#define RETURN_ADDR_REGNO 13
#define STATIC_CHAIN_REGNUM 12
#define OUTGOING_ARG_POINTER_REGNUM 11
#define OUTGOING_STATIC_CHAIN_REGNUM 10
#define FIRST_PARM_OFFSET(FNDECL) 0
#define PUSH_ARGS_REVERSED 1
#define ACCUMULATE_OUTGOING_ARGS 1
#ifdef HOST_WIDE_INT
struct nvptx_args {
union tree_node *fntype;
/* Number of arguments passed in registers so far. */
int count;
/* Offset into the stdarg area so far. */
HOST_WIDE_INT off;
};
#endif
#define CUMULATIVE_ARGS struct nvptx_args
#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
do { (CUM).fntype = (FNTYPE); (CUM).count = 0; (CUM).off = 0; } while (0)
#define FUNCTION_ARG_REGNO_P(r) 0
#define DEFAULT_PCC_STRUCT_RETURN 0
#define FUNCTION_PROFILER(file, labelno) \
fatal_error ("profiling is not yet implemented for this architecture")
#define TRAMPOLINE_SIZE 32
#define TRAMPOLINE_ALIGNMENT 256
/* We don't run reload, so this isn't actually used, but it still needs to be
defined. Showing an argp->fp elimination also stops
expand_builtin_setjmp_receiver from generating invalid insns. */
#define ELIMINABLE_REGS \
{ \
{ FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
{ ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM} \
}
/* Define the offset between two registers, one to be eliminated, and the other
its replacement, at the start of a routine. */
#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
((OFFSET) = 0)
/* Addressing Modes. */
#define MAX_REGS_PER_ADDRESS 1
#define LEGITIMATE_PIC_OPERAND_P(X) 1
struct nvptx_pseudo_info
{
int true_size;
int renumber;
};
#if defined HOST_WIDE_INT
struct GTY(()) machine_function
{
rtx_expr_list *call_args;
rtx start_call;
tree funtype;
bool has_call_with_varargs;
bool has_call_with_sc;
struct GTY((skip)) nvptx_pseudo_info *pseudos;
HOST_WIDE_INT outgoing_stdarg_size;
int ret_reg_mode;
int punning_buffer_size;
};
#endif
/* Costs. */
#define NO_FUNCTION_CSE 1
#define SLOW_BYTE_ACCESS 0
#define BRANCH_COST(speed_p, predictable_p) 6
/* Assembler Format. */
#undef ASM_DECLARE_FUNCTION_NAME
#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
nvptx_declare_function_name (FILE, NAME, DECL)
#undef ASM_DECLARE_FUNCTION_SIZE
#define ASM_DECLARE_FUNCTION_SIZE(STREAM, NAME, DECL) \
nvptx_function_end (STREAM)
#define DWARF2_ASM_LINE_DEBUG_INFO 1
#undef ASM_APP_ON
#define ASM_APP_ON "\t// #APP \n"
#undef ASM_APP_OFF
#define ASM_APP_OFF "\t// #NO_APP \n"
#define ASM_OUTPUT_COMMON(stream, name, size, rounded)
#define ASM_OUTPUT_LOCAL(stream, name, size, rounded)
#define REGISTER_NAMES \
{ \
"%hr0", "%outargs", "%hfp", "%punbuffer", "%retval", "%retval_in", "%hr6", "%hr7", \
"%hr8", "%hr9", "%hr10", "%hr11", "%hr12", "%hr13", "%argp", "%frame" \
}
#define DBX_REGISTER_NUMBER(N) N
#define TEXT_SECTION_ASM_OP ""
#define DATA_SECTION_ASM_OP ""
#undef ASM_GENERATE_INTERNAL_LABEL
#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
do \
{ \
char *__p; \
__p = stpcpy (&(LABEL)[1], PREFIX); \
(LABEL)[0] = '$'; \
sprint_ul (__p, (unsigned long) (NUM)); \
} \
while (0)
#define ASM_OUTPUT_ALIGN(FILE, POWER)
#define ASM_OUTPUT_SKIP(FILE, N) \
nvptx_output_skip (FILE, N)
#undef ASM_OUTPUT_ASCII
#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \
nvptx_output_ascii (FILE, STR, LENGTH);
#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
nvptx_declare_object_name (FILE, NAME, DECL)
#undef ASM_OUTPUT_ALIGNED_DECL_COMMON
#define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \
do \
{ \
fprintf (FILE, "// BEGIN%s VAR DEF: ", \
TREE_PUBLIC (DECL) ? " GLOBAL" : ""); \
assemble_name_raw (FILE, NAME); \
fputc ('\n', FILE); \
const char *sec = nvptx_section_for_decl (DECL); \
fprintf (FILE, ".visible%s.align %d .b8 ", sec, \
(ALIGN) / BITS_PER_UNIT); \
assemble_name ((FILE), (NAME)); \
if ((SIZE) > 0) \
fprintf (FILE, "["HOST_WIDE_INT_PRINT_DEC"]", (SIZE)); \
fprintf (FILE, ";\n"); \
} \
while (0)
#undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
#define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
do \
{ \
fprintf (FILE, "// BEGIN VAR DEF: "); \
assemble_name_raw (FILE, NAME); \
fputc ('\n', FILE); \
const char *sec = nvptx_section_for_decl (DECL); \
fprintf (FILE, ".visible%s.align %d .b8 ", sec, \
(ALIGN) / BITS_PER_UNIT); \
assemble_name ((FILE), (NAME)); \
if ((SIZE) > 0) \
fprintf (FILE, "["HOST_WIDE_INT_PRINT_DEC"]", (SIZE)); \
fprintf (FILE, ";\n"); \
} \
while (0)
#define CASE_VECTOR_PC_RELATIVE flag_pic
#define JUMP_TABLES_IN_TEXT_SECTION flag_pic
#define ADDR_VEC_ALIGN(VEC) (JUMP_TABLES_IN_TEXT_SECTION ? 5 : 2)
/* Misc. */
#define DWARF2_DEBUGGING_INFO 1
#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
((VALUE) = GET_MODE_BITSIZE ((MODE)), 2)
#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
((VALUE) = GET_MODE_BITSIZE ((MODE)), 2)
#define NO_DOT_IN_LABEL
#define ASM_COMMENT_START "//"
#define STORE_FLAG_VALUE -1
#define FLOAT_STORE_FLAG_VALUE(MODE) REAL_VALUE_ATOF("1.0", (MODE))
#define CASE_VECTOR_MODE SImode
#define MOVE_MAX 4
#define MOVE_RATIO(SPEED) 4
#define TRULY_NOOP_TRUNCATION(outprec, inprec) 1
#define FUNCTION_MODE QImode
#define HAS_INIT_SECTION 1
#endif /* GCC_NVPTX_H */

1376
gcc/config/nvptx/nvptx.md Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,30 @@
; Options for the NVPTX port
; Copyright 2014 Free Software Foundation, Inc.
;
; This file is part of GCC.
;
; 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/>.
m64
Target Report RejectNegative Mask(ABI64)
Generate code for a 64 bit ABI
m32
Target Report RejectNegative InverseMask(ABI64)
Generate code for a 32 bit ABI
mmainkernel
Target Report RejectNegative
Link in code for a __main kernel.

2
gcc/config/nvptx/t-nvptx Normal file
View File

@ -0,0 +1,2 @@
#

View File

@ -1,3 +1,16 @@
2014-11-06 Bernd Schmidt <bernds@codesourcery.com>
* config.host: Handle nvptx-*-*.
* shared-object.mk (as-flags-$o): Define.
($(base)$(objext), $(base)_s$(objext)): Use it instead of
-xassembler-with-cpp.
* static-object.mk: Identical changes.
* config/nvptx/t-nvptx: New file.
* config/nvptx/crt0.s: New file.
* config/nvptx/free.asm: New file.
* config/nvptx/malloc.asm: New file.
* config/nvptx/realloc.c: New file.
2014-10-30 Joseph Myers <joseph@codesourcery.com>
* Makefile.in (libgcc.map.in): New target.

View File

@ -1256,6 +1256,10 @@ mep*-*-*)
tmake_file="mep/t-mep t-fdpbit"
extra_parts="crtbegin.o crtend.o"
;;
nvptx-*)
tmake_file="$tmake_file nvptx/t-nvptx"
extra_parts="crt0.o"
;;
*)
echo "*** Configuration ${host} not supported" 1>&2
exit 1

View File

@ -0,0 +1,45 @@
.version 3.1
.target sm_30
.address_size 64
.global .u64 %__exitval;
// BEGIN GLOBAL FUNCTION DEF: abort
.visible .func abort
{
.reg .u64 %rd1;
ld.global.u64 %rd1,[%__exitval];
st.u32 [%rd1], 255;
exit;
}
// BEGIN GLOBAL FUNCTION DEF: exit
.visible .func exit (.param .u32 %arg)
{
.reg .u64 %rd1;
.reg .u32 %val;
ld.param.u32 %val,[%arg];
ld.global.u64 %rd1,[%__exitval];
st.u32 [%rd1], %val;
exit;
}
.extern .func (.param.u32 retval) main (.param.u32 argc, .param.u64 argv);
.visible .entry __main (.param .u64 __retval, .param.u32 __argc, .param.u64 __argv)
{
.reg .u32 %r<3>;
.reg .u64 %rd<3>;
.param.u32 %argc;
.param.u64 %argp;
.param.u32 %mainret;
ld.param.u64 %rd0, [__retval];
st.global.u64 [%__exitval], %rd0;
ld.param.u32 %r1, [__argc];
ld.param.u64 %rd1, [__argv];
st.param.u32 [%argc], %r1;
st.param.u64 [%argp], %rd1;
call.uni (%mainret), main, (%argc, %argp);
ld.param.u32 %r1,[%mainret];
st.s32 [%rd0], %r1;
exit;
}

View File

@ -0,0 +1,50 @@
// A wrapper around free to enable a realloc implementation.
// Copyright (C) 2014 Free Software Foundation, Inc.
// This file 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.
// This file 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.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
.version 3.1
.target sm_30
.address_size 64
.extern .func free(.param.u64 %in_ar1);
// BEGIN GLOBAL FUNCTION DEF: __nvptx_free
.visible .func __nvptx_free(.param.u64 %in_ar1)
{
.reg.u64 %ar1;
.reg.u64 %hr10;
.reg.u64 %r23;
.reg.pred %r25;
.reg.u64 %r27;
ld.param.u64 %ar1, [%in_ar1];
mov.u64 %r23, %ar1;
setp.eq.u64 %r25,%r23,0;
@%r25 bra $L1;
add.u64 %r27, %r23, -8;
{
.param.u64 %out_arg0;
st.param.u64 [%out_arg0], %r27;
call free, (%out_arg0);
}
$L1:
ret;
}

View File

@ -0,0 +1,55 @@
// A wrapper around malloc to enable a realloc implementation.
// Copyright (C) 2014 Free Software Foundation, Inc.
// This file 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.
// This file 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.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
.version 3.1
.target sm_30
.address_size 64
.extern .func (.param.u64 %out_retval) malloc(.param.u64 %in_ar1);
// BEGIN GLOBAL FUNCTION DEF: __nvptx_malloc
.visible .func (.param.u64 %out_retval) __nvptx_malloc(.param.u64 %in_ar1)
{
.reg.u64 %ar1;
.reg.u64 %retval;
.reg.u64 %hr10;
.reg.u64 %r26;
.reg.u64 %r28;
.reg.u64 %r29;
.reg.u64 %r31;
ld.param.u64 %ar1, [%in_ar1];
mov.u64 %r26, %ar1;
add.u64 %r28, %r26, 8;
{
.param.u64 %retval_in;
.param.u64 %out_arg0;
st.param.u64 [%out_arg0], %r28;
call (%retval_in), malloc, (%out_arg0);
ld.param.u64 %r29, [%retval_in];
}
st.u64 [%r29], %r26;
add.u64 %r31, %r29, 8;
mov.u64 %retval, %r31;
st.param.u64 [%out_retval], %retval;
ret;
}

View File

@ -0,0 +1,26 @@
/* Declarations for the malloc wrappers.
Copyright (C) 2014 Free Software Foundation, Inc.
This file 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.
This file 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.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
extern void __nvptx_free (void *);
extern void *__nvptx_malloc (size_t);
extern void *__nvptx_realloc (void *, size_t);

View File

@ -0,0 +1,51 @@
/* Implement realloc with the help of the malloc and free wrappers.
Copyright (C) 2014 Free Software Foundation, Inc.
This file 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.
This file 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.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#include <string.h>
#include "nvptx-malloc.h"
void *
__nvptx_realloc (void *ptr, size_t newsz)
{
if (newsz == 0)
{
__nvptx_free (ptr);
return NULL;
}
void *newptr = __nvptx_malloc (newsz);
size_t oldsz;
if (ptr == NULL)
oldsz = 0;
else
{
size_t *sp = __extension__ (size_t *)(ptr - 8);
oldsz = *sp;
}
if (oldsz != 0)
memcpy (newptr, ptr, oldsz > newsz ? newsz : oldsz);
__nvptx_free (ptr);
return newptr;
}

View File

@ -0,0 +1,9 @@
LIB2ADD=$(srcdir)/config/nvptx/malloc.asm \
$(srcdir)/config/nvptx/free.asm \
$(srcdir)/config/nvptx/realloc.c
LIB2ADDEH=
LIB2FUNCS_EXCLUDE=__main
crt0.o: $(srcdir)/config/nvptx/crt0.s
cp $< $@

View File

@ -24,13 +24,15 @@ $(error Unsupported file type: $o)
endif
endif
as_flags-$o := -xassembler$(if $(filter .S,$(suffix $o)),-with-cpp)
$(base)$(objext): $o $(base).vis
$(gcc_compile) -c -xassembler-with-cpp -include $*.vis $<
$(gcc_compile) -c $(as_flags-$<) -include $*.vis $<
$(base).vis: $(base)_s$(objext)
$(gen-hide-list)
$(base)_s$(objext): $o
$(gcc_s_compile) -c -xassembler-with-cpp $<
$(gcc_s_compile) -c $(as_flags-$<) $<
endif

View File

@ -24,13 +24,15 @@ $(error Unsupported file type: $o)
endif
endif
as_flags-$o := -xassembler$(if $(filter .S,$(suffix $o)),-with-cpp)
$(base)$(objext): $o $(base).vis
$(gcc_compile) -c -xassembler-with-cpp -include $*.vis $<
$(gcc_compile) -c $(as_flags-$<) -include $*.vis $<
$(base).vis: $(base)_s$(objext)
$(gen-hide-list)
$(base)_s$(objext): $o
$(gcc_s_compile) -c -xassembler-with-cpp $<
$(gcc_s_compile) -c $(as_flags-$<) $<
endif