pan/midgard,bifrost: Expand nir_const_load_to_arr
[mesa.git] / src / panfrost / bifrost / compiler_defines.h
1 /*
2 * Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef __compiler_defines_h__
25 #define __compiler_defines_h__
26 #include "bifrost.h"
27 #include "bifrost_compile.h"
28 #include "bifrost_ops.h"
29
30 struct nir_builder;
31
32 typedef struct ssa_args {
33 uint32_t dest;
34 uint32_t src0, src1, src2, src3;
35 } ssa_args;
36
37 /**
38 * @brief Singular unpacked instruction that lives outside of the clause bundle
39 */
40 typedef struct bifrost_instruction {
41 // Must be first
42 struct list_head link;
43
44 /**
45 * @brief Pre-RA arguments
46 */
47 struct ssa_args ssa_args;
48 uint32_t literal_args[4];
49 uint32_t src_modifiers;
50 unsigned op;
51
52
53 /**
54 * @brief Post-RA arguments
55 */
56 struct ssa_args args;
57
58 /**
59 * @brief The number of components that the destination takes up
60 *
61 * This allows the RA to understand when it needs to allocate registers from different classes
62 */
63 unsigned dest_components;
64
65 } bifrost_instruction;
66
67 typedef struct bifrost_clause {
68 struct bifrost_header header;
69
70 /* List of bifrost_instructions emitted for the current clause */
71 struct list_head instructions;
72
73 } bifrost_clause;
74
75 typedef struct bifrost_block {
76 /* Link to next block. Must be first for mir_get_block */
77 struct list_head link;
78
79 /* List of bifrost_instructions emitted for the current block */
80 struct list_head instructions;
81
82 /* List of bifrost clauses to be emitted for the current block*/
83 struct util_dynarray clauses;
84
85 /* Maximum number of successors is 2 */
86 struct bifrost_block *successors[2];
87 uint32_t num_successors;
88
89 } bifrost_block;
90
91 typedef struct compiler_context {
92 nir_shader *nir;
93 gl_shader_stage stage;
94
95 /* Current NIR function */
96 nir_function *func;
97 struct nir_builder *b;
98
99 /* Unordered list of bifrost_blocks */
100 uint32_t block_count;
101 struct list_head blocks;
102
103 /* The current block we are operating on */
104 struct bifrost_block *current_block;
105
106 struct hash_table_u64 *ssa_constants;
107
108 /* Uniform IDs */
109 struct hash_table_u64 *uniform_nir_to_bi;
110 uint32_t uniform_count;
111
112 struct hash_table_u64 *varying_nir_to_bi;
113 uint32_t varying_count;
114
115 struct hash_table_u64 *outputs_nir_to_bi;
116 uint32_t outputs_count;
117
118 /* Count of instructions emitted from NIR overall, across all blocks */
119 uint32_t instruction_count;
120
121 uint32_t mir_temp;
122
123 struct hash_table_u64 *hash_to_temp;
124 uint32_t num_temps;
125
126 uint32_t max_hash;
127
128 } compiler_context;
129
130 #define mir_foreach_block(ctx, v) list_for_each_entry(struct bifrost_block, v, &ctx->blocks, link)
131 #define mir_foreach_block_from(ctx, from, v) list_for_each_entry_from(struct bifrost_block, v, from, &ctx->blocks, link)
132
133 #define mir_last_block(ctx) list_last_entry(&ctx->blocks, struct bifrost_block, link)
134
135 #define mir_foreach_instr(ctx, v) list_for_each_entry(struct bifrost_instruction, v, &ctx->current_block->instructions, link)
136 #define mir_foreach_instr_in_block(block, v) list_for_each_entry(struct bifrost_instruction, v, &block->instructions, link)
137 #define mir_foreach_instr_in_block_from(block, v, from) list_for_each_entry_from(struct bifrost_instruction, v, from, &block->instructions, link)
138 #define mir_foreach_instr_in_block_safe(block, v) list_for_each_entry_safe(struct bifrost_instruction, v, &block->instructions, link)
139 #define mir_last_instr_in_block(block) list_last_entry(&block->instructions, struct bifrost_instruction, link)
140 #define mir_foreach_instr_in_block_from_rev(block, v, from) list_for_each_entry_from_rev(struct bifrost_instruction, v, from, &block->instructions, link)
141
142 #define mir_next_instr(from) list_first_entry(&(from->link), struct bifrost_instruction, link)
143 #define mir_remove_instr(instr) list_del(&instr->link)
144
145 #define mir_insert_instr_before(before, ins) list_addtail(&(mir_alloc_ins(ins))->link, &before->link)
146
147 #define SSA_INVALID_VALUE ~0U
148 #define SSA_TEMP_SHIFT 24
149 #define SSA_FIXED_REGISTER_SHIFT 25
150
151 #define SSA_FIXED_REGISTER(x) ((1U << SSA_FIXED_REGISTER_SHIFT) + (x))
152 #define SSA_REG_FROM_FIXED(x) ((x) & ~(1U << SSA_FIXED_REGISTER_SHIFT))
153
154 #define SSA_FIXED_MINIMUM SSA_FIXED_REGISTER(0)
155 #define SSA_FIXED_UREG_MINIMUM SSA_FIXED_REGISTER(64)
156 #define SSA_FIXED_CONST_0 SSA_FIXED_REGISTER(256 + 64)
157
158 #define SSA_FIXED_UREGISTER(x) (SSA_FIXED_REGISTER(x + 64))
159 #define SSA_UREG_FROM_FIXED(x) (SSA_REG_FROM_FIXED(x) - 64)
160
161 #define SSA_TEMP_VALUE(x) ((1U << SSA_TEMP_SHIFT) + (x))
162 #define SSA_TEMP_FROM_VALUE(x) (((x) & ~(1U << SSA_TEMP_SHIFT)))
163 #define MIR_TEMP_MINIMUM SSA_TEMP_VALUE(0)
164
165 #define SRC_MOD_ABS 1
166 #define SRC_MOD_NEG 2
167 #define MOD_SIZE 2
168 #define SOURCE_MODIFIER(src, mod) (mod << (src * MOD_SIZE))
169
170 struct bifrost_instruction *
171 mir_alloc_ins(struct bifrost_instruction instr);
172
173 #endif