Path: blob/21.2-virgl/src/compiler/glsl/ir_array_refcount.h
4545 views
/*1* Copyright © 2016 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 OTHER20* DEALINGS IN THE SOFTWARE.21*/2223/**24* \file ir_array_refcount.h25*26* Provides a visitor which produces a list of variables referenced.27*/2829#ifndef GLSL_IR_ARRAY_REFCOUNT_H30#define GLSL_IR_ARRAY_REFCOUNT_H3132#include "ir.h"33#include "ir_visitor.h"34#include "linker_util.h"35#include "compiler/glsl_types.h"36#include "util/bitset.h"3738class ir_array_refcount_entry39{40public:41ir_array_refcount_entry(ir_variable *var);42~ir_array_refcount_entry();4344ir_variable *var; /* The key: the variable's pointer. */4546/** Has the variable been referenced? */47bool is_referenced;4849/** Count of nested arrays in the type. */50unsigned array_depth;5152/** Set of bit-flags to note which array elements have been accessed. */53BITSET_WORD *bits;5455/** Has a linearized array index been referenced? */56bool is_linearized_index_referenced(unsigned linearized_index) const57{58assert(bits != 0);59assert(linearized_index <= num_bits);6061return BITSET_TEST(bits, linearized_index);62}6364private:6566/**67* Total number of bits referenced by \c bits.68*69* Also the total number of array(s-of-arrays) elements of \c var.70*/71unsigned num_bits;7273friend class array_refcount_test;74};7576class ir_array_refcount_visitor : public ir_hierarchical_visitor {77public:78ir_array_refcount_visitor(void);79~ir_array_refcount_visitor(void);8081virtual ir_visitor_status visit(ir_dereference_variable *);8283virtual ir_visitor_status visit_enter(ir_function_signature *);84virtual ir_visitor_status visit_enter(ir_dereference_array *);8586/**87* Find variable in the hash table, and insert it if not present88*/89ir_array_refcount_entry *get_variable_entry(ir_variable *var);9091/**92* Hash table mapping ir_variable to ir_array_refcount_entry.93*/94struct hash_table *ht;9596void *mem_ctx;9798private:99/** Get an array_deref_range element from private tracking. */100array_deref_range *get_array_deref();101102/**103* Last ir_dereference_array that was visited104*105* Used to prevent some redundant calculations.106*107* \sa ::visit_enter(ir_dereference_array *)108*/109ir_dereference_array *last_array_deref;110111/**112* \name array_deref_range tracking113*/114/*@{*/115/** Currently allocated block of derefs. */116array_deref_range *derefs;117118/** Number of derefs used in current processing. */119unsigned num_derefs;120121/** Size of the derefs buffer in bytes. */122unsigned derefs_size;123/*@}*/124};125126#endif /* GLSL_IR_ARRAY_REFCOUNT_H */127128129