mirror of https://github.com/rust-lang/rust.git
Stop using `to_hir_binop` in codegen
This commit is contained in:
parent
b54dd08a84
commit
8ee3d29cd9
|
@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::OperandRef;
|
||||||
use rustc_codegen_ssa::mir::place::PlaceRef;
|
use rustc_codegen_ssa::mir::place::PlaceRef;
|
||||||
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
|
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
use rustc_middle::mir::BinOp;
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::layout::HasTyCtxt;
|
use rustc_middle::ty::layout::HasTyCtxt;
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
|
@ -122,12 +123,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
|
||||||
let in_ty = arg_tys[0];
|
let in_ty = arg_tys[0];
|
||||||
|
|
||||||
let comparison = match name {
|
let comparison = match name {
|
||||||
sym::simd_eq => Some(hir::BinOpKind::Eq),
|
sym::simd_eq => Some(BinOp::Eq),
|
||||||
sym::simd_ne => Some(hir::BinOpKind::Ne),
|
sym::simd_ne => Some(BinOp::Ne),
|
||||||
sym::simd_lt => Some(hir::BinOpKind::Lt),
|
sym::simd_lt => Some(BinOp::Lt),
|
||||||
sym::simd_le => Some(hir::BinOpKind::Le),
|
sym::simd_le => Some(BinOp::Le),
|
||||||
sym::simd_gt => Some(hir::BinOpKind::Gt),
|
sym::simd_gt => Some(BinOp::Gt),
|
||||||
sym::simd_ge => Some(hir::BinOpKind::Ge),
|
sym::simd_ge => Some(BinOp::Ge),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
|
||||||
use rustc_codegen_ssa::mir::place::PlaceRef;
|
use rustc_codegen_ssa::mir::place::PlaceRef;
|
||||||
use rustc_codegen_ssa::traits::*;
|
use rustc_codegen_ssa::traits::*;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
use rustc_middle::mir::BinOp;
|
||||||
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf};
|
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf};
|
||||||
use rustc_middle::ty::{self, GenericArgsRef, Ty};
|
use rustc_middle::ty::{self, GenericArgsRef, Ty};
|
||||||
use rustc_middle::{bug, span_bug};
|
use rustc_middle::{bug, span_bug};
|
||||||
|
@ -1104,12 +1105,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
|
||||||
let in_ty = arg_tys[0];
|
let in_ty = arg_tys[0];
|
||||||
|
|
||||||
let comparison = match name {
|
let comparison = match name {
|
||||||
sym::simd_eq => Some(hir::BinOpKind::Eq),
|
sym::simd_eq => Some(BinOp::Eq),
|
||||||
sym::simd_ne => Some(hir::BinOpKind::Ne),
|
sym::simd_ne => Some(BinOp::Ne),
|
||||||
sym::simd_lt => Some(hir::BinOpKind::Lt),
|
sym::simd_lt => Some(BinOp::Lt),
|
||||||
sym::simd_le => Some(hir::BinOpKind::Le),
|
sym::simd_le => Some(BinOp::Le),
|
||||||
sym::simd_gt => Some(hir::BinOpKind::Gt),
|
sym::simd_gt => Some(BinOp::Gt),
|
||||||
sym::simd_ge => Some(hir::BinOpKind::Ge),
|
sym::simd_ge => Some(BinOp::Ge),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||||
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
|
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
|
||||||
use rustc_data_structures::sync::par_map;
|
use rustc_data_structures::sync::par_map;
|
||||||
use rustc_data_structures::unord::UnordMap;
|
use rustc_data_structures::unord::UnordMap;
|
||||||
use rustc_hir as hir;
|
|
||||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_metadata::EncodedMetadata;
|
use rustc_metadata::EncodedMetadata;
|
||||||
|
@ -30,6 +29,7 @@ use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, Debugger
|
||||||
use rustc_middle::middle::exported_symbols;
|
use rustc_middle::middle::exported_symbols;
|
||||||
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
||||||
use rustc_middle::middle::lang_items;
|
use rustc_middle::middle::lang_items;
|
||||||
|
use rustc_middle::mir::BinOp;
|
||||||
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
|
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
|
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
|
||||||
|
@ -46,32 +46,32 @@ use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> IntPredicate {
|
pub fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate {
|
||||||
match op {
|
match op {
|
||||||
hir::BinOpKind::Eq => IntPredicate::IntEQ,
|
BinOp::Eq => IntPredicate::IntEQ,
|
||||||
hir::BinOpKind::Ne => IntPredicate::IntNE,
|
BinOp::Ne => IntPredicate::IntNE,
|
||||||
hir::BinOpKind::Lt => {
|
BinOp::Lt => {
|
||||||
if signed {
|
if signed {
|
||||||
IntPredicate::IntSLT
|
IntPredicate::IntSLT
|
||||||
} else {
|
} else {
|
||||||
IntPredicate::IntULT
|
IntPredicate::IntULT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::BinOpKind::Le => {
|
BinOp::Le => {
|
||||||
if signed {
|
if signed {
|
||||||
IntPredicate::IntSLE
|
IntPredicate::IntSLE
|
||||||
} else {
|
} else {
|
||||||
IntPredicate::IntULE
|
IntPredicate::IntULE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::BinOpKind::Gt => {
|
BinOp::Gt => {
|
||||||
if signed {
|
if signed {
|
||||||
IntPredicate::IntSGT
|
IntPredicate::IntSGT
|
||||||
} else {
|
} else {
|
||||||
IntPredicate::IntUGT
|
IntPredicate::IntUGT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::BinOpKind::Ge => {
|
BinOp::Ge => {
|
||||||
if signed {
|
if signed {
|
||||||
IntPredicate::IntSGE
|
IntPredicate::IntSGE
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,14 +86,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> IntPredicat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
|
pub fn bin_op_to_fcmp_predicate(op: BinOp) -> RealPredicate {
|
||||||
match op {
|
match op {
|
||||||
hir::BinOpKind::Eq => RealPredicate::RealOEQ,
|
BinOp::Eq => RealPredicate::RealOEQ,
|
||||||
hir::BinOpKind::Ne => RealPredicate::RealUNE,
|
BinOp::Ne => RealPredicate::RealUNE,
|
||||||
hir::BinOpKind::Lt => RealPredicate::RealOLT,
|
BinOp::Lt => RealPredicate::RealOLT,
|
||||||
hir::BinOpKind::Le => RealPredicate::RealOLE,
|
BinOp::Le => RealPredicate::RealOLE,
|
||||||
hir::BinOpKind::Gt => RealPredicate::RealOGT,
|
BinOp::Gt => RealPredicate::RealOGT,
|
||||||
hir::BinOpKind::Ge => RealPredicate::RealOGE,
|
BinOp::Ge => RealPredicate::RealOGE,
|
||||||
op => {
|
op => {
|
||||||
bug!(
|
bug!(
|
||||||
"comparison_op_to_fcmp_predicate: expected comparison operator, \
|
"comparison_op_to_fcmp_predicate: expected comparison operator, \
|
||||||
|
@ -110,7 +110,7 @@ pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||||
rhs: Bx::Value,
|
rhs: Bx::Value,
|
||||||
t: Ty<'tcx>,
|
t: Ty<'tcx>,
|
||||||
ret_ty: Bx::Type,
|
ret_ty: Bx::Type,
|
||||||
op: hir::BinOpKind,
|
op: BinOp,
|
||||||
) -> Bx::Value {
|
) -> Bx::Value {
|
||||||
let signed = match t.kind() {
|
let signed = match t.kind() {
|
||||||
ty::Float(_) => {
|
ty::Float(_) => {
|
||||||
|
|
|
@ -7,7 +7,6 @@ use crate::common::IntPredicate;
|
||||||
use crate::traits::*;
|
use crate::traits::*;
|
||||||
use crate::MemFlags;
|
use crate::MemFlags;
|
||||||
|
|
||||||
use rustc_hir as hir;
|
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
use rustc_middle::ty::cast::{CastTy, IntTy};
|
use rustc_middle::ty::cast::{CastTy, IntTy};
|
||||||
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
|
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
|
||||||
|
@ -896,9 +895,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
| mir::BinOp::Le
|
| mir::BinOp::Le
|
||||||
| mir::BinOp::Ge => {
|
| mir::BinOp::Ge => {
|
||||||
if is_float {
|
if is_float {
|
||||||
bx.fcmp(base::bin_op_to_fcmp_predicate(op.to_hir_binop()), lhs, rhs)
|
bx.fcmp(base::bin_op_to_fcmp_predicate(op), lhs, rhs)
|
||||||
} else {
|
} else {
|
||||||
bx.icmp(base::bin_op_to_icmp_predicate(op.to_hir_binop(), is_signed), lhs, rhs)
|
bx.icmp(base::bin_op_to_icmp_predicate(op, is_signed), lhs, rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mir::BinOp::Cmp => {
|
mir::BinOp::Cmp => {
|
||||||
|
@ -912,16 +911,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
// `PartialOrd`, so only use it in debug for now. Once LLVM can handle it
|
// `PartialOrd`, so only use it in debug for now. Once LLVM can handle it
|
||||||
// better (see <https://github.com/llvm/llvm-project/issues/73417>), it'll
|
// better (see <https://github.com/llvm/llvm-project/issues/73417>), it'll
|
||||||
// be worth trying it in optimized builds as well.
|
// be worth trying it in optimized builds as well.
|
||||||
let is_gt = bx.icmp(pred(hir::BinOpKind::Gt), lhs, rhs);
|
let is_gt = bx.icmp(pred(mir::BinOp::Gt), lhs, rhs);
|
||||||
let gtext = bx.zext(is_gt, bx.type_i8());
|
let gtext = bx.zext(is_gt, bx.type_i8());
|
||||||
let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs);
|
let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs);
|
||||||
let ltext = bx.zext(is_lt, bx.type_i8());
|
let ltext = bx.zext(is_lt, bx.type_i8());
|
||||||
bx.unchecked_ssub(gtext, ltext)
|
bx.unchecked_ssub(gtext, ltext)
|
||||||
} else {
|
} else {
|
||||||
// These operations are those expected by `tests/codegen/integer-cmp.rs`,
|
// These operations are those expected by `tests/codegen/integer-cmp.rs`,
|
||||||
// from <https://github.com/rust-lang/rust/pull/63767>.
|
// from <https://github.com/rust-lang/rust/pull/63767>.
|
||||||
let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs);
|
let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs);
|
||||||
let is_ne = bx.icmp(pred(hir::BinOpKind::Ne), lhs, rhs);
|
let is_ne = bx.icmp(pred(mir::BinOp::Ne), lhs, rhs);
|
||||||
let ge = bx.select(
|
let ge = bx.select(
|
||||||
is_ne,
|
is_ne,
|
||||||
bx.cx().const_i8(Ordering::Greater as i8),
|
bx.cx().const_i8(Ordering::Greater as i8),
|
||||||
|
|
|
@ -295,7 +295,7 @@ impl BorrowKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BinOp {
|
impl BinOp {
|
||||||
pub fn to_hir_binop(self) -> hir::BinOpKind {
|
pub(crate) fn to_hir_binop(self) -> hir::BinOpKind {
|
||||||
match self {
|
match self {
|
||||||
BinOp::Add => hir::BinOpKind::Add,
|
BinOp::Add => hir::BinOpKind::Add,
|
||||||
BinOp::Sub => hir::BinOpKind::Sub,
|
BinOp::Sub => hir::BinOpKind::Sub,
|
||||||
|
|
Loading…
Reference in New Issue