1 /* brig-copy-move-inst-handler.cc -- brig copy/move instruction handling
2    Copyright (C) 2016-2019 Free Software Foundation, Inc.
3    Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4    for General Processor Tech.
5 
6    This file is part of GCC.
7 
8    GCC is free software; you can redistribute it and/or modify it under
9    the terms of the GNU General Public License as published by the Free
10    Software Foundation; either version 3, or (at your option) any later
11    version.
12 
13    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14    WARRANTY; without even the implied warranty of MERCHANTABILITY or
15    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16    for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with GCC; see the file COPYING3.  If not see
20    <http://www.gnu.org/licenses/>.  */
21 
22 #include "brig-code-entry-handler.h"
23 #include "tree-pretty-print.h"
24 #include "print-tree.h"
25 #include "errors.h"
26 #include "brig-util.h"
27 
28 size_t
handle_lda(const BrigInstBase * brig_inst)29 brig_copy_move_inst_handler::handle_lda (const BrigInstBase *brig_inst)
30 {
31   tree dest_type = gccbrig_tree_type_for_hsa_type (brig_inst->type);
32 
33   tree input = build_tree_operand_from_brig (brig_inst, NULL, 1);
34   tree output = build_tree_operand_from_brig (brig_inst, dest_type, 0);
35 
36   build_output_assignment (*brig_inst, output, input);
37   return brig_inst->base.byteCount;
38 }
39 
40 size_t
operator ()(const BrigBase * base)41 brig_copy_move_inst_handler::operator () (const BrigBase *base)
42 {
43   const BrigInstBase *brig_inst
44     = (const BrigInstBase *) &((const BrigInstBasic *) base)->base;
45 
46   if (brig_inst->opcode == BRIG_OPCODE_LDA)
47     return handle_lda (brig_inst);
48 
49   const BrigInstSourceType *inst_src_type = (const BrigInstSourceType *) base;
50 
51   tree source_type = gccbrig_tree_type_for_hsa_type (inst_src_type->sourceType);
52   tree dest_type = gccbrig_tree_type_for_hsa_type (brig_inst->type);
53 
54   tree input = build_tree_operand_from_brig (brig_inst, source_type, 1);
55   tree output = build_tree_operand_from_brig (brig_inst, dest_type, 0);
56 
57   if (brig_inst->opcode == BRIG_OPCODE_COMBINE)
58     {
59       /* For combine, a simple reinterpret cast from the array constructor
60 	 works.  */
61       tree casted = build_resize_convert_view (TREE_TYPE (output), input);
62       tree assign = build2 (MODIFY_EXPR, TREE_TYPE (output), output, casted);
63       m_parent.m_cf->append_statement (assign);
64     }
65   else if (brig_inst->opcode == BRIG_OPCODE_EXPAND)
66     build_output_assignment (*brig_inst, output, input);
67   else
68     {
69       brig_basic_inst_handler basic (m_parent);
70       return basic (base);
71     }
72   return base->byteCount;
73 }
74