1 /* 2 * Copyright © 2012 Intel Corporation 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 DEALINGS 21 * IN THE SOFTWARE. 22 * 23 * Authors: 24 * Eric Anholt <[email protected]> 25 * 26 */ 27 28 #ifndef ELK_VEC4_LIVE_VARIABLES_H 29 #define ELK_VEC4_LIVE_VARIABLES_H 30 31 #include "elk_ir_vec4.h" 32 #include "elk_ir_analysis.h" 33 #include "util/bitset.h" 34 35 struct elk_backend_shader; 36 37 namespace elk { 38 39 class vec4_live_variables { 40 public: 41 struct block_data { 42 /** 43 * Which variables are defined before being used in the block. 44 * 45 * Note that for our purposes, "defined" means unconditionally, completely 46 * defined. 47 */ 48 BITSET_WORD *def; 49 50 /** 51 * Which variables are used before being defined in the block. 52 */ 53 BITSET_WORD *use; 54 55 /** Which defs reach the entry point of the block. */ 56 BITSET_WORD *livein; 57 58 /** Which defs reach the exit point of the block. */ 59 BITSET_WORD *liveout; 60 61 BITSET_WORD flag_def[1]; 62 BITSET_WORD flag_use[1]; 63 BITSET_WORD flag_livein[1]; 64 BITSET_WORD flag_liveout[1]; 65 }; 66 67 vec4_live_variables(const elk_backend_shader *s); 68 vec4_live_variables(const vec4_live_variables &) = delete; 69 ~vec4_live_variables(); 70 vec4_live_variables & operator=(const vec4_live_variables &) = delete; 71 72 bool 73 validate(const elk_backend_shader *s) const; 74 75 analysis_dependency_class dependency_class()76 dependency_class() const 77 { 78 return (DEPENDENCY_INSTRUCTION_IDENTITY | 79 DEPENDENCY_INSTRUCTION_DATA_FLOW | 80 DEPENDENCY_VARIABLES); 81 } 82 83 int num_vars; 84 int bitset_words; 85 86 const struct intel_device_info *devinfo; 87 88 /** Per-basic-block information on live variables */ 89 struct block_data *block_data; 90 91 /** @{ 92 * Final computed live ranges for each variable. 93 */ 94 int *start; 95 int *end; 96 /** @} */ 97 98 int var_range_start(unsigned v, unsigned n) const; 99 int var_range_end(unsigned v, unsigned n) const; 100 bool vgrfs_interfere(int a, int b) const; 101 102 protected: 103 void setup_def_use(); 104 void compute_live_variables(); 105 void compute_start_end(); 106 107 const simple_allocator &alloc; 108 elk_cfg_t *cfg; 109 void *mem_ctx; 110 }; 111 112 /* Returns the variable index for the k-th dword of the c-th component of 113 * register reg. 114 */ 115 inline unsigned 116 var_from_reg(const simple_allocator &alloc, const src_reg ®, 117 unsigned c = 0, unsigned k = 0) 118 { 119 assert(reg.file == VGRF && reg.nr < alloc.count && c < 4); 120 const unsigned csize = DIV_ROUND_UP(type_sz(reg.type), 4); 121 unsigned result = 122 8 * alloc.offsets[reg.nr] + reg.offset / 4 + 123 (ELK_GET_SWZ(reg.swizzle, c) + k / csize * 4) * csize + k % csize; 124 /* Do not exceed the limit for this register */ 125 assert(result < 8 * (alloc.offsets[reg.nr] + alloc.sizes[reg.nr])); 126 return result; 127 } 128 129 inline unsigned 130 var_from_reg(const simple_allocator &alloc, const dst_reg ®, 131 unsigned c = 0, unsigned k = 0) 132 { 133 assert(reg.file == VGRF && reg.nr < alloc.count && c < 4); 134 const unsigned csize = DIV_ROUND_UP(type_sz(reg.type), 4); 135 unsigned result = 136 8 * alloc.offsets[reg.nr] + reg.offset / 4 + 137 (c + k / csize * 4) * csize + k % csize; 138 /* Do not exceed the limit for this register */ 139 assert(result < 8 * (alloc.offsets[reg.nr] + alloc.sizes[reg.nr])); 140 return result; 141 } 142 143 } /* namespace elk */ 144 145 #endif /* ELK_VEC4_LIVE_VARIABLES_H */ 146