aboutsummaryrefslogtreecommitdiff
path: root/gcc/brig/brigfrontend/brig-variable-handler.cc
diff options
context:
space:
mode:
authorPekka Jääskeläinen <pekka@parmance.com>2017-01-24 12:45:56 +0000
committerMartin Jambor <jamborm@gcc.gnu.org>2017-01-24 13:45:56 +0100
commit5fd1486ce58297190c2b924e96e716087139a8b5 (patch)
tree80abae8778b2f25cc8bf5960402f20f16e4e7a8c /gcc/brig/brigfrontend/brig-variable-handler.cc
parente1e41b6f10c76dbdc8bfd2d4a345dffefd45968f (diff)
downloadgcc-5fd1486ce58297190c2b924e96e716087139a8b5.zip
gcc-5fd1486ce58297190c2b924e96e716087139a8b5.tar.gz
gcc-5fd1486ce58297190c2b924e96e716087139a8b5.tar.bz2
Brig front-end
2017-01-24 Pekka Jääskeläinen <pekka@parmance.com> Martin Jambor <mjambor@suse.cz> * Makefile.def (target_modules): Added libhsail-rt. (languages): Added language brig. * Makefile.in: Regenerated. * configure.ac (TOPLEVEL_CONFIGURE_ARGUMENTS): Added tgarget-libhsail-rt. Make brig unsupported on untested architectures. * configure: Regenerated. gcc/ * brig-builtins.def: New file. * builtins.def (DEF_HSAIL_BUILTIN): New macro. (DEF_HSAIL_ATOMIC_BUILTIN): Likewise. (DEF_HSAIL_SAT_BUILTIN): Likewise. (DEF_HSAIL_INTR_BUILTIN): Likewise. (DEF_HSAIL_CVT_ZEROI_SAT_BUILTIN): Likewise. * builtin-types.def (BT_INT8): New. (BT_INT16): Likewise. (BT_UINT8): Likewise. (BT_UINT16): Likewise. (BT_FN_ULONG): Likewise. (BT_FN_UINT_INT): Likewise. (BT_FN_UINT_ULONG): Likewise. (BT_FN_UINT_LONG): Likewise. (BT_FN_UINT_PTR): Likewise. (BT_FN_ULONG_PTR): Likewise. (BT_FN_INT8_FLOAT): Likewise. (BT_FN_INT16_FLOAT): Likewise. (BT_FN_UINT32_FLOAT): Likewise. (BT_FN_UINT16_FLOAT): Likewise. (BT_FN_UINT8_FLOAT): Likewise. (BT_FN_UINT64_FLOAT): Likewise. (BT_FN_UINT16_UINT32): Likewise. (BT_FN_UINT32_UINT16): Likewise. (BT_FN_UINT16_UINT16_UINT16): Likewise. (BT_FN_INT_PTR_INT): Likewise. (BT_FN_UINT_PTR_UINT): Likewise. (BT_FN_LONG_PTR_LONG): Likewise. (BT_FN_ULONG_PTR_ULONG): Likewise. (BT_FN_VOID_UINT64_UINT64): Likewise. (BT_FN_UINT8_UINT8_UINT8): Likewise. (BT_FN_INT8_INT8_INT8): Likewise. (BT_FN_INT16_INT16_INT16): Likewise. (BT_FN_INT_INT_INT): Likewise. (BT_FN_UINT_FLOAT_UINT): Likewise. (BT_FN_FLOAT_UINT_UINT): Likewise. (BT_FN_ULONG_UINT_UINT): Likewise. (BT_FN_ULONG_UINT_PTR): Likewise. (BT_FN_ULONG_ULONG_ULONG): Likewise. (BT_FN_UINT_UINT_UINT): Likewise. (BT_FN_VOID_UINT_PTR): Likewise. (BT_FN_UINT_UINT_PTR: Likewise. (BT_FN_UINT32_UINT64_PTR): Likewise. (BT_FN_INT_INT_UINT_UINT): Likewise. (BT_FN_UINT_UINT_UINT_UINT): Likewise. (BT_FN_UINT_UINT_UINT_PTR): Likewise. (BT_FN_UINT_ULONG_ULONG_UINT): Likewise. (BT_FN_ULONG_ULONG_ULONG_ULONG): Likewise. (BT_FN_LONG_LONG_UINT_UINT): Likewise. (BT_FN_ULONG_ULONG_UINT_UINT): Likewise. (BT_FN_VOID_UINT32_UINT64_PTR): Likewise. (BT_FN_VOID_UINT32_UINT32_PTR): Likewise. (BT_FN_UINT_UINT_UINT_UINT_UINT): Likewise. (BT_FN_UINT_FLOAT_FLOAT_FLOAT_FLOAT): Likewise. (BT_FN_ULONG_ULONG_ULONG_UINT_UINT): Likewise. * doc/frontends.texi: List BRIG FE. * doc/install.texi (Testing): Add BRIG tesring requirements. * doc/invoke.texi (Overall Options): Mention BRIG. * doc/standards.texi (Standards): Doucment BRIG HSA version. gcc/brig/ * Make-lang.in: New file. * brig-builtins.h: Likewise. * brig-c.h: Likewise. * brig-lang.c: Likewise. * brigspec.c: Likewise. * config-lang.in: Likewise. * lang-specs.h: Likewise. * lang.opt: Likewise. * brigfrontend/brig-arg-block-handler.cc: Likewise. * brigfrontend/brig-atomic-inst-handler.cc: Likewise. * brigfrontend/brig-basic-inst-handler.cc: Likewise. * brigfrontend/brig-branch-inst-handler.cc: Likewise. * brigfrontend/brig-cmp-inst-handler.cc: Likewise. * brigfrontend/brig-code-entry-handler.cc: Likewise. * brigfrontend/brig-code-entry-handler.h: Likewise. * brigfrontend/brig-comment-handler.cc: Likewise. * brigfrontend/brig-control-handler.cc: Likewise. * brigfrontend/brig-copy-move-inst-handler.cc: Likewise. * brigfrontend/brig-cvt-inst-handler.cc: Likewise. * brigfrontend/brig-fbarrier-handler.cc: Likewise. * brigfrontend/brig-function-handler.cc: Likewise. * brigfrontend/brig-function.cc: Likewise. * brigfrontend/brig-function.h: Likewise. * brigfrontend/brig-inst-mod-handler.cc: Likewise. * brigfrontend/brig-label-handler.cc: Likewise. * brigfrontend/brig-lane-inst-handler.cc: Likewise. * brigfrontend/brig-machine.c: Likewise. * brigfrontend/brig-machine.h: Likewise. * brigfrontend/brig-mem-inst-handler.cc: Likewise. * brigfrontend/brig-module-handler.cc: Likewise. * brigfrontend/brig-queue-inst-handler.cc: Likewise. * brigfrontend/brig-seg-inst-handler.cc: Likewise. * brigfrontend/brig-signal-inst-handler.cc: Likewise. * brigfrontend/brig-to-generic.cc: Likewise. * brigfrontend/brig-to-generic.h: Likewise. * brigfrontend/brig-util.cc: Likewise. * brigfrontend/brig-util.h: Likewise. * brigfrontend/brig-variable-handler.cc: Likewise. * brigfrontend/phsa.h: Likewise. gcc/testsuite/ * lib/brig-dg.exp: New file. * lib/brig.exp: Likewise. * brig.dg/README: Likewise. * brig.dg/dg.exp: Likewise. * brig.dg/test/gimple/alloca.hsail: Likewise. * brig.dg/test/gimple/atomics.hsail: Likewise. * brig.dg/test/gimple/branches.hsail: Likewise. * brig.dg/test/gimple/fbarrier.hsail: Likewise. * brig.dg/test/gimple/function_calls.hsail: Likewise. * brig.dg/test/gimple/kernarg.hsail: Likewise. * brig.dg/test/gimple/mem.hsail: Likewise. * brig.dg/test/gimple/mulhi.hsail: Likewise. * brig.dg/test/gimple/packed.hsail: Likewise. * brig.dg/test/gimple/smoke_test.hsail: Likewise. * brig.dg/test/gimple/variables.hsail: Likewise. * brig.dg/test/gimple/vector.hsail: Likewise. include/ * hsa.h: Moved here from libgomp/plugin/hsa.h. libgomp/ * plugin/hsa.h: Moved to top level include. * plugin/plugin-hsa.c: Chanfgd include of hsa.h accordingly. libhsail-rt/ * Makefile.am: New file. * target-config.h.in: Likewise. * configure.ac: Likewise. * configure: Likewise. * config.h.in: Likewise. * aclocal.m4: Likewise. * README: Likewise. * Makefile.in: Likewise. * include/internal/fibers.h: Likewise. * include/internal/phsa-queue-interface.h: Likewise. * include/internal/phsa-rt.h: Likewise. * include/internal/workitems.h: Likewise. * rt/arithmetic.c: Likewise. * rt/atomics.c: Likewise. * rt/bitstring.c: Likewise. * rt/fbarrier.c: Likewise. * rt/fibers.c: Likewise. * rt/fp16.c: Likewise. * rt/misc.c: Likewise. * rt/multimedia.c: Likewise. * rt/queue.c: Likewise. * rt/sat_arithmetic.c: Likewise. * rt/segment.c: Likewise. * rt/workitems.c: Likewise. Co-Authored-By: Martin Jambor <mjambor@suse.cz> From-SVN: r244867
Diffstat (limited to 'gcc/brig/brigfrontend/brig-variable-handler.cc')
-rw-r--r--gcc/brig/brigfrontend/brig-variable-handler.cc264
1 files changed, 264 insertions, 0 deletions
diff --git a/gcc/brig/brigfrontend/brig-variable-handler.cc b/gcc/brig/brigfrontend/brig-variable-handler.cc
new file mode 100644
index 0000000..b4a8d67
--- /dev/null
+++ b/gcc/brig/brigfrontend/brig-variable-handler.cc
@@ -0,0 +1,264 @@
+/* brig-variable-handler.cc -- brig variable directive handling
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
+ for General Processor Tech.
+
+ 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 "brig-code-entry-handler.h"
+
+#include "stringpool.h"
+#include "errors.h"
+#include "brig-machine.h"
+#include "brig-util.h"
+#include "print-tree.h"
+#include "diagnostic-core.h"
+
+tree
+brig_directive_variable_handler::build_variable
+ (const BrigDirectiveVariable *brigVar, tree_code var_decltype)
+{
+ std::string var_name = m_parent.get_mangled_name (brigVar);
+
+ bool is_definition = brigVar->modifier & BRIG_VARIABLE_DEFINITION;
+
+ tree name_identifier = get_identifier (var_name.c_str ());
+
+ tree var_decl;
+ tree t;
+ if (brigVar->type & BRIG_TYPE_ARRAY)
+ {
+ tree element_type
+ = gccbrig_tree_type_for_hsa_type (brigVar->type & ~BRIG_TYPE_ARRAY);
+ uint64_t element_count = gccbrig_to_uint64_t (brigVar->dim);
+ if (is_definition && element_count == 0)
+ fatal_error (UNKNOWN_LOCATION, "Array definition with zero elements.");
+ if (var_decltype == PARM_DECL)
+ t = build_pointer_type (element_type);
+ else
+ t = build_array_type_nelts (element_type, element_count);
+ }
+ else
+ {
+ t = gccbrig_tree_type_for_hsa_type (brigVar->type);
+ }
+
+ size_t alignment = get_brig_var_alignment (brigVar);
+
+ if (brigVar->segment == BRIG_SEGMENT_READONLY
+ || brigVar->segment == BRIG_SEGMENT_KERNARG
+ || (brigVar->modifier & BRIG_VARIABLE_CONST))
+ TYPE_READONLY (t) = 1;
+
+ TYPE_ADDR_SPACE (t) = gccbrig_get_target_addr_space_id (brigVar->segment);
+
+ var_decl = build_decl (UNKNOWN_LOCATION, var_decltype, name_identifier, t);
+
+ SET_DECL_ALIGN (var_decl, alignment * BITS_PER_UNIT);
+
+ /* Force the HSA alignments. */
+ DECL_USER_ALIGN (var_decl) = 1;
+
+ TREE_USED (var_decl) = 1;
+
+ TREE_PUBLIC (var_decl) = 1;
+ if (is_definition)
+ DECL_EXTERNAL (var_decl) = 0;
+ else
+ DECL_EXTERNAL (var_decl) = 1; /* The definition is elsewhere. */
+
+ if (brigVar->init != 0)
+ {
+ gcc_assert (brigVar->segment == BRIG_SEGMENT_READONLY
+ || brigVar->segment == BRIG_SEGMENT_GLOBAL);
+
+ const BrigBase *cst_operand_data
+ = m_parent.get_brig_operand_entry (brigVar->init);
+
+ tree initializer = NULL_TREE;
+ if (cst_operand_data->kind == BRIG_KIND_OPERAND_CONSTANT_BYTES)
+ initializer = get_tree_cst_for_hsa_operand
+ ((const BrigOperandConstantBytes *) cst_operand_data, t);
+ else
+ error ("variable initializers of type %x not implemented",
+ cst_operand_data->kind);
+ gcc_assert (initializer != NULL_TREE);
+ DECL_INITIAL (var_decl) = initializer;
+ }
+
+ if (var_decltype == PARM_DECL)
+ {
+ DECL_ARG_TYPE (var_decl) = TREE_TYPE (var_decl);
+ DECL_EXTERNAL (var_decl) = 0;
+ TREE_PUBLIC (var_decl) = 0;
+ }
+
+ TREE_ADDRESSABLE (var_decl) = 1;
+
+ TREE_USED (var_decl) = 1;
+ DECL_NONLOCAL (var_decl) = 1;
+ DECL_ARTIFICIAL (var_decl) = 0;
+
+ return var_decl;
+}
+
+size_t
+brig_directive_variable_handler::operator () (const BrigBase *base)
+{
+ const BrigDirectiveVariable *brigVar = (const BrigDirectiveVariable *) base;
+
+ bool is_definition = brigVar->modifier & BRIG_VARIABLE_DEFINITION;
+
+ size_t var_size;
+ tree var_type;
+ if (brigVar->type & BRIG_TYPE_ARRAY)
+ {
+ tree element_type
+ = gccbrig_tree_type_for_hsa_type (brigVar->type & ~BRIG_TYPE_ARRAY);
+ uint64_t element_count = gccbrig_to_uint64_t (brigVar->dim);
+ if (is_definition && element_count == 0)
+ fatal_error (UNKNOWN_LOCATION, "Array definition with zero elements.");
+ var_type = build_array_type_nelts (element_type, element_count);
+ size_t element_size = tree_to_uhwi (TYPE_SIZE (element_type));
+ var_size = element_size * element_count / 8;
+ }
+ else
+ {
+ var_type = gccbrig_tree_type_for_hsa_type (brigVar->type);
+ var_size = tree_to_uhwi (TYPE_SIZE (var_type)) / 8;
+ }
+
+ size_t alignment = get_brig_var_alignment (brigVar);
+
+ if (m_parent.m_cf != NULL)
+ m_parent.m_cf->m_function_scope_vars.insert (base);
+
+ std::string var_name = m_parent.get_mangled_name (brigVar);
+ if (brigVar->segment == BRIG_SEGMENT_KERNARG)
+ {
+ /* Do not create a real variable, but only a table of
+ offsets to the kernarg segment buffer passed as the
+ single argument by the kernel launcher for later
+ reference. Ignore kernel declarations. */
+ if (m_parent.m_cf != NULL && m_parent.m_cf->m_func_decl != NULL_TREE)
+ m_parent.m_cf->append_kernel_arg (brigVar, var_size, alignment);
+ return base->byteCount;
+ }
+ else if (brigVar->segment == BRIG_SEGMENT_GROUP)
+ {
+ /* Handle group region variables similarly as kernargs:
+ assign offsets to the group region on the fly when
+ a new module scope or function scope group variable is
+ introduced. These offsets will be then added to the
+ group_base hidden pointer passed to the kernel in order to
+ get the flat address. */
+ if (!m_parent.has_group_variable (var_name))
+ m_parent.append_group_variable (var_name, var_size, alignment);
+ return base->byteCount;
+ }
+ else if (brigVar->segment == BRIG_SEGMENT_PRIVATE
+ || brigVar->segment == BRIG_SEGMENT_SPILL)
+ {
+ /* Private variables are handled like group variables,
+ except that their offsets are multiplied by the work-item
+ flat id, when accessed. */
+ if (!m_parent.has_private_variable (var_name))
+ m_parent.append_private_variable (var_name, var_size, alignment);
+ return base->byteCount;
+ }
+ else if (brigVar->segment == BRIG_SEGMENT_GLOBAL
+ || brigVar->segment == BRIG_SEGMENT_READONLY)
+ {
+ tree def = is_definition ? NULL_TREE :
+ m_parent.global_variable (var_name);
+
+ if (!is_definition && def != NULL_TREE)
+ {
+ /* We have a definition already for this declaration.
+ Use the definition instead of the declaration. */
+ }
+ else if (gccbrig_might_be_host_defined_var_p (brigVar))
+ {
+ tree var_decl = build_variable (brigVar);
+ m_parent.add_host_def_var_ptr (var_name, var_decl);
+ }
+ else
+ {
+ tree var_decl = build_variable (brigVar);
+ /* Make all global variables program scope for now
+ so we can get their address from the Runtime API. */
+ DECL_CONTEXT (var_decl) = NULL_TREE;
+ TREE_STATIC (var_decl) = 1;
+ m_parent.add_global_variable (var_name, var_decl);
+ }
+ }
+ else if (brigVar->segment == BRIG_SEGMENT_ARG)
+ {
+
+ if (m_parent.m_cf->m_generating_arg_block)
+ {
+ tree var_decl = build_variable (brigVar);
+ tree bind_expr = m_parent.m_cf->m_current_bind_expr;
+
+ DECL_CONTEXT (var_decl) = m_parent.m_cf->m_func_decl;
+ DECL_CHAIN (var_decl) = BIND_EXPR_VARS (bind_expr);
+ BIND_EXPR_VARS (bind_expr) = var_decl;
+ TREE_PUBLIC (var_decl) = 0;
+
+ m_parent.m_cf->add_arg_variable (brigVar, var_decl);
+ }
+ else
+ {
+ /* Must be an incoming function argument which has
+ been parsed in brig-function-handler.cc. No
+ need to generate anything here. */
+ }
+ }
+ else
+ gcc_unreachable ();
+
+ return base->byteCount;
+}
+
+/* Returns the alignment for the given BRIG variable. In case the variable
+ explicitly defines alignment and its larger than the natural alignment,
+ returns it instead of the natural one. */
+
+size_t
+brig_directive_variable_handler::get_brig_var_alignment
+(const BrigDirectiveVariable *brigVar)
+{
+
+ size_t defined_alignment
+ = brigVar->align == BRIG_ALIGNMENT_NONE ? 0 : 1 << (brigVar->align - 1);
+ size_t natural_alignment;
+ if (brigVar->type & BRIG_TYPE_ARRAY)
+ {
+ tree element_type
+ = gccbrig_tree_type_for_hsa_type (brigVar->type & ~BRIG_TYPE_ARRAY);
+ size_t element_size = tree_to_uhwi (TYPE_SIZE (element_type));
+ natural_alignment = element_size / BITS_PER_UNIT;
+ }
+ else
+ {
+ tree t = gccbrig_tree_type_for_hsa_type (brigVar->type);
+ natural_alignment = tree_to_uhwi (TYPE_SIZE (t)) / BITS_PER_UNIT;
+ }
+
+ return natural_alignment > defined_alignment
+ ? natural_alignment : defined_alignment;
+}