1 /*
2 * Copyright © 2023 Advanced Micro Devices, Inc.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include "ac_debug.h"
8 #include <string.h>
9 #include <stdlib.h>
10
main(int argc,char ** argv)11 int main(int argc, char **argv)
12 {
13 if (argc < 3) {
14 fprintf(stderr, "Usage: [LLVM processor] [IB filenames]\n");
15 return 1;
16 }
17
18 const char *gpu = argv[1];
19 enum amd_gfx_level gfx_level;
20 enum radeon_family family = CHIP_UNKNOWN;
21
22 for (unsigned i = 0; i < CHIP_LAST; i++) {
23 if (!strcmp(gpu, ac_get_llvm_processor_name(i))) {
24 family = i;
25 gfx_level = ac_get_gfx_level(i);
26 break;
27 }
28 }
29
30 if (family == CHIP_UNKNOWN) {
31 fprintf(stderr, "Unknown LLVM processor.\n");
32 return 1;
33 }
34
35 for (unsigned i = 2; i < argc; i++) {
36 const char *filename = argv[i];
37
38 FILE *f = fopen(filename, "r");
39 if (!f) {
40 fprintf(stderr, "Can't open IB: %s\n", filename);
41 continue;
42 }
43
44 fseek(f, 0, SEEK_END);
45 int size = ftell(f);
46 fseek(f, 0, SEEK_SET);
47
48 uint32_t *ib = (uint32_t*)malloc(size);
49
50 if (fread(ib, size, 1, f) != 1) {
51 fprintf(stderr, "Can't read IB: %s\n", filename);
52 fclose(f);
53 free(ib);
54 continue;
55 }
56 fclose(f);
57
58 struct ac_ib_parser ib_parser = {
59 .f = stdout,
60 .ib = ib,
61 .num_dw = size / 4,
62 .gfx_level = gfx_level,
63 .family = family,
64 .ip_type = AMD_IP_GFX,
65 };
66
67 ac_parse_ib(&ib_parser, filename);
68 free(ib);
69 }
70
71 return 0;
72 }
73