Skip to content

Commit f5c0e5f

Browse files
Added spelled-out aliases for abbreviated predicate cases. (#66)
* Added spelled-out aliases for abbreviated predicate cases. * Added deprecations with fixits for renaming to the expanded cases. * Updated tests to fix deprecation warnings. * Fixed documentation flub. * Fixed documentation flub.
1 parent 0b8bc56 commit f5c0e5f

File tree

4 files changed

+163
-69
lines changed

4 files changed

+163
-69
lines changed

Sources/LLVM/Constant.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ public struct Constant<Repr: ConstantRepresentation>: IRValue {
323323

324324
switch lhs.repr {
325325
case .signed:
326-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.eq.llvm, lhs.llvm, rhs.llvm))
326+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.equal.llvm, lhs.llvm, rhs.llvm))
327327
case .unsigned:
328-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.eq.llvm, lhs.llvm, rhs.llvm))
328+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.equal.llvm, lhs.llvm, rhs.llvm))
329329
case .floating:
330-
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.oeq.llvm, lhs.llvm, rhs.llvm))
330+
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedEqual.llvm, lhs.llvm, rhs.llvm))
331331
}
332332
}
333333

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

344344
switch lhs.repr {
345345
case .signed:
346-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.slt.llvm, lhs.llvm, rhs.llvm))
346+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedLessThan.llvm, lhs.llvm, rhs.llvm))
347347
case .unsigned:
348-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.ult.llvm, lhs.llvm, rhs.llvm))
348+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedLessThan.llvm, lhs.llvm, rhs.llvm))
349349
case .floating:
350-
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.olt.llvm, lhs.llvm, rhs.llvm))
350+
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedLessThan.llvm, lhs.llvm, rhs.llvm))
351351
}
352352
}
353353

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

364364
switch lhs.repr {
365365
case .signed:
366-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.sgt.llvm, lhs.llvm, rhs.llvm))
366+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedGreaterThan.llvm, lhs.llvm, rhs.llvm))
367367
case .unsigned:
368-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.ugt.llvm, lhs.llvm, rhs.llvm))
368+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedGreaterThan.llvm, lhs.llvm, rhs.llvm))
369369
case .floating:
370-
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.ogt.llvm, lhs.llvm, rhs.llvm))
370+
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedGreaterThan.llvm, lhs.llvm, rhs.llvm))
371371
}
372372
}
373373

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

384384
switch lhs.repr {
385385
case .signed:
386-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.sle.llvm, lhs.llvm, rhs.llvm))
386+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm))
387387
case .unsigned:
388-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.ule.llvm, lhs.llvm, rhs.llvm))
388+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm))
389389
case .floating:
390-
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.ole.llvm, lhs.llvm, rhs.llvm))
390+
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm))
391391
}
392392
}
393393

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

404404
switch lhs.repr {
405405
case .signed:
406-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.sge.llvm, lhs.llvm, rhs.llvm))
406+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.signedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm))
407407
case .unsigned:
408-
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.uge.llvm, lhs.llvm, rhs.llvm))
408+
return Constant<Signed>(llvm: LLVMConstICmp(IntPredicate.unsignedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm))
409409
case .floating:
410-
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.oge.llvm, lhs.llvm, rhs.llvm))
410+
return Constant<Signed>(llvm: LLVMConstFCmp(RealPredicate.orderedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm))
411411
}
412412
}
413413
}

Sources/LLVM/IRBuilder.swift

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,43 @@ public enum OverflowBehavior {
2020
public enum IntPredicate {
2121
/// Yields `true` if the operands are equal, false otherwise without sign
2222
/// interpretation.
23-
case eq
23+
case equal
2424
/// Yields `true` if the operands are unequal, false otherwise without sign
2525
/// interpretation.
26-
case ne
26+
case notEqual
2727

2828
/// Interprets the operands as unsigned values and yields true if the first is
2929
/// greater than the second.
30-
case ugt
30+
case unsignedGreaterThan
3131
/// Interprets the operands as unsigned values and yields true if the first is
3232
/// greater than or equal to the second.
33-
case uge
33+
case unsignedGreaterThanOrEqual
3434
/// Interprets the operands as unsigned values and yields true if the first is
3535
/// less than the second.
36-
case ult
36+
case unsignedLessThan
3737
/// Interprets the operands as unsigned values and yields true if the first is
3838
/// less than or equal to the second.
39-
case ule
39+
case unsignedLessThanOrEqual
4040

4141
/// Interprets the operands as signed values and yields true if the first is
4242
/// greater than the second.
43-
case sgt
43+
case signedGreaterThan
4444
/// Interprets the operands as signed values and yields true if the first is
4545
/// greater than or equal to the second.
46-
case sge
46+
case signedGreaterThanOrEqual
4747
/// Interprets the operands as signed values and yields true if the first is
4848
/// less than the second.
49-
case slt
49+
case signedLessThan
5050
/// Interprets the operands as signed values and yields true if the first is
5151
/// less than or equal to the second.
52-
case sle
52+
case signedLessThanOrEqual
5353

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

6062
/// Retrieves the corresponding `LLVMIntPredicate`.
@@ -68,42 +70,44 @@ public enum RealPredicate {
6870
/// No comparison, always returns `false`.
6971
case `false`
7072
/// Ordered and equal.
71-
case oeq
73+
case orderedEqual
7274
/// Ordered greater than.
73-
case ogt
75+
case orderedGreaterThan
7476
/// Ordered greater than or equal.
75-
case oge
77+
case orderedGreaterThanOrEqual
7678
/// Ordered less than.
77-
case olt
79+
case orderedLessThan
7880
/// Ordered less than or equal.
79-
case ole
81+
case orderedLessThanOrEqual
8082
/// Ordered and not equal.
81-
case one
82-
/// Oredered (no nans).
83-
case ord
83+
case orderedNotEqual
84+
/// Ordered (no nans).
85+
case ordered
8486
/// Unordered (either nans).
85-
case uno
87+
case unordered
8688
/// Unordered or equal.
87-
case ueq
89+
case unorderedEqual
8890
/// Unordered or greater than.
89-
case ugt
91+
case unorderedGreaterThan
9092
/// Unordered or greater than or equal.
91-
case uge
93+
case unorderedGreaterThanOrEqual
9294
/// Unordered or less than.
93-
case ult
95+
case unorderedLessThan
9496
/// Unordered or less than or equal.
95-
case ule
97+
case unorderedLessThanOrEqual
9698
/// Unordered or not equal.
97-
case une
99+
case unorderedNotEqual
98100
/// No comparison, always returns `true`.
99101
case `true`
100102

101103
static let predicateMapping: [RealPredicate: LLVMRealPredicate] = [
102-
.false: LLVMRealPredicateFalse, .oeq: LLVMRealOEQ, .ogt: LLVMRealOGT,
103-
.oge: LLVMRealOGE, .olt: LLVMRealOLT, .ole: LLVMRealOLE,
104-
.one: LLVMRealONE, .ord: LLVMRealORD, .uno: LLVMRealUNO,
105-
.ueq: LLVMRealUEQ, .ugt: LLVMRealUGT, .uge: LLVMRealUGE,
106-
.ult: LLVMRealULT, .ule: LLVMRealULE, .une: LLVMRealUNE,
104+
.false: LLVMRealPredicateFalse, .orderedEqual: LLVMRealOEQ,
105+
.orderedGreaterThan: LLVMRealOGT, .orderedGreaterThanOrEqual: LLVMRealOGE,
106+
.orderedLessThan: LLVMRealOLT, .orderedLessThanOrEqual: LLVMRealOLE,
107+
.orderedNotEqual: LLVMRealONE, .ordered: LLVMRealORD, .unordered: LLVMRealUNO,
108+
.unorderedEqual: LLVMRealUEQ, .unorderedGreaterThan: LLVMRealUGT,
109+
.unorderedGreaterThanOrEqual: LLVMRealUGE, .unorderedLessThan: LLVMRealULT,
110+
.unorderedLessThanOrEqual: LLVMRealULE, .unorderedNotEqual: LLVMRealUNE,
107111
.true: LLVMRealPredicateTrue,
108112
]
109113

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
extension IntPredicate {
2+
/// Yields `true` if the operands are equal, false otherwise without sign
3+
/// interpretation.
4+
@available(*, deprecated, renamed: "equal")
5+
public static let eq = equal
6+
/// Yields `true` if the operands are unequal, false otherwise without sign
7+
/// interpretation.
8+
@available(*, deprecated, renamed: "notEqual")
9+
public static let ne = notEqual
10+
11+
/// Interprets the operands as unsigned values and yields true if the first is
12+
/// greater than the second.
13+
@available(*, deprecated, renamed: "unsignedGreaterThan")
14+
public static let ugt = unsignedGreaterThan
15+
/// Interprets the operands as unsigned values and yields true if the first is
16+
/// greater than or equal to the second.
17+
18+
@available(*, deprecated, renamed: "unsignedGreaterThanOrEqual")
19+
public static let uge = unsignedGreaterThanOrEqual
20+
/// Interprets the operands as unsigned values and yields true if the first is
21+
/// less than the second.
22+
@available(*, deprecated, renamed: "unsignedLessThan")
23+
public static let ult = unsignedLessThan
24+
/// Interprets the operands as unsigned values and yields true if the first is
25+
/// less than or equal to the second.
26+
@available(*, deprecated, renamed: "unsignedLessThanOrEqual")
27+
public static let ule = unsignedLessThanOrEqual
28+
29+
/// Interprets the operands as signed values and yields true if the first is
30+
/// greater than the second.
31+
@available(*, deprecated, renamed: "signedGreaterThan")
32+
public static let sgt = signedGreaterThan
33+
/// Interprets the operands as signed values and yields true if the first is
34+
/// greater than or equal to the second.
35+
@available(*, deprecated, renamed: "signedGreaterThanOrEqual")
36+
public static let sge = signedGreaterThanOrEqual
37+
/// Interprets the operands as signed values and yields true if the first is
38+
/// less than the second.
39+
@available(*, deprecated, renamed: "signedLessThan")
40+
public static let slt = signedLessThan
41+
/// Interprets the operands as signed values and yields true if the first is
42+
/// less than or equal to the second.
43+
@available(*, deprecated, renamed: "signedLessThanOrEqual")
44+
public static let sle = signedLessThanOrEqual
45+
}
46+
47+
extension RealPredicate {
48+
/// Ordered and equal.
49+
@available(*, deprecated, renamed: "orderedEqual")
50+
public static let oeq = orderedEqual
51+
/// Ordered greater than.
52+
@available(*, deprecated, renamed: "orderedGreaterThan")
53+
public static let ogt = orderedGreaterThan
54+
/// Ordered greater than or equal.
55+
@available(*, deprecated, renamed: "orderedGreaterThanOrEqual")
56+
public static let oge = orderedGreaterThanOrEqual
57+
/// Ordered less than.
58+
@available(*, deprecated, renamed: "orderedLessThan")
59+
public static let olt = orderedLessThan
60+
/// Ordered less than or equal.
61+
@available(*, deprecated, renamed: "orderedLessThanOrEqual")
62+
public static let ole = orderedLessThanOrEqual
63+
/// Ordered and not equal.
64+
@available(*, deprecated, renamed: "orderedNotEqual")
65+
public static let one = orderedNotEqual
66+
/// Ordered (no nans).
67+
@available(*, deprecated, renamed: "ordered")
68+
public static let ord = ordered
69+
/// Unordered (either nans).
70+
@available(*, deprecated, renamed: "unordered")
71+
public static let uno = unordered
72+
/// Unordered or equal.
73+
@available(*, deprecated, renamed: "unorderedEqual")
74+
public static let ueq = unorderedEqual
75+
/// Unordered or greater than.
76+
@available(*, deprecated, renamed: "unorderedGreaterThan")
77+
public static let ugt = unorderedGreaterThan
78+
/// Unordered or greater than or equal.
79+
@available(*, deprecated, renamed: "unorderedGreaterThanOrEqual")
80+
public static let uge = unorderedGreaterThanOrEqual
81+
/// Unordered or less than.
82+
@available(*, deprecated, renamed: "unorderedLessThan")
83+
public static let ult = unorderedLessThan
84+
/// Unordered or less than or equal.
85+
@available(*, deprecated, renamed: "unorderedLessThanOrEqual")
86+
public static let ule = unorderedLessThanOrEqual
87+
/// Unordered or not equal.
88+
@available(*, deprecated, renamed: "unorderedNotEqual")
89+
public static let une = unorderedNotEqual
90+
}

Tests/LLVMTests/IRBuilderSpec.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,25 @@ class IRBuilderSpec : XCTestCase {
117117
let vg2 = builder.buildLoad(g2)
118118

119119
// IRBUILDERCMP-NEXT: %2 = icmp eq i32 %0, %1
120-
_ = builder.buildICmp(vg1, vg2, .eq)
120+
_ = builder.buildICmp(vg1, vg2, .equal)
121121
// IRBUILDERCMP-NEXT: %3 = icmp ne i32 %0, %1
122-
_ = builder.buildICmp(vg1, vg2, .ne)
122+
_ = builder.buildICmp(vg1, vg2, .notEqual)
123123
// IRBUILDERCMP-NEXT: %4 = icmp ugt i32 %0, %1
124-
_ = builder.buildICmp(vg1, vg2, .ugt)
124+
_ = builder.buildICmp(vg1, vg2, .unsignedGreaterThan)
125125
// IRBUILDERCMP-NEXT: %5 = icmp uge i32 %0, %1
126-
_ = builder.buildICmp(vg1, vg2, .uge)
126+
_ = builder.buildICmp(vg1, vg2, .unsignedGreaterThanOrEqual)
127127
// IRBUILDERCMP-NEXT: %6 = icmp ult i32 %0, %1
128-
_ = builder.buildICmp(vg1, vg2, .ult)
128+
_ = builder.buildICmp(vg1, vg2, .unsignedLessThan)
129129
// IRBUILDERCMP-NEXT: %7 = icmp ule i32 %0, %1
130-
_ = builder.buildICmp(vg1, vg2, .ule)
130+
_ = builder.buildICmp(vg1, vg2, .unsignedLessThanOrEqual)
131131
// IRBUILDERCMP-NEXT: %8 = icmp sgt i32 %0, %1
132-
_ = builder.buildICmp(vg1, vg2, .sgt)
132+
_ = builder.buildICmp(vg1, vg2, .signedGreaterThan)
133133
// IRBUILDERCMP-NEXT: %9 = icmp sge i32 %0, %1
134-
_ = builder.buildICmp(vg1, vg2, .sge)
134+
_ = builder.buildICmp(vg1, vg2, .signedGreaterThanOrEqual)
135135
// IRBUILDERCMP-NEXT: %10 = icmp slt i32 %0, %1
136-
_ = builder.buildICmp(vg1, vg2, .slt)
136+
_ = builder.buildICmp(vg1, vg2, .signedLessThan)
137137
// IRBUILDERCMP-NEXT: %11 = icmp sle i32 %0, %1
138-
_ = builder.buildICmp(vg1, vg2, .sle)
138+
_ = builder.buildICmp(vg1, vg2, .signedLessThanOrEqual)
139139

140140
// IRBUILDERCMP-NEXT: ret void
141141
builder.buildRetVoid()
@@ -171,25 +171,25 @@ class IRBuilderSpec : XCTestCase {
171171
let vg2 = builder.buildLoad(g2)
172172

173173
// IRBUILDERFCMP-NEXT: %2 = fcmp oeq double %0, %1
174-
_ = builder.buildFCmp(vg1, vg2, .oeq)
174+
_ = builder.buildFCmp(vg1, vg2, .orderedEqual)
175175
// IRBUILDERFCMP-NEXT: %3 = fcmp one double %0, %1
176-
_ = builder.buildFCmp(vg1, vg2, .one)
176+
_ = builder.buildFCmp(vg1, vg2, .orderedNotEqual)
177177
// IRBUILDERFCMP-NEXT: %4 = fcmp ugt double %0, %1
178-
_ = builder.buildFCmp(vg1, vg2, .ugt)
178+
_ = builder.buildFCmp(vg1, vg2, .unorderedGreaterThan)
179179
// IRBUILDERFCMP-NEXT: %5 = fcmp uge double %0, %1
180-
_ = builder.buildFCmp(vg1, vg2, .uge)
180+
_ = builder.buildFCmp(vg1, vg2, .unorderedGreaterThanOrEqual)
181181
// IRBUILDERFCMP-NEXT: %6 = fcmp ult double %0, %1
182-
_ = builder.buildFCmp(vg1, vg2, .ult)
182+
_ = builder.buildFCmp(vg1, vg2, .unorderedLessThan)
183183
// IRBUILDERFCMP-NEXT: %7 = fcmp ule double %0, %1
184-
_ = builder.buildFCmp(vg1, vg2, .ule)
184+
_ = builder.buildFCmp(vg1, vg2, .unorderedLessThanOrEqual)
185185
// IRBUILDERFCMP-NEXT: %8 = fcmp ogt double %0, %1
186-
_ = builder.buildFCmp(vg1, vg2, .ogt)
186+
_ = builder.buildFCmp(vg1, vg2, .orderedGreaterThan)
187187
// IRBUILDERFCMP-NEXT: %9 = fcmp oge double %0, %1
188-
_ = builder.buildFCmp(vg1, vg2, .oge)
188+
_ = builder.buildFCmp(vg1, vg2, .orderedGreaterThanOrEqual)
189189
// IRBUILDERFCMP-NEXT: %10 = fcmp olt double %0, %1
190-
_ = builder.buildFCmp(vg1, vg2, .olt)
190+
_ = builder.buildFCmp(vg1, vg2, .orderedLessThan)
191191
// IRBUILDERFCMP-NEXT: %11 = fcmp ole double %0, %1
192-
_ = builder.buildFCmp(vg1, vg2, .ole)
192+
_ = builder.buildFCmp(vg1, vg2, .orderedLessThanOrEqual)
193193
// IRBUILDERFCMP-NEXT: %12 = fcmp true double %0, %1
194194
_ = builder.buildFCmp(vg1, vg2, .true)
195195
// IRBUILDERFCMP-NEXT: %13 = fcmp false double %0, %1
@@ -227,7 +227,7 @@ class IRBuilderSpec : XCTestCase {
227227
let load = builder.buildLoad(variable)
228228

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

232232
let thenBB = main.appendBasicBlock(named: "then")
233233
let elseBB = main.appendBasicBlock(named: "else")

0 commit comments

Comments
 (0)