101e04c3fSmrg/* 201e04c3fSmrg * Copyright © 2010 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_variable_refcount.h 2601e04c3fSmrg * 2701e04c3fSmrg * Provides a visitor which produces a list of variables referenced, 2801e04c3fSmrg * how many times they were referenced and assigned, and whether they 2901e04c3fSmrg * were defined in the scope. 3001e04c3fSmrg */ 3101e04c3fSmrg 3201e04c3fSmrg#ifndef GLSL_IR_VARIABLE_REFCOUNT_H 3301e04c3fSmrg#define GLSL_IR_VARIABLE_REFCOUNT_H 3401e04c3fSmrg 3501e04c3fSmrg#include "ir.h" 3601e04c3fSmrg#include "ir_visitor.h" 3701e04c3fSmrg#include "compiler/glsl_types.h" 3801e04c3fSmrg 3901e04c3fSmrgstruct assignment_entry { 4001e04c3fSmrg exec_node link; 4101e04c3fSmrg ir_assignment *assign; 4201e04c3fSmrg}; 4301e04c3fSmrg 4401e04c3fSmrgclass ir_variable_refcount_entry 4501e04c3fSmrg{ 4601e04c3fSmrgpublic: 4701e04c3fSmrg ir_variable_refcount_entry(ir_variable *var); 4801e04c3fSmrg 4901e04c3fSmrg ir_variable *var; /* The key: the variable's pointer. */ 5001e04c3fSmrg 5101e04c3fSmrg /** 5201e04c3fSmrg * List of assignments to the variable, if any. 5301e04c3fSmrg * This is intended to be used for dead code optimisation and may 5401e04c3fSmrg * not be a complete list. 5501e04c3fSmrg */ 5601e04c3fSmrg exec_list assign_list; 5701e04c3fSmrg 5801e04c3fSmrg /** Number of times the variable is referenced, including assignments. */ 5901e04c3fSmrg unsigned referenced_count; 6001e04c3fSmrg 6101e04c3fSmrg /** Number of times the variable is assigned. */ 6201e04c3fSmrg unsigned assigned_count; 6301e04c3fSmrg 6401e04c3fSmrg bool declaration; /* If the variable had a decl in the instruction stream */ 6501e04c3fSmrg}; 6601e04c3fSmrg 6701e04c3fSmrgclass ir_variable_refcount_visitor : public ir_hierarchical_visitor { 6801e04c3fSmrgpublic: 6901e04c3fSmrg ir_variable_refcount_visitor(void); 7001e04c3fSmrg ~ir_variable_refcount_visitor(void); 7101e04c3fSmrg 7201e04c3fSmrg virtual ir_visitor_status visit(ir_variable *); 7301e04c3fSmrg virtual ir_visitor_status visit(ir_dereference_variable *); 7401e04c3fSmrg 7501e04c3fSmrg virtual ir_visitor_status visit_enter(ir_function_signature *); 7601e04c3fSmrg virtual ir_visitor_status visit_leave(ir_assignment *); 7701e04c3fSmrg 7801e04c3fSmrg /** 7901e04c3fSmrg * Find variable in the hash table, and insert it if not present 8001e04c3fSmrg */ 8101e04c3fSmrg ir_variable_refcount_entry *get_variable_entry(ir_variable *var); 8201e04c3fSmrg 8301e04c3fSmrg /** 8401e04c3fSmrg * Hash table mapping ir_variable to ir_variable_refcount_entry. 8501e04c3fSmrg */ 8601e04c3fSmrg struct hash_table *ht; 8701e04c3fSmrg 8801e04c3fSmrg void *mem_ctx; 8901e04c3fSmrg}; 9001e04c3fSmrg 9101e04c3fSmrg#endif /* GLSL_IR_VARIABLE_REFCOUNT_H */ 92