2 * Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
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:
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
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
24 #ifndef __compiler_defines_h__
25 #define __compiler_defines_h__
27 #include "bifrost_compile.h"
28 #include "bifrost_ops.h"
32 typedef struct ssa_args
{
34 uint32_t src0
, src1
, src2
, src3
;
38 * @brief Singular unpacked instruction that lives outside of the clause bundle
40 typedef struct bifrost_instruction
{
42 struct list_head link
;
45 * @brief Pre-RA arguments
47 struct ssa_args ssa_args
;
48 uint32_t literal_args
[4];
49 uint32_t src_modifiers
;
54 * @brief Post-RA arguments
59 * @brief The number of components that the destination takes up
61 * This allows the RA to understand when it needs to allocate registers from different classes
63 unsigned dest_components
;
65 } bifrost_instruction
;
67 typedef struct bifrost_clause
{
68 struct bifrost_header header
;
70 /* List of bifrost_instructions emitted for the current clause */
71 struct list_head instructions
;
75 typedef struct bifrost_block
{
76 /* Link to next block. Must be first for mir_get_block */
77 struct list_head link
;
79 /* List of bifrost_instructions emitted for the current block */
80 struct list_head instructions
;
82 /* List of bifrost clauses to be emitted for the current block*/
83 struct util_dynarray clauses
;
85 /* Maximum number of successors is 2 */
86 struct bifrost_block
*successors
[2];
87 uint32_t num_successors
;
91 typedef struct compiler_context
{
93 gl_shader_stage stage
;
95 /* Current NIR function */
97 struct nir_builder
*b
;
99 /* Unordered list of bifrost_blocks */
100 uint32_t block_count
;
101 struct list_head blocks
;
103 /* The current block we are operating on */
104 struct bifrost_block
*current_block
;
106 struct hash_table_u64
*ssa_constants
;
109 struct hash_table_u64
*uniform_nir_to_bi
;
110 uint32_t uniform_count
;
112 struct hash_table_u64
*varying_nir_to_bi
;
113 uint32_t varying_count
;
115 struct hash_table_u64
*outputs_nir_to_bi
;
116 uint32_t outputs_count
;
118 /* Count of instructions emitted from NIR overall, across all blocks */
119 uint32_t instruction_count
;
123 struct hash_table_u64
*hash_to_temp
;
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)
133 #define mir_last_block(ctx) list_last_entry(&ctx->blocks, struct bifrost_block, link)
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)
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)
145 #define mir_insert_instr_before(before, ins) list_addtail(&(mir_alloc_ins(ins))->link, &before->link)
147 #define SSA_INVALID_VALUE ~0U
148 #define SSA_TEMP_SHIFT 24
149 #define SSA_FIXED_REGISTER_SHIFT 25
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))
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)
158 #define SSA_FIXED_UREGISTER(x) (SSA_FIXED_REGISTER(x + 64))
159 #define SSA_UREG_FROM_FIXED(x) (SSA_REG_FROM_FIXED(x) - 64)
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)
165 #define SRC_MOD_ABS 1
166 #define SRC_MOD_NEG 2
168 #define SOURCE_MODIFIER(src, mod) (mod << (src * MOD_SIZE))
170 struct bifrost_instruction
*
171 mir_alloc_ins(struct bifrost_instruction instr
);