18bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt/* 2565ff676887fc40b4715b44d9407c638480485e6Kenneth Graunke * Copyright © 2010 Intel Corporation 38bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * 48bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a 58bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * constant of this software and associated documentation files (the "Software"), 68bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * to deal in the Software without restriction, including without limitation 78bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * the rights to use, constant, modify, merge, publish, distribute, sublicense, 88bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * and/or sell copies of the Software, and to permit persons to whom the 98bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * Software is furnished to do so, subject to the following conditions: 108bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * 118bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * The above constantright notice and this permission notice (including the next 128bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * paragraph) shall be included in all copies or substantial portions of the 138bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * Software. 148bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * 158bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * THE AUTHORS OR CONSTANTRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 208bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 218bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * DEALINGS IN THE SOFTWARE. 228bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 238bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 248bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt/** 25df883eb1575a740bf91e01cbe2eaa4dbc1f9f154Chad Versace * \file opt_constant_propagation.cpp 268bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * 278bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * Tracks assignments of constants to channels of variables, and 288bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * usage of those constant channels with direct usage of the constants. 298bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * 308bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * This can lead to constant folding and algebraic optimizations in 318bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * those later expressions, while causing no increase in instruction 328bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * count (due to constants being generally free to load from a 338bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * constant push buffer or as instruction immediate values) and 348bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * possibly reducing register pressure. 358bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 368bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 378bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt#include "ir.h" 388bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt#include "ir_visitor.h" 3942cab131dac469475c67ab38a2c29f2f66e6ff49Eric Anholt#include "ir_rvalue_visitor.h" 408bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt#include "ir_basic_block.h" 418bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt#include "ir_optimization.h" 428bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt#include "glsl_types.h" 438bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 44337d9c955b070224f7278524af54ddacd8bb0f17Eric Anholtnamespace { 45337d9c955b070224f7278524af54ddacd8bb0f17Eric Anholt 468bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtclass acp_entry : public exec_node 478bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 488bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtpublic: 498bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt acp_entry(ir_variable *var, unsigned write_mask, ir_constant *constant) 508bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt { 518bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt assert(var); 528bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt assert(constant); 538bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->var = var; 548bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->write_mask = write_mask; 558bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->constant = constant; 560eb97979584b73907327eebc547302e6b8d8976aIan Romanick this->initial_values = write_mask; 570eb97979584b73907327eebc547302e6b8d8976aIan Romanick } 580eb97979584b73907327eebc547302e6b8d8976aIan Romanick 590eb97979584b73907327eebc547302e6b8d8976aIan Romanick acp_entry(const acp_entry *src) 600eb97979584b73907327eebc547302e6b8d8976aIan Romanick { 610eb97979584b73907327eebc547302e6b8d8976aIan Romanick this->var = src->var; 620eb97979584b73907327eebc547302e6b8d8976aIan Romanick this->write_mask = src->write_mask; 630eb97979584b73907327eebc547302e6b8d8976aIan Romanick this->constant = src->constant; 640eb97979584b73907327eebc547302e6b8d8976aIan Romanick this->initial_values = src->initial_values; 658bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 668bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 678bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_variable *var; 688bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_constant *constant; 698bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt unsigned write_mask; 700eb97979584b73907327eebc547302e6b8d8976aIan Romanick 710eb97979584b73907327eebc547302e6b8d8976aIan Romanick /** Mask of values initially available in the constant. */ 720eb97979584b73907327eebc547302e6b8d8976aIan Romanick unsigned initial_values; 738bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt}; 748bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 758bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 768bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtclass kill_entry : public exec_node 778bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 788bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtpublic: 798bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt kill_entry(ir_variable *var, unsigned write_mask) 808bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt { 818bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt assert(var); 828bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->var = var; 838bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->write_mask = write_mask; 848bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 858bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 868bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_variable *var; 878bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt unsigned write_mask; 888bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt}; 898bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 9042cab131dac469475c67ab38a2c29f2f66e6ff49Eric Anholtclass ir_constant_propagation_visitor : public ir_rvalue_visitor { 918bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtpublic: 928bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_constant_propagation_visitor() 938bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt { 948bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt progress = false; 95eadadecbaad7f72dbdb122385447e3f4e251837dDave Airlie killed_all = false; 96d3073f58c17d8675a2ecdd5dfa83e5520c78e1a8Kenneth Graunke mem_ctx = ralloc_context(0); 978bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp = new(mem_ctx) exec_list; 988bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills = new(mem_ctx) exec_list; 998bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 1008bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ~ir_constant_propagation_visitor() 1018bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt { 102d3073f58c17d8675a2ecdd5dfa83e5520c78e1a8Kenneth Graunke ralloc_free(mem_ctx); 1038bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 1048bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1058bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt virtual ir_visitor_status visit_enter(class ir_loop *); 1068bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt virtual ir_visitor_status visit_enter(class ir_function_signature *); 1078bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt virtual ir_visitor_status visit_enter(class ir_function *); 1084e5b41c2f6b6423d0df260a9dea7938546134ec6Ian Romanick virtual ir_visitor_status visit_leave(class ir_assignment *); 1098bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt virtual ir_visitor_status visit_enter(class ir_call *); 1108bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt virtual ir_visitor_status visit_enter(class ir_if *); 1118bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1128bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt void add_constant(ir_assignment *ir); 1138bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt void kill(ir_variable *ir, unsigned write_mask); 1148bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt void handle_if_block(exec_list *instructions); 1158bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt void handle_rvalue(ir_rvalue **rvalue); 1168bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1178bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /** List of acp_entry: The available constants to propagate */ 1188bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *acp; 1198bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1208bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /** 1218bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * List of kill_entry: The masks of variables whose values were 1228bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * killed in this block. 1238bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 1248bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *kills; 1258bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1268bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt bool progress; 1278bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1288bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt bool killed_all; 1298bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1308bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt void *mem_ctx; 1318bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt}; 1328bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1338bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1348bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtvoid 1358bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::handle_rvalue(ir_rvalue **rvalue) 1368bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 1374e5b41c2f6b6423d0df260a9dea7938546134ec6Ian Romanick if (this->in_assignee || !*rvalue) 1388bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 1398bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1408bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt const glsl_type *type = (*rvalue)->type; 1418bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!type->is_scalar() && !type->is_vector()) 1428bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 1438bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1448bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_swizzle *swiz = NULL; 1458bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_dereference_variable *deref = (*rvalue)->as_dereference_variable(); 1468bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!deref) { 1478bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt swiz = (*rvalue)->as_swizzle(); 1488bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!swiz) 1498bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 1508bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1518bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt deref = swiz->val->as_dereference_variable(); 1528bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!deref) 1538bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 1548bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 1558bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1568bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_constant_data data; 1578bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt memset(&data, 0, sizeof(data)); 1588bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1598bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt for (unsigned int i = 0; i < type->components(); i++) { 1608bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt int channel; 1618bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt acp_entry *found = NULL; 1628bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1638bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (swiz) { 1648bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt switch (i) { 1658bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case 0: channel = swiz->mask.x; break; 1668bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case 1: channel = swiz->mask.y; break; 1678bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case 2: channel = swiz->mask.z; break; 1688bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case 3: channel = swiz->mask.w; break; 1698bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt default: assert(!"shouldn't be reached"); channel = 0; break; 1708bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 1718bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } else { 1728bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt channel = i; 1738bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 1748bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1758bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt foreach_iter(exec_list_iterator, iter, *this->acp) { 1768bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt acp_entry *entry = (acp_entry *)iter.get(); 1778bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (entry->var == deref->var && entry->write_mask & (1 << channel)) { 1788bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt found = entry; 1798bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt break; 1808bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 1818bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 1828bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 1838bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!found) 1848bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 1858bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 186b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt int rhs_channel = 0; 187b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt for (int j = 0; j < 4; j++) { 188b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt if (j == channel) 189b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt break; 1900eb97979584b73907327eebc547302e6b8d8976aIan Romanick if (found->initial_values & (1 << j)) 191b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt rhs_channel++; 192b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt } 193b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt 1948bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt switch (type->base_type) { 1958bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case GLSL_TYPE_FLOAT: 196b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt data.f[i] = found->constant->value.f[rhs_channel]; 1978bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt break; 1988bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case GLSL_TYPE_INT: 199b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt data.i[i] = found->constant->value.i[rhs_channel]; 2008bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt break; 2018bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case GLSL_TYPE_UINT: 202b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt data.u[i] = found->constant->value.u[rhs_channel]; 2038bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt break; 2048bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt case GLSL_TYPE_BOOL: 205b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt data.b[i] = found->constant->value.b[rhs_channel]; 2068bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt break; 2078bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt default: 2088bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt assert(!"not reached"); 2098bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt break; 2108bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 2118bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 2128bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 213d3073f58c17d8675a2ecdd5dfa83e5520c78e1a8Kenneth Graunke *rvalue = new(ralloc_parent(deref)) ir_constant(type, &data); 2148bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->progress = true; 2158bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 2168bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2178bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_visitor_status 2188bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::visit_enter(ir_function_signature *ir) 2198bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 2208bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Treat entry into a function signature as a completely separate 2218bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * block. Any instructions at global scope will be shuffled into 2228bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * main() at link time, so they're irrelevant to us. 2238bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 2248bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *orig_acp = this->acp; 2258bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *orig_kills = this->kills; 2268bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt bool orig_killed_all = this->killed_all; 2278bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2288bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp = new(mem_ctx) exec_list; 2298bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills = new(mem_ctx) exec_list; 2308bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->killed_all = false; 2318bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2328bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt visit_list_elements(this, &ir->body); 2338bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2348bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills = orig_kills; 2358bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp = orig_acp; 2368bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->killed_all = orig_killed_all; 2378bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2388bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return visit_continue_with_parent; 2398bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 2408bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2418bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_visitor_status 2424e5b41c2f6b6423d0df260a9dea7938546134ec6Ian Romanickir_constant_propagation_visitor::visit_leave(ir_assignment *ir) 2438bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 2444e5b41c2f6b6423d0df260a9dea7938546134ec6Ian Romanick if (this->in_assignee) 2454e5b41c2f6b6423d0df260a9dea7938546134ec6Ian Romanick return visit_continue; 2468bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 247aa173e16a07566b7549b00946840ea16ac17a380Paul Berry unsigned kill_mask = ir->write_mask; 248aa173e16a07566b7549b00946840ea16ac17a380Paul Berry if (ir->lhs->as_dereference_array()) { 249aa173e16a07566b7549b00946840ea16ac17a380Paul Berry /* The LHS of the assignment uses an array indexing operator (e.g. v[i] 250aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * = ...;). Since we only try to constant propagate vectors and 251aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * scalars, this means that either (a) array indexing is being used to 252aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * select a vector component, or (b) the variable in question is neither 253aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * a scalar or a vector, so we don't care about it. In the former case, 254aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * we want to kill the whole vector, since in general we can't predict 255aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * which vector component will be selected by array indexing. In the 256aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * latter case, it doesn't matter what we do, so go ahead and kill the 257aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * whole variable anyway. 258aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * 259aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * Note that if the array index is constant (e.g. v[2] = ...;), we could 260aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * in principle be smarter, but we don't need to, because a future 261aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * optimization pass will convert it to a simple assignment with the 262aa173e16a07566b7549b00946840ea16ac17a380Paul Berry * correct mask. 263aa173e16a07566b7549b00946840ea16ac17a380Paul Berry */ 264aa173e16a07566b7549b00946840ea16ac17a380Paul Berry kill_mask = ~0; 265aa173e16a07566b7549b00946840ea16ac17a380Paul Berry } 266aa173e16a07566b7549b00946840ea16ac17a380Paul Berry kill(ir->lhs->variable_referenced(), kill_mask); 2678bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2688bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt add_constant(ir); 2698bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2704e5b41c2f6b6423d0df260a9dea7938546134ec6Ian Romanick return visit_continue; 2718bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 2728bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2738bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_visitor_status 2748bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::visit_enter(ir_function *ir) 2758bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 2768bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt (void) ir; 2778bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return visit_continue; 2788bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 2798bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2808bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_visitor_status 2818bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::visit_enter(ir_call *ir) 2828bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 2838bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Do constant propagation on call parameters, but skip any out params */ 28482065fa20ee3f2880a070f1f4f75509b910ceddeKenneth Graunke exec_list_iterator sig_param_iter = ir->callee->parameters.iterator(); 2858bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt foreach_iter(exec_list_iterator, iter, ir->actual_parameters) { 2868bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_variable *sig_param = (ir_variable *)sig_param_iter.get(); 2878bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_rvalue *param = (ir_rvalue *)iter.get(); 2888bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (sig_param->mode != ir_var_out && sig_param->mode != ir_var_inout) { 2898bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_rvalue *new_param = param; 2908bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt handle_rvalue(&new_param); 2918bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (new_param != param) 2928bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt param->replace_with(new_param); 2938bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt else 2948bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt param->accept(this); 2958bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 2968bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt sig_param_iter.next(); 2978bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 2988bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 2998bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Since we're unlinked, we don't (necssarily) know the side effects of 3008bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * this call. So kill all copies. 3018bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 3028bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt acp->make_empty(); 3038bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->killed_all = true; 3048bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3058bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return visit_continue_with_parent; 3068bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 3078bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3088bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtvoid 3098bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::handle_if_block(exec_list *instructions) 3108bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 3118bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *orig_acp = this->acp; 3128bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *orig_kills = this->kills; 3138bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt bool orig_killed_all = this->killed_all; 3148bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3158bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp = new(mem_ctx) exec_list; 3168bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills = new(mem_ctx) exec_list; 3178bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->killed_all = false; 3188bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3198bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Populate the initial acp with a constant of the original */ 3208bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt foreach_iter(exec_list_iterator, iter, *orig_acp) { 3218bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt acp_entry *a = (acp_entry *)iter.get(); 3220eb97979584b73907327eebc547302e6b8d8976aIan Romanick this->acp->push_tail(new(this->mem_ctx) acp_entry(a)); 3238bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 3248bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3258bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt visit_list_elements(this, instructions); 3268bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3278bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (this->killed_all) { 3288bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt orig_acp->make_empty(); 3298bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 3308bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3318bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *new_kills = this->kills; 3328bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills = orig_kills; 3338bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp = orig_acp; 3348bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->killed_all = this->killed_all || orig_killed_all; 3358bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3368bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt foreach_iter(exec_list_iterator, iter, *new_kills) { 3378bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt kill_entry *k = (kill_entry *)iter.get(); 3388bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt kill(k->var, k->write_mask); 3398bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 3408bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 3418bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3428bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_visitor_status 3438bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::visit_enter(ir_if *ir) 3448bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 3458bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir->condition->accept(this); 3468bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt handle_rvalue(&ir->condition); 3478bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3488bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt handle_if_block(&ir->then_instructions); 3498bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt handle_if_block(&ir->else_instructions); 3508bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3518bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* handle_if_block() already descended into the children. */ 3528bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return visit_continue_with_parent; 3538bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 3548bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3558bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_visitor_status 3568bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::visit_enter(ir_loop *ir) 3578bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 3588bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *orig_acp = this->acp; 3598bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *orig_kills = this->kills; 3608bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt bool orig_killed_all = this->killed_all; 3618bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3628bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* FINISHME: For now, the initial acp for loops is totally empty. 3638bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * We could go through once, then go through again with the acp 3648bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * cloned minus the killed entries after the first run through. 3658bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 3668bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp = new(mem_ctx) exec_list; 3678bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills = new(mem_ctx) exec_list; 3688bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->killed_all = false; 3698bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3708bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt visit_list_elements(this, &ir->body_instructions); 3718bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3728bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (this->killed_all) { 3738bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt orig_acp->make_empty(); 3748bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 3758bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3768bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt exec_list *new_kills = this->kills; 3778bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills = orig_kills; 3788bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp = orig_acp; 3798bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->killed_all = this->killed_all || orig_killed_all; 3808bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3818bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt foreach_iter(exec_list_iterator, iter, *new_kills) { 3828bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt kill_entry *k = (kill_entry *)iter.get(); 3838bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt kill(k->var, k->write_mask); 3848bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 3858bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3868bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* already descended into the children. */ 3878bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return visit_continue_with_parent; 3888bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 3898bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3908bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtvoid 3918bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask) 3928bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 3938bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt assert(var != NULL); 3948bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3958bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* We don't track non-vectors. */ 3968bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!var->type->is_vector() && !var->type->is_scalar()) 3978bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 3988bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 3998bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Remove any entries currently in the ACP for this kill. */ 4008bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt foreach_iter(exec_list_iterator, iter, *this->acp) { 4018bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt acp_entry *entry = (acp_entry *)iter.get(); 4028bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4038bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (entry->var == var) { 4048bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt entry->write_mask &= ~write_mask; 4058bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (entry->write_mask == 0) 4068bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt entry->remove(); 4078bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 4088bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 4098bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4108bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Add this writemask of the variable to the list of killed 4118bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * variables in this block. 4128bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 4138bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt foreach_iter(exec_list_iterator, iter, *this->kills) { 4148bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt kill_entry *entry = (kill_entry *)iter.get(); 4158bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4168bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (entry->var == var) { 4178bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt entry->write_mask |= write_mask; 4188bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 4198bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 4208bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt } 4218bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Not already in the list. Make new entry. */ 4228bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->kills->push_tail(new(this->mem_ctx) kill_entry(var, write_mask)); 4238bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 4248bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4258bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt/** 4268bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * Adds an entry to the available constant list if it's a plain assignment 4278bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * of a variable to a variable. 4288bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 4298bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtvoid 4308bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtir_constant_propagation_visitor::add_constant(ir_assignment *ir) 4318bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 4328bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt acp_entry *entry; 4338bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 43429a2e9133e415de8b010df5b80db758aaf1007a6Eric Anholt if (ir->condition) 43529a2e9133e415de8b010df5b80db758aaf1007a6Eric Anholt return; 4368bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4378bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!ir->write_mask) 4388bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 4398bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4408bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_dereference_variable *deref = ir->lhs->as_dereference_variable(); 4418bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_constant *constant = ir->rhs->as_constant(); 4428bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4438bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!deref || !constant) 4448bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 4458bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4468bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt /* Only do constant propagation on vectors. Constant matrices, 4478bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * arrays, or structures would require more work elsewhere. 4488bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 4498bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt if (!deref->var->type->is_vector() && !deref->var->type->is_scalar()) 4508bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return; 4518bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4528bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt entry = new(this->mem_ctx) acp_entry(deref->var, ir->write_mask, constant); 4538bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt this->acp->push_tail(entry); 4548bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 4558bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 456337d9c955b070224f7278524af54ddacd8bb0f17Eric Anholt} /* unnamed namespace */ 457337d9c955b070224f7278524af54ddacd8bb0f17Eric Anholt 4588bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt/** 4598bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt * Does a constant propagation pass on the code present in the instruction stream. 4608bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt */ 4618bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtbool 4628bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtdo_constant_propagation(exec_list *instructions) 4638bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt{ 4648bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt ir_constant_propagation_visitor v; 4658bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4668bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt visit_list_elements(&v, instructions); 4678bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt 4688bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt return v.progress; 4698bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholt} 470