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