ir_builder.h revision 7e88f8ce8f9d72bbda248554e0630b4aca7e1154
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
537e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholtclass ir_factory {
547e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholtpublic:
557e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt   void emit(ir_instruction *ir);
567e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt
577e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt   exec_list *instructions;
587e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt   void *mem_ctx;
597e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt};
607e88f8ce8f9d72bbda248554e0630b4aca7e1154Eric Anholt
61d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *expr(ir_expression_operation op, operand a, operand b);
62d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *add(operand a, operand b);
63d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *sub(operand a, operand b);
64d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *mul(operand a, operand b);
65d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *dot(operand a, operand b);
66d6e6566206029ace72ba037a3ef7950876eeb88bEric Anholtir_expression *saturate(operand a);
67599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt
68b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xxxx(operand a);
69b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_yyyy(operand a);
70b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_zzzz(operand a);
71b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_wwww(operand a);
72b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_x(operand a);
73b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_y(operand a);
74b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_z(operand a);
75b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_w(operand a);
76b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xy(operand a);
77b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xyz(operand a);
78b782352745d322596a9122969f5c0e57ea032c1bEric Anholtir_swizzle *swizzle_xyzw(operand a);
79b782352745d322596a9122969f5c0e57ea032c1bEric Anholt
80599aac95ff2149d881177ed75a48d97d3dcf47bdEric Anholt} /* namespace ir_builder */
81