Skip to content

Commit 56a64ba

Browse files
committed
Avoid Cell in CodegenCx
1 parent 5d5cd2a commit 56a64ba

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/inline_asm.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,12 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
102102
// Pass a wrapper rather than the function itself as the function itself may not
103103
// be exported from the main codegen unit and may thus be unreachable from the
104104
// object file created by an external assembler.
105-
let inline_asm_index = fx.cx.inline_asm_index.get();
106-
fx.cx.inline_asm_index.set(inline_asm_index + 1);
107105
let wrapper_name = format!(
108106
"__inline_asm_{}_wrapper_n{}",
109107
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
110-
inline_asm_index
108+
fx.cx.inline_asm_index
111109
);
110+
fx.cx.inline_asm_index += 1;
112111
let sig =
113112
get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance);
114113
create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name);
@@ -167,13 +166,12 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>(
167166
asm_gen.allocate_registers();
168167
asm_gen.allocate_stack_slots();
169168

170-
let inline_asm_index = fx.cx.inline_asm_index.get();
171-
fx.cx.inline_asm_index.set(inline_asm_index + 1);
172169
let asm_name = format!(
173170
"__inline_asm_{}_n{}",
174171
fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
175-
inline_asm_index
172+
fx.cx.inline_asm_index
176173
);
174+
fx.cx.inline_asm_index += 1;
177175

178176
let generated_asm = asm_gen.generate_asm_wrapper(&asm_name);
179177
fx.cx.global_asm.push_str(&generated_asm);
@@ -266,13 +264,12 @@ pub(crate) fn codegen_naked_asm<'tcx>(
266264
// Pass a wrapper rather than the function itself as the function itself may not
267265
// be exported from the main codegen unit and may thus be unreachable from the
268266
// object file created by an external assembler.
269-
let inline_asm_index = cx.inline_asm_index.get();
270-
cx.inline_asm_index.set(inline_asm_index + 1);
271267
let wrapper_name = format!(
272268
"__inline_asm_{}_wrapper_n{}",
273269
cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
274-
inline_asm_index
270+
cx.inline_asm_index
275271
);
272+
cx.inline_asm_index += 1;
276273
let sig =
277274
get_function_sig(tcx, module.target_config().default_call_conv, instance);
278275
create_wrapper_function(module, sig, &wrapper_name, symbol.name);

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extern crate rustc_target;
3434
extern crate rustc_driver;
3535

3636
use std::any::Any;
37-
use std::cell::Cell;
3837
use std::env;
3938
use std::sync::Arc;
4039

@@ -128,7 +127,7 @@ struct CodegenCx {
128127
output_filenames: Arc<OutputFilenames>,
129128
should_write_ir: bool,
130129
global_asm: String,
131-
inline_asm_index: Cell<usize>,
130+
inline_asm_index: usize,
132131
debug_context: Option<DebugContext>,
133132
cgu_name: Symbol,
134133
}
@@ -147,7 +146,7 @@ impl CodegenCx {
147146
output_filenames: tcx.output_filenames(()).clone(),
148147
should_write_ir: crate::pretty_clif::should_write_ir(tcx),
149148
global_asm: String::new(),
150-
inline_asm_index: Cell::new(0),
149+
inline_asm_index: 0,
151150
debug_context,
152151
cgu_name,
153152
}

0 commit comments

Comments
 (0)