From 0beb7c71f1f5c889ea5dba550243fecc9ba82892 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 7 Dec 2015 17:53:09 +0000 Subject: [PATCH] nvptx.c (write_return): New. * config//nvptx/nvptx.c (write_return): New. (write_fn_proto, nvptx_declare_function_name): Call it. From-SVN: r231375 --- gcc/ChangeLog | 5 ++++ gcc/config/nvptx/nvptx.c | 55 ++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d60a6da679c..f843e4be54b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-12-07 Nathan Sidwell + + * config//nvptx/nvptx.c (write_return): New. + (write_fn_proto, nvptx_declare_function_name): Call it. + 2015-12-07 Jan Hubicka PR ipa/61886 diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index 6ce8d4b37d5..5a32adeb53a 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -452,6 +452,33 @@ write_one_arg (std::stringstream &s, int for_reg, int argno, return argno + 1; } +static bool +write_return (std::stringstream &s, bool for_proto, tree type, + machine_mode ret_mode) +{ + machine_mode mode = TYPE_MODE (type); + bool return_in_mem = mode != VOIDmode && !RETURN_IN_REG_P (mode); + + mode = arg_promotion (mode); + if (for_proto) + { + if (!return_in_mem && mode != VOIDmode) + s << "(.param" << nvptx_ptx_type_from_mode (mode, false) + << " %out_retval) "; + } + else + { + /* Prologue. C++11 ABI causes us to return a reference to the + passed in pointer for return_in_mem. */ + ret_mode = arg_promotion (ret_mode); + if (ret_mode != VOIDmode) + s << "\t.reg" << nvptx_ptx_type_from_mode (ret_mode, false) + << " %retval;\n"; + } + + return return_in_mem; +} + /* Look for attributes in ATTRS that would indicate we must write a function as a .entry kernel rather than a .func. Return true if one is found. */ @@ -520,19 +547,7 @@ write_fn_proto (std::stringstream &s, bool is_defn, tree result_type = TREE_TYPE (fntype); /* Declare the result. */ - bool return_in_mem = false; - if (TYPE_MODE (result_type) != VOIDmode) - { - machine_mode mode = TYPE_MODE (result_type); - if (!RETURN_IN_REG_P (mode)) - return_in_mem = true; - else - { - mode = arg_promotion (mode); - s << "(.param" << nvptx_ptx_type_from_mode (mode, false) - << " %out_retval) "; - } - } + bool return_in_mem = write_return (s, true, result_type, VOIDmode); s << name; @@ -725,8 +740,8 @@ nvptx_declare_function_name (FILE *file, const char *name, const_tree decl) write_fn_proto (s, true, name, decl); s << "{\n"; - bool return_in_mem = (TYPE_MODE (result_type) != VOIDmode - && !RETURN_IN_REG_P (TYPE_MODE (result_type))); + bool return_in_mem = write_return (s, false, result_type, + (machine_mode)cfun->machine->ret_reg_mode); if (return_in_mem) argno = write_one_arg (s, 0, argno, ptr_type_node, true); @@ -755,16 +770,6 @@ nvptx_declare_function_name (FILE *file, const char *name, const_tree decl) fprintf (file, "%s", s.str().c_str()); - /* C++11 ABI causes us to return a reference to the passed in - pointer for return_in_mem. */ - if (cfun->machine->ret_reg_mode != VOIDmode) - { - machine_mode mode = arg_promotion - ((machine_mode)cfun->machine->ret_reg_mode); - fprintf (file, "\t.reg%s %%retval;\n", - nvptx_ptx_type_from_mode (mode, false)); - } - fprintf (file, "\t.reg.u%d %s;\n", GET_MODE_BITSIZE (Pmode), reg_names[OUTGOING_STATIC_CHAIN_REGNUM]); -- 2.30.2