annotate gcc/brig/brigfrontend/brig-seg-inst-handler.cc @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* brig-seg-inst-handler.cc -- brig segment related instruction handling
kono
parents:
diff changeset
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
kono
parents:
diff changeset
4 for General Processor Tech.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 This file is part of GCC.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
9 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
10 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
11 version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
16 for more details.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
19 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
20 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 #include <sstream>
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #include "brig-code-entry-handler.h"
kono
parents:
diff changeset
25 #include "brig-util.h"
kono
parents:
diff changeset
26 #include "convert.h"
kono
parents:
diff changeset
27 #include "tree-pretty-print.h"
kono
parents:
diff changeset
28 #include "errors.h"
kono
parents:
diff changeset
29 #include "diagnostic-core.h"
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 brig_seg_inst_handler::brig_seg_inst_handler (brig_to_generic &parent)
kono
parents:
diff changeset
32 : brig_code_entry_handler (parent)
kono
parents:
diff changeset
33 {
kono
parents:
diff changeset
34 }
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 size_t
kono
parents:
diff changeset
37 brig_seg_inst_handler::operator () (const BrigBase *base)
kono
parents:
diff changeset
38 {
kono
parents:
diff changeset
39 const BrigInstBase &inst_base = *(const BrigInstBase *) base;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 std::vector<tree> operands = build_operands (inst_base);
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 tree expr = NULL_TREE;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 if (inst_base.opcode == BRIG_OPCODE_STOF)
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 const BrigInstSegCvt &inst = *(const BrigInstSegCvt *) base;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 if (inst.segment == BRIG_SEGMENT_GROUP)
kono
parents:
diff changeset
50 expr = build2 (PLUS_EXPR, size_type_node,
kono
parents:
diff changeset
51 convert_to_integer (size_type_node,
kono
parents:
diff changeset
52 m_parent.m_cf->m_group_base_arg),
kono
parents:
diff changeset
53 convert_to_integer (size_type_node, operands[1]));
kono
parents:
diff changeset
54 else if (inst.segment == BRIG_SEGMENT_PRIVATE
kono
parents:
diff changeset
55 || inst.segment == BRIG_SEGMENT_SPILL)
kono
parents:
diff changeset
56 expr = build2 (PLUS_EXPR, size_type_node,
kono
parents:
diff changeset
57 convert_to_integer (size_type_node,
kono
parents:
diff changeset
58 m_parent.m_cf->m_private_base_arg),
kono
parents:
diff changeset
59 convert_to_integer (size_type_node, operands[1]));
kono
parents:
diff changeset
60 else
kono
parents:
diff changeset
61 gcc_unreachable ();
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 if (!(inst.modifier & BRIG_SEG_CVT_NONULL))
kono
parents:
diff changeset
64 {
kono
parents:
diff changeset
65 /* Need to convert the null value. -1 is used for 32b segments,
kono
parents:
diff changeset
66 and 0 for flat/global. */
kono
parents:
diff changeset
67 tree cmp
kono
parents:
diff changeset
68 = build2 (EQ_EXPR, uint32_type_node,
kono
parents:
diff changeset
69 build_int_cstu (uint32_type_node, -1), operands[1]);
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 tree null_check = build3 (COND_EXPR, size_type_node, cmp,
kono
parents:
diff changeset
72 build_int_cstu (size_type_node, 0), expr);
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 expr = null_check;
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76 }
kono
parents:
diff changeset
77 else if (inst_base.opcode == BRIG_OPCODE_FTOS)
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 const BrigInstSegCvt &inst = *(const BrigInstSegCvt *) base;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 if (inst.segment == BRIG_SEGMENT_GROUP)
kono
parents:
diff changeset
82 expr = build2 (MINUS_EXPR, size_type_node,
kono
parents:
diff changeset
83 convert_to_integer (size_type_node,
kono
parents:
diff changeset
84 m_parent.m_cf->m_group_base_arg),
kono
parents:
diff changeset
85 convert_to_integer (size_type_node, operands[1]));
kono
parents:
diff changeset
86 else if (inst.segment == BRIG_SEGMENT_PRIVATE)
kono
parents:
diff changeset
87 expr = build2 (MINUS_EXPR, size_type_node,
kono
parents:
diff changeset
88 convert_to_integer (size_type_node,
kono
parents:
diff changeset
89 m_parent.m_cf->m_private_base_arg),
kono
parents:
diff changeset
90 convert_to_integer (size_type_node, operands[1]));
kono
parents:
diff changeset
91 else
kono
parents:
diff changeset
92 gcc_unreachable ();
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 if (!(inst.modifier & BRIG_SEG_CVT_NONULL))
kono
parents:
diff changeset
95 {
kono
parents:
diff changeset
96 /* Need to convert the null value. -1 is used for 32b segments,
kono
parents:
diff changeset
97 and 0 for flat/global. */
kono
parents:
diff changeset
98 tree cmp = build2 (EQ_EXPR, size_type_node,
kono
parents:
diff changeset
99 build_int_cstu (size_type_node, 0), operands[1]);
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 tree null_check
kono
parents:
diff changeset
102 = build3 (COND_EXPR, size_type_node, cmp,
kono
parents:
diff changeset
103 build_int_cstu (uint32_type_node, -1), expr);
kono
parents:
diff changeset
104 expr = null_check;
kono
parents:
diff changeset
105 }
kono
parents:
diff changeset
106 }
kono
parents:
diff changeset
107 else if (inst_base.opcode == BRIG_OPCODE_NULLPTR)
kono
parents:
diff changeset
108 {
kono
parents:
diff changeset
109 const BrigInstSeg &inst = *(const BrigInstSeg *) base;
kono
parents:
diff changeset
110 if (inst.segment == BRIG_SEGMENT_GLOBAL
kono
parents:
diff changeset
111 || inst.segment == BRIG_SEGMENT_FLAT
kono
parents:
diff changeset
112 || inst.segment == BRIG_SEGMENT_READONLY)
kono
parents:
diff changeset
113 expr = build_int_cstu (uint64_type_node, 0);
kono
parents:
diff changeset
114 else
kono
parents:
diff changeset
115 expr = build_int_cstu (uint32_type_node, -1);
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117 else if (inst_base.opcode == BRIG_OPCODE_SEGMENTP)
kono
parents:
diff changeset
118 {
kono
parents:
diff changeset
119 const BrigInstSegCvt &inst = *(const BrigInstSegCvt *) base;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 tree builtin = NULL_TREE;
kono
parents:
diff changeset
122 switch (inst.segment)
kono
parents:
diff changeset
123 {
kono
parents:
diff changeset
124 case BRIG_SEGMENT_GLOBAL:
kono
parents:
diff changeset
125 builtin = builtin_decl_explicit (BUILT_IN_HSAIL_SEGMENTP_GLOBAL);
kono
parents:
diff changeset
126 break;
kono
parents:
diff changeset
127 case BRIG_SEGMENT_GROUP:
kono
parents:
diff changeset
128 builtin = builtin_decl_explicit (BUILT_IN_HSAIL_SEGMENTP_GROUP);
kono
parents:
diff changeset
129 break;
kono
parents:
diff changeset
130 case BRIG_SEGMENT_PRIVATE:
kono
parents:
diff changeset
131 builtin = builtin_decl_explicit (BUILT_IN_HSAIL_SEGMENTP_PRIVATE);
kono
parents:
diff changeset
132 break;
kono
parents:
diff changeset
133 default:
kono
parents:
diff changeset
134 gcc_unreachable ();
kono
parents:
diff changeset
135 }
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 expr = call_builtin (builtin, 2,
kono
parents:
diff changeset
138 uint32_type_node, uint64_type_node, operands[1],
kono
parents:
diff changeset
139 ptr_type_node, m_parent.m_cf->m_context_arg);
kono
parents:
diff changeset
140 }
kono
parents:
diff changeset
141 else
kono
parents:
diff changeset
142 gcc_unreachable ();
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 build_output_assignment (inst_base, operands[0], expr);
kono
parents:
diff changeset
145 return base->byteCount;
kono
parents:
diff changeset
146 }