hsail_code.hh (11308:7d8836fd043d) hsail_code.hh (12603:ab2cec4483af)
1/*
2 * Copyright (c) 2012-2015 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * For use for simulation and test purposes only
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Author: Steve Reinhardt
34 */
35
36#ifndef __HSAIL_CODE_HH__
37#define __HSAIL_CODE_HH__
38
39#include <cassert>
40#include <list>
41#include <map>
42#include <string>
43#include <vector>
44
45#include "arch/gpu_decoder.hh"
46#include "arch/hsail/Brig.h"
47#include "base/addr_range_map.hh"
48#include "base/intmath.hh"
49#include "config/the_gpu_isa.hh"
50#include "gpu-compute/hsa_code.hh"
51#include "gpu-compute/hsa_kernel_info.hh"
52#include "gpu-compute/misc.hh"
53
54class BrigObject;
55class GPUStaticInst;
56
57inline int
58popcount(uint64_t src, int sz)
59{
60 int cnt = 0;
61
62 for (int i = 0; i < sz; ++i) {
63 if (src & 1)
64 ++cnt;
65 src >>= 1;
66 }
67
68 return cnt;
69}
70
71inline int
72firstbit(uint64_t src, int sz)
73{
74 int i;
75
76 for (i = 0; i < sz; ++i) {
77 if (src & 1)
78 break;
79 src >>= 1;
80 }
81
82 return i;
83}
84
85inline int
86lastbit(uint64_t src, int sz)
87{
88 int i0 = -1;
89
90 for (int i = 0; i < sz; ++i) {
91 if (src & 1)
92 i0 = i;
93 src >>= 1;
94 }
95
96 return i0;
97}
98
99inline int
100signbit(uint64_t src, int sz)
101{
102 int i0 = -1;
103
104 if (src & (1 << (sz - 1))) {
105 for (int i = 0; i < sz - 1; ++i) {
106 if (!(src & 1))
107 i0 = i;
108 src >>= 1;
109 }
110 } else {
111 for (int i = 0; i < sz - 1; ++i) {
112 if (src & 1)
113 i0 = i;
114 src >>= 1;
115 }
116 }
117
118 return i0;
119}
120
121inline uint64_t
122bitrev(uint64_t src, int sz)
123{
124 uint64_t r = 0;
125
126 for (int i = 0; i < sz; ++i) {
127 r <<= 1;
128 if (src & 1)
129 r |= 1;
130 src >>= 1;
131 }
132
133 return r;
134}
135
136inline uint64_t
137mul_hi(uint32_t a, uint32_t b)
138{
139 return ((uint64_t)a * (uint64_t)b) >> 32;
140}
141
142inline uint64_t
143mul_hi(int32_t a, int32_t b)
144{
145 return ((int64_t)a * (int64_t)b) >> 32;
146}
147
148inline uint64_t
149mul_hi(uint64_t a, uint64_t b)
150{
151 return ((uint64_t)a * (uint64_t)b) >> 32;
152}
153
154inline uint64_t
155mul_hi(int64_t a, int64_t b)
156{
157 return ((int64_t)a * (int64_t)b) >> 32;
158}
159
160inline uint64_t
161mul_hi(double a, double b)
162{
163 return 0;
164}
165
166class Label
167{
168 public:
169 std::string name;
170 int value;
171
172 Label() : value(-1)
173 {
174 }
175
176 bool defined() { return value != -1; }
177
178 void
179 checkName(std::string &_name)
180 {
181 if (name.empty()) {
182 name = _name;
183 } else {
184 assert(name == _name);
185 }
186 }
187
188 void
189 define(std::string &_name, int _value)
190 {
191 assert(!defined());
192 assert(_value != -1);
193 value = _value;
194 checkName(_name);
195 }
196
197 int
198 get()
199 {
200 assert(defined());
201 return value;
202 }
203};
204
205class LabelMap
206{
207 std::map<std::string, Label> map;
208
209 public:
210 LabelMap() { }
211
212 void addLabel(const Brig::BrigDirectiveLabel *lbl, int inst_index,
213 const BrigObject *obj);
214
215 Label *refLabel(const Brig::BrigDirectiveLabel *lbl,
216 const BrigObject *obj);
217};
218
219const int NumSegments = Brig::BRIG_SEGMENT_AMD_GCN;
220
221extern const char *segmentNames[];
222
223class StorageElement
224{
225 public:
226 std::string name;
227 uint64_t offset;
228
229 uint64_t size;
230 const Brig::BrigDirectiveVariable *brigSymbol;
231 StorageElement(const char *_name, uint64_t _offset, int _size,
232 const Brig::BrigDirectiveVariable *sym)
233 : name(_name), offset(_offset), size(_size), brigSymbol(sym)
234 {
235 }
236};
237
238class StorageSpace
239{
240 typedef std::map<const Brig::BrigDirectiveVariable*, StorageElement*>
241 DirVarToSE_map;
242
243 std::list<StorageElement*> elements;
244 AddrRangeMap<StorageElement*> elements_by_addr;
245 DirVarToSE_map elements_by_brigptr;
246
247 uint64_t nextOffset;
1/*
2 * Copyright (c) 2012-2015 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * For use for simulation and test purposes only
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Author: Steve Reinhardt
34 */
35
36#ifndef __HSAIL_CODE_HH__
37#define __HSAIL_CODE_HH__
38
39#include <cassert>
40#include <list>
41#include <map>
42#include <string>
43#include <vector>
44
45#include "arch/gpu_decoder.hh"
46#include "arch/hsail/Brig.h"
47#include "base/addr_range_map.hh"
48#include "base/intmath.hh"
49#include "config/the_gpu_isa.hh"
50#include "gpu-compute/hsa_code.hh"
51#include "gpu-compute/hsa_kernel_info.hh"
52#include "gpu-compute/misc.hh"
53
54class BrigObject;
55class GPUStaticInst;
56
57inline int
58popcount(uint64_t src, int sz)
59{
60 int cnt = 0;
61
62 for (int i = 0; i < sz; ++i) {
63 if (src & 1)
64 ++cnt;
65 src >>= 1;
66 }
67
68 return cnt;
69}
70
71inline int
72firstbit(uint64_t src, int sz)
73{
74 int i;
75
76 for (i = 0; i < sz; ++i) {
77 if (src & 1)
78 break;
79 src >>= 1;
80 }
81
82 return i;
83}
84
85inline int
86lastbit(uint64_t src, int sz)
87{
88 int i0 = -1;
89
90 for (int i = 0; i < sz; ++i) {
91 if (src & 1)
92 i0 = i;
93 src >>= 1;
94 }
95
96 return i0;
97}
98
99inline int
100signbit(uint64_t src, int sz)
101{
102 int i0 = -1;
103
104 if (src & (1 << (sz - 1))) {
105 for (int i = 0; i < sz - 1; ++i) {
106 if (!(src & 1))
107 i0 = i;
108 src >>= 1;
109 }
110 } else {
111 for (int i = 0; i < sz - 1; ++i) {
112 if (src & 1)
113 i0 = i;
114 src >>= 1;
115 }
116 }
117
118 return i0;
119}
120
121inline uint64_t
122bitrev(uint64_t src, int sz)
123{
124 uint64_t r = 0;
125
126 for (int i = 0; i < sz; ++i) {
127 r <<= 1;
128 if (src & 1)
129 r |= 1;
130 src >>= 1;
131 }
132
133 return r;
134}
135
136inline uint64_t
137mul_hi(uint32_t a, uint32_t b)
138{
139 return ((uint64_t)a * (uint64_t)b) >> 32;
140}
141
142inline uint64_t
143mul_hi(int32_t a, int32_t b)
144{
145 return ((int64_t)a * (int64_t)b) >> 32;
146}
147
148inline uint64_t
149mul_hi(uint64_t a, uint64_t b)
150{
151 return ((uint64_t)a * (uint64_t)b) >> 32;
152}
153
154inline uint64_t
155mul_hi(int64_t a, int64_t b)
156{
157 return ((int64_t)a * (int64_t)b) >> 32;
158}
159
160inline uint64_t
161mul_hi(double a, double b)
162{
163 return 0;
164}
165
166class Label
167{
168 public:
169 std::string name;
170 int value;
171
172 Label() : value(-1)
173 {
174 }
175
176 bool defined() { return value != -1; }
177
178 void
179 checkName(std::string &_name)
180 {
181 if (name.empty()) {
182 name = _name;
183 } else {
184 assert(name == _name);
185 }
186 }
187
188 void
189 define(std::string &_name, int _value)
190 {
191 assert(!defined());
192 assert(_value != -1);
193 value = _value;
194 checkName(_name);
195 }
196
197 int
198 get()
199 {
200 assert(defined());
201 return value;
202 }
203};
204
205class LabelMap
206{
207 std::map<std::string, Label> map;
208
209 public:
210 LabelMap() { }
211
212 void addLabel(const Brig::BrigDirectiveLabel *lbl, int inst_index,
213 const BrigObject *obj);
214
215 Label *refLabel(const Brig::BrigDirectiveLabel *lbl,
216 const BrigObject *obj);
217};
218
219const int NumSegments = Brig::BRIG_SEGMENT_AMD_GCN;
220
221extern const char *segmentNames[];
222
223class StorageElement
224{
225 public:
226 std::string name;
227 uint64_t offset;
228
229 uint64_t size;
230 const Brig::BrigDirectiveVariable *brigSymbol;
231 StorageElement(const char *_name, uint64_t _offset, int _size,
232 const Brig::BrigDirectiveVariable *sym)
233 : name(_name), offset(_offset), size(_size), brigSymbol(sym)
234 {
235 }
236};
237
238class StorageSpace
239{
240 typedef std::map<const Brig::BrigDirectiveVariable*, StorageElement*>
241 DirVarToSE_map;
242
243 std::list<StorageElement*> elements;
244 AddrRangeMap<StorageElement*> elements_by_addr;
245 DirVarToSE_map elements_by_brigptr;
246
247 uint64_t nextOffset;
248 Brig::BrigSegment segment;
249
250 public:
248
249 public:
251 StorageSpace(Brig::BrigSegment _class)
252 : nextOffset(0), segment(_class)
250 StorageSpace(Brig::BrigSegment _class) : nextOffset(0)
253 {
254 }
255
256 StorageElement *addSymbol(const Brig::BrigDirectiveVariable *sym,
257 const BrigObject *obj);
258
259 StorageElement* findSymbol(std::string name);
260 StorageElement* findSymbol(uint64_t addr);
261 StorageElement* findSymbol(const Brig::BrigDirectiveVariable *brigptr);
262
263 int getSize() { return nextOffset; }
264 void resetOffset() { nextOffset = 0; }
265};
266
267class StorageMap
268{
269 StorageMap *outerScopeMap;
270 StorageSpace *space[NumSegments];
271
272 public:
273 StorageMap(StorageMap *outerScope = nullptr);
274
275 StorageElement *addSymbol(const Brig::BrigDirectiveVariable *sym,
276 const BrigObject *obj);
277
278 StorageElement* findSymbol(Brig::BrigSegment segment, std::string name);
279 StorageElement* findSymbol(Brig::BrigSegment segment, uint64_t addr);
280
281 StorageElement* findSymbol(Brig::BrigSegment segment,
282 const Brig::BrigDirectiveVariable *brigptr);
283
284 // overloaded version to avoid casting
285 StorageElement*
286 findSymbol(Brig::BrigSegment8_t segment, std::string name)
287 {
288 return findSymbol((Brig::BrigSegment)segment, name);
289 }
290
291 int getSize(Brig::BrigSegment segment);
292 void resetOffset(Brig::BrigSegment segment);
293};
294
295typedef enum
296{
297 BT_DEFAULT,
298 BT_B8,
299 BT_U8,
300 BT_U16,
301 BT_U32,
302 BT_U64,
303 BT_S8,
304 BT_S16,
305 BT_S32,
306 BT_S64,
307 BT_F16,
308 BT_F32,
309 BT_F64,
310 BT_NULL
311} base_type_e;
312
313/* @class HsailCode
314 * the HsailCode class is used to store information
315 * about HSA kernels stored in the BRIG format. it holds
316 * all information about a kernel, function, or variable
317 * symbol and provides methods for accessing that
318 * information.
319 */
320
321class HsailCode final : public HsaCode
322{
323 public:
324 TheGpuISA::Decoder decoder;
325
326 StorageMap *storageMap;
327 LabelMap labelMap;
328 uint32_t kernarg_start;
329 uint32_t kernarg_end;
330 int32_t private_size;
331
332 int32_t readonly_size;
333
334 // We track the maximum register index used for each register
335 // class when we load the code so we can size the register files
336 // appropriately (i.e., one more than the max index).
337 uint32_t max_creg; // maximum c-register index
338 uint32_t max_sreg; // maximum s-register index
339 uint32_t max_dreg; // maximum d-register index
340
341 HsailCode(const std::string &name_str,
342 const Brig::BrigDirectiveExecutable *code_dir,
343 const BrigObject *obj,
344 StorageMap *objStorageMap);
345
346 // this version is used to create a placeholder when
347 // we encounter a kernel-related directive before the
348 // kernel itself
349 HsailCode(const std::string &name_str);
350
351 void init(const Brig::BrigDirectiveExecutable *code_dir,
352 const BrigObject *obj, StorageMap *objStorageMap);
353
354 void
355 generateHsaKernelInfo(HsaKernelInfo *hsaKernelInfo) const
356 {
357 hsaKernelInfo->sRegCount = max_sreg + 1;
358 hsaKernelInfo->dRegCount = max_dreg + 1;
359 hsaKernelInfo->cRegCount = max_creg + 1;
360
361 hsaKernelInfo->static_lds_size = getSize(Brig::BRIG_SEGMENT_GROUP);
362
363 hsaKernelInfo->private_mem_size =
364 roundUp(getSize(Brig::BRIG_SEGMENT_PRIVATE), 8);
365
366 hsaKernelInfo->spill_mem_size =
367 roundUp(getSize(Brig::BRIG_SEGMENT_SPILL), 8);
368 }
369
370 int
371 getSize(MemorySegment segment) const
372 {
373 Brig::BrigSegment brigSeg;
374
375 switch (segment) {
376 case MemorySegment::NONE:
377 brigSeg = Brig::BRIG_SEGMENT_NONE;
378 break;
379 case MemorySegment::FLAT:
380 brigSeg = Brig::BRIG_SEGMENT_FLAT;
381 break;
382 case MemorySegment::GLOBAL:
383 brigSeg = Brig::BRIG_SEGMENT_GLOBAL;
384 break;
385 case MemorySegment::READONLY:
386 brigSeg = Brig::BRIG_SEGMENT_READONLY;
387 break;
388 case MemorySegment::KERNARG:
389 brigSeg = Brig::BRIG_SEGMENT_KERNARG;
390 break;
391 case MemorySegment::GROUP:
392 brigSeg = Brig::BRIG_SEGMENT_GROUP;
393 break;
394 case MemorySegment::PRIVATE:
395 brigSeg = Brig::BRIG_SEGMENT_PRIVATE;
396 break;
397 case MemorySegment::SPILL:
398 brigSeg = Brig::BRIG_SEGMENT_SPILL;
399 break;
400 case MemorySegment::ARG:
401 brigSeg = Brig::BRIG_SEGMENT_ARG;
402 break;
403 case MemorySegment::EXTSPACE0:
404 brigSeg = Brig::BRIG_SEGMENT_AMD_GCN;
405 break;
406 default:
407 fatal("Unknown BrigSegment type.\n");
408 }
409
410 return getSize(brigSeg);
411 }
412
413 private:
414 int
415 getSize(Brig::BrigSegment segment) const
416 {
417 if (segment == Brig::BRIG_SEGMENT_PRIVATE) {
418 // with the code generated by new HSA compiler the assertion
419 // does not hold anymore..
420 //assert(private_size != -1);
421 return private_size;
422 } else {
423 return storageMap->getSize(segment);
424 }
425 }
426
427 public:
428 StorageElement*
429 findSymbol(Brig::BrigSegment segment, uint64_t addr)
430 {
431 return storageMap->findSymbol(segment, addr);
432 }
433
434 void
435 setPrivateSize(int32_t _private_size)
436 {
437 private_size = _private_size;
438 }
439
440 Label*
441 refLabel(const Brig::BrigDirectiveLabel *lbl, const BrigObject *obj)
442 {
443 return labelMap.refLabel(lbl, obj);
444 }
445};
446
447#endif // __HSAIL_CODE_HH__
251 {
252 }
253
254 StorageElement *addSymbol(const Brig::BrigDirectiveVariable *sym,
255 const BrigObject *obj);
256
257 StorageElement* findSymbol(std::string name);
258 StorageElement* findSymbol(uint64_t addr);
259 StorageElement* findSymbol(const Brig::BrigDirectiveVariable *brigptr);
260
261 int getSize() { return nextOffset; }
262 void resetOffset() { nextOffset = 0; }
263};
264
265class StorageMap
266{
267 StorageMap *outerScopeMap;
268 StorageSpace *space[NumSegments];
269
270 public:
271 StorageMap(StorageMap *outerScope = nullptr);
272
273 StorageElement *addSymbol(const Brig::BrigDirectiveVariable *sym,
274 const BrigObject *obj);
275
276 StorageElement* findSymbol(Brig::BrigSegment segment, std::string name);
277 StorageElement* findSymbol(Brig::BrigSegment segment, uint64_t addr);
278
279 StorageElement* findSymbol(Brig::BrigSegment segment,
280 const Brig::BrigDirectiveVariable *brigptr);
281
282 // overloaded version to avoid casting
283 StorageElement*
284 findSymbol(Brig::BrigSegment8_t segment, std::string name)
285 {
286 return findSymbol((Brig::BrigSegment)segment, name);
287 }
288
289 int getSize(Brig::BrigSegment segment);
290 void resetOffset(Brig::BrigSegment segment);
291};
292
293typedef enum
294{
295 BT_DEFAULT,
296 BT_B8,
297 BT_U8,
298 BT_U16,
299 BT_U32,
300 BT_U64,
301 BT_S8,
302 BT_S16,
303 BT_S32,
304 BT_S64,
305 BT_F16,
306 BT_F32,
307 BT_F64,
308 BT_NULL
309} base_type_e;
310
311/* @class HsailCode
312 * the HsailCode class is used to store information
313 * about HSA kernels stored in the BRIG format. it holds
314 * all information about a kernel, function, or variable
315 * symbol and provides methods for accessing that
316 * information.
317 */
318
319class HsailCode final : public HsaCode
320{
321 public:
322 TheGpuISA::Decoder decoder;
323
324 StorageMap *storageMap;
325 LabelMap labelMap;
326 uint32_t kernarg_start;
327 uint32_t kernarg_end;
328 int32_t private_size;
329
330 int32_t readonly_size;
331
332 // We track the maximum register index used for each register
333 // class when we load the code so we can size the register files
334 // appropriately (i.e., one more than the max index).
335 uint32_t max_creg; // maximum c-register index
336 uint32_t max_sreg; // maximum s-register index
337 uint32_t max_dreg; // maximum d-register index
338
339 HsailCode(const std::string &name_str,
340 const Brig::BrigDirectiveExecutable *code_dir,
341 const BrigObject *obj,
342 StorageMap *objStorageMap);
343
344 // this version is used to create a placeholder when
345 // we encounter a kernel-related directive before the
346 // kernel itself
347 HsailCode(const std::string &name_str);
348
349 void init(const Brig::BrigDirectiveExecutable *code_dir,
350 const BrigObject *obj, StorageMap *objStorageMap);
351
352 void
353 generateHsaKernelInfo(HsaKernelInfo *hsaKernelInfo) const
354 {
355 hsaKernelInfo->sRegCount = max_sreg + 1;
356 hsaKernelInfo->dRegCount = max_dreg + 1;
357 hsaKernelInfo->cRegCount = max_creg + 1;
358
359 hsaKernelInfo->static_lds_size = getSize(Brig::BRIG_SEGMENT_GROUP);
360
361 hsaKernelInfo->private_mem_size =
362 roundUp(getSize(Brig::BRIG_SEGMENT_PRIVATE), 8);
363
364 hsaKernelInfo->spill_mem_size =
365 roundUp(getSize(Brig::BRIG_SEGMENT_SPILL), 8);
366 }
367
368 int
369 getSize(MemorySegment segment) const
370 {
371 Brig::BrigSegment brigSeg;
372
373 switch (segment) {
374 case MemorySegment::NONE:
375 brigSeg = Brig::BRIG_SEGMENT_NONE;
376 break;
377 case MemorySegment::FLAT:
378 brigSeg = Brig::BRIG_SEGMENT_FLAT;
379 break;
380 case MemorySegment::GLOBAL:
381 brigSeg = Brig::BRIG_SEGMENT_GLOBAL;
382 break;
383 case MemorySegment::READONLY:
384 brigSeg = Brig::BRIG_SEGMENT_READONLY;
385 break;
386 case MemorySegment::KERNARG:
387 brigSeg = Brig::BRIG_SEGMENT_KERNARG;
388 break;
389 case MemorySegment::GROUP:
390 brigSeg = Brig::BRIG_SEGMENT_GROUP;
391 break;
392 case MemorySegment::PRIVATE:
393 brigSeg = Brig::BRIG_SEGMENT_PRIVATE;
394 break;
395 case MemorySegment::SPILL:
396 brigSeg = Brig::BRIG_SEGMENT_SPILL;
397 break;
398 case MemorySegment::ARG:
399 brigSeg = Brig::BRIG_SEGMENT_ARG;
400 break;
401 case MemorySegment::EXTSPACE0:
402 brigSeg = Brig::BRIG_SEGMENT_AMD_GCN;
403 break;
404 default:
405 fatal("Unknown BrigSegment type.\n");
406 }
407
408 return getSize(brigSeg);
409 }
410
411 private:
412 int
413 getSize(Brig::BrigSegment segment) const
414 {
415 if (segment == Brig::BRIG_SEGMENT_PRIVATE) {
416 // with the code generated by new HSA compiler the assertion
417 // does not hold anymore..
418 //assert(private_size != -1);
419 return private_size;
420 } else {
421 return storageMap->getSize(segment);
422 }
423 }
424
425 public:
426 StorageElement*
427 findSymbol(Brig::BrigSegment segment, uint64_t addr)
428 {
429 return storageMap->findSymbol(segment, addr);
430 }
431
432 void
433 setPrivateSize(int32_t _private_size)
434 {
435 private_size = _private_size;
436 }
437
438 Label*
439 refLabel(const Brig::BrigDirectiveLabel *lbl, const BrigObject *obj)
440 {
441 return labelMap.refLabel(lbl, obj);
442 }
443};
444
445#endif // __HSAIL_CODE_HH__