Add load_vector function

This commit is contained in:
bjorn3 2019-12-23 16:48:19 +01:00
parent dadfbeab6c
commit f8e846dee0
2 changed files with 18 additions and 8 deletions

View File

@ -66,14 +66,6 @@ pub fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types:
}
}
ty::Param(_) => bug!("ty param {:?}", ty),
_ if ty.is_simd() => {
let (lane_type, lane_count) = crate::intrinsics::lane_type_and_count(
tcx,
tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap(),
);
let lane_type = clif_type_from_ty(tcx, lane_type.ty)?;
return lane_type.by(u16::try_from(lane_count).unwrap());
}
_ => return None,
})
}

View File

@ -161,6 +161,24 @@ impl<'tcx> CValue<'tcx> {
}
}
/// Load a value with layout.abi of vector
pub fn load_vector<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Value {
let layout = self.1;
match self.0 {
CValueInner::ByRef(ptr) => {
let clif_ty = match layout.abi {
layout::Abi::Vector { ref element, count } => {
scalar_to_clif_type(fx.tcx, element.clone()).by(u16::try_from(count).unwrap()).unwrap()
}
_ => unreachable!(),
};
ptr.load(fx, clif_ty, MemFlags::new())
}
CValueInner::ByVal(value) => value,
CValueInner::ByValPair(_, _) => bug!("Please use load_scalar_pair for ByValPair"),
}
}
pub fn value_field<'a>(
self,
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,