MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / post_link_single_module

Function post_link_single_module

crates/rustc_codegen_spirv/src/link.rs:213–287  ·  view source on GitHub ↗
(
    sess: &Session,
    cg_args: &CodegenArgs,
    module: Module,
    out_filename: &Path,
    dump_prefix: Option<&OsStr>,
)

Source from the content-addressed store, hash-verified

211}
212
213fn post_link_single_module(
214 sess: &Session,
215 cg_args: &CodegenArgs,
216 module: Module,
217 out_filename: &Path,
218 dump_prefix: Option<&OsStr>,
219) {
220 cg_args.do_disassemble(&module);
221 let spv_binary = module.assemble();
222
223 if let Some(dir) = &cg_args.dump_post_link {
224 // FIXME(eddyb) rename `filename` with `file_path` to make this less confusing.
225 let out_filename_file_name = out_filename.file_name().unwrap();
226 let dump_path = match dump_prefix {
227 Some(prefix) => dir.join(prefix).with_extension(out_filename_file_name),
228 None => dir.join(out_filename_file_name),
229 };
230 std::fs::write(dump_path, spirv_tools::binary::from_binary(&spv_binary)).unwrap();
231 }
232
233 let val_options = spirv_tools::val::ValidatorOptions {
234 relax_struct_store: cg_args.relax_struct_store,
235 relax_logical_pointer: cg_args.relax_logical_pointer,
236 before_legalization: false,
237 relax_block_layout: cg_args.relax_block_layout,
238 uniform_buffer_standard_layout: cg_args.uniform_buffer_standard_layout,
239 scalar_block_layout: cg_args.scalar_block_layout,
240 skip_block_layout: cg_args.skip_block_layout,
241 max_limits: vec![],
242 };
243 let opt_options = spirv_tools::opt::Options {
244 validator_options: Some(val_options.clone()),
245 max_id_bound: None,
246 preserve_bindings: cg_args.preserve_bindings,
247 preserve_spec_constants: false,
248 };
249
250 let spv_binary = if sess.opts.optimize != OptLevel::No
251 || (sess.opts.debuginfo == DebugInfo::None && cg_args.spirv_metadata == SpirvMetadata::None)
252 {
253 if cg_args.run_spirv_opt {
254 let _timer = sess.timer("link_spirv_opt");
255 do_spirv_opt(sess, cg_args, spv_binary, out_filename, opt_options)
256 } else {
257 let reason = match (sess.opts.optimize, sess.opts.debuginfo == DebugInfo::None) {
258 (OptLevel::No, true) => "debuginfo=None".to_string(),
259 (optlevel, false) => format!("optlevel={optlevel:?}"),
260 (optlevel, true) => format!("optlevel={optlevel:?}, debuginfo=None"),
261 };
262 sess.warn(format!(
263 "`spirv-opt` should have ran ({reason}) but was disabled by `--no-spirv-opt`"
264 ));
265 spv_binary
266 }
267 } else {
268 spv_binary
269 };
270

Callers 1

link_exeFunction · 0.85

Calls 6

do_spirv_optFunction · 0.85
do_spirv_valFunction · 0.85
do_disassembleMethod · 0.80
struct_errMethod · 0.80
noteMethod · 0.80
emitMethod · 0.45

Tested by

no test coverage detected