|
1 | 1 | use std::collections::BTreeMap; |
2 | 2 | use std::ffi::{CStr, CString}; |
3 | 3 | use std::fs::File; |
4 | | -use std::mem::ManuallyDrop; |
5 | 4 | use std::path::Path; |
6 | 5 | use std::sync::Arc; |
7 | 6 | use std::{io, iter, slice}; |
8 | 7 |
|
9 | 8 | use object::read::archive::ArchiveFile; |
10 | 9 | use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared}; |
11 | 10 | use rustc_codegen_ssa::back::symbol_export; |
12 | | -use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, TargetMachineFactoryConfig}; |
| 11 | +use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput}; |
13 | 12 | use rustc_codegen_ssa::traits::*; |
14 | 13 | use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file}; |
15 | 14 | use rustc_data_structures::fx::FxHashMap; |
@@ -706,18 +705,15 @@ pub(crate) unsafe fn optimize_thin_module( |
706 | 705 | let dcx = dcx.handle(); |
707 | 706 |
|
708 | 707 | let module_name = &thin_module.shared.module_names[thin_module.idx]; |
709 | | - let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap()); |
710 | | - let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(dcx, e))?; |
711 | 708 |
|
712 | 709 | // Right now the implementation we've got only works over serialized |
713 | 710 | // modules, so we create a fresh new LLVM context and parse the module |
714 | 711 | // into that context. One day, however, we may do this for upstream |
715 | 712 | // crates but for locally codegened modules we may be able to reuse |
716 | 713 | // that LLVM Context and Module. |
717 | | - let llcx = unsafe { llvm::LLVMRustContextCreate(cgcx.fewer_names) }; |
718 | | - let llmod_raw = parse_module(llcx, module_name, thin_module.data(), dcx)? as *const _; |
| 714 | + let module_llvm = ModuleLlvm::parse(cgcx, module_name, thin_module.data(), dcx)?; |
719 | 715 | let mut module = ModuleCodegen { |
720 | | - module_llvm: ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) }, |
| 716 | + module_llvm, |
721 | 717 | name: thin_module.name().to_string(), |
722 | 718 | kind: ModuleKind::Regular, |
723 | 719 | }; |
|
0 commit comments