vulkan/wsi: disable the hardware cursor
[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, std::ostream& out)
13 {
14 if (program->chip_class <= GFX7) {
15 out << "Disassembly for this GPU currently not supported." << std::endl;
16 return;
17 }
18 std::vector<bool> referenced_blocks(program->blocks.size());
19 referenced_blocks[0] = true;
20 for (Block& block : program->blocks) {
21 for (unsigned succ : block.linear_succs)
22 referenced_blocks[succ] = true;
23 }
24
25 std::vector<std::tuple<uint64_t, llvm::StringRef, uint8_t>> symbols;
26 std::vector<std::array<char,16>> block_names;
27 block_names.reserve(program->blocks.size());
28 for (Block& block : program->blocks) {
29 if (!referenced_blocks[block.index])
30 continue;
31 std::array<char, 16> name;
32 sprintf(name.data(), "BB%u", block.index);
33 block_names.push_back(name);
34 symbols.emplace_back(block.offset * 4, llvm::StringRef(block_names[block_names.size() - 1].data()), 0);
35 }
36
37 const char *features = "";
38 if (program->chip_class >= GFX10 && program->wave_size == 64) {
39 features = "+wavefrontsize64";
40 }
41
42 LLVMDisasmContextRef disasm = LLVMCreateDisasmCPUFeatures("amdgcn-mesa-mesa3d",
43 ac_get_llvm_processor_name(program->family),
44 features,
45 &symbols, 0, NULL, NULL);
46
47 char outline[1024];
48 size_t pos = 0;
49 bool invalid = false;
50 unsigned next_block = 0;
51 while (pos < exec_size) {
52 while (next_block < program->blocks.size() && pos == program->blocks[next_block].offset) {
53 if (referenced_blocks[next_block])
54 out << "BB" << std::dec << next_block << ":" << std::endl;
55 next_block++;
56 }
57
58 /* mask out src2 on v_writelane_b32 */
59 if (((program->chip_class == GFX8 || program->chip_class == GFX9) && (binary[pos] & 0xffff8000) == 0xd28a0000) ||
60 (program->chip_class == GFX10 && (binary[pos] & 0xffff8000) == 0xd7610000)) {
61 binary[pos+1] = binary[pos+1] & 0xF803FFFF;
62 }
63
64 size_t l = LLVMDisasmInstruction(disasm, (uint8_t *) &binary[pos],
65 (exec_size - pos) * sizeof(uint32_t), pos * 4,
66 outline, sizeof(outline));
67
68 size_t new_pos;
69 const int align_width = 60;
70 if (!l && program->chip_class == GFX9 && ((binary[pos] & 0xffff8000) == 0xd1348000)) { /* not actually an invalid instruction */
71 out << std::left << std::setw(align_width) << std::setfill(' ') << "\tv_add_u32_e64 + clamp";
72 new_pos = pos + 2;
73 } else if (!l) {
74 out << std::left << std::setw(align_width) << std::setfill(' ') << "(invalid instruction)";
75 new_pos = pos + 1;
76 invalid = true;
77 } else {
78 out << std::left << std::setw(align_width) << std::setfill(' ') << outline;
79 assert(l % 4 == 0);
80 new_pos = pos + l / 4;
81 }
82 out << std::right;
83
84 out << " ;";
85 for (; pos < new_pos; pos++)
86 out << " " << std::setfill('0') << std::setw(8) << std::hex << binary[pos];
87 out << std::endl;
88 }
89 out << std::setfill(' ') << std::setw(0) << std::dec;
90 assert(next_block == program->blocks.size());
91
92 LLVMDisasmDispose(disasm);
93
94 if (program->constant_data.size()) {
95 out << std::endl << "/* constant data */" << std::endl;
96 for (unsigned i = 0; i < program->constant_data.size(); i += 32) {
97 out << '[' << std::setw(6) << std::setfill('0') << std::dec << i << ']';
98 unsigned line_size = std::min<size_t>(program->constant_data.size() - i, 32);
99 for (unsigned j = 0; j < line_size; j += 4) {
100 unsigned size = std::min<size_t>(program->constant_data.size() - (i + j), 4);
101 uint32_t v = 0;
102 memcpy(&v, &program->constant_data[i + j], size);
103 out << " " << std::setw(8) << std::setfill('0') << std::hex << v;
104 }
105 out << std::endl;
106 }
107 }
108
109 out << std::setfill(' ') << std::setw(0) << std::dec;
110
111 if (invalid) {
112 /* Invalid instructions usually lead to GPU hangs, which can make
113 * getting the actual invalid instruction hard. Abort here so that we
114 * can find the problem.
115 */
116 abort();
117 }
118 }
119
120 }