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