Flatten if
s in rustc_codegen_ssa
This commit is contained in:
parent
9c67cecd12
commit
36f6bc5e3d
7 changed files with 81 additions and 98 deletions
|
@ -389,11 +389,10 @@ impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
|
||||||
mut skip: Box<dyn FnMut(&str) -> bool + 'static>,
|
mut skip: Box<dyn FnMut(&str) -> bool + 'static>,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut archive_path = archive_path.to_path_buf();
|
let mut archive_path = archive_path.to_path_buf();
|
||||||
if self.sess.target.llvm_target.contains("-apple-macosx") {
|
if self.sess.target.llvm_target.contains("-apple-macosx")
|
||||||
if let Some(new_archive_path) = try_extract_macho_fat_archive(self.sess, &archive_path)?
|
&& let Some(new_archive_path) = try_extract_macho_fat_archive(self.sess, &archive_path)?
|
||||||
{
|
{
|
||||||
archive_path = new_archive_path
|
archive_path = new_archive_path
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.src_archives.iter().any(|archive| archive.0 == archive_path) {
|
if self.src_archives.iter().any(|archive| archive.0 == archive_path) {
|
||||||
|
|
|
@ -151,17 +151,17 @@ pub fn link_binary(
|
||||||
sess.dcx().emit_artifact_notification(&out_filename, "link");
|
sess.dcx().emit_artifact_notification(&out_filename, "link");
|
||||||
}
|
}
|
||||||
|
|
||||||
if sess.prof.enabled() {
|
if sess.prof.enabled()
|
||||||
if let Some(artifact_name) = out_filename.file_name() {
|
&& let Some(artifact_name) = out_filename.file_name()
|
||||||
// Record size for self-profiling
|
{
|
||||||
let file_size = std::fs::metadata(&out_filename).map(|m| m.len()).unwrap_or(0);
|
// Record size for self-profiling
|
||||||
|
let file_size = std::fs::metadata(&out_filename).map(|m| m.len()).unwrap_or(0);
|
||||||
|
|
||||||
sess.prof.artifact_size(
|
sess.prof.artifact_size(
|
||||||
"linked_artifact",
|
"linked_artifact",
|
||||||
artifact_name.to_string_lossy(),
|
artifact_name.to_string_lossy(),
|
||||||
file_size,
|
file_size,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if output.is_stdout() {
|
if output.is_stdout() {
|
||||||
|
@ -186,16 +186,12 @@ pub fn link_binary(
|
||||||
|
|
||||||
let maybe_remove_temps_from_module =
|
let maybe_remove_temps_from_module =
|
||||||
|preserve_objects: bool, preserve_dwarf_objects: bool, module: &CompiledModule| {
|
|preserve_objects: bool, preserve_dwarf_objects: bool, module: &CompiledModule| {
|
||||||
if !preserve_objects {
|
if !preserve_objects && let Some(ref obj) = module.object {
|
||||||
if let Some(ref obj) = module.object {
|
ensure_removed(sess.dcx(), obj);
|
||||||
ensure_removed(sess.dcx(), obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !preserve_dwarf_objects {
|
if !preserve_dwarf_objects && let Some(ref dwo_obj) = module.dwarf_object {
|
||||||
if let Some(ref dwo_obj) = module.dwarf_object {
|
ensure_removed(sess.dcx(), dwo_obj);
|
||||||
ensure_removed(sess.dcx(), dwo_obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2116,11 +2112,11 @@ fn add_local_crate_metadata_objects(
|
||||||
// When linking a dynamic library, we put the metadata into a section of the
|
// When linking a dynamic library, we put the metadata into a section of the
|
||||||
// executable. This metadata is in a separate object file from the main
|
// executable. This metadata is in a separate object file from the main
|
||||||
// object file, so we link that in here.
|
// object file, so we link that in here.
|
||||||
if crate_type == CrateType::Dylib || crate_type == CrateType::ProcMacro {
|
if matches!(crate_type, CrateType::Dylib | CrateType::ProcMacro)
|
||||||
if let Some(obj) = codegen_results.metadata_module.as_ref().and_then(|m| m.object.as_ref())
|
&& let Some(m) = &codegen_results.metadata_module
|
||||||
{
|
&& let Some(obj) = &m.object
|
||||||
cmd.add_object(obj);
|
{
|
||||||
}
|
cmd.add_object(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2540,10 +2536,11 @@ fn add_order_independent_options(
|
||||||
|
|
||||||
cmd.output_filename(out_filename);
|
cmd.output_filename(out_filename);
|
||||||
|
|
||||||
if crate_type == CrateType::Executable && sess.target.is_like_windows {
|
if crate_type == CrateType::Executable
|
||||||
if let Some(ref s) = codegen_results.crate_info.windows_subsystem {
|
&& sess.target.is_like_windows
|
||||||
cmd.subsystem(s);
|
&& let Some(s) = &codegen_results.crate_info.windows_subsystem
|
||||||
}
|
{
|
||||||
|
cmd.subsystem(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to strip as much out of the generated object by removing unused
|
// Try to strip as much out of the generated object by removing unused
|
||||||
|
|
|
@ -111,24 +111,22 @@ pub(crate) fn get_linker<'a>(
|
||||||
// PATH for the child.
|
// PATH for the child.
|
||||||
let mut new_path = sess.get_tools_search_paths(self_contained);
|
let mut new_path = sess.get_tools_search_paths(self_contained);
|
||||||
let mut msvc_changed_path = false;
|
let mut msvc_changed_path = false;
|
||||||
if sess.target.is_like_msvc {
|
if sess.target.is_like_msvc
|
||||||
if let Some(ref tool) = msvc_tool {
|
&& let Some(ref tool) = msvc_tool
|
||||||
cmd.args(tool.args());
|
{
|
||||||
for (k, v) in tool.env() {
|
cmd.args(tool.args());
|
||||||
if k == "PATH" {
|
for (k, v) in tool.env() {
|
||||||
new_path.extend(env::split_paths(v));
|
if k == "PATH" {
|
||||||
msvc_changed_path = true;
|
new_path.extend(env::split_paths(v));
|
||||||
} else {
|
msvc_changed_path = true;
|
||||||
cmd.env(k, v);
|
} else {
|
||||||
}
|
cmd.env(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !msvc_changed_path {
|
if !msvc_changed_path && let Some(path) = env::var_os("PATH") {
|
||||||
if let Some(path) = env::var_os("PATH") {
|
new_path.extend(env::split_paths(&path));
|
||||||
new_path.extend(env::split_paths(&path));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cmd.env("PATH", env::join_paths(new_path).unwrap());
|
cmd.env("PATH", env::join_paths(new_path).unwrap());
|
||||||
|
|
||||||
|
|
|
@ -566,16 +566,13 @@ fn produce_final_output_artifacts(
|
||||||
|
|
||||||
// Produce final compile outputs.
|
// Produce final compile outputs.
|
||||||
let copy_gracefully = |from: &Path, to: &OutFileName| match to {
|
let copy_gracefully = |from: &Path, to: &OutFileName| match to {
|
||||||
OutFileName::Stdout => {
|
OutFileName::Stdout if let Err(e) = copy_to_stdout(from) => {
|
||||||
if let Err(e) = copy_to_stdout(from) {
|
sess.dcx().emit_err(errors::CopyPath::new(from, to.as_path(), e));
|
||||||
sess.dcx().emit_err(errors::CopyPath::new(from, to.as_path(), e));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
OutFileName::Real(path) => {
|
OutFileName::Real(path) if let Err(e) = fs::copy(from, path) => {
|
||||||
if let Err(e) = fs::copy(from, path) {
|
sess.dcx().emit_err(errors::CopyPath::new(from, path, e));
|
||||||
sess.dcx().emit_err(errors::CopyPath::new(from, path, e));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let copy_if_one_unit = |output_type: OutputType, keep_numbered: bool| {
|
let copy_if_one_unit = |output_type: OutputType, keep_numbered: bool| {
|
||||||
|
@ -685,14 +682,12 @@ fn produce_final_output_artifacts(
|
||||||
needs_crate_object || (user_wants_objects && sess.codegen_units().as_usize() > 1);
|
needs_crate_object || (user_wants_objects && sess.codegen_units().as_usize() > 1);
|
||||||
|
|
||||||
for module in compiled_modules.modules.iter() {
|
for module in compiled_modules.modules.iter() {
|
||||||
if let Some(ref path) = module.object {
|
if !keep_numbered_objects {
|
||||||
if !keep_numbered_objects {
|
if let Some(ref path) = module.object {
|
||||||
ensure_removed(sess.dcx(), path);
|
ensure_removed(sess.dcx(), path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref path) = module.dwarf_object {
|
if let Some(ref path) = module.dwarf_object {
|
||||||
if !keep_numbered_objects {
|
|
||||||
ensure_removed(sess.dcx(), path);
|
ensure_removed(sess.dcx(), path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -704,12 +699,11 @@ fn produce_final_output_artifacts(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !user_wants_bitcode {
|
if !user_wants_bitcode
|
||||||
if let Some(ref allocator_module) = compiled_modules.allocator_module {
|
&& let Some(ref allocator_module) = compiled_modules.allocator_module
|
||||||
if let Some(ref path) = allocator_module.bytecode {
|
&& let Some(ref path) = allocator_module.bytecode
|
||||||
ensure_removed(sess.dcx(), path);
|
{
|
||||||
}
|
ensure_removed(sess.dcx(), path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -555,11 +555,9 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
|
||||||
|
|
||||||
pub fn push_item_name(tcx: TyCtxt<'_>, def_id: DefId, qualified: bool, output: &mut String) {
|
pub fn push_item_name(tcx: TyCtxt<'_>, def_id: DefId, qualified: bool, output: &mut String) {
|
||||||
let def_key = tcx.def_key(def_id);
|
let def_key = tcx.def_key(def_id);
|
||||||
if qualified {
|
if qualified && let Some(parent) = def_key.parent {
|
||||||
if let Some(parent) = def_key.parent {
|
push_item_name(tcx, DefId { krate: def_id.krate, index: parent }, true, output);
|
||||||
push_item_name(tcx, DefId { krate: def_id.krate, index: parent }, true, output);
|
output.push_str("::");
|
||||||
output.push_str("::");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
push_unqualified_item_name(tcx, def_id, def_key.disambiguated_data, output);
|
push_unqualified_item_name(tcx, def_id, def_key.disambiguated_data, output);
|
||||||
|
|
|
@ -163,25 +163,25 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
|
||||||
mergeable_succ: bool,
|
mergeable_succ: bool,
|
||||||
) -> MergingSucc {
|
) -> MergingSucc {
|
||||||
let tcx = bx.tcx();
|
let tcx = bx.tcx();
|
||||||
if let Some(instance) = instance {
|
if let Some(instance) = instance
|
||||||
if is_call_from_compiler_builtins_to_upstream_monomorphization(tcx, instance) {
|
&& is_call_from_compiler_builtins_to_upstream_monomorphization(tcx, instance)
|
||||||
if destination.is_some() {
|
{
|
||||||
let caller_def = fx.instance.def_id();
|
if destination.is_some() {
|
||||||
let e = CompilerBuiltinsCannotCall {
|
let caller_def = fx.instance.def_id();
|
||||||
span: tcx.def_span(caller_def),
|
let e = CompilerBuiltinsCannotCall {
|
||||||
caller: with_no_trimmed_paths!(tcx.def_path_str(caller_def)),
|
span: tcx.def_span(caller_def),
|
||||||
callee: with_no_trimmed_paths!(tcx.def_path_str(instance.def_id())),
|
caller: with_no_trimmed_paths!(tcx.def_path_str(caller_def)),
|
||||||
};
|
callee: with_no_trimmed_paths!(tcx.def_path_str(instance.def_id())),
|
||||||
tcx.dcx().emit_err(e);
|
};
|
||||||
} else {
|
tcx.dcx().emit_err(e);
|
||||||
info!(
|
} else {
|
||||||
"compiler_builtins call to diverging function {:?} replaced with abort",
|
info!(
|
||||||
instance.def_id()
|
"compiler_builtins call to diverging function {:?} replaced with abort",
|
||||||
);
|
instance.def_id()
|
||||||
bx.abort();
|
);
|
||||||
bx.unreachable();
|
bx.abort();
|
||||||
return MergingSucc::False;
|
bx.unreachable();
|
||||||
}
|
return MergingSucc::False;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -837,15 +837,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
fn evaluate_array_len(&mut self, bx: &mut Bx, place: mir::Place<'tcx>) -> Bx::Value {
|
fn evaluate_array_len(&mut self, bx: &mut Bx, place: mir::Place<'tcx>) -> Bx::Value {
|
||||||
// ZST are passed as operands and require special handling
|
// ZST are passed as operands and require special handling
|
||||||
// because codegen_place() panics if Local is operand.
|
// because codegen_place() panics if Local is operand.
|
||||||
if let Some(index) = place.as_local() {
|
if let Some(index) = place.as_local()
|
||||||
if let LocalRef::Operand(op) = self.locals[index] {
|
&& let LocalRef::Operand(op) = self.locals[index]
|
||||||
if let ty::Array(_, n) = op.layout.ty.kind() {
|
&& let ty::Array(_, n) = op.layout.ty.kind()
|
||||||
let n = n
|
{
|
||||||
.try_to_target_usize(bx.tcx())
|
let n = n.try_to_target_usize(bx.tcx()).expect("expected monomorphic const in codegen");
|
||||||
.expect("expected monomorphic const in codegen");
|
return bx.cx().const_usize(n);
|
||||||
return bx.cx().const_usize(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// use common size calculation for non zero-sized types
|
// use common size calculation for non zero-sized types
|
||||||
let cg_value = self.codegen_place(bx, place.as_ref());
|
let cg_value = self.codegen_place(bx, place.as_ref());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue