1 /* brig-util.h -- gccbrig utility functions
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4 for General Processor Tech.
6 This file is part of GCC.
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
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
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/>. */
22 #ifndef GCC_BRIG_UTIL_H
23 #define GCC_BRIG_UTIL_H
31 #include "coretypes.h"
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)
44 /* Helper class for keeping book of group variable offsets. */
46 class group_variable_offset_index
49 group_variable_offset_index () : m_next_group_offset (0) {}
51 typedef std::map
<std::string
, size_t> varname_offset_table
;
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;
56 size_t size () const { return m_next_group_offset
; }
59 size_t m_next_group_offset
;
60 varname_offset_table m_group_offsets
;
63 bool gccbrig_hsa_opcode_op_output_p (BrigOpcode16_t opcode
, int opnum
);
65 unsigned gccbrig_hsa_type_bit_size (BrigType16_t t
);
67 uint64_t gccbrig_to_uint64_t (const BrigUInt64
&brig_type
);
69 int gccbrig_reg_size (const BrigOperandRegister
*brig_reg
);
71 std::string
gccbrig_reg_name (const BrigOperandRegister
*reg
);
73 std::string
gccbrig_type_name (BrigType16_t type
);
75 std::string
gccbrig_segment_name (BrigSegment8_t segment
);
77 bool gccbrig_is_float_type (BrigType16_t type
);
79 bool gccbrig_is_bit_operation (BrigOpcode16_t opcode
);
81 BrigType16_t
gccbrig_tree_type_to_hsa_type (tree tree_type
);
82 tree
gccbrig_tree_type_for_hsa_type (BrigType16_t brig_type
);
84 bool gccbrig_might_be_host_defined_var_p (const BrigDirectiveVariable
*brigVar
);
87 bool hsa_type_packed_p (BrigType16_t type
);
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
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
;
102 /* key = hsa register entry generated by gccbrig_hsa_reg_id (). */
103 typedef std::map
<size_t, reg_use_info
> regs_use_index
;
105 size_t gccbrig_hsa_reg_id (const BrigOperandRegister
®
);
106 std::string
gccbrig_hsa_reg_name_from_id (size_t reg_hash
);
108 void gccbrig_print_reg_use_info (FILE *dump
, const regs_use_index
&info
);
110 /* Return the number of elements in a VECTOR_TYPE. BRIG does not support
111 variable-length vectors. */
112 inline unsigned HOST_WIDE_INT
113 gccbrig_type_vector_subparts (const_tree type
)
115 return TYPE_VECTOR_SUBPARTS (type
).to_constant ();