From c5006ca75912bdab8256fe4670645d5f1ad54a14 Mon Sep 17 00:00:00 2001 From: marxin Date: Mon, 26 Oct 2015 16:58:26 +0100 Subject: [PATCH 1/9] HSA: fix generation of address that end as SSA_NAME or VAR_DECL. gcc/ChangeLog: 2015-10-22 Martin Liska * hsa-brig.c (emit_function_directives): Emit private variables. * hsa-gen.c (hsa_function_representation::~hsa_function_representation): Release the container. (hsa_function_representation::create_hsa_temporary): New function. (gen_hsa_addr): Handle properly SSA_NAMEs and VAR_DECLs. * hsa.h (hsa_function_representation::m_private_variables): Declare new variable. --- gcc/hsa-brig.c | 7 ++++++- gcc/hsa-gen.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- gcc/hsa.h | 14 ++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c index be7ef59..0c26b58 100644 --- a/gcc/hsa-brig.c +++ b/gcc/hsa-brig.c @@ -626,6 +626,7 @@ emit_function_directives (hsa_function_representation *f, bool is_declaration) if (TREE_CODE ((*iter)->m_decl) == VAR_DECL) count++; count += f->m_spill_symbols.length (); + count += f->m_private_variables.length (); } next_toplev_off = scoped_off + count * sizeof (struct BrigDirectiveVariable); @@ -685,7 +686,11 @@ emit_function_directives (hsa_function_representation *f, bool is_declaration) emit_directive_variable (sym); brig_insn_count++; } - + for (unsigned i = 0; i < f->m_private_variables.length (); i++) + { + emit_directive_variable (f->m_private_variables[i]); + brig_insn_count++; + } } return ptr_to_fndir; diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c index c36c9e0..15f9050 100644 --- a/gcc/hsa-gen.c +++ b/gcc/hsa-gen.c @@ -228,10 +228,10 @@ hsa_function_representation::hsa_function_representation (tree fdecl, bool kernel_p): m_name (NULL), m_input_args_count (0), m_reg_count (0), m_input_args (NULL), m_output_arg (NULL), m_spill_symbols (vNULL), m_readonly_variables (vNULL), - m_called_functions (vNULL), m_hbb_count (0), m_in_ssa (true), - m_kern_p (kernel_p), m_declaration_p (false), m_decl (fdecl), + m_private_variables (vNULL), m_called_functions (vNULL), m_hbb_count (0), + m_in_ssa (true), m_kern_p (kernel_p), m_declaration_p (false), m_decl (fdecl), m_shadow_reg (NULL), m_kernel_dispatch_count (0), m_maximum_omp_data_size (0), - m_seen_error (false) + m_seen_error (false), m_temp_symbol_count (0) { int sym_init_len = (vec_safe_length (cfun->local_decls) / 2) + 1;; m_local_symbols = new hash_table (sym_init_len); @@ -251,6 +251,7 @@ hsa_function_representation::~hsa_function_representation () m_spill_symbols.release (); m_readonly_variables.release (); + m_private_variables.release (); m_called_functions.release (); } @@ -284,6 +285,24 @@ bool hsa_function_representation::has_shadow_reg_p () return m_shadow_reg != NULL; } +void +hsa_function_representation::init_extra_bbs () +{ + hsa_init_new_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun)); + hsa_init_new_bb (EXIT_BLOCK_PTR_FOR_FN (cfun)); +} + +hsa_symbol * +hsa_function_representation::create_hsa_temporary (BrigType16_t type) +{ + hsa_symbol *s = new hsa_symbol (type, BRIG_SEGMENT_PRIVATE, + BRIG_LINKAGE_FUNCTION); + s->m_name_number = m_temp_symbol_count++; + + hsa_cfun->m_private_variables.safe_push (s); + return s; +} + /* Allocate HSA structures that we need only while generating with this. */ static void @@ -1711,6 +1730,13 @@ process_mem_base (tree base, hsa_symbol **symbol, BrigType16_t *addrtype, gcc_unreachable (); } +/* Forward declaration of a function. */ + +static void +gen_hsa_addr_insns (tree val, hsa_op_reg *dest, hsa_bb *hbb, + vec *ssa_map); + + /* Generate HSA address operand for a given tree memory reference REF. If instructions need to be created to calculate the address, they will be added to the end of HBB, SSA_MAP is an array mapping gimple SSA names to HSA @@ -1731,6 +1757,7 @@ gen_hsa_addr (tree ref, hsa_bb *hbb, vec *ssa_map, tree varoffset = NULL_TREE; BrigType16_t addrtype = hsa_get_segment_addr_type (BRIG_SEGMENT_FLAT); HOST_WIDE_INT bitsize = 0, bitpos = 0; + BrigType16_t flat_addrtype = hsa_get_segment_addr_type (BRIG_SEGMENT_FLAT); if (TREE_CODE (ref) == STRING_CST) { @@ -1762,8 +1789,27 @@ gen_hsa_addr (tree ref, hsa_bb *hbb, vec *ssa_map, switch (TREE_CODE (ref)) { case ADDR_EXPR: - gcc_unreachable (); + { + addrtype = hsa_get_segment_addr_type (BRIG_SEGMENT_PRIVATE); + symbol = hsa_cfun->create_hsa_temporary (flat_addrtype); + hsa_op_reg *r = new hsa_op_reg (flat_addrtype); + gen_hsa_addr_insns (ref, r, hbb, ssa_map); + hbb->append_insn (new hsa_insn_mem (BRIG_OPCODE_ST, r->m_type, + r, new hsa_op_address (symbol))); + + break; + } + case SSA_NAME: + { + addrtype = hsa_get_segment_addr_type (BRIG_SEGMENT_PRIVATE); + symbol = hsa_cfun->create_hsa_temporary (flat_addrtype); + hsa_op_reg *r = hsa_reg_for_gimple_ssa (ref, ssa_map); + + hbb->append_insn (new hsa_insn_mem (BRIG_OPCODE_ST, r->m_type, + r, new hsa_op_address (symbol))); + break; + } case PARM_DECL: case VAR_DECL: case RESULT_DECL: @@ -1821,7 +1867,6 @@ gen_hsa_addr (tree ref, hsa_bb *hbb, vec *ssa_map, HSA_SORRY_AT (EXPR_LOCATION (origref), "support for HSA does not implement function pointers"); goto out; - case SSA_NAME: default: HSA_SORRY_ATV (EXPR_LOCATION (origref), "support for HSA does " "not implement memory access to %E", origref); diff --git a/gcc/hsa.h b/gcc/hsa.h index 3c83d61..d38255f 100644 --- a/gcc/hsa.h +++ b/gcc/hsa.h @@ -940,6 +940,14 @@ public: shadow register. */ bool has_shadow_reg_p (); + /* The entry/exit blocks don't contain incoming code, + but the HSA generator might use them to put code into, + so we need hsa_bb instances of them. */ + void init_extra_bbs (); + + /* Create a private symbol of requested TYPE. */ + hsa_symbol *create_hsa_temporary (BrigType16_t type); + /* Name of the function. */ char *m_name; @@ -967,6 +975,9 @@ public: noni-addressable variables with a constructor). */ vec m_readonly_variables; + /* Private function artificial variables. */ + vec m_private_variables; + /* Vector of called function declarations. */ vec m_called_functions; @@ -998,6 +1009,9 @@ public: /* Return true if there's an HSA-specific warning already seen. */ bool m_seen_error; + + /* Counter for temporary symbols created in the function representation. */ + unsigned m_temp_symbol_count; }; enum hsa_function_kind -- 2.6.2