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_FS_LIVE_VARIABLES_H 29 #define ELK_FS_LIVE_VARIABLES_H 30 31 #include "elk_ir_analysis.h" 32 #include "elk_ir_fs.h" 33 #include "util/bitset.h" 34 35 struct elk_cfg_t; 36 struct elk_backend_shader; 37 38 namespace elk { 39 40 class fs_live_variables { 41 public: 42 struct block_data { 43 /** 44 * Which variables are defined before being used in the block. 45 * 46 * Note that for our purposes, "defined" means unconditionally, completely 47 * defined. 48 */ 49 BITSET_WORD *def; 50 51 /** 52 * Which variables are used before being defined in the block. 53 */ 54 BITSET_WORD *use; 55 56 /** Which defs reach the entry point of the block. */ 57 BITSET_WORD *livein; 58 59 /** Which defs reach the exit point of the block. */ 60 BITSET_WORD *liveout; 61 62 /** 63 * Variables such that the entry point of the block may be reached from any 64 * of their definitions. 65 */ 66 BITSET_WORD *defin; 67 68 /** 69 * Variables such that the exit point of the block may be reached from any 70 * of their definitions. 71 */ 72 BITSET_WORD *defout; 73 74 BITSET_WORD flag_def[1]; 75 BITSET_WORD flag_use[1]; 76 BITSET_WORD flag_livein[1]; 77 BITSET_WORD flag_liveout[1]; 78 }; 79 80 fs_live_variables(const elk_backend_shader *s); 81 fs_live_variables(const fs_live_variables &) = delete; 82 ~fs_live_variables(); 83 fs_live_variables & operator=(const fs_live_variables &) = delete; 84 85 bool validate(const elk_backend_shader *s) const; 86 87 analysis_dependency_class dependency_class()88 dependency_class() const 89 { 90 return (DEPENDENCY_INSTRUCTION_IDENTITY | 91 DEPENDENCY_INSTRUCTION_DATA_FLOW | 92 DEPENDENCY_VARIABLES); 93 } 94 95 bool vars_interfere(int a, int b) const; 96 bool vgrfs_interfere(int a, int b) const; var_from_reg(const elk_fs_reg & reg)97 int var_from_reg(const elk_fs_reg ®) const 98 { 99 return var_from_vgrf[reg.nr] + reg.offset / REG_SIZE; 100 } 101 102 /** Map from virtual GRF number to index in block_data arrays. */ 103 int *var_from_vgrf; 104 105 /** 106 * Map from any index in block_data to the virtual GRF containing it. 107 * 108 * For alloc.sizes of [1, 2, 3], vgrf_from_var would contain 109 * [0, 1, 1, 2, 2, 2]. 110 */ 111 int *vgrf_from_var; 112 113 int num_vars; 114 int num_vgrfs; 115 int bitset_words; 116 117 /** @{ 118 * Final computed live ranges for each var (each component of each virtual 119 * GRF). 120 */ 121 int *start; 122 int *end; 123 /** @} */ 124 125 /** @{ 126 * Final computed live ranges for each VGRF. 127 */ 128 int *vgrf_start; 129 int *vgrf_end; 130 /** @} */ 131 132 /** Per-basic-block information on live variables */ 133 struct block_data *block_data; 134 135 protected: 136 void setup_def_use(); 137 void setup_one_read(struct block_data *bd, int ip, const elk_fs_reg ®); 138 void setup_one_write(struct block_data *bd, elk_fs_inst *inst, int ip, 139 const elk_fs_reg ®); 140 void compute_live_variables(); 141 void compute_start_end(); 142 143 const struct intel_device_info *devinfo; 144 const elk_cfg_t *cfg; 145 void *mem_ctx; 146 }; 147 148 } /* namespace elk */ 149 150 #endif /* ELK_FS_LIVE_VARIABLES_H */ 151