Skip to content

Commit 887f57f

Browse files
committed
Remove type_i1 and type_struct from cg_ssa
They are not representable by Cranelift
1 parent aacdce3 commit 887f57f

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

compiler/rustc_codegen_gcc/src/type_.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,34 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
8989
ty::FloatTy::F128 => self.type_f128(),
9090
}
9191
}
92-
}
9392

94-
impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
95-
fn type_i1(&self) -> Type<'gcc> {
93+
pub fn type_i1(&self) -> Type<'gcc> {
9694
self.bool_type
9795
}
9896

97+
pub fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
98+
let types = fields.to_vec();
99+
if let Some(typ) = self.struct_types.borrow().get(fields) {
100+
return *typ;
101+
}
102+
let fields: Vec<_> = fields
103+
.iter()
104+
.enumerate()
105+
.map(|(index, field)| {
106+
self.context.new_field(None, *field, format!("field{}_TODO", index))
107+
})
108+
.collect();
109+
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
110+
if packed {
111+
#[cfg(feature = "master")]
112+
typ.set_packed();
113+
}
114+
self.struct_types.borrow_mut().insert(types, typ);
115+
typ
116+
}
117+
}
118+
119+
impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
99120
fn type_i8(&self) -> Type<'gcc> {
100121
self.i8_type
101122
}
@@ -131,7 +152,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
131152
fn type_f64(&self) -> Type<'gcc> {
132153
self.double_type
133154
}
134-
155+
135156
fn type_f128(&self) -> Type<'gcc> {
136157
unimplemented!("f16_f128")
137158
}
@@ -140,27 +161,6 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
140161
self.context.new_function_pointer_type(None, return_type, params, false)
141162
}
142163

143-
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
144-
let types = fields.to_vec();
145-
if let Some(typ) = self.struct_types.borrow().get(fields) {
146-
return *typ;
147-
}
148-
let fields: Vec<_> = fields
149-
.iter()
150-
.enumerate()
151-
.map(|(index, field)| {
152-
self.context.new_field(None, *field, format!("field{}_TODO", index))
153-
})
154-
.collect();
155-
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
156-
if packed {
157-
#[cfg(feature = "master")]
158-
typ.set_packed();
159-
}
160-
self.struct_types.borrow_mut().insert(types, typ);
161-
typ
162-
}
163-
164164
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
165165
if self.is_int_type_or_bool(typ) {
166166
TypeKind::Integer

compiler/rustc_codegen_llvm/src/type_.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,24 @@ impl<'ll> CodegenCx<'ll, '_> {
127127
pub(crate) fn type_variadic_func(&self, args: &[&'ll Type], ret: &'ll Type) -> &'ll Type {
128128
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, True) }
129129
}
130-
}
131130

132-
impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
133-
fn type_i1(&self) -> &'ll Type {
131+
pub(crate) fn type_i1(&self) -> &'ll Type {
134132
unsafe { llvm::LLVMInt1TypeInContext(self.llcx) }
135133
}
136134

135+
pub(crate) fn type_struct(&self, els: &[&'ll Type], packed: bool) -> &'ll Type {
136+
unsafe {
137+
llvm::LLVMStructTypeInContext(
138+
self.llcx,
139+
els.as_ptr(),
140+
els.len() as c_uint,
141+
packed as Bool,
142+
)
143+
}
144+
}
145+
}
146+
147+
impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
137148
fn type_i8(&self) -> &'ll Type {
138149
unsafe { llvm::LLVMInt8TypeInContext(self.llcx) }
139150
}
@@ -178,17 +189,6 @@ impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
178189
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, False) }
179190
}
180191

181-
fn type_struct(&self, els: &[&'ll Type], packed: bool) -> &'ll Type {
182-
unsafe {
183-
llvm::LLVMStructTypeInContext(
184-
self.llcx,
185-
els.as_ptr(),
186-
els.len() as c_uint,
187-
packed as Bool,
188-
)
189-
}
190-
}
191-
192192
fn type_kind(&self, ty: &'ll Type) -> TypeKind {
193193
unsafe { llvm::LLVMRustGetTypeKind(ty).to_generic() }
194194
}

compiler/rustc_codegen_ssa/src/traits/type_.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_target::abi::{AddressSpace, Float, Integer};
1212
// This depends on `Backend` and not `BackendTypes`, because consumers will probably want to use
1313
// `LayoutOf` or `HasTyCtxt`. This way, they don't have to add a constraint on it themselves.
1414
pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
15-
fn type_i1(&self) -> Self::Type;
1615
fn type_i8(&self) -> Self::Type;
1716
fn type_i16(&self) -> Self::Type;
1817
fn type_i32(&self) -> Self::Type;
@@ -27,7 +26,6 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
2726

2827
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
2928
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
30-
fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type;
3129
fn type_kind(&self, ty: Self::Type) -> TypeKind;
3230
fn type_ptr(&self) -> Self::Type;
3331
fn type_ptr_ext(&self, address_space: AddressSpace) -> Self::Type;

0 commit comments

Comments
 (0)