Skip to content

Added spelled-out aliases for abbreviated predicate cases. #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Sources/LLVM/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ public struct Constant<Repr: ConstantRepresentation>: IRValue {

switch lhs.repr {
case .signed:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.eq.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.equal.llvm, lhs.llvm, rhs.llvm))
case .unsigned:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.eq.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.equal.llvm, lhs.llvm, rhs.llvm))
case .floating:
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.oeq.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedEqual.llvm, lhs.llvm, rhs.llvm))
}
}

Expand All @@ -343,11 +343,11 @@ public struct Constant<Repr: ConstantRepresentation>: IRValue {

switch lhs.repr {
case .signed:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.slt.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedLessThan.llvm, lhs.llvm, rhs.llvm))
case .unsigned:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.ult.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedLessThan.llvm, lhs.llvm, rhs.llvm))
case .floating:
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.olt.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedLessThan.llvm, lhs.llvm, rhs.llvm))
}
}

Expand All @@ -363,11 +363,11 @@ public struct Constant<Repr: ConstantRepresentation>: IRValue {

switch lhs.repr {
case .signed:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.sgt.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedGreaterThan.llvm, lhs.llvm, rhs.llvm))
case .unsigned:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.ugt.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedGreaterThan.llvm, lhs.llvm, rhs.llvm))
case .floating:
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.ogt.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedGreaterThan.llvm, lhs.llvm, rhs.llvm))
}
}

Expand All @@ -383,11 +383,11 @@ public struct Constant<Repr: ConstantRepresentation>: IRValue {

switch lhs.repr {
case .signed:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.sle.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm))
case .unsigned:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.ule.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm))
case .floating:
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.ole.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm))
}
}

Expand All @@ -403,11 +403,11 @@ public struct Constant<Repr: ConstantRepresentation>: IRValue {

switch lhs.repr {
case .signed:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.sge.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm))
case .unsigned:
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.uge.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm))
case .floating:
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.oge.llvm, lhs.llvm, rhs.llvm))
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm))
}
}
}
Expand Down
70 changes: 37 additions & 33 deletions Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,43 @@ public enum OverflowBehavior {
public enum IntPredicate {
/// Yields `true` if the operands are equal, false otherwise without sign
/// interpretation.
case eq
case equal
/// Yields `true` if the operands are unequal, false otherwise without sign
/// interpretation.
case ne
case notEqual

/// Interprets the operands as unsigned values and yields true if the first is
/// greater than the second.
case ugt
case unsignedGreaterThan
/// Interprets the operands as unsigned values and yields true if the first is
/// greater than or equal to the second.
case uge
case unsignedGreaterThanOrEqual
/// Interprets the operands as unsigned values and yields true if the first is
/// less than the second.
case ult
case unsignedLessThan
/// Interprets the operands as unsigned values and yields true if the first is
/// less than or equal to the second.
case ule
case unsignedLessThanOrEqual

/// Interprets the operands as signed values and yields true if the first is
/// greater than the second.
case sgt
case signedGreaterThan
/// Interprets the operands as signed values and yields true if the first is
/// greater than or equal to the second.
case sge
case signedGreaterThanOrEqual
/// Interprets the operands as signed values and yields true if the first is
/// less than the second.
case slt
case signedLessThan
/// Interprets the operands as signed values and yields true if the first is
/// less than or equal to the second.
case sle
case signedLessThanOrEqual

static let predicateMapping: [IntPredicate: LLVMIntPredicate] = [
.eq: LLVMIntEQ, .ne: LLVMIntNE, .ugt: LLVMIntUGT, .uge: LLVMIntUGE,
.ult: LLVMIntULT, .ule: LLVMIntULE, .sgt: LLVMIntSGT, .sge: LLVMIntSGE,
.slt: LLVMIntSLT, .sle: LLVMIntSLE,
.equal: LLVMIntEQ, .notEqual: LLVMIntNE, .unsignedGreaterThan: LLVMIntUGT,
.unsignedGreaterThanOrEqual: LLVMIntUGE, .unsignedLessThan: LLVMIntULT,
.unsignedLessThanOrEqual: LLVMIntULE, .signedGreaterThan: LLVMIntSGT,
.signedGreaterThanOrEqual: LLVMIntSGE, .signedLessThan: LLVMIntSLT,
.signedLessThanOrEqual: LLVMIntSLE,
]

/// Retrieves the corresponding `LLVMIntPredicate`.
Expand All @@ -68,42 +70,44 @@ public enum RealPredicate {
/// No comparison, always returns `false`.
case `false`
/// Ordered and equal.
case oeq
case orderedEqual
/// Ordered greater than.
case ogt
case orderedGreaterThan
/// Ordered greater than or equal.
case oge
case orderedGreaterThanOrEqual
/// Ordered less than.
case olt
case orderedLessThan
/// Ordered less than or equal.
case ole
case orderedLessThanOrEqual
/// Ordered and not equal.
case one
/// Oredered (no nans).
case ord
case orderedNotEqual
/// Ordered (no nans).
case ordered
/// Unordered (either nans).
case uno
case unordered
/// Unordered or equal.
case ueq
case unorderedEqual
/// Unordered or greater than.
case ugt
case unorderedGreaterThan
/// Unordered or greater than or equal.
case uge
case unorderedGreaterThanOrEqual
/// Unordered or less than.
case ult
case unorderedLessThan
/// Unordered or less than or equal.
case ule
case unorderedLessThanOrEqual
/// Unordered or not equal.
case une
case unorderedNotEqual
/// No comparison, always returns `true`.
case `true`

static let predicateMapping: [RealPredicate: LLVMRealPredicate] = [
.false: LLVMRealPredicateFalse, .oeq: LLVMRealOEQ, .ogt: LLVMRealOGT,
.oge: LLVMRealOGE, .olt: LLVMRealOLT, .ole: LLVMRealOLE,
.one: LLVMRealONE, .ord: LLVMRealORD, .uno: LLVMRealUNO,
.ueq: LLVMRealUEQ, .ugt: LLVMRealUGT, .uge: LLVMRealUGE,
.ult: LLVMRealULT, .ule: LLVMRealULE, .une: LLVMRealUNE,
.false: LLVMRealPredicateFalse, .orderedEqual: LLVMRealOEQ,
.orderedGreaterThan: LLVMRealOGT, .orderedGreaterThanOrEqual: LLVMRealOGE,
.orderedLessThan: LLVMRealOLT, .orderedLessThanOrEqual: LLVMRealOLE,
.orderedNotEqual: LLVMRealONE, .ordered: LLVMRealORD, .unordered: LLVMRealUNO,
.unorderedEqual: LLVMRealUEQ, .unorderedGreaterThan: LLVMRealUGT,
.unorderedGreaterThanOrEqual: LLVMRealUGE, .unorderedLessThan: LLVMRealULT,
.unorderedLessThanOrEqual: LLVMRealULE, .unorderedNotEqual: LLVMRealUNE,
.true: LLVMRealPredicateTrue,
]

Expand Down
90 changes: 90 additions & 0 deletions Sources/LLVM/Predicates+Deprecations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
extension IntPredicate {
/// Yields `true` if the operands are equal, false otherwise without sign
/// interpretation.
@available(*, deprecated, renamed: "equal")
public static let eq = equal
/// Yields `true` if the operands are unequal, false otherwise without sign
/// interpretation.
@available(*, deprecated, renamed: "notEqual")
public static let ne = notEqual

/// Interprets the operands as unsigned values and yields true if the first is
/// greater than the second.
@available(*, deprecated, renamed: "unsignedGreaterThan")
public static let ugt = unsignedGreaterThan
/// Interprets the operands as unsigned values and yields true if the first is
/// greater than or equal to the second.

@available(*, deprecated, renamed: "unsignedGreaterThanOrEqual")
public static let uge = unsignedGreaterThanOrEqual
/// Interprets the operands as unsigned values and yields true if the first is
/// less than the second.
@available(*, deprecated, renamed: "unsignedLessThan")
public static let ult = unsignedLessThan
/// Interprets the operands as unsigned values and yields true if the first is
/// less than or equal to the second.
@available(*, deprecated, renamed: "unsignedLessThanOrEqual")
public static let ule = unsignedLessThanOrEqual

/// Interprets the operands as signed values and yields true if the first is
/// greater than the second.
@available(*, deprecated, renamed: "signedGreaterThan")
public static let sgt = signedGreaterThan
/// Interprets the operands as signed values and yields true if the first is
/// greater than or equal to the second.
@available(*, deprecated, renamed: "signedGreaterThanOrEqual")
public static let sge = signedGreaterThanOrEqual
/// Interprets the operands as signed values and yields true if the first is
/// less than the second.
@available(*, deprecated, renamed: "signedLessThan")
public static let slt = signedLessThan
/// Interprets the operands as signed values and yields true if the first is
/// less than or equal to the second.
@available(*, deprecated, renamed: "signedLessThanOrEqual")
public static let sle = signedLessThanOrEqual
}

extension RealPredicate {
/// Ordered and equal.
@available(*, deprecated, renamed: "orderedEqual")
public static let oeq = orderedEqual
/// Ordered greater than.
@available(*, deprecated, renamed: "orderedGreaterThan")
public static let ogt = orderedGreaterThan
/// Ordered greater than or equal.
@available(*, deprecated, renamed: "orderedGreaterThanOrEqual")
public static let oge = orderedGreaterThanOrEqual
/// Ordered less than.
@available(*, deprecated, renamed: "orderedLessThan")
public static let olt = orderedLessThan
/// Ordered less than or equal.
@available(*, deprecated, renamed: "orderedLessThanOrEqual")
public static let ole = orderedLessThanOrEqual
/// Ordered and not equal.
@available(*, deprecated, renamed: "orderedNotEqual")
public static let one = orderedNotEqual
/// Ordered (no nans).
@available(*, deprecated, renamed: "ordered")
public static let ord = ordered
/// Unordered (either nans).
@available(*, deprecated, renamed: "unordered")
public static let uno = unordered
/// Unordered or equal.
@available(*, deprecated, renamed: "unorderedEqual")
public static let ueq = unorderedEqual
/// Unordered or greater than.
@available(*, deprecated, renamed: "unorderedGreaterThan")
public static let ugt = unorderedGreaterThan
/// Unordered or greater than or equal.
@available(*, deprecated, renamed: "unorderedGreaterThanOrEqual")
public static let uge = unorderedGreaterThanOrEqual
/// Unordered or less than.
@available(*, deprecated, renamed: "unorderedLessThan")
public static let ult = unorderedLessThan
/// Unordered or less than or equal.
@available(*, deprecated, renamed: "unorderedLessThanOrEqual")
public static let ule = unorderedLessThanOrEqual
/// Unordered or not equal.
@available(*, deprecated, renamed: "unorderedNotEqual")
public static let une = unorderedNotEqual
}
42 changes: 21 additions & 21 deletions Tests/LLVMTests/IRBuilderSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,25 @@ class IRBuilderSpec : XCTestCase {
let vg2 = builder.buildLoad(g2)

// IRBUILDERCMP-NEXT: %2 = icmp eq i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .eq)
_ = builder.buildICmp(vg1, vg2, .equal)
// IRBUILDERCMP-NEXT: %3 = icmp ne i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .ne)
_ = builder.buildICmp(vg1, vg2, .notEqual)
// IRBUILDERCMP-NEXT: %4 = icmp ugt i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .ugt)
_ = builder.buildICmp(vg1, vg2, .unsignedGreaterThan)
// IRBUILDERCMP-NEXT: %5 = icmp uge i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .uge)
_ = builder.buildICmp(vg1, vg2, .unsignedGreaterThanOrEqual)
// IRBUILDERCMP-NEXT: %6 = icmp ult i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .ult)
_ = builder.buildICmp(vg1, vg2, .unsignedLessThan)
// IRBUILDERCMP-NEXT: %7 = icmp ule i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .ule)
_ = builder.buildICmp(vg1, vg2, .unsignedLessThanOrEqual)
// IRBUILDERCMP-NEXT: %8 = icmp sgt i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .sgt)
_ = builder.buildICmp(vg1, vg2, .signedGreaterThan)
// IRBUILDERCMP-NEXT: %9 = icmp sge i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .sge)
_ = builder.buildICmp(vg1, vg2, .signedGreaterThanOrEqual)
// IRBUILDERCMP-NEXT: %10 = icmp slt i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .slt)
_ = builder.buildICmp(vg1, vg2, .signedLessThan)
// IRBUILDERCMP-NEXT: %11 = icmp sle i32 %0, %1
_ = builder.buildICmp(vg1, vg2, .sle)
_ = builder.buildICmp(vg1, vg2, .signedLessThanOrEqual)

// IRBUILDERCMP-NEXT: ret void
builder.buildRetVoid()
Expand Down Expand Up @@ -171,25 +171,25 @@ class IRBuilderSpec : XCTestCase {
let vg2 = builder.buildLoad(g2)

// IRBUILDERFCMP-NEXT: %2 = fcmp oeq double %0, %1
_ = builder.buildFCmp(vg1, vg2, .oeq)
_ = builder.buildFCmp(vg1, vg2, .orderedEqual)
// IRBUILDERFCMP-NEXT: %3 = fcmp one double %0, %1
_ = builder.buildFCmp(vg1, vg2, .one)
_ = builder.buildFCmp(vg1, vg2, .orderedNotEqual)
// IRBUILDERFCMP-NEXT: %4 = fcmp ugt double %0, %1
_ = builder.buildFCmp(vg1, vg2, .ugt)
_ = builder.buildFCmp(vg1, vg2, .unorderedGreaterThan)
// IRBUILDERFCMP-NEXT: %5 = fcmp uge double %0, %1
_ = builder.buildFCmp(vg1, vg2, .uge)
_ = builder.buildFCmp(vg1, vg2, .unorderedGreaterThanOrEqual)
// IRBUILDERFCMP-NEXT: %6 = fcmp ult double %0, %1
_ = builder.buildFCmp(vg1, vg2, .ult)
_ = builder.buildFCmp(vg1, vg2, .unorderedLessThan)
// IRBUILDERFCMP-NEXT: %7 = fcmp ule double %0, %1
_ = builder.buildFCmp(vg1, vg2, .ule)
_ = builder.buildFCmp(vg1, vg2, .unorderedLessThanOrEqual)
// IRBUILDERFCMP-NEXT: %8 = fcmp ogt double %0, %1
_ = builder.buildFCmp(vg1, vg2, .ogt)
_ = builder.buildFCmp(vg1, vg2, .orderedGreaterThan)
// IRBUILDERFCMP-NEXT: %9 = fcmp oge double %0, %1
_ = builder.buildFCmp(vg1, vg2, .oge)
_ = builder.buildFCmp(vg1, vg2, .orderedGreaterThanOrEqual)
// IRBUILDERFCMP-NEXT: %10 = fcmp olt double %0, %1
_ = builder.buildFCmp(vg1, vg2, .olt)
_ = builder.buildFCmp(vg1, vg2, .orderedLessThan)
// IRBUILDERFCMP-NEXT: %11 = fcmp ole double %0, %1
_ = builder.buildFCmp(vg1, vg2, .ole)
_ = builder.buildFCmp(vg1, vg2, .orderedLessThanOrEqual)
// IRBUILDERFCMP-NEXT: %12 = fcmp true double %0, %1
_ = builder.buildFCmp(vg1, vg2, .true)
// IRBUILDERFCMP-NEXT: %13 = fcmp false double %0, %1
Expand Down Expand Up @@ -227,7 +227,7 @@ class IRBuilderSpec : XCTestCase {
let load = builder.buildLoad(variable)

// CONTROLFLOW-NEXT: %1 = icmp eq i64 %0, 0
let res = builder.buildICmp(load, IntType.int64.zero(), .eq)
let res = builder.buildICmp(load, IntType.int64.zero(), .equal)

let thenBB = main.appendBasicBlock(named: "then")
let elseBB = main.appendBasicBlock(named: "else")
Expand Down