1// RUN: llvm-tblgen %s | FileCheck %s 2 3// Support for an `!if' operator as part of a `let' statement. 4// CHECK: class C 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} }; 6class C<bits<3> x, bits<4> y, bit z> { 7 bits<16> n; 8 9 let n{11} = !if(y{3}, 1, 10 !if(y{2}, x{0}, 11 !if(y{1}, x{1}, 12 !if(y{0}, x{2}, ?)))); 13 let n{10-9}= !if(x{2}, y{3-2}, 14 !if(x{1}, y{2-1}, 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}}); 19} 20 21def C1 : C<{1, 0, 1}, {0, 1, 0, 1}, 0>; 22def C2 : C<{0, 1, 0}, {1, 0, 1, 0}, 1>; 23def C3 : C<{0, 0, 0}, {1, 0, 1, 0}, 0>; 24def C4 : C<{0, 0, 0}, {0, 0, 0, 0}, 0>; 25 26// CHECK: def C1 27// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 }; 28// CHECK: def C2 29// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 }; 30// CHECK: def C3 31// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, ?, ?, 1, 1, 0, 0, 1, 0, 0, 1, 0 }; 32// CHECK: def C4 33// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, ?, ?, ?, 1, 1, 0, 0, 1, 0, 0, 0, 0 }; 34 35class S<int s> { 36 bits<2> val = !if(!eq(s, 8), {0, 0}, 37 !if(!eq(s, 16), 0b01, 38 !if(!eq(s, 32), 2, 39 !if(!eq(s, 64), {1, 1}, ?)))); 40} 41 42def D8 : S<8>; 43def D16 : S<16>; 44def D32 : S<32>; 45def D64 : S<64>; 46def D128: S<128>; 47// CHECK: def D128 48// CHECK-NEXT: bits<2> val = { ?, ? }; 49// CHECK: def D16 50// CHECK-NEXT: bits<2> val = { 0, 1 }; 51// CHECK: def D32 52// CHECK-NEXT: bits<2> val = { 1, 0 }; 53// CHECK: def D64 54// CHECK-NEXT: bits<2> val = { 1, 1 }; 55// CHECK: def D8 56// CHECK-NEXT: bits<2> val = { 0, 0 }; 57 58// CHECK: def One 59// CHECK-NEXT: list<int> first = [1, 2, 3]; 60// CHECK-NEXT: list<int> rest = [1, 2, 3]; 61 62// CHECK: def OneB 63// CHECK-NEXT: list<int> vals = [1, 2, 3]; 64 65// CHECK: def Two 66// CHECK-NEXT: list<int> first = [1, 2, 3]; 67// CHECK-NEXT: list<int> rest = [4, 5, 6]; 68 69// CHECK: def TwoB 70// CHECK-NEXT: list<int> vals = [4, 5, 6]; 71 72class A<list<list<int>> vals> { 73 list<int> first = vals[0]; 74 list<int> rest = !if(!empty(!tail(vals)), vals[0], vals[1]); 75} 76 77def One : A<[[1,2,3]]>; 78def Two : A<[[1,2,3], [4,5,6]]>; 79 80class B<list<int> v> { 81 list<int> vals = v; 82} 83 84class BB<list<list<int>> vals> : B<!if(!empty(!tail(vals)), vals[0], vals[1])>; 85class BBB<list<list<int>> vals> : BB<vals>; 86 87def OneB : BBB<[[1,2,3]]>; 88def TwoB : BBB<[[1,2,3],[4,5,6]]>; 89