xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/brig/brigfrontend/brig-queue-inst-handler.cc (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1 /* brig-queue-inst-handler.cc -- brig user mode queue related instruction
2    handling
3    Copyright (C) 2016-2020 Free Software Foundation, Inc.
4    Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
5    for General Processor Tech.
6 
7 This file is part of GCC.
8 
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13 
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22 
23 #include <sstream>
24 
25 #include "brig-code-entry-handler.h"
26 #include "brig-util.h"
27 #include "convert.h"
28 #include "tree-pretty-print.h"
29 #include "errors.h"
30 #include "diagnostic-core.h"
31 #include "brig-builtins.h"
32 
brig_queue_inst_handler(brig_to_generic & parent)33 brig_queue_inst_handler::brig_queue_inst_handler (brig_to_generic &parent)
34   : brig_code_entry_handler (parent)
35 {
36 }
37 
38 size_t
operator ()(const BrigBase * base)39 brig_queue_inst_handler::operator () (const BrigBase *base)
40 {
41   const BrigInstBase &inst_base = *(const BrigInstBase *) base;
42 
43   tree_stl_vec operands = build_operands (inst_base);
44 
45   if (inst_base.opcode == BRIG_OPCODE_LDQUEUEWRITEINDEX
46       || inst_base.opcode == BRIG_OPCODE_LDQUEUEREADINDEX)
47     {
48       tree builtin
49 	= inst_base.opcode == BRIG_OPCODE_LDQUEUEWRITEINDEX
50 	? builtin_decl_explicit (BUILT_IN_HSAIL_LDQUEUEWRITEINDEX)
51 	: builtin_decl_explicit (BUILT_IN_HSAIL_LDQUEUEREADINDEX);
52 
53       tree expr
54 	= call_builtin (builtin, 1, uint64_type_node,
55 			uint64_type_node, operands[1]);
56       build_output_assignment (inst_base, operands[0], expr);
57     }
58   else if (inst_base.opcode == BRIG_OPCODE_STQUEUEWRITEINDEX
59 	   || inst_base.opcode == BRIG_OPCODE_STQUEUEREADINDEX)
60     {
61       tree builtin
62 	= inst_base.opcode == BRIG_OPCODE_STQUEUEWRITEINDEX
63 	? builtin_decl_explicit (BUILT_IN_HSAIL_STQUEUEWRITEINDEX)
64 	: builtin_decl_explicit (BUILT_IN_HSAIL_STQUEUEREADINDEX);
65 
66       call_builtin (builtin, 2, void_type_node,
67 		    uint64_type_node, operands[0], uint64_type_node,
68 		    operands[1]);
69     }
70   else if (inst_base.opcode == BRIG_OPCODE_ADDQUEUEWRITEINDEX)
71     {
72       tree builtin = builtin_decl_explicit (BUILT_IN_HSAIL_ADDQUEUEWRITEINDEX);
73 
74       tree expr = call_builtin (builtin, 2,
75 				uint64_type_node, uint64_type_node, operands[1],
76 				uint64_type_node, operands[2]);
77       build_output_assignment (inst_base, operands[0], expr);
78     }
79   else if (inst_base.opcode == BRIG_OPCODE_CASQUEUEWRITEINDEX)
80     {
81       tree builtin = builtin_decl_explicit (BUILT_IN_HSAIL_CASQUEUEWRITEINDEX);
82 
83       tree expr
84 	= call_builtin (builtin, 3, uint64_type_node,
85 			uint64_type_node, operands[1], uint64_type_node,
86 			operands[2], uint64_type_node, operands[3]);
87       build_output_assignment (inst_base, operands[0], expr);
88     }
89   else
90     gcc_unreachable ();
91 
92   return base->byteCount;
93 }
94