2011-10-06 15:39:59 +02:00
|
|
|
// RUN: llvm-tblgen %s | FileCheck %s
|
2013-11-10 15:26:08 +01:00
|
|
|
// XFAIL: vg_leak
|
2009-05-15 01:26:46 +02:00
|
|
|
|
2010-12-13 02:46:19 +01:00
|
|
|
// Support for an `!if' operator as part of a `let' statement.
|
|
|
|
// CHECK: class C
|
2014-08-07 07:47:04 +02:00
|
|
|
// 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} };
|
2010-12-13 02:46:19 +01:00
|
|
|
class C<bits<3> x, bits<4> y, bit z> {
|
|
|
|
bits<16> n;
|
|
|
|
|
Re-work bit/bits value resolving in tblgen
- This patch is inspired by the failure of the following code snippet
which is used to convert enumerable values into encoding bits to
improve the readability of td files.
class S<int s> {
bits<2> V = !if(!eq(s, 8), {0, 0},
!if(!eq(s, 16), {0, 1},
!if(!eq(s, 32), {1, 0},
!if(!eq(s, 64), {1, 1}, {?, ?}))));
}
Later, PR8330 is found to report not exactly the same bug relevant
issue to bit/bits values.
- Instead of resolving bit/bits values separately through
resolveBitReference(), this patch adds getBit() for all Inits and
resolves bit value by resolving plus getting the specified bit. This
unifies the resolving of bit with other values and removes redundant
logic for resolving bit only. In addition,
BitsInit::resolveReferences() is optimized to take advantage of this
origanization by resolving VarBitInit's variable reference first and
then getting bits from it.
- The type interference in '!if' operator is revised to support possible
combinations of int and bits/bit in MHS and RHS.
- As there may be illegal assignments from integer value to bit, says
assign 2 to a bit, but we only check this during instantiation in some
cases, e.g.
bit V = !if(!eq(x, 17), 0, 2);
Verbose diagnostic message is generated when invalid value is
resolveed to help locating the error.
- PR8330 is fixed as well.
llvm-svn: 163360
2012-09-07 01:32:48 +02:00
|
|
|
let n{11} = !if(y{3}, 1,
|
|
|
|
!if(y{2}, x{0},
|
|
|
|
!if(y{1}, x{1},
|
|
|
|
!if(y{0}, x{2}, ?))));
|
|
|
|
let n{10-9}= !if(x{2}, y{3-2},
|
|
|
|
!if(x{1}, y{2-1},
|
|
|
|
!if(x{0}, y{1-0}, ?)));
|
2010-12-13 02:46:19 +01:00
|
|
|
let n{8-6} = !if(x{2}, 0b010, 0b110);
|
|
|
|
let n{5-4} = !if(x{1}, y{3-2}, {0, 1});
|
|
|
|
let n{3-0} = !if(x{0}, y{3-0}, {z, y{2}, y{1}, y{0}});
|
|
|
|
}
|
|
|
|
|
Re-work bit/bits value resolving in tblgen
- This patch is inspired by the failure of the following code snippet
which is used to convert enumerable values into encoding bits to
improve the readability of td files.
class S<int s> {
bits<2> V = !if(!eq(s, 8), {0, 0},
!if(!eq(s, 16), {0, 1},
!if(!eq(s, 32), {1, 0},
!if(!eq(s, 64), {1, 1}, {?, ?}))));
}
Later, PR8330 is found to report not exactly the same bug relevant
issue to bit/bits values.
- Instead of resolving bit/bits values separately through
resolveBitReference(), this patch adds getBit() for all Inits and
resolves bit value by resolving plus getting the specified bit. This
unifies the resolving of bit with other values and removes redundant
logic for resolving bit only. In addition,
BitsInit::resolveReferences() is optimized to take advantage of this
origanization by resolving VarBitInit's variable reference first and
then getting bits from it.
- The type interference in '!if' operator is revised to support possible
combinations of int and bits/bit in MHS and RHS.
- As there may be illegal assignments from integer value to bit, says
assign 2 to a bit, but we only check this during instantiation in some
cases, e.g.
bit V = !if(!eq(x, 17), 0, 2);
Verbose diagnostic message is generated when invalid value is
resolveed to help locating the error.
- PR8330 is fixed as well.
llvm-svn: 163360
2012-09-07 01:32:48 +02:00
|
|
|
def C1 : C<{1, 0, 1}, {0, 1, 0, 1}, 0>;
|
|
|
|
def C2 : C<{0, 1, 0}, {1, 0, 1, 0}, 1>;
|
|
|
|
def C3 : C<{0, 0, 0}, {1, 0, 1, 0}, 0>;
|
|
|
|
def C4 : C<{0, 0, 0}, {0, 0, 0, 0}, 0>;
|
|
|
|
|
|
|
|
// CHECK: def C1
|
|
|
|
// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 };
|
|
|
|
// CHECK: def C2
|
|
|
|
// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 };
|
|
|
|
// CHECK: def C3
|
|
|
|
// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, 1, ?, ?, 1, 1, 0, 0, 1, 0, 0, 1, 0 };
|
|
|
|
// CHECK: def C4
|
|
|
|
// CHECK-NEXT: bits<16> n = { ?, ?, ?, ?, ?, ?, ?, 1, 1, 0, 0, 1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
class S<int s> {
|
|
|
|
bits<2> val = !if(!eq(s, 8), {0, 0},
|
|
|
|
!if(!eq(s, 16), 0b01,
|
|
|
|
!if(!eq(s, 32), 2,
|
|
|
|
!if(!eq(s, 64), {1, 1}, ?))));
|
|
|
|
}
|
|
|
|
|
|
|
|
def D8 : S<8>;
|
|
|
|
def D16 : S<16>;
|
|
|
|
def D32 : S<32>;
|
|
|
|
def D64 : S<64>;
|
|
|
|
def D128: S<128>;
|
|
|
|
// CHECK: def D128
|
|
|
|
// CHECK-NEXT: bits<2> val = { ?, ? };
|
|
|
|
// CHECK: def D16
|
|
|
|
// CHECK-NEXT: bits<2> val = { 0, 1 };
|
|
|
|
// CHECK: def D32
|
|
|
|
// CHECK-NEXT: bits<2> val = { 1, 0 };
|
|
|
|
// CHECK: def D64
|
|
|
|
// CHECK-NEXT: bits<2> val = { 1, 1 };
|
|
|
|
// CHECK: def D8
|
|
|
|
// CHECK-NEXT: bits<2> val = { 0, 0 };
|
|
|
|
|
2018-01-30 20:29:21 +01:00
|
|
|
// Make sure !if gets propagated across multiple layers of inheritance.
|
|
|
|
class getInt<int c> {
|
|
|
|
int ret = !if(c, 0, 1);
|
|
|
|
}
|
|
|
|
class I1<int c> {
|
|
|
|
int i = getInt<c>.ret;
|
|
|
|
}
|
|
|
|
class I2<int c> : I1<c>;
|
|
|
|
|
|
|
|
// CHECK: def DI1 { // I1
|
|
|
|
// CHECK-NEXT: int i = 0;
|
|
|
|
def DI1: I1<1>;
|
|
|
|
|
2018-02-23 12:31:49 +01:00
|
|
|
// CHECK: def DI2 { // I1 I2
|
2018-01-30 20:29:21 +01:00
|
|
|
// CHECK-NEXT: int i = 0;
|
|
|
|
def DI2: I2<1>;
|
|
|
|
|
2018-03-06 14:48:20 +01:00
|
|
|
// Check that !if with operands of different subtypes can initialize a
|
|
|
|
// supertype variable.
|
|
|
|
//
|
|
|
|
// CHECK: def EXd1 {
|
|
|
|
// CHECK: E x = E1d;
|
|
|
|
// CHECK: }
|
|
|
|
//
|
|
|
|
// CHECK: def EXd2 {
|
|
|
|
// CHECK: E x = E2d;
|
|
|
|
// CHECK: }
|
|
|
|
class E<int dummy> {}
|
|
|
|
class E1<int dummy> : E<dummy> {}
|
|
|
|
class E2<int dummy> : E<dummy> {}
|
|
|
|
|
|
|
|
class EX<int cc, E1 b, E2 c> {
|
|
|
|
E x = !if(cc, b, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
def E1d : E1<0>;
|
|
|
|
def E2d : E2<0>;
|
|
|
|
|
|
|
|
def EXd1 : EX<1, E1d, E2d>;
|
|
|
|
def EXd2 : EX<0, E1d, E2d>;
|
|
|
|
|
2010-12-13 02:46:19 +01:00
|
|
|
// CHECK: def One
|
|
|
|
// CHECK-NEXT: list<int> first = [1, 2, 3];
|
|
|
|
// CHECK-NEXT: list<int> rest = [1, 2, 3];
|
|
|
|
|
|
|
|
// CHECK: def OneB
|
|
|
|
// CHECK-NEXT: list<int> vals = [1, 2, 3];
|
|
|
|
|
|
|
|
// CHECK: def Two
|
|
|
|
// CHECK-NEXT: list<int> first = [1, 2, 3];
|
|
|
|
// CHECK-NEXT: list<int> rest = [4, 5, 6];
|
|
|
|
|
|
|
|
// CHECK: def TwoB
|
|
|
|
// CHECK-NEXT: list<int> vals = [4, 5, 6];
|
|
|
|
|
2009-05-15 01:26:46 +02:00
|
|
|
class A<list<list<int>> vals> {
|
|
|
|
list<int> first = vals[0];
|
2011-01-07 18:05:37 +01:00
|
|
|
list<int> rest = !if(!empty(!tail(vals)), vals[0], vals[1]);
|
2009-05-15 01:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def One : A<[[1,2,3]]>;
|
2010-12-13 02:46:19 +01:00
|
|
|
def Two : A<[[1,2,3], [4,5,6]]>;
|
2009-05-15 01:26:46 +02:00
|
|
|
|
|
|
|
class B<list<int> v> {
|
|
|
|
list<int> vals = v;
|
|
|
|
}
|
|
|
|
|
2011-01-07 18:05:37 +01:00
|
|
|
class BB<list<list<int>> vals> : B<!if(!empty(!tail(vals)), vals[0], vals[1])>;
|
2009-05-15 01:26:46 +02:00
|
|
|
class BBB<list<list<int>> vals> : BB<vals>;
|
|
|
|
|
|
|
|
def OneB : BBB<[[1,2,3]]>;
|
|
|
|
def TwoB : BBB<[[1,2,3],[4,5,6]]>;
|