Add new optimization keywords to the polygen grammar.
[oota-llvm.git] / utils / llvm.grm
1 (*
2
3 polygen grammar for LLVM assembly language.
4
5 This file defines an LLVM assembly language grammar for polygen,
6 which is a tool for generating random text based on a grammar.
7 It is strictly syntax-based, and makes no attempt to generate
8 IR that is semantically valid. Most of the IR produced doesn't
9 pass the Verifier.
10
11 *)
12
13 I ::=   "title:    LLVM assembly language\n"
14       ^ "status:   experimental\n"
15       ^ "audience: LLVM developers\n"
16 ;
17
18 S ::= Module ;
19
20 (*
21 Define rules for non-keyword tokens. This is currently just a bunch
22 of hacks. They don't cover many valid forms of tokens, and they also
23 generate some invalid forms of tokens. The LLVM parser has custom
24 C++ code to lex these; custom C++ code for emitting them would be
25 convenient, but polygen doesn't support that.
26 *)
27 NonZeroDecimalDigit ::=     1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
28 DecimalDigit        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
29 DecimalDigitSeq     ::= DecimalDigit [^ DecimalDigitSeq ];
30 HexDigit            ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
31                       | a | b | c | d | e | f ;
32 HexDigitSeq         ::= HexDigit [^ HexDigitSeq ];
33 StringChar          ::= a | b | c | d | e | f | g | h | i | j | k | l | m
34                       | n | o | p | q | r | s | t | u | v | w | x | y | z ;
35 StringConstantSeq   ::= StringChar [^ StringConstantSeq ];
36 StringConstant      ::= StringChar [^ StringConstantSeq ];
37 EUINT64VAL          ::= NonZeroDecimalDigit [^ DecimalDigitSeq ];
38 ESINT64VAL          ::= [ "-" ] ^ EUINT64VAL ;
39 EUAPINTVAL          ::= EUINT64VAL ;
40 ESAPINTVAL          ::= ESINT64VAL ;
41 LOCALVALID          ::= "%" ^ DecimalDigitSeq ;
42 GLOBALVALID         ::= "@" ^ DecimalDigitSeq ;
43 INTTYPE             ::= "i" ^ EUINT64VAL ;
44 GLOBALVAR           ::= "@" ^ StringConstant ;
45 LOCALVAR            ::= "%" ^ StringConstant ;
46 STRINGCONSTANT      ::= "\"" ^ StringConstant ^ "\"" ;
47 ATSTRINGCONSTANT    ::= "@" ^ STRINGCONSTANT ;
48 PCTSTRINGCONSTANT   ::= "%" ^ STRINGCONSTANT ;
49 LABELSTR            ::= StringConstant ;
50 FPVAL               ::= ESAPINTVAL ^ "." ^ EUAPINTVAL | "0x" ^ HexDigitSeq ;
51
52 (*
53 The rest of this file is derived directly from llvmAsmParser.y.
54 *)
55
56 ArithmeticOps ::= + OptNW add | fadd | OptNW sub | fsub | OptNW mul | fmul |
57                   udiv | OptExact sdiv | fdiv | urem | srem | frem ;
58 LogicalOps    ::= shl | lshr | ashr | and | or | xor;
59 CastOps       ::= trunc | zext | sext | fptrunc | fpext | bitcast |
60                   uitofp | sitofp | fptoui | fptosi | inttoptr | ptrtoint ;
61
62 IPredicates ::= eq | ne | slt | sgt | sle | sge | ult | ugt | ule | uge ;
63
64 FPredicates ::= oeq | one | olt | ogt | ole | oge | ord | uno | ueq | une
65               | ult | ugt | ule | uge | true | false ;
66
67 IntType ::= INTTYPE;
68 FPType  ::= float | double | "ppc_fp128" | fp128 | "x86_fp80";
69
70 LocalName ::= LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
71 OptLocalName ::= LocalName | _ ;
72
73 OptAddrSpace ::= - addrspace ^ "(" ^ EUINT64VAL ^ ")" | _ ;
74
75 OptLocalAssign ::= LocalName "=" | _ ;
76
77 GlobalName ::= GLOBALVAR | ATSTRINGCONSTANT ;
78
79 OptGlobalAssign ::= GlobalAssign | _ ;
80
81 GlobalAssign ::= GlobalName "=" ;
82
83 GVInternalLinkage
84   ::= + internal
85  | weak
86  | "weak_odr"
87  | linkonce
88  | "linkonce_odr"
89  | appending
90  | dllexport
91  | common
92  | private
93  ;
94
95 GVExternalLinkage
96   ::= dllimport
97  | "extern_weak"
98  | + external
99  ;
100
101 GVVisibilityStyle
102   ::= + _
103  | default
104  | hidden
105  | protected
106  ;
107
108 FunctionDeclareLinkage
109   ::= + _
110  | dllimport
111  | "extern_weak"
112  ;
113
114 FunctionDefineLinkage
115   ::= + _
116  | internal
117  | linkonce
118  | "linkonce_odr"
119  | weak
120  | "weak_odr"
121  | dllexport
122  ;
123
124 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
125
126 OptCallingConv ::= + _ |
127                  ccc |
128                  fastcc |
129                  coldcc |
130                  "x86_stdcallcc" |
131                  "x86_fastcallcc" |
132                  cc EUINT64VAL ;
133
134 ParamAttr ::= zeroext
135  | signext
136  | inreg
137  | sret
138  | noalias
139  | nocapture
140  | byval
141  | nest
142  | align EUINT64VAL
143  ;
144
145 OptParamAttrs ::= + _ | OptParamAttrs ParamAttr ;
146
147 RetAttr       ::= inreg
148               | zeroext
149               | signext
150               | noalias
151               ;
152
153 OptRetAttrs  ::= _
154              | OptRetAttrs RetAttr
155              ;
156
157 FuncAttr      ::= noreturn
158  | nounwind
159  | inreg
160  | zeroext
161  | signext
162  | readnone
163  | readonly
164  | noinline
165  | alwaysinline
166  | optsize
167  | ssp
168  | sspreq
169  ;
170
171 OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;
172
173 OptGC         ::= + _ | gc STRINGCONSTANT ;
174
175 OptAlign      ::= + _ | align EUINT64VAL ;
176 OptCAlign     ::= + _ | ^ "," align EUINT64VAL ;
177
178 SectionString ::= section STRINGCONSTANT ;
179
180 OptSection    ::= + _ | SectionString ;
181
182 GlobalVarAttributes ::= + _ | ^ "," GlobalVarAttribute GlobalVarAttributes ;
183 GlobalVarAttribute  ::= SectionString | align EUINT64VAL ;
184
185 PrimType ::= INTTYPE | float | double | "ppc_fp128" | fp128 | "x86_fp80"
186           | - label ;
187
188 Types
189   ::= opaque
190  | PrimType
191  | Types OptAddrSpace ^ "*"
192  | SymbolicValueRef
193  | "\\" ^ EUINT64VAL
194  | Types "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
195  | void "(" ^ ArgTypeListI ^ ")" OptFuncAttrs
196  | "[" ^ EUINT64VAL "x" Types ^ "]"
197  | "<" ^ EUINT64VAL "x" Types ^ ">"
198  | "{" TypeListI "}"
199  | "{" ^ "}"
200  | "<" ^ "{" TypeListI "}" ^ ">"
201  | "<" ^ "{" ^ "}" ^ ">"
202  ;
203
204 ArgType ::= Types OptParamAttrs ;
205
206 ResultTypes ::= Types | void ;
207
208 ArgTypeList ::= ArgType | ArgTypeList ^ "," ArgType ;
209
210 ArgTypeListI ::= ArgTypeList | ArgTypeList ^ "," "..." | "..." | _ ;
211
212 TypeListI ::= Types | TypeListI ^ "," Types ;
213
214 ConstVal::= Types "[" ^ ConstVector ^ "]"
215  | Types "[" ^ "]"
216  | Types "c" ^ STRINGCONSTANT
217  | Types "<" ^ ConstVector ^ ">"
218  | Types "{" ConstVector "}"
219  | Types "{" ^ "}"
220  | Types "<" ^ "{" ConstVector "}" ^ ">"
221  | Types "<" ^ "{" ^ "}" ^ ">"
222  | Types null
223  | Types undef
224  | Types SymbolicValueRef
225  | Types ConstExpr
226  | Types zeroinitializer
227  | Types ESINT64VAL
228  | Types ESAPINTVAL
229  | Types EUINT64VAL
230  | Types EUAPINTVAL
231  | Types true
232  | Types false
233  | Types FPVAL ;
234
235 ConstExpr::= CastOps "(" ^ ConstVal to Types ^ ")"
236  | getelementptr "(" ^ ConstVal IndexList ^ ")"
237  | select "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
238  | ArithmeticOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
239  | LogicalOps "(" ^ ConstVal ^ "," ConstVal ^ ")"
240  | icmp IPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
241  | fcmp FPredicates "(" ^ ConstVal ^ "," ConstVal ^ ")"
242  | extractelement "(" ^ ConstVal ^ "," ConstVal ^ ")"
243  | insertelement "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
244  | shufflevector "(" ^ ConstVal ^ "," ConstVal ^ "," ConstVal ^ ")"
245  | extractvalue "(" ^ ConstVal ^ ConstantIndexList ^ ")"
246  | insertvalue "(" ^ ConstVal ^ "," ConstVal ^ ConstantIndexList ^ ")" ;
247
248 ConstVector ::= ConstVector ^ "," ConstVal | ConstVal ;
249
250 GlobalType ::= global | constant ;
251
252 ThreadLocal ::= - "thread_local" | _ ;
253
254 AliaseeRef ::= ResultTypes SymbolicValueRef
255  | bitcast "(" ^ AliaseeRef to Types ^ ")" ;
256
257 Module ::= +++ DefinitionList | --- _ ;
258
259 DefinitionList ::= - Definition | + DefinitionList Definition ;
260
261 Definition
262   ::= ^ ( +++++ define Function
263  | declare FunctionProto
264  | - module asm AsmBlock
265  | OptLocalAssign type Types
266  | OptGlobalAssign GVVisibilityStyle ThreadLocal OptAddrSpace GlobalType
267    ConstVal GlobalVarAttributes
268  | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
269    GlobalType ConstVal GlobalVarAttributes
270  | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal OptAddrSpace
271    GlobalType Types GlobalVarAttributes
272  | OptGlobalAssign GVVisibilityStyle alias AliasLinkage AliaseeRef
273  | target TargetDefinition
274  | deplibs "=" LibrariesDefinition
275  ) ^ "\n";
276
277 AsmBlock ::= STRINGCONSTANT ;
278
279 TargetDefinition ::= triple "=" STRINGCONSTANT
280  | datalayout "=" STRINGCONSTANT ;
281
282 LibrariesDefinition ::= "[" ( LibList | _ ) "]";
283
284 LibList ::= LibList ^ "," STRINGCONSTANT | STRINGCONSTANT ;
285
286 ArgListH ::= ArgListH ^ "," Types OptParamAttrs OptLocalName
287  | Types OptParamAttrs OptLocalName ;
288
289 ArgList ::= ArgListH | ArgListH ^ "," "..." | "..." | _ ;
290
291 FunctionHeaderH ::= OptCallingConv OptRetAttrs ResultTypes
292                   GlobalName ^ "(" ^ ArgList ^ ")"
293                   OptFuncAttrs OptSection OptAlign OptGC ;
294
295 BEGIN ::= ( begin | "{" ) ^ "\n";
296
297 FunctionHeader ::=
298   FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN ;
299
300 END ::= ^ ( end | "}" ) ^ "\n";
301
302 Function ::= BasicBlockList END ;
303
304 FunctionProto ::= FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH ;
305
306 OptSideEffect ::= _ | sideeffect ;
307
308 ConstValueRef ::= ESINT64VAL
309  | EUINT64VAL
310  | FPVAL
311  | true
312  | false
313  | null
314  | undef
315  | zeroinitializer
316  | "<" ConstVector ">"
317  | "[" ConstVector "]"
318  | "[" ^ "]"
319  | "c" ^ STRINGCONSTANT
320  | "{" ConstVector "}"
321  | "{" ^ "}"
322  | "<" ^ "{" ConstVector "}" ^ ">"
323  | "<" ^ "{" ^ "}" ^ ">"
324  | ConstExpr
325  | asm OptSideEffect STRINGCONSTANT ^ "," STRINGCONSTANT ;
326
327 SymbolicValueRef ::= LOCALVALID
328  | GLOBALVALID
329  | LocalName
330  | GlobalName ;
331
332 ValueRef ::= SymbolicValueRef | ConstValueRef;
333
334 ResolvedVal ::= Types ValueRef ;
335
336 ReturnedVal ::= ResolvedVal | ReturnedVal ^ "," ResolvedVal ;
337
338 BasicBlockList ::= BasicBlockList BasicBlock | FunctionHeader BasicBlock ;
339
340 BasicBlock ::= InstructionList OptLocalAssign BBTerminatorInst ;
341
342 InstructionList ::= +++ InstructionList Inst
343  | - _
344  | ^ LABELSTR ^ ":\n" ;
345
346 BBTerminatorInst ::= ^ "  " ^
347  ( ret ReturnedVal
348  | ret void
349  | br label ValueRef
350  | br INTTYPE ValueRef ^ "," label ValueRef ^ "," label ValueRef
351  | switch IntType ValueRef ^ "," label ValueRef "[" JumpTable "]"
352  | switch IntType ValueRef ^ "," label ValueRef "[" ^ "]"
353  | invoke OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
354    OptFuncAttrs
355    to label ValueRef unwind label ValueRef
356  | unwind
357  | unreachable ) ^ "\n";
358
359 JumpTable ::= JumpTable IntType ConstValueRef ^ "," label ValueRef
360  | IntType ConstValueRef ^ "," label ValueRef ;
361
362 Inst ::= ^ "  " ^ OptLocalAssign InstVal ^ "\n";
363
364 PHIList ::= Types "[" ValueRef ^ "," ValueRef "]"
365  | PHIList ^ "," "[" ValueRef ^ "," ValueRef "]" ;
366
367 ParamList ::= Types OptParamAttrs ValueRef OptParamAttrs
368  | label OptParamAttrs ValueRef OptParamAttrs
369  | ParamList ^ "," Types OptParamAttrs ValueRef OptParamAttrs
370  | ParamList ^ "," label OptParamAttrs ValueRef OptParamAttrs
371  | - _ ;
372
373 IndexList ::= _ | IndexList ^ "," ResolvedVal ;
374
375 ConstantIndexList ::= "," EUINT64VAL | ConstantIndexList ^ "," EUINT64VAL ;
376
377 OptTailCall ::= tail call | call ;
378
379 InstVal ::=
380    ArithmeticOps Types ValueRef ^ "," ValueRef
381  | LogicalOps Types ValueRef ^ "," ValueRef
382  | icmp IPredicates Types ValueRef ^ "," ValueRef
383  | fcmp FPredicates Types ValueRef ^ "," ValueRef
384  | CastOps ResolvedVal to Types
385  | select ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
386  | "va_arg" ResolvedVal ^ "," Types
387  | extractelement ResolvedVal ^ "," ResolvedVal
388  | insertelement ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
389  | shufflevector ResolvedVal ^ "," ResolvedVal ^ "," ResolvedVal
390  | phi PHIList
391  | OptTailCall OptCallingConv ResultTypes ValueRef ^ "(" ^ ParamList ^ ")"
392    OptFuncAttrs
393  | MemoryInst ;
394
395 OptVolatile ::= - volatile | _ ;
396 OptExact ::= - exact | _ ;
397 OptNSW ::= - nsw | _ ;
398 OptNUW ::= - nuw | _ ;
399 OptNW  ::= OptNUW OptNSW ;
400
401 MemoryInst ::= malloc Types OptCAlign
402  | malloc Types ^ "," INTTYPE ValueRef OptCAlign
403  | alloca Types OptCAlign
404  | alloca Types ^ "," INTTYPE ValueRef OptCAlign
405  | free ResolvedVal
406  | OptVolatile load Types ValueRef OptCAlign
407  | OptVolatile store ResolvedVal ^ "," Types ValueRef OptCAlign
408  | getresult Types ValueRef ^ "," EUINT64VAL
409  | getelementptr Types ValueRef IndexList
410  | extractvalue Types ValueRef ^ ConstantIndexList 
411  | insertvalue Types ValueRef ^ "," Types ValueRef ^ ConstantIndexList ;