1e7f3d68da51cc1157b469eb478c4c672bdd352e
[oota-llvm.git] / include / llvm / Intrinsics.td
1 //===- Intrinsics.td - Defines all LLVM intrinsics ---------*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines properties of all LLVM intrinsics.
11 //
12 //===----------------------------------------------------------------------===//
13
14 include "llvm/CodeGen/ValueTypes.td"
15
16 //===----------------------------------------------------------------------===//
17 //  Properties we keep track of for intrinsics.
18 //===----------------------------------------------------------------------===//
19
20 class IntrinsicProperty;
21
22 // Intr*Mem - Memory properties.  An intrinsic is allowed to have exactly one of
23 // these properties set.  They are listed from the most aggressive (best to use
24 // if correct) to the least aggressive.  If no property is set, the worst case 
25 // is assumed (IntrWriteMem).
26
27 // IntrNoMem - The intrinsic does not access memory or have any other side
28 // effects.  It may be CSE'd deleted if dead, etc.
29 def IntrNoMem : IntrinsicProperty;
30
31 // IntrReadArgMem - This intrinsic reads only from memory that one of its
32 // arguments points to, but may read an unspecified amount.
33 def IntrReadArgMem : IntrinsicProperty;
34
35 // IntrReadMem - This intrinsic reads from unspecified memory, so it cannot be
36 // moved across stores.  However, it can be reordered otherwise and can be
37 // deleted if dead.
38 def IntrReadMem : IntrinsicProperty;
39
40 // IntrWriteArgMem - This intrinsic reads and writes only from memory that one
41 // of its arguments points to, but may access an unspecified amount.  It has no
42 // other side effects.  This may only be used if the intrinsic doesn't "capture"
43 // the argument pointer (e.g. storing it someplace).
44 def IntrWriteArgMem : IntrinsicProperty;
45
46 // IntrWriteMem - This intrinsic may read or modify unspecified memory or has 
47 // other side effects.  It cannot be modified by the optimizer.  This is the
48 // default if the intrinsic has no other Intr*Mem property.
49 def IntrWriteMem : IntrinsicProperty;
50
51 // Commutative - This intrinsic is commutative: X op Y == Y op X.
52 def Commutative : IntrinsicProperty;
53
54 //===----------------------------------------------------------------------===//
55 // Types used by intrinsics.
56 //===----------------------------------------------------------------------===//
57
58 class LLVMType<ValueType vt> {
59   ValueType VT = vt;
60 }
61
62 class LLVMPointerType<LLVMType elty>
63   : LLVMType<iPTR>{
64   LLVMType ElTy = elty;
65
66
67 class LLVMAnyPointerType<LLVMType elty>
68   : LLVMType<iPTRAny>{
69   LLVMType ElTy = elty;
70
71
72 class LLVMMatchType<int num>
73   : LLVMType<OtherVT>{
74   int Number = num;
75 }
76
77 def llvm_void_ty       : LLVMType<isVoid>;
78 def llvm_anyint_ty     : LLVMType<iAny>;
79 def llvm_anyfloat_ty   : LLVMType<fAny>;
80 def llvm_i1_ty         : LLVMType<i1>;
81 def llvm_i8_ty         : LLVMType<i8>;
82 def llvm_i16_ty        : LLVMType<i16>;
83 def llvm_i32_ty        : LLVMType<i32>;
84 def llvm_i64_ty        : LLVMType<i64>;
85 def llvm_float_ty      : LLVMType<f32>;
86 def llvm_double_ty     : LLVMType<f64>;
87 def llvm_f80_ty        : LLVMType<f80>;
88 def llvm_f128_ty       : LLVMType<f128>;
89 def llvm_ppcf128_ty    : LLVMType<ppcf128>;
90 def llvm_ptr_ty        : LLVMPointerType<llvm_i8_ty>;             // i8*
91 def llvm_ptrptr_ty     : LLVMPointerType<llvm_ptr_ty>;            // i8**
92 def llvm_anyptr_ty     : LLVMAnyPointerType<llvm_i8_ty>;          // (space)i8*
93 def llvm_empty_ty      : LLVMType<OtherVT>;                       // { }
94 def llvm_descriptor_ty : LLVMPointerType<llvm_empty_ty>;          // { }*
95
96 def llvm_v16i8_ty      : LLVMType<v16i8>;    // 16 x i8
97 def llvm_v8i16_ty      : LLVMType<v8i16>;    //  8 x i16
98 def llvm_v2i64_ty      : LLVMType<v2i64>;    //  2 x i64
99 def llvm_v2i32_ty      : LLVMType<v2i32>;    //  2 x i32
100 def llvm_v1i64_ty      : LLVMType<v1i64>;    //  1 x i64
101 def llvm_v4i32_ty      : LLVMType<v4i32>;    //  4 x i32
102 def llvm_v4f32_ty      : LLVMType<v4f32>;    //  4 x float
103 def llvm_v2f64_ty      : LLVMType<v2f64>;    //  2 x double
104
105 // MMX Vector Types
106 def llvm_v8i8_ty       : LLVMType<v8i8>;     //  8 x i8
107 def llvm_v4i16_ty      : LLVMType<v4i16>;    //  4 x i16
108
109 def llvm_vararg_ty     : LLVMType<isVoid>;   // this means vararg here
110
111 //===----------------------------------------------------------------------===//
112 // Intrinsic Definitions.
113 //===----------------------------------------------------------------------===//
114
115 // Intrinsic class - This is used to define one LLVM intrinsic.  The name of the
116 // intrinsic definition should start with "int_", then match the LLVM intrinsic
117 // name with the "llvm." prefix removed, and all "."s turned into "_"s.  For
118 // example, llvm.bswap.i16 -> int_bswap_i16.
119 //
120 //  * RetTypes is a list containing the return types expected for the
121 //    intrinsic.
122 //  * ParamTypes is a list containing the parameter types expected for the
123 //    intrinsic.
124 //  * Properties can be set to describe the behavior of the intrinsic.
125 //
126 class Intrinsic<list<LLVMType> ret_types,
127                 list<LLVMType> param_types = [],
128                 list<IntrinsicProperty> properties = [],
129                 string name = ""> {
130   string LLVMName = name;
131   string TargetPrefix = "";   // Set to a prefix for target-specific intrinsics.
132   list<LLVMType> RetTypes = ret_types;
133   list<LLVMType> ParamTypes = param_types;
134   list<IntrinsicProperty> Properties = properties;
135 }
136
137 /// GCCBuiltin - If this intrinsic exactly corresponds to a GCC builtin, this
138 /// specifies the name of the builtin.  This provides automatic CBE and CFE
139 /// support.
140 class GCCBuiltin<string name> {
141   string GCCBuiltinName = name;
142 }
143
144
145 //===--------------- Variable Argument Handling Intrinsics ----------------===//
146 //  
147
148 def int_vastart : Intrinsic<[llvm_void_ty], [llvm_ptr_ty], [], "llvm.va_start">;
149 def int_vacopy  : Intrinsic<[llvm_void_ty], [llvm_ptr_ty, llvm_ptr_ty], [],
150                             "llvm.va_copy">;
151 def int_vaend   : Intrinsic<[llvm_void_ty], [llvm_ptr_ty], [], "llvm.va_end">;
152
153 //===------------------- Garbage Collection Intrinsics --------------------===//
154 //  
155 def int_gcroot  : Intrinsic<[llvm_void_ty], [llvm_ptrptr_ty, llvm_ptr_ty]>;
156 def int_gcread  : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty, llvm_ptrptr_ty],
157                             [IntrReadArgMem]>;
158 def int_gcwrite : Intrinsic<[llvm_void_ty], [llvm_ptr_ty, llvm_ptr_ty,
159                              llvm_ptrptr_ty], [IntrWriteArgMem]>;
160
161 //===--------------------- Code Generator Intrinsics ----------------------===//
162 //  
163 def int_returnaddress : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty], [IntrNoMem]>;
164 def int_frameaddress  : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty], [IntrNoMem]>;
165
166 // Note: we treat stacksave/stackrestore as writemem because we don't otherwise
167 // model their dependencies on allocas.
168 def int_stacksave     : Intrinsic<[llvm_ptr_ty]>,
169                         GCCBuiltin<"__builtin_stack_save">;
170 def int_stackrestore  : Intrinsic<[llvm_void_ty], [llvm_ptr_ty]>,
171                         GCCBuiltin<"__builtin_stack_restore">;
172
173 // IntrWriteArgMem is more pessimistic than strictly necessary for prefetch,
174 // however it does conveniently prevent the prefetch from being reordered
175 // with respect to nearby accesses to the same memory.
176 def int_prefetch      : Intrinsic<[llvm_void_ty],
177                                   [llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty],
178                                   [IntrWriteArgMem]>;
179 def int_pcmarker      : Intrinsic<[llvm_void_ty], [llvm_i32_ty]>;
180
181 def int_readcyclecounter : Intrinsic<[llvm_i64_ty]>;
182
183 // Stack Protector Intrinsic - The stackprotector_create writes the stack guard
184 // to the correct place on the stack frame.
185 def int_stackprotector_create : Intrinsic<[llvm_void_ty],
186                                           [llvm_ptr_ty, llvm_ptrptr_ty],
187                                           [IntrWriteMem]>;
188
189 //===------------------- Standard C Library Intrinsics --------------------===//
190 //
191
192 let Properties = [IntrWriteArgMem] in {
193   def int_memcpy_i32  : Intrinsic<[llvm_void_ty],
194                                   [llvm_ptr_ty, llvm_ptr_ty,
195                                    llvm_i32_ty, llvm_i32_ty]>;
196   def int_memcpy_i64  : Intrinsic<[llvm_void_ty],
197                                   [llvm_ptr_ty, llvm_ptr_ty,
198                                    llvm_i64_ty, llvm_i32_ty]>;
199   def int_memmove_i32 : Intrinsic<[llvm_void_ty],
200                                   [llvm_ptr_ty, llvm_ptr_ty,
201                                    llvm_i32_ty, llvm_i32_ty]>;
202   def int_memmove_i64 : Intrinsic<[llvm_void_ty],
203                                   [llvm_ptr_ty, llvm_ptr_ty,
204                                    llvm_i64_ty, llvm_i32_ty]>;
205   def int_memset_i32  : Intrinsic<[llvm_void_ty],
206                                   [llvm_ptr_ty, llvm_i8_ty,
207                                    llvm_i32_ty, llvm_i32_ty]>;
208   def int_memset_i64  : Intrinsic<[llvm_void_ty],
209                                   [llvm_ptr_ty, llvm_i8_ty,
210                                    llvm_i64_ty, llvm_i32_ty]>;
211 }
212
213 // These functions do not actually read memory, but they are sensitive to the
214 // rounding mode.  This needs to be modelled separately; in the meantime
215 // declaring them as reading memory is conservatively correct.
216 let Properties = [IntrReadMem] in {
217   def int_sqrt : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
218   def int_powi : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>, llvm_i32_ty]>;
219   def int_sin  : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
220   def int_cos  : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>; 
221   def int_pow  : Intrinsic<[llvm_anyfloat_ty],
222                            [LLVMMatchType<0>, LLVMMatchType<0>]>;
223   def int_log  : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
224   def int_log10: Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
225   def int_log2 : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
226   def int_exp  : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
227   def int_exp2 : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
228 }
229
230 // NOTE: these are internal interfaces.
231 def int_setjmp     : Intrinsic<[llvm_i32_ty],  [llvm_ptr_ty]>;
232 def int_longjmp    : Intrinsic<[llvm_void_ty], [llvm_ptr_ty, llvm_i32_ty]>;
233 def int_sigsetjmp  : Intrinsic<[llvm_i32_ty] , [llvm_ptr_ty, llvm_i32_ty]>;
234 def int_siglongjmp : Intrinsic<[llvm_void_ty], [llvm_ptr_ty, llvm_i32_ty]>;
235
236 //===-------------------- Bit Manipulation Intrinsics ---------------------===//
237 //
238
239 // None of these intrinsics accesses memory at all.
240 let Properties = [IntrNoMem] in {
241   def int_bswap: Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>]>;
242   def int_ctpop: Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>]>;
243   def int_ctlz : Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>]>;
244   def int_cttz : Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>]>;
245   def int_part_select : 
246      Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty]>;
247   def int_part_set :
248      Intrinsic<[llvm_anyint_ty],
249                [LLVMMatchType<0>, llvm_anyint_ty, llvm_i32_ty, llvm_i32_ty]>;
250 }
251
252 //===------------------------ Debugger Intrinsics -------------------------===//
253 //
254
255 def int_dbg_stoppoint    : Intrinsic<[llvm_void_ty],
256                                      [llvm_i32_ty, llvm_i32_ty, 
257                                       llvm_descriptor_ty]>;
258 def int_dbg_region_start : Intrinsic<[llvm_void_ty], [llvm_descriptor_ty]>;
259 def int_dbg_region_end   : Intrinsic<[llvm_void_ty], [llvm_descriptor_ty]>;
260 def int_dbg_func_start   : Intrinsic<[llvm_void_ty], [llvm_descriptor_ty]>;
261 def int_dbg_declare      : Intrinsic<[llvm_void_ty],
262                                      [llvm_descriptor_ty, llvm_descriptor_ty]>;
263
264 //===------------------ Exception Handling Intrinsics----------------------===//
265 //
266 def int_eh_exception    : Intrinsic<[llvm_ptr_ty]>;
267 def int_eh_selector_i32 : Intrinsic<[llvm_i32_ty],
268                                     [llvm_ptr_ty, llvm_ptr_ty, llvm_vararg_ty]>;
269 def int_eh_selector_i64 : Intrinsic<[llvm_i64_ty],
270                                     [llvm_ptr_ty, llvm_ptr_ty, llvm_vararg_ty]>;
271
272 def int_eh_typeid_for_i32 : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty]>;
273 def int_eh_typeid_for_i64 : Intrinsic<[llvm_i64_ty], [llvm_ptr_ty]>;
274
275 def int_eh_return_i32 : Intrinsic<[llvm_void_ty], [llvm_i32_ty, llvm_ptr_ty]>;
276 def int_eh_return_i64 : Intrinsic<[llvm_void_ty], [llvm_i64_ty, llvm_ptr_ty]>;
277
278 def int_eh_unwind_init: Intrinsic<[llvm_void_ty]>,
279                         GCCBuiltin<"__builtin_unwind_init">;
280
281 def int_eh_dwarf_cfa  : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty]>;
282
283 //===---------------- Generic Variable Attribute Intrinsics----------------===//
284 //
285 def int_var_annotation : Intrinsic<[llvm_void_ty],
286                                    [llvm_ptr_ty, llvm_ptr_ty,
287                                     llvm_ptr_ty, llvm_i32_ty], 
288                                     [], "llvm.var.annotation">;
289 def int_ptr_annotation : Intrinsic<[LLVMAnyPointerType<llvm_anyint_ty>],
290                                    [LLVMMatchType<0>, llvm_ptr_ty, llvm_ptr_ty,
291                                     llvm_i32_ty], 
292                                    [], "llvm.ptr.annotation">;
293 def int_annotation : Intrinsic<[llvm_anyint_ty],
294                                [LLVMMatchType<0>, llvm_ptr_ty,
295                                 llvm_ptr_ty, llvm_i32_ty],
296                                [], "llvm.annotation">;
297
298 //===------------------------ Trampoline Intrinsics -----------------------===//
299 //
300 def int_init_trampoline : Intrinsic<[llvm_ptr_ty],
301                                     [llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
302                                     []>,
303                           GCCBuiltin<"__builtin_init_trampoline">;
304
305 //===------------------------- Atomic Intrinsics --------------------------===//
306 //
307 def int_memory_barrier : Intrinsic<[llvm_void_ty], [llvm_i1_ty, llvm_i1_ty,
308                                     llvm_i1_ty, llvm_i1_ty, llvm_i1_ty], []>,
309                                     GCCBuiltin<"__builtin_llvm_memory_barrier">;
310
311 def int_atomic_cmp_swap : Intrinsic<[llvm_anyint_ty],
312                                     [LLVMAnyPointerType<LLVMMatchType<0>>,
313                                      LLVMMatchType<0>, LLVMMatchType<0>],
314                                     [IntrWriteArgMem]>,
315                            GCCBuiltin<"__sync_val_compare_and_swap">;
316 def int_atomic_load_add : Intrinsic<[llvm_anyint_ty],
317                                     [LLVMAnyPointerType<LLVMMatchType<0>>,
318                                      LLVMMatchType<0>],
319                                     [IntrWriteArgMem]>,
320                            GCCBuiltin<"__sync_fetch_and_add">;
321 def int_atomic_swap     : Intrinsic<[llvm_anyint_ty],
322                                     [LLVMAnyPointerType<LLVMMatchType<0>>,
323                                      LLVMMatchType<0>],
324                                     [IntrWriteArgMem]>,
325                            GCCBuiltin<"__sync_lock_test_and_set">;
326 def int_atomic_load_sub : Intrinsic<[llvm_anyint_ty],
327                                     [LLVMAnyPointerType<LLVMMatchType<0>>,
328                                      LLVMMatchType<0>],
329                                     [IntrWriteArgMem]>,
330                            GCCBuiltin<"__sync_fetch_and_sub">;
331 def int_atomic_load_and : Intrinsic<[llvm_anyint_ty],
332                                     [LLVMAnyPointerType<LLVMMatchType<0>>,
333                                      LLVMMatchType<0>],
334                                     [IntrWriteArgMem]>,
335                            GCCBuiltin<"__sync_fetch_and_and">;
336 def int_atomic_load_or   : Intrinsic<[llvm_anyint_ty],
337                                      [LLVMAnyPointerType<LLVMMatchType<0>>,
338                                       LLVMMatchType<0>],
339                                      [IntrWriteArgMem]>,
340                            GCCBuiltin<"__sync_fetch_and_or">;
341 def int_atomic_load_xor : Intrinsic<[llvm_anyint_ty],
342                                     [LLVMAnyPointerType<LLVMMatchType<0>>,
343                                      LLVMMatchType<0>],
344                                     [IntrWriteArgMem]>,
345                            GCCBuiltin<"__sync_fetch_and_xor">;
346 def int_atomic_load_nand : Intrinsic<[llvm_anyint_ty],
347                                      [LLVMAnyPointerType<LLVMMatchType<0>>,
348                                       LLVMMatchType<0>],
349                                      [IntrWriteArgMem]>,
350                            GCCBuiltin<"__sync_fetch_and_nand">;
351 def int_atomic_load_min  : Intrinsic<[llvm_anyint_ty],
352                                      [LLVMAnyPointerType<LLVMMatchType<0>>,
353                                       LLVMMatchType<0>],
354                                      [IntrWriteArgMem]>,
355                            GCCBuiltin<"__sync_fetch_and_min">;
356 def int_atomic_load_max  : Intrinsic<[llvm_anyint_ty],
357                                      [LLVMAnyPointerType<LLVMMatchType<0>>,
358                                       LLVMMatchType<0>],
359                                      [IntrWriteArgMem]>,
360                            GCCBuiltin<"__sync_fetch_and_max">;
361 def int_atomic_load_umin : Intrinsic<[llvm_anyint_ty],
362                                      [LLVMAnyPointerType<LLVMMatchType<0>>,
363                                       LLVMMatchType<0>],
364                                      [IntrWriteArgMem]>,
365                            GCCBuiltin<"__sync_fetch_and_umin">;
366 def int_atomic_load_umax : Intrinsic<[llvm_anyint_ty],
367                                      [LLVMAnyPointerType<LLVMMatchType<0>>,
368                                       LLVMMatchType<0>],
369                                      [IntrWriteArgMem]>,
370                            GCCBuiltin<"__sync_fetch_and_umax">;
371                                   
372 //===-------------------------- Other Intrinsics --------------------------===//
373 //
374 def int_flt_rounds : Intrinsic<[llvm_i32_ty]>,
375                      GCCBuiltin<"__builtin_flt_rounds">;
376 def int_trap : Intrinsic<[llvm_void_ty]>,
377                GCCBuiltin<"__builtin_trap">;
378
379 // These convert intrinsics are to support various conversions between
380 // various types with rounding and saturation. NOTE: avoid using these
381 // intrinsics as they might be removed sometime in the future and
382 // most targets don't support them.
383 def int_convertff  : Intrinsic<[llvm_anyfloat_ty],
384                                [llvm_anyfloat_ty, llvm_i32_ty, llvm_i32_ty]>;
385 def int_convertfsi : Intrinsic<[llvm_anyfloat_ty],
386                                [llvm_anyint_ty, llvm_i32_ty, llvm_i32_ty]>;
387 def int_convertfui : Intrinsic<[llvm_anyfloat_ty],
388                                [llvm_anyint_ty, llvm_i32_ty, llvm_i32_ty]>;
389 def int_convertsif : Intrinsic<[llvm_anyint_ty],
390                                [llvm_anyfloat_ty, llvm_i32_ty, llvm_i32_ty]>;
391 def int_convertuif : Intrinsic<[llvm_anyint_ty],
392                                [llvm_anyfloat_ty, llvm_i32_ty, llvm_i32_ty]>;
393 def int_convertss  : Intrinsic<[llvm_anyint_ty],
394                                [llvm_anyint_ty, llvm_i32_ty, llvm_i32_ty]>;
395 def int_convertsu  : Intrinsic<[llvm_anyint_ty],
396                                [llvm_anyint_ty, llvm_i32_ty, llvm_i32_ty]>;
397 def int_convertus  : Intrinsic<[llvm_anyint_ty],
398                                [llvm_anyint_ty, llvm_i32_ty, llvm_i32_ty]>;
399 def int_convertuu  : Intrinsic<[llvm_anyint_ty],
400                                [llvm_anyint_ty, llvm_i32_ty, llvm_i32_ty]>;
401
402 //===----------------------------------------------------------------------===//
403 // Target-specific intrinsics
404 //===----------------------------------------------------------------------===//
405
406 include "llvm/IntrinsicsPowerPC.td"
407 include "llvm/IntrinsicsX86.td"
408 include "llvm/IntrinsicsARM.td"
409 include "llvm/IntrinsicsCellSPU.td"
410 include "llvm/IntrinsicsAlpha.td"
411 include "llvm/IntrinsicsXCore.td"