diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-03-05 19:12:59 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-03-05 19:12:59 +0100 |
| commit | 27886cd6b6a52d5bf3d0a9ea667e04c5e8c59705 (patch) | |
| tree | b7542f3fe3fa244ae6c219bb04d381056efa407c /src/pointer.rs | |
| parent | 8b7d335c3846b8adb6f7ced2b66a7704bf83f9bb (diff) | |
| download | rust-27886cd6b6a52d5bf3d0a9ea667e04c5e8c59705.tar.gz rust-27886cd6b6a52d5bf3d0a9ea667e04c5e8c59705.zip | |
Merge commit '9a0c32934ebe376128230aa8da3275697b2053e7' into sync_cg_clif-2021-03-05
Diffstat (limited to 'src/pointer.rs')
| -rw-r--r-- | src/pointer.rs | 123 |
1 files changed, 26 insertions, 97 deletions
diff --git a/src/pointer.rs b/src/pointer.rs index b2036d7bcd4..88a78f3214d 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -23,35 +23,20 @@ pub(crate) enum PointerBase { impl Pointer { pub(crate) fn new(addr: Value) -> Self { - Pointer { - base: PointerBase::Addr(addr), - offset: Offset32::new(0), - } + Pointer { base: PointerBase::Addr(addr), offset: Offset32::new(0) } } pub(crate) fn stack_slot(stack_slot: StackSlot) -> Self { - Pointer { - base: PointerBase::Stack(stack_slot), - offset: Offset32::new(0), - } + Pointer { base: PointerBase::Stack(stack_slot), offset: Offset32::new(0) } } - pub(crate) fn const_addr<'a, 'tcx>( - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - addr: i64, - ) -> Self { + pub(crate) fn const_addr(fx: &mut FunctionCx<'_, '_, '_>, addr: i64) -> Self { let addr = fx.bcx.ins().iconst(fx.pointer_type, addr); - Pointer { - base: PointerBase::Addr(addr), - offset: Offset32::new(0), - } + Pointer { base: PointerBase::Addr(addr), offset: Offset32::new(0) } } pub(crate) fn dangling(align: Align) -> Self { - Pointer { - base: PointerBase::Dangling(align), - offset: Offset32::new(0), - } + Pointer { base: PointerBase::Dangling(align), offset: Offset32::new(0) } } #[cfg(debug_assertions)] @@ -59,46 +44,28 @@ impl Pointer { (self.base, self.offset) } - pub(crate) fn get_addr<'a, 'tcx>(self, fx: &mut FunctionCx<'a, 'tcx, impl Module>) -> Value { + pub(crate) fn get_addr(self, fx: &mut FunctionCx<'_, '_, '_>) -> Value { match self.base { PointerBase::Addr(base_addr) => { let offset: i64 = self.offset.into(); - if offset == 0 { - base_addr - } else { - fx.bcx.ins().iadd_imm(base_addr, offset) - } + if offset == 0 { base_addr } else { fx.bcx.ins().iadd_imm(base_addr, offset) } } PointerBase::Stack(stack_slot) => { - fx.bcx - .ins() - .stack_addr(fx.pointer_type, stack_slot, self.offset) + fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, self.offset) + } + PointerBase::Dangling(align) => { + fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap()) } - PointerBase::Dangling(align) => fx - .bcx - .ins() - .iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap()), } } - pub(crate) fn offset<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - extra_offset: Offset32, - ) -> Self { + pub(crate) fn offset(self, fx: &mut FunctionCx<'_, '_, '_>, extra_offset: Offset32) -> Self { self.offset_i64(fx, extra_offset.into()) } - pub(crate) fn offset_i64<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - extra_offset: i64, - ) -> Self { + pub(crate) fn offset_i64(self, fx: &mut FunctionCx<'_, '_, '_>, extra_offset: i64) -> Self { if let Some(new_offset) = self.offset.try_add_i64(extra_offset) { - Pointer { - base: self.base, - offset: new_offset, - } + Pointer { base: self.base, offset: new_offset } } else { let base_offset: i64 = self.offset.into(); if let Some(new_offset) = base_offset.checked_add(extra_offset) { @@ -107,16 +74,12 @@ impl Pointer { PointerBase::Stack(stack_slot) => { fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0) } - PointerBase::Dangling(align) => fx - .bcx - .ins() - .iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap()), + PointerBase::Dangling(align) => { + fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap()) + } }; let addr = fx.bcx.ins().iadd_imm(base_addr, new_offset); - Pointer { - base: PointerBase::Addr(addr), - offset: Offset32::new(0), - } + Pointer { base: PointerBase::Addr(addr), offset: Offset32::new(0) } } else { panic!( "self.offset ({}) + extra_offset ({}) not representable in i64", @@ -126,31 +89,22 @@ impl Pointer { } } - pub(crate) fn offset_value<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - extra_offset: Value, - ) -> Self { + pub(crate) fn offset_value(self, fx: &mut FunctionCx<'_, '_, '_>, extra_offset: Value) -> Self { match self.base { PointerBase::Addr(addr) => Pointer { base: PointerBase::Addr(fx.bcx.ins().iadd(addr, extra_offset)), offset: self.offset, }, PointerBase::Stack(stack_slot) => { - let base_addr = fx - .bcx - .ins() - .stack_addr(fx.pointer_type, stack_slot, self.offset); + let base_addr = fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, self.offset); Pointer { base: PointerBase::Addr(fx.bcx.ins().iadd(base_addr, extra_offset)), offset: Offset32::new(0), } } PointerBase::Dangling(align) => { - let addr = fx - .bcx - .ins() - .iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap()); + let addr = + fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap()); Pointer { base: PointerBase::Addr(fx.bcx.ins().iadd(addr, extra_offset)), offset: self.offset, @@ -159,46 +113,21 @@ impl Pointer { } } - pub(crate) fn load<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - ty: Type, - flags: MemFlags, - ) -> Value { + pub(crate) fn load(self, fx: &mut FunctionCx<'_, '_, '_>, ty: Type, flags: MemFlags) -> Value { match self.base { PointerBase::Addr(base_addr) => fx.bcx.ins().load(ty, flags, base_addr, self.offset), - PointerBase::Stack(stack_slot) => { - if ty == types::I128 || ty.is_vector() { - // WORKAROUND for stack_load.i128 and stack_load.iXxY not being implemented - let base_addr = fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0); - fx.bcx.ins().load(ty, flags, base_addr, self.offset) - } else { - fx.bcx.ins().stack_load(ty, stack_slot, self.offset) - } - } + PointerBase::Stack(stack_slot) => fx.bcx.ins().stack_load(ty, stack_slot, self.offset), PointerBase::Dangling(_align) => unreachable!(), } } - pub(crate) fn store<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - value: Value, - flags: MemFlags, - ) { + pub(crate) fn store(self, fx: &mut FunctionCx<'_, '_, '_>, value: Value, flags: MemFlags) { match self.base { PointerBase::Addr(base_addr) => { fx.bcx.ins().store(flags, value, base_addr, self.offset); } PointerBase::Stack(stack_slot) => { - let val_ty = fx.bcx.func.dfg.value_type(value); - if val_ty == types::I128 || val_ty.is_vector() { - // WORKAROUND for stack_store.i128 and stack_store.iXxY not being implemented - let base_addr = fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0); - fx.bcx.ins().store(flags, value, base_addr, self.offset); - } else { - fx.bcx.ins().stack_store(value, stack_slot, self.offset); - } + fx.bcx.ins().stack_store(value, stack_slot, self.offset); } PointerBase::Dangling(_align) => unreachable!(), } |
