Path: blob/21.2-virgl/src/compiler/glsl/ir_builder.h
4545 views
/*1* Copyright © 2012 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef IR_BUILDER_H24#define IR_BUILDER_H2526#include "ir.h"2728namespace ir_builder {2930#ifndef WRITEMASK_X31enum writemask {32WRITEMASK_X = 0x1,33WRITEMASK_Y = 0x2,34WRITEMASK_Z = 0x4,35WRITEMASK_W = 0x8,36};37#endif3839/**40* This little class exists to let the helper expression generators41* take either an ir_rvalue * or an ir_variable * to be automatically42* dereferenced, while still providing compile-time type checking.43*44* You don't have to explicitly call the constructor -- C++ will see45* that you passed an ir_variable, and silently call the46* operand(ir_variable *var) constructor behind your back.47*/48class operand {49public:50operand(ir_rvalue *val)51: val(val)52{53}5455operand(ir_variable *var)56{57void *mem_ctx = ralloc_parent(var);58val = new(mem_ctx) ir_dereference_variable(var);59}6061ir_rvalue *val;62};6364/** Automatic generator for ir_dereference_variable on assignment LHS.65*66* \sa operand67*/68class deref {69public:70deref(ir_dereference *val)71: val(val)72{73}7475deref(ir_variable *var)76{77void *mem_ctx = ralloc_parent(var);78val = new(mem_ctx) ir_dereference_variable(var);79}808182ir_dereference *val;83};8485class ir_factory {86public:87ir_factory(exec_list *instructions = NULL, void *mem_ctx = NULL)88: instructions(instructions),89mem_ctx(mem_ctx)90{91return;92}9394void emit(ir_instruction *ir);95ir_variable *make_temp(const glsl_type *type, const char *name);9697ir_constant*98constant(float f)99{100return new(mem_ctx) ir_constant(f);101}102103ir_constant*104constant(int i)105{106return new(mem_ctx) ir_constant(i);107}108109ir_constant*110constant(unsigned u)111{112return new(mem_ctx) ir_constant(u);113}114115ir_constant*116constant(bool b)117{118return new(mem_ctx) ir_constant(b);119}120121exec_list *instructions;122void *mem_ctx;123};124125ir_assignment *assign(deref lhs, operand rhs);126ir_assignment *assign(deref lhs, operand rhs, int writemask);127ir_assignment *assign(deref lhs, operand rhs, operand condition);128ir_assignment *assign(deref lhs, operand rhs, operand condition, int writemask);129130ir_return *ret(operand retval);131132ir_expression *expr(ir_expression_operation op, operand a);133ir_expression *expr(ir_expression_operation op, operand a, operand b);134ir_expression *expr(ir_expression_operation op, operand a, operand b, operand c);135ir_expression *add(operand a, operand b);136ir_expression *sub(operand a, operand b);137ir_expression *mul(operand a, operand b);138ir_expression *imul_high(operand a, operand b);139ir_expression *div(operand a, operand b);140ir_expression *carry(operand a, operand b);141ir_expression *borrow(operand a, operand b);142ir_expression *trunc(operand a);143ir_expression *round_even(operand a);144ir_expression *fract(operand a);145ir_expression *dot(operand a, operand b);146ir_expression *clamp(operand a, operand b, operand c);147ir_expression *saturate(operand a);148ir_expression *abs(operand a);149ir_expression *neg(operand a);150ir_expression *sin(operand a);151ir_expression *cos(operand a);152ir_expression *exp(operand a);153ir_expression *rcp(operand a);154ir_expression *rsq(operand a);155ir_expression *sqrt(operand a);156ir_expression *log(operand a);157ir_expression *sign(operand a);158159ir_expression *subr_to_int(operand a);160ir_expression *equal(operand a, operand b);161ir_expression *nequal(operand a, operand b);162ir_expression *less(operand a, operand b);163ir_expression *greater(operand a, operand b);164ir_expression *lequal(operand a, operand b);165ir_expression *gequal(operand a, operand b);166167ir_expression *logic_not(operand a);168ir_expression *logic_and(operand a, operand b);169ir_expression *logic_or(operand a, operand b);170171ir_expression *bit_not(operand a);172ir_expression *bit_or(operand a, operand b);173ir_expression *bit_and(operand a, operand b);174ir_expression *bit_xor(operand a, operand b);175ir_expression *lshift(operand a, operand b);176ir_expression *rshift(operand a, operand b);177178ir_expression *f2i(operand a);179ir_expression *bitcast_f2i(operand a);180ir_expression *i2f(operand a);181ir_expression *bitcast_i2f(operand a);182ir_expression *f2u(operand a);183ir_expression *bitcast_f2u(operand a);184ir_expression *u2f(operand a);185ir_expression *bitcast_u2f(operand a);186ir_expression *i2u(operand a);187ir_expression *u2i(operand a);188ir_expression *b2i(operand a);189ir_expression *i2b(operand a);190ir_expression *f2b(operand a);191ir_expression *b2f(operand a);192193ir_expression *f2d(operand a);194ir_expression *i2d(operand a);195ir_expression *u2d(operand a);196197ir_expression *bitcast_d2i64(operand a);198ir_expression *bitcast_d2u64(operand a);199200ir_expression *bitcast_i642d(operand a);201ir_expression *bitcast_u642d(operand a);202203ir_expression *min2(operand a, operand b);204ir_expression *max2(operand a, operand b);205206ir_expression *interpolate_at_centroid(operand a);207ir_expression *interpolate_at_offset(operand a, operand b);208ir_expression *interpolate_at_sample(operand a, operand b);209210ir_expression *fma(operand a, operand b, operand c);211ir_expression *lrp(operand x, operand y, operand a);212ir_expression *csel(operand a, operand b, operand c);213ir_expression *bitfield_extract(operand a, operand b, operand c);214ir_expression *bitfield_insert(operand a, operand b, operand c, operand d);215216ir_swizzle *swizzle(operand a, int swizzle, int components);217/**218* Swizzle away later components, but preserve the ordering.219*/220ir_swizzle *swizzle_for_size(operand a, unsigned components);221222ir_swizzle *swizzle_xxxx(operand a);223ir_swizzle *swizzle_yyyy(operand a);224ir_swizzle *swizzle_zzzz(operand a);225ir_swizzle *swizzle_wwww(operand a);226ir_swizzle *swizzle_x(operand a);227ir_swizzle *swizzle_y(operand a);228ir_swizzle *swizzle_z(operand a);229ir_swizzle *swizzle_w(operand a);230ir_swizzle *swizzle_xy(operand a);231ir_swizzle *swizzle_xyz(operand a);232ir_swizzle *swizzle_xyzw(operand a);233234ir_if *if_tree(operand condition,235ir_instruction *then_branch);236ir_if *if_tree(operand condition,237ir_instruction *then_branch,238ir_instruction *else_branch);239240} /* namespace ir_builder */241242#endif243244245