Skip to content

Commit 60cb550

Browse files
authored
Rollup merge of #145004 - bjorn3:remove_unused_fields, r=WaffleLapkin
Couple of minor cleanups
2 parents 65e2a8b + 8f648d7 commit 60cb550

File tree

5 files changed

+37
-51
lines changed

5 files changed

+37
-51
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ pub(crate) fn codegen(
862862
.generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name);
863863
let thin_bc =
864864
module.thin_lto_buffer.as_deref().expect("cannot find embedded bitcode");
865-
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, &thin_bc);
865+
embed_bitcode(cgcx, llcx, llmod, &thin_bc);
866866
}
867867
}
868868

@@ -1058,7 +1058,6 @@ fn embed_bitcode(
10581058
cgcx: &CodegenContext<LlvmCodegenBackend>,
10591059
llcx: &llvm::Context,
10601060
llmod: &llvm::Module,
1061-
cmdline: &str,
10621061
bitcode: &[u8],
10631062
) {
10641063
// We're adding custom sections to the output object file, but we definitely
@@ -1074,7 +1073,9 @@ fn embed_bitcode(
10741073
// * Mach-O - this is for macOS. Inspecting the source code for the native
10751074
// linker here shows that the `.llvmbc` and `.llvmcmd` sections are
10761075
// automatically skipped by the linker. In that case there's nothing extra
1077-
// that we need to do here.
1076+
// that we need to do here. We do need to make sure that the
1077+
// `__LLVM,__cmdline` section exists even though it is empty as otherwise
1078+
// ld64 rejects the object file.
10781079
//
10791080
// * Wasm - the native LLD linker is hard-coded to skip `.llvmbc` and
10801081
// `.llvmcmd` sections, so there's nothing extra we need to do.
@@ -1111,7 +1112,7 @@ fn embed_bitcode(
11111112
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
11121113
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
11131114

1114-
let llconst = common::bytes_in_context(llcx, cmdline.as_bytes());
1115+
let llconst = common::bytes_in_context(llcx, &[]);
11151116
let llglobal = llvm::add_global(llmod, common::val_ty(llconst), c"rustc.embedded.cmdline");
11161117
llvm::set_initializer(llglobal, llconst);
11171118
let section = if cgcx.target_is_like_darwin {
@@ -1128,7 +1129,7 @@ fn embed_bitcode(
11281129
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
11291130
let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode);
11301131
llvm::append_module_inline_asm(llmod, &asm);
1131-
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, cmdline.as_bytes());
1132+
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, &[]);
11321133
llvm::append_module_inline_asm(llmod, &asm);
11331134
}
11341135
}

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ pub struct ModuleConfig {
7575
/// Names of additional optimization passes to run.
7676
pub passes: Vec<String>,
7777
/// Some(level) to optimize at a certain level, or None to run
78-
/// absolutely no optimizations (used for the metadata module).
78+
/// absolutely no optimizations (used for the allocator module).
7979
pub opt_level: Option<config::OptLevel>,
8080

81-
/// Some(level) to optimize binary size, or None to not affect program size.
82-
pub opt_size: Option<config::OptLevel>,
83-
8481
pub pgo_gen: SwitchWithOptPath,
8582
pub pgo_use: Option<PathBuf>,
8683
pub pgo_sample_use: Option<PathBuf>,
@@ -101,15 +98,13 @@ pub struct ModuleConfig {
10198
pub emit_obj: EmitObj,
10299
pub emit_thin_lto: bool,
103100
pub emit_thin_lto_summary: bool,
104-
pub bc_cmdline: String,
105101

106102
// Miscellaneous flags. These are mostly copied from command-line
107103
// options.
108104
pub verify_llvm_ir: bool,
109105
pub lint_llvm_ir: bool,
110106
pub no_prepopulate_passes: bool,
111107
pub no_builtins: bool,
112-
pub time_module: bool,
113108
pub vectorize_loop: bool,
114109
pub vectorize_slp: bool,
115110
pub merge_functions: bool,
@@ -170,7 +165,6 @@ impl ModuleConfig {
170165
passes: if_regular!(sess.opts.cg.passes.clone(), vec![]),
171166

172167
opt_level: opt_level_and_size,
173-
opt_size: opt_level_and_size,
174168

175169
pgo_gen: if_regular!(
176170
sess.opts.cg.profile_generate.clone(),
@@ -220,17 +214,12 @@ impl ModuleConfig {
220214
sess.opts.output_types.contains_key(&OutputType::ThinLinkBitcode),
221215
false
222216
),
223-
bc_cmdline: sess.target.bitcode_llvm_cmdline.to_string(),
224217

225218
verify_llvm_ir: sess.verify_llvm_ir(),
226219
lint_llvm_ir: sess.opts.unstable_opts.lint_llvm_ir,
227220
no_prepopulate_passes: sess.opts.cg.no_prepopulate_passes,
228221
no_builtins: no_builtins || sess.target.no_builtins,
229222

230-
// Exclude metadata and allocator modules from time_passes output,
231-
// since they throw off the "LLVM passes" measurement.
232-
time_module: if_regular!(true, false),
233-
234223
// Copy what clang does by turning on loop vectorization at O2 and
235224
// slp vectorization at O3.
236225
vectorize_loop: !sess.opts.cg.no_vectorize_loops
@@ -1726,7 +1715,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
17261715
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
17271716
work: WorkItem<B>,
17281717
) {
1729-
if cgcx.config(work.module_kind()).time_module && llvm_start_time.is_none() {
1718+
if llvm_start_time.is_none() {
17301719
*llvm_start_time = Some(cgcx.prof.verbose_generic_activity("LLVM_passes"));
17311720
}
17321721

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -680,33 +680,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
680680

681681
let ongoing_codegen = start_async_codegen(backend.clone(), tcx, target_cpu);
682682

683-
// Codegen an allocator shim, if necessary.
684-
if let Some(kind) = allocator_kind_for_codegen(tcx) {
685-
let llmod_id =
686-
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
687-
let module_llvm = tcx.sess.time("write_allocator_module", || {
688-
backend.codegen_allocator(
689-
tcx,
690-
&llmod_id,
691-
kind,
692-
// If allocator_kind is Some then alloc_error_handler_kind must
693-
// also be Some.
694-
tcx.alloc_error_handler_kind(()).unwrap(),
695-
)
696-
});
697-
698-
ongoing_codegen.wait_for_signal_to_codegen_item();
699-
ongoing_codegen.check_for_errors(tcx.sess);
700-
701-
// These modules are generally cheap and won't throw off scheduling.
702-
let cost = 0;
703-
submit_codegened_module_to_llvm(
704-
&ongoing_codegen.coordinator,
705-
ModuleCodegen::new_allocator(llmod_id, module_llvm),
706-
cost,
707-
);
708-
}
709-
710683
// For better throughput during parallel processing by LLVM, we used to sort
711684
// CGUs largest to smallest. This would lead to better thread utilization
712685
// by, for example, preventing a large CGU from being processed last and
@@ -822,6 +795,35 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
822795
}
823796
}
824797

798+
// Codegen an allocator shim, if necessary.
799+
// Do this last to ensure the LLVM_passes timer doesn't start while no CGUs have been codegened
800+
// yet for the backend to optimize.
801+
if let Some(kind) = allocator_kind_for_codegen(tcx) {
802+
let llmod_id =
803+
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
804+
let module_llvm = tcx.sess.time("write_allocator_module", || {
805+
backend.codegen_allocator(
806+
tcx,
807+
&llmod_id,
808+
kind,
809+
// If allocator_kind is Some then alloc_error_handler_kind must
810+
// also be Some.
811+
tcx.alloc_error_handler_kind(()).unwrap(),
812+
)
813+
});
814+
815+
ongoing_codegen.wait_for_signal_to_codegen_item();
816+
ongoing_codegen.check_for_errors(tcx.sess);
817+
818+
// These modules are generally cheap and won't throw off scheduling.
819+
let cost = 0;
820+
submit_codegened_module_to_llvm(
821+
&ongoing_codegen.coordinator,
822+
ModuleCodegen::new_allocator(llmod_id, module_llvm),
823+
cost,
824+
);
825+
}
826+
825827
ongoing_codegen.codegen_finished(tcx);
826828

827829
// Since the main thread is sometimes blocked during codegen, we keep track

compiler/rustc_target/src/spec/json.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ impl Target {
168168
forward!(main_needs_argc_argv);
169169
forward!(has_thread_local);
170170
forward!(obj_is_bitcode);
171-
forward!(bitcode_llvm_cmdline);
172171
forward_opt!(max_atomic_width);
173172
forward_opt!(min_atomic_width);
174173
forward!(atomic_cas);
@@ -361,7 +360,6 @@ impl ToJson for Target {
361360
target_option_val!(main_needs_argc_argv);
362361
target_option_val!(has_thread_local);
363362
target_option_val!(obj_is_bitcode);
364-
target_option_val!(bitcode_llvm_cmdline);
365363
target_option_val!(min_atomic_width);
366364
target_option_val!(max_atomic_width);
367365
target_option_val!(atomic_cas);
@@ -555,7 +553,6 @@ struct TargetSpecJson {
555553
main_needs_argc_argv: Option<bool>,
556554
has_thread_local: Option<bool>,
557555
obj_is_bitcode: Option<bool>,
558-
bitcode_llvm_cmdline: Option<StaticCow<str>>,
559556
max_atomic_width: Option<u64>,
560557
min_atomic_width: Option<u64>,
561558
atomic_cas: Option<bool>,

compiler/rustc_target/src/spec/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,8 +2624,6 @@ pub struct TargetOptions {
26242624
/// If we give emcc .o files that are actually .bc files it
26252625
/// will 'just work'.
26262626
pub obj_is_bitcode: bool,
2627-
/// Content of the LLVM cmdline section associated with embedded bitcode.
2628-
pub bitcode_llvm_cmdline: StaticCow<str>,
26292627

26302628
/// Don't use this field; instead use the `.min_atomic_width()` method.
26312629
pub min_atomic_width: Option<u64>,
@@ -2989,7 +2987,6 @@ impl Default for TargetOptions {
29892987
allow_asm: true,
29902988
has_thread_local: false,
29912989
obj_is_bitcode: false,
2992-
bitcode_llvm_cmdline: "".into(),
29932990
min_atomic_width: None,
29942991
max_atomic_width: None,
29952992
atomic_cas: true,

0 commit comments

Comments
 (0)