Skip to content

Commit b976427

Browse files
committed
Fix LLVMConst{I,F}Cmp
1 parent e42fcb9 commit b976427

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/librustc/lib/llvm.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ pub mod llvm {
220220
use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
221221
use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
222222
use super::{ValueRef};
223-
use super::{IntPredicate, RealPredicate};
224223

225224
use core::libc::{c_char, c_int, c_longlong, c_uint, c_ulonglong};
226225

@@ -453,9 +452,9 @@ pub mod llvm {
453452
#[fast_ffi]
454453
pub unsafe fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
455454
#[fast_ffi]
456-
pub unsafe fn LLVMConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef;
455+
pub unsafe fn LLVMConstICmp(Pred: c_uint, V1: ValueRef, V2: ValueRef) -> ValueRef;
457456
#[fast_ffi]
458-
pub unsafe fn LLVMConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef;
457+
pub unsafe fn LLVMConstFCmp(Pred: c_uint, V1: ValueRef, V2: ValueRef) -> ValueRef;
459458
/* only for int/vector */
460459
#[fast_ffi]
461460
pub unsafe fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
@@ -1919,6 +1918,16 @@ pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
19191918
}
19201919
}
19211920

1921+
pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1922+
unsafe {
1923+
llvm::LLVMConstICmp(Pred as c_uint, V1, V2)
1924+
}
1925+
}
1926+
pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1927+
unsafe {
1928+
llvm::LLVMConstICmp(Pred as c_uint, V1, V2)
1929+
}
1930+
}
19221931
/* Memory-managed object interface to type handles. */
19231932

19241933
pub struct TypeNames {

src/librustc/middle/trans/consts.rs

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

1111
use back::abi;
12-
use lib::llvm::{llvm, SetLinkage, PrivateLinkage, ValueRef, TypeRef, Bool, True, False};
12+
use lib::llvm::{llvm, ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, TypeRef, Bool,
13+
True, False};
1314
use lib::llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, IntSLT, IntSLE,
1415
RealOEQ, RealOGT, RealOGE, RealOLT, RealOLE, RealONE};
1516

@@ -293,39 +294,39 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
293294
else { llvm::LLVMConstLShr(te1, te2) }
294295
}
295296
ast::eq => {
296-
if is_float { llvm::LLVMConstFCmp(RealOEQ, te1, te2) }
297-
else { llvm::LLVMConstICmp(IntEQ, te1, te2) }
297+
if is_float { ConstFCmp(RealOEQ, te1, te2) }
298+
else { ConstICmp(IntEQ, te1, te2) }
298299
},
299300
ast::lt => {
300-
if is_float { llvm::LLVMConstFCmp(RealOLT, te1, te2) }
301+
if is_float { ConstFCmp(RealOLT, te1, te2) }
301302
else {
302-
if signed { llvm::LLVMConstICmp(IntSLT, te1, te2) }
303-
else { llvm::LLVMConstICmp(IntULT, te1, te2) }
303+
if signed { ConstICmp(IntSLT, te1, te2) }
304+
else { ConstICmp(IntULT, te1, te2) }
304305
}
305306
},
306307
ast::le => {
307-
if is_float { llvm::LLVMConstFCmp(RealOLE, te1, te2) }
308+
if is_float { ConstFCmp(RealOLE, te1, te2) }
308309
else {
309-
if signed { llvm::LLVMConstICmp(IntSLE, te1, te2) }
310-
else { llvm::LLVMConstICmp(IntULE, te1, te2) }
310+
if signed { ConstICmp(IntSLE, te1, te2) }
311+
else { ConstICmp(IntULE, te1, te2) }
311312
}
312313
},
313314
ast::ne => {
314-
if is_float { llvm::LLVMConstFCmp(RealONE, te1, te2) }
315-
else { llvm::LLVMConstICmp(IntNE, te1, te2) }
315+
if is_float { ConstFCmp(RealONE, te1, te2) }
316+
else { ConstICmp(IntNE, te1, te2) }
316317
},
317318
ast::ge => {
318-
if is_float { llvm::LLVMConstFCmp(RealOGE, te1, te2) }
319+
if is_float { ConstFCmp(RealOGE, te1, te2) }
319320
else {
320-
if signed { llvm::LLVMConstICmp(IntSGE, te1, te2) }
321-
else { llvm::LLVMConstICmp(IntUGE, te1, te2) }
321+
if signed { ConstICmp(IntSGE, te1, te2) }
322+
else { ConstICmp(IntUGE, te1, te2) }
322323
}
323324
},
324325
ast::gt => {
325-
if is_float { llvm::LLVMConstFCmp(RealOGT, te1, te2) }
326+
if is_float { ConstFCmp(RealOGT, te1, te2) }
326327
else {
327-
if signed { llvm::LLVMConstICmp(IntSGT, te1, te2) }
328-
else { llvm::LLVMConstICmp(IntUGT, te1, te2) }
328+
if signed { ConstICmp(IntSGT, te1, te2) }
329+
else { ConstICmp(IntUGT, te1, te2) }
329330
}
330331
},
331332
};

0 commit comments

Comments
 (0)