@@ -96,17 +96,10 @@ runtime_slug(@nospecialize(job::CompilerJob{PTXCompilerTarget})) =
9696 " -debuginfo=$(Int (llvm_debug_info (job))) " *
9797 " -exitable=$(job. config. target. exitable) "
9898
99- function process_module! (@nospecialize (job:: CompilerJob{PTXCompilerTarget} ), mod:: LLVM.Module )
99+ function finish_module! (@nospecialize (job:: CompilerJob{PTXCompilerTarget} ),
100+ mod:: LLVM.Module , entry:: LLVM.Function )
100101 ctx = context (mod)
101102
102- # calling convention
103- if LLVM. version () >= v " 8"
104- for f in functions (mod)
105- # JuliaGPU/GPUCompiler.jl#97
106- # callconv!(f, LLVM.API.LLVMPTXDeviceCallConv)
107- end
108- end
109-
110103 # emit the device capability and ptx isa version as constants in the module. this makes
111104 # it possible to 'query' these in device code, relying on LLVM to optimize the checks
112105 # away and generate static code. note that we only do so if there's actual uses of these
@@ -122,35 +115,40 @@ function process_module!(@nospecialize(job::CompilerJob{PTXCompilerTarget}), mod
122115 linkage! (gv, LLVM. API. LLVMPrivateLinkage)
123116 end
124117 end
125- end
126118
127- function process_entry! (@nospecialize (job:: CompilerJob{PTXCompilerTarget} ),
128- mod:: LLVM.Module , entry:: LLVM.Function )
129- entry = invoke (process_entry!, Tuple{CompilerJob, LLVM. Module, LLVM. Function}, job, mod, entry)
119+ # update calling convention
120+ if LLVM. version () >= v " 8"
121+ for f in functions (mod)
122+ # JuliaGPU/GPUCompiler.jl#97
123+ # callconv!(f, LLVM.API.LLVMPTXDeviceCallConv)
124+ end
125+ end
126+ if job. config. kernel && LLVM. version () >= v " 8"
127+ callconv! (entry, LLVM. API. LLVMPTXKernelCallConv)
128+ end
130129
131130 if job. config. kernel
132- if LLVM. version () >= v " 8"
133- # calling convention
134- callconv! (entry, LLVM. API. LLVMPTXKernelCallConv)
135- end
131+ # work around bad byval codegen (JuliaGPU/GPUCompiler.jl#92)
132+ entry = lower_byval (job, mod, entry)
136133 end
137134
138- return entry
139- end
135+ @dispose pm= ModulePassManager () begin
136+ # hide `unreachable` from LLVM so that it doesn't introduce divergent control flow
137+ if ! job. config. target. unreachable
138+ add! (pm, FunctionPass (" HideUnreachable" , hide_unreachable!))
139+ end
140140
141- function add_lowering_passes! (@nospecialize (job:: CompilerJob{PTXCompilerTarget} ),
142- pm:: LLVM.PassManager )
143- # hide `unreachable` from LLVM so that it doesn't introduce divergent control flow
144- if ! job. config. target. unreachable
145- add! (pm, FunctionPass (" HideUnreachable" , hide_unreachable!))
146- end
141+ # even if we support `unreachable`, we still prefer `exit` to `trap`
142+ add! (pm, ModulePass (" HideTrap" , hide_trap!))
147143
148- # even if we support `unreachable`, we still prefer `exit` to `trap`
149- add! (pm, ModulePass (" HideTrap" , hide_trap!))
144+ # we emit properties (of the device and ptx isa) as private global constants,
145+ # so run the optimizer so that they are inlined before the rest of the optimizer runs.
146+ global_optimizer! (pm)
150147
151- # we emit properties (of the device and ptx isa) as private global constants,
152- # so run the optimizer so that they are inlined before the rest of the optimizer runs.
153- global_optimizer! (pm)
148+ run! (pm, mod)
149+ end
150+
151+ return entry
154152end
155153
156154function optimize_module! (@nospecialize (job:: CompilerJob{PTXCompilerTarget} ),
@@ -187,23 +185,9 @@ function optimize_module!(@nospecialize(job::CompilerJob{PTXCompilerTarget}),
187185 end
188186end
189187
190- function finish_module! (@nospecialize (job:: CompilerJob{PTXCompilerTarget} ),
191- mod:: LLVM.Module , entry:: LLVM.Function )
192- ctx = context (mod)
193- entry = invoke (finish_module!, Tuple{CompilerJob, LLVM. Module, LLVM. Function}, job, mod, entry)
194-
195- if job. config. kernel
196- # work around bad byval codegen (JuliaGPU/GPUCompiler.jl#92)
197- entry = lower_byval (job, mod, entry)
198- end
199-
200- return entry
201- end
202-
203188function finish_ir! (@nospecialize (job:: CompilerJob{PTXCompilerTarget} ),
204189 mod:: LLVM.Module , entry:: LLVM.Function )
205190 ctx = context (mod)
206- entry = invoke (finish_ir!, Tuple{CompilerJob, LLVM. Module, LLVM. Function}, job, mod, entry)
207191
208192 if job. config. kernel
209193 # add metadata annotations for the assembler to the module
0 commit comments