File: instances.td

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (133 lines) | stat: -rw-r--r-- 3,809 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// RUN: llvm-tblgen %s | FileCheck %s
// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
// XFAIL: vg_leak

class A;
def a0 : A;
def a1 : A;

class B : A;
def b0 : B;
def b1 : B;

// CHECK-LABEL: def test0_instances_A {
// CHECK-NEXT:    list<A> instances = [a0, a1, b0, b1];
// CHECK-NEXT:  }
def test0_instances_A {
  list<A> instances = !instances<A>();
}

// CHECK-LABEL: def test1_instances_A_x0 {
// CHECK-NEXT:    list<A> instances = [a0, b0];
// CHECK-NEXT:  }
def test1_instances_A_x0 {
  list<A> instances = !instances<A>(".*0");
}

// CHECK-LABEL: def test2_instances_A_x1 {
// CHECK-NEXT:    list<A> instances = [a1, b1];
// CHECK-NEXT:  }
def test2_instances_A_x1 {
  list<A> instances = !instances<A>(".*1");
}

// CHECK-LABEL: def test3_instances_B {
// CHECK-NEXT:    list<B> instances = [b0, b1];
// CHECK-NEXT:  }
def test3_instances_B {
  list<B> instances = !instances<B>();
}

//-----------------------------------------------------------------------------//

def a2 : A;
def b2 : B;

class ClassTest {
   list<A> instances_A = !instances<A>();
   list<B> instances_B = !instances<B>();
}

def a3 : A;
def b3 : B;

def test4_in_class_def : ClassTest;
// CHECK-LABEL: def test4_in_class_def {
// CHECK-NEXT:    list<A> instances_A = [a0, a1, a2, a3, b0, b1, b2, b3];
// CHECK-NEXT:    list<B> instances_B = [b0, b1, b2, b3];
// CHECK-NEXT:  }

//-----------------------------------------------------------------------------//
// Self-recurrence is not supported, so it won't be count in.

// CHECK-LABEL: def test5_self_recurrence {
// CHECK-NEXT:    list<A> instances_A = [a0, a1, a2, a3, b0, b1, b2, b3];
// CHECK-NEXT:  }
def test5_self_recurrence : A {
   list<A> instances_A = !instances<A>();
}

//-----------------------------------------------------------------------------//
// Test these in multiclasses/loops.

class C {
  list<C> instances_C = !instances<C>();
}

multiclass MultiClassTest {
  foreach i = 0-2 in {
    def "c"#i : C;
  }
}

// CHECK-LABEL: def test6_in_multiclass_def_c0 {
// CHECK-NEXT:    list<C> instances_C = [];
// CHECK-NEXT:  }
// CHECK-LABEL: def test6_in_multiclass_def_c1 {
// CHECK-NEXT:    list<C> instances_C = [test6_in_multiclass_def_c0];
// CHECK-NEXT:  }
// CHECK-LABEL: def test6_in_multiclass_def_c2 {
// CHECK-NEXT:    list<C> instances_C = [test6_in_multiclass_def_c0, test6_in_multiclass_def_c1];
// CHECK-NEXT:  }
defm test6_in_multiclass_def_ : MultiClassTest;

//-----------------------------------------------------------------------------//
// Default argument/temporary actual parameter will be considered as well.
class D<int n>;

class TestArgument<D d = D<0>> {
  list<D> instances_D = !instances<D>();
}

// CHECK-LABEL: def test7_default_arg {
// CHECK-NEXT:    list<D> instances_D = [anonymous_0];
// CHECK-NEXT:  }
def test7_default_arg : TestArgument;

// CHECK-LABEL: def test8_anonymous0_arg {
// CHECK-NEXT:    list<D> instances_D = [anonymous_0, anonymous_1];
// CHECK-NEXT:  }
// CHECK-LABEL: def test8_anonymous1_arg {
// CHECK-NEXT:    list<D> instances_D = [anonymous_0, anonymous_1, anonymous_2];
// CHECK-NEXT:  }
def test8_anonymous0_arg : TestArgument<D<1>>;
def test8_anonymous1_arg : TestArgument<D<2>>;

//-----------------------------------------------------------------------------//

#ifdef ERROR1
defvar error1 = !instances<A>(123);
// ERROR1: error: expected string type argument in !instances operator
#endif

#ifdef ERROR2
defvar error2 = !instances<1>("");
// ERROR2: error: Unknown token when expecting a type
#endif

#ifdef ERROR3
defvar error3 = !instances<A>("([)]");
// ERROR3: error: invalid regex '([)]'
#endif