Avoid Cell in CodegenCx

This commit is contained in:
bjorn3 2024-11-21 12:49:45 +00:00
parent 5d5cd2a22b
commit 56a64baa03
2 changed files with 8 additions and 12 deletions

View file

@ -102,13 +102,12 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
// Pass a wrapper rather than the function itself as the function itself may not
// be exported from the main codegen unit and may thus be unreachable from the
// object file created by an external assembler.
let inline_asm_index = fx.cx.inline_asm_index.get();
fx.cx.inline_asm_index.set(inline_asm_index + 1);
let wrapper_name = format!(
"__inline_asm_{}_wrapper_n{}",
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
inline_asm_index
fx.cx.inline_asm_index
);
fx.cx.inline_asm_index += 1;
let sig =
get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance);
create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name);
@ -167,13 +166,12 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>(
asm_gen.allocate_registers();
asm_gen.allocate_stack_slots();
let inline_asm_index = fx.cx.inline_asm_index.get();
fx.cx.inline_asm_index.set(inline_asm_index + 1);
let asm_name = format!(
"__inline_asm_{}_n{}",
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
inline_asm_index
fx.cx.inline_asm_index
);
fx.cx.inline_asm_index += 1;
let generated_asm = asm_gen.generate_asm_wrapper(&asm_name);
fx.cx.global_asm.push_str(&generated_asm);
@ -266,13 +264,12 @@ pub(crate) fn codegen_naked_asm<'tcx>(
// Pass a wrapper rather than the function itself as the function itself may not
// be exported from the main codegen unit and may thus be unreachable from the
// object file created by an external assembler.
let inline_asm_index = cx.inline_asm_index.get();
cx.inline_asm_index.set(inline_asm_index + 1);
let wrapper_name = format!(
"__inline_asm_{}_wrapper_n{}",
cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
inline_asm_index
cx.inline_asm_index
);
cx.inline_asm_index += 1;
let sig =
get_function_sig(tcx, module.target_config().default_call_conv, instance);
create_wrapper_function(module, sig, &wrapper_name, symbol.name);

View file

@ -34,7 +34,6 @@ extern crate rustc_target;
extern crate rustc_driver;
use std::any::Any;
use std::cell::Cell;
use std::env;
use std::sync::Arc;
@ -128,7 +127,7 @@ struct CodegenCx {
output_filenames: Arc<OutputFilenames>,
should_write_ir: bool,
global_asm: String,
inline_asm_index: Cell<usize>,
inline_asm_index: usize,
debug_context: Option<DebugContext>,
cgu_name: Symbol,
}
@ -147,7 +146,7 @@ impl CodegenCx {
output_filenames: tcx.output_filenames(()).clone(),
should_write_ir: crate::pretty_clif::should_write_ir(tcx),
global_asm: String::new(),
inline_asm_index: Cell::new(0),
inline_asm_index: 0,
debug_context,
cgu_name,
}