Auto merge of #132526 - bjorn3:sync_cg_clif-2024-11-02, r=bjorn3
Subtree sync for rustc_codegen_cranelift The highlight this time is an update to Cranelift 0.113, r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
This commit is contained in:
commit
89ab6559cc
22 changed files with 170 additions and 272 deletions
|
@ -389,7 +389,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
|||
let callee = with_no_trimmed_paths!(fx.tcx.def_path_str(def_id));
|
||||
fx.tcx.dcx().emit_err(CompilerBuiltinsCannotCall { caller, callee });
|
||||
} else {
|
||||
fx.bcx.ins().trap(TrapCode::User(0));
|
||||
fx.bcx.ins().trap(TrapCode::user(2).unwrap());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -562,6 +562,11 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
|||
adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args);
|
||||
}
|
||||
|
||||
if fx.clif_comments.enabled() {
|
||||
let nop_inst = fx.bcx.ins().nop();
|
||||
with_no_trimmed_paths!(fx.add_comment(nop_inst, format!("abi: {:?}", fn_abi)));
|
||||
}
|
||||
|
||||
match func_ref {
|
||||
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
|
||||
CallTarget::Indirect(sig, func_ptr) => {
|
||||
|
@ -574,7 +579,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
|||
let ret_block = fx.get_block(dest);
|
||||
fx.bcx.ins().jump(ret_block, &[]);
|
||||
} else {
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
}
|
||||
|
||||
fn adjust_call_for_c_variadic<'tcx>(
|
||||
|
|
|
@ -103,12 +103,12 @@ pub(crate) fn codegen_fn<'tcx>(
|
|||
let block_map: IndexVec<BasicBlock, Block> =
|
||||
(0..mir.basic_blocks.len()).map(|_| bcx.create_block()).collect();
|
||||
|
||||
let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());
|
||||
|
||||
// Make FunctionCx
|
||||
let target_config = module.target_config();
|
||||
let pointer_type = target_config.pointer_type();
|
||||
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
|
||||
|
||||
let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());
|
||||
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance, fn_abi);
|
||||
|
||||
let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context {
|
||||
Some(debug_context.define_function(tcx, type_dbg, instance, fn_abi, &symbol_name, mir.span))
|
||||
|
@ -294,7 +294,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
|
|||
if arg_uninhabited {
|
||||
fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]);
|
||||
fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
return;
|
||||
}
|
||||
fx.tcx
|
||||
|
@ -311,7 +311,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
|
|||
if !reachable_blocks.contains(bb) {
|
||||
// We want to skip this block, because it's not reachable. But we still create
|
||||
// the block so terminators in other blocks can reference it.
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,6 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
|
|||
|
||||
let target = fx.get_block(*target);
|
||||
let failure = fx.bcx.create_block();
|
||||
fx.bcx.set_cold_block(failure);
|
||||
|
||||
if *expected {
|
||||
fx.bcx.ins().brif(cond, target, &[], failure, &[]);
|
||||
|
@ -541,10 +540,11 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
|
|||
}
|
||||
TerminatorKind::UnwindResume => {
|
||||
// FIXME implement unwinding
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
}
|
||||
TerminatorKind::Unreachable => {
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.set_cold_block(block);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
}
|
||||
TerminatorKind::Yield { .. }
|
||||
| TerminatorKind::FalseEdge { .. }
|
||||
|
@ -1075,12 +1075,14 @@ fn codegen_panic_inner<'tcx>(
|
|||
args: &[Value],
|
||||
span: Option<Span>,
|
||||
) {
|
||||
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
|
||||
|
||||
let def_id = fx.tcx.require_lang_item(lang_item, span);
|
||||
|
||||
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
|
||||
|
||||
if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
|
||||
fx.bcx.ins().trap(TrapCode::User(0));
|
||||
fx.bcx.ins().trap(TrapCode::user(2).unwrap());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1093,5 +1095,5 @@ fn codegen_panic_inner<'tcx>(
|
|||
args,
|
||||
);
|
||||
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
}
|
||||
|
|
|
@ -50,7 +50,12 @@ fn make_file_info(hash: SourceFileHash) -> Option<FileInfo> {
|
|||
if hash.kind == SourceFileHashAlgorithm::Md5 {
|
||||
let mut buf = [0u8; MD5_LEN];
|
||||
buf.copy_from_slice(hash.hash_bytes());
|
||||
Some(FileInfo { timestamp: 0, size: 0, md5: buf })
|
||||
Some(FileInfo {
|
||||
timestamp: 0,
|
||||
size: 0,
|
||||
md5: buf,
|
||||
source: None, // FIXME implement -Zembed-source
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ impl DebugContext {
|
|||
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
|
||||
};
|
||||
|
||||
let file_has_md5 = file_info.is_some();
|
||||
let mut line_program = LineProgram::new(
|
||||
encoding,
|
||||
LineEncoding::default(),
|
||||
|
@ -108,7 +109,7 @@ impl DebugContext {
|
|||
LineString::new(name.as_bytes(), encoding, &mut dwarf.line_strings),
|
||||
file_info,
|
||||
);
|
||||
line_program.file_has_md5 = file_info.is_some();
|
||||
line_program.file_has_md5 = file_has_md5;
|
||||
|
||||
dwarf.unit.line_program = line_program;
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ impl UnwindContext {
|
|||
self.frame_table
|
||||
.add_fde(self.cie_id.unwrap(), unwind_info.to_fde(address_for_func(func_id)));
|
||||
}
|
||||
UnwindInfo::WindowsX64(_) => {
|
||||
// FIXME implement this
|
||||
UnwindInfo::WindowsX64(_) | UnwindInfo::WindowsArm64(_) => {
|
||||
// Windows does not have debug info for its unwind info.
|
||||
}
|
||||
unwind_info => unimplemented!("{:?}", unwind_info),
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
|
|||
// asm!() by accident and breaks with the GNU assembler as well as global_asm!() for
|
||||
// the LLVM backend.
|
||||
if template.len() == 1 && template[0] == InlineAsmTemplatePiece::String("int $$0x29".into()) {
|
||||
fx.bcx.ins().trap(TrapCode::User(1));
|
||||
fx.bcx.ins().trap(TrapCode::user(2).unwrap());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
|
|||
fx.bcx.ins().jump(destination_block, &[]);
|
||||
}
|
||||
None => {
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(0 /* unreachable */).unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ fn report_atomic_type_validation_error<'tcx>(
|
|||
),
|
||||
);
|
||||
// Prevent verifier error
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
}
|
||||
|
||||
pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Type {
|
||||
|
@ -449,7 +449,8 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
|||
|
||||
match intrinsic {
|
||||
sym::abort => {
|
||||
fx.bcx.ins().trap(TrapCode::User(0));
|
||||
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
|
||||
fx.bcx.ins().trap(TrapCode::user(2).unwrap());
|
||||
return Ok(());
|
||||
}
|
||||
sym::likely | sym::unlikely => {
|
||||
|
|
|
@ -14,7 +14,7 @@ fn report_simd_type_validation_error(
|
|||
) {
|
||||
fx.tcx.dcx().span_err(span, format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", intrinsic, ty));
|
||||
// Prevent verifier error
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
}
|
||||
|
||||
pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
|
@ -190,7 +190,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
|||
format!("simd_shuffle index must be a SIMD vector of `u32`, got `{}`", idx_ty),
|
||||
);
|
||||
// Prevent verifier error
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
|
||||
return;
|
||||
};
|
||||
let n: u16 = idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap();
|
||||
|
@ -1135,7 +1135,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
|||
_ => {
|
||||
fx.tcx.dcx().span_err(span, format!("Unknown SIMD intrinsic {}", intrinsic));
|
||||
// Prevent verifier error
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
fx.bcx.ins().trap(TrapCode::user(0 /* unreachable */).unwrap());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -302,8 +302,11 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
|
|||
OptLevel::No => {
|
||||
flags_builder.set("opt_level", "none").unwrap();
|
||||
}
|
||||
OptLevel::Less | OptLevel::Default => {}
|
||||
OptLevel::Size | OptLevel::SizeMin | OptLevel::Aggressive => {
|
||||
OptLevel::Less
|
||||
| OptLevel::Default
|
||||
| OptLevel::Size
|
||||
| OptLevel::SizeMin
|
||||
| OptLevel::Aggressive => {
|
||||
flags_builder.set("opt_level", "speed_and_size").unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,9 +62,9 @@ use cranelift_codegen::entity::SecondaryMap;
|
|||
use cranelift_codegen::ir::Fact;
|
||||
use cranelift_codegen::ir::entities::AnyEntity;
|
||||
use cranelift_codegen::write::{FuncWriter, PlainWriter};
|
||||
use rustc_middle::ty::layout::FnAbiOf;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_session::config::{OutputFilenames, OutputType};
|
||||
use rustc_target::abi::call::FnAbi;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -76,17 +76,18 @@ pub(crate) struct CommentWriter {
|
|||
}
|
||||
|
||||
impl CommentWriter {
|
||||
pub(crate) fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self {
|
||||
pub(crate) fn new<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
|
||||
) -> Self {
|
||||
let enabled = should_write_ir(tcx);
|
||||
let global_comments = if enabled {
|
||||
with_no_trimmed_paths!({
|
||||
vec![
|
||||
format!("symbol {}", tcx.symbol_name(instance).name),
|
||||
format!("instance {:?}", instance),
|
||||
format!(
|
||||
"abi {:?}",
|
||||
RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())
|
||||
),
|
||||
format!("abi {:?}", fn_abi),
|
||||
String::new(),
|
||||
]
|
||||
})
|
||||
|
|
|
@ -30,5 +30,5 @@ pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRe
|
|||
let one = fx.bcx.ins().iconst(types::I32, 1);
|
||||
fx.lib_call("exit", vec![AbiParam::new(types::I32)], vec![], &[one]);
|
||||
|
||||
fx.bcx.ins().trap(TrapCode::User(!0));
|
||||
fx.bcx.ins().trap(TrapCode::user(3).unwrap());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue