Skip to content

Commit dafee5c

Browse files
committed
Remove global_asm from CodegenCx
1 parent b36dff6 commit dafee5c

File tree

7 files changed

+24
-15
lines changed

7 files changed

+24
-15
lines changed

src/base.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub(crate) struct CodegenedFunction {
2626
func: Function,
2727
clif_comments: CommentWriter,
2828
func_debug_cx: Option<FunctionDebugContext>,
29+
inline_asm: String,
2930
}
3031

3132
pub(crate) fn codegen_fn<'tcx>(
@@ -105,6 +106,7 @@ pub(crate) fn codegen_fn<'tcx>(
105106

106107
clif_comments,
107108
next_ssa_var: 0,
109+
inline_asm: String::new(),
108110
inline_asm_index: 0,
109111
};
110112

@@ -116,6 +118,7 @@ pub(crate) fn codegen_fn<'tcx>(
116118
let symbol_name = fx.symbol_name;
117119
let clif_comments = fx.clif_comments;
118120
let func_debug_cx = fx.func_debug_cx;
121+
let inline_asm = fx.inline_asm;
119122

120123
fx.constants_cx.finalize(fx.tcx, &mut *fx.module);
121124

@@ -133,7 +136,7 @@ pub(crate) fn codegen_fn<'tcx>(
133136
// Verify function
134137
verify_func(tcx, &clif_comments, &func);
135138

136-
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
139+
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx, inline_asm }
137140
}
138141

139142
pub(crate) fn compile_fn(
@@ -142,12 +145,14 @@ pub(crate) fn compile_fn(
142145
output_filenames: &OutputFilenames,
143146
cached_context: &mut Context,
144147
module: &mut dyn Module,
148+
global_asm: &mut String,
145149
codegened_func: CodegenedFunction,
146150
) {
147151
let _timer =
148152
profiler.generic_activity_with_arg("compile function", &*codegened_func.symbol_name);
149153

150154
let clif_comments = codegened_func.clif_comments;
155+
global_asm.push_str(&codegened_func.inline_asm);
151156

152157
// Store function in context
153158
let context = cached_context;

src/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
293293
/// This should only be accessed by `CPlace::new_var`.
294294
pub(crate) next_ssa_var: u32,
295295

296+
pub(crate) inline_asm: String,
296297
pub(crate) inline_asm_index: u32,
297298
}
298299

src/driver/aot.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ fn codegen_cgu_content(
512512
tcx: TyCtxt<'_>,
513513
module: &mut dyn Module,
514514
cgu_name: rustc_span::Symbol,
515-
) -> (CodegenCx, Vec<CodegenedFunction>) {
515+
) -> (CodegenCx, Vec<CodegenedFunction>, String) {
516516
let _timer = tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str());
517517

518518
let cgu = tcx.codegen_unit(cgu_name);
@@ -524,6 +524,7 @@ fn codegen_cgu_content(
524524
tcx.sess.opts.debuginfo != DebugInfo::None,
525525
cgu_name,
526526
);
527+
let mut global_asm = String::new();
527528
let mut type_dbg = TypeDebugContext::default();
528529
super::predefine_mono_items(tcx, module, &mono_items);
529530
let mut codegened_functions = vec![];
@@ -533,7 +534,7 @@ fn codegen_cgu_content(
533534
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED)
534535
{
535536
rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm(
536-
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
537+
&mut GlobalAsmContext { tcx, global_asm: &mut global_asm },
537538
instance,
538539
MonoItemData {
539540
linkage: RLinkage::External,
@@ -565,15 +566,15 @@ fn codegen_cgu_content(
565566
}
566567
MonoItem::GlobalAsm(item_id) => {
567568
rustc_codegen_ssa::base::codegen_global_asm(
568-
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
569+
&mut GlobalAsmContext { tcx, global_asm: &mut global_asm },
569570
item_id,
570571
);
571572
}
572573
}
573574
}
574575
crate::main_shim::maybe_create_entry_wrapper(tcx, module, false, cgu.is_primary());
575576

576-
(cx, codegened_functions)
577+
(cx, codegened_functions, global_asm)
577578
}
578579

579580
fn module_codegen(
@@ -586,7 +587,8 @@ fn module_codegen(
586587
) -> OngoingModuleCodegen {
587588
let mut module = make_module(tcx.sess, cgu_name.as_str().to_string());
588589

589-
let (mut cx, codegened_functions) = codegen_cgu_content(tcx, &mut module, cgu_name);
590+
let (mut cx, codegened_functions, mut global_asm) =
591+
codegen_cgu_content(tcx, &mut module, cgu_name);
590592

591593
let cgu_name = cgu_name.as_str().to_owned();
592594

@@ -610,6 +612,7 @@ fn module_codegen(
610612
&output_filenames,
611613
&mut cached_context,
612614
&mut module,
615+
&mut global_asm,
613616
codegened_func,
614617
);
615618
}
@@ -620,7 +623,7 @@ fn module_codegen(
620623
crate::global_asm::compile_global_asm(
621624
&global_asm_config,
622625
&cgu_name,
623-
&cx.global_asm,
626+
global_asm,
624627
invocation_temp.as_deref(),
625628
)
626629
})?;

src/driver/jit.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
8080
}
8181
});
8282

83-
if !cx.global_asm.is_empty() {
84-
tcx.dcx().fatal("Inline asm is not supported in JIT mode");
85-
}
86-
8783
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, true, true);
8884

8985
tcx.dcx().abort_if_errors();
@@ -153,14 +149,20 @@ fn codegen_and_compile_fn<'tcx>(
153149
module,
154150
instance,
155151
);
152+
153+
let mut global_asm = String::new();
156154
crate::base::compile_fn(
157155
cx,
158156
&tcx.prof,
159157
output_filenames,
160158
cached_context,
161159
module,
160+
&mut global_asm,
162161
codegened_func,
163162
);
163+
if !global_asm.is_empty() {
164+
tcx.dcx().fatal("Inline asm is not supported in JIT mode");
165+
}
164166
});
165167
}
166168

src/global_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl GlobalAsmConfig {
168168
pub(crate) fn compile_global_asm(
169169
config: &GlobalAsmConfig,
170170
cgu_name: &str,
171-
global_asm: &str,
171+
global_asm: String,
172172
invocation_temp: Option<&str>,
173173
) -> Result<Option<PathBuf>, String> {
174174
if global_asm.is_empty() {

src/inline_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>(
175175
fx.inline_asm_index += 1;
176176

177177
let generated_asm = asm_gen.generate_asm_wrapper(&asm_name);
178-
fx.cx.global_asm.push_str(&generated_asm);
178+
fx.inline_asm.push_str(&generated_asm);
179179

180180
let mut inputs = Vec::new();
181181
let mut outputs = Vec::new();

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
126126
/// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module).
127127
struct CodegenCx {
128128
should_write_ir: bool,
129-
global_asm: String,
130129
debug_context: Option<DebugContext>,
131130
cgu_name: Symbol,
132131
}
@@ -142,7 +141,6 @@ impl CodegenCx {
142141
};
143142
CodegenCx {
144143
should_write_ir: crate::pretty_clif::should_write_ir(tcx),
145-
global_asm: String::new(),
146144
debug_context,
147145
cgu_name,
148146
}

0 commit comments

Comments
 (0)