1
Fork 0

deduplicate constant evaluation in cranelift backend

also sync LLVM and cranelift structure a bit
This commit is contained in:
Ralf Jung 2022-11-19 13:41:21 +01:00
parent becc24a23a
commit 3338244f69
3 changed files with 31 additions and 51 deletions

View file

@ -1,5 +1,4 @@
use crate::mir::interpret::LitToConstInput;
use crate::mir::ConstantKind;
use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
use rustc_data_structures::intern::Interned;
use rustc_hir as hir;
@ -230,20 +229,6 @@ impl<'tcx> Const<'tcx> {
}
}
#[inline]
/// Tries to evaluate the constant if it is `Unevaluated` and creates a ConstValue if the
/// evaluation succeeds. If it doesn't succeed, returns the unevaluated constant.
pub fn eval_for_mir(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> ConstantKind<'tcx> {
if let Some(val) = self.kind().try_eval_for_mir(tcx, param_env) {
match val {
Ok(const_val) => ConstantKind::from_value(const_val, self.ty()),
Err(guar) => ConstantKind::Ty(tcx.const_error_with_guaranteed(self.ty(), guar)),
}
} else {
ConstantKind::Ty(self)
}
}
#[inline]
/// Panics if the value cannot be evaluated or doesn't contain a valid integer of the given type.
pub fn eval_bits(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> u128 {