Skip to content

Commit 241c83f

Browse files
committed
Deduplicate more functions between SimpleCx and CodegenCx
1 parent 29440b8 commit 241c83f

File tree

2 files changed

+4
-54
lines changed

2 files changed

+4
-54
lines changed

Diff for: compiler/rustc_codegen_llvm/src/builder.rs

+4-49
Original file line numberDiff line numberDiff line change
@@ -119,49 +119,6 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
119119
}
120120
}
121121

122-
impl<'a, 'll> SBuilder<'a, 'll> {
123-
fn check_call<'b>(
124-
&mut self,
125-
typ: &str,
126-
fn_ty: &'ll Type,
127-
llfn: &'ll Value,
128-
args: &'b [&'ll Value],
129-
) -> Cow<'b, [&'ll Value]> {
130-
assert!(
131-
self.cx.type_kind(fn_ty) == TypeKind::Function,
132-
"builder::{typ} not passed a function, but {fn_ty:?}"
133-
);
134-
135-
let param_tys = self.cx.func_params_types(fn_ty);
136-
137-
let all_args_match = iter::zip(&param_tys, args.iter().map(|&v| self.cx.val_ty(v)))
138-
.all(|(expected_ty, actual_ty)| *expected_ty == actual_ty);
139-
140-
if all_args_match {
141-
return Cow::Borrowed(args);
142-
}
143-
144-
let casted_args: Vec<_> = iter::zip(param_tys, args)
145-
.enumerate()
146-
.map(|(i, (expected_ty, &actual_val))| {
147-
let actual_ty = self.cx.val_ty(actual_val);
148-
if expected_ty != actual_ty {
149-
debug!(
150-
"type mismatch in function call of {:?}. \
151-
Expected {:?} for param {}, got {:?}; injecting bitcast",
152-
llfn, expected_ty, i, actual_ty
153-
);
154-
self.bitcast(actual_val, expected_ty)
155-
} else {
156-
actual_val
157-
}
158-
})
159-
.collect();
160-
161-
Cow::Owned(casted_args)
162-
}
163-
}
164-
165122
/// Empty string, to be used where LLVM expects an instruction name, indicating
166123
/// that the instruction is to be left unnamed (i.e. numbered, in textual IR).
167124
// FIXME(eddyb) pass `&CStr` directly to FFI once it's a thin pointer.
@@ -1610,9 +1567,7 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
16101567
let ret = unsafe { llvm::LLVMBuildCatchRet(self.llbuilder, funclet.cleanuppad(), unwind) };
16111568
ret.expect("LLVM does not have support for catchret")
16121569
}
1613-
}
16141570

1615-
impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16161571
fn check_call<'b>(
16171572
&mut self,
16181573
typ: &str,
@@ -1627,7 +1582,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16271582

16281583
let param_tys = self.cx.func_params_types(fn_ty);
16291584

1630-
let all_args_match = iter::zip(&param_tys, args.iter().map(|&v| self.val_ty(v)))
1585+
let all_args_match = iter::zip(&param_tys, args.iter().map(|&v| self.cx.val_ty(v)))
16311586
.all(|(expected_ty, actual_ty)| *expected_ty == actual_ty);
16321587

16331588
if all_args_match {
@@ -1637,7 +1592,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16371592
let casted_args: Vec<_> = iter::zip(param_tys, args)
16381593
.enumerate()
16391594
.map(|(i, (expected_ty, &actual_val))| {
1640-
let actual_ty = self.val_ty(actual_val);
1595+
let actual_ty = self.cx.val_ty(actual_val);
16411596
if expected_ty != actual_ty {
16421597
debug!(
16431598
"type mismatch in function call of {:?}. \
@@ -1653,12 +1608,12 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16531608

16541609
Cow::Owned(casted_args)
16551610
}
1656-
}
1657-
impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
1611+
16581612
pub(crate) fn va_arg(&mut self, list: &'ll Value, ty: &'ll Type) -> &'ll Value {
16591613
unsafe { llvm::LLVMBuildVAArg(self.llbuilder, list, ty, UNNAMED) }
16601614
}
16611615
}
1616+
16621617
impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16631618
pub(crate) fn call_intrinsic(&mut self, intrinsic: &str, args: &[&'ll Value]) -> &'ll Value {
16641619
let (ty, f) = self.cx.get_intrinsic(intrinsic);

Diff for: compiler/rustc_codegen_llvm/src/context.rs

-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::str;
88
use rustc_abi::{HasDataLayout, Size, TargetDataLayout, VariantIdx};
99
use rustc_codegen_ssa::back::versioned_llvm_target;
1010
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
11-
use rustc_codegen_ssa::common::TypeKind;
1211
use rustc_codegen_ssa::errors as ssa_errors;
1312
use rustc_codegen_ssa::traits::*;
1413
use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN};
@@ -682,10 +681,6 @@ impl<'ll> SimpleCx<'ll> {
682681
llvm::LLVMMDStringInContext2(self.llcx, name.as_ptr() as *const c_char, name.len())
683682
})
684683
}
685-
686-
pub(crate) fn type_kind(&self, ty: &'ll Type) -> TypeKind {
687-
unsafe { llvm::LLVMRustGetTypeKind(ty).to_generic() }
688-
}
689684
}
690685

691686
impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {

0 commit comments

Comments
 (0)