• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Test evaluation of set operations in dags.
2// RUN: llvm-tblgen -print-sets %s | FileCheck %s
3// XFAIL: vg_leak
4//
5// The -print-sets driver configures a primitive SetTheory instance that
6// understands these sets:
7
8class Set<dag d> {
9  dag Elements = d;
10}
11
12// It prints all Set instances and their ordered set interpretation.
13
14// Define some elements.
15def a;
16def b;
17def c;
18def d;
19
20// The 'add' operator evaluates and concatenates its arguments.
21def add;
22def S0a : Set<(add)>;
23def S0b : Set<(add a)>;
24def S0c : Set<(add a, b)>;
25def S0d : Set<(add b, a)>;
26def S0e : Set<(add a, a)>;
27def S0f : Set<(add a, a, b, a, c, b, d, a)>;
28def S0g : Set<(add b, a, b)>;
29// CHECK: S0a = [ ]
30// CHECK: S0b = [ a ]
31// CHECK: S0c = [ a b ]
32// CHECK: S0d = [ b a ]
33// CHECK: S0e = [ a ]
34// CHECK: S0f = [ a b c d ]
35// CHECK: S0g = [ b a ]
36
37// Defs of Set class expand into their elements.
38// Mixed sets and elements are flattened.
39def S1a : Set<(add S0a)>;
40def S1b : Set<(add S0a, S0a)>;
41def S1c : Set<(add S0d, S0f)>;
42def S1d : Set<(add d, S0d, S0f)>;
43// CHECK: S1a = [ ]
44// CHECK: S1b = [ ]
45// CHECK: S1c = [ b a c d ]
46// CHECK: S1d = [ d b a c ]
47
48// The 'sub' operator returns the first argument with the following arguments
49// removed.
50def sub;
51def S2a : Set<(sub S1a, S1c)>;
52def S2b : Set<(sub S1c, S1d)>;
53def S2c : Set<(sub S1c, b)>;
54def S2d : Set<(sub S1c, S0c)>;
55def S2e : Set<(sub S1c, S2d)>;
56// CHECK: S2a = [ ]
57// CHECK: S2b = [ ]
58// CHECK: S2c = [ a c d ]
59// CHECK: S2d = [ c d ]
60// CHECK: S2e = [ b a ]
61
62// The 'and' operator intersects two sets. The result has the same order as the
63// first argument.
64def and;
65def S3a : Set<(and S2d, S2e)>;
66def S3b : Set<(and S2d, S1d)>;
67// CHECK: S3a = [ ]
68// CHECK: S3b = [ c d ]
69
70// The 'shl' operator removes the first N elements.
71def shl;
72def S4a : Set<(shl S0f, 0)>;
73def S4b : Set<(shl S0f, 1)>;
74def S4c : Set<(shl S0f, 3)>;
75def S4d : Set<(shl S0f, 4)>;
76def S4e : Set<(shl S0f, 5)>;
77// CHECK: S4a = [ a b c d ]
78// CHECK: S4b = [ b c d ]
79// CHECK: S4c = [ d ]
80// CHECK: S4d = [ ]
81// CHECK: S4e = [ ]
82
83// The 'trunc' operator truncates after the first N elements.
84def trunc;
85def S5a : Set<(trunc S0f, 0)>;
86def S5b : Set<(trunc S0f, 1)>;
87def S5c : Set<(trunc S0f, 3)>;
88def S5d : Set<(trunc S0f, 4)>;
89def S5e : Set<(trunc S0f, 5)>;
90// CHECK: S5a = [ ]
91// CHECK: S5b = [ a ]
92// CHECK: S5c = [ a b c ]
93// CHECK: S5d = [ a b c d ]
94// CHECK: S5e = [ a b c d ]
95
96// The 'rotl' operator rotates left, but also accepts a negative shift.
97def rotl;
98def S6a : Set<(rotl S0f, 0)>;
99def S6b : Set<(rotl S0f, 1)>;
100def S6c : Set<(rotl S0f, 3)>;
101def S6d : Set<(rotl S0f, 4)>;
102def S6e : Set<(rotl S0f, 5)>;
103def S6f : Set<(rotl S0f, -1)>;
104def S6g : Set<(rotl S0f, -4)>;
105def S6h : Set<(rotl S0f, -5)>;
106// CHECK: S6a = [ a b c d ]
107// CHECK: S6b = [ b c d a ]
108// CHECK: S6c = [ d a b c ]
109// CHECK: S6d = [ a b c d ]
110// CHECK: S6e = [ b c d a ]
111// CHECK: S6f = [ d a b c ]
112// CHECK: S6g = [ a b c d ]
113// CHECK: S6h = [ d a b c ]
114
115// The 'rotr' operator rotates right, but also accepts a negative shift.
116def rotr;
117def S7a : Set<(rotr S0f, 0)>;
118def S7b : Set<(rotr S0f, 1)>;
119def S7c : Set<(rotr S0f, 3)>;
120def S7d : Set<(rotr S0f, 4)>;
121def S7e : Set<(rotr S0f, 5)>;
122def S7f : Set<(rotr S0f, -1)>;
123def S7g : Set<(rotr S0f, -4)>;
124def S7h : Set<(rotr S0f, -5)>;
125// CHECK: S7a = [ a b c d ]
126// CHECK: S7b = [ d a b c ]
127// CHECK: S7c = [ b c d a ]
128// CHECK: S7d = [ a b c d ]
129// CHECK: S7e = [ d a b c ]
130// CHECK: S7f = [ b c d a ]
131// CHECK: S7g = [ a b c d ]
132// CHECK: S7h = [ b c d a ]
133
134// The 'decimate' operator picks every N'th element.
135def decimate;
136def e0;
137def e1;
138def e2;
139def e3;
140def e4;
141def e5;
142def e6;
143def e7;
144def e8;
145def e9;
146def E : Set<(add e0, e1, e2, e3, e4, e5, e6, e7, e8, e9)>;
147def S8a : Set<(decimate E, 3)>;
148def S8b : Set<(decimate E, 9)>;
149def S8c : Set<(decimate E, 10)>;
150def S8d : Set<(decimate (rotl E, 1), 2)>;
151def S8e : Set<(add (decimate E, 2), (decimate (rotl E, 1), 2))>;
152// CHECK: S8a = [ e0 e3 e6 e9 ]
153// CHECK: S8b = [ e0 e9 ]
154// CHECK: S8c = [ e0 ]
155// CHECK: S8d = [ e1 e3 e5 e7 e9 ]
156// CHECK: S8e = [ e0 e2 e4 e6 e8 e1 e3 e5 e7 e9 ]
157
158// The 'sequence' operator finds a sequence of records from their name.
159def sequence;
160def S9a : Set<(sequence "e%u", 3, 7)>;
161def S9b : Set<(sequence "e%u", 7, 3)>;
162def S9c : Set<(sequence "e%u", 0, 0)>;
163def S9d : Set<(sequence "S%ua", 7, 9)>;
164def S9e : Set<(sequence "e%u", 3, 6, 2)>;
165// CHECK: S9a = [ e3 e4 e5 e6 e7 ]
166// CHECK: S9b = [ e7 e6 e5 e4 e3 ]
167// CHECK: S9c = [ e0 ]
168// CHECK: S9d = [ a b c d e0 e3 e6 e9 e4 e5 e7 ]
169// CHECK: S9e = [ e3 e5 ]
170
171// The 'interleave' operator is almost the inverse of 'decimate'.
172def interleave;
173def T0a : Set<(interleave S9a, S9b)>;
174def T0b : Set<(interleave S8e, S8d)>;
175// CHECK: T0a = [ e3 e7 e4 e6 e5 ]
176// CHECK: T0b = [ e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ]
177