Skip to content

Commit d2aee69

Browse files
committed
Try having names for functions and selecting through names
1 parent 0ea0fb5 commit d2aee69

File tree

10 files changed

+23
-18
lines changed

10 files changed

+23
-18
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
309309
}
310310

311311
pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
312-
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
312+
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>, name: &str) -> &'ll Type;
313313
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
314314
fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv;
315315

@@ -326,20 +326,17 @@ pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
326326
}
327327

328328
impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
329-
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
329+
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>, name: &str) -> &'ll Type {
330+
debug!("Getting LLVM type for {} with ABI {:?}", name, self);
330331
// Ignore "extra" args from the call site for C variadic functions.
331332
// Only the "fixed" args are part of the LLVM function signature.
332333
let args =
333334
if self.c_variadic { &self.args[..self.fixed_count as usize] } else { &self.args };
334335

335336
let adjust_ty = |ty| {
336-
// todo: rectify this to be more selective (help wanted)
337-
let probably_unadjusted = self.conv == Conv::C && !self.can_unwind && !self.c_variadic;
338-
let probably_amx_intrinsic = probably_unadjusted && cx.tcx.sess.target.arch == "x86_64";
337+
let amx_intrinsic = name.starts_with("llvm.x86.") && name.ends_with(".internal");
339338
// Change type to `x86amx` from `i32x256` for x86_64 AMX intrinsics
340-
if probably_amx_intrinsic
341-
&& cx.type_kind(ty) == TypeKind::Vector
342-
&& cx.vector_length(ty) == 256
339+
if amx_intrinsic && cx.type_kind(ty) == TypeKind::Vector && cx.vector_length(ty) == 256
343340
{
344341
let element_ty = cx.element_type(ty);
345342
if cx.type_kind(element_ty) == TypeKind::Integer && cx.int_width(element_ty) == 32 {

compiler/rustc_codegen_llvm/src/declare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
158158
fn_abi.llvm_cconv(self),
159159
llvm::UnnamedAddr::Global,
160160
llvm::Visibility::Default,
161-
fn_abi.llvm_type(self),
161+
fn_abi.llvm_type(self, name),
162162
);
163163
fn_abi.apply_attrs_llfn(self, llfn, instance);
164164

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ fn gen_fn<'a, 'll, 'tcx>(
10901090
codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>),
10911091
) -> (&'ll Type, &'ll Value) {
10921092
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty());
1093-
let llty = fn_abi.llvm_type(cx);
1093+
let llty = fn_abi.llvm_type(cx, name);
10941094
let llfn = cx.declare_fn(name, fn_abi, None);
10951095
cx.set_frame_pointer_type(llfn);
10961096
cx.apply_target_cpu_attr(llfn);

compiler/rustc_codegen_llvm/src/type_.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ impl<'ll, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
288288
fn cast_backend_type(&self, ty: &CastTarget) -> &'ll Type {
289289
ty.llvm_type(self)
290290
}
291-
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Type {
292-
fn_abi.llvm_type(self)
291+
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, name: &str) -> &'ll Type {
292+
fn_abi.llvm_type(self, name)
293293
}
294294
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Type {
295295
fn_abi.ptr_to_llvm_type(self)

compiler/rustc_codegen_llvm/src/value.rs

+8
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ impl fmt::Debug for Value {
2828
)
2929
}
3030
}
31+
32+
impl fmt::Display for Value {
33+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34+
f.write_str(
35+
str::from_utf8(llvm::get_value_name(&self)).expect("non-UTF8 value name from LLVM"),
36+
)
37+
}
38+
}

compiler/rustc_codegen_ssa/src/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
187187

188188
// If there is a cleanup block and the function we're calling can unwind, then
189189
// do an invoke, otherwise do a call.
190-
let fn_ty = bx.fn_decl_backend_type(fn_abi);
190+
let fn_ty = bx.fn_decl_backend_type(fn_abi, &fn_ptr.to_string());
191191

192192
let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
193193
Some(bx.tcx().codegen_fn_attrs(fx.instance.def_id()))
@@ -1806,7 +1806,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
18061806
if is_call_from_compiler_builtins_to_upstream_monomorphization(bx.tcx(), instance) {
18071807
bx.abort();
18081808
} else {
1809-
let fn_ty = bx.fn_decl_backend_type(fn_abi);
1809+
let fn_ty = bx.fn_decl_backend_type(fn_abi, reason.lang_item().name());
18101810

18111811
let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref(), None);
18121812
bx.apply_attrs_to_cleanup_callsite(llret);

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
779779
};
780780
let fn_ptr = bx.get_fn_addr(instance);
781781
let fn_abi = bx.fn_abi_of_instance(instance, ty::List::empty());
782-
let fn_ty = bx.fn_decl_backend_type(fn_abi);
782+
let fn_ty = bx.fn_decl_backend_type(fn_abi, &fn_ptr.to_string());
783783
let fn_attrs = if bx.tcx().def_kind(instance.def_id()).has_codegen_attrs() {
784784
Some(bx.tcx().codegen_fn_attrs(instance.def_id()))
785785
} else {

compiler/rustc_codegen_ssa/src/size_of_val.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
6767
// Generate the call. Cannot use `do_call` since we don't have a MIR terminator so we
6868
// can't create a `TerminationCodegenHelper`. (But we are in good company, this code is
6969
// duplicated plenty of times.)
70-
let fn_ty = bx.fn_decl_backend_type(fn_abi);
70+
let fn_ty = bx.fn_decl_backend_type(fn_abi, "panic_nounwind");
7171

7272
bx.call(
7373
fn_ty,

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::back::write::TargetMachineFactoryFn;
2121
use crate::{CodegenResults, ModuleCodegen, TargetConfig};
2222

2323
pub trait BackendTypes {
24-
type Value: CodegenObject;
24+
type Value: CodegenObject + Display;
2525
type Metadata: CodegenObject;
2626
type Function: CodegenObject;
2727

compiler/rustc_codegen_ssa/src/traits/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub trait LayoutTypeCodegenMethods<'tcx>: BackendTypes {
9696
/// such as when it's stack-allocated or when it's being loaded or stored.
9797
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
9898
fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type;
99-
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type;
99+
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, name: &str) -> Self::Type;
100100
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type;
101101
fn reg_backend_type(&self, ty: &Reg) -> Self::Type;
102102
/// The backend type used for a rust type when it's in an SSA register.

0 commit comments

Comments
 (0)