Skip to content

Commit 8adb295

Browse files
committed
Test with indirect returns
1 parent 8cdf7b8 commit 8adb295

File tree

9 files changed

+235
-20
lines changed

9 files changed

+235
-20
lines changed

gcc/calls.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3. If not see
6161
#include "value-query.h"
6262
#include "tree-pretty-print.h"
6363
#include "tree-eh.h"
64+
#include "print-tree.h"
6465

6566
/* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
6667
#define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
@@ -1338,6 +1339,8 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
13381339
CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far);
13391340
location_t loc = EXPR_LOCATION (exp);
13401341

1342+
//debug_tree (exp);
1343+
13411344
/* Count arg position in order args appear. */
13421345
int argpos;
13431346

@@ -2897,6 +2900,13 @@ expand_call (tree exp, rtx target, int ignore)
28972900
structure_value_addr = XEXP (target, 0);
28982901
else
28992902
{
2903+
fprintf (stderr, "HERE: %d %p, %d, %d\n", CALL_EXPR_RETURN_SLOT_OPT (exp),
2904+
target, MEM_P (target),
2905+
(TREE_ADDRESSABLE (rettype)
2906+
|| !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
2907+
&& targetm.slow_unaligned_access (TYPE_MODE (rettype),
2908+
MEM_ALIGN (target)))));
2909+
debug_rtx (target);
29002910
/* For variable-sized objects, we must be called with a target
29012911
specified. If we were to allocate space on the stack here,
29022912
we would have no way of knowing when to free it. */

gcc/function.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ along with GCC; see the file COPYING3. If not see
8585
#include "value-range.h"
8686
#include "gimple-range.h"
8787
#include "insn-attr.h"
88+
#include "print-tree.h"
8889

8990
/* So we can assign to cfun in this file. */
9091
#undef cfun
@@ -987,6 +988,9 @@ assign_temp (tree type_or_decl, int memory_required,
987988

988989
/* Allocating temporaries of TREE_ADDRESSABLE type must be done in the front
989990
end. See also create_tmp_var for the gimplification-time check. */
991+
//fprintf (stderr, "1\n");
992+
/*debug_tree (type_or_decl);
993+
debug_tree (type);*/
990994
gcc_assert (!TREE_ADDRESSABLE (type) && COMPLETE_TYPE_P (type));
991995

992996
if (mode == BLKmode || memory_required)

gcc/jit/jit-playback.cc

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,19 @@ new_compound_type (location *loc,
467467

468468
if (is_packed)
469469
TYPE_PACKED (t) = 1;
470-
if (is_addressable) TREE_ADDRESSABLE(t) = 1;
470+
471+
//gcc_assert (!is_addressable);
472+
if (is_addressable)
473+
{
474+
TREE_ADDRESSABLE(t) = 1;
475+
/*if (TREE_CODE (t) == COMPOUND_LITERAL_EXPR)
476+
{
477+
fprintf (stderr, "Is compound literal\n");
478+
TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t)) = 1;
479+
}
480+
else
481+
fprintf (stderr, "Is NOT compound literal\n");*/
482+
}
471483
if (loc)
472484
set_tree_location (t, loc);
473485

@@ -653,24 +665,32 @@ new_function (location *loc,
653665
const std::vector<std::pair<gcc_jit_fn_attribute,
654666
std::vector<int>>>
655667
&int_array_attributes,
656-
bool is_target_builtin)
668+
bool is_target_builtin,
669+
bool is_indirect_return)
657670
{
658671
int i;
659672
param *param;
660673

661674
//can return_type be NULL?
662675
gcc_assert (name);
663676

677+
tree func_return_type = return_type->as_tree ();
678+
if (is_indirect_return)
679+
{
680+
func_return_type = build_variant_type_copy (func_return_type);
681+
TREE_ADDRESSABLE (func_return_type) = 1;
682+
}
683+
664684
tree *arg_types = (tree *)xcalloc(params->length (), sizeof(tree*));
665685
FOR_EACH_VEC_ELT (*params, i, param)
666686
arg_types[i] = TREE_TYPE (param->as_tree ());
667687

668688
tree fn_type;
669689
if (is_variadic)
670-
fn_type = build_varargs_function_type_array (return_type->as_tree (),
690+
fn_type = build_varargs_function_type_array (func_return_type,
671691
params->length (), arg_types);
672692
else
673-
fn_type = build_function_type_array (return_type->as_tree (),
693+
fn_type = build_function_type_array (func_return_type,
674694
params->length (), arg_types);
675695
free (arg_types);
676696

@@ -682,7 +702,7 @@ new_function (location *loc,
682702
set_tree_location (fndecl, loc);
683703

684704
tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL,
685-
NULL_TREE, return_type->as_tree ());
705+
NULL_TREE, func_return_type);
686706
DECL_ARTIFICIAL (resdecl) = 1;
687707
DECL_IGNORED_P (resdecl) = 1;
688708
DECL_RESULT (fndecl) = resdecl;
@@ -1593,7 +1613,17 @@ build_call (location *loc,
15931613
vec<tree, va_gc> *tree_args;
15941614
vec_alloc (tree_args, args->length ());
15951615
for (unsigned i = 0; i < args->length (); i++)
1616+
{
1617+
if (TREE_ADDRESSABLE (TREE_TYPE ((*args)[i]->as_tree ())))
1618+
{
1619+
fprintf (stderr, "Function:\n");
1620+
debug_tree (fn_ptr);
1621+
fprintf (stderr, "Argument:\n");
1622+
debug_tree ((*args)[i]->as_tree ());
1623+
abort ();
1624+
}
15961625
tree_args->quick_push ((*args)[i]->as_tree ());
1626+
}
15971627

15981628
if (loc)
15991629
set_tree_location (fn_ptr, loc);
@@ -1604,6 +1634,11 @@ build_call (location *loc,
16041634

16051635
tree call = build_call_vec (return_type,
16061636
fn_ptr, tree_args);
1637+
if (TREE_ADDRESSABLE (return_type))
1638+
{
1639+
CALL_EXPR_RETURN_SLOT_OPT (call) = true;
1640+
//fprintf (stderr, "Setting return slot opt\n");
1641+
}
16071642

16081643
if (require_tail_call)
16091644
CALL_EXPR_MUST_TAIL_CALL (call) = 1;
@@ -2052,6 +2087,18 @@ get_aligned (size_t alignment_in_bytes) const
20522087
return new type (t_new_type);
20532088
}
20542089

2090+
/* Construct a playback::type instance (wrapping a tree)
2091+
with TREE_ADDRESSABLE set. */
2092+
2093+
playback::type *
2094+
playback::type::
2095+
get_addressable () const
2096+
{
2097+
tree t_new_type = build_variant_type_copy (m_inner);
2098+
TREE_ADDRESSABLE (t_new_type) = 1;
2099+
return new type (t_new_type);
2100+
}
2101+
20552102
/* Construct a playback::type instance (wrapping a tree)
20562103
for the given vector type. */
20572104

@@ -2120,6 +2167,8 @@ dereference (location *loc)
21202167
{
21212168
tree ptr = as_tree ();
21222169
tree datum = get_context ()->new_dereference (ptr, loc);
2170+
/*fprintf (stderr, "ptr: %p\n", ptr);
2171+
fprintf (stderr, "deref: %p\n", datum);*/
21232172
return new lvalue (get_context (), datum);
21242173
}
21252174

@@ -2294,12 +2343,13 @@ new_local (location *loc,
22942343
type->as_tree ());
22952344
else
22962345
{
2297-
inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
2346+
inner = create_tmp_var (type->as_tree (), "JITTMP");
2347+
/*inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
22982348
create_tmp_var_name ("JITTMP"),
22992349
type->as_tree ());
23002350
DECL_ARTIFICIAL (inner) = 1;
23012351
DECL_IGNORED_P (inner) = 1;
2302-
DECL_NAMELESS (inner) = 1;
2352+
DECL_NAMELESS (inner) = 1;*/
23032353
}
23042354
DECL_CONTEXT (inner) = this->m_inner_fndecl;
23052355

gcc/jit/jit-playback.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see
2727

2828
#include "timevar.h"
2929
#include "varasm.h"
30+
#include "print-tree.h"
3031

3132
#include "jit-recording.h"
3233
#include "jit-target.h"
@@ -132,7 +133,8 @@ class context : public log_user
132133
const std::vector<std::pair<gcc_jit_fn_attribute,
133134
std::vector<int>>>
134135
&int_array_attributes,
135-
bool is_target_builtin);
136+
bool is_target_builtin,
137+
bool is_indirect_return);
136138

137139
lvalue *
138140
new_global (location *loc,
@@ -542,6 +544,7 @@ class type : public wrapper
542544
}
543545

544546
type *get_aligned (size_t alignment_in_bytes) const;
547+
type *get_addressable () const;
545548
type *get_vector (size_t num_units) const;
546549

547550
private:

gcc/jit/jit-recording.cc

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,16 @@ recording::context::new_call (recording::location *loc,
14091409
int numargs , recording::rvalue **args)
14101410
{
14111411
recording::rvalue *result = new call (this, loc, func, numargs, args);
1412+
/*for (int i = 0 ; i < numargs ; i++)
1413+
{
1414+
type* type = args[i]->get_type ();
1415+
if (args[i]->is_addressable () || type->is_addressable ())
1416+
{
1417+
fprintf (stderr, "Function: %s\n", func->get_name ()->c_str ());
1418+
fprintf (stderr, "Argument: %s\n", args[i]->get_debug_string ());
1419+
abort ();
1420+
}
1421+
}*/
14121422
record (result);
14131423
return result;
14141424
}
@@ -2596,6 +2606,15 @@ recording::type::get_aligned (size_t alignment_in_bytes)
25962606
return result;
25972607
}
25982608

2609+
recording::type *
2610+
recording::type::get_addressable ()
2611+
{
2612+
recording::type *result
2613+
= new memento_of_get_addressable (this);
2614+
m_ctxt->record_type (result);
2615+
return result;
2616+
}
2617+
25992618
void
26002619
recording::type::set_packed ()
26012620
{
@@ -3427,6 +3446,43 @@ recording::memento_of_get_aligned::write_reproducer (reproducer &r)
34273446
m_alignment_in_bytes);
34283447
}
34293448

3449+
/* The implementation of class gcc::jit::recording::memento_of_get_addressable. */
3450+
3451+
/* Implementation of pure virtual hook recording::memento::replay_into
3452+
for recording::memento_of_get_addressable. */
3453+
3454+
void
3455+
recording::memento_of_get_addressable::replay_into (replayer *)
3456+
{
3457+
set_playback_obj
3458+
(m_other_type->playback_type ()->get_addressable ());
3459+
}
3460+
3461+
/* Implementation of recording::memento::make_debug_string for
3462+
results of get_addressable. */
3463+
3464+
recording::string *
3465+
recording::memento_of_get_addressable::make_debug_string ()
3466+
{
3467+
return string::from_printf (m_ctxt,
3468+
"%s adressable",
3469+
m_other_type->get_debug_string ());
3470+
}
3471+
3472+
/* Implementation of recording::memento::write_reproducer for addressable
3473+
types. */
3474+
3475+
void
3476+
recording::memento_of_get_addressable::write_reproducer (reproducer &r)
3477+
{
3478+
const char *id = r.make_identifier (this, "type");
3479+
r.write (" gcc_jit_type *%s =\n"
3480+
" gcc_jit_type_get_addressable (%s);\n",
3481+
id,
3482+
r.get_identifier_as_type (m_other_type));
3483+
}
3484+
3485+
34303486
/* The implementation of class gcc::jit::recording::vector_type. */
34313487

34323488
/* Implementation of pure virtual hook recording::memento::replay_into
@@ -4164,6 +4220,10 @@ recording::rvalue::dereference_field (recording::location *loc,
41644220
recording::lvalue *
41654221
recording::rvalue::dereference (recording::location *loc)
41664222
{
4223+
if (this->get_type ()->dereference ()->is_addressable ())
4224+
{
4225+
abort();
4226+
}
41674227
recording::lvalue *result =
41684228
new dereference_rvalue (m_ctxt, loc, this);
41694229
m_ctxt->record (result);
@@ -4515,7 +4575,8 @@ recording::function::function (context *ctxt,
45154575
m_attributes (),
45164576
m_string_attributes (),
45174577
m_int_array_attributes (),
4518-
m_is_target_builtin (is_target_builtin)
4578+
m_is_target_builtin (is_target_builtin),
4579+
m_indirect_return (false)
45194580
{
45204581
for (int i = 0; i< num_params; i++)
45214582
{
@@ -4578,7 +4639,8 @@ recording::function::replay_into (replayer *r)
45784639
m_attributes,
45794640
m_string_attributes,
45804641
m_int_array_attributes,
4581-
m_is_target_builtin));
4642+
m_is_target_builtin,
4643+
m_indirect_return));
45824644
}
45834645

45844646
/* Implementation of recording::memento::make_debug_string for
@@ -7628,7 +7690,7 @@ recording::statement::write_to_dump (dump &d)
76287690
for recording::memento_of_set_personality_function. */
76297691

76307692
void
7631-
recording::memento_of_set_personality_function::replay_into (replayer *r)
7693+
recording::memento_of_set_personality_function::replay_into (replayer * ARG_UNUSED (r))
76327694
{
76337695
m_function->playback_function ()->set_personality_function (m_personality_function->playback_function ());
76347696
}

0 commit comments

Comments
 (0)