1 /*
2 * Copyright © 2020 Valve Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 */
24 #include "aco_ir.h"
25 #include "util/crc32.h"
26
27 namespace aco {
28
29 /* sgpr_presched/vgpr_presched */
collect_presched_stats(Program * program)30 void collect_presched_stats(Program *program)
31 {
32 RegisterDemand presched_demand;
33 for (Block& block : program->blocks)
34 presched_demand.update(block.register_demand);
35 program->statistics[statistic_sgpr_presched] = presched_demand.sgpr;
36 program->statistics[statistic_vgpr_presched] = presched_demand.vgpr;
37 }
38
39 /* instructions/branches/vmem_clauses/smem_clauses/cycles */
collect_preasm_stats(Program * program)40 void collect_preasm_stats(Program *program)
41 {
42 for (Block& block : program->blocks) {
43 std::set<Temp> vmem_clause_res;
44 std::set<Temp> smem_clause_res;
45
46 program->statistics[statistic_instructions] += block.instructions.size();
47
48 for (aco_ptr<Instruction>& instr : block.instructions) {
49 if (instr->format == Format::SOPP && static_cast<SOPP_instruction*>(instr.get())->block != -1)
50 program->statistics[statistic_branches]++;
51
52 if (instr->opcode == aco_opcode::p_constaddr)
53 program->statistics[statistic_instructions] += 2;
54
55 if (instr->isVMEM() && !instr->operands.empty()) {
56 vmem_clause_res.insert(instr->operands[0].getTemp());
57 } else {
58 program->statistics[statistic_vmem_clauses] += vmem_clause_res.size();
59 vmem_clause_res.clear();
60 }
61
62 if (instr->format == Format::SMEM && !instr->operands.empty()) {
63 if (instr->operands[0].size() == 2)
64 smem_clause_res.insert(Temp(0, s2));
65 else
66 smem_clause_res.insert(instr->operands[0].getTemp());
67 } else {
68 program->statistics[statistic_smem_clauses] += smem_clause_res.size();
69 smem_clause_res.clear();
70 }
71
72 /* TODO: this incorrectly assumes instructions always take 4 cycles */
73 /* assume loops execute 4 times (TODO: it would be nice to be able to consider loop unrolling) */
74 unsigned iter = 1 << (block.loop_nest_depth * 2);
75 program->statistics[statistic_cycles] += 4 * iter;
76 }
77
78 program->statistics[statistic_vmem_clauses] += vmem_clause_res.size();
79 program->statistics[statistic_smem_clauses] += smem_clause_res.size();
80 }
81 }
82
collect_postasm_stats(Program * program,const std::vector<uint32_t> & code)83 void collect_postasm_stats(Program *program, const std::vector<uint32_t>& code)
84 {
85 program->statistics[aco::statistic_hash] = util_hash_crc32(code.data(), code.size() * 4);
86 }
87
88 }
89