blob: 89d723430470555fa01d8b05131f8620fa133168 [file] [log] [blame]
Nicolai Haehnle18f19982018-03-19 14:14:10 +00001// RUN: llvm-tblgen %s | FileCheck %s
2// XFAIL: vg_leak
3
4// CHECK: --- Defs ---
5
6// CHECK: def A0 {
7// CHECK: dag a = (ops A0);
8// CHECK: }
9
10// CHECK: def B0 {
11// CHECK: dag a = (ops);
12// CHECK: A b = B0;
13// CHECK: }
14
15// CHECK: def C0 {
16// CHECK: dag q = (ops C0);
17// CHECK: }
18
Nicolai Haehnle4186cc72018-03-19 14:14:20 +000019// CHECK: def D0 {
20// CHECK: D d = D0;
21// CHECK: }
22
23// CHECK: def E0 {
24// CHECK: E e = E0;
25// CHECK: }
26
Nicolai Haehnle18f19982018-03-19 14:14:10 +000027def ops;
28
29class A<dag d> {
30 dag a = d;
31}
32
33// This type of self-reference is used in various places defining register
34// classes.
35def A0 : A<(ops A0)>;
36
37class B<string self> {
38 A b = !cast<A>(self);
39}
40
41// A stronger form of this type of self-reference is used at least in the
42// SystemZ backend to define a record which is a ComplexPattern and an Operand
43// at the same time.
44def B0 : A<(ops)>, B<"B0">;
45
46// Casting C0 to C by name here is tricky, because it happens while (or rather:
47// before) adding C as a superclass. However, SystemZ uses this pattern.
48class C<string self> {
49 dag q = (ops !cast<C>(self));
50}
51
52def C0 : C<"C0">;
Nicolai Haehnle4186cc72018-03-19 14:14:20 +000053
54// Explore some unused corner cases.
55//
56// A self-reference within a class may seem icky, but it unavoidably falls out
57// orthogonally of having forward class declarations and late resolve of self
58// references.
59class D<string self> {
60 D d = !cast<D>(self);
61}
62
63def D0 : D<"D0">;
64
65class E<E x> {
66 E e = x;
67}
68
69// Putting the !cast directly in the def should work as well: we shouldn't
70// depend on implementation details of when exactly the record is looked up.
71//
72// Note the difference between !cast<E>("E0") and plain E0: the latter wouldn't
73// work here because E0 does not yet have E as a superclass while the template
74// arguments are being parsed.
75def E0 : E<!cast<E>("E0")>;