1 /* brig-lane-inst-handler.cc -- brig lane instruction handling
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4 for General Processor Tech.
6 This file is part of GCC.
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
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
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/>. */
22 #include "brig-code-entry-handler.h"
24 #include "diagnostic-core.h"
25 #include "brig-util.h"
27 brig_lane_inst_handler::brig_lane_inst_handler (brig_to_generic
&parent
)
28 : brig_code_entry_handler (parent
)
33 brig_lane_inst_handler::operator () (const BrigBase
*base
)
35 const BrigInstLane
&inst
= *(const BrigInstLane
*) base
;
36 tree_stl_vec operands
= build_operands (inst
.base
);
38 tree expr
= NULL_TREE
;
39 if (inst
.base
.opcode
== BRIG_OPCODE_ACTIVELANECOUNT
)
41 /* Because we are fixed to single WI per wave, it's enough to
42 just check the src value of the single work item itself. */
43 expr
= build2 (NE_EXPR
, uint32_type_node
,
44 build_zero_cst (uint32_type_node
), operands
[1]);
46 else if (inst
.base
.opcode
== BRIG_OPCODE_ACTIVELANEID
)
48 expr
= build_zero_cst (uint32_type_node
);
50 else if (inst
.base
.opcode
== BRIG_OPCODE_ACTIVELANEMASK
)
52 tree u64_type
= gccbrig_tree_type_for_hsa_type (BRIG_TYPE_U64
);
53 tree zero_cst
= build_zero_cst (u64_type
);
54 expr
= build2 (NE_EXPR
, u64_type
, zero_cst
, operands
[1]);
56 tree_stl_vec elements
;
57 elements
.push_back (expr
);
58 elements
.push_back (zero_cst
);
59 elements
.push_back (zero_cst
);
60 elements
.push_back (zero_cst
);
62 expr
= m_parent
.m_cf
->pack (elements
);
64 else if (inst
.base
.opcode
== BRIG_OPCODE_ACTIVELANEPERMUTE
)
66 tree src
= operands
[1];
67 tree identity
= operands
[3];
68 tree use_identity
= operands
[4];
70 /* When WAVESIZE is 1, we either select the src of the work-item
71 itself or 'identity' in case use_identity is 1. */
73 tree cmp
= build2 (EQ_EXPR
, uint32_type_node
,
74 build_int_cstu (TREE_TYPE (use_identity
), 1),
77 expr
= build3 (COND_EXPR
, TREE_TYPE (src
), cmp
, identity
, src
);
82 build_output_assignment (inst
.base
, operands
[0], expr
);
84 return base
->byteCount
;