comparison gcc/brig/brigfrontend/brig-util.cc @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* brig-util.cc -- gccbrig utility functions 1 /* brig-util.cc -- gccbrig utility functions
2 Copyright (C) 2016-2017 Free Software Foundation, Inc. 2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com> 3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4 for General Processor Tech. 4 for General Processor Tech.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
24 #include "stdint.h" 24 #include "stdint.h"
25 #include "hsa-brig-format.h" 25 #include "hsa-brig-format.h"
26 #include "brig-util.h" 26 #include "brig-util.h"
27 #include "errors.h" 27 #include "errors.h"
28 #include "diagnostic-core.h" 28 #include "diagnostic-core.h"
29 #include "print-tree.h"
29 30
30 bool 31 bool
31 group_variable_offset_index::has_variable (const std::string &name) const 32 group_variable_offset_index::has_variable (const std::string &name) const
32 { 33 {
33 varname_offset_table::const_iterator i = m_group_offsets.find (name); 34 varname_offset_table::const_iterator i = m_group_offsets.find (name);
471 } 472 }
472 473
473 /* Drop const qualifiers. */ 474 /* Drop const qualifiers. */
474 return tree_type; 475 return tree_type;
475 } 476 }
477
478 /* Calculates numeric identifier for the HSA register REG.
479
480 Returned value is bound to [0, BRIG_2_TREE_HSAIL_TOTAL_REG_COUNT]. */
481
482 size_t
483 gccbrig_hsa_reg_id (const BrigOperandRegister &reg)
484 {
485 size_t offset = reg.regNum;
486 switch (reg.regKind)
487 {
488 case BRIG_REGISTER_KIND_QUAD:
489 offset
490 += BRIG_2_TREE_HSAIL_D_REG_COUNT + BRIG_2_TREE_HSAIL_S_REG_COUNT
491 + BRIG_2_TREE_HSAIL_C_REG_COUNT;
492 break;
493 case BRIG_REGISTER_KIND_DOUBLE:
494 offset += BRIG_2_TREE_HSAIL_S_REG_COUNT + BRIG_2_TREE_HSAIL_C_REG_COUNT;
495 break;
496 case BRIG_REGISTER_KIND_SINGLE:
497 offset += BRIG_2_TREE_HSAIL_C_REG_COUNT;
498 case BRIG_REGISTER_KIND_CONTROL:
499 break;
500 default:
501 gcc_unreachable ();
502 break;
503 }
504 return offset;
505 }
506
507 std::string
508 gccbrig_hsa_reg_name_from_id (size_t reg_id)
509 {
510 char reg_name[32];
511 long unsigned int reg_hash = (long unsigned int) reg_id;
512 if (reg_hash < BRIG_2_TREE_HSAIL_C_REG_COUNT)
513 {
514 sprintf (reg_name, "$c%lu", reg_hash);
515 return reg_name;
516 }
517
518 reg_hash -= BRIG_2_TREE_HSAIL_C_REG_COUNT;
519 if (reg_hash < BRIG_2_TREE_HSAIL_S_REG_COUNT)
520 {
521 sprintf (reg_name, "$s%lu", reg_hash);
522 return reg_name;
523 }
524
525 reg_hash -= BRIG_2_TREE_HSAIL_S_REG_COUNT;
526 if (reg_hash < BRIG_2_TREE_HSAIL_D_REG_COUNT)
527 {
528 sprintf (reg_name, "$d%lu", reg_hash);
529 return reg_name;
530 }
531
532 reg_hash -= BRIG_2_TREE_HSAIL_D_REG_COUNT;
533 if (reg_hash < BRIG_2_TREE_HSAIL_Q_REG_COUNT)
534 {
535 sprintf (reg_name, "$q%lu", reg_hash);
536 return reg_name;
537 }
538
539 gcc_unreachable ();
540 return "$??";
541 }
542
543 /* Prints statistics of register usage to stdout. */
544
545 void
546 gccbrig_print_reg_use_info (FILE *dump, const regs_use_index &info)
547 {
548 regs_use_index::const_iterator begin_it = info.begin ();
549 regs_use_index::const_iterator end_it = info.end ();
550 for (regs_use_index::const_iterator it = begin_it; it != end_it; it++)
551 {
552 std::string hsa_reg = gccbrig_hsa_reg_name_from_id (it->first);
553 printf ("%s:\n", hsa_reg.c_str ());
554 const reg_use_info &info = it->second;
555 typedef std::vector<std::pair<tree, size_t> >::const_iterator reg_use_it;
556 reg_use_it begin_it2 = info.m_type_refs.begin ();
557 reg_use_it end_it2 = info.m_type_refs.end ();
558 for (reg_use_it it2 = begin_it2; it2 != end_it2; it2++)
559 {
560 fprintf (dump, "(%lu) ", (long unsigned int) it2->second);
561 print_node_brief (dump, "", it2->first, 0);
562 fprintf (dump, "\n");
563 }
564 }
565 }