2 * Copyright © 2012 Intel Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 namespace ir_builder
{
38 * This little class exists to let the helper expression generators
39 * take either an ir_rvalue * or an ir_variable * to be automatically
40 * dereferenced, while still providing compile-time type checking.
42 * You don't have to explicitly call the constructor -- C++ will see
43 * that you passed an ir_variable, and silently call the
44 * operand(ir_variable *var) constructor behind your back.
48 operand(ir_rvalue
*val
)
53 operand(ir_variable
*var
)
55 void *mem_ctx
= ralloc_parent(var
);
56 val
= new(mem_ctx
) ir_dereference_variable(var
);
62 /** Automatic generator for ir_dereference_variable on assignment LHS.
68 deref(ir_dereference
*val
)
73 deref(ir_variable
*var
)
75 void *mem_ctx
= ralloc_parent(var
);
76 val
= new(mem_ctx
) ir_dereference_variable(var
);
92 void emit(ir_instruction
*ir
);
93 ir_variable
*make_temp(const glsl_type
*type
, const char *name
);
98 return new(mem_ctx
) ir_constant(f
);
104 return new(mem_ctx
) ir_constant(i
);
110 return new(mem_ctx
) ir_constant(u
);
116 return new(mem_ctx
) ir_constant(b
);
119 exec_list
*instructions
;
123 ir_assignment
*assign(deref lhs
, operand rhs
);
124 ir_assignment
*assign(deref lhs
, operand rhs
, int writemask
);
126 ir_expression
*expr(ir_expression_operation op
, operand a
);
127 ir_expression
*expr(ir_expression_operation op
, operand a
, operand b
);
128 ir_expression
*add(operand a
, operand b
);
129 ir_expression
*sub(operand a
, operand b
);
130 ir_expression
*mul(operand a
, operand b
);
131 ir_expression
*div(operand a
, operand b
);
132 ir_expression
*round_even(operand a
);
133 ir_expression
*dot(operand a
, operand b
);
134 ir_expression
*clamp(operand a
, operand b
, operand c
);
135 ir_expression
*saturate(operand a
);
137 ir_expression
*equal(operand a
, operand b
);
138 ir_expression
*less(operand a
, operand b
);
139 ir_expression
*greater(operand a
, operand b
);
140 ir_expression
*lequal(operand a
, operand b
);
141 ir_expression
*gequal(operand a
, operand b
);
143 ir_expression
*logic_not(operand a
);
144 ir_expression
*logic_and(operand a
, operand b
);
145 ir_expression
*logic_or(operand a
, operand b
);
147 ir_expression
*bit_not(operand a
);
148 ir_expression
*bit_or(operand a
, operand b
);
149 ir_expression
*bit_and(operand a
, operand b
);
150 ir_expression
*lshift(operand a
, operand b
);
151 ir_expression
*rshift(operand a
, operand b
);
153 ir_expression
*f2i(operand a
);
154 ir_expression
*i2f(operand a
);
155 ir_expression
*f2u(operand a
);
156 ir_expression
*u2f(operand a
);
157 ir_expression
*i2u(operand a
);
158 ir_expression
*u2i(operand a
);
161 * Swizzle away later components, but preserve the ordering.
163 ir_swizzle
*swizzle_for_size(operand a
, unsigned components
);
165 ir_swizzle
*swizzle_xxxx(operand a
);
166 ir_swizzle
*swizzle_yyyy(operand a
);
167 ir_swizzle
*swizzle_zzzz(operand a
);
168 ir_swizzle
*swizzle_wwww(operand a
);
169 ir_swizzle
*swizzle_x(operand a
);
170 ir_swizzle
*swizzle_y(operand a
);
171 ir_swizzle
*swizzle_z(operand a
);
172 ir_swizzle
*swizzle_w(operand a
);
173 ir_swizzle
*swizzle_xy(operand a
);
174 ir_swizzle
*swizzle_xyz(operand a
);
175 ir_swizzle
*swizzle_xyzw(operand a
);
177 ir_if
*if_tree(operand condition
,
178 ir_instruction
*then_branch
);
179 ir_if
*if_tree(operand condition
,
180 ir_instruction
*then_branch
,
181 ir_instruction
*else_branch
);
183 } /* namespace ir_builder */