1 // RUN: llvm-tblgen %s | FileCheck %s
3 // Support for an `!if' operator as part of a `let' statement.
5 // 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} }, 2, 6){2}, !if({ C:x{2} }, 2, 6){1}, !if({ C:x{2} }, 2, 6){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} };
6 class C<bits<3> x, bits<4> y, bit z> {
9 let n{11} = !if(y{3}, 1,
12 !if(y{0}, x{2}, ?))));
13 let n{10-9}= !if(x{2}, y{3-2},
15 !if(x{0}, y{1-0}, ?)));
16 let n{8-6} = !if(x{2}, 0b010, 0b110);
17 let n{5-4} = !if(x{1}, y{3-2}, {0, 1});
18 let n{3-0} = !if(x{0}, y{3-0}, {z, y{2}, y{1}, y{0}});
21 def C1 : C<{1, 0, 1}, {0, 1, 0, 1}, 0>;
22 def C2 : C<{0, 1, 0}, {1, 0, 1, 0}, 1>;
23 def C3 : C<{0, 0, 0}, {1, 0, 1, 0}, 0>;
24 def C4 : C<{0, 0, 0}, {0, 0, 0, 0}, 0>;
27 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 };
29 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 };
31 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, ?, ?, 1, 1, 0, 0, 1, 0, 0, 1, 0 };
33 // CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, ?, ?, ?, 1, 1, 0, 0, 1, 0, 0, 0, 0 };
36 bits<2> val = !if(!eq(s, 8), {0, 0},
39 !if(!eq(s, 64), {1, 1}, ?))));
48 // CHECK-NEXT: bits<2> val = { ?, ? };
50 // CHECK-NEXT: bits<2> val = { 0, 1 };
52 // CHECK-NEXT: bits<2> val = { 1, 0 };
54 // CHECK-NEXT: bits<2> val = { 1, 1 };
56 // CHECK-NEXT: bits<2> val = { 0, 0 };
59 // CHECK-NEXT: list<int> first = [1, 2, 3];
60 // CHECK-NEXT: list<int> rest = [1, 2, 3];
63 // CHECK-NEXT: list<int> vals = [1, 2, 3];
66 // CHECK-NEXT: list<int> first = [1, 2, 3];
67 // CHECK-NEXT: list<int> rest = [4, 5, 6];
70 // CHECK-NEXT: list<int> vals = [4, 5, 6];
72 class A<list<list<int>> vals> {
73 list<int> first = vals[0];
74 list<int> rest = !if(!empty(!tail(vals)), vals[0], vals[1]);
77 def One : A<[[1,2,3]]>;
78 def Two : A<[[1,2,3], [4,5,6]]>;
80 class B<list<int> v> {
84 class BB<list<list<int>> vals> : B<!if(!empty(!tail(vals)), vals[0], vals[1])>;
85 class BBB<list<list<int>> vals> : BB<vals>;
87 def OneB : BBB<[[1,2,3]]>;
88 def TwoB : BBB<[[1,2,3],[4,5,6]]>;