| ... | ... | @@ -0,0 +1,1102 @@ |
| 1 | const std = @import("std"); |
| 2 | const Builder = @import("Builder.zig"); |
| 3 | const bitcode_writer = @import("bitcode_writer.zig"); |
| 4 | |
| 5 | const AbbrevOp = bitcode_writer.AbbrevOp; |
| 6 | |
| 7 | pub const MAGIC: u32 = 0xdec04342; |
| 8 | |
| 9 | const ValueAbbrev = AbbrevOp{ .vbr = 6 }; |
| 10 | const ValueArrayAbbrev = AbbrevOp{ .array_vbr = 6 }; |
| 11 | |
| 12 | const ConstantAbbrev = AbbrevOp{ .vbr = 6 }; |
| 13 | const ConstantArrayAbbrev = AbbrevOp{ .array_vbr = 6 }; |
| 14 | |
| 15 | const BlockAbbrev = AbbrevOp{ .vbr = 6 }; |
| 16 | |
| 17 | pub const Identification = struct { |
| 18 | pub const id = 13; |
| 19 | |
| 20 | pub const abbrevs = [_]type{ |
| 21 | Version, |
| 22 | Epoch, |
| 23 | }; |
| 24 | |
| 25 | pub const Version = struct { |
| 26 | pub const ops = [_]AbbrevOp{ |
| 27 | .{ .literal = 1 }, |
| 28 | .{ .array_fixed = 8 }, |
| 29 | }; |
| 30 | string: []const u8, |
| 31 | }; |
| 32 | |
| 33 | pub const Epoch = struct { |
| 34 | pub const ops = [_]AbbrevOp{ |
| 35 | .{ .literal = 2 }, |
| 36 | .{ .vbr = 6 }, |
| 37 | }; |
| 38 | epoch: u32, |
| 39 | }; |
| 40 | }; |
| 41 | |
| 42 | pub const Module = struct { |
| 43 | pub const id = 8; |
| 44 | |
| 45 | pub const abbrevs = [_]type{ |
| 46 | Version, |
| 47 | String, |
| 48 | Variable, |
| 49 | Function, |
| 50 | Alias, |
| 51 | }; |
| 52 | |
| 53 | pub const Version = struct { |
| 54 | pub const ops = [_]AbbrevOp{ |
| 55 | .{ .literal = 1 }, |
| 56 | .{ .literal = 2 }, |
| 57 | }; |
| 58 | }; |
| 59 | |
| 60 | pub const String = struct { |
| 61 | pub const ops = [_]AbbrevOp{ |
| 62 | .{ .vbr = 4 }, |
| 63 | .{ .array_fixed = 8 }, |
| 64 | }; |
| 65 | code: u16, |
| 66 | string: []const u8, |
| 67 | }; |
| 68 | |
| 69 | pub const Variable = struct { |
| 70 | const AddrSpaceAndIsConst = packed struct { |
| 71 | is_const: bool, |
| 72 | one: u1 = 1, |
| 73 | addr_space: Builder.AddrSpace, |
| 74 | }; |
| 75 | |
| 76 | pub const ops = [_]AbbrevOp{ |
| 77 | .{ .literal = 7 }, // Code |
| 78 | .{ .vbr = 16 }, // strtab_offset |
| 79 | .{ .vbr = 16 }, // strtab_size |
| 80 | .{ .fixed_runtime = Builder.Type }, |
| 81 | .{ .fixed = @bitSizeOf(AddrSpaceAndIsConst) }, // isconst |
| 82 | ConstantAbbrev, // initid |
| 83 | .{ .fixed = @bitSizeOf(Builder.Linkage) }, |
| 84 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 85 | .{ .vbr = 16 }, // section |
| 86 | .{ .fixed = @bitSizeOf(Builder.Visibility) }, |
| 87 | .{ .fixed = @bitSizeOf(Builder.ThreadLocal) }, // threadlocal |
| 88 | .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) }, |
| 89 | .{ .fixed = @bitSizeOf(Builder.ExternallyInitialized) }, |
| 90 | .{ .fixed = @bitSizeOf(Builder.DllStorageClass) }, |
| 91 | .{ .literal = 0 }, // comdat |
| 92 | .{ .literal = 0 }, // attributes |
| 93 | .{ .fixed = @bitSizeOf(Builder.Preemption) }, |
| 94 | }; |
| 95 | strtab_offset: usize, |
| 96 | strtab_size: usize, |
| 97 | type_index: Builder.Type, |
| 98 | is_const: AddrSpaceAndIsConst, |
| 99 | initid: u32, |
| 100 | linkage: Builder.Linkage, |
| 101 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 102 | section: usize, |
| 103 | visibility: Builder.Visibility, |
| 104 | thread_local: Builder.ThreadLocal, |
| 105 | unnamed_addr: Builder.UnnamedAddr, |
| 106 | externally_initialized: Builder.ExternallyInitialized, |
| 107 | dllstorageclass: Builder.DllStorageClass, |
| 108 | preemption: Builder.Preemption, |
| 109 | }; |
| 110 | |
| 111 | pub const Function = struct { |
| 112 | pub const ops = [_]AbbrevOp{ |
| 113 | .{ .literal = 8 }, // Code |
| 114 | .{ .vbr = 16 }, // strtab_offset |
| 115 | .{ .vbr = 16 }, // strtab_size |
| 116 | .{ .fixed_runtime = Builder.Type }, |
| 117 | .{ .fixed = @bitSizeOf(Builder.CallConv) }, |
| 118 | .{ .fixed = 1 }, // isproto |
| 119 | .{ .fixed = @bitSizeOf(Builder.Linkage) }, |
| 120 | .{ .vbr = 16 }, // paramattr |
| 121 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 122 | .{ .vbr = 16 }, // section |
| 123 | .{ .fixed = @bitSizeOf(Builder.Visibility) }, |
| 124 | .{ .literal = 0 }, // gc |
| 125 | .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) }, |
| 126 | .{ .literal = 0 }, // prologuedata |
| 127 | .{ .fixed = @bitSizeOf(Builder.DllStorageClass) }, |
| 128 | .{ .literal = 0 }, // comdat |
| 129 | .{ .literal = 0 }, // prefixdata |
| 130 | .{ .literal = 0 }, // personalityfn |
| 131 | .{ .fixed = @bitSizeOf(Builder.Preemption) }, |
| 132 | .{ .fixed = @bitSizeOf(Builder.AddrSpace) }, |
| 133 | }; |
| 134 | strtab_offset: usize, |
| 135 | strtab_size: usize, |
| 136 | type_index: Builder.Type, |
| 137 | call_conv: Builder.CallConv, |
| 138 | is_proto: bool, |
| 139 | linkage: Builder.Linkage, |
| 140 | paramattr: usize, |
| 141 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 142 | section: usize, |
| 143 | visibility: Builder.Visibility, |
| 144 | unnamed_addr: Builder.UnnamedAddr, |
| 145 | dllstorageclass: Builder.DllStorageClass, |
| 146 | preemption: Builder.Preemption, |
| 147 | addr_space: Builder.AddrSpace, |
| 148 | }; |
| 149 | |
| 150 | pub const Alias = struct { |
| 151 | pub const ops = [_]AbbrevOp{ |
| 152 | .{ .literal = 9 }, // Code |
| 153 | .{ .vbr = 16 }, // strtab_offset |
| 154 | .{ .vbr = 16 }, // strtab_size |
| 155 | .{ .fixed_runtime = Builder.Type }, |
| 156 | .{ .fixed = @bitSizeOf(Builder.AddrSpace) }, |
| 157 | ConstantAbbrev, // aliasee val |
| 158 | .{ .fixed = @bitSizeOf(Builder.Linkage) }, |
| 159 | .{ .fixed = @bitSizeOf(Builder.Visibility) }, |
| 160 | .{ .fixed = @bitSizeOf(Builder.DllStorageClass) }, |
| 161 | .{ .fixed = @bitSizeOf(Builder.ThreadLocal) }, |
| 162 | .{ .fixed = @bitSizeOf(Builder.UnnamedAddr) }, |
| 163 | .{ .fixed = @bitSizeOf(Builder.Preemption) }, |
| 164 | }; |
| 165 | strtab_offset: usize, |
| 166 | strtab_size: usize, |
| 167 | type_index: Builder.Type, |
| 168 | addr_space: Builder.AddrSpace, |
| 169 | aliasee: u32, |
| 170 | linkage: Builder.Linkage, |
| 171 | visibility: Builder.Visibility, |
| 172 | dllstorageclass: Builder.DllStorageClass, |
| 173 | thread_local: Builder.ThreadLocal, |
| 174 | unnamed_addr: Builder.UnnamedAddr, |
| 175 | preemption: Builder.Preemption, |
| 176 | }; |
| 177 | }; |
| 178 | |
| 179 | pub const Type = struct { |
| 180 | pub const id = 17; |
| 181 | |
| 182 | pub const abbrevs = [_]type{ |
| 183 | NumEntry, |
| 184 | Simple, |
| 185 | Integer, |
| 186 | StructAnon, |
| 187 | StructNamed, |
| 188 | StructName, |
| 189 | Array, |
| 190 | Vector, |
| 191 | Pointer, |
| 192 | Target, |
| 193 | Function, |
| 194 | }; |
| 195 | |
| 196 | pub const NumEntry = struct { |
| 197 | pub const ops = [_]AbbrevOp{ |
| 198 | .{ .literal = 1 }, |
| 199 | .{ .fixed = 32 }, |
| 200 | }; |
| 201 | num: u32, |
| 202 | }; |
| 203 | |
| 204 | pub const Simple = struct { |
| 205 | pub const ops = [_]AbbrevOp{ |
| 206 | .{ .vbr = 4 }, |
| 207 | }; |
| 208 | code: u5, |
| 209 | }; |
| 210 | |
| 211 | pub const Integer = struct { |
| 212 | pub const ops = [_]AbbrevOp{ |
| 213 | .{ .literal = 7 }, |
| 214 | .{ .fixed = 28 }, |
| 215 | }; |
| 216 | width: u28, |
| 217 | }; |
| 218 | |
| 219 | pub const StructAnon = struct { |
| 220 | pub const ops = [_]AbbrevOp{ |
| 221 | .{ .literal = 18 }, |
| 222 | .{ .fixed = 1 }, |
| 223 | .{ .array_fixed_runtime = Builder.Type }, |
| 224 | }; |
| 225 | is_packed: bool, |
| 226 | types: []const Builder.Type, |
| 227 | }; |
| 228 | |
| 229 | pub const StructNamed = struct { |
| 230 | pub const ops = [_]AbbrevOp{ |
| 231 | .{ .literal = 20 }, |
| 232 | .{ .fixed = 1 }, |
| 233 | .{ .array_fixed_runtime = Builder.Type }, |
| 234 | }; |
| 235 | is_packed: bool, |
| 236 | types: []const Builder.Type, |
| 237 | }; |
| 238 | |
| 239 | pub const StructName = struct { |
| 240 | pub const ops = [_]AbbrevOp{ |
| 241 | .{ .literal = 19 }, |
| 242 | .{ .array_fixed = 8 }, |
| 243 | }; |
| 244 | string: []const u8, |
| 245 | }; |
| 246 | |
| 247 | pub const Array = struct { |
| 248 | pub const ops = [_]AbbrevOp{ |
| 249 | .{ .literal = 11 }, |
| 250 | .{ .vbr = 16 }, |
| 251 | .{ .fixed_runtime = Builder.Type }, |
| 252 | }; |
| 253 | len: u64, |
| 254 | child: Builder.Type, |
| 255 | }; |
| 256 | |
| 257 | pub const Vector = struct { |
| 258 | pub const ops = [_]AbbrevOp{ |
| 259 | .{ .literal = 12 }, |
| 260 | .{ .vbr = 16 }, |
| 261 | .{ .fixed_runtime = Builder.Type }, |
| 262 | }; |
| 263 | len: u64, |
| 264 | child: Builder.Type, |
| 265 | }; |
| 266 | |
| 267 | pub const Pointer = struct { |
| 268 | pub const ops = [_]AbbrevOp{ |
| 269 | .{ .literal = 25 }, |
| 270 | .{ .vbr = 4 }, |
| 271 | }; |
| 272 | addr_space: Builder.AddrSpace, |
| 273 | }; |
| 274 | |
| 275 | pub const Target = struct { |
| 276 | pub const ops = [_]AbbrevOp{ |
| 277 | .{ .literal = 26 }, |
| 278 | .{ .vbr = 4 }, |
| 279 | .{ .array_fixed_runtime = Builder.Type }, |
| 280 | .{ .array_fixed = 32 }, |
| 281 | }; |
| 282 | num_types: u32, |
| 283 | types: []const Builder.Type, |
| 284 | ints: []const u32, |
| 285 | }; |
| 286 | |
| 287 | pub const Function = struct { |
| 288 | pub const ops = [_]AbbrevOp{ |
| 289 | .{ .literal = 21 }, |
| 290 | .{ .fixed = 1 }, |
| 291 | .{ .fixed_runtime = Builder.Type }, |
| 292 | .{ .array_fixed_runtime = Builder.Type }, |
| 293 | }; |
| 294 | is_vararg: bool, |
| 295 | return_type: Builder.Type, |
| 296 | param_types: []const Builder.Type, |
| 297 | }; |
| 298 | }; |
| 299 | |
| 300 | pub const Paramattr = struct { |
| 301 | pub const id = 9; |
| 302 | |
| 303 | pub const abbrevs = [_]type{ |
| 304 | Entry, |
| 305 | }; |
| 306 | |
| 307 | pub const Entry = struct { |
| 308 | pub const ops = [_]AbbrevOp{ |
| 309 | .{ .literal = 2 }, |
| 310 | .{ .array_vbr = 8 }, |
| 311 | }; |
| 312 | group_indices: []const u64, |
| 313 | }; |
| 314 | }; |
| 315 | |
| 316 | pub const ParamattrGroup = struct { |
| 317 | pub const id = 10; |
| 318 | |
| 319 | pub const abbrevs = [_]type{}; |
| 320 | }; |
| 321 | |
| 322 | pub const Constants = struct { |
| 323 | pub const id = 11; |
| 324 | |
| 325 | pub const abbrevs = [_]type{ |
| 326 | SetType, |
| 327 | Null, |
| 328 | Undef, |
| 329 | Poison, |
| 330 | Integer, |
| 331 | Half, |
| 332 | Float, |
| 333 | Double, |
| 334 | Fp80, |
| 335 | Fp128, |
| 336 | Aggregate, |
| 337 | String, |
| 338 | CString, |
| 339 | Cast, |
| 340 | Binary, |
| 341 | Cmp, |
| 342 | ExtractElement, |
| 343 | InsertElement, |
| 344 | ShuffleVector, |
| 345 | ShuffleVectorEx, |
| 346 | BlockAddress, |
| 347 | DsoLocalEquivalentOrNoCfi, |
| 348 | }; |
| 349 | |
| 350 | pub const SetType = struct { |
| 351 | pub const ops = [_]AbbrevOp{ |
| 352 | .{ .literal = 1 }, |
| 353 | .{ .fixed_runtime = Builder.Type }, |
| 354 | }; |
| 355 | type_id: Builder.Type, |
| 356 | }; |
| 357 | |
| 358 | pub const Null = struct { |
| 359 | pub const ops = [_]AbbrevOp{ |
| 360 | .{ .literal = 2 }, |
| 361 | }; |
| 362 | }; |
| 363 | |
| 364 | pub const Undef = struct { |
| 365 | pub const ops = [_]AbbrevOp{ |
| 366 | .{ .literal = 3 }, |
| 367 | }; |
| 368 | }; |
| 369 | |
| 370 | pub const Poison = struct { |
| 371 | pub const ops = [_]AbbrevOp{ |
| 372 | .{ .literal = 26 }, |
| 373 | }; |
| 374 | }; |
| 375 | |
| 376 | pub const Integer = struct { |
| 377 | pub const ops = [_]AbbrevOp{ |
| 378 | .{ .literal = 4 }, |
| 379 | .{ .vbr = 16 }, |
| 380 | }; |
| 381 | value: std.math.big.Limb, |
| 382 | }; |
| 383 | |
| 384 | pub const Half = struct { |
| 385 | pub const ops = [_]AbbrevOp{ |
| 386 | .{ .literal = 6 }, |
| 387 | .{ .fixed = 16 }, |
| 388 | }; |
| 389 | value: u16, |
| 390 | }; |
| 391 | |
| 392 | pub const Float = struct { |
| 393 | pub const ops = [_]AbbrevOp{ |
| 394 | .{ .literal = 6 }, |
| 395 | .{ .fixed = 32 }, |
| 396 | }; |
| 397 | value: u32, |
| 398 | }; |
| 399 | |
| 400 | pub const Double = struct { |
| 401 | pub const ops = [_]AbbrevOp{ |
| 402 | .{ .literal = 6 }, |
| 403 | .{ .vbr = 6 }, |
| 404 | }; |
| 405 | value: u64, |
| 406 | }; |
| 407 | |
| 408 | pub const Fp80 = struct { |
| 409 | pub const ops = [_]AbbrevOp{ |
| 410 | .{ .literal = 6 }, |
| 411 | .{ .vbr = 6 }, |
| 412 | .{ .vbr = 6 }, |
| 413 | }; |
| 414 | lo: u64, |
| 415 | hi: u16, |
| 416 | }; |
| 417 | |
| 418 | pub const Fp128 = struct { |
| 419 | pub const ops = [_]AbbrevOp{ |
| 420 | .{ .literal = 6 }, |
| 421 | .{ .vbr = 6 }, |
| 422 | .{ .vbr = 6 }, |
| 423 | }; |
| 424 | lo: u64, |
| 425 | hi: u64, |
| 426 | }; |
| 427 | |
| 428 | pub const Aggregate = struct { |
| 429 | pub const ops = [_]AbbrevOp{ |
| 430 | .{ .literal = 7 }, |
| 431 | .{ .array_fixed = 32 }, |
| 432 | }; |
| 433 | values: []const Builder.Constant, |
| 434 | }; |
| 435 | |
| 436 | pub const String = struct { |
| 437 | pub const ops = [_]AbbrevOp{ |
| 438 | .{ .literal = 8 }, |
| 439 | .{ .array_fixed = 8 }, |
| 440 | }; |
| 441 | string: []const u8, |
| 442 | }; |
| 443 | |
| 444 | pub const CString = struct { |
| 445 | pub const ops = [_]AbbrevOp{ |
| 446 | .{ .literal = 9 }, |
| 447 | .{ .array_fixed = 8 }, |
| 448 | }; |
| 449 | string: []const u8, |
| 450 | }; |
| 451 | |
| 452 | pub const Cast = struct { |
| 453 | const CastOpcode = Builder.CastOpcode; |
| 454 | pub const ops = [_]AbbrevOp{ |
| 455 | .{ .literal = 11 }, |
| 456 | .{ .fixed = @bitSizeOf(CastOpcode) }, |
| 457 | .{ .fixed_runtime = Builder.Type }, |
| 458 | ConstantAbbrev, |
| 459 | }; |
| 460 | |
| 461 | opcode: CastOpcode, |
| 462 | type_index: Builder.Type, |
| 463 | val: Builder.Constant, |
| 464 | }; |
| 465 | |
| 466 | pub const Binary = struct { |
| 467 | const BinaryOpcode = Builder.BinaryOpcode; |
| 468 | pub const ops = [_]AbbrevOp{ |
| 469 | .{ .literal = 10 }, |
| 470 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, |
| 471 | ConstantAbbrev, |
| 472 | ConstantAbbrev, |
| 473 | }; |
| 474 | |
| 475 | opcode: BinaryOpcode, |
| 476 | lhs: Builder.Constant, |
| 477 | rhs: Builder.Constant, |
| 478 | }; |
| 479 | |
| 480 | pub const Cmp = struct { |
| 481 | pub const ops = [_]AbbrevOp{ |
| 482 | .{ .literal = 17 }, |
| 483 | .{ .fixed_runtime = Builder.Type }, |
| 484 | ConstantAbbrev, |
| 485 | ConstantAbbrev, |
| 486 | .{ .vbr = 6 }, |
| 487 | }; |
| 488 | |
| 489 | ty: Builder.Type, |
| 490 | lhs: Builder.Constant, |
| 491 | rhs: Builder.Constant, |
| 492 | pred: u32, |
| 493 | }; |
| 494 | |
| 495 | pub const ExtractElement = struct { |
| 496 | pub const ops = [_]AbbrevOp{ |
| 497 | .{ .literal = 14 }, |
| 498 | .{ .fixed_runtime = Builder.Type }, |
| 499 | ConstantAbbrev, |
| 500 | .{ .fixed_runtime = Builder.Type }, |
| 501 | ConstantAbbrev, |
| 502 | }; |
| 503 | |
| 504 | val_type: Builder.Type, |
| 505 | val: Builder.Constant, |
| 506 | index_type: Builder.Type, |
| 507 | index: Builder.Constant, |
| 508 | }; |
| 509 | |
| 510 | pub const InsertElement = struct { |
| 511 | pub const ops = [_]AbbrevOp{ |
| 512 | .{ .literal = 15 }, |
| 513 | ConstantAbbrev, |
| 514 | ConstantAbbrev, |
| 515 | .{ .fixed_runtime = Builder.Type }, |
| 516 | ConstantAbbrev, |
| 517 | }; |
| 518 | |
| 519 | val: Builder.Constant, |
| 520 | elem: Builder.Constant, |
| 521 | index_type: Builder.Type, |
| 522 | index: Builder.Constant, |
| 523 | }; |
| 524 | |
| 525 | pub const ShuffleVector = struct { |
| 526 | pub const ops = [_]AbbrevOp{ |
| 527 | .{ .literal = 16 }, |
| 528 | ValueAbbrev, |
| 529 | ValueAbbrev, |
| 530 | ValueAbbrev, |
| 531 | }; |
| 532 | |
| 533 | lhs: Builder.Constant, |
| 534 | rhs: Builder.Constant, |
| 535 | mask: Builder.Constant, |
| 536 | }; |
| 537 | |
| 538 | pub const ShuffleVectorEx = struct { |
| 539 | pub const ops = [_]AbbrevOp{ |
| 540 | .{ .literal = 19 }, |
| 541 | .{ .fixed_runtime = Builder.Type }, |
| 542 | ValueAbbrev, |
| 543 | ValueAbbrev, |
| 544 | ValueAbbrev, |
| 545 | }; |
| 546 | |
| 547 | ty: Builder.Type, |
| 548 | lhs: Builder.Constant, |
| 549 | rhs: Builder.Constant, |
| 550 | mask: Builder.Constant, |
| 551 | }; |
| 552 | |
| 553 | pub const BlockAddress = struct { |
| 554 | pub const ops = [_]AbbrevOp{ |
| 555 | .{ .literal = 21 }, |
| 556 | .{ .fixed_runtime = Builder.Type }, |
| 557 | ConstantAbbrev, |
| 558 | BlockAbbrev, |
| 559 | }; |
| 560 | type_id: Builder.Type, |
| 561 | function: u32, |
| 562 | block: u32, |
| 563 | }; |
| 564 | |
| 565 | pub const DsoLocalEquivalentOrNoCfi = struct { |
| 566 | pub const ops = [_]AbbrevOp{ |
| 567 | .{ .fixed = 5 }, |
| 568 | .{ .fixed_runtime = Builder.Type }, |
| 569 | ConstantAbbrev, |
| 570 | }; |
| 571 | code: u5, |
| 572 | type_id: Builder.Type, |
| 573 | function: u32, |
| 574 | }; |
| 575 | }; |
| 576 | |
| 577 | pub const FunctionBlock = struct { |
| 578 | pub const id = 12; |
| 579 | |
| 580 | pub const abbrevs = [_]type{ |
| 581 | DeclareBlocks, |
| 582 | Call, |
| 583 | CallFast, |
| 584 | FNeg, |
| 585 | FNegFast, |
| 586 | Binary, |
| 587 | BinaryFast, |
| 588 | Cmp, |
| 589 | CmpFast, |
| 590 | Select, |
| 591 | SelectFast, |
| 592 | Cast, |
| 593 | Alloca, |
| 594 | GetElementPtr, |
| 595 | ExtractValue, |
| 596 | InsertValue, |
| 597 | ExtractElement, |
| 598 | InsertElement, |
| 599 | ShuffleVector, |
| 600 | RetVoid, |
| 601 | Ret, |
| 602 | Unreachable, |
| 603 | Load, |
| 604 | LoadAtomic, |
| 605 | Store, |
| 606 | StoreAtomic, |
| 607 | BrUnconditional, |
| 608 | BrConditional, |
| 609 | VaArg, |
| 610 | AtomicRmw, |
| 611 | CmpXchg, |
| 612 | Fence, |
| 613 | }; |
| 614 | |
| 615 | pub const DeclareBlocks = struct { |
| 616 | pub const ops = [_]AbbrevOp{ |
| 617 | .{ .literal = 1 }, |
| 618 | .{ .vbr = 8 }, |
| 619 | }; |
| 620 | num_blocks: usize, |
| 621 | }; |
| 622 | |
| 623 | pub const Call = struct { |
| 624 | pub const CallType = packed struct(u17) { |
| 625 | tail: bool = false, |
| 626 | call_conv: Builder.CallConv, |
| 627 | reserved: u3 = 0, |
| 628 | must_tail: bool = false, |
| 629 | // We always use the explicit type version as that is what LLVM does |
| 630 | explicit_type: bool = true, |
| 631 | no_tail: bool = false, |
| 632 | }; |
| 633 | pub const ops = [_]AbbrevOp{ |
| 634 | .{ .literal = 34 }, |
| 635 | .{ .fixed_runtime = Builder.FunctionAttributes }, |
| 636 | .{ .fixed = @bitSizeOf(CallType) }, |
| 637 | .{ .fixed_runtime = Builder.Type }, |
| 638 | ValueAbbrev, // Callee |
| 639 | ValueArrayAbbrev, // Args |
| 640 | }; |
| 641 | |
| 642 | attributes: Builder.FunctionAttributes, |
| 643 | call_type: CallType, |
| 644 | type_id: Builder.Type, |
| 645 | callee: Builder.Value, |
| 646 | args: []const Builder.Value, |
| 647 | }; |
| 648 | |
| 649 | pub const CallFast = struct { |
| 650 | const CallType = packed struct(u18) { |
| 651 | tail: bool = false, |
| 652 | call_conv: Builder.CallConv, |
| 653 | reserved: u3 = 0, |
| 654 | must_tail: bool = false, |
| 655 | // We always use the explicit type version as that is what LLVM does |
| 656 | explicit_type: bool = true, |
| 657 | no_tail: bool = false, |
| 658 | fast: bool = true, |
| 659 | }; |
| 660 | |
| 661 | pub const ops = [_]AbbrevOp{ |
| 662 | .{ .literal = 34 }, |
| 663 | .{ .fixed_runtime = Builder.FunctionAttributes }, |
| 664 | .{ .fixed = @bitSizeOf(CallType) }, |
| 665 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, |
| 666 | .{ .fixed_runtime = Builder.Type }, |
| 667 | ValueAbbrev, // Callee |
| 668 | ValueArrayAbbrev, // Args |
| 669 | }; |
| 670 | |
| 671 | attributes: Builder.FunctionAttributes, |
| 672 | call_type: CallType, |
| 673 | fast_math: Builder.FastMath, |
| 674 | type_id: Builder.Type, |
| 675 | callee: Builder.Value, |
| 676 | args: []const Builder.Value, |
| 677 | }; |
| 678 | |
| 679 | pub const FNeg = struct { |
| 680 | pub const ops = [_]AbbrevOp{ |
| 681 | .{ .literal = 56 }, |
| 682 | ValueAbbrev, |
| 683 | .{ .literal = 0 }, |
| 684 | }; |
| 685 | |
| 686 | val: u32, |
| 687 | }; |
| 688 | |
| 689 | pub const FNegFast = struct { |
| 690 | pub const ops = [_]AbbrevOp{ |
| 691 | .{ .literal = 56 }, |
| 692 | ValueAbbrev, |
| 693 | .{ .literal = 0 }, |
| 694 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, |
| 695 | }; |
| 696 | |
| 697 | val: u32, |
| 698 | fast_math: Builder.FastMath, |
| 699 | }; |
| 700 | |
| 701 | pub const Binary = struct { |
| 702 | const BinaryOpcode = Builder.BinaryOpcode; |
| 703 | pub const ops = [_]AbbrevOp{ |
| 704 | .{ .literal = 2 }, |
| 705 | ValueAbbrev, |
| 706 | ValueAbbrev, |
| 707 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, |
| 708 | }; |
| 709 | |
| 710 | lhs: u32, |
| 711 | rhs: u32, |
| 712 | opcode: BinaryOpcode, |
| 713 | }; |
| 714 | |
| 715 | pub const BinaryFast = struct { |
| 716 | const BinaryOpcode = Builder.BinaryOpcode; |
| 717 | pub const ops = [_]AbbrevOp{ |
| 718 | .{ .literal = 2 }, |
| 719 | ValueAbbrev, |
| 720 | ValueAbbrev, |
| 721 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, |
| 722 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, |
| 723 | }; |
| 724 | |
| 725 | lhs: u32, |
| 726 | rhs: u32, |
| 727 | opcode: BinaryOpcode, |
| 728 | fast_math: Builder.FastMath, |
| 729 | }; |
| 730 | |
| 731 | pub const Cmp = struct { |
| 732 | const CmpPredicate = Builder.CmpPredicate; |
| 733 | pub const ops = [_]AbbrevOp{ |
| 734 | .{ .literal = 28 }, |
| 735 | ValueAbbrev, |
| 736 | ValueAbbrev, |
| 737 | .{ .fixed = @bitSizeOf(CmpPredicate) }, |
| 738 | }; |
| 739 | |
| 740 | lhs: u32, |
| 741 | rhs: u32, |
| 742 | pred: CmpPredicate, |
| 743 | }; |
| 744 | |
| 745 | pub const CmpFast = struct { |
| 746 | const CmpPredicate = Builder.CmpPredicate; |
| 747 | pub const ops = [_]AbbrevOp{ |
| 748 | .{ .literal = 28 }, |
| 749 | ValueAbbrev, |
| 750 | ValueAbbrev, |
| 751 | .{ .fixed = @bitSizeOf(CmpPredicate) }, |
| 752 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, |
| 753 | }; |
| 754 | |
| 755 | lhs: u32, |
| 756 | rhs: u32, |
| 757 | pred: CmpPredicate, |
| 758 | fast_math: Builder.FastMath, |
| 759 | }; |
| 760 | |
| 761 | pub const Select = struct { |
| 762 | pub const ops = [_]AbbrevOp{ |
| 763 | .{ .literal = 29 }, |
| 764 | ValueAbbrev, |
| 765 | ValueAbbrev, |
| 766 | ValueAbbrev, |
| 767 | }; |
| 768 | |
| 769 | lhs: u32, |
| 770 | rhs: u32, |
| 771 | cond: u32, |
| 772 | }; |
| 773 | |
| 774 | pub const SelectFast = struct { |
| 775 | pub const ops = [_]AbbrevOp{ |
| 776 | .{ .literal = 29 }, |
| 777 | ValueAbbrev, |
| 778 | ValueAbbrev, |
| 779 | ValueAbbrev, |
| 780 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, |
| 781 | }; |
| 782 | |
| 783 | lhs: u32, |
| 784 | rhs: u32, |
| 785 | cond: u32, |
| 786 | fast_math: Builder.FastMath, |
| 787 | }; |
| 788 | |
| 789 | pub const Cast = struct { |
| 790 | const CastOpcode = Builder.CastOpcode; |
| 791 | pub const ops = [_]AbbrevOp{ |
| 792 | .{ .literal = 3 }, |
| 793 | ValueAbbrev, |
| 794 | .{ .fixed_runtime = Builder.Type }, |
| 795 | .{ .fixed = @bitSizeOf(CastOpcode) }, |
| 796 | }; |
| 797 | |
| 798 | val: u32, |
| 799 | type_index: Builder.Type, |
| 800 | opcode: CastOpcode, |
| 801 | }; |
| 802 | |
| 803 | pub const Alloca = struct { |
| 804 | pub const Flags = packed struct(u11) { |
| 805 | align_lower: u5, |
| 806 | inalloca: bool, |
| 807 | explicit_type: bool, |
| 808 | swift_error: bool, |
| 809 | align_upper: u3, |
| 810 | }; |
| 811 | pub const ops = [_]AbbrevOp{ |
| 812 | .{ .literal = 19 }, |
| 813 | .{ .fixed_runtime = Builder.Type }, |
| 814 | .{ .fixed_runtime = Builder.Type }, |
| 815 | ValueAbbrev, |
| 816 | .{ .fixed = @bitSizeOf(Flags) }, |
| 817 | }; |
| 818 | |
| 819 | inst_type: Builder.Type, |
| 820 | len_type: Builder.Type, |
| 821 | len_value: u32, |
| 822 | flags: Flags, |
| 823 | }; |
| 824 | |
| 825 | pub const RetVoid = struct { |
| 826 | pub const ops = [_]AbbrevOp{ |
| 827 | .{ .literal = 10 }, |
| 828 | }; |
| 829 | }; |
| 830 | |
| 831 | pub const Ret = struct { |
| 832 | pub const ops = [_]AbbrevOp{ |
| 833 | .{ .literal = 10 }, |
| 834 | ValueAbbrev, |
| 835 | }; |
| 836 | val: u32, |
| 837 | }; |
| 838 | |
| 839 | pub const GetElementPtr = struct { |
| 840 | pub const ops = [_]AbbrevOp{ |
| 841 | .{ .literal = 43 }, |
| 842 | .{ .fixed = 1 }, |
| 843 | .{ .fixed_runtime = Builder.Type }, |
| 844 | ValueAbbrev, |
| 845 | ValueArrayAbbrev, |
| 846 | }; |
| 847 | |
| 848 | is_inbounds: bool, |
| 849 | type_index: Builder.Type, |
| 850 | base: Builder.Value, |
| 851 | indices: []const Builder.Value, |
| 852 | }; |
| 853 | |
| 854 | pub const ExtractValue = struct { |
| 855 | pub const ops = [_]AbbrevOp{ |
| 856 | .{ .literal = 26 }, |
| 857 | ValueAbbrev, |
| 858 | ValueArrayAbbrev, |
| 859 | }; |
| 860 | |
| 861 | val: u32, |
| 862 | indices: []const u32, |
| 863 | }; |
| 864 | |
| 865 | pub const InsertValue = struct { |
| 866 | pub const ops = [_]AbbrevOp{ |
| 867 | .{ .literal = 27 }, |
| 868 | ValueAbbrev, |
| 869 | ValueAbbrev, |
| 870 | ValueArrayAbbrev, |
| 871 | }; |
| 872 | |
| 873 | val: u32, |
| 874 | elem: u32, |
| 875 | indices: []const u32, |
| 876 | }; |
| 877 | |
| 878 | pub const ExtractElement = struct { |
| 879 | pub const ops = [_]AbbrevOp{ |
| 880 | .{ .literal = 6 }, |
| 881 | ValueAbbrev, |
| 882 | ValueAbbrev, |
| 883 | }; |
| 884 | |
| 885 | val: u32, |
| 886 | index: u32, |
| 887 | }; |
| 888 | |
| 889 | pub const InsertElement = struct { |
| 890 | pub const ops = [_]AbbrevOp{ |
| 891 | .{ .literal = 7 }, |
| 892 | ValueAbbrev, |
| 893 | ValueAbbrev, |
| 894 | ValueAbbrev, |
| 895 | }; |
| 896 | |
| 897 | val: u32, |
| 898 | elem: u32, |
| 899 | index: u32, |
| 900 | }; |
| 901 | |
| 902 | pub const ShuffleVector = struct { |
| 903 | pub const ops = [_]AbbrevOp{ |
| 904 | .{ .literal = 8 }, |
| 905 | ValueAbbrev, |
| 906 | ValueAbbrev, |
| 907 | ValueAbbrev, |
| 908 | }; |
| 909 | |
| 910 | lhs: u32, |
| 911 | rhs: u32, |
| 912 | mask: u32, |
| 913 | }; |
| 914 | |
| 915 | pub const Unreachable = struct { |
| 916 | pub const ops = [_]AbbrevOp{ |
| 917 | .{ .literal = 15 }, |
| 918 | }; |
| 919 | }; |
| 920 | |
| 921 | pub const Load = struct { |
| 922 | pub const ops = [_]AbbrevOp{ |
| 923 | .{ .literal = 20 }, |
| 924 | ValueAbbrev, |
| 925 | .{ .fixed_runtime = Builder.Type }, |
| 926 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 927 | .{ .fixed = 1 }, |
| 928 | }; |
| 929 | ptr: u32, |
| 930 | ty: Builder.Type, |
| 931 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 932 | is_volatile: bool, |
| 933 | }; |
| 934 | |
| 935 | pub const LoadAtomic = struct { |
| 936 | pub const ops = [_]AbbrevOp{ |
| 937 | .{ .literal = 41 }, |
| 938 | ValueAbbrev, |
| 939 | .{ .fixed_runtime = Builder.Type }, |
| 940 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 941 | .{ .fixed = 1 }, |
| 942 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, |
| 943 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, |
| 944 | }; |
| 945 | ptr: u32, |
| 946 | ty: Builder.Type, |
| 947 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 948 | is_volatile: bool, |
| 949 | success_ordering: Builder.AtomicOrdering, |
| 950 | sync_scope: Builder.SyncScope, |
| 951 | }; |
| 952 | |
| 953 | pub const Store = struct { |
| 954 | pub const ops = [_]AbbrevOp{ |
| 955 | .{ .literal = 44 }, |
| 956 | ValueAbbrev, |
| 957 | ValueAbbrev, |
| 958 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 959 | .{ .fixed = 1 }, |
| 960 | }; |
| 961 | ptr: u32, |
| 962 | val: u32, |
| 963 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 964 | is_volatile: bool, |
| 965 | }; |
| 966 | |
| 967 | pub const StoreAtomic = struct { |
| 968 | pub const ops = [_]AbbrevOp{ |
| 969 | .{ .literal = 45 }, |
| 970 | ValueAbbrev, |
| 971 | ValueAbbrev, |
| 972 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 973 | .{ .fixed = 1 }, |
| 974 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, |
| 975 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, |
| 976 | }; |
| 977 | ptr: u32, |
| 978 | val: u32, |
| 979 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 980 | is_volatile: bool, |
| 981 | success_ordering: Builder.AtomicOrdering, |
| 982 | sync_scope: Builder.SyncScope, |
| 983 | }; |
| 984 | |
| 985 | pub const BrUnconditional = struct { |
| 986 | pub const ops = [_]AbbrevOp{ |
| 987 | .{ .literal = 11 }, |
| 988 | BlockAbbrev, |
| 989 | }; |
| 990 | block: u32, |
| 991 | }; |
| 992 | |
| 993 | pub const BrConditional = struct { |
| 994 | pub const ops = [_]AbbrevOp{ |
| 995 | .{ .literal = 11 }, |
| 996 | BlockAbbrev, |
| 997 | BlockAbbrev, |
| 998 | BlockAbbrev, |
| 999 | }; |
| 1000 | then_block: u32, |
| 1001 | else_block: u32, |
| 1002 | condition: u32, |
| 1003 | }; |
| 1004 | |
| 1005 | pub const VaArg = struct { |
| 1006 | pub const ops = [_]AbbrevOp{ |
| 1007 | .{ .literal = 23 }, |
| 1008 | .{ .fixed_runtime = Builder.Type }, |
| 1009 | ValueAbbrev, |
| 1010 | .{ .fixed_runtime = Builder.Type }, |
| 1011 | }; |
| 1012 | list_type: Builder.Type, |
| 1013 | list: u32, |
| 1014 | type: Builder.Type, |
| 1015 | }; |
| 1016 | |
| 1017 | pub const AtomicRmw = struct { |
| 1018 | pub const ops = [_]AbbrevOp{ |
| 1019 | .{ .literal = 59 }, |
| 1020 | ValueAbbrev, |
| 1021 | ValueAbbrev, |
| 1022 | .{ .fixed = @bitSizeOf(Builder.Function.Instruction.AtomicRmw.Operation) }, |
| 1023 | .{ .fixed = 1 }, |
| 1024 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, |
| 1025 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, |
| 1026 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 1027 | }; |
| 1028 | ptr: u32, |
| 1029 | val: u32, |
| 1030 | operation: Builder.Function.Instruction.AtomicRmw.Operation, |
| 1031 | is_volatile: bool, |
| 1032 | success_ordering: Builder.AtomicOrdering, |
| 1033 | sync_scope: Builder.SyncScope, |
| 1034 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 1035 | }; |
| 1036 | |
| 1037 | pub const CmpXchg = struct { |
| 1038 | pub const ops = [_]AbbrevOp{ |
| 1039 | .{ .literal = 46 }, |
| 1040 | ValueAbbrev, |
| 1041 | ValueAbbrev, |
| 1042 | ValueAbbrev, |
| 1043 | .{ .fixed = 1 }, |
| 1044 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, |
| 1045 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, |
| 1046 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, |
| 1047 | .{ .fixed = 1 }, |
| 1048 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, |
| 1049 | }; |
| 1050 | ptr: u32, |
| 1051 | cmp: u32, |
| 1052 | new: u32, |
| 1053 | is_volatile: bool, |
| 1054 | success_ordering: Builder.AtomicOrdering, |
| 1055 | sync_scope: Builder.SyncScope, |
| 1056 | failure_ordering: Builder.AtomicOrdering, |
| 1057 | is_weak: bool, |
| 1058 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), |
| 1059 | }; |
| 1060 | |
| 1061 | pub const Fence = struct { |
| 1062 | pub const ops = [_]AbbrevOp{ |
| 1063 | .{ .literal = 36 }, |
| 1064 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, |
| 1065 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, |
| 1066 | }; |
| 1067 | ordering: Builder.AtomicOrdering, |
| 1068 | sync_scope: Builder.SyncScope, |
| 1069 | }; |
| 1070 | }; |
| 1071 | |
| 1072 | pub const FunctionValueSymbolTable = struct { |
| 1073 | pub const id = 14; |
| 1074 | |
| 1075 | pub const abbrevs = [_]type{ |
| 1076 | BlockEntry, |
| 1077 | }; |
| 1078 | |
| 1079 | pub const BlockEntry = struct { |
| 1080 | pub const ops = [_]AbbrevOp{ |
| 1081 | .{ .literal = 2 }, |
| 1082 | ValueAbbrev, |
| 1083 | .{ .array_fixed = 8 }, |
| 1084 | }; |
| 1085 | value_id: u32, |
| 1086 | string: []const u8, |
| 1087 | }; |
| 1088 | }; |
| 1089 | |
| 1090 | pub const Strtab = struct { |
| 1091 | pub const id = 23; |
| 1092 | |
| 1093 | pub const abbrevs = [_]type{Blob}; |
| 1094 | |
| 1095 | pub const Blob = struct { |
| 1096 | pub const ops = [_]AbbrevOp{ |
| 1097 | .{ .literal = 1 }, |
| 1098 | .blob, |
| 1099 | }; |
| 1100 | blob: []const u8, |
| 1101 | }; |
| 1102 | }; |