xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r300/compiler/radeon_rename_regs.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2010 Tom Stellard <[email protected]>
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  */
rc_rename_regs(struct radeon_compiler * c,void * user)23 void rc_rename_regs(struct radeon_compiler *c, void *user)
24 {
25 	struct rc_instruction * inst;
26 	struct rc_list * variables;
27 	struct rc_list * var_ptr;
28 
29 	/* XXX Remove this once the register allocation works with flow control. */
30 	for(inst = c->Program.Instructions.Next;
31 					inst != &c->Program.Instructions;
32 					inst = inst->Next) {
33 		if (inst->U.I.Opcode == RC_OPCODE_BGNLOOP)
34 			return;
35 	}
36 
37 	variables = rc_get_variables(c);
38 
39 	for (var_ptr = variables; var_ptr; var_ptr = var_ptr->Next) {
40 		int new_index;
41 		unsigned writemask;
42 		struct rc_variable * var = var_ptr->Item;
43 
44 		if (var->Inst->U.I.DstReg.File != RC_FILE_TEMPORARY) {
45 			continue;
46 		}
47 
48 		new_index = rc_find_free_temporary(c);
49 		if (new_index < 0) {
50 			rc_error(c, "Ran out of temporary registers\n");
51 			return;
52 		}
53 
54 		writemask = rc_variable_writemask_sum(var);
55 		rc_variable_change_dst(var, new_index, writemask);
56 	}
57 }
58