1 //===- NaClLLVMBitCodes.h ---------------------------------------*- C++ -*-===//
2 //     Enum values for the NaCl bitcode wire format
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This header defines Bitcode enum values for NaCl bitcode wire format.
12 //
13 // The enum values defined in this file should be considered permanent.  If
14 // new features are added, they should have values added at the end of the
15 // respective lists.
16 //
17 // Note: PNaCl version 1 is no longer supported, and has been removed from
18 // comments.
19 //
20 //===----------------------------------------------------------------------===//
21 
22 #ifndef LLVM_BITCODE_NACL_NACLLLVMBITCODES_H
23 #define LLVM_BITCODE_NACL_NACLLLVMBITCODES_H
24 
25 #include "llvm/Bitcode/NaCl/NaClBitCodes.h"
26 
27 namespace llvm {
28 namespace naclbitc {
29 // The only top-level block type defined is for a module.
30 enum NaClBlockIDs {
31   // Blocks
32   MODULE_BLOCK_ID = FIRST_APPLICATION_BLOCKID,
33 
34   // Module sub-block id's.
35   PARAMATTR_BLOCK_ID,       // Not used in PNaCl.
36   PARAMATTR_GROUP_BLOCK_ID, // Not used in PNaCl.
37 
38   CONSTANTS_BLOCK_ID,
39   FUNCTION_BLOCK_ID,
40 
41   UNUSED_ID1,
42 
43   VALUE_SYMTAB_BLOCK_ID,
44   METADATA_BLOCK_ID,      // Not used in PNaCl.
45   METADATA_ATTACHMENT_ID, // Not used in PNaCl.
46 
47   TYPE_BLOCK_ID_NEW,
48 
49   USELIST_BLOCK_ID, // Not used in PNaCl.
50   GLOBALVAR_BLOCK_ID
51 };
52 
53 /// MODULE blocks have a number of optional fields and subblocks.
54 enum NaClModuleCodes {
55   MODULE_CODE_VERSION = 1,     // VERSION:     [version#]
56   MODULE_CODE_TRIPLE = 2,      // Not used in PNaCl
57   MODULE_CODE_DATALAYOUT = 3,  // Not used in PNaCl
58   MODULE_CODE_ASM = 4,         // Not used in PNaCl
59   MODULE_CODE_SECTIONNAME = 5, // Not used in PNaCl
60   MODULE_CODE_DEPLIB = 6,      // Not used in PNaCl
61   MODULE_CODE_GLOBALVAR = 7,   // Not used in PNaCl
62   // FUNCTION:  [type, callingconv, isproto, linkage]
63   MODULE_CODE_FUNCTION = 8,
64   MODULE_CODE_ALIAS = 9,      // Not used in PNaCl
65   MODULE_CODE_PURGEVALS = 10, // Not used in PNaCl
66   MODULE_CODE_GCNAME = 11     // Not used in PNaCl
67 };
68 
69 /// PARAMATTR blocks have code for defining a parameter attribute set.
70 enum NaClAttributeCodes {
71   // FIXME: Remove `PARAMATTR_CODE_ENTRY_OLD' in 4.0
72   PARAMATTR_CODE_ENTRY_OLD = 1, // ENTRY: [paramidx0, attr0,
73                                 //         paramidx1, attr1...]
74   PARAMATTR_CODE_ENTRY = 2,     // ENTRY: [paramidx0, attrgrp0,
75                                 //         paramidx1, attrgrp1, ...]
76   PARAMATTR_GRP_CODE_ENTRY = 3  // ENTRY: [id, attr0, att1, ...]
77 };
78 
79 /// TYPE blocks have codes for each type primitive they use.
80 enum NaClTypeCodes {
81   TYPE_CODE_NUMENTRY = 1, // NUMENTRY: [numentries]
82 
83   // Type Codes
84   TYPE_CODE_VOID = 2,   // VOID
85   TYPE_CODE_FLOAT = 3,  // FLOAT
86   TYPE_CODE_DOUBLE = 4, // DOUBLE
87   // TODO(mseaborn): Remove LABEL when we drop support for v1 of the
88   // PNaCl bitcode format.  The writer no longer generates it.
89   TYPE_CODE_LABEL = 5,   // LABEL
90   TYPE_CODE_OPAQUE = 6,  // Not used in PNaCl.
91   TYPE_CODE_INTEGER = 7, // INTEGER: [width]
92   TYPE_CODE_POINTER = 8, // POINTER: [pointee type]
93 
94   TYPE_CODE_FUNCTION_OLD = 9, // Not used in PNaCl.
95 
96   TYPE_CODE_HALF = 10, // Not used in PNaCl.
97 
98   TYPE_CODE_ARRAY = 11,  // Not used in PNaCl.
99   TYPE_CODE_VECTOR = 12, // VECTOR: [numelts, eltty]
100 
101   // These are not with the other floating point types because they're
102   // a late addition, and putting them in the right place breaks
103   // binary compatibility.
104   TYPE_CODE_X86_FP80 = 13,  // Not used in PNaCl.
105   TYPE_CODE_FP128 = 14,     // Not used in PNaCl.
106   TYPE_CODE_PPC_FP128 = 15, // Not used in PNaCl.
107 
108   TYPE_CODE_METADATA = 16, // Not used in PNaCl.
109 
110   TYPE_CODE_X86_MMX = 17, // Not used in PNaCl.
111 
112   TYPE_CODE_STRUCT_ANON = 18,  // Not used in PNaCl.
113   TYPE_CODE_STRUCT_NAME = 19,  // Not used in PNaCl.
114   TYPE_CODE_STRUCT_NAMED = 20, // Not used in PNaCl.
115 
116   TYPE_CODE_FUNCTION = 21 // FUNCTION: [vararg, retty, paramty x N]
117 };
118 
119 // The type symbol table only has one code (TST_ENTRY_CODE).
120 enum NaClTypeSymtabCodes {
121   TST_CODE_ENTRY = 1 // TST_ENTRY: [typeid, namechar x N]
122 };
123 
124 // The value symbol table only has one code (VST_ENTRY_CODE).
125 enum NaClValueSymtabCodes {
126   VST_CODE_ENTRY = 1,  // VST_ENTRY: [valid, namechar x N]
127   VST_CODE_BBENTRY = 2 // VST_BBENTRY: [bbid, namechar x N]
128 };
129 
130 // Not used in PNaCl.
131 enum NaClMetadataCodes {
132   METADATA_STRING = 1, // MDSTRING:      [values]
133   // 2 is unused.
134   // 3 is unused.
135   METADATA_NAME = 4, // STRING:        [values]
136   // 5 is unused.
137   METADATA_KIND = 6, // [n x [id, name]]
138   // 7 is unused.
139   METADATA_NODE = 8,        // NODE:          [n x (type num, value num)]
140   METADATA_FN_NODE = 9,     // FN_NODE:       [n x (type num, value num)]
141   METADATA_NAMED_NODE = 10, // NAMED_NODE:    [n x mdnodes]
142   METADATA_ATTACHMENT = 11  // [m x [value, [n x [id, mdnode]]]
143 };
144 
145 // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
146 // constant and maintains an implicit current type value.
147 enum NaClConstantsCodes {
148   CST_CODE_SETTYPE = 1,          // SETTYPE:       [typeid]
149   CST_CODE_NULL = 2,             // Not used in PNaCl.
150   CST_CODE_UNDEF = 3,            // UNDEF
151   CST_CODE_INTEGER = 4,          // INTEGER:       [intval]
152   CST_CODE_WIDE_INTEGER = 5,     // Not used in PNaCl.
153   CST_CODE_FLOAT = 6,            // FLOAT:         [fpval]
154   CST_CODE_AGGREGATE = 7,        // Not used in PNaCl.
155   CST_CODE_STRING = 8,           // Not used in PNaCl.
156   CST_CODE_CSTRING = 9,          // Not used in PNaCl.
157   CST_CODE_CE_BINOP = 10,        // Not used in PNaCl.
158   CST_CODE_CE_CAST = 11,         // Not used in PNaCl.
159   CST_CODE_CE_GEP = 12,          // Not used in PNaCl.
160   CST_CODE_CE_SELECT = 13,       // Not used in PNaCl.
161   CST_CODE_CE_EXTRACTELT = 14,   // Not used in PNaCl.
162   CST_CODE_CE_INSERTELT = 15,    // Not used in PNaCl.
163   CST_CODE_CE_SHUFFLEVEC = 16,   // Not used in PNaCl.
164   CST_CODE_CE_CMP = 17,          // Not used in PNaCl.
165   CST_CODE_INLINEASM_OLD = 18,   // No longer used.
166   CST_CODE_CE_SHUFVEC_EX = 19,   // Not used in PNaCl.
167   CST_CODE_CE_INBOUNDS_GEP = 20, // Not used in PNaCl.
168   CST_CODE_BLOCKADDRESS = 21,    // Not used in PNaCl.
169   CST_CODE_DATA = 22,            // Not used in PNaCl.
170   CST_CODE_INLINEASM = 23        // Not used in PNaCl.
171 };
172 
173 /// GlobalVarOpcodes - These are values used in the bitcode files to
174 /// encode records defining global variables.
175 ///
176 /// The structure of global variables can be summarized as follows:
177 ///
178 /// The global variable block begins with a GLOBALVAR_COUNT, defining
179 /// the number of global variables in the bitcode file. After that,
180 /// each global variable is defined.
181 ///
182 /// Global variables are defined by a GLOBALVAR_VAR record, followed
183 /// by 1 or more records defining its initial value. Simple
184 /// variables have a single initializer. Structured variables are
185 /// defined by an initial GLOBALVAR_COMPOUND record defining the
186 /// number of fields in the structure, followed by an initializer
187 /// for each of its fields. In this context, a field is either data,
188 /// or a relocation.  A data field is defined by a
189 /// GLOBALVAR_ZEROFILL or GLOBALVAR_DATA record.  A relocation field
190 /// is defined by a GLOBALVAR_RELOC record.
191 enum NaClGlobalVarOpcodes {
192   GLOBALVAR_VAR = 0,      // VAR: [align, isconst]
193   GLOBALVAR_COMPOUND = 1, // COMPOUND: [size]
194   GLOBALVAR_ZEROFILL = 2, // ZEROFILL: [size]
195   GLOBALVAR_DATA = 3,     // DATA: [b0, b1, ...]
196   GLOBALVAR_RELOC = 4,    // RELOC: [val, [addend]]
197   GLOBALVAR_COUNT = 5     // COUNT: [n]
198 };
199 
200 /// CastOpcodes - These are values used in the bitcode files to encode which
201 /// cast a CST_CODE_CE_CAST or a XXX refers to.  The values of these enums
202 /// have no fixed relation to the LLVM IR enum values.  Changing these will
203 /// break compatibility with old files.
204 enum NaClCastOpcodes {
205   CAST_TRUNC = 0,
206   CAST_ZEXT = 1,
207   CAST_SEXT = 2,
208   CAST_FPTOUI = 3,
209   CAST_FPTOSI = 4,
210   CAST_UITOFP = 5,
211   CAST_SITOFP = 6,
212   CAST_FPTRUNC = 7,
213   CAST_FPEXT = 8,
214   // 9 was CAST_PTRTOINT; not used in PNaCl.
215   // 10 was CAST_INTTOPTR; not used in PNaCl.
216   CAST_BITCAST = 11
217 };
218 
219 /// BinaryOpcodes - These are values used in the bitcode files to encode which
220 /// binop a CST_CODE_CE_BINOP or a XXX refers to.  The values of these enums
221 /// have no fixed relation to the LLVM IR enum values.  Changing these will
222 /// break compatibility with old files.
223 enum NaClBinaryOpcodes {
224   BINOP_ADD = 0,
225   BINOP_SUB = 1,
226   BINOP_MUL = 2,
227   BINOP_UDIV = 3,
228   BINOP_SDIV = 4, // overloaded for FP
229   BINOP_UREM = 5,
230   BINOP_SREM = 6, // overloaded for FP
231   BINOP_SHL = 7,
232   BINOP_LSHR = 8,
233   BINOP_ASHR = 9,
234   BINOP_AND = 10,
235   BINOP_OR = 11,
236   BINOP_XOR = 12
237 };
238 
239 /// OverflowingBinaryOperatorOptionalFlags - Flags for serializing
240 /// OverflowingBinaryOperator's SubclassOptionalData contents.
241 /// Note: This enum is no longer used in PNaCl, because these
242 /// flags can't exist in files that meet the PNaCl ABI.
243 enum NaClOverflowingBinaryOperatorOptionalFlags {
244   OBO_NO_UNSIGNED_WRAP = 0,
245   OBO_NO_SIGNED_WRAP = 1
246 };
247 
248 /// PossiblyExactOperatorOptionalFlags - Flags for serializing
249 /// PossiblyExactOperator's SubclassOptionalData contents.
250 /// Note: This enum is no longer used in PNaCl, because these
251 /// flags can't exist in files that meet the PNaCl ABI.
252 enum NaClPossiblyExactOperatorOptionalFlags { PEO_EXACT = 0 };
253 
254 /// \brief Flags for serializing floating point binary operators's
255 /// SubclassOptionalData contents.
256 /// Note: This enum is no longer used in PNaCl, because these
257 /// flags shouldn't exist in files that meet the PNaCl ABI, unless
258 /// they are old. In the latter case, they are ignored by the reader.
259 enum NaClFloatingPointBinaryOperatorOptionalFlags {
260   FPO_UNSAFE_ALGEBRA = 0,
261   FPO_NO_NANS = 1,
262   FPO_NO_INFS = 2,
263   FPO_NO_SIGNED_ZEROS = 3,
264   FPO_ALLOW_RECIPROCAL = 4
265 };
266 
267 /// Encoded function calling conventions.
268 enum NaClCallingConventions { C_CallingConv = 0 };
269 
270 /// Encoded comparison predicates.
271 enum NaClComparisonPredicates {
272   // Opcode              U L G E    Intuitive operation
273   FCMP_FALSE = 0, ///< 0 0 0 0    Always false (always folded)
274   FCMP_OEQ = 1,   ///< 0 0 0 1    True if ordered and equal
275   FCMP_OGT = 2,   ///< 0 0 1 0    True if ordered and greater than
276   FCMP_OGE = 3,   ///< 0 0 1 1    True if ordered and greater than or equal
277   FCMP_OLT = 4,   ///< 0 1 0 0    True if ordered and less than
278   FCMP_OLE = 5,   ///< 0 1 0 1    True if ordered and less than or equal
279   FCMP_ONE = 6,   ///< 0 1 1 0    True if ordered and operands are unequal
280   FCMP_ORD = 7,   ///< 0 1 1 1    True if ordered (no nans)
281   FCMP_UNO = 8,   ///< 1 0 0 0    True if unordered: isnan(X) | isnan(Y)
282   FCMP_UEQ = 9,   ///< 1 0 0 1    True if unordered or equal
283   FCMP_UGT = 10,  ///< 1 0 1 0    True if unordered or greater than
284   FCMP_UGE = 11,  ///< 1 0 1 1    True if unordered, greater than, or equal
285   FCMP_ULT = 12,  ///< 1 1 0 0    True if unordered or less than
286   FCMP_ULE = 13,  ///< 1 1 0 1    True if unordered, less than, or equal
287   FCMP_UNE = 14,  ///< 1 1 1 0    True if unordered or not equal
288   FCMP_TRUE = 15, ///< 1 1 1 1    Always true (always folded)
289   ICMP_EQ = 32,   ///< equal
290   ICMP_NE = 33,   ///< not equal
291   ICMP_UGT = 34,  ///< unsigned greater than
292   ICMP_UGE = 35,  ///< unsigned greater or equal
293   ICMP_ULT = 36,  ///< unsigned less than
294   ICMP_ULE = 37,  ///< unsigned less or equal
295   ICMP_SGT = 38,  ///< signed greater than
296   ICMP_SGE = 39,  ///< signed greater or equal
297   ICMP_SLT = 40,  ///< signed less than
298   ICMP_SLE = 41   ///< signed less or equal
299 };
300 
301 enum NaClLinkageTypes { LINKAGE_EXTERNAL = 0, LINKAGE_INTERNAL = 3 };
302 
303 // The function body block (FUNCTION_BLOCK_ID) describes function bodies.  It
304 // can contain a constant block (CONSTANTS_BLOCK_ID).
305 enum NaClFunctionCodes {
306   FUNC_CODE_DECLAREBLOCKS = 1, // DECLAREBLOCKS: [n]
307 
308   FUNC_CODE_INST_BINOP = 2,      // BINOP:      [opval, opval, opcode]
309                                  // Note: because old PNaCl bitcode files
310                                  // may contain flags (which we now ignore),
311                                  // the reader must also support:
312                                  // BINOP: [opval, opval, opcode, flags]
313   FUNC_CODE_INST_CAST = 3,       // CAST:       [opval, destty, castopc]
314   FUNC_CODE_INST_GEP = 4,        // Not used in PNaCl.
315   FUNC_CODE_INST_SELECT = 5,     // Not used in PNaCl. Replaced by VSELECT.
316   FUNC_CODE_INST_EXTRACTELT = 6, // EXTRACTELT: [opval, opval]
317   FUNC_CODE_INST_INSERTELT = 7,  // INSERTELT:  [opval, opval, opval]
318   FUNC_CODE_INST_SHUFFLEVEC = 8, // Not used in PNaCl.
319   FUNC_CODE_INST_CMP = 9,        // Not used in PNaCl. Replaced by CMP2.
320   FUNC_CODE_INST_RET = 10,       // RET:        [opval<optional>]
321   FUNC_CODE_INST_BR = 11,        // BR:         [bb#, bb#, cond] or [bb#]
322   FUNC_CODE_INST_SWITCH = 12,    // SWITCH:     [opty, op0, op1, ...]
323   FUNC_CODE_INST_INVOKE = 13,    // Not used in PNaCl.
324   // 14 is unused.
325   FUNC_CODE_INST_UNREACHABLE = 15, // UNREACHABLE
326 
327   FUNC_CODE_INST_PHI = 16, // PHI:        [ty, val0,bb0, ...]
328   // 17 is unused.
329   // 18 is unused.
330   FUNC_CODE_INST_ALLOCA = 19, // ALLOCA:     [op, align]
331   FUNC_CODE_INST_LOAD = 20,   // LOAD: [op, align, ty]
332   // 21 is unused.
333   // 22 is unused.
334   FUNC_CODE_INST_VAARG = 23, // Not used in PNaCl.
335   FUNC_CODE_INST_STORE = 24, // STORE: [ptr, val, align]
336   // 25 is unused.
337   FUNC_CODE_INST_EXTRACTVAL = 26, // Not used in PNaCl.
338   FUNC_CODE_INST_INSERTVAL = 27,  // Not used in PNaCl.
339   // fcmp/icmp returning Int1TY or vector of Int1Ty. Same as CMP, exists to
340   // support legacy vicmp/vfcmp instructions.
341   FUNC_CODE_INST_CMP2 = 28, // CMP2:       [opval, opval, pred]
342   // new select on i1 or [N x i1]
343   FUNC_CODE_INST_VSELECT = 29,      // VSELECT:    [opval, opval, pred]
344   FUNC_CODE_INST_INBOUNDS_GEP = 30, // Not used in PNaCl.
345   FUNC_CODE_INST_INDIRECTBR = 31,   // Not used in PNaCl.
346   // 32 is unused.
347   FUNC_CODE_DEBUG_LOC_AGAIN = 33, // Not used in PNaCl.
348 
349   FUNC_CODE_INST_CALL = 34,           // CALL: [cc, fnid, args...]
350                                       // See FUNC_CODE_INST_CALL_INDIRECT below.
351   FUNC_CODE_DEBUG_LOC = 35,           // Not used in PNaCl.
352   FUNC_CODE_INST_FENCE = 36,          // Not used in PNaCl.
353   FUNC_CODE_INST_CMPXCHG = 37,        // Not used in PNaCl.
354   FUNC_CODE_INST_ATOMICRMW = 38,      // Not used in PNaCl.
355   FUNC_CODE_INST_RESUME = 39,         // Not used in PNaCl.
356   FUNC_CODE_INST_LANDINGPAD = 40,     // Not used in PNaCl.
357   FUNC_CODE_INST_LOADATOMIC = 41,     // Not used in PNaCl.
358   FUNC_CODE_INST_STOREATOMIC = 42,    // Not used in PNaCl.
359   FUNC_CODE_INST_FORWARDTYPEREF = 43, // TYPE: [opval, ty]
360   // CALL_INDIRECT: [cc, fnid, returnty, args...]
361   FUNC_CODE_INST_CALL_INDIRECT = 44
362 };
363 } // namespace naclbitc
364 } // namespace llvm
365 
366 #endif
367