Skip to content

Commit d34bfea

Browse files
committed
compile.h: make RUN_PASS's complex body into a function
1 parent 1898147 commit d34bfea

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

src/shady/compile.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,30 @@ void add_scheduler_source(const CompilerConfig* config, Module* dst) {
8787
destroy_ir_arena(get_module_arena(builtin_scheduler_mod));
8888
}
8989

90+
void run_pass_impl(CompilerConfig* config, Module** pmod, IrArena* initial_arena, RewritePass pass, String pass_name) {
91+
Module* old_mod = NULL;
92+
old_mod = *pmod;
93+
*pmod = pass(config, *pmod);
94+
(*pmod)->sealed = true;
95+
if (SHADY_RUN_VERIFY)
96+
verify_module(config, *pmod);
97+
if (get_module_arena(old_mod) != get_module_arena(*pmod) && get_module_arena(old_mod) != initial_arena)
98+
destroy_ir_arena(get_module_arena(old_mod));
99+
old_mod = *pmod;
100+
if (config->optimisations.cleanup.after_every_pass)
101+
*pmod = cleanup(config, *pmod);
102+
debugvv_print("After pass %s: \n", pass_name);
103+
log_module(DEBUGVV, config, *pmod);
104+
if (SHADY_RUN_VERIFY)
105+
verify_module(config, *pmod);
106+
if (get_module_arena(old_mod) != get_module_arena(*pmod) && get_module_arena(old_mod) != initial_arena)
107+
destroy_ir_arena(get_module_arena(old_mod));
108+
if (config->hooks.after_pass.fn)
109+
config->hooks.after_pass.fn(config->hooks.after_pass.uptr, pass_name, *pmod);
110+
}
111+
90112
CompilationResult run_compiler_passes(CompilerConfig* config, Module** pmod) {
91113
IrArena* initial_arena = (*pmod)->arena;
92-
Module* old_mod = NULL;
93114

94115
if (config->dynamic_scheduling) {
95116
*pmod = import(config, *pmod); // we don't want to mess with the original module

src/shady/compile.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,8 @@
1212
#define SHADY_RUN_VERIFY 1
1313
#endif
1414

15-
#define RUN_PASS(pass_name) { \
16-
old_mod = *pmod; \
17-
*pmod = pass_name(config, *pmod); \
18-
(*pmod)->sealed = true; \
19-
if (SHADY_RUN_VERIFY) \
20-
verify_module(config, *pmod); \
21-
if (get_module_arena(old_mod) != get_module_arena(*pmod) && get_module_arena(old_mod) != initial_arena) \
22-
destroy_ir_arena(get_module_arena(old_mod)); \
23-
old_mod = *pmod; \
24-
if (config->optimisations.cleanup.after_every_pass) \
25-
*pmod = cleanup(config, *pmod); \
26-
debugvv_print("After "#pass_name" pass: \n"); \
27-
log_module(DEBUGVV, config, *pmod); \
28-
if (SHADY_RUN_VERIFY) \
29-
verify_module(config, *pmod); \
30-
if (get_module_arena(old_mod) != get_module_arena(*pmod) && get_module_arena(old_mod) != initial_arena) \
31-
destroy_ir_arena(get_module_arena(old_mod)); \
32-
if (config->hooks.after_pass.fn) \
33-
config->hooks.after_pass.fn(config->hooks.after_pass.uptr, #pass_name, *pmod); \
34-
} \
15+
void run_pass_impl(CompilerConfig* config, Module** pmod, IrArena* initial_arena, RewritePass pass, String pass_name);
16+
17+
#define RUN_PASS(pass_name) run_pass_impl(config, pmod, initial_arena, pass_name, #pass_name);
3518

3619
#endif

src/shady/emit/c/emit_c.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ bool compare_node(Node**, Node**);
688688

689689
static Module* run_backend_specific_passes(CompilerConfig* config, CEmitterConfig* econfig, Module* initial_mod) {
690690
IrArena* initial_arena = initial_mod->arena;
691-
Module* old_mod = NULL;
692691
Module** pmod = &initial_mod;
693692

694693
// C lacks a nice way to express constants that can be used in type definitions afterwards, so let's just inline them all.

src/shady/emit/spirv/emit_spv.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ bool compare_string(const char** a, const char** b);
520520

521521
static Module* run_backend_specific_passes(CompilerConfig* config, Module* initial_mod) {
522522
IrArena* initial_arena = initial_mod->arena;
523-
Module* old_mod = NULL;
524523
Module** pmod = &initial_mod;
525524

526525
RUN_PASS(lower_entrypoint_args)

0 commit comments

Comments
 (0)