2 * Copyright © 2020 Valve 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 "util/crc32.h"
29 /* sgpr_presched/vgpr_presched */
30 void collect_presched_stats(Program
*program
)
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
;
39 /* instructions/branches/vmem_clauses/smem_clauses/cycles */
40 void collect_preasm_stats(Program
*program
)
42 for (Block
& block
: program
->blocks
) {
43 std::set
<Temp
> vmem_clause_res
;
44 std::set
<Temp
> smem_clause_res
;
46 program
->statistics
[statistic_instructions
] += block
.instructions
.size();
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
]++;
52 if (instr
->opcode
== aco_opcode::p_constaddr
)
53 program
->statistics
[statistic_instructions
] += 2;
55 if (instr
->isVMEM() && !instr
->operands
.empty()) {
56 vmem_clause_res
.insert(instr
->operands
[0].getTemp());
58 program
->statistics
[statistic_vmem_clauses
] += vmem_clause_res
.size();
59 vmem_clause_res
.clear();
62 if (instr
->format
== Format::SMEM
&& !instr
->operands
.empty()) {
63 if (instr
->operands
[0].size() == 2)
64 smem_clause_res
.insert(Temp(0, s2
));
66 smem_clause_res
.insert(instr
->operands
[0].getTemp());
68 program
->statistics
[statistic_smem_clauses
] += smem_clause_res
.size();
69 smem_clause_res
.clear();
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
;
78 program
->statistics
[statistic_vmem_clauses
] += vmem_clause_res
.size();
79 program
->statistics
[statistic_smem_clauses
] += smem_clause_res
.size();
83 void collect_postasm_stats(Program
*program
, const std::vector
<uint32_t>& code
)
85 program
->statistics
[aco::statistic_hash
] = util_hash_crc32(code
.data(), code
.size() * 4);