1 // RUN: llvm-tblgen %s | FileCheck %s
4 // Support for an `!if' operator as part of a `let' statement.
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} };
7 class C<bits<3> x, bits<4> y, bit z> {
10 let n{11} = !if(y{3}, 1,
13 !if(y{0}, x{2}, ?))));
14 let n{10-9}= !if(x{2}, y{3-2},
16 !if(x{0}, y{1-0}, ?)));
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}});
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>;
28 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 };
30 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 };
32 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, ?, ?, 1, 1, 0, 0, 1, 0, 0, 1, 0 };
34 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, ?, ?, ?, 1, 1, 0, 0, 1, 0, 0, 0, 0 };
37 bits<2> val = !if(!eq(s, 8), {0, 0},
40 !if(!eq(s, 64), {1, 1}, ?))));
49 // CHECK-NEXT: bits<2> val = { ?, ? };
51 // CHECK-NEXT: bits<2> val = { 0, 1 };
53 // CHECK-NEXT: bits<2> val = { 1, 0 };
55 // CHECK-NEXT: bits<2> val = { 1, 1 };
57 // CHECK-NEXT: bits<2> val = { 0, 0 };
59 // Make sure !if gets propagated across multiple layers of inheritance.
61 int ret = !if(c, 0, 1);
64 int i = getInt<c>.ret;
66 class I2<int c> : I1<c>;
68 // CHECK: def DI1 { // I1
69 // CHECK-NEXT: int i = 0;
72 // CHECK: def DI2 { // I1 I2
73 // CHECK-NEXT: int i = 0;
76 // Check that !if with operands of different subtypes can initialize a
77 // supertype variable.
87 class E1<int dummy> : E<dummy> {}
88 class E2<int dummy> : E<dummy> {}
90 class EX<int cc, E1 b, E2 c> {
97 def EXd1 : EX<1, E1d, E2d>;
98 def EXd2 : EX<0, E1d, E2d>;
101 // CHECK-NEXT: list<int> first = [1, 2, 3];
102 // CHECK-NEXT: list<int> rest = [1, 2, 3];
105 // CHECK-NEXT: list<int> vals = [1, 2, 3];
108 // CHECK-NEXT: list<int> first = [1, 2, 3];
109 // CHECK-NEXT: list<int> rest = [4, 5, 6];
112 // CHECK-NEXT: list<int> vals = [4, 5, 6];
114 class A<list<list<int>> vals> {
115 list<int> first = vals[0];
116 list<int> rest = !if(!empty(!tail(vals)), vals[0], vals[1]);
119 def One : A<[[1,2,3]]>;
120 def Two : A<[[1,2,3], [4,5,6]]>;
122 class B<list<int> v> {
126 class BB<list<list<int>> vals> : B<!if(!empty(!tail(vals)), vals[0], vals[1])>;
127 class BBB<list<list<int>> vals> : BB<vals>;
129 def OneB : BBB<[[1,2,3]]>;
130 def TwoB : BBB<[[1,2,3],[4,5,6]]>;