1 /* 2 * Copyright 2010 Tom Stellard <tstellar@gmail.com> 3 * SPDX-License-Identifier: MIT 4 */ 5 6 #include "util/u_math.h" 7 8 #include "radeon_rename_regs.h" 9 10 #include "radeon_compiler.h" 11 #include "radeon_list.h" 12 #include "radeon_program.h" 13 #include "radeon_variable.h" 14 15 /** 16 * This function renames registers in an attempt to get the code close to 17 * SSA form. After this function has completed, most of the register are only 18 * written to one time, with a few exceptions. 19 * 20 * This function assumes all the instructions are still of type 21 * RC_INSTRUCTION_NORMAL. 22 */ 23 void rc_rename_regs(struct radeon_compiler * c,void * user)24rc_rename_regs(struct radeon_compiler *c, void *user) 25 { 26 struct rc_instruction *inst; 27 struct rc_list *variables; 28 struct rc_list *var_ptr; 29 30 /* XXX Remove this once the register allocation works with flow control. */ 31 for (inst = c->Program.Instructions.Next; inst != &c->Program.Instructions; inst = inst->Next) { 32 if (inst->U.I.Opcode == RC_OPCODE_BGNLOOP) 33 return; 34 } 35 36 variables = rc_get_variables(c); 37 38 for (var_ptr = variables; var_ptr; var_ptr = var_ptr->Next) { 39 int new_index; 40 unsigned writemask; 41 struct rc_variable *var = var_ptr->Item; 42 43 if (var->Inst->U.I.DstReg.File != RC_FILE_TEMPORARY) { 44 continue; 45 } 46 47 new_index = rc_find_free_temporary(c); 48 if (new_index < 0) { 49 rc_error(c, "Ran out of temporary registers\n"); 50 return; 51 } 52 53 writemask = rc_variable_writemask_sum(var); 54 rc_variable_change_dst(var, new_index, writemask); 55 } 56 } 57