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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
| include "llvm/TableGen/Automaton.td"
include "llvm/TableGen/SearchableTable.td"
// Define a set of input token symbols.
class SymKindTy;
def SK_a : SymKindTy;
def SK_b : SymKindTy;
def SK_c : SymKindTy;
def SK_d : SymKindTy;
// Emit those as a C++ enum using SearchableTables.
def SymKind : GenericEnum {
let FilterClass = "SymKindTy";
}
// Define a transition implementation.
class SimpleTransition<bits<2> State, SymKindTy A> : Transition {
let NewState{1-0} = State;
SymKindTy ActionSym = A;
}
// Token SK_a sets bit 0b01.
def : SimpleTransition<0b01, SK_a>;
// Token SK_b sets bits 0b10.
def : SimpleTransition<0b10, SK_b>;
// Token SK_c sets both bits 0b11.
def : SimpleTransition<0b11, SK_c>;
def SimpleAutomaton : GenericAutomaton {
let TransitionClass = "SimpleTransition";
let SymbolFields = ["ActionSym"];
// Override the type of ActionSym from SymKindTy to the C++ type SymKind.
string TypeOf_ActionSym = "SymKind";
}
//===----------------------------------------------------------------------===//
// TupleActionAutomaton test implementation
// Define a transition implementation.
class TupleTransition<bits<2> State, SymKindTy s1, SymKindTy s2, string s3> : Transition {
let NewState{1-0} = State;
SymKindTy S1 = s1;
SymKindTy S2 = s2;
string S3 = s3;
}
def : TupleTransition<0b01, SK_a, SK_b, "yeet">;
def : TupleTransition<0b10, SK_b, SK_b, "foo">;
def : TupleTransition<0b10, SK_c, SK_a, "foo">;
def TupleAutomaton : GenericAutomaton {
let TransitionClass = "TupleTransition";
let SymbolFields = ["S1", "S2", "S3"];
string TypeOf_S1 = "SymKind";
string TypeOf_S2 = "SymKind";
}
//===----------------------------------------------------------------------===//
// NfaAutomaton test implementation
class NfaTransition<bits<2> State, SymKindTy S> : Transition {
let NewState{1-0} = State;
SymKindTy A = S;
}
// Symbols a and b can transition to 0b01 or 0b11 (sets bit 0).
def : NfaTransition<0b01, SK_a>;
def : NfaTransition<0b01, SK_b>;
// Symbols a and b can also transition to 0b10 or 0b11 (sets bit 1).
def : NfaTransition<0b10, SK_a>;
def : NfaTransition<0b10, SK_b>;
def NfaAutomaton : GenericAutomaton {
let TransitionClass = "NfaTransition";
let SymbolFields = ["A"];
string TypeOf_A = "SymKind";
}
//===----------------------------------------------------------------------===//
// BinPacker test implementation
//===----------------------------------------------------------------------===//
// This test generates an automaton that can pack values into bins subject to
// constraints. There are 6 possible bins, and the input tokens are constraint
// types. Some input types span two bins.
// The symbol type for a bin constraint. We use lists of ints as a tblgen hack
// to conditionally generate defs within multiclasses based on record
// information. A bin is nonempty (has a dummy one-element value) if enabled.
class BinRequirementKind {
list<int> Bin0 = [];
list<int> Bin1 = [];
list<int> Bin2 = [];
list<int> Bin3 = [];
list<int> Bin4 = [];
list<int> Bin5 = [];
}
// Can use bins {0-3}
def BRK_0_to_4 : BinRequirementKind { let Bin0 = [1]; let Bin1 = [1]; let Bin2 = [1]; let Bin3 = [1]; }
// Can use bins {0-3} but only evens (0 and 2).
def BRK_0_to_4_lo : BinRequirementKind { let Bin0 = [1]; let Bin2 = [1]; }
// Can use bins {0-3} but only odds (1 and 3).
def BRK_0_to_4_hi : BinRequirementKind { let Bin1 = [1]; let Bin3 = [1]; }
// Can use bins {0-3} but only even-odd pairs (0+1 or 1+2).
def BRK_0_to_4_dbl : BinRequirementKind { let Bin0 = [1]; let Bin2 = [1]; }
def BRK_0_to_6 : BinRequirementKind { let Bin0 = [1]; let Bin1 = [1]; let Bin2 = [1];
let Bin3 = [1]; let Bin4 = [1]; let Bin5 = [1]; }
def BRK_0_to_6_lo : BinRequirementKind { let Bin0 = [1]; let Bin2 = [1]; let Bin4 = [1]; }
def BRK_0_to_6_hi : BinRequirementKind { let Bin1 = [1]; let Bin3 = [1]; let Bin5 = [1]; }
def BRK_0_to_6_dbl : BinRequirementKind { let Bin0 = [1]; let Bin2 = [1]; let Bin4 = [1]; }
def BRK_2_to_6 : BinRequirementKind { let Bin2 = [1];
let Bin3 = [1]; let Bin4 = [1]; let Bin5 = [1]; }
def BRK_2_to_6_lo : BinRequirementKind { let Bin2 = [1]; let Bin4 = [1]; }
def BRK_2_to_6_hi : BinRequirementKind { let Bin3 = [1]; let Bin5 = [1];}
def BRK_2_to_6_dbl : BinRequirementKind { let Bin2 = [1]; let Bin4 = [1]; }
def BRK_2_to_4 : BinRequirementKind { let Bin2 = [1]; let Bin3 = [1]; }
def BRK_2_to_4_lo : BinRequirementKind { let Bin2 = [1]; }
def BRK_2_to_4_hi : BinRequirementKind { let Bin3 = [1]; }
def BRK_2_to_4_dbl : BinRequirementKind { let Bin2 = [1]; }
def BinRequirementKindEnum : GenericEnum {
let FilterClass = "BinRequirementKind";
}
// The transition class is trivial; it just contains the constraint symbol.
class BinTransition : Transition {
BinRequirementKind Sym;
}
// Mixin that occupies a single bin.
class Bin0 : BinTransition { let NewState{0} = 1; }
class Bin1 : BinTransition { let NewState{1} = 1; }
class Bin2 : BinTransition { let NewState{2} = 1;}
class Bin3 : BinTransition { let NewState{3} = 1; }
class Bin4 : BinTransition { let NewState{4} = 1;}
class Bin5 : BinTransition { let NewState{5} = 1; }
// Mixin that occupies a pair of bins (even-odd pairs).
class Bin01 : BinTransition { let NewState{0,1} = 0b11; }
class Bin23 : BinTransition { let NewState{2,3} = 0b11; }
class Bin45 : BinTransition { let NewState{4,5} = 0b11; }
// Instantiate all possible bin assignments for E.
multiclass BinAssignments<BinRequirementKind E> {
let Sym = E in {
// Note the tablegen hack to conditionally instantiate a def based on E.
foreach x = E.Bin0 in { def : Bin0; }
foreach x = E.Bin1 in { def : Bin1; }
foreach x = E.Bin2 in { def : Bin2; }
foreach x = E.Bin3 in { def : Bin3; }
foreach x = E.Bin4 in { def : Bin4; }
foreach x = E.Bin5 in { def : Bin5; }
}
}
// Instantiate all possible bin assignments for E, which spans even-odd pairs.
multiclass DblBinAssignments<BinRequirementKind E> {
let Sym = E in {
foreach x = E.Bin0 in { def : Bin01; }
foreach x = E.Bin2 in { def : Bin23; }
foreach x = E.Bin4 in { def : Bin45; }
}
}
defm : BinAssignments<BRK_0_to_4>;
defm : DblBinAssignments<BRK_0_to_4_dbl>;
defm : BinAssignments<BRK_0_to_4_lo>;
defm : BinAssignments<BRK_0_to_4_hi>;
defm : BinAssignments<BRK_0_to_6>;
defm : DblBinAssignments<BRK_0_to_6_dbl>;
defm : BinAssignments<BRK_0_to_6_lo>;
defm : BinAssignments<BRK_0_to_6_hi>;
defm : BinAssignments<BRK_2_to_6>;
defm : DblBinAssignments<BRK_2_to_6_dbl>;
defm : BinAssignments<BRK_2_to_6_lo>;
defm : BinAssignments<BRK_2_to_6_hi>;
defm : BinAssignments<BRK_2_to_4>;
defm : DblBinAssignments<BRK_2_to_4_dbl>;
defm : BinAssignments<BRK_2_to_4_lo>;
defm : BinAssignments<BRK_2_to_4_hi>;
def BinPackerAutomaton : GenericAutomaton {
let TransitionClass = "BinTransition";
let SymbolFields = ["Sym"];
string TypeOf_Sym = "BinRequirementKindEnum";
}
|