#include "ac_llvm_util.h"
#include <llvm/ADT/StringRef.h>
+#if LLVM_VERSION_MAJOR >= 11
+#include <llvm/MC/MCDisassembler/MCDisassembler.h>
+#endif
namespace aco {
{
char path[] = "/tmp/fileXXXXXX";
char line[2048], command[128];
+ const char *gpu_type;
FILE *p;
int fd;
goto fail;
}
- sprintf(command, "clrxdisasm --gpuType=%s -r %s",
- program->chip_class == GFX6 ? "gfx600" : "gfx700", path);
+ /* Determine the GPU type for CLRXdisasm. Use the family for GFX6 chips
+ * because it doesn't allow to use gfx600 directly.
+ */
+ switch (program->chip_class) {
+ case GFX6:
+ switch (program->family) {
+ case CHIP_TAHITI:
+ gpu_type = "tahiti";
+ break;
+ case CHIP_PITCAIRN:
+ gpu_type = "pitcairn";
+ break;
+ case CHIP_VERDE:
+ gpu_type = "capeverde";
+ break;
+ case CHIP_OLAND:
+ gpu_type = "oland";
+ break;
+ case CHIP_HAINAN:
+ gpu_type = "hainan";
+ break;
+ default:
+ unreachable("Invalid GFX6 family!");
+ }
+ break;
+ case GFX7:
+ gpu_type = "gfx700";
+ break;
+ default:
+ unreachable("Invalid chip class!");
+ }
+
+ sprintf(command, "clrxdisasm --gpuType=%s -r %s", gpu_type, path);
p = popen(command, "r");
if (p) {
- while (fgets(line, sizeof(line), p))
+ if (!fgets(line, sizeof(line), p)) {
+ out << "clrxdisasm not found\n";
+ pclose(p);
+ goto fail;
+ }
+
+ do {
out << line;
+ } while (fgets(line, sizeof(line), p));
+
pclose(p);
}
referenced_blocks[succ] = true;
}
+ #if LLVM_VERSION_MAJOR >= 11
+ std::vector<llvm::SymbolInfoTy> symbols;
+ #else
std::vector<std::tuple<uint64_t, llvm::StringRef, uint8_t>> symbols;
+ #endif
std::vector<std::array<char,16>> block_names;
block_names.reserve(program->blocks.size());
for (Block& block : program->blocks) {
/* mask out src2 on v_writelane_b32 */
if (((program->chip_class == GFX8 || program->chip_class == GFX9) && (binary[pos] & 0xffff8000) == 0xd28a0000) ||
- (program->chip_class == GFX10 && (binary[pos] & 0xffff8000) == 0xd7610000)) {
+ (program->chip_class >= GFX10 && (binary[pos] & 0xffff8000) == 0xd7610000)) {
binary[pos+1] = binary[pos+1] & 0xF803FFFF;
}
size_t new_pos;
const int align_width = 60;
- if (!l && program->chip_class == GFX9 && ((binary[pos] & 0xffff8000) == 0xd1348000)) { /* not actually an invalid instruction */
- out << std::left << std::setw(align_width) << std::setfill(' ') << "\tv_add_u32_e64 + clamp";
+ if (!l &&
+ ((program->chip_class >= GFX9 && (binary[pos] & 0xffff8000) == 0xd1348000) || /* v_add_u32_e64 + clamp */
+ (program->chip_class >= GFX10 && (binary[pos] & 0xffff8000) == 0xd7038000) || /* v_add_u16_e64 + clamp */
+ (program->chip_class <= GFX9 && (binary[pos] & 0xffff8000) == 0xd1268000)) /* v_add_u16_e64 + clamp */) {
+ out << std::left << std::setw(align_width) << std::setfill(' ') << "\tinteger addition + clamp";
+ bool has_literal = program->chip_class >= GFX10 &&
+ (((binary[pos+1] & 0x1ff) == 0xff) || (((binary[pos+1] >> 9) & 0x1ff) == 0xff));
+ new_pos = pos + 2 + has_literal;
+ } else if (program->chip_class >= GFX10 && l == 4 && ((binary[pos] & 0xfe0001ff) == 0x020000f9)) {
+ out << std::left << std::setw(align_width) << std::setfill(' ') << "\tv_cndmask_b32 + sdwa";
new_pos = pos + 2;
} else if (!l) {
out << std::left << std::setw(align_width) << std::setfill(' ') << "(invalid instruction)";