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