brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · cd8a8e7 Raw
164 lines · plain
1// RUN: llvm-tblgen --no-warn-on-unused-template-args %s | FileCheck %s2// XFAIL: vg_leak3 4// Support for an `!if' operator as part of a `let' statement.5// CHECK:      class C6// 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 C128// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 };29// CHECK: def C230// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 };31// CHECK: def C332// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, ?, ?, 1, 1, 0, 0, 1, 0, 0, 1, 0 };33// CHECK: def C434// 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 D12849// CHECK-NEXT: bits<2> val = { ?, ? };50// CHECK: def D1651// CHECK-NEXT: bits<2> val = { 0, 1 };52// CHECK: def D3253// CHECK-NEXT: bits<2> val = { 1, 0 };54// CHECK: def D6455// CHECK-NEXT: bits<2> val = { 1, 1 };56// CHECK: def D857// CHECK-NEXT: bits<2> val = { 0, 0 };58 59// Make sure !if gets propagated across multiple layers of inheritance.60class getInt<int c> {61  int ret = !if(c, 0, 1);62}63class I1<int c> {64  int i = getInt<c>.ret;65}66class I2<int c> : I1<c>;67 68// CHECK: def DI1 {     // I169// CHECK-NEXT: int i = 0;70def DI1: I1<1>;71 72// CHECK: def DI2 {     // I1 I273// CHECK-NEXT: int i = 0;74def DI2: I2<1>;75 76// Check that !if with operands of different subtypes can initialize a77// 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: }86class E<int dummy> {}87class E1<int dummy> : E<dummy> {}88class E2<int dummy> : E<dummy> {}89 90class EX<int cc, E1 b, E2 c> {91  E x = !if(cc, b, c);92}93 94def E1d : E1<0>;95def E2d : E2<0>;96 97def EXd1 : EX<1, E1d, E2d>;98def EXd2 : EX<0, E1d, E2d>;99 100// CHECK: def Not1101// CHECK: Result1a = "OK"102// CHECK: Result1b = "OK"103// CHECK: Result1c = "OK"104// CHECK: Result1d = "OK"105// CHECK: Result1e = "OK"106// CHECK: def Not2107// CHECK: Result2a = "OK"108// CHECK: Result2b = "OK"109// CHECK: Result2c = "OK"110// CHECK: Result2d = "OK"111 112def Not1 {113  bit True = 1;114  string Result1a = !if(True, "OK", "not OK");115  string Result1b = !if(!not(True), "not OK", "OK");116 117  bit False = 0;118  string Result1c = !if(False, "not OK", "OK");119  string Result1d = !if(!not(False), "OK", "not OK");120  string Result1e = !if(!not(!not(False)), "not OK", "OK");121}122 123def Not2 {124  int one = 1;125  string Result2a = !if(one, "OK", "not OK");126  string Result2b = !if(!not(one), "not OK", "OK");127 128  int zero = 0;129  string Result2c = !if(zero, "not OK", "OK");130  string Result2d = !if(!not(zero), "OK", "not OK");131}132 133// CHECK:      def One134// CHECK-NEXT: list<int> first = [1, 2, 3];135// CHECK-NEXT: list<int> rest = [1, 2, 3];136 137// CHECK:      def OneB138// CHECK-NEXT: list<int> vals = [1, 2, 3];139 140// CHECK:      def Two141// CHECK-NEXT: list<int> first = [1, 2, 3];142// CHECK-NEXT: list<int> rest = [4, 5, 6];143 144// CHECK:      def TwoB145// CHECK-NEXT: list<int> vals = [4, 5, 6];146 147class A<list<list<int>> vals> {148  list<int> first = vals[0];149  list<int> rest  = !if(!empty(!tail(vals)), vals[0], vals[1]);150}151 152def One : A<[[1,2,3]]>;153def Two : A<[[1,2,3], [4,5,6]]>;154 155class B<list<int> v> {156  list<int> vals = v;157}158 159class BB<list<list<int>> vals> : B<!if(!empty(!tail(vals)), vals[0], vals[1])>;160class BBB<list<list<int>> vals> : BB<vals>;161 162def OneB : BBB<[[1,2,3]]>;163def TwoB : BBB<[[1,2,3],[4,5,6]]>;164