@@ -64,6 +64,8 @@ function enable_verifier!(pm, enable=true)
64
64
return pm
65
65
end
66
66
67
+ const DUMP_MLIR_DIR = Ref {Union{Nothing,String}} (nothing )
68
+
67
69
"""
68
70
run!(passManager, module)
69
71
@@ -76,16 +78,28 @@ function run!(pm::PassManager, mod::Module)
76
78
API. mlirPassManagerRun (pm, mod)
77
79
end )
78
80
if isfailure (status)
79
- dir = mktempdir ()
80
- path = joinpath (dir, " module.mlir" )
81
- open (path, " w" ) do io
82
- println (io, " // Pass pipeline:" )
83
- print (io, " // " )
84
- print_pass_pipeline (io, OpPassManager (pm))
85
- println (io)
86
- show (IOContext (io, :debug => true ), mod)
81
+ # If `DUMP_MLIR_DIR` is `nothing`, create a persistent new temp
82
+ # directory, otherwise use the provided path.
83
+ dir = if isnothing (DUMP_MLIR_DIR[])
84
+ mktempdir (; prefix= " reactant_" , cleanup= false )
85
+ else
86
+ DUMP_MLIR_DIR[]
87
+ end
88
+ try
89
+ # Make sure the directory exists
90
+ mkpath (dir)
91
+ path = tempname (dir; cleanup= false ) * " .mlir"
92
+ open (path, " w" ) do io
93
+ println (io, " // Pass pipeline:" )
94
+ print (io, " // " )
95
+ print_pass_pipeline (io, OpPassManager (pm))
96
+ println (io)
97
+ show (IOContext (io, :debug => true ), mod)
98
+ end
99
+ @error " Dumped module to " * path
100
+ catch err
101
+ @error " Couldn't save MLIR module" exception = err
87
102
end
88
- @error " Dumped module to " * path
89
103
throw (" failed to run pass manager on module" )
90
104
end
91
105
return mod
0 commit comments