1
Fork 0

Let LtoModuleCodegen::optimize take self by value

This commit is contained in:
bjorn3 2022-04-30 20:51:17 +02:00
parent 336bb0afea
commit ee94ff254a
6 changed files with 13 additions and 14 deletions

View file

@ -42,7 +42,7 @@ pub struct ThinShared<B: WriteBackendMethods> {
pub enum LtoModuleCodegen<B: WriteBackendMethods> {
Fat {
module: Option<ModuleCodegen<B::Module>>,
module: ModuleCodegen<B::Module>,
_serialized_bitcode: Vec<SerializedModule<B::ModuleBuffer>>,
},
@ -64,19 +64,18 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
/// It's intended that the module returned is immediately code generated and
/// dropped, and then this LTO module is dropped.
pub unsafe fn optimize(
&mut self,
self,
cgcx: &CodegenContext<B>,
) -> Result<ModuleCodegen<B::Module>, FatalError> {
match *self {
LtoModuleCodegen::Fat { ref mut module, .. } => {
let module = module.take().unwrap();
match self {
LtoModuleCodegen::Fat { module, .. } => {
{
let config = cgcx.config(module.kind);
B::run_lto_pass_manager(cgcx, &module, config, false)?;
B::optimize_fat(cgcx, &module, config)?;
}
Ok(module)
}
LtoModuleCodegen::Thin(ref mut thin) => B::optimize_thin(cgcx, thin),
LtoModuleCodegen::Thin(thin) => B::optimize_thin(cgcx, thin),
}
}