xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/brig/brigfrontend/brig-util.h (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1 /* brig-util.h -- gccbrig utility functions
2    Copyright (C) 2016-2020 Free Software Foundation, Inc.
3    Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4    for General Processor Tech.
5 
6 This file is part of GCC.
7 
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
11 version.
12 
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
16 for more details.
17 
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/>.  */
21 
22 #ifndef GCC_BRIG_UTIL_H
23 #define GCC_BRIG_UTIL_H
24 
25 #include <map>
26 #include <vector>
27 
28 #include "config.h"
29 #include "system.h"
30 #include "ansidecl.h"
31 #include "coretypes.h"
32 #include "opts.h"
33 #include "tree.h"
34 
35 /* There are 128 c regs and 2048 s/d/q regs each in the HSAIL.  */
36 #define BRIG_2_TREE_HSAIL_C_REG_COUNT (128)
37 #define BRIG_2_TREE_HSAIL_S_REG_COUNT (2048)
38 #define BRIG_2_TREE_HSAIL_D_REG_COUNT (2048)
39 #define BRIG_2_TREE_HSAIL_Q_REG_COUNT (2048)
40 #define BRIG_2_TREE_HSAIL_TOTAL_REG_COUNT				\
41   (BRIG_2_TREE_HSAIL_C_REG_COUNT + BRIG_2_TREE_HSAIL_S_REG_COUNT	\
42    + BRIG_2_TREE_HSAIL_D_REG_COUNT + BRIG_2_TREE_HSAIL_Q_REG_COUNT)
43 
44 /* Helper class for keeping book of group variable offsets.  */
45 
46 class group_variable_offset_index
47 {
48 public:
group_variable_offset_index()49   group_variable_offset_index () : m_next_group_offset (0) {}
50 
51   typedef std::map<std::string, size_t> varname_offset_table;
52 
53   bool has_variable (const std::string &name) const;
54   void add (const std::string &name, size_t size, size_t alignment);
55   size_t segment_offset (const std::string &name) const;
size()56   size_t size () const { return m_next_group_offset; }
57 
58 private:
59   size_t m_next_group_offset;
60   varname_offset_table m_group_offsets;
61 };
62 
63 bool gccbrig_hsa_opcode_op_output_p (BrigOpcode16_t opcode, int opnum);
64 
65 unsigned gccbrig_hsa_type_bit_size (BrigType16_t t);
66 
67 uint64_t gccbrig_to_uint64_t (const BrigUInt64 &brig_type);
68 
69 int gccbrig_reg_size (const BrigOperandRegister *brig_reg);
70 
71 std::string gccbrig_reg_name (const BrigOperandRegister *reg);
72 
73 std::string gccbrig_type_name (BrigType16_t type);
74 
75 std::string gccbrig_segment_name (BrigSegment8_t segment);
76 
77 bool gccbrig_is_float_type (BrigType16_t type);
78 
79 bool gccbrig_is_bit_operation (BrigOpcode16_t opcode);
80 
81 BrigType16_t gccbrig_tree_type_to_hsa_type (tree tree_type);
82 tree gccbrig_tree_type_for_hsa_type (BrigType16_t brig_type);
83 
84 bool gccbrig_might_be_host_defined_var_p (const BrigDirectiveVariable *brigVar);
85 
86 /* From hsa.h.  */
87 bool hsa_type_packed_p (BrigType16_t type);
88 
89 struct reg_use_info
90 {
91   /* This vector keeps count of the times an HSAIL register is used as
92      a tree type in generic expressions.  The count is used to select
93      type for 'register' variables to reduce emission of
94      VIEW_CONVERT_EXPR nodes.  The data is kept in vector (insertion
95      order) for determinism, in a case there is a tie with the
96      counts.  */
97   std::vector<std::pair<tree, size_t> > m_type_refs;
98   /* Tree to index.  Lookup for the above vector.  */
99   std::map<tree, size_t> m_type_refs_lookup;
100 };
101 
102 /* key = hsa register entry generated by gccbrig_hsa_reg_id ().  */
103 typedef std::map<size_t, reg_use_info> regs_use_index;
104 
105 size_t gccbrig_hsa_reg_id (const BrigOperandRegister &reg);
106 std::string gccbrig_hsa_reg_name_from_id (size_t reg_hash);
107 
108 void gccbrig_print_reg_use_info (FILE *dump, const regs_use_index &info);
109 
110 /* Return the number of elements in a VECTOR_TYPE.  BRIG does not support
111    variable-length vectors.  */
112 inline unsigned HOST_WIDE_INT
gccbrig_type_vector_subparts(const_tree type)113 gccbrig_type_vector_subparts (const_tree type)
114 {
115   return TYPE_VECTOR_SUBPARTS (type).to_constant ();
116 }
117 
118 #endif
119