1use std::fmt::Write;
2
3use rustc_abi::Primitive::{Float, Int, Pointer};
4use rustc_abi::{Align, BackendRepr, FieldsShape, Scalar, Size, Variants};
5use rustc_codegen_ssa::traits::*;
6use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
7use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
8use rustc_middle::ty::{self, CoroutineArgsExt, Ty, TypeVisitableExt};
9use rustc_span::{DUMMY_SP, Span, bug};
10use tracing::debug;
11
12use crate::common::*;
13use crate::llvm::Type;
14
15fn uncached_llvm_type<'a, 'tcx>(
16 cx: &CodegenCx<'a, 'tcx>,
17 layout: TyAndLayout<'tcx>,
18 defer: &mut Option<(&'a Type, TyAndLayout<'tcx>)>,
19) -> &'a Type {
20 match layout.backend_repr {
21 BackendRepr::Scalar(_) => bug_impl(None, format_args!("handled elsewhere"), Location::caller())bug!("handled elsewhere"),
22 BackendRepr::SimdVector { element, count } => {
23 let element = layout.scalar_llvm_type_at(cx, element);
24 return cx.type_vector(element, count.as_u64());
25 }
26 BackendRepr::SimdScalableVector { ref element, count, number_of_vectors } => {
27 let element = if element.is_bool() {
28 cx.type_i1()
29 } else {
30 layout.scalar_llvm_type_at(cx, *element)
31 };
32
33 let vector_type = cx.type_scalable_vector(element, count.as_u64());
34 return match number_of_vectors.0 {
35 1 => vector_type,
36 2 => cx.type_struct(&[vector_type, vector_type], false),
37 3 => cx.type_struct(&[vector_type, vector_type, vector_type], false),
38 4 => cx.type_struct(&[vector_type, vector_type, vector_type, vector_type], false),
39 5 => cx.type_struct(
40 &[vector_type, vector_type, vector_type, vector_type, vector_type],
41 false,
42 ),
43 6 => cx.type_struct(
44 &[vector_type, vector_type, vector_type, vector_type, vector_type, vector_type],
45 false,
46 ),
47 7 => cx.type_struct(
48 &[
49 vector_type,
50 vector_type,
51 vector_type,
52 vector_type,
53 vector_type,
54 vector_type,
55 vector_type,
56 ],
57 false,
58 ),
59 8 => cx.type_struct(
60 &[
61 vector_type,
62 vector_type,
63 vector_type,
64 vector_type,
65 vector_type,
66 vector_type,
67 vector_type,
68 vector_type,
69 ],
70 false,
71 ),
72 _ => bug_impl(None,
format_args!("`#[rustc_scalable_vector]` tuple struct with too many fields"),
Location::caller())bug!("`#[rustc_scalable_vector]` tuple struct with too many fields"),
73 };
74 }
75 BackendRepr::Memory { .. } | BackendRepr::ScalarPair { .. } => {}
76 }
77
78 let name = match layout.ty.kind() {
79 ty::Adt(..) | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str
83 if !cx.sess().fewer_names() =>
85 {
86 let mut name = {
let _guard = NoVisibleGuard::new();
{ let _guard = NoTrimmedGuard::new(); layout.ty.to_string() }
}with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string()));
87 if let (&ty::Adt(def, _), &Variants::Single { index }) =
88 (layout.ty.kind(), &layout.variants)
89 {
90 if def.is_enum() {
91 (&mut name).write_fmt(format_args!("::{0}", def.variant(index).name))write!(&mut name, "::{}", def.variant(index).name).unwrap();
92 }
93 }
94 if let (&ty::Coroutine(_, _), &Variants::Single { index }) =
95 (layout.ty.kind(), &layout.variants)
96 {
97 (&mut name).write_fmt(format_args!("::{0}",
ty::CoroutineArgs::variant_name(index)))write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap();
98 }
99 Some(name)
100 }
101 _ => None,
102 };
103
104 match layout.fields {
105 FieldsShape::Primitive | FieldsShape::Union(_) => {
106 let fill = cx.type_padding_filler(layout.size, layout.align.abi);
107 let packed = false;
108 match name {
109 None => cx.type_struct(&[fill], packed),
110 Some(ref name) => {
111 let llty = cx.type_named_struct(name);
112 cx.set_struct_body(llty, &[fill], packed);
113 llty
114 }
115 }
116 }
117 FieldsShape::Array { count, .. } => cx.type_array(layout.field(cx, 0).llvm_type(cx), count),
118 FieldsShape::Arbitrary { .. } => match name {
119 None => {
120 let (llfields, packed) = struct_llfields(cx, layout);
121 cx.type_struct(&llfields, packed)
122 }
123 Some(ref name) => {
124 let llty = cx.type_named_struct(name);
125 *defer = Some((llty, layout));
126 llty
127 }
128 },
129 }
130}
131
132fn struct_llfields<'a, 'tcx>(
133 cx: &CodegenCx<'a, 'tcx>,
134 layout: TyAndLayout<'tcx>,
135) -> (Vec<&'a Type>, bool) {
136 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs:136",
"rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs"),
::tracing_core::__macro_support::Option::Some(136u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("struct_llfields: {0:#?}",
layout) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("struct_llfields: {:#?}", layout);
137 let field_count = layout.fields.count();
138
139 let mut packed = false;
140 let mut offset = Size::ZERO;
141 let mut prev_effective_align = layout.align.abi;
142 let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
143 for i in layout.fields.index_by_increasing_offset() {
144 let target_offset = layout.fields.offset(i as usize);
145 let field = layout.field(cx, i);
146 let effective_field_align =
147 layout.align.abi.min(field.align.abi).restrict_for_offset(target_offset);
148 packed |= effective_field_align < field.align.abi;
149
150 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs:150",
"rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs"),
::tracing_core::__macro_support::Option::Some(150u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("struct_llfields: {0}: {1:?} offset: {2:?} target_offset: {3:?} effective_field_align: {4}",
i, field, offset, target_offset,
effective_field_align.bytes()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
151 "struct_llfields: {}: {:?} offset: {:?} target_offset: {:?} \
152 effective_field_align: {}",
153 i,
154 field,
155 offset,
156 target_offset,
157 effective_field_align.bytes()
158 );
159 if !(target_offset >= offset) {
::core::panicking::panic("assertion failed: target_offset >= offset")
};assert!(target_offset >= offset);
160 let padding = target_offset - offset;
161 if padding != Size::ZERO {
162 let padding_align = prev_effective_align.min(effective_field_align);
163 {
match (&(offset.align_to(padding_align) + padding), &target_offset) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(offset.align_to(padding_align) + padding, target_offset);
164 result.push(cx.type_padding_filler(padding, padding_align));
165 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs:165",
"rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs"),
::tracing_core::__macro_support::Option::Some(165u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" padding before: {0:?}",
padding) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(" padding before: {:?}", padding);
166 }
167 result.push(field.llvm_type(cx));
168 offset = target_offset + field.size;
169 prev_effective_align = effective_field_align;
170 }
171 if layout.is_sized() && field_count > 0 {
172 if offset > layout.size {
173 bug_impl(None,
format_args!("layout: {0:#?} stride: {1:?} offset: {2:?}", layout,
layout.size, offset), Location::caller());bug!("layout: {:#?} stride: {:?} offset: {:?}", layout, layout.size, offset);
174 }
175 let padding = layout.size - offset;
176 if padding != Size::ZERO {
177 let padding_align = prev_effective_align;
178 {
match (&(offset.align_to(padding_align) + padding), &layout.size) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(offset.align_to(padding_align) + padding, layout.size);
179 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs:179",
"rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs"),
::tracing_core::__macro_support::Option::Some(179u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("struct_llfields: pad_bytes: {0:?} offset: {1:?} stride: {2:?}",
padding, offset, layout.size) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
180 "struct_llfields: pad_bytes: {:?} offset: {:?} stride: {:?}",
181 padding, offset, layout.size
182 );
183 result.push(cx.type_padding_filler(padding, padding_align));
184 }
185 } else {
186 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs:186",
"rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs"),
::tracing_core::__macro_support::Option::Some(186u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("struct_llfields: offset: {0:?} stride: {1:?}",
offset, layout.size) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
187 }
188 (result, packed)
189}
190
191impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
192 pub(crate) fn align_of(&self, ty: Ty<'tcx>) -> Align {
193 self.layout_of(ty).align.abi
194 }
195
196 pub(crate) fn size_of(&self, ty: Ty<'tcx>) -> Size {
197 self.layout_of(ty).size
198 }
199
200 pub(crate) fn size_and_align_of(&self, ty: Ty<'tcx>) -> (Size, Align) {
201 self.spanned_size_and_align_of(ty, DUMMY_SP)
202 }
203
204 pub(crate) fn spanned_size_and_align_of(&self, ty: Ty<'tcx>, span: Span) -> (Size, Align) {
205 let layout = self.spanned_layout_of(ty, span);
206 (layout.size, layout.align.abi)
207 }
208}
209
210pub(crate) trait LayoutLlvmExt<'tcx> {
211 fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type;
212 fn immediate_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type;
213 fn scalar_llvm_type_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, scalar: Scalar) -> &'a Type;
214 fn scalar_pair_element_llvm_type<'a>(
215 &self,
216 cx: &CodegenCx<'a, 'tcx>,
217 index: usize,
218 immediate: bool,
219 ) -> &'a Type;
220}
221
222impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
223 fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
235 if let BackendRepr::Scalar(scalar) = self.backend_repr {
239 if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) {
242 return llty;
243 }
244 let llty = self.scalar_llvm_type_at(cx, scalar);
245 cx.scalar_lltypes.borrow_mut().insert(self.ty, llty);
246 return llty;
247 }
248
249 let variant_index = match self.variants {
251 Variants::Single { index } => Some(index),
252 _ => None,
253 };
254 if let Some(llty) = cx.type_lowering.borrow().get(&(self.ty, variant_index)) {
255 return llty;
256 }
257
258 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs:258",
"rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs"),
::tracing_core::__macro_support::Option::Some(258u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("llvm_type({0:#?})",
self) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("llvm_type({:#?})", self);
259
260 if !!self.ty.has_escaping_bound_vars() {
{
::core::panicking::panic_fmt(format_args!("{0:?} has escaping bound vars",
self.ty));
}
};assert!(!self.ty.has_escaping_bound_vars(), "{:?} has escaping bound vars", self.ty);
261
262 let normal_ty = cx.tcx.erase_and_anonymize_regions(self.ty);
265
266 let mut defer = None;
267 let llty = if self.ty != normal_ty {
268 let mut layout = cx.layout_of(normal_ty);
269 if let Some(v) = variant_index {
270 layout = layout.for_variant(cx, v);
271 }
272 layout.llvm_type(cx)
273 } else {
274 uncached_llvm_type(cx, *self, &mut defer)
275 };
276 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs:276",
"rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_codegen_llvm/src/type_of.rs"),
::tracing_core::__macro_support::Option::Some(276u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> mapped {0:#?} to llty={1:?}",
self, llty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("--> mapped {:#?} to llty={:?}", self, llty);
277
278 cx.type_lowering.borrow_mut().insert((self.ty, variant_index), llty);
279
280 if let Some((llty, layout)) = defer {
281 let (llfields, packed) = struct_llfields(cx, layout);
282 cx.set_struct_body(llty, &llfields, packed);
283 }
284 llty
285 }
286
287 fn immediate_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
288 match self.backend_repr {
289 BackendRepr::Scalar(scalar) => {
290 if scalar.is_bool() {
291 return cx.type_i1();
292 }
293 }
294 BackendRepr::ScalarPair { .. } => {
295 return cx.type_struct(
298 &[
299 self.scalar_pair_element_llvm_type(cx, 0, true),
300 self.scalar_pair_element_llvm_type(cx, 1, true),
301 ],
302 false,
303 );
304 }
305 _ => {}
306 };
307 self.llvm_type(cx)
308 }
309
310 fn scalar_llvm_type_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, scalar: Scalar) -> &'a Type {
311 match scalar.primitive() {
312 Int(i, _) => cx.type_from_integer(i),
313 Float(f) => cx.type_from_float(f),
314 Pointer(address_space) => cx.type_ptr_ext(address_space),
315 }
316 }
317
318 fn scalar_pair_element_llvm_type<'a>(
319 &self,
320 cx: &CodegenCx<'a, 'tcx>,
321 index: usize,
322 immediate: bool,
323 ) -> &'a Type {
324 let BackendRepr::ScalarPair { a, b, b_offset: _ } = self.backend_repr else {
328 bug_impl(None,
format_args!("TyAndLayout::scalar_pair_element_llty({0:?}): not applicable",
self), Location::caller());bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self);
329 };
330 let scalar = [a, b][index];
331
332 if immediate && scalar.is_bool() {
339 return cx.type_i1();
340 }
341
342 self.scalar_llvm_type_at(cx, scalar)
343 }
344}