Remove a lot of methods from *TypeMethods

This commit is contained in:
bjorn3 2019-03-01 15:47:06 +01:00
parent b0ee1f7f99
commit 0e166bb217
3 changed files with 92 additions and 114 deletions

View File

@ -11,8 +11,9 @@ use rustc_codegen_ssa::traits::*;
use crate::common;
use crate::type_of::LayoutLlvmExt;
use crate::abi::{LlvmType, FnTypeExt};
use syntax::ast;
use rustc::ty::Ty;
use rustc::ty::layout::TyLayout;
use rustc::ty::layout::{self, Align, Size, TyLayout};
use rustc_target::abi::call::{CastTarget, FnType, Reg};
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_codegen_ssa::common::TypeKind;
@ -50,21 +51,99 @@ impl CodegenCx<'ll, 'tcx> {
els.len() as c_uint, packed as Bool)
}
}
}
impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
fn type_void(&self) -> &'ll Type {
crate fn type_void(&self) -> &'ll Type {
unsafe {
llvm::LLVMVoidTypeInContext(self.llcx)
}
}
fn type_metadata(&self) -> &'ll Type {
crate fn type_metadata(&self) -> &'ll Type {
unsafe {
llvm::LLVMRustMetadataTypeInContext(self.llcx)
}
}
///x Creates an integer type with the given number of bits, e.g., i24
crate fn type_ix(&self, num_bits: u64) -> &'ll Type {
unsafe {
llvm::LLVMIntTypeInContext(self.llcx, num_bits as c_uint)
}
}
crate fn type_x86_mmx(&self) -> &'ll Type {
unsafe {
llvm::LLVMX86MMXTypeInContext(self.llcx)
}
}
crate fn type_vector(&self, ty: &'ll Type, len: u64) -> &'ll Type {
unsafe {
llvm::LLVMVectorType(ty, len as c_uint)
}
}
crate fn func_params_types(&self, ty: &'ll Type) -> Vec<&'ll Type> {
unsafe {
let n_args = llvm::LLVMCountParamTypes(ty) as usize;
let mut args = Vec::with_capacity(n_args);
llvm::LLVMGetParamTypes(ty, args.as_mut_ptr());
args.set_len(n_args);
args
}
}
crate fn type_bool(&self) -> &'ll Type {
self.type_i8()
}
crate fn type_int_from_ty(&self, t: ast::IntTy) -> &'ll Type {
match t {
ast::IntTy::Isize => self.type_isize(),
ast::IntTy::I8 => self.type_i8(),
ast::IntTy::I16 => self.type_i16(),
ast::IntTy::I32 => self.type_i32(),
ast::IntTy::I64 => self.type_i64(),
ast::IntTy::I128 => self.type_i128(),
}
}
crate fn type_uint_from_ty(&self, t: ast::UintTy) -> &'ll Type {
match t {
ast::UintTy::Usize => self.type_isize(),
ast::UintTy::U8 => self.type_i8(),
ast::UintTy::U16 => self.type_i16(),
ast::UintTy::U32 => self.type_i32(),
ast::UintTy::U64 => self.type_i64(),
ast::UintTy::U128 => self.type_i128(),
}
}
crate fn type_float_from_ty(&self, t: ast::FloatTy) -> &'ll Type {
match t {
ast::FloatTy::F32 => self.type_f32(),
ast::FloatTy::F64 => self.type_f64(),
}
}
crate fn type_pointee_for_align(&self, align: Align) -> &'ll Type {
// FIXME(eddyb) We could find a better approximation if ity.align < align.
let ity = layout::Integer::approximate_align(self, align);
self.type_from_integer(ity)
}
/// Return a LLVM type that has at most the required alignment,
/// and exactly the required size, as a best-effort padding array.
crate fn type_padding_filler(&self, size: Size, align: Align) -> &'ll Type {
let unit = layout::Integer::approximate_align(self, align);
let size = size.bytes();
let unit_size = unit.size().bytes();
assert_eq!(size % unit_size, 0);
self.type_array(self.type_from_integer(unit), size / unit_size)
}
}
impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
fn type_i1(&self) -> &'ll Type {
unsafe {
llvm::LLVMInt1TypeInContext(self.llcx)
@ -102,12 +181,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}
fn type_ix(&self, num_bits: u64) -> &'ll Type {
unsafe {
llvm::LLVMIntTypeInContext(self.llcx, num_bits as c_uint)
}
}
fn type_isize(&self) -> &'ll Type {
self.isize_ty
}
@ -124,12 +197,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}
fn type_x86_mmx(&self) -> &'ll Type {
unsafe {
llvm::LLVMX86MMXTypeInContext(self.llcx)
}
}
fn type_func(
&self,
args: &[&'ll Type],
@ -171,12 +238,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}
fn type_vector(&self, ty: &'ll Type, len: u64) -> &'ll Type {
unsafe {
llvm::LLVMVectorType(ty, len as c_uint)
}
}
fn type_kind(&self, ty: &'ll Type) -> TypeKind {
unsafe {
llvm::LLVMRustGetTypeKind(ty).to_generic()
@ -201,16 +262,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}
fn func_params_types(&self, ty: &'ll Type) -> Vec<&'ll Type> {
unsafe {
let n_args = llvm::LLVMCountParamTypes(ty) as usize;
let mut args = Vec::with_capacity(n_args);
llvm::LLVMGetParamTypes(ty, args.as_mut_ptr());
args.set_len(n_args);
args
}
}
fn float_width(&self, ty: &'ll Type) -> usize {
match self.type_kind(ty) {
TypeKind::Float => 32,
@ -288,9 +339,6 @@ impl LayoutTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
fn cast_backend_type(&self, ty: &CastTarget) -> &'ll Type {
ty.llvm_type(self)
}
fn fn_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> &'ll Type {
ty.llvm_type(self)
}
fn fn_ptr_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> &'ll Type {
ty.ptr_to_llvm_type(self)
}

View File

@ -1,7 +1,7 @@
#![allow(non_camel_case_types, non_snake_case)]
use rustc::ty::{self, Ty, TyCtxt};
use syntax_pos::{DUMMY_SP, Span};
use rustc::ty::{Ty, TyCtxt};
use syntax_pos::Span;
use rustc::hir::def_id::DefId;
use rustc::middle::lang_items::LangItem;
@ -11,18 +11,6 @@ use crate::traits::*;
use rustc::hir;
use crate::traits::BuilderMethods;
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
}
pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all())
}
pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
}
pub enum IntPredicate {
IntEQ,
IntNE,

View File

@ -1,38 +1,31 @@
use super::misc::MiscMethods;
use super::Backend;
use super::HasCodegen;
use crate::common::{self, TypeKind};
use crate::common::TypeKind;
use crate::mir::place::PlaceRef;
use rustc::ty::layout::{self, Align, Size, TyLayout};
use rustc::ty::{self, Ty};
use rustc::ty::layout::{self, TyLayout};
use rustc_target::abi::call::{ArgType, CastTarget, FnType, Reg};
use syntax::ast;
use syntax_pos::DUMMY_SP;
// This depends on `Backend` and not `BackendTypes`, because consumers will probably want to use
// `LayoutOf` or `HasTyCtxt`. This way, they don't have to add a constraint on it themselves.
pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
fn type_void(&self) -> Self::Type;
fn type_metadata(&self) -> Self::Type;
fn type_i1(&self) -> Self::Type;
fn type_i8(&self) -> Self::Type;
fn type_i16(&self) -> Self::Type;
fn type_i32(&self) -> Self::Type;
fn type_i64(&self) -> Self::Type;
fn type_i128(&self) -> Self::Type;
// Creates an integer type with the given number of bits, e.g., i24
fn type_ix(&self, num_bits: u64) -> Self::Type;
fn type_isize(&self) -> Self::Type;
fn type_f32(&self) -> Self::Type;
fn type_f64(&self) -> Self::Type;
fn type_x86_mmx(&self) -> Self::Type;
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
fn type_variadic_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type;
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
fn type_vector(&self, ty: Self::Type, len: u64) -> Self::Type;
fn type_kind(&self, ty: Self::Type) -> TypeKind;
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type;
fn element_type(&self, ty: Self::Type) -> Self::Type;
@ -40,7 +33,6 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
/// Returns the number of elements in `self` if it is a LLVM vector type.
fn vector_length(&self, ty: Self::Type) -> usize;
fn func_params_types(&self, ty: Self::Type) -> Vec<Self::Type>;
fn float_width(&self, ty: Self::Type) -> usize;
/// Retrieves the bit width of the integer type `self`.
@ -50,10 +42,6 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
}
pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
fn type_bool(&self) -> Self::Type {
self.type_i8()
}
fn type_i8p(&self) -> Self::Type {
self.type_ptr_to(self.type_i8())
}
@ -67,35 +55,6 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
}
}
fn type_int_from_ty(&self, t: ast::IntTy) -> Self::Type {
match t {
ast::IntTy::Isize => self.type_isize(),
ast::IntTy::I8 => self.type_i8(),
ast::IntTy::I16 => self.type_i16(),
ast::IntTy::I32 => self.type_i32(),
ast::IntTy::I64 => self.type_i64(),
ast::IntTy::I128 => self.type_i128(),
}
}
fn type_uint_from_ty(&self, t: ast::UintTy) -> Self::Type {
match t {
ast::UintTy::Usize => self.type_isize(),
ast::UintTy::U8 => self.type_i8(),
ast::UintTy::U16 => self.type_i16(),
ast::UintTy::U32 => self.type_i32(),
ast::UintTy::U64 => self.type_i64(),
ast::UintTy::U128 => self.type_i128(),
}
}
fn type_float_from_ty(&self, t: ast::FloatTy) -> Self::Type {
match t {
ast::FloatTy::F32 => self.type_f32(),
ast::FloatTy::F64 => self.type_f64(),
}
}
fn type_from_integer(&self, i: layout::Integer) -> Self::Type {
use rustc::ty::layout::Integer::*;
match i {
@ -107,32 +66,16 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
}
}
fn type_pointee_for_align(&self, align: Align) -> Self::Type {
// FIXME(eddyb) We could find a better approximation if ity.align < align.
let ity = layout::Integer::approximate_align(self, align);
self.type_from_integer(ity)
}
/// Return a LLVM type that has at most the required alignment,
/// and exactly the required size, as a best-effort padding array.
fn type_padding_filler(&self, size: Size, align: Align) -> Self::Type {
let unit = layout::Integer::approximate_align(self, align);
let size = size.bytes();
let unit_size = unit.size().bytes();
assert_eq!(size % unit_size, 0);
self.type_array(self.type_from_integer(unit), size / unit_size)
}
fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
common::type_needs_drop(self.tcx(), ty)
ty.needs_drop(self.tcx(), ty::ParamEnv::reveal_all())
}
fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
common::type_is_sized(self.tcx(), ty)
ty.is_sized(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
}
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
common::type_is_freeze(self.tcx(), ty)
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all(), DUMMY_SP)
}
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
@ -155,7 +98,6 @@ impl<T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscM
pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
fn backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type;
fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type;
fn fn_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> Self::Type;
fn fn_ptr_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> Self::Type;
fn reg_backend_type(&self, ty: &Reg) -> Self::Type;
fn immediate_backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type;