|
1 | 1 | use gccjit::LValue;
|
2 | 2 | use gccjit::{RValue, Type, ToRValue};
|
3 |
| -use rustc_codegen_ssa::mir::place::PlaceRef; |
4 | 3 | use rustc_codegen_ssa::traits::{
|
5 | 4 | BaseTypeMethods,
|
6 | 5 | ConstMethods,
|
7 |
| - DerivedTypeMethods, |
8 | 6 | MiscMethods,
|
9 | 7 | StaticMethods,
|
10 | 8 | };
|
11 | 9 | use rustc_middle::mir::Mutability;
|
12 |
| -use rustc_middle::ty::layout::{TyAndLayout, LayoutOf}; |
| 10 | +use rustc_middle::ty::layout::{LayoutOf}; |
13 | 11 | use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
|
14 |
| -use rustc_target::abi::{self, HasDataLayout, Pointer, Size}; |
| 12 | +use rustc_target::abi::{self, HasDataLayout, Pointer}; |
15 | 13 |
|
16 | 14 | use crate::consts::const_alloc_to_gcc;
|
17 | 15 | use crate::context::CodegenCx;
|
@@ -240,28 +238,26 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
|
240 | 238 | const_alloc_to_gcc(self, alloc)
|
241 | 239 | }
|
242 | 240 |
|
243 |
| - fn from_const_alloc(&self, layout: TyAndLayout<'tcx>, alloc: ConstAllocation<'tcx>, offset: Size) -> PlaceRef<'tcx, RValue<'gcc>> { |
244 |
| - assert_eq!(alloc.inner().align, layout.align.abi); |
245 |
| - let ty = self.type_ptr_to(layout.gcc_type(self)); |
246 |
| - let value = |
247 |
| - if layout.size == Size::ZERO { |
248 |
| - let value = self.const_usize(alloc.inner().align.bytes()); |
249 |
| - self.const_bitcast(value, ty) |
250 |
| - } |
251 |
| - else { |
252 |
| - let init = const_alloc_to_gcc(self, alloc); |
253 |
| - let base_addr = self.static_addr_of(init, alloc.inner().align, None); |
254 |
| - |
255 |
| - let array = self.const_bitcast(base_addr, self.type_i8p()); |
256 |
| - let value = self.context.new_array_access(None, array, self.const_usize(offset.bytes())).get_address(None); |
257 |
| - self.const_bitcast(value, ty) |
258 |
| - }; |
259 |
| - PlaceRef::new_sized(value, layout) |
260 |
| - } |
261 |
| - |
262 | 241 | fn const_ptrcast(&self, val: RValue<'gcc>, ty: Type<'gcc>) -> RValue<'gcc> {
|
263 | 242 | self.context.new_cast(None, val, ty)
|
264 | 243 | }
|
| 244 | + |
| 245 | + fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc> { |
| 246 | + if value.get_type() == self.bool_type.make_pointer() { |
| 247 | + if let Some(pointee) = typ.get_pointee() { |
| 248 | + if pointee.dyncast_vector().is_some() { |
| 249 | + panic!() |
| 250 | + } |
| 251 | + } |
| 252 | + } |
| 253 | + // NOTE: since bitcast makes a value non-constant, don't bitcast if not necessary as some |
| 254 | + // SIMD builtins require a constant value. |
| 255 | + self.bitcast_if_needed(value, typ) |
| 256 | + } |
| 257 | + |
| 258 | + fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value { |
| 259 | + self.context.new_array_access(None, base_addr, self.const_usize(offset.bytes())).get_address(None) |
| 260 | + } |
265 | 261 | }
|
266 | 262 |
|
267 | 263 | pub trait SignType<'gcc, 'tcx> {
|
|
0 commit comments