xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r300/compiler/radeon_regalloc.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2009 Nicolai Haehnle.
3  * Copyright 2011 Tom Stellard <[email protected]>
4  * Copyright 2012 Advanced Micro Devices, Inc.
5  * Author: Tom Stellard <[email protected]>
6  * SPDX-License-Identifier: MIT
7  */
8 
9 #ifndef RADEON_REGALLOC_H
10 #define RADEON_REGALLOC_H
11 
12 #include "util/register_allocate.h"
13 #include "util/u_memory.h"
14 #include "util/ralloc.h"
15 
16 #include "radeon_variable.h"
17 
18 struct ra_regs;
19 
20 enum rc_reg_class {
21 	RC_REG_CLASS_FP_SINGLE,
22 	RC_REG_CLASS_FP_DOUBLE,
23 	RC_REG_CLASS_FP_TRIPLE,
24 	RC_REG_CLASS_FP_ALPHA,
25 	RC_REG_CLASS_FP_SINGLE_PLUS_ALPHA,
26 	RC_REG_CLASS_FP_DOUBLE_PLUS_ALPHA,
27 	RC_REG_CLASS_FP_TRIPLE_PLUS_ALPHA,
28 	RC_REG_CLASS_FP_X,
29 	RC_REG_CLASS_FP_Y,
30 	RC_REG_CLASS_FP_Z,
31 	RC_REG_CLASS_FP_XY,
32 	RC_REG_CLASS_FP_YZ,
33 	RC_REG_CLASS_FP_XZ,
34 	RC_REG_CLASS_FP_XW,
35 	RC_REG_CLASS_FP_YW,
36 	RC_REG_CLASS_FP_ZW,
37 	RC_REG_CLASS_FP_XYW,
38 	RC_REG_CLASS_FP_YZW,
39 	RC_REG_CLASS_FP_XZW,
40 	RC_REG_CLASS_FP_COUNT
41 };
42 
43 enum rc_reg_class_vp {
44 	RC_REG_CLASS_VP_SINGLE,
45 	RC_REG_CLASS_VP_DOUBLE,
46 	RC_REG_CLASS_VP_TRIPLE,
47 	RC_REG_CLASS_VP_QUADRUPLE,
48 	RC_REG_CLASS_VP_COUNT
49 };
50 
51 struct rc_regalloc_state {
52 	struct ra_regs *regs;
53 	struct ra_class *classes[RC_REG_CLASS_FP_COUNT];
54 	const struct rc_class *class_list;
55 };
56 
57 struct register_info {
58 	struct live_intervals Live[4];
59 
60 	unsigned int Used:1;
61 	unsigned int Allocated:1;
62 	unsigned int File:3;
63 	unsigned int Index:RC_REGISTER_INDEX_BITS;
64 	unsigned int Writemask;
65 };
66 
67 struct regalloc_state {
68 	struct radeon_compiler * C;
69 
70 	struct register_info * Input;
71 	unsigned int NumInputs;
72 
73 	struct register_info * Temporary;
74 	unsigned int NumTemporaries;
75 
76 	unsigned int Simple;
77 	int LoopEnd;
78 };
79 
80 struct rc_class {
81 	enum rc_reg_class ID;
82 
83 	unsigned int WritemaskCount;
84 
85 	/** List of writemasks that belong to this class */
86 	unsigned int Writemasks[6];
87 };
88 
89 int rc_find_class(
90 	const struct rc_class * classes,
91 	unsigned int writemask,
92 	unsigned int max_writemask_count);
93 
94 unsigned int rc_overlap_live_intervals_array(
95 	struct live_intervals * a,
96 	struct live_intervals * b);
97 
reg_get_index(int reg)98 static inline unsigned int reg_get_index(int reg)
99 {
100 	return reg / RC_MASK_XYZW;
101 };
102 
reg_get_writemask(int reg)103 static inline unsigned int reg_get_writemask(int reg)
104 {
105 	return (reg % RC_MASK_XYZW) + 1;
106 };
107 
get_reg_id(unsigned int index,unsigned int writemask)108 static inline int get_reg_id(unsigned int index, unsigned int writemask)
109 {
110        assert(writemask);
111        if (writemask == 0) {
112                return 0;
113        }
114        return (index * RC_MASK_XYZW) + (writemask - 1);
115 }
116 
117 void rc_build_interference_graph(
118 	struct ra_graph * graph,
119 	struct rc_list * variables);
120 
121 void rc_init_regalloc_state(struct rc_regalloc_state *s, enum rc_program_type prog);
122 void rc_destroy_regalloc_state(struct rc_regalloc_state *s);
123 
124 #endif /* RADEON_REGALLOC_H */
125