This patch merges the two places were we handle return type emission. In a
similar way to write_one_arg, we now have write_return.
This patch shows that the C++ NRV patch I created some time back is at best
incomplete, because it's not being considered in the prototype emission.
Something that I've been wondering about for a little while.
So, back to figuring out that one now ...
nathan
2015-12-07 Nathan Sidwell <nat...@acm.org>
* config//nvptx/nvptx.c (write_return): New.
(write_fn_proto, nvptx_declare_function_name): Call it.
Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c (revision 231372)
+++ config/nvptx/nvptx.c (working copy)
@@ -452,6 +452,33 @@ write_one_arg (std::stringstream &s, int
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, bo
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,
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,
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]);