101e04c3fSmrg/* 201e04c3fSmrg * Copyright © 2016 Intel Corporation 301e04c3fSmrg * 401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 501e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 601e04c3fSmrg * to deal in the Software without restriction, including without limitation 701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 901e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1001e04c3fSmrg * 1101e04c3fSmrg * The above copyright notice and this permission notice (including the next 1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1301e04c3fSmrg * Software. 1401e04c3fSmrg * 1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2001e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2101e04c3fSmrg * DEALINGS IN THE SOFTWARE. 2201e04c3fSmrg */ 2301e04c3fSmrg 2401e04c3fSmrg/** 2501e04c3fSmrg * \file ir_array_refcount.h 2601e04c3fSmrg * 2701e04c3fSmrg * Provides a visitor which produces a list of variables referenced. 2801e04c3fSmrg */ 2901e04c3fSmrg 3001e04c3fSmrg#ifndef GLSL_IR_ARRAY_REFCOUNT_H 3101e04c3fSmrg#define GLSL_IR_ARRAY_REFCOUNT_H 3201e04c3fSmrg 3301e04c3fSmrg#include "ir.h" 3401e04c3fSmrg#include "ir_visitor.h" 357ec681f3Smrg#include "linker_util.h" 3601e04c3fSmrg#include "compiler/glsl_types.h" 3701e04c3fSmrg#include "util/bitset.h" 3801e04c3fSmrg 3901e04c3fSmrgclass ir_array_refcount_entry 4001e04c3fSmrg{ 4101e04c3fSmrgpublic: 4201e04c3fSmrg ir_array_refcount_entry(ir_variable *var); 4301e04c3fSmrg ~ir_array_refcount_entry(); 4401e04c3fSmrg 4501e04c3fSmrg ir_variable *var; /* The key: the variable's pointer. */ 4601e04c3fSmrg 4701e04c3fSmrg /** Has the variable been referenced? */ 4801e04c3fSmrg bool is_referenced; 4901e04c3fSmrg 507ec681f3Smrg /** Count of nested arrays in the type. */ 517ec681f3Smrg unsigned array_depth; 527ec681f3Smrg 537ec681f3Smrg /** Set of bit-flags to note which array elements have been accessed. */ 547ec681f3Smrg BITSET_WORD *bits; 5501e04c3fSmrg 5601e04c3fSmrg /** Has a linearized array index been referenced? */ 5701e04c3fSmrg bool is_linearized_index_referenced(unsigned linearized_index) const 5801e04c3fSmrg { 5901e04c3fSmrg assert(bits != 0); 6001e04c3fSmrg assert(linearized_index <= num_bits); 6101e04c3fSmrg 6201e04c3fSmrg return BITSET_TEST(bits, linearized_index); 6301e04c3fSmrg } 6401e04c3fSmrg 6501e04c3fSmrgprivate: 6601e04c3fSmrg 6701e04c3fSmrg /** 6801e04c3fSmrg * Total number of bits referenced by \c bits. 6901e04c3fSmrg * 7001e04c3fSmrg * Also the total number of array(s-of-arrays) elements of \c var. 7101e04c3fSmrg */ 7201e04c3fSmrg unsigned num_bits; 7301e04c3fSmrg 7401e04c3fSmrg friend class array_refcount_test; 7501e04c3fSmrg}; 7601e04c3fSmrg 7701e04c3fSmrgclass ir_array_refcount_visitor : public ir_hierarchical_visitor { 7801e04c3fSmrgpublic: 7901e04c3fSmrg ir_array_refcount_visitor(void); 8001e04c3fSmrg ~ir_array_refcount_visitor(void); 8101e04c3fSmrg 8201e04c3fSmrg virtual ir_visitor_status visit(ir_dereference_variable *); 8301e04c3fSmrg 8401e04c3fSmrg virtual ir_visitor_status visit_enter(ir_function_signature *); 8501e04c3fSmrg virtual ir_visitor_status visit_enter(ir_dereference_array *); 8601e04c3fSmrg 8701e04c3fSmrg /** 8801e04c3fSmrg * Find variable in the hash table, and insert it if not present 8901e04c3fSmrg */ 9001e04c3fSmrg ir_array_refcount_entry *get_variable_entry(ir_variable *var); 9101e04c3fSmrg 9201e04c3fSmrg /** 9301e04c3fSmrg * Hash table mapping ir_variable to ir_array_refcount_entry. 9401e04c3fSmrg */ 9501e04c3fSmrg struct hash_table *ht; 9601e04c3fSmrg 9701e04c3fSmrg void *mem_ctx; 9801e04c3fSmrg 9901e04c3fSmrgprivate: 10001e04c3fSmrg /** Get an array_deref_range element from private tracking. */ 10101e04c3fSmrg array_deref_range *get_array_deref(); 10201e04c3fSmrg 10301e04c3fSmrg /** 10401e04c3fSmrg * Last ir_dereference_array that was visited 10501e04c3fSmrg * 10601e04c3fSmrg * Used to prevent some redundant calculations. 10701e04c3fSmrg * 10801e04c3fSmrg * \sa ::visit_enter(ir_dereference_array *) 10901e04c3fSmrg */ 11001e04c3fSmrg ir_dereference_array *last_array_deref; 11101e04c3fSmrg 11201e04c3fSmrg /** 11301e04c3fSmrg * \name array_deref_range tracking 11401e04c3fSmrg */ 11501e04c3fSmrg /*@{*/ 11601e04c3fSmrg /** Currently allocated block of derefs. */ 11701e04c3fSmrg array_deref_range *derefs; 11801e04c3fSmrg 11901e04c3fSmrg /** Number of derefs used in current processing. */ 12001e04c3fSmrg unsigned num_derefs; 12101e04c3fSmrg 12201e04c3fSmrg /** Size of the derefs buffer in bytes. */ 12301e04c3fSmrg unsigned derefs_size; 12401e04c3fSmrg /*@}*/ 12501e04c3fSmrg}; 12601e04c3fSmrg 12701e04c3fSmrg#endif /* GLSL_IR_ARRAY_REFCOUNT_H */ 128