1// RUN: llvm-tblgen %s | FileCheck %s
2// XFAIL: vg_leak
3
4// Support for an `!if' operator as part of a `let' statement.
5// CHECK:      class C
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} };
7class C<bits<3> x, bits<4> y, bit z> {
8  bits<16> n;
9
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}, ?)));
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
22def C1 : C<{1, 0, 1}, {0, 1, 0, 1}, 0>;
23def C2 : C<{0, 1, 0}, {1, 0, 1, 0}, 1>;
24def C3 : C<{0, 0, 0}, {1, 0, 1, 0}, 0>;
25def 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
36class 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
43def D8  : S<8>;
44def D16 : S<16>;
45def D32 : S<32>;
46def D64 : S<64>;
47def 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
59// CHECK:      def One
60// CHECK-NEXT: list<int> first = [1, 2, 3];
61// CHECK-NEXT: list<int> rest = [1, 2, 3];
62
63// CHECK:      def OneB
64// CHECK-NEXT: list<int> vals = [1, 2, 3];
65
66// CHECK:      def Two
67// CHECK-NEXT: list<int> first = [1, 2, 3];
68// CHECK-NEXT: list<int> rest = [4, 5, 6];
69
70// CHECK:      def TwoB
71// CHECK-NEXT: list<int> vals = [4, 5, 6];
72
73class A<list<list<int>> vals> {
74  list<int> first = vals[0];
75  list<int> rest  = !if(!empty(!tail(vals)), vals[0], vals[1]);
76}
77
78def One : A<[[1,2,3]]>;
79def Two : A<[[1,2,3], [4,5,6]]>;
80
81class B<list<int> v> {
82  list<int> vals = v;
83}
84
85class BB<list<list<int>> vals> : B<!if(!empty(!tail(vals)), vals[0], vals[1])>;
86class BBB<list<list<int>> vals> : BB<vals>;
87
88def OneB : BBB<[[1,2,3]]>;
89def TwoB : BBB<[[1,2,3],[4,5,6]]>;
90