android: aco: fix undefined template 'std::__1::array' build errors
[mesa.git] / src / amd / compiler / aco_print_asm.cpp
1 #include <array>
2 #include <iomanip>
3 #include "aco_ir.h"
4 #include "llvm-c/Disassembler.h"
5 #include "ac_llvm_util.h"
6
7 #include <llvm/ADT/StringRef.h>
8
9 namespace aco {
10
11 void print_asm(Program *program, std::vector<uint32_t>& binary,
12 unsigned exec_size, enum radeon_family family, std::ostream& out)
13 {
14 std::vector<bool> referenced_blocks(program->blocks.size());
15 referenced_blocks[0] = true;
16 for (Block& block : program->blocks) {
17 for (unsigned succ : block.linear_succs)
18 referenced_blocks[succ] = true;
19 }
20
21 std::vector<std::tuple<uint64_t, llvm::StringRef, uint8_t>> symbols;
22 std::vector<std::array<char,16>> block_names;
23 block_names.reserve(program->blocks.size());
24 for (Block& block : program->blocks) {
25 if (!referenced_blocks[block.index])
26 continue;
27 std::array<char, 16> name;
28 sprintf(name.data(), "BB%u", block.index);
29 block_names.push_back(name);
30 symbols.emplace_back(block.offset * 4, llvm::StringRef(block_names[block_names.size() - 1].data()), 0);
31 }
32
33 LLVMDisasmContextRef disasm = LLVMCreateDisasmCPU("amdgcn-mesa-mesa3d",
34 ac_get_llvm_processor_name(family),
35 &symbols, 0, NULL, NULL);
36
37 char outline[1024];
38 size_t pos = 0;
39 bool invalid = false;
40 unsigned next_block = 0;
41 while (pos < exec_size) {
42 while (next_block < program->blocks.size() && pos == program->blocks[next_block].offset) {
43 if (referenced_blocks[next_block])
44 out << "BB" << std::dec << next_block << ":" << std::endl;
45 next_block++;
46 }
47
48 size_t l = LLVMDisasmInstruction(disasm, (uint8_t *) &binary[pos],
49 (exec_size - pos) * sizeof(uint32_t), pos * 4,
50 outline, sizeof(outline));
51
52 size_t new_pos;
53 const int align_width = 60;
54 if (program->chip_class == GFX9 && !l && ((binary[pos] & 0xffff8000) == 0xd1348000)) { /* not actually an invalid instruction */
55 out << std::left << std::setw(align_width) << std::setfill(' ') << "\tv_add_u32_e64 + clamp";
56 new_pos = pos + 2;
57 } else if (!l) {
58 out << std::left << std::setw(align_width) << std::setfill(' ') << "(invalid instruction)";
59 new_pos = pos + 1;
60 invalid = true;
61 } else {
62 out << std::left << std::setw(align_width) << std::setfill(' ') << outline;
63 assert(l % 4 == 0);
64 new_pos = pos + l / 4;
65 }
66 out << std::right;
67
68 out << " ;";
69 for (; pos < new_pos; pos++)
70 out << " " << std::setfill('0') << std::setw(8) << std::hex << binary[pos];
71 out << std::endl;
72 }
73 out << std::setfill(' ') << std::setw(0) << std::dec;
74 assert(next_block == program->blocks.size());
75
76 LLVMDisasmDispose(disasm);
77
78 if (program->constant_data.size()) {
79 out << std::endl << "/* constant data */" << std::endl;
80 for (unsigned i = 0; i < program->constant_data.size(); i += 32) {
81 out << '[' << std::setw(6) << std::setfill('0') << std::dec << i << ']';
82 unsigned line_size = std::min<size_t>(program->constant_data.size() - i, 32);
83 for (unsigned j = 0; j < line_size; j += 4) {
84 unsigned size = std::min<size_t>(program->constant_data.size() - (i + j), 4);
85 uint32_t v = 0;
86 memcpy(&v, &program->constant_data[i + j], size);
87 out << " " << std::setw(8) << std::setfill('0') << std::hex << v;
88 }
89 out << std::endl;
90 }
91 }
92
93 out << std::setfill(' ') << std::setw(0) << std::dec;
94
95 if (invalid) {
96 /* Invalid instructions usually lead to GPU hangs, which can make
97 * getting the actual invalid instruction hard. Abort here so that we
98 * can find the problem.
99 */
100 abort();
101 }
102 }
103
104 }