|
1 | 1 | //! Final steps in codegen, coalescing modules and feeding them to libnvvm. |
2 | 2 |
|
| 3 | +use crate::back::demangle_callback; |
3 | 4 | use crate::builder::unnamed; |
| 5 | +use crate::context::CodegenArgs; |
4 | 6 | use crate::llvm::*; |
5 | 7 | use crate::lto::ThinBuffer; |
6 | 8 | use find_cuda_helper::find_cuda_root; |
7 | 9 | use nvvm::*; |
8 | 10 | use rustc_codegen_ssa::traits::ThinBufferMethods; |
| 11 | +use rustc_fs_util::path_to_c_string; |
9 | 12 | use rustc_session::{config::DebugInfo, Session}; |
10 | 13 | use std::ffi::OsStr; |
11 | 14 | use std::fmt::Display; |
@@ -50,7 +53,7 @@ impl Display for CodegenErr { |
50 | 53 | /// Note that this will implicitly try to find libdevice and add it, so don't do that |
51 | 54 | /// step before this. It will fatal error if it cannot find it. |
52 | 55 | pub fn codegen_bitcode_modules( |
53 | | - opts: &[NvvmOption], |
| 56 | + args: &CodegenArgs, |
54 | 57 | sess: &Session, |
55 | 58 | modules: Vec<Vec<u8>>, |
56 | 59 | llcx: &Context, |
@@ -89,7 +92,16 @@ pub fn codegen_bitcode_modules( |
89 | 92 | let node = LLVMMDNodeInContext(llcx, vals.as_ptr(), vals.len() as u32); |
90 | 93 |
|
91 | 94 | LLVMAddNamedMetadataOperand(module, "nvvmir.version\0".as_ptr().cast(), node); |
| 95 | + |
| 96 | + if let Some(path) = &args.final_module_path { |
| 97 | + let out_c = path_to_c_string(path); |
| 98 | + let result = LLVMRustPrintModule(module, out_c.as_ptr(), demangle_callback); |
| 99 | + result |
| 100 | + .into_result() |
| 101 | + .expect("Failed to write final llvm module output"); |
| 102 | + } |
92 | 103 | } |
| 104 | + |
93 | 105 | let buf = ThinBuffer::new(module); |
94 | 106 |
|
95 | 107 | prog.add_module(buf.data(), "merged".to_string())?; |
@@ -122,7 +134,7 @@ pub fn codegen_bitcode_modules( |
122 | 134 | ); |
123 | 135 | } |
124 | 136 |
|
125 | | - let res = match prog.compile(opts) { |
| 137 | + let res = match prog.compile(&args.nvvm_options) { |
126 | 138 | Ok(b) => b, |
127 | 139 | Err(error) => { |
128 | 140 | // this should never happen, if it does, something went really bad or its a bug on libnvvm's end |
|
0 commit comments