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 #ifndef BRW_VEC4_LIVE_VARIABLES_H 29 #define BRW_VEC4_LIVE_VARIABLES_H 30 31 #include "util/bitset.h" 32 #include "brw_vec4.h" 33 34 namespace brw { 35 36 struct block_data { 37 /** 38 * Which variables are defined before being used in the block. 39 * 40 * Note that for our purposes, "defined" means unconditionally, completely 41 * defined. 42 */ 43 BITSET_WORD *def; 44 45 /** 46 * Which variables are used before being defined in the block. 47 */ 48 BITSET_WORD *use; 49 50 /** Which defs reach the entry point of the block. */ 51 BITSET_WORD *livein; 52 53 /** Which defs reach the exit point of the block. */ 54 BITSET_WORD *liveout; 55 56 BITSET_WORD flag_def[1]; 57 BITSET_WORD flag_use[1]; 58 BITSET_WORD flag_livein[1]; 59 BITSET_WORD flag_liveout[1]; 60 }; 61 62 class vec4_live_variables { 63 public: 64 DECLARE_RALLOC_CXX_OPERATORS(vec4_live_variables) 65 66 vec4_live_variables(const simple_allocator &alloc, cfg_t *cfg); 67 ~vec4_live_variables(); 68 69 int num_vars; 70 int bitset_words; 71 72 /** Per-basic-block information on live variables */ 73 struct block_data *block_data; 74 75 protected: 76 void setup_def_use(); 77 void compute_live_variables(); 78 79 const simple_allocator &alloc; 80 cfg_t *cfg; 81 void *mem_ctx; 82 }; 83 84 /* Returns the variable index for the k-th dword of the c-th component of 85 * register reg. 86 */ 87 inline unsigned 88 var_from_reg(const simple_allocator &alloc, const src_reg ®, 89 unsigned c = 0, unsigned k = 0) 90 { 91 assert(reg.file == VGRF && reg.nr < alloc.count && c < 4); 92 const unsigned csize = DIV_ROUND_UP(type_sz(reg.type), 4); 93 unsigned result = 94 8 * alloc.offsets[reg.nr] + reg.offset / 4 + 95 (BRW_GET_SWZ(reg.swizzle, c) + k / csize * 4) * csize + k % csize; 96 /* Do not exceed the limit for this register */ 97 assert(result < 8 * (alloc.offsets[reg.nr] + alloc.sizes[reg.nr])); 98 return result; 99 } 100 101 inline unsigned 102 var_from_reg(const simple_allocator &alloc, const dst_reg ®, 103 unsigned c = 0, unsigned k = 0) 104 { 105 assert(reg.file == VGRF && reg.nr < alloc.count && c < 4); 106 const unsigned csize = DIV_ROUND_UP(type_sz(reg.type), 4); 107 unsigned result = 108 8 * alloc.offsets[reg.nr] + reg.offset / 4 + 109 (c + k / csize * 4) * csize + k % csize; 110 /* Do not exceed the limit for this register */ 111 assert(result < 8 * (alloc.offsets[reg.nr] + alloc.sizes[reg.nr])); 112 return result; 113 } 114 115 } /* namespace brw */ 116 117 #endif /* BRW_VEC4_LIVE_VARIABLES_H */ 118