1 /* 2 * Copyright © 2017 Gert Wollny 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef MESA_GLSL_TO_TGSI_TEMPRENAME_H 25 #define MESA_GLSL_TO_TGSI_TEMPRENAME_H 26 27 #include "st_glsl_to_tgsi_array_merge.h" 28 29 /** Storage to record the required live range of a temporary register 30 * begin == end == -1 indicates that the register can be reused without 31 * limitations. Otherwise, "begin" indicates the first instruction in which 32 * a write operation may target this temporary, and end indicates the 33 * last instruction in which a value can be read from this temporary. 34 * Hence, a register R2 can be merged with a register R1 if R1.end <= R2.begin. 35 */ 36 struct register_live_range { 37 int begin; 38 int end; 39 }; 40 41 /** Evaluates the required live ranges of temporary registers in a shader. 42 * The live range estimation can only be run sucessfully if the shader doesn't 43 * call a subroutine. 44 * @param[in] mem_ctx a memory context that can be used with the ralloc_* 45 * functions 46 * @param[in] instructions the shader to be anlzyed 47 * @param[in] ntemps number of temporaries reserved for this shader 48 * @param[in,out] reg_live_ranges memory location to store the estimated 49 * required live ranges for each temporary register. The parameter must 50 * point to allocated memory that can hold ntemps register_live_range 51 * structures. On output the live ranges contains the live ranges for 52 * the registers with the exception of TEMP[0] 53 * @param[in] narrays number of array sreserved for this shader 54 * @param[in,out] arr_live_ranges memory location to store the estimated required 55 * live ranges for each array. The parameter must point to allocated memory 56 * that can hold narrays array_live_range structures. On output the live 57 * ranges contains the live ranges for the registers with the exception of 58 * ARRAY[0]. 59 * @returns: true if the lifetimes were estimated, false if not (i.e. if a 60 * subroutine was called). 61 */ 62 bool 63 get_temp_registers_required_live_ranges(void *mem_ctx, exec_list *instructions, 64 int ntemps, struct register_live_range *register_live_ranges, 65 int narrays, array_live_range *array_live_ranges); 66 67 /** Estimate the merge remapping of the registers. 68 * @param[in] mem_ctx a memory context that can be used with the ralloc_* 69 * functions 70 * @param[in] ntemps number of temporaries reserved for this shader 71 * @param[in] reg_live_ranges required live range for each temporary register. 72 * @param[in,out] result memory location to store the register remapping table. 73 * On input the parameter must point to allocated memory that can hold the 74 * renaming information for ntemps registers, on output the mapping is stored. 75 * Note that TEMP[0] is not considered for register renaming. 76 */ 77 void get_temp_registers_remapping(void *mem_ctx, int ntemps, 78 const struct register_live_range* reg_live_ranges, 79 struct rename_reg_pair *result); 80 #endif