Skip to content

Commit 8590336

Browse files
denismerigouxeddyb
authored andcommitted
Generalized RealPredicate
1 parent 51b7f27 commit 8590336

File tree

5 files changed

+62
-16
lines changed

5 files changed

+62
-16
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
7575
use rustc_data_structures::sync::Lrc;
7676
use rustc_data_structures::indexed_vec::Idx;
7777

78-
use traits::{IntPredicate, BuilderMethods};
78+
use traits::{IntPredicate, RealPredicate, BuilderMethods};
7979
use llvm::BasicBlock;
8080

8181
use std::any::Any;
@@ -143,14 +143,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind,
143143
}
144144
}
145145

146-
pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> llvm::RealPredicate {
146+
pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
147147
match op {
148-
hir::BinOpKind::Eq => llvm::RealOEQ,
149-
hir::BinOpKind::Ne => llvm::RealUNE,
150-
hir::BinOpKind::Lt => llvm::RealOLT,
151-
hir::BinOpKind::Le => llvm::RealOLE,
152-
hir::BinOpKind::Gt => llvm::RealOGT,
153-
hir::BinOpKind::Ge => llvm::RealOGE,
148+
hir::BinOpKind::Eq => RealPredicate::RealOEQ,
149+
hir::BinOpKind::Ne => RealPredicate::RealUNE,
150+
hir::BinOpKind::Lt => RealPredicate::RealOLT,
151+
hir::BinOpKind::Le => RealPredicate::RealOLE,
152+
hir::BinOpKind::Gt => RealPredicate::RealOGT,
153+
hir::BinOpKind::Ge => RealPredicate::RealOGE,
154154
op => {
155155
bug!("comparison_op_to_fcmp_predicate: expected comparison operator, \
156156
found {:?}",

src/librustc_codegen_llvm/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect};
12-
use llvm::{RealPredicate, False, OperandBundleDef};
12+
use llvm::{False, OperandBundleDef};
1313
use llvm::{self, BasicBlock};
1414
use common::*;
1515
use type_::Type;
@@ -697,7 +697,7 @@ impl BuilderMethods<'a, 'll, 'tcx, Value, BasicBlock>
697697
}
698698
}
699699

700-
fn fcmp(&self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
700+
fn fcmp(&self, op: traits::RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
701701
self.count_insn("fcmp");
702702
unsafe {
703703
llvm::LLVMBuildFCmp(self.llbuilder, op as c_uint, lhs, rhs, noname())

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,29 @@ pub enum RealPredicate {
181181
RealPredicateTrue = 15,
182182
}
183183

184+
impl traits::RealPredicateMethods for RealPredicate {
185+
fn convert_to_backend_specific(realpred: traits::RealPredicate) -> Self {
186+
match realpred {
187+
traits::RealPredicate::RealPredicateFalse => RealPredicate::RealPredicateFalse,
188+
traits::RealPredicate::RealOEQ => RealPredicate::RealOEQ,
189+
traits::RealPredicate::RealOGT => RealPredicate::RealOGT,
190+
traits::RealPredicate::RealOGE => RealPredicate::RealOGE,
191+
traits::RealPredicate::RealOLT => RealPredicate::RealOLT,
192+
traits::RealPredicate::RealOLE => RealPredicate::RealOLE,
193+
traits::RealPredicate::RealONE => RealPredicate::RealONE,
194+
traits::RealPredicate::RealORD => RealPredicate::RealORD,
195+
traits::RealPredicate::RealUNO => RealPredicate::RealUNO,
196+
traits::RealPredicate::RealUEQ => RealPredicate::RealUEQ,
197+
traits::RealPredicate::RealUGT => RealPredicate::RealUGT,
198+
traits::RealPredicate::RealUGE => RealPredicate::RealUGE,
199+
traits::RealPredicate::RealULT => RealPredicate::RealULT,
200+
traits::RealPredicate::RealULE => RealPredicate::RealULE,
201+
traits::RealPredicate::RealUNE => RealPredicate::RealUNE,
202+
traits::RealPredicate::RealPredicateTrue => RealPredicate::RealPredicateTrue
203+
}
204+
}
205+
}
206+
184207
/// LLVMTypeKind
185208
#[derive(Copy, Clone, PartialEq, Debug)]
186209
#[repr(C)]

src/librustc_codegen_llvm/mir/rvalue.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use llvm;
1211
use rustc::ty::{self, Ty};
1312
use rustc::ty::cast::{CastTy, IntTy};
1413
use rustc::ty::layout::{self, LayoutOf};
@@ -28,7 +27,7 @@ use type_::Type;
2827
use type_of::LayoutLlvmExt;
2928
use value::Value;
3029

31-
use traits::{IntPredicate,BuilderMethods};
30+
use traits::{IntPredicate, RealPredicate, BuilderMethods};
3231

3332
use super::{FunctionCx, LocalRef};
3433
use super::operand::{OperandRef, OperandValue};
@@ -962,8 +961,8 @@ fn cast_float_to_int(bx: &Builder<'_, 'll, '_>,
962961
// negation, and the negation can be merged into the select. Therefore, it not necessarily any
963962
// more expensive than a ordered ("normal") comparison. Whether these optimizations will be
964963
// performed is ultimately up to the backend, but at least x86 does perform them.
965-
let less_or_nan = bx.fcmp(llvm::RealULT, x, f_min);
966-
let greater = bx.fcmp(llvm::RealOGT, x, f_max);
964+
let less_or_nan = bx.fcmp(RealPredicate::RealULT, x, f_min);
965+
let greater = bx.fcmp(RealPredicate::RealOGT, x, f_max);
967966
let int_max = C_uint_big(int_ty, int_max(signed, int_ty));
968967
let int_min = C_uint_big(int_ty, int_min(signed, int_ty) as u128);
969968
let s0 = bx.select(less_or_nan, int_min, fptosui_result);
@@ -974,7 +973,7 @@ fn cast_float_to_int(bx: &Builder<'_, 'll, '_>,
974973
// Therefore we only need to execute this step for signed integer types.
975974
if signed {
976975
// LLVM has no isNaN predicate, so we use (x == x) instead
977-
bx.select(bx.fcmp(llvm::RealOEQ, x, x), s1, C_uint(int_ty, 0))
976+
bx.select(bx.fcmp(RealPredicate::RealOEQ, x, x), s1, C_uint(int_ty, 0))
978977
} else {
979978
s1
980979
}

src/librustc_codegen_llvm/traits.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect};
12-
use llvm::{RealPredicate, OperandBundleDef};
12+
use llvm::OperandBundleDef;
1313
use common::*;
1414
use type_::Type;
1515
use libc::c_char;
@@ -38,6 +38,30 @@ pub trait IntPredicateMethods {
3838
fn convert_to_backend_specific(intpre : IntPredicate) -> Self;
3939
}
4040

41+
#[allow(dead_code)]
42+
pub enum RealPredicate {
43+
RealPredicateFalse,
44+
RealOEQ,
45+
RealOGT,
46+
RealOGE,
47+
RealOLT,
48+
RealOLE,
49+
RealONE,
50+
RealORD,
51+
RealUNO,
52+
RealUEQ,
53+
RealUGT,
54+
RealUGE,
55+
RealULT,
56+
RealULE,
57+
RealUNE,
58+
RealPredicateTrue,
59+
}
60+
61+
pub trait RealPredicateMethods {
62+
fn convert_to_backend_specific(realpred : RealPredicate) -> Self;
63+
}
64+
4165

4266
pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll,
4367
Value : ?Sized,

0 commit comments

Comments
 (0)