• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2024 Imagination Technologies Ltd.
3  *
4  * SPDX-License-Identifier: MIT
5  */
6 
7 /**
8  * \file pco_ir.c
9  *
10  * \brief PCO IR-specific functions.
11  */
12 
13 #include "pco.h"
14 #include "pco_internal.h"
15 #include "util/u_debug.h"
16 
17 #include <stdbool.h>
18 #include <stdio.h>
19 
pco_should_skip_pass(const char * pass)20 static inline bool pco_should_skip_pass(const char *pass)
21 {
22    return comma_separated_list_contains(pco_skip_passes, pass);
23 }
24 
25 #define PCO_PASS(progress, shader, pass, ...)                 \
26    do {                                                       \
27       if (pco_should_skip_pass(#pass)) {                      \
28          fprintf(stdout, "Skipping pass '%s'\n", #pass);      \
29          break;                                               \
30       }                                                       \
31                                                               \
32       if (pass(shader, ##__VA_ARGS__)) {                      \
33          UNUSED bool _;                                       \
34          progress = true;                                     \
35                                                               \
36          if (PCO_DEBUG(REINDEX))                              \
37             pco_index(shader, false);                         \
38                                                               \
39          pco_validate_shader(shader, "after " #pass);         \
40                                                               \
41          if (pco_should_print_shader_pass(shader))            \
42             pco_print_shader(shader, stdout, "after " #pass); \
43       }                                                       \
44    } while (0)
45 
46 /**
47  * \brief Runs passes on a PCO shader.
48  *
49  * \param[in] ctx PCO compiler context.
50  * \param[in,out] shader PCO shader.
51  */
pco_process_ir(pco_ctx * ctx,pco_shader * shader)52 void pco_process_ir(pco_ctx *ctx, pco_shader *shader)
53 {
54    pco_validate_shader(shader, "before passes");
55 
56    PCO_PASS(_, shader, pco_const_imms);
57    PCO_PASS(_, shader, pco_opt);
58    PCO_PASS(_, shader, pco_dce);
59    /* TODO: schedule after RA instead as e.g. vecs may no longer be the first
60     * time a drc result is used.
61     */
62    PCO_PASS(_, shader, pco_schedule);
63    PCO_PASS(_, shader, pco_ra);
64    PCO_PASS(_, shader, pco_end);
65    PCO_PASS(_, shader, pco_group_instrs);
66 
67    pco_validate_shader(shader, "after passes");
68 
69    if (pco_should_print_shader(shader))
70       pco_print_shader(shader, stdout, "after passes");
71 }
72