Peter Collingbourne | 5d5c062 | 2011-10-06 13:39:59 +0000 | [diff] [blame] | 1 | // RUN: llvm-tblgen %s | FileCheck %s |
NAKAMURA Takumi | a22657f | 2013-11-10 14:26:08 +0000 | [diff] [blame] | 2 | // XFAIL: vg_leak |
David Greene | 9bea7c8 | 2009-05-14 23:26:46 +0000 | [diff] [blame] | 3 | |
Bill Wendling | 548f5a0b | 2010-12-13 01:46:19 +0000 | [diff] [blame] | 4 | // Support for an `!if' operator as part of a `let' statement. |
| 5 | // CHECK: class C |
Pete Cooper | 2093e2c | 2014-08-07 05:47:04 +0000 | [diff] [blame] | 6 | // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, !if({ C:y{3} }, 1, !if({ C:y{2} }, { C:x{0} }, !if({ C:y{1} }, { C:x{1} }, !if({ C:y{0} }, { C:x{2} }, ?)))){0}, !if({ C:x{2} }, { C:y{3}, C:y{2} }, !if({ C:x{1} }, { C:y{2}, C:y{1} }, !if({ C:x{0} }, { C:y{1}, C:y{0} }, ?))){1}, !if({ C:x{2} }, { C:y{3}, C:y{2} }, !if({ C:x{1} }, { C:y{2}, C:y{1} }, !if({ C:x{0} }, { C:y{1}, C:y{0} }, ?))){0}, !if({ C:x{2} }, { 0, 1, 0 }, { 1, 1, 0 }){2}, !if({ C:x{2} }, { 0, 1, 0 }, { 1, 1, 0 }){1}, !if({ C:x{2} }, { 0, 1, 0 }, { 1, 1, 0 }){0}, !if({ C:x{1} }, { C:y{3}, C:y{2} }, { 0, 1 }){1}, !if({ C:x{1} }, { C:y{3}, C:y{2} }, { 0, 1 }){0}, !if({ C:x{0} }, { C:y{3}, C:y{2}, C:y{1}, C:y{0} }, { C:z, C:y{2}, C:y{1}, C:y{0} }){3}, !if({ C:x{0} }, { C:y{3}, C:y{2}, C:y{1}, C:y{0} }, { C:z, C:y{2}, C:y{1}, C:y{0} }){2}, !if({ C:x{0} }, { C:y{3}, C:y{2}, C:y{1}, C:y{0} }, { C:z, C:y{2}, C:y{1}, C:y{0} }){1}, !if({ C:x{0} }, { C:y{3}, C:y{2}, C:y{1}, C:y{0} }, { C:z, C:y{2}, C:y{1}, C:y{0} }){0} }; |
Bill Wendling | 548f5a0b | 2010-12-13 01:46:19 +0000 | [diff] [blame] | 7 | class C<bits<3> x, bits<4> y, bit z> { |
| 8 | bits<16> n; |
| 9 | |
Michael Liao | 307525c | 2012-09-06 23:32:48 +0000 | [diff] [blame] | 10 | let n{11} = !if(y{3}, 1, |
| 11 | !if(y{2}, x{0}, |
| 12 | !if(y{1}, x{1}, |
| 13 | !if(y{0}, x{2}, ?)))); |
| 14 | let n{10-9}= !if(x{2}, y{3-2}, |
| 15 | !if(x{1}, y{2-1}, |
| 16 | !if(x{0}, y{1-0}, ?))); |
Bill Wendling | 548f5a0b | 2010-12-13 01:46:19 +0000 | [diff] [blame] | 17 | let n{8-6} = !if(x{2}, 0b010, 0b110); |
| 18 | let n{5-4} = !if(x{1}, y{3-2}, {0, 1}); |
| 19 | let n{3-0} = !if(x{0}, y{3-0}, {z, y{2}, y{1}, y{0}}); |
| 20 | } |
| 21 | |
Michael Liao | 307525c | 2012-09-06 23:32:48 +0000 | [diff] [blame] | 22 | def C1 : C<{1, 0, 1}, {0, 1, 0, 1}, 0>; |
| 23 | def C2 : C<{0, 1, 0}, {1, 0, 1, 0}, 1>; |
| 24 | def C3 : C<{0, 0, 0}, {1, 0, 1, 0}, 0>; |
| 25 | def C4 : C<{0, 0, 0}, {0, 0, 0, 0}, 0>; |
| 26 | |
| 27 | // CHECK: def C1 |
| 28 | // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 }; |
| 29 | // CHECK: def C2 |
| 30 | // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 }; |
| 31 | // CHECK: def C3 |
| 32 | // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, ?, ?, 1, 1, 0, 0, 1, 0, 0, 1, 0 }; |
| 33 | // CHECK: def C4 |
| 34 | // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, ?, ?, ?, 1, 1, 0, 0, 1, 0, 0, 0, 0 }; |
| 35 | |
| 36 | class S<int s> { |
| 37 | bits<2> val = !if(!eq(s, 8), {0, 0}, |
| 38 | !if(!eq(s, 16), 0b01, |
| 39 | !if(!eq(s, 32), 2, |
| 40 | !if(!eq(s, 64), {1, 1}, ?)))); |
| 41 | } |
| 42 | |
| 43 | def D8 : S<8>; |
| 44 | def D16 : S<16>; |
| 45 | def D32 : S<32>; |
| 46 | def D64 : S<64>; |
| 47 | def D128: S<128>; |
| 48 | // CHECK: def D128 |
| 49 | // CHECK-NEXT: bits<2> val = { ?, ? }; |
| 50 | // CHECK: def D16 |
| 51 | // CHECK-NEXT: bits<2> val = { 0, 1 }; |
| 52 | // CHECK: def D32 |
| 53 | // CHECK-NEXT: bits<2> val = { 1, 0 }; |
| 54 | // CHECK: def D64 |
| 55 | // CHECK-NEXT: bits<2> val = { 1, 1 }; |
| 56 | // CHECK: def D8 |
| 57 | // CHECK-NEXT: bits<2> val = { 0, 0 }; |
| 58 | |
Artem Belevich | 34517fa | 2018-01-30 19:29:21 +0000 | [diff] [blame] | 59 | // Make sure !if gets propagated across multiple layers of inheritance. |
| 60 | class getInt<int c> { |
| 61 | int ret = !if(c, 0, 1); |
| 62 | } |
| 63 | class I1<int c> { |
| 64 | int i = getInt<c>.ret; |
| 65 | } |
| 66 | class I2<int c> : I1<c>; |
| 67 | |
| 68 | // CHECK: def DI1 { // I1 |
| 69 | // CHECK-NEXT: int i = 0; |
| 70 | def DI1: I1<1>; |
| 71 | |
Nicolai Haehnle | aba588d | 2018-02-23 11:31:49 +0000 | [diff] [blame] | 72 | // CHECK: def DI2 { // I1 I2 |
Artem Belevich | 34517fa | 2018-01-30 19:29:21 +0000 | [diff] [blame] | 73 | // CHECK-NEXT: int i = 0; |
| 74 | def DI2: I2<1>; |
| 75 | |
Nicolai Haehnle | c1dad06 | 2018-03-06 13:48:20 +0000 | [diff] [blame] | 76 | // Check that !if with operands of different subtypes can initialize a |
| 77 | // supertype variable. |
| 78 | // |
| 79 | // CHECK: def EXd1 { |
| 80 | // CHECK: E x = E1d; |
| 81 | // CHECK: } |
| 82 | // |
| 83 | // CHECK: def EXd2 { |
| 84 | // CHECK: E x = E2d; |
| 85 | // CHECK: } |
| 86 | class E<int dummy> {} |
| 87 | class E1<int dummy> : E<dummy> {} |
| 88 | class E2<int dummy> : E<dummy> {} |
| 89 | |
| 90 | class EX<int cc, E1 b, E2 c> { |
| 91 | E x = !if(cc, b, c); |
| 92 | } |
| 93 | |
| 94 | def E1d : E1<0>; |
| 95 | def E2d : E2<0>; |
| 96 | |
| 97 | def EXd1 : EX<1, E1d, E2d>; |
| 98 | def EXd2 : EX<0, E1d, E2d>; |
| 99 | |
Bill Wendling | 548f5a0b | 2010-12-13 01:46:19 +0000 | [diff] [blame] | 100 | // CHECK: def One |
| 101 | // CHECK-NEXT: list<int> first = [1, 2, 3]; |
| 102 | // CHECK-NEXT: list<int> rest = [1, 2, 3]; |
| 103 | |
| 104 | // CHECK: def OneB |
| 105 | // CHECK-NEXT: list<int> vals = [1, 2, 3]; |
| 106 | |
| 107 | // CHECK: def Two |
| 108 | // CHECK-NEXT: list<int> first = [1, 2, 3]; |
| 109 | // CHECK-NEXT: list<int> rest = [4, 5, 6]; |
| 110 | |
| 111 | // CHECK: def TwoB |
| 112 | // CHECK-NEXT: list<int> vals = [4, 5, 6]; |
| 113 | |
David Greene | 9bea7c8 | 2009-05-14 23:26:46 +0000 | [diff] [blame] | 114 | class A<list<list<int>> vals> { |
| 115 | list<int> first = vals[0]; |
David Greene | 1434f66 | 2011-01-07 17:05:37 +0000 | [diff] [blame] | 116 | list<int> rest = !if(!empty(!tail(vals)), vals[0], vals[1]); |
David Greene | 9bea7c8 | 2009-05-14 23:26:46 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | def One : A<[[1,2,3]]>; |
Bill Wendling | 548f5a0b | 2010-12-13 01:46:19 +0000 | [diff] [blame] | 120 | def Two : A<[[1,2,3], [4,5,6]]>; |
David Greene | 9bea7c8 | 2009-05-14 23:26:46 +0000 | [diff] [blame] | 121 | |
| 122 | class B<list<int> v> { |
| 123 | list<int> vals = v; |
| 124 | } |
| 125 | |
David Greene | 1434f66 | 2011-01-07 17:05:37 +0000 | [diff] [blame] | 126 | class BB<list<list<int>> vals> : B<!if(!empty(!tail(vals)), vals[0], vals[1])>; |
David Greene | 9bea7c8 | 2009-05-14 23:26:46 +0000 | [diff] [blame] | 127 | class BBB<list<list<int>> vals> : BB<vals>; |
| 128 | |
| 129 | def OneB : BBB<[[1,2,3]]>; |
| 130 | def TwoB : BBB<[[1,2,3],[4,5,6]]>; |