d5fd21d99a4ff51daae3dfe641c4db420101a2f7
2 * Copyright © 2011 Intel Corporation
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:
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
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
25 #include "../glsl/ir_print_visitor.h"
32 assign(int *reg_hw_locations
, reg
*reg
)
34 if (reg
->file
== GRF
) {
35 reg
->reg
= reg_hw_locations
[reg
->reg
];
40 vec4_visitor::reg_allocate_trivial()
42 int hw_reg_mapping
[this->virtual_grf_count
];
43 bool virtual_grf_used
[this->virtual_grf_count
];
47 /* Calculate which virtual GRFs are actually in use after whatever
48 * optimization passes have occurred.
50 for (int i
= 0; i
< this->virtual_grf_count
; i
++) {
51 virtual_grf_used
[i
] = false;
54 foreach_iter(exec_list_iterator
, iter
, this->instructions
) {
55 vec4_instruction
*inst
= (vec4_instruction
*)iter
.get();
57 if (inst
->dst
.file
== GRF
)
58 virtual_grf_used
[inst
->dst
.reg
] = true;
60 for (int i
= 0; i
< 3; i
++) {
61 if (inst
->src
[i
].file
== GRF
)
62 virtual_grf_used
[inst
->src
[i
].reg
] = true;
66 /* Note that compressed instructions require alignment to 2 registers. */
67 hw_reg_mapping
[0] = this->first_non_payload_grf
;
68 next
= hw_reg_mapping
[0] + this->virtual_grf_sizes
[0];
69 for (i
= 1; i
< this->virtual_grf_count
; i
++) {
70 if (virtual_grf_used
[i
]) {
71 hw_reg_mapping
[i
] = next
;
72 next
+= this->virtual_grf_sizes
[i
];
75 prog_data
->total_grf
= next
;
77 foreach_iter(exec_list_iterator
, iter
, this->instructions
) {
78 vec4_instruction
*inst
= (vec4_instruction
*)iter
.get();
80 assign(hw_reg_mapping
, &inst
->dst
);
81 assign(hw_reg_mapping
, &inst
->src
[0]);
82 assign(hw_reg_mapping
, &inst
->src
[1]);
83 assign(hw_reg_mapping
, &inst
->src
[2]);
86 if (prog_data
->total_grf
> BRW_MAX_GRF
) {
87 fail("Ran out of regs on trivial allocator (%d/%d)\n",
88 prog_data
->total_grf
, BRW_MAX_GRF
);
93 vec4_visitor::reg_allocate()
95 reg_allocate_trivial();