Skip to content

Commit

Permalink
nix rustc_target::abi::* reexport in ty::layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Apr 2, 2020
1 parent 127a11a commit 1241447
Show file tree
Hide file tree
Showing 85 changed files with 333 additions and 369 deletions.
14 changes: 6 additions & 8 deletions src/librustc_codegen_llvm/abi.rs
Expand Up @@ -10,17 +10,15 @@ use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::MemFlags;
use rustc_middle::bug;
use rustc_middle::ty::layout::{self};
pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
use rustc_middle::ty::Ty;
use rustc_target::abi::call::ArgAbi;
use rustc_target::abi::{HasDataLayout, LayoutOf};

use libc::c_uint;

pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
pub use rustc_target::abi::call::*;
use rustc_target::abi::{self, HasDataLayout, Int, LayoutOf};
pub use rustc_target::spec::abi::Abi;

use libc::c_uint;

macro_rules! for_each_kind {
($flags: ident, $f: ident, $($kind: ident),+) => ({
$(if $flags.contains(ArgAttribute::$kind) { $f(llvm::Attribute::$kind) })+
Expand Down Expand Up @@ -450,11 +448,11 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
PassMode::Indirect(ref attrs, _) => apply(attrs, Some(self.ret.layout.llvm_type(bx))),
_ => {}
}
if let layout::Abi::Scalar(ref scalar) = self.ret.layout.abi {
if let abi::Abi::Scalar(ref scalar) = self.ret.layout.abi {
// If the value is a boolean, the range is 0..2 and that ultimately
// become 0..0 when the type becomes i1, which would be rejected
// by the LLVM verifier.
if let layout::Int(..) = scalar.value {
if let Int(..) = scalar.value {
if !scalar.is_bool() {
let range = scalar.valid_range_exclusive(bx);
if range.start != range.end {
Expand Down
21 changes: 11 additions & 10 deletions src/librustc_codegen_llvm/builder.rs
Expand Up @@ -16,9 +16,10 @@ use rustc_codegen_ssa::MemFlags;
use rustc_data_structures::const_cstr;
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::{self, Align, Size, TyAndLayout};
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::config::{self, Sanitizer};
use rustc_target::abi::{self, Align, Size};
use rustc_target::spec::{HasTargetSpec, Target};
use std::borrow::Cow;
use std::ffi::CStr;
Expand Down Expand Up @@ -60,8 +61,8 @@ impl BackendTypes for Builder<'_, 'll, 'tcx> {
type DIVariable = <CodegenCx<'ll, 'tcx> as BackendTypes>::DIVariable;
}

impl ty::layout::HasDataLayout for Builder<'_, '_, '_> {
fn data_layout(&self) -> &ty::layout::TargetDataLayout {
impl abi::HasDataLayout for Builder<'_, '_, '_> {
fn data_layout(&self) -> &abi::TargetDataLayout {
self.cx.data_layout()
}
}
Expand All @@ -84,7 +85,7 @@ impl HasTargetSpec for Builder<'_, '_, 'tcx> {
}
}

impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
impl abi::LayoutOf for Builder<'_, '_, 'tcx> {
type Ty = Ty<'tcx>;
type TyAndLayout = TyAndLayout<'tcx>;

Expand Down Expand Up @@ -435,17 +436,17 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
fn scalar_load_metadata<'a, 'll, 'tcx>(
bx: &mut Builder<'a, 'll, 'tcx>,
load: &'ll Value,
scalar: &layout::Scalar,
scalar: &abi::Scalar,
) {
let vr = scalar.valid_range.clone();
match scalar.value {
layout::Int(..) => {
abi::Int(..) => {
let range = scalar.valid_range_exclusive(bx);
if range.start != range.end {
bx.range_metadata(load, range);
}
}
layout::Pointer if vr.start() < vr.end() && !vr.contains(&0) => {
abi::Pointer if vr.start() < vr.end() && !vr.contains(&0) => {
bx.nonnull_metadata(load);
}
_ => {}
Expand All @@ -465,16 +466,16 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
let llval = const_llval.unwrap_or_else(|| {
let load = self.load(place.llval, place.align);
if let layout::Abi::Scalar(ref scalar) = place.layout.abi {
if let abi::Abi::Scalar(ref scalar) = place.layout.abi {
scalar_load_metadata(self, load, scalar);
}
load
});
OperandValue::Immediate(to_immediate(self, llval, place.layout))
} else if let layout::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
} else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
let b_offset = a.value.size(self).align_to(b.value.align(self).abi);

let mut load = |i, scalar: &layout::Scalar, align| {
let mut load = |i, scalar: &abi::Scalar, align| {
let llptr = self.struct_gep(place.llval, i as u64);
let load = self.load(llptr, align);
scalar_load_metadata(self, load, scalar);
Expand Down
31 changes: 12 additions & 19 deletions src/librustc_codegen_llvm/common.rs
Expand Up @@ -2,26 +2,24 @@

//! Code that is useful in various codegen modules.

use crate::consts;
use crate::consts::{self, const_alloc_to_llvm};
pub use crate::context::CodegenCx;
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True};
use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
use log::debug;
use rustc_codegen_ssa::traits::*;
use rustc_middle::bug;

use crate::consts::const_alloc_to_llvm;
use rustc_ast::ast::Mutability;
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::*;
use rustc_middle::bug;
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
use rustc_middle::ty::layout::{self, HasDataLayout, LayoutOf, Size, TyAndLayout};

use libc::{c_char, c_uint};

use rustc_ast::ast::Mutability;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_span::symbol::Symbol;
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Pointer, Size};

pub use crate::context::CodegenCx;
use libc::{c_char, c_uint};
use log::debug;

/*
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
Expand Down Expand Up @@ -229,12 +227,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
})
}

fn scalar_to_backend(
&self,
cv: Scalar,
layout: &layout::Scalar,
llty: &'ll Type,
) -> &'ll Value {
fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: &'ll Type) -> &'ll Value {
let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() };
match cv {
Scalar::Raw { size: 0, .. } => {
Expand All @@ -244,7 +237,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
Scalar::Raw { data, size } => {
assert_eq!(size as u64, layout.value.size(self).bytes());
let llval = self.const_uint_big(self.type_ix(bitsize), data);
if layout.value == layout::Pointer {
if layout.value == Pointer {
unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
} else {
self.const_bitcast(llval, llty)
Expand Down Expand Up @@ -278,7 +271,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
1,
)
};
if layout.value != layout::Pointer {
if layout.value != Pointer {
unsafe { llvm::LLVMConstPtrToInt(llval, llty) }
} else {
self.const_bitcast(llval, llty)
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_codegen_llvm/consts.rs
Expand Up @@ -16,12 +16,11 @@ use rustc_middle::mir::interpret::{
read_target_uint, Allocation, ConstValue, ErrorHandled, Pointer,
};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::layout::{self, Align, LayoutOf, Size};
use rustc_middle::ty::{self, Instance, Ty};
use rustc_middle::{bug, span_bug};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;
use rustc_target::abi::HasDataLayout;
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size};

use std::ffi::CStr;

Expand Down Expand Up @@ -56,7 +55,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
as u64;
llvals.push(cx.scalar_to_backend(
Pointer::new(alloc_id, Size::from_bytes(ptr_offset)).into(),
&layout::Scalar { value: layout::Primitive::Pointer, valid_range: 0..=!0 },
&Scalar { value: Primitive::Pointer, valid_range: 0..=!0 },
cx.type_i8p(),
));
next_offset = offset + pointer_size;
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_codegen_llvm/context.rs
Expand Up @@ -14,14 +14,13 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_middle::bug;
use rustc_middle::mir::mono::CodegenUnit;
use rustc_middle::ty::layout::{
HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyAndLayout, VariantIdx,
};
use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::{self, CFGuard, DebugInfo};
use rustc_session::Session;
use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_span::symbol::Symbol;
use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
use rustc_target::spec::{HasTargetSpec, Target};

use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -817,8 +816,8 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
}
}

impl ty::layout::HasDataLayout for CodegenCx<'ll, 'tcx> {
fn data_layout(&self) -> &ty::layout::TargetDataLayout {
impl HasDataLayout for CodegenCx<'ll, 'tcx> {
fn data_layout(&self) -> &TargetDataLayout {
&self.tcx.data_layout
}
}
Expand Down
68 changes: 29 additions & 39 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Expand Up @@ -34,17 +34,17 @@ use rustc_middle::ich::NodeIdHashingMode;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::interpret::truncate;
use rustc_middle::mir::{self, Field, GeneratorLayout};
use rustc_middle::ty::layout::{
self, Align, Integer, IntegerExt, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx,
};
use rustc_middle::ty::layout::{self, IntegerExt, PrimitiveExt, TyAndLayout};
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::Instance;
use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_session::config::{self, DebugInfo};
use rustc_span::symbol::{Interner, Symbol};
use rustc_span::{self, FileName, Span};
use rustc_target::abi::HasDataLayout;
use rustc_target::abi::{Abi, Align, DiscriminantKind, HasDataLayout, Integer, LayoutOf};
use rustc_target::abi::{Int, Pointer, F32, F64};
use rustc_target::abi::{Primitive, Size, VariantIdx, Variants};

use libc::{c_longlong, c_uint};
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -1364,7 +1364,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
};

match self.layout.variants {
layout::Variants::Single { index } => {
Variants::Single { index } => {
if let ty::Adt(adt, _) = &self.enum_type.kind {
if adt.variants.is_empty() {
return vec![];
Expand Down Expand Up @@ -1399,8 +1399,8 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
discriminant: None,
}]
}
layout::Variants::Multiple {
discr_kind: layout::DiscriminantKind::Tag,
Variants::Multiple {
discr_kind: DiscriminantKind::Tag,
discr_index,
ref variants,
..
Expand Down Expand Up @@ -1457,9 +1457,9 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
})
.collect()
}
layout::Variants::Multiple {
Variants::Multiple {
discr_kind:
layout::DiscriminantKind::Niche { ref niche_variants, niche_start, dataful_variant },
DiscriminantKind::Niche { ref niche_variants, niche_start, dataful_variant },
ref discr,
ref variants,
discr_index,
Expand Down Expand Up @@ -1592,7 +1592,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
// Creates `MemberDescription`s for the fields of a single enum variant.
struct VariantMemberDescriptionFactory<'ll, 'tcx> {
/// Cloned from the `layout::Struct` describing the variant.
offsets: Vec<layout::Size>,
offsets: Vec<Size>,
args: Vec<(String, Ty<'tcx>)>,
discriminant_type_metadata: Option<&'ll DIType>,
span: Span,
Expand Down Expand Up @@ -1777,7 +1777,7 @@ fn prepare_enum_metadata(
// <unknown>
let file_metadata = unknown_file_metadata(cx);

let discriminant_type_metadata = |discr: layout::Primitive| {
let discriminant_type_metadata = |discr: Primitive| {
let enumerators_metadata: Vec<_> = match enum_type.kind {
ty::Adt(def, _) => def
.discriminants(cx.tcx)
Expand Down Expand Up @@ -1870,27 +1870,20 @@ fn prepare_enum_metadata(
let layout = cx.layout_of(enum_type);

if let (
&layout::Abi::Scalar(_),
&layout::Variants::Multiple {
discr_kind: layout::DiscriminantKind::Tag, ref discr, ..
},
&Abi::Scalar(_),
&Variants::Multiple { discr_kind: DiscriminantKind::Tag, ref discr, .. },
) = (&layout.abi, &layout.variants)
{
return FinalMetadata(discriminant_type_metadata(discr.value));
}

if use_enum_fallback(cx) {
let discriminant_type_metadata = match layout.variants {
layout::Variants::Single { .. }
| layout::Variants::Multiple {
discr_kind: layout::DiscriminantKind::Niche { .. },
..
} => None,
layout::Variants::Multiple {
discr_kind: layout::DiscriminantKind::Tag,
ref discr,
..
} => Some(discriminant_type_metadata(discr.value)),
Variants::Single { .. }
| Variants::Multiple { discr_kind: DiscriminantKind::Niche { .. }, .. } => None,
Variants::Multiple { discr_kind: DiscriminantKind::Tag, ref discr, .. } => {
Some(discriminant_type_metadata(discr.value))
}
};

let enum_metadata = {
Expand Down Expand Up @@ -1938,10 +1931,10 @@ fn prepare_enum_metadata(
};
let discriminator_metadata = match layout.variants {
// A single-variant enum has no discriminant.
layout::Variants::Single { .. } => None,
Variants::Single { .. } => None,

layout::Variants::Multiple {
discr_kind: layout::DiscriminantKind::Niche { .. },
Variants::Multiple {
discr_kind: DiscriminantKind::Niche { .. },
ref discr,
discr_index,
..
Expand All @@ -1951,10 +1944,10 @@ fn prepare_enum_metadata(
let align = discr.value.align(cx);

let discr_type = match discr.value {
layout::Int(t, _) => t,
layout::F32 => Integer::I32,
layout::F64 => Integer::I64,
layout::Pointer => cx.data_layout().ptr_sized_integer(),
Int(t, _) => t,
F32 => Integer::I32,
F64 => Integer::I64,
Pointer => cx.data_layout().ptr_sized_integer(),
}
.to_ty(cx.tcx, false);

Expand All @@ -1976,11 +1969,8 @@ fn prepare_enum_metadata(
}
}

layout::Variants::Multiple {
discr_kind: layout::DiscriminantKind::Tag,
ref discr,
discr_index,
..
Variants::Multiple {
discr_kind: DiscriminantKind::Tag, ref discr, discr_index, ..
} => {
let discr_type = discr.value.to_ty(cx.tcx);
let (size, align) = cx.size_and_align_of(discr_type);
Expand All @@ -2005,8 +1995,8 @@ fn prepare_enum_metadata(
};

let mut outer_fields = match layout.variants {
layout::Variants::Single { .. } => vec![],
layout::Variants::Multiple { .. } => {
Variants::Single { .. } => vec![],
Variants::Multiple { .. } => {
let tuple_mdf = TupleMemberDescriptionFactory {
ty: enum_type,
component_types: outer_field_tys,
Expand Down

0 comments on commit 1241447

Please sign in to comment.