Skip to content

Commit 1bbff0c

Browse files
committed
change pointer_patching_diff
1 parent c8cfd3f commit 1bbff0c

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/pointer_patching.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,17 @@ end
155155

156156
llvmeltype(x::LLVM.Value) = eltype(LLVM.llvmtype(x))
157157

158-
function pointer_patching_diff(mod::LLVM.Module, path1=tempname(), path2=tempname(); show_reloc_table=false)
158+
function pointer_patching_diff(f, tt, path1=tempname(), path2=tempname(); show_reloc_table=false)
159+
tm = GPUCompiler.llvm_machine(NativeCompilerTarget())
160+
job, kwargs = native_job(f, tt; name=GPUCompiler.safe_name(repr(f)))
161+
#Get LLVM to generated a module of code for us. We don't want GPUCompiler's optimization passes.
162+
mod, meta = GPUCompiler.JuliaContext() do context
163+
GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false, optimize=false, ctx=context)
164+
end
165+
# Use Enzyme's annotation and optimization pipeline
166+
annotate!(mod)
167+
optimize!(mod, tm)
168+
159169
s1 = string(mod)
160170
write(path1, s1)
161171

@@ -167,12 +177,9 @@ function pointer_patching_diff(mod::LLVM.Module, path1=tempname(), path2=tempnam
167177
s2 = string(mod)
168178
write(path2, s2)
169179

170-
try
171-
# this always ends in an error for me for some reason
172-
run(`diff $path1 $path2`)
173-
catch e;
174-
nothing
175-
end
180+
pdiff = run(Cmd(`diff $path1 $path2`, ignorestatus=true))
181+
pdiff.exitcode == 2 && error("Showing diff caused an error")
182+
nothing
176183
end
177184

178185

0 commit comments

Comments
 (0)