1599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt/*
2599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * Copyright © 2012 Intel Corporation
3599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt *
4599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
5599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * copy of this software and associated documentation files (the "Software"),
6599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * to deal in the Software without restriction, including without limitation
7599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * and/or sell copies of the Software, and to permit persons to whom the
9599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * Software is furnished to do so, subject to the following conditions:
10599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt *
11599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * The above copyright notice and this permission notice (including the next
12599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * paragraph) shall be included in all copies or substantial portions of the
13599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * Software.
14599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt *
15599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt * IN THE SOFTWARE.
22599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt */
23599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt
24599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt#include "ir.h"
25599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt
26599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholtnamespace ir_builder {
27599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt
28d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt/**
29d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt * This little class exists to let the helper expression generators
30d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt * take either an ir_rvalue * or an ir_variable * to be automatically
31d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt * dereferenced, while still providing compile-time type checking.
32d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt *
33d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt * You don't have to explicitly call the constructor -- C++ will see
34d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt * that you passed an ir_variable, and silently call the
35d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt * operand(ir_variable *var) constructor behind your back.
36d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt */
37d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtclass operand {
38d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtpublic:
39d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt   operand(ir_rvalue *val)
40d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt      : val(val)
41d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt   {
42d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt   }
43d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt
44d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt   operand(ir_variable *var)
45d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt   {
46d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt      void *mem_ctx = ralloc_parent(var);
47d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt      val = new(mem_ctx) ir_dereference_variable(var);
48d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt   }
49d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt
50d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt   ir_rvalue *val;
51d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt};
52d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholt
53d32780d5041a6d241834fe565739104f86300425Eric Anholt/** Automatic generator for ir_dereference_variable on assignment LHS.
54d32780d5041a6d241834fe565739104f86300425Eric Anholt *
55d32780d5041a6d241834fe565739104f86300425Eric Anholt * \sa operand
56d32780d5041a6d241834fe565739104f86300425Eric Anholt */
57d32780d5041a6d241834fe565739104f86300425Eric Anholtclass deref {
58d32780d5041a6d241834fe565739104f86300425Eric Anholtpublic:
59d32780d5041a6d241834fe565739104f86300425Eric Anholt   deref(ir_dereference *val)
60d32780d5041a6d241834fe565739104f86300425Eric Anholt      : val(val)
61d32780d5041a6d241834fe565739104f86300425Eric Anholt   {
62d32780d5041a6d241834fe565739104f86300425Eric Anholt   }
63d32780d5041a6d241834fe565739104f86300425Eric Anholt
64d32780d5041a6d241834fe565739104f86300425Eric Anholt   deref(ir_variable *var)
65d32780d5041a6d241834fe565739104f86300425Eric Anholt   {
66d32780d5041a6d241834fe565739104f86300425Eric Anholt      void *mem_ctx = ralloc_parent(var);
67d32780d5041a6d241834fe565739104f86300425Eric Anholt      val = new(mem_ctx) ir_dereference_variable(var);
68d32780d5041a6d241834fe565739104f86300425Eric Anholt   }
69d32780d5041a6d241834fe565739104f86300425Eric Anholt
70d32780d5041a6d241834fe565739104f86300425Eric Anholt
71d32780d5041a6d241834fe565739104f86300425Eric Anholt   ir_dereference *val;
72d32780d5041a6d241834fe565739104f86300425Eric Anholt};
73d32780d5041a6d241834fe565739104f86300425Eric Anholt
747e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholtclass ir_factory {
757e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholtpublic:
767e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt   void emit(ir_instruction *ir);
778bb0091e6838aeee2a5819850c334fde71b5a439Eric Anholt   ir_variable *make_temp(const glsl_type *type, const char *name);
787e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt
797e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt   exec_list *instructions;
807e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt   void *mem_ctx;
817e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt};
827e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt
83d32780d5041a6d241834fe565739104f86300425Eric Anholtir_assignment *assign(deref lhs, operand rhs);
84d32780d5041a6d241834fe565739104f86300425Eric Anholtir_assignment *assign(deref lhs, operand rhs, int writemask);
85d32780d5041a6d241834fe565739104f86300425Eric Anholt
860bb3d4ba54f98f4d45abe598dabc905f08055cd5Kenneth Graunkeir_expression *expr(ir_expression_operation op, operand a);
87d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *expr(ir_expression_operation op, operand a, operand b);
88d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *add(operand a, operand b);
89d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *sub(operand a, operand b);
90d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *mul(operand a, operand b);
91d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *dot(operand a, operand b);
92d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *saturate(operand a);
93599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt
94d9da350a8334201400a43d105b92fce2bd6a5f32Kenneth Graunke/**
95d9da350a8334201400a43d105b92fce2bd6a5f32Kenneth Graunke * Swizzle away later components, but preserve the ordering.
96d9da350a8334201400a43d105b92fce2bd6a5f32Kenneth Graunke */
97d9da350a8334201400a43d105b92fce2bd6a5f32Kenneth Graunkeir_swizzle *swizzle_for_size(operand a, int components);
98d9da350a8334201400a43d105b92fce2bd6a5f32Kenneth Graunke
99b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xxxx(operand a);
100b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_yyyy(operand a);
101b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_zzzz(operand a);
102b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_wwww(operand a);
103b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_x(operand a);
104b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_y(operand a);
105b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_z(operand a);
106b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_w(operand a);
107b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xy(operand a);
108b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xyz(operand a);
109b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xyzw(operand a);
110b782352745d322596a9122969f5c0e57ea032c1bEric Anholt
111599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt} /* namespace ir_builder */
112