Skip to content

Commit dad85cf

Browse files
authored
Rollup merge of rust-lang#145004 - bjorn3:remove_unused_fields, r=WaffleLapkin
Couple of minor cleanups
2 parents ea47c11 + 6fbea4f commit dad85cf

File tree

5 files changed

+51
-83
lines changed

5 files changed

+51
-83
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 20 additions & 37 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,40 +1058,38 @@ 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
10651064
// do not want these custom sections to make their way into the final linked
1066-
// executable. The purpose of these custom sections is for tooling
1067-
// surrounding object files to work with the LLVM IR, if necessary. For
1068-
// example rustc's own LTO will look for LLVM IR inside of the object file
1069-
// in these sections by default.
1065+
// executable. The purpose of this custom section is for tooling surrounding
1066+
// object files to work with the LLVM IR, if necessary. For example rustc's
1067+
// own LTO will look for LLVM IR inside of the object file in this section
1068+
// by default.
10701069
//
10711070
// To handle this is a bit different depending on the object file format
10721071
// used by the backend, broken down into a few different categories:
10731072
//
10741073
// * Mach-O - this is for macOS. Inspecting the source code for the native
1075-
// linker here shows that the `.llvmbc` and `.llvmcmd` sections are
1076-
// automatically skipped by the linker. In that case there's nothing extra
1077-
// that we need to do here.
1074+
// linker here shows that the `.llvmbc` section is automatically skipped
1075+
// by the linker. In that case there's nothing extra that we need to do
1076+
// here.
10781077
//
1079-
// * Wasm - the native LLD linker is hard-coded to skip `.llvmbc` and
1080-
// `.llvmcmd` sections, so there's nothing extra we need to do.
1078+
// * Wasm - the native LLD linker is hard-coded to skip `.llvmbc` section,
1079+
// so there's nothing extra we need to do.
10811080
//
1082-
// * COFF - if we don't do anything the linker will by default copy all
1083-
// these sections to the output artifact, not what we want! To subvert
1084-
// this we want to flag the sections we inserted here as
1085-
// `IMAGE_SCN_LNK_REMOVE`.
1081+
// * COFF - if we don't do anything the linker will by default copy this
1082+
// section to the output artifact, not what we want! To subvert this we
1083+
// want to flag the section we inserted here as `IMAGE_SCN_LNK_REMOVE`.
10861084
//
1087-
// * ELF - this is very similar to COFF above. One difference is that these
1088-
// sections are removed from the output linked artifact when
1089-
// `--gc-sections` is passed, which we pass by default. If that flag isn't
1090-
// passed though then these sections will show up in the final output.
1091-
// Additionally the flag that we need to set here is `SHF_EXCLUDE`.
1085+
// * ELF - this is very similar to COFF above. One difference is that this
1086+
// section is removed from the output linked artifact when `--gc-sections`
1087+
// is passed, which we pass by default. If that flag isn't passed through
1088+
// then this section will show up in the final output. Additionally the
1089+
// flag that we need to set here is `SHF_EXCLUDE`.
10921090
//
1093-
// * XCOFF - AIX linker ignores content in .ipa and .info if no auxiliary
1094-
// symbol associated with these sections.
1091+
// * XCOFF - AIX linker ignores content in .ipa if no auxiliary symbol
1092+
// associated with this section.
10951093
//
10961094
// Unfortunately, LLVM provides no way to set custom section flags. For ELF
10971095
// and COFF we emit the sections using module level inline assembly for that
@@ -1110,26 +1108,11 @@ fn embed_bitcode(
11101108
llvm::set_section(llglobal, bitcode_section_name(cgcx));
11111109
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
11121110
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
1113-
1114-
let llconst = common::bytes_in_context(llcx, cmdline.as_bytes());
1115-
let llglobal = llvm::add_global(llmod, common::val_ty(llconst), c"rustc.embedded.cmdline");
1116-
llvm::set_initializer(llglobal, llconst);
1117-
let section = if cgcx.target_is_like_darwin {
1118-
c"__LLVM,__cmdline"
1119-
} else if cgcx.target_is_like_aix {
1120-
c".info"
1121-
} else {
1122-
c".llvmcmd"
1123-
};
1124-
llvm::set_section(llglobal, section);
1125-
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
11261111
} else {
11271112
// We need custom section flags, so emit module-level inline assembly.
11281113
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
11291114
let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode);
11301115
llvm::append_module_inline_asm(llmod, &asm);
1131-
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, cmdline.as_bytes());
1132-
llvm::append_module_inline_asm(llmod, &asm);
11331116
}
11341117
}
11351118

compiler/rustc_codegen_ssa/src/back/write.rs

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

82-
/// Some(level) to optimize binary size, or None to not affect program size.
83-
pub opt_size: Option<config::OptLevel>,
84-
8582
pub pgo_gen: SwitchWithOptPath,
8683
pub pgo_use: Option<PathBuf>,
8784
pub pgo_sample_use: Option<PathBuf>,
@@ -102,15 +99,13 @@ pub struct ModuleConfig {
10299
pub emit_obj: EmitObj,
103100
pub emit_thin_lto: bool,
104101
pub emit_thin_lto_summary: bool,
105-
pub bc_cmdline: String,
106102

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

173168
opt_level: opt_level_and_size,
174-
opt_size: opt_level_and_size,
175169

176170
pgo_gen: if_regular!(
177171
sess.opts.cg.profile_generate.clone(),
@@ -221,17 +215,12 @@ impl ModuleConfig {
221215
sess.opts.output_types.contains_key(&OutputType::ThinLinkBitcode),
222216
false
223217
),
224-
bc_cmdline: sess.target.bitcode_llvm_cmdline.to_string(),
225218

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

231-
// Exclude metadata and allocator modules from time_passes output,
232-
// since they throw off the "LLVM passes" measurement.
233-
time_module: if_regular!(true, false),
234-
235224
// Copy what clang does by turning on loop vectorization at O2 and
236225
// slp vectorization at O3.
237226
vectorize_loop: !sess.opts.cg.no_vectorize_loops
@@ -1740,7 +1729,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
17401729
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
17411730
work: WorkItem<B>,
17421731
) {
1743-
if cgcx.config(work.module_kind()).time_module && llvm_start_time.is_none() {
1732+
if llvm_start_time.is_none() {
17441733
*llvm_start_time = Some(cgcx.prof.verbose_generic_activity("LLVM_passes"));
17451734
}
17461735

compiler/rustc_codegen_ssa/src/base.rs

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

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

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

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

828830
// 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
@@ -167,7 +167,6 @@ impl Target {
167167
forward!(main_needs_argc_argv);
168168
forward!(has_thread_local);
169169
forward!(obj_is_bitcode);
170-
forward!(bitcode_llvm_cmdline);
171170
forward_opt!(max_atomic_width);
172171
forward_opt!(min_atomic_width);
173172
forward!(atomic_cas);
@@ -359,7 +358,6 @@ impl ToJson for Target {
359358
target_option_val!(main_needs_argc_argv);
360359
target_option_val!(has_thread_local);
361360
target_option_val!(obj_is_bitcode);
362-
target_option_val!(bitcode_llvm_cmdline);
363361
target_option_val!(min_atomic_width);
364362
target_option_val!(max_atomic_width);
365363
target_option_val!(atomic_cas);
@@ -578,7 +576,6 @@ struct TargetSpecJson {
578576
main_needs_argc_argv: Option<bool>,
579577
has_thread_local: Option<bool>,
580578
obj_is_bitcode: Option<bool>,
581-
bitcode_llvm_cmdline: Option<StaticCow<str>>,
582579
max_atomic_width: Option<u64>,
583580
min_atomic_width: Option<u64>,
584581
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
@@ -2153,8 +2153,6 @@ pub struct TargetOptions {
21532153
/// If we give emcc .o files that are actually .bc files it
21542154
/// will 'just work'.
21552155
pub obj_is_bitcode: bool,
2156-
/// Content of the LLVM cmdline section associated with embedded bitcode.
2157-
pub bitcode_llvm_cmdline: StaticCow<str>,
21582156

21592157
/// Don't use this field; instead use the `.min_atomic_width()` method.
21602158
pub min_atomic_width: Option<u64>,
@@ -2517,7 +2515,6 @@ impl Default for TargetOptions {
25172515
allow_asm: true,
25182516
has_thread_local: false,
25192517
obj_is_bitcode: false,
2520-
bitcode_llvm_cmdline: "".into(),
25212518
min_atomic_width: None,
25222519
max_atomic_width: None,
25232520
atomic_cas: true,

0 commit comments

Comments
 (0)