authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-25 23:24:41-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-01-25 23:24:41-05:00
log4e9b1f5479e3b7ce47d059e0e6f3d62cd4ee7254
tree05564ca6ace71b9baf054099a0e79b473d47b9ff
parentaaa2f9ab2febf9e8be9bb284cd8d5e3f6c2c54f1
parent32f0039b436a4c30b1bffef28e2f5c00ad5974bb
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4290 from ziglang/split-ir-structs

split IrInstruction into IrInst, IrInstSrc, IrInstGen

9 files changed, 11124 insertions(+), 9106 deletions(-)

src/all_types.hpp+1380-908
......@@ -33,12 +33,15 @@ struct BuiltinFnEntry;
3333struct TypeStructField;
3434struct CodeGen;
3535struct ZigValue;
36struct IrInstruction;
37struct IrInstructionCast;
38struct IrInstructionAllocaGen;
39struct IrInstructionCallGen;
40struct IrInstructionAwaitGen;
41struct IrBasicBlock;
36struct IrInst;
37struct IrInstSrc;
38struct IrInstGen;
39struct IrInstGenCast;
40struct IrInstGenAlloca;
41struct IrInstGenCall;
42struct IrInstGenAwait;
43struct IrBasicBlockSrc;
44struct IrBasicBlockGen;
4245struct ScopeDecls;
4346struct ZigWindowsSDK;
4447struct Tld;
......@@ -50,6 +53,7 @@ struct ResultLocPeerParent;
5053struct ResultLocBitCast;
5154struct ResultLocCast;
5255struct ResultLocReturn;
56struct IrExecutableGen;
5357
5458enum PtrLen {
5559 PtrLenUnknown,
......@@ -97,8 +101,8 @@ enum X64CABIClass {
97101 X64CABIClass_SSE,
98102};
99103
100struct IrExecutable {
101 ZigList<IrBasicBlock *> basic_block_list;
104struct IrExecutableSrc {
105 ZigList<IrBasicBlockSrc *> basic_block_list;
102106 Buf *name;
103107 ZigFn *name_fn;
104108 size_t mem_slot_count;
......@@ -108,8 +112,7 @@ struct IrExecutable {
108112 ZigFn *fn_entry;
109113 Buf *c_import_buf;
110114 AstNode *source_node;
111 IrExecutable *parent_exec;
112 IrExecutable *source_exec;
115 IrExecutableGen *parent_exec;
113116 IrAnalyze *analysis;
114117 Scope *begin_scope;
115118 ErrorMsg *first_err_trace_msg;
......@@ -124,6 +127,32 @@ struct IrExecutable {
124127 void src();
125128};
126129
130struct IrExecutableGen {
131 ZigList<IrBasicBlockGen *> basic_block_list;
132 Buf *name;
133 ZigFn *name_fn;
134 size_t mem_slot_count;
135 size_t next_debug_id;
136 size_t *backward_branch_count;
137 size_t *backward_branch_quota;
138 ZigFn *fn_entry;
139 Buf *c_import_buf;
140 AstNode *source_node;
141 IrExecutableGen *parent_exec;
142 IrExecutableSrc *source_exec;
143 Scope *begin_scope;
144 ErrorMsg *first_err_trace_msg;
145 ZigList<Tld *> tld_list;
146
147 bool is_inline;
148 bool is_generic_instantiation;
149 bool need_err_code_spill;
150
151 // This is a function for use in the debugger to print
152 // the source location.
153 void src();
154};
155
127156enum OutType {
128157 OutTypeUnknown,
129158 OutTypeExe,
......@@ -287,7 +316,7 @@ struct ConstErrValue {
287316
288317struct ConstBoundFnValue {
289318 ZigFn *fn;
290 IrInstruction *first_arg;
319 IrInstGen *first_arg;
291320};
292321
293322struct ConstArgTuple {
......@@ -350,14 +379,14 @@ struct LazyValueAlignOf {
350379 LazyValue base;
351380
352381 IrAnalyze *ira;
353 IrInstruction *target_type;
382 IrInstGen *target_type;
354383};
355384
356385struct LazyValueSizeOf {
357386 LazyValue base;
358387
359388 IrAnalyze *ira;
360 IrInstruction *target_type;
389 IrInstGen *target_type;
361390
362391 bool bit_size;
363392};
......@@ -366,9 +395,9 @@ struct LazyValueSliceType {
366395 LazyValue base;
367396
368397 IrAnalyze *ira;
369 IrInstruction *sentinel; // can be null
370 IrInstruction *elem_type;
371 IrInstruction *align_inst; // can be null
398 IrInstGen *sentinel; // can be null
399 IrInstGen *elem_type;
400 IrInstGen *align_inst; // can be null
372401
373402 bool is_const;
374403 bool is_volatile;
......@@ -379,8 +408,8 @@ struct LazyValueArrayType {
379408 LazyValue base;
380409
381410 IrAnalyze *ira;
382 IrInstruction *sentinel; // can be null
383 IrInstruction *elem_type;
411 IrInstGen *sentinel; // can be null
412 IrInstGen *elem_type;
384413 uint64_t length;
385414};
386415
......@@ -388,9 +417,9 @@ struct LazyValuePtrType {
388417 LazyValue base;
389418
390419 IrAnalyze *ira;
391 IrInstruction *sentinel; // can be null
392 IrInstruction *elem_type;
393 IrInstruction *align_inst; // can be null
420 IrInstGen *sentinel; // can be null
421 IrInstGen *elem_type;
422 IrInstGen *align_inst; // can be null
394423
395424 PtrLen ptr_len;
396425 uint32_t bit_offset_in_host;
......@@ -405,7 +434,7 @@ struct LazyValueOptType {
405434 LazyValue base;
406435
407436 IrAnalyze *ira;
408 IrInstruction *payload_type;
437 IrInstGen *payload_type;
409438};
410439
411440struct LazyValueFnType {
......@@ -413,9 +442,9 @@ struct LazyValueFnType {
413442
414443 IrAnalyze *ira;
415444 AstNode *proto_node;
416 IrInstruction **param_types;
417 IrInstruction *align_inst; // can be null
418 IrInstruction *return_type;
445 IrInstGen **param_types;
446 IrInstGen *align_inst; // can be null
447 IrInstGen *return_type;
419448
420449 CallingConvention cc;
421450 bool is_generic;
......@@ -425,8 +454,8 @@ struct LazyValueErrUnionType {
425454 LazyValue base;
426455
427456 IrAnalyze *ira;
428 IrInstruction *err_set_type;
429 IrInstruction *payload_type;
457 IrInstGen *err_set_type;
458 IrInstGen *payload_type;
430459 Buf *type_name;
431460};
432461
......@@ -1602,19 +1631,19 @@ struct ZigFn {
16021631 // in the case of async functions this is the implicit return type according to the
16031632 // zig source code, not according to zig ir
16041633 ZigType *src_implicit_return_type;
1605 IrExecutable *ir_executable;
1606 IrExecutable analyzed_executable;
1634 IrExecutableSrc *ir_executable;
1635 IrExecutableGen analyzed_executable;
16071636 size_t prealloc_bbc;
16081637 size_t prealloc_backward_branch_quota;
16091638 AstNode **param_source_nodes;
16101639 Buf **param_names;
1611 IrInstruction *err_code_spill;
1640 IrInstGen *err_code_spill;
16121641 AstNode *assumed_non_async;
16131642
16141643 AstNode *fn_no_inline_set_node;
16151644 AstNode *fn_static_eval_set_node;
16161645
1617 ZigList<IrInstructionAllocaGen *> alloca_gen_list;
1646 ZigList<IrInstGenAlloca *> alloca_gen_list;
16181647 ZigList<ZigVar *> variable_list;
16191648
16201649 Buf *section_name;
......@@ -1626,8 +1655,8 @@ struct ZigFn {
16261655 AstNode *non_async_node;
16271656
16281657 ZigList<GlobalExport> export_list;
1629 ZigList<IrInstructionCallGen *> call_list;
1630 ZigList<IrInstructionAwaitGen *> await_list;
1658 ZigList<IrInstGenCall *> call_list;
1659 ZigList<IrInstGenAwait *> await_list;
16311660
16321661 LLVMValueRef valgrind_client_request_array;
16331662
......@@ -2098,8 +2127,9 @@ struct CodeGen {
20982127 Buf *zig_c_headers_dir; // Cannot be overridden; derived from zig_lib_dir.
20992128 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.
21002129
2101 IrInstruction *invalid_instruction;
2102 IrInstruction *unreach_instruction;
2130 IrInstSrc *invalid_inst_src;
2131 IrInstGen *invalid_inst_gen;
2132 IrInstGen *unreach_instruction;
21032133
21042134 ZigValue panic_msg_vals[PanicMsgIdCount];
21052135
......@@ -2222,8 +2252,8 @@ struct ZigVar {
22222252 ZigValue *const_value;
22232253 ZigType *var_type;
22242254 LLVMValueRef value_ref;
2225 IrInstruction *is_comptime;
2226 IrInstruction *ptr_instruction;
2255 IrInstSrc *is_comptime;
2256 IrInstGen *ptr_instruction;
22272257 // which node is the declaration of the variable
22282258 AstNode *decl_node;
22292259 ZigLLVMDILocalVariable *di_loc_var;
......@@ -2232,7 +2262,7 @@ struct ZigVar {
22322262 Scope *child_scope;
22332263 LLVMValueRef param_value_ref;
22342264 size_t mem_slot_index;
2235 IrExecutable *owner_exec;
2265 IrExecutableSrc *owner_exec;
22362266
22372267 Buf *section_name;
22382268
......@@ -2323,11 +2353,11 @@ struct ScopeBlock {
23232353 Scope base;
23242354
23252355 Buf *name;
2326 IrBasicBlock *end_block;
2327 IrInstruction *is_comptime;
2356 IrBasicBlockSrc *end_block;
2357 IrInstSrc *is_comptime;
23282358 ResultLocPeerParent *peer_parent;
2329 ZigList<IrInstruction *> *incoming_values;
2330 ZigList<IrBasicBlock *> *incoming_blocks;
2359 ZigList<IrInstSrc *> *incoming_values;
2360 ZigList<IrBasicBlockSrc *> *incoming_blocks;
23312361
23322362 AstNode *safety_set_node;
23332363 AstNode *fast_math_set_node;
......@@ -2378,11 +2408,11 @@ struct ScopeLoop {
23782408
23792409 LVal lval;
23802410 Buf *name;
2381 IrBasicBlock *break_block;
2382 IrBasicBlock *continue_block;
2383 IrInstruction *is_comptime;
2384 ZigList<IrInstruction *> *incoming_values;
2385 ZigList<IrBasicBlock *> *incoming_blocks;
2411 IrBasicBlockSrc *break_block;
2412 IrBasicBlockSrc *continue_block;
2413 IrInstSrc *is_comptime;
2414 ZigList<IrInstSrc *> *incoming_values;
2415 ZigList<IrBasicBlockSrc *> *incoming_blocks;
23862416 ResultLocPeerParent *peer_parent;
23872417 ScopeExpr *spill_scope;
23882418};
......@@ -2393,7 +2423,7 @@ struct ScopeLoop {
23932423struct ScopeRuntime {
23942424 Scope base;
23952425
2396 IrInstruction *is_comptime;
2426 IrInstSrc *is_comptime;
23972427};
23982428
23992429// This scope is created for a suspend block in order to have labeled
......@@ -2472,319 +2502,450 @@ enum AtomicRmwOp {
24722502// to another basic block.
24732503// Phi instructions must be first in a basic block.
24742504// The last instruction in a basic block must be of type unreachable.
2475struct IrBasicBlock {
2476 ZigList<IrInstruction *> instruction_list;
2477 IrBasicBlock *other;
2505struct IrBasicBlockSrc {
2506 ZigList<IrInstSrc *> instruction_list;
2507 IrBasicBlockGen *child;
2508 Scope *scope;
2509 const char *name_hint;
2510 IrInst *suspend_instruction_ref;
2511
2512 uint32_t ref_count;
2513 uint32_t index; // index into the basic block list
2514
2515 uint32_t debug_id;
2516 bool suspended;
2517 bool in_resume_stack;
2518};
2519
2520struct IrBasicBlockGen {
2521 ZigList<IrInstGen *> instruction_list;
2522 IrBasicBlockSrc *parent;
24782523 Scope *scope;
24792524 const char *name_hint;
2480 size_t debug_id;
2481 size_t ref_count;
2482 // index into the basic block list
2483 size_t index;
2525 uint32_t index; // index into the basic block list
2526 uint32_t ref_count;
24842527 LLVMBasicBlockRef llvm_block;
24852528 LLVMBasicBlockRef llvm_exit_block;
24862529 // The instruction that referenced this basic block and caused us to
24872530 // analyze the basic block. If the same instruction wants us to emit
24882531 // the same basic block, then we re-generate it instead of saving it.
2489 IrInstruction *ref_instruction;
2532 IrInst *ref_instruction;
24902533 // When this is non-null, a branch to this basic block is only allowed
24912534 // if the branch is comptime. The instruction points to the reason
24922535 // the basic block must be comptime.
2493 IrInstruction *must_be_comptime_source_instr;
2494 IrInstruction *suspend_instruction_ref;
2536 IrInst *must_be_comptime_source_instr;
2537
2538 uint32_t debug_id;
24952539 bool already_appended;
2496 bool suspended;
2497 bool in_resume_stack;
24982540};
24992541
2500// These instructions are in transition to having "pass 1" instructions
2501// and "pass 2" instructions. The pass 1 instructions are suffixed with Src
2502// and pass 2 are suffixed with Gen.
2503// Once all instructions are separated in this way, they'll have different
2504// base types for better type safety.
25052542// Src instructions are generated by ir_gen_* functions in ir.cpp from AST.
25062543// ir_analyze_* functions consume Src instructions and produce Gen instructions.
2544// Src instructions do not have type information; Gen instructions do.
2545enum IrInstSrcId {
2546 IrInstSrcIdInvalid,
2547 IrInstSrcIdDeclVar,
2548 IrInstSrcIdBr,
2549 IrInstSrcIdCondBr,
2550 IrInstSrcIdSwitchBr,
2551 IrInstSrcIdSwitchVar,
2552 IrInstSrcIdSwitchElseVar,
2553 IrInstSrcIdSwitchTarget,
2554 IrInstSrcIdPhi,
2555 IrInstSrcIdUnOp,
2556 IrInstSrcIdBinOp,
2557 IrInstSrcIdMergeErrSets,
2558 IrInstSrcIdLoadPtr,
2559 IrInstSrcIdStorePtr,
2560 IrInstSrcIdFieldPtr,
2561 IrInstSrcIdElemPtr,
2562 IrInstSrcIdVarPtr,
2563 IrInstSrcIdCall,
2564 IrInstSrcIdCallArgs,
2565 IrInstSrcIdCallExtra,
2566 IrInstSrcIdConst,
2567 IrInstSrcIdReturn,
2568 IrInstSrcIdContainerInitList,
2569 IrInstSrcIdContainerInitFields,
2570 IrInstSrcIdUnreachable,
2571 IrInstSrcIdTypeOf,
2572 IrInstSrcIdSetCold,
2573 IrInstSrcIdSetRuntimeSafety,
2574 IrInstSrcIdSetFloatMode,
2575 IrInstSrcIdArrayType,
2576 IrInstSrcIdAnyFrameType,
2577 IrInstSrcIdSliceType,
2578 IrInstSrcIdAsm,
2579 IrInstSrcIdSizeOf,
2580 IrInstSrcIdTestNonNull,
2581 IrInstSrcIdOptionalUnwrapPtr,
2582 IrInstSrcIdClz,
2583 IrInstSrcIdCtz,
2584 IrInstSrcIdPopCount,
2585 IrInstSrcIdBswap,
2586 IrInstSrcIdBitReverse,
2587 IrInstSrcIdImport,
2588 IrInstSrcIdCImport,
2589 IrInstSrcIdCInclude,
2590 IrInstSrcIdCDefine,
2591 IrInstSrcIdCUndef,
2592 IrInstSrcIdRef,
2593 IrInstSrcIdCompileErr,
2594 IrInstSrcIdCompileLog,
2595 IrInstSrcIdErrName,
2596 IrInstSrcIdEmbedFile,
2597 IrInstSrcIdCmpxchg,
2598 IrInstSrcIdFence,
2599 IrInstSrcIdTruncate,
2600 IrInstSrcIdIntCast,
2601 IrInstSrcIdFloatCast,
2602 IrInstSrcIdIntToFloat,
2603 IrInstSrcIdFloatToInt,
2604 IrInstSrcIdBoolToInt,
2605 IrInstSrcIdIntType,
2606 IrInstSrcIdVectorType,
2607 IrInstSrcIdShuffleVector,
2608 IrInstSrcIdSplat,
2609 IrInstSrcIdBoolNot,
2610 IrInstSrcIdMemset,
2611 IrInstSrcIdMemcpy,
2612 IrInstSrcIdSlice,
2613 IrInstSrcIdMemberCount,
2614 IrInstSrcIdMemberType,
2615 IrInstSrcIdMemberName,
2616 IrInstSrcIdBreakpoint,
2617 IrInstSrcIdReturnAddress,
2618 IrInstSrcIdFrameAddress,
2619 IrInstSrcIdFrameHandle,
2620 IrInstSrcIdFrameType,
2621 IrInstSrcIdFrameSize,
2622 IrInstSrcIdAlignOf,
2623 IrInstSrcIdOverflowOp,
2624 IrInstSrcIdTestErr,
2625 IrInstSrcIdMulAdd,
2626 IrInstSrcIdFloatOp,
2627 IrInstSrcIdUnwrapErrCode,
2628 IrInstSrcIdUnwrapErrPayload,
2629 IrInstSrcIdFnProto,
2630 IrInstSrcIdTestComptime,
2631 IrInstSrcIdPtrCast,
2632 IrInstSrcIdBitCast,
2633 IrInstSrcIdIntToPtr,
2634 IrInstSrcIdPtrToInt,
2635 IrInstSrcIdIntToEnum,
2636 IrInstSrcIdEnumToInt,
2637 IrInstSrcIdIntToErr,
2638 IrInstSrcIdErrToInt,
2639 IrInstSrcIdCheckSwitchProngs,
2640 IrInstSrcIdCheckStatementIsVoid,
2641 IrInstSrcIdTypeName,
2642 IrInstSrcIdDeclRef,
2643 IrInstSrcIdPanic,
2644 IrInstSrcIdTagName,
2645 IrInstSrcIdTagType,
2646 IrInstSrcIdFieldParentPtr,
2647 IrInstSrcIdByteOffsetOf,
2648 IrInstSrcIdBitOffsetOf,
2649 IrInstSrcIdTypeInfo,
2650 IrInstSrcIdType,
2651 IrInstSrcIdHasField,
2652 IrInstSrcIdTypeId,
2653 IrInstSrcIdSetEvalBranchQuota,
2654 IrInstSrcIdPtrType,
2655 IrInstSrcIdAlignCast,
2656 IrInstSrcIdImplicitCast,
2657 IrInstSrcIdResolveResult,
2658 IrInstSrcIdResetResult,
2659 IrInstSrcIdOpaqueType,
2660 IrInstSrcIdSetAlignStack,
2661 IrInstSrcIdArgType,
2662 IrInstSrcIdExport,
2663 IrInstSrcIdErrorReturnTrace,
2664 IrInstSrcIdErrorUnion,
2665 IrInstSrcIdAtomicRmw,
2666 IrInstSrcIdAtomicLoad,
2667 IrInstSrcIdAtomicStore,
2668 IrInstSrcIdSaveErrRetAddr,
2669 IrInstSrcIdAddImplicitReturnType,
2670 IrInstSrcIdErrSetCast,
2671 IrInstSrcIdToBytes,
2672 IrInstSrcIdFromBytes,
2673 IrInstSrcIdCheckRuntimeScope,
2674 IrInstSrcIdHasDecl,
2675 IrInstSrcIdUndeclaredIdent,
2676 IrInstSrcIdAlloca,
2677 IrInstSrcIdEndExpr,
2678 IrInstSrcIdUnionInitNamedField,
2679 IrInstSrcIdSuspendBegin,
2680 IrInstSrcIdSuspendFinish,
2681 IrInstSrcIdAwait,
2682 IrInstSrcIdResume,
2683 IrInstSrcIdSpillBegin,
2684 IrInstSrcIdSpillEnd,
2685};
2686
25072687// ir_render_* functions in codegen.cpp consume Gen instructions and produce LLVM IR.
25082688// Src instructions do not have type information; Gen instructions do.
2509enum IrInstructionId {
2510 IrInstructionIdInvalid,
2511 IrInstructionIdDeclVarSrc,
2512 IrInstructionIdDeclVarGen,
2513 IrInstructionIdBr,
2514 IrInstructionIdCondBr,
2515 IrInstructionIdSwitchBr,
2516 IrInstructionIdSwitchVar,
2517 IrInstructionIdSwitchElseVar,
2518 IrInstructionIdSwitchTarget,
2519 IrInstructionIdPhi,
2520 IrInstructionIdUnOp,
2521 IrInstructionIdBinOp,
2522 IrInstructionIdMergeErrSets,
2523 IrInstructionIdLoadPtr,
2524 IrInstructionIdLoadPtrGen,
2525 IrInstructionIdStorePtr,
2526 IrInstructionIdVectorStoreElem,
2527 IrInstructionIdFieldPtr,
2528 IrInstructionIdStructFieldPtr,
2529 IrInstructionIdUnionFieldPtr,
2530 IrInstructionIdElemPtr,
2531 IrInstructionIdVarPtr,
2532 IrInstructionIdReturnPtr,
2533 IrInstructionIdCallSrc,
2534 IrInstructionIdCallSrcArgs,
2535 IrInstructionIdCallExtra,
2536 IrInstructionIdCallGen,
2537 IrInstructionIdConst,
2538 IrInstructionIdReturn,
2539 IrInstructionIdCast,
2540 IrInstructionIdResizeSlice,
2541 IrInstructionIdContainerInitList,
2542 IrInstructionIdContainerInitFields,
2543 IrInstructionIdUnreachable,
2544 IrInstructionIdTypeOf,
2545 IrInstructionIdSetCold,
2546 IrInstructionIdSetRuntimeSafety,
2547 IrInstructionIdSetFloatMode,
2548 IrInstructionIdArrayType,
2549 IrInstructionIdAnyFrameType,
2550 IrInstructionIdSliceType,
2551 IrInstructionIdAsmSrc,
2552 IrInstructionIdAsmGen,
2553 IrInstructionIdSizeOf,
2554 IrInstructionIdTestNonNull,
2555 IrInstructionIdOptionalUnwrapPtr,
2556 IrInstructionIdOptionalWrap,
2557 IrInstructionIdUnionTag,
2558 IrInstructionIdClz,
2559 IrInstructionIdCtz,
2560 IrInstructionIdPopCount,
2561 IrInstructionIdBswap,
2562 IrInstructionIdBitReverse,
2563 IrInstructionIdImport,
2564 IrInstructionIdCImport,
2565 IrInstructionIdCInclude,
2566 IrInstructionIdCDefine,
2567 IrInstructionIdCUndef,
2568 IrInstructionIdRef,
2569 IrInstructionIdRefGen,
2570 IrInstructionIdCompileErr,
2571 IrInstructionIdCompileLog,
2572 IrInstructionIdErrName,
2573 IrInstructionIdEmbedFile,
2574 IrInstructionIdCmpxchgSrc,
2575 IrInstructionIdCmpxchgGen,
2576 IrInstructionIdFence,
2577 IrInstructionIdTruncate,
2578 IrInstructionIdIntCast,
2579 IrInstructionIdFloatCast,
2580 IrInstructionIdIntToFloat,
2581 IrInstructionIdFloatToInt,
2582 IrInstructionIdBoolToInt,
2583 IrInstructionIdIntType,
2584 IrInstructionIdVectorType,
2585 IrInstructionIdShuffleVector,
2586 IrInstructionIdSplatSrc,
2587 IrInstructionIdSplatGen,
2588 IrInstructionIdBoolNot,
2589 IrInstructionIdMemset,
2590 IrInstructionIdMemcpy,
2591 IrInstructionIdSliceSrc,
2592 IrInstructionIdSliceGen,
2593 IrInstructionIdMemberCount,
2594 IrInstructionIdMemberType,
2595 IrInstructionIdMemberName,
2596 IrInstructionIdBreakpoint,
2597 IrInstructionIdReturnAddress,
2598 IrInstructionIdFrameAddress,
2599 IrInstructionIdFrameHandle,
2600 IrInstructionIdFrameType,
2601 IrInstructionIdFrameSizeSrc,
2602 IrInstructionIdFrameSizeGen,
2603 IrInstructionIdAlignOf,
2604 IrInstructionIdOverflowOp,
2605 IrInstructionIdTestErrSrc,
2606 IrInstructionIdTestErrGen,
2607 IrInstructionIdMulAdd,
2608 IrInstructionIdFloatOp,
2609 IrInstructionIdUnwrapErrCode,
2610 IrInstructionIdUnwrapErrPayload,
2611 IrInstructionIdErrWrapCode,
2612 IrInstructionIdErrWrapPayload,
2613 IrInstructionIdFnProto,
2614 IrInstructionIdTestComptime,
2615 IrInstructionIdPtrCastSrc,
2616 IrInstructionIdPtrCastGen,
2617 IrInstructionIdBitCastSrc,
2618 IrInstructionIdBitCastGen,
2619 IrInstructionIdWidenOrShorten,
2620 IrInstructionIdIntToPtr,
2621 IrInstructionIdPtrToInt,
2622 IrInstructionIdIntToEnum,
2623 IrInstructionIdEnumToInt,
2624 IrInstructionIdIntToErr,
2625 IrInstructionIdErrToInt,
2626 IrInstructionIdCheckSwitchProngs,
2627 IrInstructionIdCheckStatementIsVoid,
2628 IrInstructionIdTypeName,
2629 IrInstructionIdDeclRef,
2630 IrInstructionIdPanic,
2631 IrInstructionIdTagName,
2632 IrInstructionIdTagType,
2633 IrInstructionIdFieldParentPtr,
2634 IrInstructionIdByteOffsetOf,
2635 IrInstructionIdBitOffsetOf,
2636 IrInstructionIdTypeInfo,
2637 IrInstructionIdType,
2638 IrInstructionIdHasField,
2639 IrInstructionIdTypeId,
2640 IrInstructionIdSetEvalBranchQuota,
2641 IrInstructionIdPtrType,
2642 IrInstructionIdAlignCast,
2643 IrInstructionIdImplicitCast,
2644 IrInstructionIdResolveResult,
2645 IrInstructionIdResetResult,
2646 IrInstructionIdOpaqueType,
2647 IrInstructionIdSetAlignStack,
2648 IrInstructionIdArgType,
2649 IrInstructionIdExport,
2650 IrInstructionIdErrorReturnTrace,
2651 IrInstructionIdErrorUnion,
2652 IrInstructionIdAtomicRmw,
2653 IrInstructionIdAtomicLoad,
2654 IrInstructionIdAtomicStore,
2655 IrInstructionIdSaveErrRetAddr,
2656 IrInstructionIdAddImplicitReturnType,
2657 IrInstructionIdErrSetCast,
2658 IrInstructionIdToBytes,
2659 IrInstructionIdFromBytes,
2660 IrInstructionIdCheckRuntimeScope,
2661 IrInstructionIdVectorToArray,
2662 IrInstructionIdArrayToVector,
2663 IrInstructionIdAssertZero,
2664 IrInstructionIdAssertNonNull,
2665 IrInstructionIdHasDecl,
2666 IrInstructionIdUndeclaredIdent,
2667 IrInstructionIdAllocaSrc,
2668 IrInstructionIdAllocaGen,
2669 IrInstructionIdEndExpr,
2670 IrInstructionIdPtrOfArrayToSlice,
2671 IrInstructionIdUnionInitNamedField,
2672 IrInstructionIdSuspendBegin,
2673 IrInstructionIdSuspendFinish,
2674 IrInstructionIdAwaitSrc,
2675 IrInstructionIdAwaitGen,
2676 IrInstructionIdResume,
2677 IrInstructionIdSpillBegin,
2678 IrInstructionIdSpillEnd,
2679 IrInstructionIdVectorExtractElem,
2680};
2681
2682struct IrInstruction {
2683 Scope *scope;
2684 AstNode *source_node;
2685 LLVMValueRef llvm_value;
2686 ZigValue *value;
2687 uint32_t debug_id;
2689enum IrInstGenId {
2690 IrInstGenIdInvalid,
2691 IrInstGenIdDeclVar,
2692 IrInstGenIdBr,
2693 IrInstGenIdCondBr,
2694 IrInstGenIdSwitchBr,
2695 IrInstGenIdPhi,
2696 IrInstGenIdBinaryNot,
2697 IrInstGenIdNegation,
2698 IrInstGenIdNegationWrapping,
2699 IrInstGenIdBinOp,
2700 IrInstGenIdLoadPtr,
2701 IrInstGenIdStorePtr,
2702 IrInstGenIdVectorStoreElem,
2703 IrInstGenIdStructFieldPtr,
2704 IrInstGenIdUnionFieldPtr,
2705 IrInstGenIdElemPtr,
2706 IrInstGenIdVarPtr,
2707 IrInstGenIdReturnPtr,
2708 IrInstGenIdCall,
2709 IrInstGenIdReturn,
2710 IrInstGenIdCast,
2711 IrInstGenIdResizeSlice,
2712 IrInstGenIdUnreachable,
2713 IrInstGenIdAsm,
2714 IrInstGenIdTestNonNull,
2715 IrInstGenIdOptionalUnwrapPtr,
2716 IrInstGenIdOptionalWrap,
2717 IrInstGenIdUnionTag,
2718 IrInstGenIdClz,
2719 IrInstGenIdCtz,
2720 IrInstGenIdPopCount,
2721 IrInstGenIdBswap,
2722 IrInstGenIdBitReverse,
2723 IrInstGenIdRef,
2724 IrInstGenIdErrName,
2725 IrInstGenIdCmpxchg,
2726 IrInstGenIdFence,
2727 IrInstGenIdTruncate,
2728 IrInstGenIdShuffleVector,
2729 IrInstGenIdSplat,
2730 IrInstGenIdBoolNot,
2731 IrInstGenIdMemset,
2732 IrInstGenIdMemcpy,
2733 IrInstGenIdSlice,
2734 IrInstGenIdBreakpoint,
2735 IrInstGenIdReturnAddress,
2736 IrInstGenIdFrameAddress,
2737 IrInstGenIdFrameHandle,
2738 IrInstGenIdFrameSize,
2739 IrInstGenIdOverflowOp,
2740 IrInstGenIdTestErr,
2741 IrInstGenIdMulAdd,
2742 IrInstGenIdFloatOp,
2743 IrInstGenIdUnwrapErrCode,
2744 IrInstGenIdUnwrapErrPayload,
2745 IrInstGenIdErrWrapCode,
2746 IrInstGenIdErrWrapPayload,
2747 IrInstGenIdPtrCast,
2748 IrInstGenIdBitCast,
2749 IrInstGenIdWidenOrShorten,
2750 IrInstGenIdIntToPtr,
2751 IrInstGenIdPtrToInt,
2752 IrInstGenIdIntToEnum,
2753 IrInstGenIdIntToErr,
2754 IrInstGenIdErrToInt,
2755 IrInstGenIdPanic,
2756 IrInstGenIdTagName,
2757 IrInstGenIdFieldParentPtr,
2758 IrInstGenIdAlignCast,
2759 IrInstGenIdErrorReturnTrace,
2760 IrInstGenIdAtomicRmw,
2761 IrInstGenIdAtomicLoad,
2762 IrInstGenIdAtomicStore,
2763 IrInstGenIdSaveErrRetAddr,
2764 IrInstGenIdVectorToArray,
2765 IrInstGenIdArrayToVector,
2766 IrInstGenIdAssertZero,
2767 IrInstGenIdAssertNonNull,
2768 IrInstGenIdPtrOfArrayToSlice,
2769 IrInstGenIdSuspendBegin,
2770 IrInstGenIdSuspendFinish,
2771 IrInstGenIdAwait,
2772 IrInstGenIdResume,
2773 IrInstGenIdSpillBegin,
2774 IrInstGenIdSpillEnd,
2775 IrInstGenIdVectorExtractElem,
2776 IrInstGenIdAlloca,
2777 IrInstGenIdConst,
2778};
2779
2780// Common fields between IrInstSrc and IrInstGen. This allows future passes
2781// after pass2 to be added to zig.
2782struct IrInst {
26882783 // if ref_count is zero and the instruction has no side effects,
26892784 // the instruction can be omitted in codegen
26902785 uint32_t ref_count;
2786 uint32_t debug_id;
2787
2788 Scope *scope;
2789 AstNode *source_node;
2790
2791 // for debugging purposes, these are useful to call to inspect the instruction
2792 void dump();
2793 void src();
2794};
2795
2796struct IrInstSrc {
2797 IrInst base;
2798
2799 IrInstSrcId id;
2800 // true if this instruction was generated by zig and not from user code
2801 // this matters for the "unreachable code" compile error
2802 bool is_gen;
2803 bool is_noreturn;
2804
26912805 // When analyzing IR, instructions that point to this instruction in the "old ir"
26922806 // can find the instruction that corresponds to this value in the "new ir"
26932807 // with this child field.
2694 IrInstruction *child;
2695 IrBasicBlock *owner_bb;
2808 IrInstGen *child;
2809 IrBasicBlockSrc *owner_bb;
2810
2811 // for debugging purposes, these are useful to call to inspect the instruction
2812 void dump();
2813 void src();
2814};
2815
2816struct IrInstGen {
2817 IrInst base;
2818
2819 IrInstGenId id;
2820
2821 LLVMValueRef llvm_value;
2822 ZigValue *value;
2823 IrBasicBlockGen *owner_bb;
26962824 // Nearly any instruction can have to be stored as a local variable before suspending
26972825 // and then loaded after resuming, in case there is an expression with a suspend point
26982826 // in it, such as: x + await y
2699 IrInstruction *spill;
2700 IrInstructionId id;
2701 // true if this instruction was generated by zig and not from user code
2702 bool is_gen;
2827 IrInstGen *spill;
27032828
27042829 // for debugging purposes, these are useful to call to inspect the instruction
27052830 void dump();
27062831 void src();
27072832};
27082833
2709struct IrInstructionDeclVarSrc {
2710 IrInstruction base;
2834struct IrInstSrcDeclVar {
2835 IrInstSrc base;
27112836
27122837 ZigVar *var;
2713 IrInstruction *var_type;
2714 IrInstruction *align_value;
2715 IrInstruction *ptr;
2838 IrInstSrc *var_type;
2839 IrInstSrc *align_value;
2840 IrInstSrc *ptr;
27162841};
27172842
2718struct IrInstructionDeclVarGen {
2719 IrInstruction base;
2843struct IrInstGenDeclVar {
2844 IrInstGen base;
27202845
27212846 ZigVar *var;
2722 IrInstruction *var_ptr;
2847 IrInstGen *var_ptr;
27232848};
27242849
2725struct IrInstructionCondBr {
2726 IrInstruction base;
2850struct IrInstSrcCondBr {
2851 IrInstSrc base;
27272852
2728 IrInstruction *condition;
2729 IrBasicBlock *then_block;
2730 IrBasicBlock *else_block;
2731 IrInstruction *is_comptime;
2853 IrInstSrc *condition;
2854 IrBasicBlockSrc *then_block;
2855 IrBasicBlockSrc *else_block;
2856 IrInstSrc *is_comptime;
27322857 ResultLoc *result_loc;
27332858};
27342859
2735struct IrInstructionBr {
2736 IrInstruction base;
2860struct IrInstGenCondBr {
2861 IrInstGen base;
2862
2863 IrInstGen *condition;
2864 IrBasicBlockGen *then_block;
2865 IrBasicBlockGen *else_block;
2866};
2867
2868struct IrInstSrcBr {
2869 IrInstSrc base;
2870
2871 IrBasicBlockSrc *dest_block;
2872 IrInstSrc *is_comptime;
2873};
2874
2875struct IrInstGenBr {
2876 IrInstGen base;
2877
2878 IrBasicBlockGen *dest_block;
2879};
2880
2881struct IrInstSrcSwitchBrCase {
2882 IrInstSrc *value;
2883 IrBasicBlockSrc *block;
2884};
2885
2886struct IrInstSrcSwitchBr {
2887 IrInstSrc base;
27372888
2738 IrBasicBlock *dest_block;
2739 IrInstruction *is_comptime;
2889 IrInstSrc *target_value;
2890 IrBasicBlockSrc *else_block;
2891 size_t case_count;
2892 IrInstSrcSwitchBrCase *cases;
2893 IrInstSrc *is_comptime;
2894 IrInstSrc *switch_prongs_void;
27402895};
27412896
2742struct IrInstructionSwitchBrCase {
2743 IrInstruction *value;
2744 IrBasicBlock *block;
2897struct IrInstGenSwitchBrCase {
2898 IrInstGen *value;
2899 IrBasicBlockGen *block;
27452900};
27462901
2747struct IrInstructionSwitchBr {
2748 IrInstruction base;
2902struct IrInstGenSwitchBr {
2903 IrInstGen base;
27492904
2750 IrInstruction *target_value;
2751 IrBasicBlock *else_block;
2905 IrInstGen *target_value;
2906 IrBasicBlockGen *else_block;
27522907 size_t case_count;
2753 IrInstructionSwitchBrCase *cases;
2754 IrInstruction *is_comptime;
2755 IrInstruction *switch_prongs_void;
2908 IrInstGenSwitchBrCase *cases;
27562909};
27572910
2758struct IrInstructionSwitchVar {
2759 IrInstruction base;
2911struct IrInstSrcSwitchVar {
2912 IrInstSrc base;
27602913
2761 IrInstruction *target_value_ptr;
2762 IrInstruction **prongs_ptr;
2914 IrInstSrc *target_value_ptr;
2915 IrInstSrc **prongs_ptr;
27632916 size_t prongs_len;
27642917};
27652918
2766struct IrInstructionSwitchElseVar {
2767 IrInstruction base;
2919struct IrInstSrcSwitchElseVar {
2920 IrInstSrc base;
27682921
2769 IrInstruction *target_value_ptr;
2770 IrInstructionSwitchBr *switch_br;
2922 IrInstSrc *target_value_ptr;
2923 IrInstSrcSwitchBr *switch_br;
27712924};
27722925
2773struct IrInstructionSwitchTarget {
2774 IrInstruction base;
2926struct IrInstSrcSwitchTarget {
2927 IrInstSrc base;
27752928
2776 IrInstruction *target_value_ptr;
2929 IrInstSrc *target_value_ptr;
27772930};
27782931
2779struct IrInstructionPhi {
2780 IrInstruction base;
2932struct IrInstSrcPhi {
2933 IrInstSrc base;
27812934
27822935 size_t incoming_count;
2783 IrBasicBlock **incoming_blocks;
2784 IrInstruction **incoming_values;
2936 IrBasicBlockSrc **incoming_blocks;
2937 IrInstSrc **incoming_values;
27852938 ResultLocPeerParent *peer_parent;
27862939};
27872940
2941struct IrInstGenPhi {
2942 IrInstGen base;
2943
2944 size_t incoming_count;
2945 IrBasicBlockGen **incoming_blocks;
2946 IrInstGen **incoming_values;
2947};
2948
27882949enum IrUnOp {
27892950 IrUnOpInvalid,
27902951 IrUnOpBinNot,
......@@ -2794,15 +2955,30 @@ enum IrUnOp {
27942955 IrUnOpOptional,
27952956};
27962957
2797struct IrInstructionUnOp {
2798 IrInstruction base;
2958struct IrInstSrcUnOp {
2959 IrInstSrc base;
27992960
28002961 IrUnOp op_id;
28012962 LVal lval;
2802 IrInstruction *value;
2963 IrInstSrc *value;
28032964 ResultLoc *result_loc;
28042965};
28052966
2967struct IrInstGenBinaryNot {
2968 IrInstGen base;
2969 IrInstGen *operand;
2970};
2971
2972struct IrInstGenNegation {
2973 IrInstGen base;
2974 IrInstGen *operand;
2975};
2976
2977struct IrInstGenNegationWrapping {
2978 IrInstGen base;
2979 IrInstGen *operand;
2980};
2981
28062982enum IrBinOp {
28072983 IrBinOpInvalid,
28082984 IrBinOpBoolOr,
......@@ -2837,113 +3013,144 @@ enum IrBinOp {
28373013 IrBinOpArrayMult,
28383014};
28393015
2840struct IrInstructionBinOp {
2841 IrInstruction base;
3016struct IrInstSrcBinOp {
3017 IrInstSrc base;
3018
3019 IrInstSrc *op1;
3020 IrInstSrc *op2;
3021 IrBinOp op_id;
3022 bool safety_check_on;
3023};
3024
3025struct IrInstGenBinOp {
3026 IrInstGen base;
28423027
2843 IrInstruction *op1;
2844 IrInstruction *op2;
3028 IrInstGen *op1;
3029 IrInstGen *op2;
28453030 IrBinOp op_id;
28463031 bool safety_check_on;
28473032};
28483033
2849struct IrInstructionMergeErrSets {
2850 IrInstruction base;
3034struct IrInstSrcMergeErrSets {
3035 IrInstSrc base;
28513036
2852 IrInstruction *op1;
2853 IrInstruction *op2;
3037 IrInstSrc *op1;
3038 IrInstSrc *op2;
28543039 Buf *type_name;
28553040};
28563041
2857struct IrInstructionLoadPtr {
2858 IrInstruction base;
3042struct IrInstSrcLoadPtr {
3043 IrInstSrc base;
28593044
2860 IrInstruction *ptr;
3045 IrInstSrc *ptr;
28613046};
28623047
2863struct IrInstructionLoadPtrGen {
2864 IrInstruction base;
3048struct IrInstGenLoadPtr {
3049 IrInstGen base;
28653050
2866 IrInstruction *ptr;
2867 IrInstruction *result_loc;
3051 IrInstGen *ptr;
3052 IrInstGen *result_loc;
28683053};
28693054
2870struct IrInstructionStorePtr {
2871 IrInstruction base;
3055struct IrInstSrcStorePtr {
3056 IrInstSrc base;
3057
3058 IrInstSrc *ptr;
3059 IrInstSrc *value;
28723060
28733061 bool allow_write_through_const;
2874 IrInstruction *ptr;
2875 IrInstruction *value;
28763062};
28773063
2878struct IrInstructionVectorStoreElem {
2879 IrInstruction base;
3064struct IrInstGenStorePtr {
3065 IrInstGen base;
28803066
2881 IrInstruction *vector_ptr;
2882 IrInstruction *index;
2883 IrInstruction *value;
3067 IrInstGen *ptr;
3068 IrInstGen *value;
28843069};
28853070
2886struct IrInstructionFieldPtr {
2887 IrInstruction base;
3071struct IrInstGenVectorStoreElem {
3072 IrInstGen base;
28883073
2889 bool initializing;
2890 IrInstruction *container_ptr;
3074 IrInstGen *vector_ptr;
3075 IrInstGen *index;
3076 IrInstGen *value;
3077};
3078
3079struct IrInstSrcFieldPtr {
3080 IrInstSrc base;
3081
3082 IrInstSrc *container_ptr;
28913083 Buf *field_name_buffer;
2892 IrInstruction *field_name_expr;
3084 IrInstSrc *field_name_expr;
3085 bool initializing;
28933086};
28943087
2895struct IrInstructionStructFieldPtr {
2896 IrInstruction base;
3088struct IrInstGenStructFieldPtr {
3089 IrInstGen base;
28973090
2898 IrInstruction *struct_ptr;
3091 IrInstGen *struct_ptr;
28993092 TypeStructField *field;
29003093 bool is_const;
29013094};
29023095
2903struct IrInstructionUnionFieldPtr {
2904 IrInstruction base;
3096struct IrInstGenUnionFieldPtr {
3097 IrInstGen base;
29053098
3099 IrInstGen *union_ptr;
3100 TypeUnionField *field;
29063101 bool safety_check_on;
29073102 bool initializing;
2908 IrInstruction *union_ptr;
2909 TypeUnionField *field;
29103103};
29113104
2912struct IrInstructionElemPtr {
2913 IrInstruction base;
3105struct IrInstSrcElemPtr {
3106 IrInstSrc base;
29143107
2915 IrInstruction *array_ptr;
2916 IrInstruction *elem_index;
3108 IrInstSrc *array_ptr;
3109 IrInstSrc *elem_index;
29173110 AstNode *init_array_type_source_node;
29183111 PtrLen ptr_len;
29193112 bool safety_check_on;
29203113};
29213114
2922struct IrInstructionVarPtr {
2923 IrInstruction base;
3115struct IrInstGenElemPtr {
3116 IrInstGen base;
3117
3118 IrInstGen *array_ptr;
3119 IrInstGen *elem_index;
3120 bool safety_check_on;
3121};
3122
3123struct IrInstSrcVarPtr {
3124 IrInstSrc base;
29243125
29253126 ZigVar *var;
29263127 ScopeFnDef *crossed_fndef_scope;
29273128};
29283129
3130struct IrInstGenVarPtr {
3131 IrInstGen base;
3132
3133 ZigVar *var;
3134};
3135
29293136// For functions that have a return type for which handle_is_ptr is true, a
29303137// result location pointer is the secret first parameter ("sret"). This
29313138// instruction returns that pointer.
2932struct IrInstructionReturnPtr {
2933 IrInstruction base;
3139struct IrInstGenReturnPtr {
3140 IrInstGen base;
29343141};
29353142
2936struct IrInstructionCallSrc {
2937 IrInstruction base;
3143struct IrInstSrcCall {
3144 IrInstSrc base;
29383145
2939 IrInstruction *fn_ref;
3146 IrInstSrc *fn_ref;
29403147 ZigFn *fn_entry;
29413148 size_t arg_count;
2942 IrInstruction **args;
2943 IrInstruction *ret_ptr;
3149 IrInstSrc **args;
3150 IrInstSrc *ret_ptr;
29443151 ResultLoc *result_loc;
29453152
2946 IrInstruction *new_stack;
3153 IrInstSrc *new_stack;
29473154
29483155 CallModifier modifier;
29493156 bool is_async_call_builtin;
......@@ -2951,12 +3158,12 @@ struct IrInstructionCallSrc {
29513158
29523159// This is a pass1 instruction, used by @call when the args node is
29533160// a tuple or struct literal.
2954struct IrInstructionCallSrcArgs {
2955 IrInstruction base;
3161struct IrInstSrcCallArgs {
3162 IrInstSrc base;
29563163
2957 IrInstruction *options;
2958 IrInstruction *fn_ref;
2959 IrInstruction **args_ptr;
3164 IrInstSrc *options;
3165 IrInstSrc *fn_ref;
3166 IrInstSrc **args_ptr;
29603167 size_t args_len;
29613168 ResultLoc *result_loc;
29623169};
......@@ -2964,42 +3171,54 @@ struct IrInstructionCallSrcArgs {
29643171// This is a pass1 instruction, used by @call, when the args node
29653172// is not a literal.
29663173// `args` is expected to be either a struct or a tuple.
2967struct IrInstructionCallExtra {
2968 IrInstruction base;
3174struct IrInstSrcCallExtra {
3175 IrInstSrc base;
29693176
2970 IrInstruction *options;
2971 IrInstruction *fn_ref;
2972 IrInstruction *args;
3177 IrInstSrc *options;
3178 IrInstSrc *fn_ref;
3179 IrInstSrc *args;
29733180 ResultLoc *result_loc;
29743181};
29753182
2976struct IrInstructionCallGen {
2977 IrInstruction base;
3183struct IrInstGenCall {
3184 IrInstGen base;
29783185
2979 IrInstruction *fn_ref;
3186 IrInstGen *fn_ref;
29803187 ZigFn *fn_entry;
29813188 size_t arg_count;
2982 IrInstruction **args;
2983 IrInstruction *result_loc;
2984 IrInstruction *frame_result_loc;
2985 IrInstruction *new_stack;
3189 IrInstGen **args;
3190 IrInstGen *result_loc;
3191 IrInstGen *frame_result_loc;
3192 IrInstGen *new_stack;
29863193
29873194 CallModifier modifier;
29883195
29893196 bool is_async_call_builtin;
29903197};
29913198
2992struct IrInstructionConst {
2993 IrInstruction base;
3199struct IrInstSrcConst {
3200 IrInstSrc base;
3201
3202 ZigValue *value;
3203};
3204
3205struct IrInstGenConst {
3206 IrInstGen base;
3207};
3208
3209struct IrInstSrcReturn {
3210 IrInstSrc base;
3211
3212 IrInstSrc *operand;
29943213};
29953214
29963215// When an IrExecutable is not in a function, a return instruction means that
29973216// the expression returns with that value, even though a return statement from
29983217// an AST perspective is invalid.
2999struct IrInstructionReturn {
3000 IrInstruction base;
3218struct IrInstGenReturn {
3219 IrInstGen base;
30013220
3002 IrInstruction *operand;
3221 IrInstGen *operand;
30033222};
30043223
30053224enum CastOp {
......@@ -3014,89 +3233,92 @@ enum CastOp {
30143233};
30153234
30163235// TODO get rid of this instruction, replace with instructions for each op code
3017struct IrInstructionCast {
3018 IrInstruction base;
3236struct IrInstGenCast {
3237 IrInstGen base;
30193238
3020 IrInstruction *value;
3021 ZigType *dest_type;
3239 IrInstGen *value;
30223240 CastOp cast_op;
30233241};
30243242
3025struct IrInstructionResizeSlice {
3026 IrInstruction base;
3243struct IrInstGenResizeSlice {
3244 IrInstGen base;
30273245
3028 IrInstruction *operand;
3029 IrInstruction *result_loc;
3246 IrInstGen *operand;
3247 IrInstGen *result_loc;
30303248};
30313249
3032struct IrInstructionContainerInitList {
3033 IrInstruction base;
3250struct IrInstSrcContainerInitList {
3251 IrInstSrc base;
30343252
3035 IrInstruction *elem_type;
3253 IrInstSrc *elem_type;
30363254 size_t item_count;
3037 IrInstruction **elem_result_loc_list;
3038 IrInstruction *result_loc;
3255 IrInstSrc **elem_result_loc_list;
3256 IrInstSrc *result_loc;
30393257 AstNode *init_array_type_source_node;
30403258};
30413259
3042struct IrInstructionContainerInitFieldsField {
3260struct IrInstSrcContainerInitFieldsField {
30433261 Buf *name;
30443262 AstNode *source_node;
30453263 TypeStructField *type_struct_field;
3046 IrInstruction *result_loc;
3264 IrInstSrc *result_loc;
30473265};
30483266
3049struct IrInstructionContainerInitFields {
3050 IrInstruction base;
3267struct IrInstSrcContainerInitFields {
3268 IrInstSrc base;
30513269
30523270 size_t field_count;
3053 IrInstructionContainerInitFieldsField *fields;
3054 IrInstruction *result_loc;
3271 IrInstSrcContainerInitFieldsField *fields;
3272 IrInstSrc *result_loc;
3273};
3274
3275struct IrInstSrcUnreachable {
3276 IrInstSrc base;
30553277};
30563278
3057struct IrInstructionUnreachable {
3058 IrInstruction base;
3279struct IrInstGenUnreachable {
3280 IrInstGen base;
30593281};
30603282
3061struct IrInstructionTypeOf {
3062 IrInstruction base;
3283struct IrInstSrcTypeOf {
3284 IrInstSrc base;
30633285
3064 IrInstruction *value;
3286 IrInstSrc *value;
30653287};
30663288
3067struct IrInstructionSetCold {
3068 IrInstruction base;
3289struct IrInstSrcSetCold {
3290 IrInstSrc base;
30693291
3070 IrInstruction *is_cold;
3292 IrInstSrc *is_cold;
30713293};
30723294
3073struct IrInstructionSetRuntimeSafety {
3074 IrInstruction base;
3295struct IrInstSrcSetRuntimeSafety {
3296 IrInstSrc base;
30753297
3076 IrInstruction *safety_on;
3298 IrInstSrc *safety_on;
30773299};
30783300
3079struct IrInstructionSetFloatMode {
3080 IrInstruction base;
3301struct IrInstSrcSetFloatMode {
3302 IrInstSrc base;
30813303
3082 IrInstruction *scope_value;
3083 IrInstruction *mode_value;
3304 IrInstSrc *scope_value;
3305 IrInstSrc *mode_value;
30843306};
30853307
3086struct IrInstructionArrayType {
3087 IrInstruction base;
3308struct IrInstSrcArrayType {
3309 IrInstSrc base;
30883310
3089 IrInstruction *size;
3090 IrInstruction *sentinel;
3091 IrInstruction *child_type;
3311 IrInstSrc *size;
3312 IrInstSrc *sentinel;
3313 IrInstSrc *child_type;
30923314};
30933315
3094struct IrInstructionPtrType {
3095 IrInstruction base;
3316struct IrInstSrcPtrType {
3317 IrInstSrc base;
30963318
3097 IrInstruction *sentinel;
3098 IrInstruction *align_value;
3099 IrInstruction *child_type;
3319 IrInstSrc *sentinel;
3320 IrInstSrc *align_value;
3321 IrInstSrc *child_type;
31003322 uint32_t bit_offset_start;
31013323 uint32_t host_int_bytes;
31023324 PtrLen ptr_len;
......@@ -3105,375 +3327,459 @@ struct IrInstructionPtrType {
31053327 bool is_allow_zero;
31063328};
31073329
3108struct IrInstructionAnyFrameType {
3109 IrInstruction base;
3330struct IrInstSrcAnyFrameType {
3331 IrInstSrc base;
31103332
3111 IrInstruction *payload_type;
3333 IrInstSrc *payload_type;
31123334};
31133335
3114struct IrInstructionSliceType {
3115 IrInstruction base;
3336struct IrInstSrcSliceType {
3337 IrInstSrc base;
31163338
3117 IrInstruction *sentinel;
3118 IrInstruction *align_value;
3119 IrInstruction *child_type;
3339 IrInstSrc *sentinel;
3340 IrInstSrc *align_value;
3341 IrInstSrc *child_type;
31203342 bool is_const;
31213343 bool is_volatile;
31223344 bool is_allow_zero;
31233345};
31243346
3125struct IrInstructionAsmSrc {
3126 IrInstruction base;
3347struct IrInstSrcAsm {
3348 IrInstSrc base;
31273349
3128 IrInstruction *asm_template;
3129 IrInstruction **input_list;
3130 IrInstruction **output_types;
3350 IrInstSrc *asm_template;
3351 IrInstSrc **input_list;
3352 IrInstSrc **output_types;
31313353 ZigVar **output_vars;
31323354 size_t return_count;
31333355 bool has_side_effects;
31343356 bool is_global;
31353357};
31363358
3137struct IrInstructionAsmGen {
3138 IrInstruction base;
3359struct IrInstGenAsm {
3360 IrInstGen base;
31393361
31403362 Buf *asm_template;
31413363 AsmToken *token_list;
31423364 size_t token_list_len;
3143 IrInstruction **input_list;
3144 IrInstruction **output_types;
3365 IrInstGen **input_list;
3366 IrInstGen **output_types;
31453367 ZigVar **output_vars;
31463368 size_t return_count;
31473369 bool has_side_effects;
31483370};
31493371
3150struct IrInstructionSizeOf {
3151 IrInstruction base;
3372struct IrInstSrcSizeOf {
3373 IrInstSrc base;
31523374
3375 IrInstSrc *type_value;
31533376 bool bit_size;
3154 IrInstruction *type_value;
31553377};
31563378
31573379// returns true if nonnull, returns false if null
3158// this is so that `zeroes` sets maybe values to null
3159struct IrInstructionTestNonNull {
3160 IrInstruction base;
3380struct IrInstSrcTestNonNull {
3381 IrInstSrc base;
3382
3383 IrInstSrc *value;
3384};
3385
3386struct IrInstGenTestNonNull {
3387 IrInstGen base;
31613388
3162 IrInstruction *value;
3389 IrInstGen *value;
31633390};
31643391
31653392// Takes a pointer to an optional value, returns a pointer
31663393// to the payload.
3167struct IrInstructionOptionalUnwrapPtr {
3168 IrInstruction base;
3394struct IrInstSrcOptionalUnwrapPtr {
3395 IrInstSrc base;
3396
3397 IrInstSrc *base_ptr;
3398 bool safety_check_on;
3399 bool initializing;
3400};
31693401
3402struct IrInstGenOptionalUnwrapPtr {
3403 IrInstGen base;
3404
3405 IrInstGen *base_ptr;
31703406 bool safety_check_on;
31713407 bool initializing;
3172 IrInstruction *base_ptr;
31733408};
31743409
3175struct IrInstructionCtz {
3176 IrInstruction base;
3410struct IrInstSrcCtz {
3411 IrInstSrc base;
3412
3413 IrInstSrc *type;
3414 IrInstSrc *op;
3415};
3416
3417struct IrInstGenCtz {
3418 IrInstGen base;
3419
3420 IrInstGen *op;
3421};
3422
3423struct IrInstSrcClz {
3424 IrInstSrc base;
3425
3426 IrInstSrc *type;
3427 IrInstSrc *op;
3428};
3429
3430struct IrInstGenClz {
3431 IrInstGen base;
31773432
3178 IrInstruction *type;
3179 IrInstruction *op;
3433 IrInstGen *op;
31803434};
31813435
3182struct IrInstructionClz {
3183 IrInstruction base;
3436struct IrInstSrcPopCount {
3437 IrInstSrc base;
31843438
3185 IrInstruction *type;
3186 IrInstruction *op;
3439 IrInstSrc *type;
3440 IrInstSrc *op;
31873441};
31883442
3189struct IrInstructionPopCount {
3190 IrInstruction base;
3443struct IrInstGenPopCount {
3444 IrInstGen base;
31913445
3192 IrInstruction *type;
3193 IrInstruction *op;
3446 IrInstGen *op;
31943447};
31953448
3196struct IrInstructionUnionTag {
3197 IrInstruction base;
3449struct IrInstGenUnionTag {
3450 IrInstGen base;
31983451
3199 IrInstruction *value;
3452 IrInstGen *value;
32003453};
32013454
3202struct IrInstructionImport {
3203 IrInstruction base;
3455struct IrInstSrcImport {
3456 IrInstSrc base;
32043457
3205 IrInstruction *name;
3458 IrInstSrc *name;
32063459};
32073460
3208struct IrInstructionRef {
3209 IrInstruction base;
3461struct IrInstSrcRef {
3462 IrInstSrc base;
32103463
3211 IrInstruction *value;
3464 IrInstSrc *value;
32123465 bool is_const;
32133466 bool is_volatile;
32143467};
32153468
3216struct IrInstructionRefGen {
3217 IrInstruction base;
3469struct IrInstGenRef {
3470 IrInstGen base;
32183471
3219 IrInstruction *operand;
3220 IrInstruction *result_loc;
3472 IrInstGen *operand;
3473 IrInstGen *result_loc;
32213474};
32223475
3223struct IrInstructionCompileErr {
3224 IrInstruction base;
3476struct IrInstSrcCompileErr {
3477 IrInstSrc base;
32253478
3226 IrInstruction *msg;
3479 IrInstSrc *msg;
32273480};
32283481
3229struct IrInstructionCompileLog {
3230 IrInstruction base;
3482struct IrInstSrcCompileLog {
3483 IrInstSrc base;
32313484
32323485 size_t msg_count;
3233 IrInstruction **msg_list;
3486 IrInstSrc **msg_list;
32343487};
32353488
3236struct IrInstructionErrName {
3237 IrInstruction base;
3489struct IrInstSrcErrName {
3490 IrInstSrc base;
32383491
3239 IrInstruction *value;
3492 IrInstSrc *value;
32403493};
32413494
3242struct IrInstructionCImport {
3243 IrInstruction base;
3495struct IrInstGenErrName {
3496 IrInstGen base;
3497
3498 IrInstGen *value;
3499};
3500
3501struct IrInstSrcCImport {
3502 IrInstSrc base;
32443503};
32453504
3246struct IrInstructionCInclude {
3247 IrInstruction base;
3505struct IrInstSrcCInclude {
3506 IrInstSrc base;
32483507
3249 IrInstruction *name;
3508 IrInstSrc *name;
32503509};
32513510
3252struct IrInstructionCDefine {
3253 IrInstruction base;
3511struct IrInstSrcCDefine {
3512 IrInstSrc base;
32543513
3255 IrInstruction *name;
3256 IrInstruction *value;
3514 IrInstSrc *name;
3515 IrInstSrc *value;
32573516};
32583517
3259struct IrInstructionCUndef {
3260 IrInstruction base;
3518struct IrInstSrcCUndef {
3519 IrInstSrc base;
32613520
3262 IrInstruction *name;
3521 IrInstSrc *name;
32633522};
32643523
3265struct IrInstructionEmbedFile {
3266 IrInstruction base;
3524struct IrInstSrcEmbedFile {
3525 IrInstSrc base;
32673526
3268 IrInstruction *name;
3527 IrInstSrc *name;
32693528};
32703529
3271struct IrInstructionCmpxchgSrc {
3272 IrInstruction base;
3530struct IrInstSrcCmpxchg {
3531 IrInstSrc base;
32733532
32743533 bool is_weak;
3275 IrInstruction *type_value;
3276 IrInstruction *ptr;
3277 IrInstruction *cmp_value;
3278 IrInstruction *new_value;
3279 IrInstruction *success_order_value;
3280 IrInstruction *failure_order_value;
3534 IrInstSrc *type_value;
3535 IrInstSrc *ptr;
3536 IrInstSrc *cmp_value;
3537 IrInstSrc *new_value;
3538 IrInstSrc *success_order_value;
3539 IrInstSrc *failure_order_value;
32813540 ResultLoc *result_loc;
32823541};
32833542
3284struct IrInstructionCmpxchgGen {
3285 IrInstruction base;
3543struct IrInstGenCmpxchg {
3544 IrInstGen base;
32863545
3287 bool is_weak;
32883546 AtomicOrder success_order;
32893547 AtomicOrder failure_order;
3290 IrInstruction *ptr;
3291 IrInstruction *cmp_value;
3292 IrInstruction *new_value;
3293 IrInstruction *result_loc;
3548 IrInstGen *ptr;
3549 IrInstGen *cmp_value;
3550 IrInstGen *new_value;
3551 IrInstGen *result_loc;
3552 bool is_weak;
32943553};
32953554
3296struct IrInstructionFence {
3297 IrInstruction base;
3555struct IrInstSrcFence {
3556 IrInstSrc base;
3557
3558 IrInstSrc *order;
3559};
32983560
3299 IrInstruction *order_value;
3561struct IrInstGenFence {
3562 IrInstGen base;
33003563
3301 // if this instruction gets to runtime then we know these values:
33023564 AtomicOrder order;
33033565};
33043566
3305struct IrInstructionTruncate {
3306 IrInstruction base;
3567struct IrInstSrcTruncate {
3568 IrInstSrc base;
3569
3570 IrInstSrc *dest_type;
3571 IrInstSrc *target;
3572};
3573
3574struct IrInstGenTruncate {
3575 IrInstGen base;
33073576
3308 IrInstruction *dest_type;
3309 IrInstruction *target;
3577 IrInstGen *target;
33103578};
33113579
3312struct IrInstructionIntCast {
3313 IrInstruction base;
3580struct IrInstSrcIntCast {
3581 IrInstSrc base;
33143582
3315 IrInstruction *dest_type;
3316 IrInstruction *target;
3583 IrInstSrc *dest_type;
3584 IrInstSrc *target;
33173585};
33183586
3319struct IrInstructionFloatCast {
3320 IrInstruction base;
3587struct IrInstSrcFloatCast {
3588 IrInstSrc base;
33213589
3322 IrInstruction *dest_type;
3323 IrInstruction *target;
3590 IrInstSrc *dest_type;
3591 IrInstSrc *target;
33243592};
33253593
3326struct IrInstructionErrSetCast {
3327 IrInstruction base;
3594struct IrInstSrcErrSetCast {
3595 IrInstSrc base;
33283596
3329 IrInstruction *dest_type;
3330 IrInstruction *target;
3597 IrInstSrc *dest_type;
3598 IrInstSrc *target;
33313599};
33323600
3333struct IrInstructionToBytes {
3334 IrInstruction base;
3601struct IrInstSrcToBytes {
3602 IrInstSrc base;
33353603
3336 IrInstruction *target;
3604 IrInstSrc *target;
33373605 ResultLoc *result_loc;
33383606};
33393607
3340struct IrInstructionFromBytes {
3341 IrInstruction base;
3608struct IrInstSrcFromBytes {
3609 IrInstSrc base;
33423610
3343 IrInstruction *dest_child_type;
3344 IrInstruction *target;
3611 IrInstSrc *dest_child_type;
3612 IrInstSrc *target;
33453613 ResultLoc *result_loc;
33463614};
33473615
3348struct IrInstructionIntToFloat {
3349 IrInstruction base;
3616struct IrInstSrcIntToFloat {
3617 IrInstSrc base;
33503618
3351 IrInstruction *dest_type;
3352 IrInstruction *target;
3619 IrInstSrc *dest_type;
3620 IrInstSrc *target;
33533621};
33543622
3355struct IrInstructionFloatToInt {
3356 IrInstruction base;
3623struct IrInstSrcFloatToInt {
3624 IrInstSrc base;
33573625
3358 IrInstruction *dest_type;
3359 IrInstruction *target;
3626 IrInstSrc *dest_type;
3627 IrInstSrc *target;
33603628};
33613629
3362struct IrInstructionBoolToInt {
3363 IrInstruction base;
3630struct IrInstSrcBoolToInt {
3631 IrInstSrc base;
33643632
3365 IrInstruction *target;
3633 IrInstSrc *target;
33663634};
33673635
3368struct IrInstructionIntType {
3369 IrInstruction base;
3636struct IrInstSrcIntType {
3637 IrInstSrc base;
33703638
3371 IrInstruction *is_signed;
3372 IrInstruction *bit_count;
3639 IrInstSrc *is_signed;
3640 IrInstSrc *bit_count;
33733641};
33743642
3375struct IrInstructionVectorType {
3376 IrInstruction base;
3643struct IrInstSrcVectorType {
3644 IrInstSrc base;
33773645
3378 IrInstruction *len;
3379 IrInstruction *elem_type;
3646 IrInstSrc *len;
3647 IrInstSrc *elem_type;
33803648};
33813649
3382struct IrInstructionBoolNot {
3383 IrInstruction base;
3650struct IrInstSrcBoolNot {
3651 IrInstSrc base;
33843652
3385 IrInstruction *value;
3653 IrInstSrc *value;
33863654};
33873655
3388struct IrInstructionMemset {
3389 IrInstruction base;
3656struct IrInstGenBoolNot {
3657 IrInstGen base;
33903658
3391 IrInstruction *dest_ptr;
3392 IrInstruction *byte;
3393 IrInstruction *count;
3659 IrInstGen *value;
33943660};
33953661
3396struct IrInstructionMemcpy {
3397 IrInstruction base;
3662struct IrInstSrcMemset {
3663 IrInstSrc base;
33983664
3399 IrInstruction *dest_ptr;
3400 IrInstruction *src_ptr;
3401 IrInstruction *count;
3665 IrInstSrc *dest_ptr;
3666 IrInstSrc *byte;
3667 IrInstSrc *count;
34023668};
34033669
3404struct IrInstructionSliceSrc {
3405 IrInstruction base;
3670struct IrInstGenMemset {
3671 IrInstGen base;
34063672
3407 bool safety_check_on;
3408 IrInstruction *ptr;
3409 IrInstruction *start;
3410 IrInstruction *end;
3411 IrInstruction *sentinel;
3673 IrInstGen *dest_ptr;
3674 IrInstGen *byte;
3675 IrInstGen *count;
3676};
3677
3678struct IrInstSrcMemcpy {
3679 IrInstSrc base;
3680
3681 IrInstSrc *dest_ptr;
3682 IrInstSrc *src_ptr;
3683 IrInstSrc *count;
3684};
3685
3686struct IrInstGenMemcpy {
3687 IrInstGen base;
3688
3689 IrInstGen *dest_ptr;
3690 IrInstGen *src_ptr;
3691 IrInstGen *count;
3692};
3693
3694struct IrInstSrcSlice {
3695 IrInstSrc base;
3696
3697 IrInstSrc *ptr;
3698 IrInstSrc *start;
3699 IrInstSrc *end;
3700 IrInstSrc *sentinel;
34123701 ResultLoc *result_loc;
3702 bool safety_check_on;
34133703};
34143704
3415struct IrInstructionSliceGen {
3416 IrInstruction base;
3705struct IrInstGenSlice {
3706 IrInstGen base;
34173707
3708 IrInstGen *ptr;
3709 IrInstGen *start;
3710 IrInstGen *end;
3711 IrInstGen *result_loc;
34183712 bool safety_check_on;
3419 IrInstruction *ptr;
3420 IrInstruction *start;
3421 IrInstruction *end;
3422 IrInstruction *result_loc;
34233713};
34243714
3425struct IrInstructionMemberCount {
3426 IrInstruction base;
3715struct IrInstSrcMemberCount {
3716 IrInstSrc base;
3717
3718 IrInstSrc *container;
3719};
3720
3721struct IrInstSrcMemberType {
3722 IrInstSrc base;
34273723
3428 IrInstruction *container;
3724 IrInstSrc *container_type;
3725 IrInstSrc *member_index;
34293726};
34303727
3431struct IrInstructionMemberType {
3432 IrInstruction base;
3728struct IrInstSrcMemberName {
3729 IrInstSrc base;
3730
3731 IrInstSrc *container_type;
3732 IrInstSrc *member_index;
3733};
3734
3735struct IrInstSrcBreakpoint {
3736 IrInstSrc base;
3737};
34333738
3434 IrInstruction *container_type;
3435 IrInstruction *member_index;
3739struct IrInstGenBreakpoint {
3740 IrInstGen base;
34363741};
34373742
3438struct IrInstructionMemberName {
3439 IrInstruction base;
3743struct IrInstSrcReturnAddress {
3744 IrInstSrc base;
3745};
34403746
3441 IrInstruction *container_type;
3442 IrInstruction *member_index;
3747struct IrInstGenReturnAddress {
3748 IrInstGen base;
34433749};
34443750
3445struct IrInstructionBreakpoint {
3446 IrInstruction base;
3751struct IrInstSrcFrameAddress {
3752 IrInstSrc base;
34473753};
34483754
3449struct IrInstructionReturnAddress {
3450 IrInstruction base;
3755struct IrInstGenFrameAddress {
3756 IrInstGen base;
34513757};
34523758
3453struct IrInstructionFrameAddress {
3454 IrInstruction base;
3759struct IrInstSrcFrameHandle {
3760 IrInstSrc base;
34553761};
34563762
3457struct IrInstructionFrameHandle {
3458 IrInstruction base;
3763struct IrInstGenFrameHandle {
3764 IrInstGen base;
34593765};
34603766
3461struct IrInstructionFrameType {
3462 IrInstruction base;
3767struct IrInstSrcFrameType {
3768 IrInstSrc base;
34633769
3464 IrInstruction *fn;
3770 IrInstSrc *fn;
34653771};
34663772
3467struct IrInstructionFrameSizeSrc {
3468 IrInstruction base;
3773struct IrInstSrcFrameSize {
3774 IrInstSrc base;
34693775
3470 IrInstruction *fn;
3776 IrInstSrc *fn;
34713777};
34723778
3473struct IrInstructionFrameSizeGen {
3474 IrInstruction base;
3779struct IrInstGenFrameSize {
3780 IrInstGen base;
34753781
3476 IrInstruction *fn;
3782 IrInstGen *fn;
34773783};
34783784
34793785enum IrOverflowOp {
......@@ -3483,560 +3789,713 @@ enum IrOverflowOp {
34833789 IrOverflowOpShl,
34843790};
34853791
3486struct IrInstructionOverflowOp {
3487 IrInstruction base;
3792struct IrInstSrcOverflowOp {
3793 IrInstSrc base;
3794
3795 IrOverflowOp op;
3796 IrInstSrc *type_value;
3797 IrInstSrc *op1;
3798 IrInstSrc *op2;
3799 IrInstSrc *result_ptr;
3800};
3801
3802struct IrInstGenOverflowOp {
3803 IrInstGen base;
34883804
34893805 IrOverflowOp op;
3490 IrInstruction *type_value;
3491 IrInstruction *op1;
3492 IrInstruction *op2;
3493 IrInstruction *result_ptr;
3806 IrInstGen *op1;
3807 IrInstGen *op2;
3808 IrInstGen *result_ptr;
34943809
3810 // TODO can this field be removed?
34953811 ZigType *result_ptr_type;
34963812};
34973813
3498struct IrInstructionMulAdd {
3499 IrInstruction base;
3814struct IrInstSrcMulAdd {
3815 IrInstSrc base;
3816
3817 IrInstSrc *type_value;
3818 IrInstSrc *op1;
3819 IrInstSrc *op2;
3820 IrInstSrc *op3;
3821};
3822
3823struct IrInstGenMulAdd {
3824 IrInstGen base;
35003825
3501 IrInstruction *type_value;
3502 IrInstruction *op1;
3503 IrInstruction *op2;
3504 IrInstruction *op3;
3826 IrInstGen *op1;
3827 IrInstGen *op2;
3828 IrInstGen *op3;
35053829};
35063830
3507struct IrInstructionAlignOf {
3508 IrInstruction base;
3831struct IrInstSrcAlignOf {
3832 IrInstSrc base;
35093833
3510 IrInstruction *type_value;
3834 IrInstSrc *type_value;
35113835};
35123836
35133837// returns true if error, returns false if not error
3514struct IrInstructionTestErrSrc {
3515 IrInstruction base;
3838struct IrInstSrcTestErr {
3839 IrInstSrc base;
35163840
3841 IrInstSrc *base_ptr;
35173842 bool resolve_err_set;
35183843 bool base_ptr_is_payload;
3519 IrInstruction *base_ptr;
35203844};
35213845
3522struct IrInstructionTestErrGen {
3523 IrInstruction base;
3846struct IrInstGenTestErr {
3847 IrInstGen base;
35243848
3525 IrInstruction *err_union;
3849 IrInstGen *err_union;
35263850};
35273851
35283852// Takes an error union pointer, returns a pointer to the error code.
3529struct IrInstructionUnwrapErrCode {
3530 IrInstruction base;
3853struct IrInstSrcUnwrapErrCode {
3854 IrInstSrc base;
35313855
3856 IrInstSrc *err_union_ptr;
35323857 bool initializing;
3533 IrInstruction *err_union_ptr;
35343858};
35353859
3536struct IrInstructionUnwrapErrPayload {
3537 IrInstruction base;
3860struct IrInstGenUnwrapErrCode {
3861 IrInstGen base;
35383862
3863 IrInstGen *err_union_ptr;
3864 bool initializing;
3865};
3866
3867struct IrInstSrcUnwrapErrPayload {
3868 IrInstSrc base;
3869
3870 IrInstSrc *value;
3871 bool safety_check_on;
3872 bool initializing;
3873};
3874
3875struct IrInstGenUnwrapErrPayload {
3876 IrInstGen base;
3877
3878 IrInstGen *value;
35393879 bool safety_check_on;
35403880 bool initializing;
3541 IrInstruction *value;
35423881};
35433882
3544struct IrInstructionOptionalWrap {
3545 IrInstruction base;
3883struct IrInstGenOptionalWrap {
3884 IrInstGen base;
35463885
3547 IrInstruction *operand;
3548 IrInstruction *result_loc;
3886 IrInstGen *operand;
3887 IrInstGen *result_loc;
35493888};
35503889
3551struct IrInstructionErrWrapPayload {
3552 IrInstruction base;
3890struct IrInstGenErrWrapPayload {
3891 IrInstGen base;
35533892
3554 IrInstruction *operand;
3555 IrInstruction *result_loc;
3893 IrInstGen *operand;
3894 IrInstGen *result_loc;
35563895};
35573896
3558struct IrInstructionErrWrapCode {
3559 IrInstruction base;
3897struct IrInstGenErrWrapCode {
3898 IrInstGen base;
35603899
3561 IrInstruction *operand;
3562 IrInstruction *result_loc;
3900 IrInstGen *operand;
3901 IrInstGen *result_loc;
35633902};
35643903
3565struct IrInstructionFnProto {
3566 IrInstruction base;
3904struct IrInstSrcFnProto {
3905 IrInstSrc base;
35673906
3568 IrInstruction **param_types;
3569 IrInstruction *align_value;
3570 IrInstruction *callconv_value;
3571 IrInstruction *return_type;
3907 IrInstSrc **param_types;
3908 IrInstSrc *align_value;
3909 IrInstSrc *callconv_value;
3910 IrInstSrc *return_type;
35723911 bool is_var_args;
35733912};
35743913
35753914// true if the target value is compile time known, false otherwise
3576struct IrInstructionTestComptime {
3577 IrInstruction base;
3915struct IrInstSrcTestComptime {
3916 IrInstSrc base;
35783917
3579 IrInstruction *value;
3918 IrInstSrc *value;
35803919};
35813920
3582struct IrInstructionPtrCastSrc {
3583 IrInstruction base;
3921struct IrInstSrcPtrCast {
3922 IrInstSrc base;
35843923
3585 IrInstruction *dest_type;
3586 IrInstruction *ptr;
3924 IrInstSrc *dest_type;
3925 IrInstSrc *ptr;
35873926 bool safety_check_on;
35883927};
35893928
3590struct IrInstructionPtrCastGen {
3591 IrInstruction base;
3929struct IrInstGenPtrCast {
3930 IrInstGen base;
35923931
3593 IrInstruction *ptr;
3932 IrInstGen *ptr;
35943933 bool safety_check_on;
35953934};
35963935
3597struct IrInstructionImplicitCast {
3598 IrInstruction base;
3936struct IrInstSrcImplicitCast {
3937 IrInstSrc base;
35993938
3600 IrInstruction *operand;
3939 IrInstSrc *operand;
36013940 ResultLocCast *result_loc_cast;
36023941};
36033942
3604struct IrInstructionBitCastSrc {
3605 IrInstruction base;
3943struct IrInstSrcBitCast {
3944 IrInstSrc base;
36063945
3607 IrInstruction *operand;
3946 IrInstSrc *operand;
36083947 ResultLocBitCast *result_loc_bit_cast;
36093948};
36103949
3611struct IrInstructionBitCastGen {
3612 IrInstruction base;
3950struct IrInstGenBitCast {
3951 IrInstGen base;
3952
3953 IrInstGen *operand;
3954};
3955
3956struct IrInstGenWidenOrShorten {
3957 IrInstGen base;
3958
3959 IrInstGen *target;
3960};
3961
3962struct IrInstSrcPtrToInt {
3963 IrInstSrc base;
3964
3965 IrInstSrc *target;
3966};
3967
3968struct IrInstGenPtrToInt {
3969 IrInstGen base;
3970
3971 IrInstGen *target;
3972};
3973
3974struct IrInstSrcIntToPtr {
3975 IrInstSrc base;
3976
3977 IrInstSrc *dest_type;
3978 IrInstSrc *target;
3979};
3980
3981struct IrInstGenIntToPtr {
3982 IrInstGen base;
36133983
3614 IrInstruction *operand;
3984 IrInstGen *target;
36153985};
36163986
3617struct IrInstructionWidenOrShorten {
3618 IrInstruction base;
3987struct IrInstSrcIntToEnum {
3988 IrInstSrc base;
36193989
3620 IrInstruction *target;
3990 IrInstSrc *dest_type;
3991 IrInstSrc *target;
36213992};
36223993
3623struct IrInstructionPtrToInt {
3624 IrInstruction base;
3994struct IrInstGenIntToEnum {
3995 IrInstGen base;
36253996
3626 IrInstruction *target;
3997 IrInstGen *target;
36273998};
36283999
3629struct IrInstructionIntToPtr {
3630 IrInstruction base;
4000struct IrInstSrcEnumToInt {
4001 IrInstSrc base;
36314002
3632 IrInstruction *dest_type;
3633 IrInstruction *target;
4003 IrInstSrc *target;
36344004};
36354005
3636struct IrInstructionIntToEnum {
3637 IrInstruction base;
4006struct IrInstSrcIntToErr {
4007 IrInstSrc base;
36384008
3639 IrInstruction *dest_type;
3640 IrInstruction *target;
4009 IrInstSrc *target;
36414010};
36424011
3643struct IrInstructionEnumToInt {
3644 IrInstruction base;
4012struct IrInstGenIntToErr {
4013 IrInstGen base;
36454014
3646 IrInstruction *target;
4015 IrInstGen *target;
36474016};
36484017
3649struct IrInstructionIntToErr {
3650 IrInstruction base;
4018struct IrInstSrcErrToInt {
4019 IrInstSrc base;
36514020
3652 IrInstruction *target;
4021 IrInstSrc *target;
36534022};
36544023
3655struct IrInstructionErrToInt {
3656 IrInstruction base;
4024struct IrInstGenErrToInt {
4025 IrInstGen base;
36574026
3658 IrInstruction *target;
4027 IrInstGen *target;
36594028};
36604029
3661struct IrInstructionCheckSwitchProngsRange {
3662 IrInstruction *start;
3663 IrInstruction *end;
4030struct IrInstSrcCheckSwitchProngsRange {
4031 IrInstSrc *start;
4032 IrInstSrc *end;
36644033};
36654034
3666struct IrInstructionCheckSwitchProngs {
3667 IrInstruction base;
4035struct IrInstSrcCheckSwitchProngs {
4036 IrInstSrc base;
36684037
3669 IrInstruction *target_value;
3670 IrInstructionCheckSwitchProngsRange *ranges;
4038 IrInstSrc *target_value;
4039 IrInstSrcCheckSwitchProngsRange *ranges;
36714040 size_t range_count;
36724041 bool have_else_prong;
36734042 bool have_underscore_prong;
36744043};
36754044
3676struct IrInstructionCheckStatementIsVoid {
3677 IrInstruction base;
4045struct IrInstSrcCheckStatementIsVoid {
4046 IrInstSrc base;
36784047
3679 IrInstruction *statement_value;
4048 IrInstSrc *statement_value;
36804049};
36814050
3682struct IrInstructionTypeName {
3683 IrInstruction base;
4051struct IrInstSrcTypeName {
4052 IrInstSrc base;
36844053
3685 IrInstruction *type_value;
4054 IrInstSrc *type_value;
36864055};
36874056
3688struct IrInstructionDeclRef {
3689 IrInstruction base;
4057struct IrInstSrcDeclRef {
4058 IrInstSrc base;
36904059
36914060 LVal lval;
36924061 Tld *tld;
36934062};
36944063
3695struct IrInstructionPanic {
3696 IrInstruction base;
4064struct IrInstSrcPanic {
4065 IrInstSrc base;
4066
4067 IrInstSrc *msg;
4068};
4069
4070struct IrInstGenPanic {
4071 IrInstGen base;
4072
4073 IrInstGen *msg;
4074};
4075
4076struct IrInstSrcTagName {
4077 IrInstSrc base;
4078
4079 IrInstSrc *target;
4080};
4081
4082struct IrInstGenTagName {
4083 IrInstGen base;
36974084
3698 IrInstruction *msg;
4085 IrInstGen *target;
36994086};
37004087
3701struct IrInstructionTagName {
3702 IrInstruction base;
4088struct IrInstSrcTagType {
4089 IrInstSrc base;
37034090
3704 IrInstruction *target;
4091 IrInstSrc *target;
37054092};
37064093
3707struct IrInstructionTagType {
3708 IrInstruction base;
4094struct IrInstSrcFieldParentPtr {
4095 IrInstSrc base;
37094096
3710 IrInstruction *target;
4097 IrInstSrc *type_value;
4098 IrInstSrc *field_name;
4099 IrInstSrc *field_ptr;
37114100};
37124101
3713struct IrInstructionFieldParentPtr {
3714 IrInstruction base;
4102struct IrInstGenFieldParentPtr {
4103 IrInstGen base;
37154104
3716 IrInstruction *type_value;
3717 IrInstruction *field_name;
3718 IrInstruction *field_ptr;
4105 IrInstGen *field_ptr;
37194106 TypeStructField *field;
37204107};
37214108
3722struct IrInstructionByteOffsetOf {
3723 IrInstruction base;
4109struct IrInstSrcByteOffsetOf {
4110 IrInstSrc base;
4111
4112 IrInstSrc *type_value;
4113 IrInstSrc *field_name;
4114};
4115
4116struct IrInstSrcBitOffsetOf {
4117 IrInstSrc base;
37244118
3725 IrInstruction *type_value;
3726 IrInstruction *field_name;
4119 IrInstSrc *type_value;
4120 IrInstSrc *field_name;
37274121};
37284122
3729struct IrInstructionBitOffsetOf {
3730 IrInstruction base;
4123struct IrInstSrcTypeInfo {
4124 IrInstSrc base;
37314125
3732 IrInstruction *type_value;
3733 IrInstruction *field_name;
4126 IrInstSrc *type_value;
37344127};
37354128
3736struct IrInstructionTypeInfo {
3737 IrInstruction base;
4129struct IrInstSrcType {
4130 IrInstSrc base;
37384131
3739 IrInstruction *type_value;
4132 IrInstSrc *type_info;
37404133};
37414134
3742struct IrInstructionType {
3743 IrInstruction base;
4135struct IrInstSrcHasField {
4136 IrInstSrc base;
37444137
3745 IrInstruction *type_info;
4138 IrInstSrc *container_type;
4139 IrInstSrc *field_name;
37464140};
37474141
3748struct IrInstructionHasField {
3749 IrInstruction base;
4142struct IrInstSrcTypeId {
4143 IrInstSrc base;
37504144
3751 IrInstruction *container_type;
3752 IrInstruction *field_name;
4145 IrInstSrc *type_value;
37534146};
37544147
3755struct IrInstructionTypeId {
3756 IrInstruction base;
4148struct IrInstSrcSetEvalBranchQuota {
4149 IrInstSrc base;
37574150
3758 IrInstruction *type_value;
4151 IrInstSrc *new_quota;
37594152};
37604153
3761struct IrInstructionSetEvalBranchQuota {
3762 IrInstruction base;
4154struct IrInstSrcAlignCast {
4155 IrInstSrc base;
37634156
3764 IrInstruction *new_quota;
4157 IrInstSrc *align_bytes;
4158 IrInstSrc *target;
37654159};
37664160
3767struct IrInstructionAlignCast {
3768 IrInstruction base;
4161struct IrInstGenAlignCast {
4162 IrInstGen base;
37694163
3770 IrInstruction *align_bytes;
3771 IrInstruction *target;
4164 IrInstGen *target;
37724165};
37734166
3774struct IrInstructionOpaqueType {
3775 IrInstruction base;
4167struct IrInstSrcOpaqueType {
4168 IrInstSrc base;
37764169};
37774170
3778struct IrInstructionSetAlignStack {
3779 IrInstruction base;
4171struct IrInstSrcSetAlignStack {
4172 IrInstSrc base;
37804173
3781 IrInstruction *align_bytes;
4174 IrInstSrc *align_bytes;
37824175};
37834176
3784struct IrInstructionArgType {
3785 IrInstruction base;
4177struct IrInstSrcArgType {
4178 IrInstSrc base;
37864179
3787 IrInstruction *fn_type;
3788 IrInstruction *arg_index;
4180 IrInstSrc *fn_type;
4181 IrInstSrc *arg_index;
37894182 bool allow_var;
37904183};
37914184
3792struct IrInstructionExport {
3793 IrInstruction base;
4185struct IrInstSrcExport {
4186 IrInstSrc base;
4187
4188 IrInstSrc *target;
4189 IrInstSrc *options;
4190};
4191
4192enum IrInstErrorReturnTraceOptional {
4193 IrInstErrorReturnTraceNull,
4194 IrInstErrorReturnTraceNonNull,
4195};
4196
4197struct IrInstSrcErrorReturnTrace {
4198 IrInstSrc base;
37944199
3795 IrInstruction *target;
3796 IrInstruction *options;
4200 IrInstErrorReturnTraceOptional optional;
37974201};
37984202
3799struct IrInstructionErrorReturnTrace {
3800 IrInstruction base;
4203struct IrInstGenErrorReturnTrace {
4204 IrInstGen base;
38014205
3802 enum Optional {
3803 Null,
3804 NonNull,
3805 } optional;
4206 IrInstErrorReturnTraceOptional optional;
38064207};
38074208
3808struct IrInstructionErrorUnion {
3809 IrInstruction base;
4209struct IrInstSrcErrorUnion {
4210 IrInstSrc base;
38104211
3811 IrInstruction *err_set;
3812 IrInstruction *payload;
4212 IrInstSrc *err_set;
4213 IrInstSrc *payload;
38134214 Buf *type_name;
38144215};
38154216
3816struct IrInstructionAtomicRmw {
3817 IrInstruction base;
4217struct IrInstSrcAtomicRmw {
4218 IrInstSrc base;
4219
4220 IrInstSrc *operand_type;
4221 IrInstSrc *ptr;
4222 IrInstSrc *op;
4223 IrInstSrc *operand;
4224 IrInstSrc *ordering;
4225};
4226
4227struct IrInstGenAtomicRmw {
4228 IrInstGen base;
4229
4230 IrInstGen *ptr;
4231 IrInstGen *operand;
4232 AtomicRmwOp op;
4233 AtomicOrder ordering;
4234};
4235
4236struct IrInstSrcAtomicLoad {
4237 IrInstSrc base;
4238
4239 IrInstSrc *operand_type;
4240 IrInstSrc *ptr;
4241 IrInstSrc *ordering;
4242};
4243
4244struct IrInstGenAtomicLoad {
4245 IrInstGen base;
38184246
3819 IrInstruction *operand_type;
3820 IrInstruction *ptr;
3821 IrInstruction *op;
3822 AtomicRmwOp resolved_op;
3823 IrInstruction *operand;
3824 IrInstruction *ordering;
3825 AtomicOrder resolved_ordering;
4247 IrInstGen *ptr;
4248 AtomicOrder ordering;
38264249};
38274250
3828struct IrInstructionAtomicLoad {
3829 IrInstruction base;
4251struct IrInstSrcAtomicStore {
4252 IrInstSrc base;
38304253
3831 IrInstruction *operand_type;
3832 IrInstruction *ptr;
3833 IrInstruction *ordering;
3834 AtomicOrder resolved_ordering;
4254 IrInstSrc *operand_type;
4255 IrInstSrc *ptr;
4256 IrInstSrc *value;
4257 IrInstSrc *ordering;
38354258};
38364259
3837struct IrInstructionAtomicStore {
3838 IrInstruction base;
4260struct IrInstGenAtomicStore {
4261 IrInstGen base;
4262
4263 IrInstGen *ptr;
4264 IrInstGen *value;
4265 AtomicOrder ordering;
4266};
38394267
3840 IrInstruction *operand_type;
3841 IrInstruction *ptr;
3842 IrInstruction *value;
3843 IrInstruction *ordering;
3844 AtomicOrder resolved_ordering;
4268struct IrInstSrcSaveErrRetAddr {
4269 IrInstSrc base;
38454270};
38464271
3847struct IrInstructionSaveErrRetAddr {
3848 IrInstruction base;
4272struct IrInstGenSaveErrRetAddr {
4273 IrInstGen base;
38494274};
38504275
3851struct IrInstructionAddImplicitReturnType {
3852 IrInstruction base;
4276struct IrInstSrcAddImplicitReturnType {
4277 IrInstSrc base;
38534278
3854 IrInstruction *value;
4279 IrInstSrc *value;
38554280 ResultLocReturn *result_loc_ret;
38564281};
38574282
3858// For float ops which take a single argument
3859struct IrInstructionFloatOp {
3860 IrInstruction base;
4283// For float ops that take a single argument
4284struct IrInstSrcFloatOp {
4285 IrInstSrc base;
4286
4287 IrInstSrc *operand;
4288 BuiltinFnId fn_id;
4289};
4290
4291struct IrInstGenFloatOp {
4292 IrInstGen base;
38614293
4294 IrInstGen *operand;
38624295 BuiltinFnId fn_id;
3863 IrInstruction *operand;
38644296};
38654297
3866struct IrInstructionCheckRuntimeScope {
3867 IrInstruction base;
4298struct IrInstSrcCheckRuntimeScope {
4299 IrInstSrc base;
4300
4301 IrInstSrc *scope_is_comptime;
4302 IrInstSrc *is_comptime;
4303};
4304
4305struct IrInstSrcBswap {
4306 IrInstSrc base;
4307
4308 IrInstSrc *type;
4309 IrInstSrc *op;
4310};
4311
4312struct IrInstGenBswap {
4313 IrInstGen base;
4314
4315 IrInstGen *op;
4316};
4317
4318struct IrInstSrcBitReverse {
4319 IrInstSrc base;
38684320
3869 IrInstruction *scope_is_comptime;
3870 IrInstruction *is_comptime;
4321 IrInstSrc *type;
4322 IrInstSrc *op;
38714323};
38724324
3873struct IrInstructionBswap {
3874 IrInstruction base;
4325struct IrInstGenBitReverse {
4326 IrInstGen base;
38754327
3876 IrInstruction *type;
3877 IrInstruction *op;
4328 IrInstGen *op;
38784329};
38794330
3880struct IrInstructionBitReverse {
3881 IrInstruction base;
4331struct IrInstGenArrayToVector {
4332 IrInstGen base;
38824333
3883 IrInstruction *type;
3884 IrInstruction *op;
4334 IrInstGen *array;
38854335};
38864336
3887struct IrInstructionArrayToVector {
3888 IrInstruction base;
4337struct IrInstGenVectorToArray {
4338 IrInstGen base;
38894339
3890 IrInstruction *array;
4340 IrInstGen *vector;
4341 IrInstGen *result_loc;
38914342};
38924343
3893struct IrInstructionVectorToArray {
3894 IrInstruction base;
4344struct IrInstSrcShuffleVector {
4345 IrInstSrc base;
38954346
3896 IrInstruction *vector;
3897 IrInstruction *result_loc;
4347 IrInstSrc *scalar_type;
4348 IrInstSrc *a;
4349 IrInstSrc *b;
4350 IrInstSrc *mask; // This is in zig-format, not llvm format
38984351};
38994352
3900struct IrInstructionShuffleVector {
3901 IrInstruction base;
4353struct IrInstGenShuffleVector {
4354 IrInstGen base;
39024355
3903 IrInstruction *scalar_type;
3904 IrInstruction *a;
3905 IrInstruction *b;
3906 IrInstruction *mask; // This is in zig-format, not llvm format
4356 IrInstGen *a;
4357 IrInstGen *b;
4358 IrInstGen *mask; // This is in zig-format, not llvm format
39074359};
39084360
3909struct IrInstructionSplatSrc {
3910 IrInstruction base;
4361struct IrInstSrcSplat {
4362 IrInstSrc base;
39114363
3912 IrInstruction *len;
3913 IrInstruction *scalar;
4364 IrInstSrc *len;
4365 IrInstSrc *scalar;
39144366};
39154367
3916struct IrInstructionSplatGen {
3917 IrInstruction base;
4368struct IrInstGenSplat {
4369 IrInstGen base;
39184370
3919 IrInstruction *scalar;
4371 IrInstGen *scalar;
39204372};
39214373
3922struct IrInstructionAssertZero {
3923 IrInstruction base;
4374struct IrInstGenAssertZero {
4375 IrInstGen base;
39244376
3925 IrInstruction *target;
4377 IrInstGen *target;
39264378};
39274379
3928struct IrInstructionAssertNonNull {
3929 IrInstruction base;
4380struct IrInstGenAssertNonNull {
4381 IrInstGen base;
39304382
3931 IrInstruction *target;
4383 IrInstGen *target;
39324384};
39334385
3934struct IrInstructionUnionInitNamedField {
3935 IrInstruction base;
4386struct IrInstSrcUnionInitNamedField {
4387 IrInstSrc base;
39364388
3937 IrInstruction *union_type;
3938 IrInstruction *field_name;
3939 IrInstruction *field_result_loc;
3940 IrInstruction *result_loc;
4389 IrInstSrc *union_type;
4390 IrInstSrc *field_name;
4391 IrInstSrc *field_result_loc;
4392 IrInstSrc *result_loc;
39414393};
39424394
3943struct IrInstructionHasDecl {
3944 IrInstruction base;
4395struct IrInstSrcHasDecl {
4396 IrInstSrc base;
39454397
3946 IrInstruction *container;
3947 IrInstruction *name;
4398 IrInstSrc *container;
4399 IrInstSrc *name;
39484400};
39494401
3950struct IrInstructionUndeclaredIdent {
3951 IrInstruction base;
4402struct IrInstSrcUndeclaredIdent {
4403 IrInstSrc base;
39524404
39534405 Buf *name;
39544406};
39554407
3956struct IrInstructionAllocaSrc {
3957 IrInstruction base;
4408struct IrInstSrcAlloca {
4409 IrInstSrc base;
39584410
3959 IrInstruction *align;
3960 IrInstruction *is_comptime;
4411 IrInstSrc *align;
4412 IrInstSrc *is_comptime;
39614413 const char *name_hint;
39624414};
39634415
3964struct IrInstructionAllocaGen {
3965 IrInstruction base;
4416struct IrInstGenAlloca {
4417 IrInstGen base;
39664418
39674419 uint32_t align;
39684420 const char *name_hint;
39694421 size_t field_index;
39704422};
39714423
3972struct IrInstructionEndExpr {
3973 IrInstruction base;
4424struct IrInstSrcEndExpr {
4425 IrInstSrc base;
39744426
3975 IrInstruction *value;
4427 IrInstSrc *value;
39764428 ResultLoc *result_loc;
39774429};
39784430
39794431// This one is for writing through the result pointer.
3980struct IrInstructionResolveResult {
3981 IrInstruction base;
4432struct IrInstSrcResolveResult {
4433 IrInstSrc base;
39824434
39834435 ResultLoc *result_loc;
3984 IrInstruction *ty;
4436 IrInstSrc *ty;
39854437};
39864438
3987// This one is when you want to read the value of the result.
3988// You have to give the value in case it is comptime.
3989struct IrInstructionResultPtr {
3990 IrInstruction base;
4439struct IrInstSrcResetResult {
4440 IrInstSrc base;
39914441
39924442 ResultLoc *result_loc;
3993 IrInstruction *result;
39944443};
39954444
3996struct IrInstructionResetResult {
3997 IrInstruction base;
4445struct IrInstGenPtrOfArrayToSlice {
4446 IrInstGen base;
39984447
3999 ResultLoc *result_loc;
4448 IrInstGen *operand;
4449 IrInstGen *result_loc;
40004450};
40014451
4002struct IrInstructionPtrOfArrayToSlice {
4003 IrInstruction base;
4004
4005 IrInstruction *operand;
4006 IrInstruction *result_loc;
4452struct IrInstSrcSuspendBegin {
4453 IrInstSrc base;
40074454};
40084455
4009struct IrInstructionSuspendBegin {
4010 IrInstruction base;
4456struct IrInstGenSuspendBegin {
4457 IrInstGen base;
40114458
40124459 LLVMBasicBlockRef resume_bb;
40134460};
40144461
4015struct IrInstructionSuspendFinish {
4016 IrInstruction base;
4462struct IrInstSrcSuspendFinish {
4463 IrInstSrc base;
4464
4465 IrInstSrcSuspendBegin *begin;
4466};
4467
4468struct IrInstGenSuspendFinish {
4469 IrInstGen base;
40174470
4018 IrInstructionSuspendBegin *begin;
4471 IrInstGenSuspendBegin *begin;
40194472};
40204473
4021struct IrInstructionAwaitSrc {
4022 IrInstruction base;
4474struct IrInstSrcAwait {
4475 IrInstSrc base;
40234476
4024 IrInstruction *frame;
4477 IrInstSrc *frame;
40254478 ResultLoc *result_loc;
40264479};
40274480
4028struct IrInstructionAwaitGen {
4029 IrInstruction base;
4481struct IrInstGenAwait {
4482 IrInstGen base;
40304483
4031 IrInstruction *frame;
4032 IrInstruction *result_loc;
4484 IrInstGen *frame;
4485 IrInstGen *result_loc;
40334486 ZigFn *target_fn;
40344487};
40354488
4036struct IrInstructionResume {
4037 IrInstruction base;
4489struct IrInstSrcResume {
4490 IrInstSrc base;
4491
4492 IrInstSrc *frame;
4493};
4494
4495struct IrInstGenResume {
4496 IrInstGen base;
40384497
4039 IrInstruction *frame;
4498 IrInstGen *frame;
40404499};
40414500
40424501enum SpillId {
......@@ -4044,24 +4503,37 @@ enum SpillId {
40444503 SpillIdRetErrCode,
40454504};
40464505
4047struct IrInstructionSpillBegin {
4048 IrInstruction base;
4506struct IrInstSrcSpillBegin {
4507 IrInstSrc base;
4508
4509 IrInstSrc *operand;
4510 SpillId spill_id;
4511};
4512
4513struct IrInstGenSpillBegin {
4514 IrInstGen base;
40494515
40504516 SpillId spill_id;
4051 IrInstruction *operand;
4517 IrInstGen *operand;
4518};
4519
4520struct IrInstSrcSpillEnd {
4521 IrInstSrc base;
4522
4523 IrInstSrcSpillBegin *begin;
40524524};
40534525
4054struct IrInstructionSpillEnd {
4055 IrInstruction base;
4526struct IrInstGenSpillEnd {
4527 IrInstGen base;
40564528
4057 IrInstructionSpillBegin *begin;
4529 IrInstGenSpillBegin *begin;
40584530};
40594531
4060struct IrInstructionVectorExtractElem {
4061 IrInstruction base;
4532struct IrInstGenVectorExtractElem {
4533 IrInstGen base;
40624534
4063 IrInstruction *vector;
4064 IrInstruction *index;
4535 IrInstGen *vector;
4536 IrInstGen *index;
40654537};
40664538
40674539enum ResultLocId {
......@@ -4082,9 +4554,9 @@ struct ResultLoc {
40824554 ResultLocId id;
40834555 bool written;
40844556 bool allow_write_through_const;
4085 IrInstruction *resolved_loc; // result ptr
4086 IrInstruction *source_instruction;
4087 IrInstruction *gen_instruction; // value to store to the result loc
4557 IrInstGen *resolved_loc; // result ptr
4558 IrInstSrc *source_instruction;
4559 IrInstGen *gen_instruction; // value to store to the result loc
40884560 ZigType *implicit_elem_type;
40894561};
40904562
......@@ -4114,18 +4586,18 @@ struct ResultLocPeerParent {
41144586
41154587 bool skipped;
41164588 bool done_resuming;
4117 IrBasicBlock *end_bb;
4589 IrBasicBlockSrc *end_bb;
41184590 ResultLoc *parent;
41194591 ZigList<ResultLocPeer *> peers;
41204592 ZigType *resolved_type;
4121 IrInstruction *is_comptime;
4593 IrInstSrc *is_comptime;
41224594};
41234595
41244596struct ResultLocPeer {
41254597 ResultLoc base;
41264598
41274599 ResultLocPeerParent *parent;
4128 IrBasicBlock *next_bb;
4600 IrBasicBlockSrc *next_bb;
41294601 IrSuspendPosition suspend_pos;
41304602};
41314603
......@@ -4196,7 +4668,7 @@ struct FnWalkAttrs {
41964668struct FnWalkCall {
41974669 ZigList<LLVMValueRef> *gen_param_values;
41984670 ZigList<ZigType *> *gen_param_types;
4199 IrInstructionCallGen *inst;
4671 IrInstGenCall *inst;
42004672 bool is_var_args;
42014673};
42024674
src/analyze.cpp+94-61
......@@ -199,7 +199,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
199199 return scope;
200200}
201201
202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime) {
202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime) {
203203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);
204204 scope->is_comptime = is_comptime;
205205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);
......@@ -3350,7 +3350,7 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
33503350
33513351ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
33523352 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");
3353 fn_entry->ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");
3353 fn_entry->ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
33543354
33553355 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
33563356
......@@ -4097,7 +4097,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
40974097 if (type_is_invalid(result->type)) {
40984098 dest_decls_scope->any_imports_failed = true;
40994099 using_namespace->base.resolution = TldResolutionInvalid;
4100 using_namespace->using_namespace_value = g->invalid_instruction->value;
4100 using_namespace->using_namespace_value = g->invalid_inst_gen->value;
41014101 return;
41024102 }
41034103
......@@ -4106,7 +4106,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
41064106 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));
41074107 dest_decls_scope->any_imports_failed = true;
41084108 using_namespace->base.resolution = TldResolutionInvalid;
4109 using_namespace->using_namespace_value = g->invalid_instruction->value;
4109 using_namespace->using_namespace_value = g->invalid_inst_gen->value;
41104110 return;
41114111 }
41124112}
......@@ -4667,12 +4667,12 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
46674667 }
46684668
46694669 for (size_t i = 0; i < fn->call_list.length; i += 1) {
4670 IrInstructionCallGen *call = fn->call_list.at(i);
4670 IrInstGenCall *call = fn->call_list.at(i);
46714671 if (call->fn_entry == nullptr) {
46724672 // TODO function pointer call here, could be anything
46734673 continue;
46744674 }
4675 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.source_node, must_not_be_async,
4675 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.base.source_node, must_not_be_async,
46764676 call->modifier))
46774677 {
46784678 case ErrorSemanticAnalyzeFail:
......@@ -4690,10 +4690,10 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
46904690 }
46914691 }
46924692 for (size_t i = 0; i < fn->await_list.length; i += 1) {
4693 IrInstructionAwaitGen *await = fn->await_list.at(i);
4693 IrInstGenAwait *await = fn->await_list.at(i);
46944694 // TODO If this is a noasync await, it doesn't count
46954695 // https://github.com/ziglang/zig/issues/3157
4696 switch (analyze_callee_async(g, fn, await->target_fn, await->base.source_node, must_not_be_async,
4696 switch (analyze_callee_async(g, fn, await->target_fn, await->base.base.source_node, must_not_be_async,
46974697 CallModifierNone))
46984698 {
46994699 case ErrorSemanticAnalyzeFail:
......@@ -4784,7 +4784,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
47844784
47854785 if (g->verbose_ir) {
47864786 fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name));
4787 ir_print(g, stderr, &fn->analyzed_executable, 4, IrPassGen);
4787 ir_print_gen(g, stderr, &fn->analyzed_executable, 4);
47884788 fprintf(stderr, "}\n");
47894789 }
47904790 fn->anal_state = FnAnalStateComplete;
......@@ -4827,7 +4827,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
48274827 fprintf(stderr, "\n");
48284828 ast_render(stderr, fn_table_entry->body_node, 4);
48294829 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));
4830 ir_print(g, stderr, fn_table_entry->ir_executable, 4, IrPassSrc);
4830 ir_print_src(g, stderr, fn_table_entry->ir_executable, 4);
48314831 fprintf(stderr, "}\n");
48324832 }
48334833
......@@ -6191,13 +6191,13 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
61916191 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
61926192
61936193 if (fn->analyzed_executable.need_err_code_spill) {
6194 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
6195 alloca_gen->base.id = IrInstructionIdAllocaGen;
6196 alloca_gen->base.source_node = fn->proto_node;
6197 alloca_gen->base.scope = fn->child_scope;
6194 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
6195 alloca_gen->base.id = IrInstGenIdAlloca;
6196 alloca_gen->base.base.source_node = fn->proto_node;
6197 alloca_gen->base.base.scope = fn->child_scope;
61986198 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
61996199 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
6200 alloca_gen->base.ref_count = 1;
6200 alloca_gen->base.base.ref_count = 1;
62016201 alloca_gen->name_hint = "";
62026202 fn->alloca_gen_list.append(alloca_gen);
62036203 fn->err_code_spill = &alloca_gen->base;
......@@ -6205,18 +6205,18 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62056205
62066206 ZigType *largest_call_frame_type = nullptr;
62076207 // Later we'll change this to be largest_call_frame_type instead of void.
6208 IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn->fndef_scope->base, fn->body_node,
6208 IrInstGen *all_calls_alloca = ir_create_alloca(g, &fn->fndef_scope->base, fn->body_node,
62096209 fn, g->builtin_types.entry_void, "@async_call_frame");
62106210
62116211 for (size_t i = 0; i < fn->call_list.length; i += 1) {
6212 IrInstructionCallGen *call = fn->call_list.at(i);
6212 IrInstGenCall *call = fn->call_list.at(i);
62136213 if (call->new_stack != nullptr) {
62146214 // don't need to allocate a frame for this
62156215 continue;
62166216 }
62176217 ZigFn *callee = call->fn_entry;
62186218 if (callee == nullptr) {
6219 add_node_error(g, call->base.source_node,
6219 add_node_error(g, call->base.base.source_node,
62206220 buf_sprintf("function is not comptime-known; @asyncCall required"));
62216221 return ErrorSemanticAnalyzeFail;
62226222 }
......@@ -6226,14 +6226,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62266226 if (callee->anal_state == FnAnalStateProbing) {
62276227 ErrorMsg *msg = add_node_error(g, fn->proto_node,
62286228 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));
6229 g->trace_err = add_error_note(g, msg, call->base.source_node,
6229 g->trace_err = add_error_note(g, msg, call->base.base.source_node,
62306230 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));
62316231 return ErrorSemanticAnalyzeFail;
62326232 }
62336233
62346234 ZigType *callee_frame_type = get_fn_frame_type(g, callee);
62356235 frame_type->data.frame.resolve_loop_type = callee_frame_type;
6236 frame_type->data.frame.resolve_loop_src_node = call->base.source_node;
6236 frame_type->data.frame.resolve_loop_src_node = call->base.base.source_node;
62376237
62386238 analyze_fn_body(g, callee);
62396239 if (callee->anal_state == FnAnalStateInvalid) {
......@@ -6249,7 +6249,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62496249 if (!fn_is_async(callee))
62506250 continue;
62516251
6252 mark_suspension_point(call->base.scope);
6252 mark_suspension_point(call->base.base.scope);
62536253
62546254 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {
62556255 return err;
......@@ -6271,7 +6271,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62716271 // For example: foo() + await z
62726272 // The funtion call result of foo() must be spilled.
62736273 for (size_t i = 0; i < fn->await_list.length; i += 1) {
6274 IrInstructionAwaitGen *await = fn->await_list.at(i);
6274 IrInstGenAwait *await = fn->await_list.at(i);
62756275 // TODO If this is a noasync await, it doesn't suspend
62766276 // https://github.com/ziglang/zig/issues/3157
62776277 if (await->base.value->special != ConstValSpecialRuntime) {
......@@ -6293,52 +6293,51 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62936293 }
62946294 // This await is a suspend point, but it might not need a spill.
62956295 // We do need to mark the ExprScope as having a suspend point in it.
6296 mark_suspension_point(await->base.scope);
6296 mark_suspension_point(await->base.base.scope);
62976297
62986298 if (await->result_loc != nullptr) {
62996299 // If there's a result location, that is the spill
63006300 continue;
63016301 }
6302 if (await->base.ref_count == 0)
6302 if (await->base.base.ref_count == 0)
63036303 continue;
63046304 if (!type_has_bits(await->base.value->type))
63056305 continue;
6306 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,
6306 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,
63076307 await->base.value->type, "");
63086308 }
63096309 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
6310 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);
6310 IrBasicBlockGen *block = fn->analyzed_executable.basic_block_list.at(block_i);
63116311 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6312 IrInstruction *instruction = block->instruction_list.at(instr_i);
6313 if (instruction->id == IrInstructionIdSuspendFinish) {
6314 mark_suspension_point(instruction->scope);
6312 IrInstGen *instruction = block->instruction_list.at(instr_i);
6313 if (instruction->id == IrInstGenIdSuspendFinish) {
6314 mark_suspension_point(instruction->base.scope);
63156315 }
63166316 }
63176317 }
63186318 // Now that we've marked all the expr scopes that have to spill, we go over the instructions
63196319 // and spill the relevant ones.
63206320 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
6321 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);
6321 IrBasicBlockGen *block = fn->analyzed_executable.basic_block_list.at(block_i);
63226322 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6323 IrInstruction *instruction = block->instruction_list.at(instr_i);
6324 if (instruction->id == IrInstructionIdAwaitGen ||
6325 instruction->id == IrInstructionIdVarPtr ||
6326 instruction->id == IrInstructionIdDeclRef ||
6327 instruction->id == IrInstructionIdAllocaGen)
6323 IrInstGen *instruction = block->instruction_list.at(instr_i);
6324 if (instruction->id == IrInstGenIdAwait ||
6325 instruction->id == IrInstGenIdVarPtr ||
6326 instruction->id == IrInstGenIdAlloca)
63286327 {
63296328 // This instruction does its own spilling specially, or otherwise doesn't need it.
63306329 continue;
63316330 }
63326331 if (instruction->value->special != ConstValSpecialRuntime)
63336332 continue;
6334 if (instruction->ref_count == 0)
6333 if (instruction->base.ref_count == 0)
63356334 continue;
63366335 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
63376336 return ErrorSemanticAnalyzeFail;
63386337 if (!type_has_bits(instruction->value->type))
63396338 continue;
6340 if (scope_needs_spill(instruction->scope)) {
6341 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,
6339 if (scope_needs_spill(instruction->base.scope)) {
6340 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,
63426341 fn, instruction->value->type, "");
63436342 }
63446343 }
......@@ -6389,14 +6388,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
63896388 }
63906389
63916390 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {
6392 IrInstructionAllocaGen *instruction = fn->alloca_gen_list.at(alloca_i);
6391 IrInstGenAlloca *instruction = fn->alloca_gen_list.at(alloca_i);
63936392 instruction->field_index = SIZE_MAX;
63946393 ZigType *ptr_type = instruction->base.value->type;
63956394 assert(ptr_type->id == ZigTypeIdPointer);
63966395 ZigType *child_type = ptr_type->data.pointer.child_type;
63976396 if (!type_has_bits(child_type))
63986397 continue;
6399 if (instruction->base.ref_count == 0)
6398 if (instruction->base.base.ref_count == 0)
64006399 continue;
64016400 if (instruction->base.value->special != ConstValSpecialRuntime) {
64026401 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
......@@ -6407,7 +6406,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
64076406 }
64086407
64096408 frame_type->data.frame.resolve_loop_type = child_type;
6410 frame_type->data.frame.resolve_loop_src_node = instruction->base.source_node;
6409 frame_type->data.frame.resolve_loop_src_node = instruction->base.base.source_node;
64116410 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
64126411 return err;
64136412 }
......@@ -6421,7 +6420,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
64216420 instruction->field_index = fields.length;
64226421
64236422 src_assert(child_type->id != ZigTypeIdPointer || child_type->data.pointer.inferred_struct_field == nullptr,
6424 instruction->base.source_node);
6423 instruction->base.base.source_node);
64256424 fields.append({name, child_type, instruction->align});
64266425 }
64276426
......@@ -6554,8 +6553,10 @@ bool ir_get_var_is_comptime(ZigVar *var) {
65546553 // As an optimization, is_comptime values which are constant are allowed
65556554 // to be omitted from analysis. In this case, there is no child instruction
65566555 // and we simply look at the unanalyzed const parent instruction.
6557 assert(var->is_comptime->value->type->id == ZigTypeIdBool);
6558 var->is_comptime_memoized_value = var->is_comptime->value->data.x_bool;
6556 assert(var->is_comptime->id == IrInstSrcIdConst);
6557 IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(var->is_comptime);
6558 assert(const_inst->value->type->id == ZigTypeIdBool);
6559 var->is_comptime_memoized_value = const_inst->value->data.x_bool;
65596560 var->is_comptime = nullptr;
65606561 return var->is_comptime_memoized_value;
65616562}
......@@ -9193,21 +9194,6 @@ void src_assert(bool ok, AstNode *source_node) {
91939194 stage2_panic(msg, strlen(msg));
91949195}
91959196
9196IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
9197 ZigType *var_type, const char *name_hint)
9198{
9199 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
9200 alloca_gen->base.id = IrInstructionIdAllocaGen;
9201 alloca_gen->base.source_node = source_node;
9202 alloca_gen->base.scope = scope;
9203 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
9204 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
9205 alloca_gen->base.ref_count = 1;
9206 alloca_gen->name_hint = name_hint;
9207 fn->alloca_gen_list.append(alloca_gen);
9208 return &alloca_gen->base;
9209}
9210
92119197Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
92129198 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path)
92139199{
......@@ -9268,8 +9254,17 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
92689254}
92699255
92709256
9271void IrExecutable::src() {
9272 IrExecutable *it;
9257void IrExecutableSrc::src() {
9258 if (this->source_node != nullptr) {
9259 this->source_node->src();
9260 }
9261 if (this->parent_exec != nullptr) {
9262 this->parent_exec->src();
9263 }
9264}
9265
9266void IrExecutableGen::src() {
9267 IrExecutableGen *it;
92739268 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {
92749269 it->source_node->src();
92759270 }
......@@ -9357,3 +9352,41 @@ bool type_is_numeric(ZigType *ty) {
93579352 }
93589353 zig_unreachable();
93599354}
9355
9356// float ops that take a single argument
9357//TODO Powi, Pow, minnum, maxnum, maximum, minimum, copysign, lround, llround, lrint, llrint
9358const char *float_op_to_name(BuiltinFnId op) {
9359 switch (op) {
9360 case BuiltinFnIdSqrt:
9361 return "sqrt";
9362 case BuiltinFnIdSin:
9363 return "sin";
9364 case BuiltinFnIdCos:
9365 return "cos";
9366 case BuiltinFnIdExp:
9367 return "exp";
9368 case BuiltinFnIdExp2:
9369 return "exp2";
9370 case BuiltinFnIdLog:
9371 return "log";
9372 case BuiltinFnIdLog10:
9373 return "log10";
9374 case BuiltinFnIdLog2:
9375 return "log2";
9376 case BuiltinFnIdFabs:
9377 return "fabs";
9378 case BuiltinFnIdFloor:
9379 return "floor";
9380 case BuiltinFnIdCeil:
9381 return "ceil";
9382 case BuiltinFnIdTrunc:
9383 return "trunc";
9384 case BuiltinFnIdNearbyInt:
9385 return "nearbyint";
9386 case BuiltinFnIdRound:
9387 return "round";
9388 default:
9389 zig_unreachable();
9390 }
9391}
9392
src/analyze.hpp+2-3
......@@ -120,7 +120,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
120120ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
121121ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
122122Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
123Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);
123Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime);
124124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
125125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126
......@@ -271,8 +271,6 @@ ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
271271
272272void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn);
273273
274IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
275 ZigType *var_type, const char *name_hint);
276274Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
277275 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
278276ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
......@@ -281,4 +279,5 @@ void copy_const_val(ZigValue *dest, ZigValue *src);
281279bool type_has_optional_repr(ZigType *ty);
282280bool is_opt_err_set(ZigType *ty);
283281bool type_is_numeric(ZigType *ty);
282const char *float_op_to_name(BuiltinFnId op);
284283#endif
src/codegen.cpp+408-475
......@@ -191,7 +191,7 @@ static void generate_error_name_table(CodeGen *g);
191191static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);
192192static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
193193static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);
194static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
194static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
195195 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
196196 LLVMValueRef result_loc, bool non_async);
197197static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix);
......@@ -877,14 +877,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type
877877 }
878878}
879879
880static void ir_assert(bool ok, IrInstruction *source_instruction) {
880static void ir_assert(bool ok, IrInstGen *source_instruction) {
881881 if (ok) return;
882 src_assert(ok, source_instruction->source_node);
882 src_assert(ok, source_instruction->base.source_node);
883883}
884884
885static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
885static bool ir_want_fast_math(CodeGen *g, IrInstGen *instruction) {
886886 // TODO memoize
887 Scope *scope = instruction->scope;
887 Scope *scope = instruction->base.scope;
888888 while (scope) {
889889 if (scope->id == ScopeIdBlock) {
890890 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -919,8 +919,8 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {
919919 g->build_mode != BuildModeSmallRelease);
920920}
921921
922static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
923 return ir_want_runtime_safety_scope(g, instruction->scope);
922static bool ir_want_runtime_safety(CodeGen *g, IrInstGen *instruction) {
923 return ir_want_runtime_safety_scope(g, instruction->base.scope);
924924}
925925
926926static Buf *panic_msg_buf(PanicMsgId msg_id) {
......@@ -1046,8 +1046,8 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco
10461046 }
10471047}
10481048
1049static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstruction *source_instruction) {
1050 return gen_assertion_scope(g, msg_id, source_instruction->scope);
1049static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstGen *source_instruction) {
1050 return gen_assertion_scope(g, msg_id, source_instruction->base.scope);
10511051}
10521052
10531053static LLVMValueRef get_stacksave_fn_val(CodeGen *g) {
......@@ -1761,7 +1761,7 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
17611761 LLVMGetInsertBlock(g->builder));
17621762}
17631763
1764static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1764static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstGen *instruction) {
17651765 Error err;
17661766
17671767 bool value_has_bits;
......@@ -1772,8 +1772,8 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
17721772 return nullptr;
17731773
17741774 if (!instruction->llvm_value) {
1775 if (instruction->id == IrInstructionIdAwaitGen) {
1776 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);
1775 if (instruction->id == IrInstGenIdAwait) {
1776 IrInstGenAwait *await = reinterpret_cast<IrInstGenAwait*>(instruction);
17771777 if (await->result_loc != nullptr) {
17781778 return get_handle_value(g, ir_llvm_value(g, await->result_loc),
17791779 await->result_loc->value->type->data.pointer.child_type, await->result_loc->value->type);
......@@ -1856,9 +1856,9 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
18561856 case FnWalkIdCall: {
18571857 if (src_i >= fn_walk->data.call.inst->arg_count)
18581858 return false;
1859 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];
1859 IrInstGen *arg = fn_walk->data.call.inst->args[src_i];
18601860 ty = arg->value->type;
1861 source_node = arg->source_node;
1861 source_node = arg->base.source_node;
18621862 val = ir_llvm_value(g, arg);
18631863 break;
18641864 }
......@@ -2091,10 +2091,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
20912091 return;
20922092 }
20932093 if (fn_walk->id == FnWalkIdCall) {
2094 IrInstructionCallGen *instruction = fn_walk->data.call.inst;
2094 IrInstGenCall *instruction = fn_walk->data.call.inst;
20952095 bool is_var_args = fn_walk->data.call.is_var_args;
20962096 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
2097 IrInstruction *param_instruction = instruction->args[call_i];
2097 IrInstGen *param_instruction = instruction->args[call_i];
20982098 ZigType *param_type = param_instruction->value->type;
20992099 if (is_var_args || type_has_bits(param_type)) {
21002100 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
......@@ -2309,14 +2309,14 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
23092309 return fn_val;
23102310
23112311}
2312static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,
2313 IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)
2312static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutableGen *executable,
2313 IrInstGenSaveErrRetAddr *save_err_ret_addr_instruction)
23142314{
23152315 assert(g->have_err_ret_tracing);
23162316
23172317 LLVMValueRef return_err_fn = get_return_err_fn(g);
23182318 bool is_llvm_alloca;
2319 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.scope,
2319 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.base.scope,
23202320 &is_llvm_alloca);
23212321 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,
23222322 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -2331,7 +2331,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut
23312331 return nullptr;
23322332}
23332333
2334static void gen_assert_resume_id(CodeGen *g, IrInstruction *source_instr, ResumeId resume_id, PanicMsgId msg_id,
2334static void gen_assert_resume_id(CodeGen *g, IrInstGen *source_instr, ResumeId resume_id, PanicMsgId msg_id,
23352335 LLVMBasicBlockRef end_bb)
23362336{
23372337 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
......@@ -2408,7 +2408,7 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV
24082408 }
24092409}
24102410
2411static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
2411static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
24122412 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
24132413
24142414 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;
......@@ -2487,7 +2487,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
24872487 frame_index_trace_arg(g, ret_type) + 1, "");
24882488 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");
24892489 bool is_llvm_alloca;
2490 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
2490 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
24912491 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };
24922492 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
24932493 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -2502,7 +2502,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
25022502 LLVMBuildRetVoid(g->builder);
25032503}
25042504
2505static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *instruction) {
2505static LLVMValueRef ir_render_return(CodeGen *g, IrExecutableGen *executable, IrInstGenReturn *instruction) {
25062506 if (fn_is_async(g->cur_fn)) {
25072507 gen_async_return(g, instruction);
25082508 return nullptr;
......@@ -2843,12 +2843,12 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
28432843
28442844}
28452845
2846static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2847 IrInstructionBinOp *bin_op_instruction)
2846static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutableGen *executable,
2847 IrInstGenBinOp *bin_op_instruction)
28482848{
28492849 IrBinOp op_id = bin_op_instruction->op_id;
2850 IrInstruction *op1 = bin_op_instruction->op1;
2851 IrInstruction *op2 = bin_op_instruction->op2;
2850 IrInstGen *op1 = bin_op_instruction->op1;
2851 IrInstGen *op2 = bin_op_instruction->op2;
28522852
28532853 ZigType *operand_type = op1->value->type;
28542854 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
......@@ -3053,8 +3053,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
30533053 }
30543054}
30553055
3056static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
3057 IrInstructionResizeSlice *instruction)
3056static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutableGen *executable,
3057 IrInstGenResizeSlice *instruction)
30583058{
30593059 ZigType *actual_type = instruction->operand->value->type;
30603060 ZigType *wanted_type = instruction->base.value->type;
......@@ -3121,8 +3121,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
31213121 return result_loc;
31223122}
31233123
3124static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
3125 IrInstructionCast *cast_instruction)
3124static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
3125 IrInstGenCast *cast_instruction)
31263126{
31273127 ZigType *actual_type = cast_instruction->value->value->type;
31283128 ZigType *wanted_type = cast_instruction->base.value->type;
......@@ -3199,8 +3199,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
31993199 zig_unreachable();
32003200}
32013201
3202static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable,
3203 IrInstructionPtrOfArrayToSlice *instruction)
3202static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen *executable,
3203 IrInstGenPtrOfArrayToSlice *instruction)
32043204{
32053205 ZigType *actual_type = instruction->operand->value->type;
32063206 ZigType *slice_type = instruction->base.value->type;
......@@ -3236,8 +3236,8 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex
32363236 return result_loc;
32373237}
32383238
3239static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
3240 IrInstructionPtrCastGen *instruction)
3239static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
3240 IrInstGenPtrCast *instruction)
32413241{
32423242 ZigType *wanted_type = instruction->base.value->type;
32433243 if (!type_has_bits(wanted_type)) {
......@@ -3262,8 +3262,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
32623262 return result_ptr;
32633263}
32643264
3265static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
3266 IrInstructionBitCastGen *instruction)
3265static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
3266 IrInstGenBitCast *instruction)
32673267{
32683268 ZigType *wanted_type = instruction->base.value->type;
32693269 ZigType *actual_type = instruction->operand->value->type;
......@@ -3286,8 +3286,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
32863286 }
32873287}
32883288
3289static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,
3290 IrInstructionWidenOrShorten *instruction)
3289static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutableGen *executable,
3290 IrInstGenWidenOrShorten *instruction)
32913291{
32923292 ZigType *actual_type = instruction->target->value->type;
32933293 // TODO instead of this logic, use the Noop instruction to change the type from
......@@ -3303,7 +3303,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
33033303 instruction->base.value->type, target_val);
33043304}
33053305
3306static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {
3306static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToPtr *instruction) {
33073307 ZigType *wanted_type = instruction->base.value->type;
33083308 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
33093309
......@@ -3341,13 +3341,13 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I
33413341 return LLVMBuildIntToPtr(g->builder, target_val, get_llvm_type(g, wanted_type), "");
33423342}
33433343
3344static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {
3344static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenPtrToInt *instruction) {
33453345 ZigType *wanted_type = instruction->base.value->type;
33463346 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
33473347 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");
33483348}
33493349
3350static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
3350static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToEnum *instruction) {
33513351 ZigType *wanted_type = instruction->base.value->type;
33523352 assert(wanted_type->id == ZigTypeIdEnum);
33533353 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
......@@ -3374,7 +3374,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
33743374 return tag_int_value;
33753375}
33763376
3377static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {
3377static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToErr *instruction) {
33783378 ZigType *wanted_type = instruction->base.value->type;
33793379 assert(wanted_type->id == ZigTypeIdErrorSet);
33803380
......@@ -3391,7 +3391,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
33913391 return gen_widen_or_shorten(g, false, actual_type, g->err_tag_type, target_val);
33923392}
33933393
3394static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {
3394static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenErrToInt *instruction) {
33953395 ZigType *wanted_type = instruction->base.value->type;
33963396 assert(wanted_type->id == ZigTypeIdInt);
33973397 assert(!wanted_type->data.integral.is_signed);
......@@ -3417,8 +3417,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
34173417 }
34183418}
34193419
3420static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
3421 IrInstructionUnreachable *unreachable_instruction)
3420static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutableGen *executable,
3421 IrInstGenUnreachable *unreachable_instruction)
34223422{
34233423 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {
34243424 gen_safety_crash(g, PanicMsgIdUnreachable);
......@@ -3428,8 +3428,8 @@ static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
34283428 return nullptr;
34293429}
34303430
3431static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,
3432 IrInstructionCondBr *cond_br_instruction)
3431static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutableGen *executable,
3432 IrInstGenCondBr *cond_br_instruction)
34333433{
34343434 LLVMBuildCondBr(g->builder,
34353435 ir_llvm_value(g, cond_br_instruction->condition),
......@@ -3438,51 +3438,56 @@ static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,
34383438 return nullptr;
34393439}
34403440
3441static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstructionBr *br_instruction) {
3441static LLVMValueRef ir_render_br(CodeGen *g, IrExecutableGen *executable, IrInstGenBr *br_instruction) {
34423442 LLVMBuildBr(g->builder, br_instruction->dest_block->llvm_block);
34433443 return nullptr;
34443444}
34453445
3446static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
3447 IrUnOp op_id = un_op_instruction->op_id;
3448 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);
3449 ZigType *operand_type = un_op_instruction->value->value->type;
3450 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
3451
3452 switch (op_id) {
3453 case IrUnOpInvalid:
3454 case IrUnOpOptional:
3455 case IrUnOpDereference:
3456 zig_unreachable();
3457 case IrUnOpNegation:
3458 case IrUnOpNegationWrap:
3459 {
3460 if (scalar_type->id == ZigTypeIdFloat) {
3461 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));
3462 return LLVMBuildFNeg(g->builder, expr, "");
3463 } else if (scalar_type->id == ZigTypeIdInt) {
3464 if (op_id == IrUnOpNegationWrap) {
3465 return LLVMBuildNeg(g->builder, expr, "");
3466 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {
3467 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr));
3468 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, expr);
3469 } else if (scalar_type->data.integral.is_signed) {
3470 return LLVMBuildNSWNeg(g->builder, expr, "");
3471 } else {
3472 return LLVMBuildNUWNeg(g->builder, expr, "");
3473 }
3474 } else {
3475 zig_unreachable();
3476 }
3477 }
3478 case IrUnOpBinNot:
3479 return LLVMBuildNot(g->builder, expr, "");
3446static LLVMValueRef ir_render_binary_not(CodeGen *g, IrExecutableGen *executable,
3447 IrInstGenBinaryNot *inst)
3448{
3449 LLVMValueRef operand = ir_llvm_value(g, inst->operand);
3450 return LLVMBuildNot(g->builder, operand, "");
3451}
3452
3453static LLVMValueRef ir_gen_negation(CodeGen *g, IrInstGen *inst, IrInstGen *operand, bool wrapping) {
3454 LLVMValueRef llvm_operand = ir_llvm_value(g, operand);
3455 ZigType *operand_type = operand->value->type;
3456 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
3457 operand_type->data.vector.elem_type : operand_type;
3458
3459 if (scalar_type->id == ZigTypeIdFloat) {
3460 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, inst));
3461 return LLVMBuildFNeg(g->builder, llvm_operand, "");
3462 } else if (scalar_type->id == ZigTypeIdInt) {
3463 if (wrapping) {
3464 return LLVMBuildNeg(g->builder, llvm_operand, "");
3465 } else if (ir_want_runtime_safety(g, inst)) {
3466 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(llvm_operand));
3467 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, llvm_operand);
3468 } else if (scalar_type->data.integral.is_signed) {
3469 return LLVMBuildNSWNeg(g->builder, llvm_operand, "");
3470 } else {
3471 return LLVMBuildNUWNeg(g->builder, llvm_operand, "");
3472 }
3473 } else {
3474 zig_unreachable();
34803475 }
3476}
34813477
3482 zig_unreachable();
3478static LLVMValueRef ir_render_negation(CodeGen *g, IrExecutableGen *executable,
3479 IrInstGenNegation *inst)
3480{
3481 return ir_gen_negation(g, &inst->base, inst->operand, false);
34833482}
34843483
3485static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrInstructionBoolNot *instruction) {
3484static LLVMValueRef ir_render_negation_wrapping(CodeGen *g, IrExecutableGen *executable,
3485 IrInstGenNegationWrapping *inst)
3486{
3487 return ir_gen_negation(g, &inst->base, inst->operand, true);
3488}
3489
3490static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutableGen *executable, IrInstGenBoolNot *instruction) {
34863491 LLVMValueRef value = ir_llvm_value(g, instruction->value);
34873492 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(value));
34883493 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");
......@@ -3496,14 +3501,14 @@ static void render_decl_var(CodeGen *g, ZigVar *var) {
34963501 gen_var_debug_decl(g, var);
34973502}
34983503
3499static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrInstructionDeclVarGen *instruction) {
3504static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutableGen *executable, IrInstGenDeclVar *instruction) {
35003505 instruction->var->ptr_instruction = instruction->var_ptr;
35013506 render_decl_var(g, instruction->var);
35023507 return nullptr;
35033508}
35043509
3505static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,
3506 IrInstructionLoadPtrGen *instruction)
3510static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
3511 IrInstGenLoadPtr *instruction)
35073512{
35083513 ZigType *child_type = instruction->base.value->type;
35093514 if (!type_has_bits(child_type))
......@@ -3705,7 +3710,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_
37053710 }
37063711}
37073712
3708static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {
3713static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenStorePtr *instruction) {
37093714 Error err;
37103715
37113716 ZigType *ptr_type = instruction->ptr->value->type;
......@@ -3715,7 +3720,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
37153720 codegen_report_errors_and_exit(g);
37163721 if (!ptr_type_has_bits)
37173722 return nullptr;
3718 if (instruction->ptr->ref_count == 0) {
3723 if (instruction->ptr->base.ref_count == 0) {
37193724 // In this case, this StorePtr instruction should be elided. Something happened like this:
37203725 // var t = true;
37213726 // const x = if (t) Num.Two else unreachable;
......@@ -3737,8 +3742,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
37373742 return nullptr;
37383743}
37393744
3740static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *executable,
3741 IrInstructionVectorStoreElem *instruction)
3745static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutableGen *executable,
3746 IrInstGenVectorStoreElem *instruction)
37423747{
37433748 LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);
37443749 LLVMValueRef index = ir_llvm_value(g, instruction->index);
......@@ -3750,7 +3755,7 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut
37503755 return nullptr;
37513756}
37523757
3753static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
3758static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenVarPtr *instruction) {
37543759 if (instruction->base.value->special != ConstValSpecialRuntime)
37553760 return ir_llvm_value(g, &instruction->base);
37563761 ZigVar *var = instruction->var;
......@@ -3762,8 +3767,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
37623767 }
37633768}
37643769
3765static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
3766 IrInstructionReturnPtr *instruction)
3770static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,
3771 IrInstGenReturnPtr *instruction)
37673772{
37683773 if (!type_has_bits(instruction->base.value->type))
37693774 return nullptr;
......@@ -3771,7 +3776,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
37713776 return g->cur_ret_ptr;
37723777}
37733778
3774static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
3779static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenElemPtr *instruction) {
37753780 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
37763781 ZigType *array_ptr_type = instruction->array_ptr->value->type;
37773782 assert(array_ptr_type->id == ZigTypeIdPointer);
......@@ -3947,7 +3952,7 @@ static void render_async_spills(CodeGen *g) {
39473952 ZigType *frame_type = g->cur_fn->frame_type->data.frame.locals_struct;
39483953
39493954 for (size_t alloca_i = 0; alloca_i < g->cur_fn->alloca_gen_list.length; alloca_i += 1) {
3950 IrInstructionAllocaGen *instruction = g->cur_fn->alloca_gen_list.at(alloca_i);
3955 IrInstGenAlloca *instruction = g->cur_fn->alloca_gen_list.at(alloca_i);
39513956 if (instruction->field_index == SIZE_MAX)
39523957 continue;
39533958
......@@ -4014,7 +4019,7 @@ static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMV
40144019 LLVMBuildStore(g->builder, LLVMConstInt(usize_type_ref, stack_trace_ptr_count, false), addrs_len_ptr);
40154020}
40164021
4017static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCallGen *instruction) {
4022static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrInstGenCall *instruction) {
40184023 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
40194024
40204025 LLVMValueRef fn_val;
......@@ -4149,7 +4154,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
41494154 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,
41504155 frame_index_trace_arg(g, src_return_type) + 1, "");
41514156 bool is_llvm_alloca;
4152 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope,
4157 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope,
41534158 &is_llvm_alloca);
41544159 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);
41554160 }
......@@ -4208,7 +4213,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
42084213 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
42094214
42104215 bool is_llvm_alloca;
4211 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
4216 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
42124217 }
42134218 }
42144219 } else {
......@@ -4217,7 +4222,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
42174222 }
42184223 if (prefix_arg_err_ret_stack) {
42194224 bool is_llvm_alloca;
4220 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
4225 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
42214226 }
42224227 }
42234228 FnWalk fn_walk = {};
......@@ -4327,13 +4332,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
43274332
43284333 LLVMPositionBuilderAtEnd(g->builder, call_bb);
43294334 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);
4330 render_async_var_decls(g, instruction->base.scope);
4335 render_async_var_decls(g, instruction->base.base.scope);
43314336
43324337 if (!type_has_bits(src_return_type))
43334338 return nullptr;
43344339
43354340 if (result_loc != nullptr) {
4336 if (instruction->result_loc->id == IrInstructionIdReturnPtr) {
4341 if (instruction->result_loc->id == IrInstGenIdReturnPtr) {
43374342 instruction->base.spill = nullptr;
43384343 return g->cur_ret_ptr;
43394344 } else {
......@@ -4393,8 +4398,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
43934398 }
43944399}
43954400
4396static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executable,
4397 IrInstructionStructFieldPtr *instruction)
4401static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *executable,
4402 IrInstGenStructFieldPtr *instruction)
43984403{
43994404 Error err;
44004405
......@@ -4444,8 +4449,8 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
44444449 return field_ptr_val;
44454450}
44464451
4447static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,
4448 IrInstructionUnionFieldPtr *instruction)
4452static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *executable,
4453 IrInstGenUnionFieldPtr *instruction)
44494454{
44504455 if (instruction->base.value->special != ConstValSpecialRuntime)
44514456 return nullptr;
......@@ -4544,8 +4549,8 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
45444549 return SIZE_MAX;
45454550}
45464551
4547static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrInstructionAsmGen *instruction) {
4548 AstNode *asm_node = instruction->base.source_node;
4552static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, IrInstGenAsm *instruction) {
4553 AstNode *asm_node = instruction->base.base.source_node;
45494554 assert(asm_node->type == NodeTypeAsmExpr);
45504555 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;
45514556
......@@ -4629,7 +4634,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrIn
46294634 for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
46304635 AsmInput *asm_input = asm_expr->input_list.at(i);
46314636 buf_replace(asm_input->constraint, ',', '|');
4632 IrInstruction *ir_input = instruction->input_list[i];
4637 IrInstGen *ir_input = instruction->input_list[i];
46334638 buf_append_buf(&constraint_buf, asm_input->constraint);
46344639 if (total_index + 1 < total_constraint_count) {
46354640 buf_append_char(&constraint_buf, ',');
......@@ -4692,14 +4697,14 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
46924697 return gen_load_untyped(g, maybe_field_ptr, 0, false, "");
46934698}
46944699
4695static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,
4696 IrInstructionTestNonNull *instruction)
4700static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutableGen *executable,
4701 IrInstGenTestNonNull *instruction)
46974702{
46984703 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));
46994704}
47004705
4701static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable,
4702 IrInstructionOptionalUnwrapPtr *instruction)
4706static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutableGen *executable,
4707 IrInstGenOptionalUnwrapPtr *instruction)
47034708{
47044709 if (instruction->base.value->special != ConstValSpecialRuntime)
47054710 return nullptr;
......@@ -4801,7 +4806,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
48014806 return fn_val;
48024807}
48034808
4804static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {
4809static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutableGen *executable, IrInstGenClz *instruction) {
48054810 ZigType *int_type = instruction->op->value->type;
48064811 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
48074812 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -4813,7 +4818,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
48134818 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
48144819}
48154820
4816static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {
4821static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutableGen *executable, IrInstGenCtz *instruction) {
48174822 ZigType *int_type = instruction->op->value->type;
48184823 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
48194824 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -4825,7 +4830,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
48254830 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
48264831}
48274832
4828static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executable, IrInstructionShuffleVector *instruction) {
4833static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *executable, IrInstGenShuffleVector *instruction) {
48294834 uint64_t len_a = instruction->a->value->type->data.vector.len;
48304835 uint64_t len_mask = instruction->mask->value->type->data.vector.len;
48314836
......@@ -4834,7 +4839,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
48344839 // when changing code, so Zig uses negative numbers to index the
48354840 // second vector. These start at -1 and go down, and are easiest to use
48364841 // with the ~ operator. Here we convert between the two formats.
4837 IrInstruction *mask = instruction->mask;
4842 IrInstGen *mask = instruction->mask;
48384843 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
48394844 for (uint64_t i = 0; i < len_mask; i++) {
48404845 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {
......@@ -4855,7 +4860,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
48554860 llvm_mask_value, "");
48564861}
48574862
4858static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInstructionSplatGen *instruction) {
4863static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutableGen *executable, IrInstGenSplat *instruction) {
48594864 ZigType *result_type = instruction->base.value->type;
48604865 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);
48614866 uint32_t len = result_type->data.vector.len;
......@@ -4867,7 +4872,7 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst
48674872 return LLVMBuildShuffleVector(g->builder, op_vector, undef_vector, LLVMConstNull(mask_llvm_type), "");
48684873}
48694874
4870static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {
4875static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutableGen *executable, IrInstGenPopCount *instruction) {
48714876 ZigType *int_type = instruction->op->value->type;
48724877 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
48734878 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -4875,7 +4880,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir
48754880 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
48764881}
48774882
4878static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) {
4883static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable, IrInstGenSwitchBr *instruction) {
48794884 ZigType *target_type = instruction->target_value->value->type;
48804885 LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;
48814886
......@@ -4889,7 +4894,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
48894894 (unsigned)instruction->case_count);
48904895
48914896 for (size_t i = 0; i < instruction->case_count; i += 1) {
4892 IrInstructionSwitchBrCase *this_case = &instruction->cases[i];
4897 IrInstGenSwitchBrCase *this_case = &instruction->cases[i];
48934898
48944899 LLVMValueRef case_value = ir_llvm_value(g, this_case->value);
48954900 if (target_type->id == ZigTypeIdPointer) {
......@@ -4903,7 +4908,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
49034908 return nullptr;
49044909}
49054910
4906static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) {
4911static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrInstGenPhi *instruction) {
49074912 if (!type_has_bits(instruction->base.value->type))
49084913 return nullptr;
49094914
......@@ -4925,7 +4930,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
49254930 return phi;
49264931}
49274932
4928static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) {
4933static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrInstGenRef *instruction) {
49294934 if (!type_has_bits(instruction->base.value->type)) {
49304935 return nullptr;
49314936 }
......@@ -4939,7 +4944,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstru
49394944 }
49404945}
49414946
4942static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrInstructionErrName *instruction) {
4947static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutableGen *executable, IrInstGenErrName *instruction) {
49434948 assert(g->generate_error_name_table);
49444949
49454950 if (g->errors_by_index.length == 1) {
......@@ -5060,13 +5065,13 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
50605065 return fn_val;
50615066}
50625067
5063static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,
5064 IrInstructionTagName *instruction)
5068static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutableGen *executable,
5069 IrInstGenTagName *instruction)
50655070{
50665071 ZigType *enum_type = instruction->target->value->type;
50675072 assert(enum_type->id == ZigTypeIdEnum);
50685073 if (enum_type->data.enumeration.non_exhaustive) {
5069 add_node_error(g, instruction->base.source_node,
5074 add_node_error(g, instruction->base.base.source_node,
50705075 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));
50715076 codegen_report_errors_and_exit(g);
50725077 }
......@@ -5078,8 +5083,8 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
50785083 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
50795084}
50805085
5081static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,
5082 IrInstructionFieldParentPtr *instruction)
5086static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutableGen *executable,
5087 IrInstGenFieldParentPtr *instruction)
50835088{
50845089 ZigType *container_ptr_type = instruction->base.value->type;
50855090 assert(container_ptr_type->id == ZigTypeIdPointer);
......@@ -5105,7 +5110,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
51055110 }
51065111}
51075112
5108static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, IrInstructionAlignCast *instruction) {
5113static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutableGen *executable, IrInstGenAlignCast *instruction) {
51095114 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
51105115 assert(target_val);
51115116
......@@ -5168,11 +5173,11 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
51685173 return target_val;
51695174}
51705175
5171static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *executable,
5172 IrInstructionErrorReturnTrace *instruction)
5176static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutableGen *executable,
5177 IrInstGenErrorReturnTrace *instruction)
51735178{
51745179 bool is_llvm_alloca;
5175 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
5180 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
51765181 if (cur_err_ret_trace_val == nullptr) {
51775182 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));
51785183 }
......@@ -5210,7 +5215,7 @@ static enum ZigLLVM_AtomicRMWBinOp to_ZigLLVMAtomicRMWBinOp(AtomicRmwOp op, bool
52105215 zig_unreachable();
52115216}
52125217
5213static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrInstructionCmpxchgGen *instruction) {
5218static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, IrInstGenCmpxchg *instruction) {
52145219 LLVMValueRef ptr_val = ir_llvm_value(g, instruction->ptr);
52155220 LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value);
52165221 LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value);
......@@ -5251,13 +5256,13 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
52515256 return result_loc;
52525257}
52535258
5254static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInstructionFence *instruction) {
5259static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutableGen *executable, IrInstGenFence *instruction) {
52555260 LLVMAtomicOrdering atomic_order = to_LLVMAtomicOrdering(instruction->order);
52565261 LLVMBuildFence(g->builder, atomic_order, false, "");
52575262 return nullptr;
52585263}
52595264
5260static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
5265static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutableGen *executable, IrInstGenTruncate *instruction) {
52615266 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
52625267 ZigType *dest_type = instruction->base.value->type;
52635268 ZigType *src_type = instruction->target->value->type;
......@@ -5272,7 +5277,7 @@ static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrI
52725277 }
52735278}
52745279
5275static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrInstructionMemset *instruction) {
5280static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, IrInstGenMemset *instruction) {
52765281 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
52775282 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
52785283
......@@ -5284,7 +5289,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
52845289
52855290 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);
52865291 LLVMValueRef fill_char;
5287 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) {
5292 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.base.scope)) {
52885293 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
52895294 } else {
52905295 fill_char = ir_llvm_value(g, instruction->byte);
......@@ -5298,7 +5303,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
52985303 return nullptr;
52995304}
53005305
5301static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrInstructionMemcpy *instruction) {
5306static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutableGen *executable, IrInstGenMemcpy *instruction) {
53025307 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
53035308 LLVMValueRef src_ptr = ir_llvm_value(g, instruction->src_ptr);
53045309 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
......@@ -5320,7 +5325,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
53205325 return nullptr;
53215326}
53225327
5323static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) {
5328static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrInstGenSlice *instruction) {
53245329 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
53255330 ZigType *array_ptr_type = instruction->ptr->value->type;
53265331 assert(array_ptr_type->id == ZigTypeIdPointer);
......@@ -5482,13 +5487,13 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) {
54825487}
54835488
54845489
5485static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutable *executable, IrInstructionBreakpoint *instruction) {
5490static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutableGen *executable, IrInstGenBreakpoint *instruction) {
54865491 LLVMBuildCall(g->builder, get_trap_fn_val(g), nullptr, 0, "");
54875492 return nullptr;
54885493}
54895494
5490static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutable *executable,
5491 IrInstructionReturnAddress *instruction)
5495static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutableGen *executable,
5496 IrInstGenReturnAddress *instruction)
54925497{
54935498 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
54945499 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
......@@ -5509,19 +5514,19 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
55095514 return g->frame_address_fn_val;
55105515}
55115516
5512static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable,
5513 IrInstructionFrameAddress *instruction)
5517static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutableGen *executable,
5518 IrInstGenFrameAddress *instruction)
55145519{
55155520 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
55165521 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
55175522 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");
55185523}
55195524
5520static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable, IrInstructionFrameHandle *instruction) {
5525static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutableGen *executable, IrInstGenFrameHandle *instruction) {
55215526 return g->cur_frame_ptr;
55225527}
55235528
5524static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
5529static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstGenOverflowOp *instruction) {
55255530 ZigType *int_type = instruction->result_ptr_type;
55265531 assert(int_type->id == ZigTypeIdInt);
55275532
......@@ -5546,7 +5551,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
55465551 return overflow_bit;
55475552}
55485553
5549static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, IrInstructionOverflowOp *instruction) {
5554static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutableGen *executable, IrInstGenOverflowOp *instruction) {
55505555 AddSubMul add_sub_mul;
55515556 switch (instruction->op) {
55525557 case IrOverflowOpAdd:
......@@ -5584,7 +5589,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
55845589 return overflow_bit;
55855590}
55865591
5587static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) {
5592static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutableGen *executable, IrInstGenTestErr *instruction) {
55885593 ZigType *err_union_type = instruction->err_union->value->type;
55895594 ZigType *payload_type = err_union_type->data.error_union.payload_type;
55905595 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
......@@ -5601,8 +5606,8 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
56015606 return LLVMBuildICmp(g->builder, LLVMIntNE, err_val, zero, "");
56025607}
56035608
5604static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,
5605 IrInstructionUnwrapErrCode *instruction)
5609static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *executable,
5610 IrInstGenUnwrapErrCode *instruction)
56065611{
56075612 if (instruction->base.value->special != ConstValSpecialRuntime)
56085613 return nullptr;
......@@ -5621,8 +5626,8 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
56215626 }
56225627}
56235628
5624static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,
5625 IrInstructionUnwrapErrPayload *instruction)
5629static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *executable,
5630 IrInstGenUnwrapErrPayload *instruction)
56265631{
56275632 Error err;
56285633
......@@ -5665,7 +5670,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
56655670 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
56665671
56675672 LLVMPositionBuilderAtEnd(g->builder, err_block);
5668 gen_safety_crash_for_err(g, err_val, instruction->base.scope);
5673 gen_safety_crash_for_err(g, err_val, instruction->base.base.scope);
56695674
56705675 LLVMPositionBuilderAtEnd(g->builder, ok_block);
56715676 }
......@@ -5682,7 +5687,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
56825687 }
56835688}
56845689
5685static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
5690static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executable, IrInstGenOptionalWrap *instruction) {
56865691 ZigType *wanted_type = instruction->base.value->type;
56875692
56885693 assert(wanted_type->id == ZigTypeIdOptional);
......@@ -5718,7 +5723,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
57185723 return result_loc;
57195724}
57205725
5721static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {
5726static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapCode *instruction) {
57225727 ZigType *wanted_type = instruction->base.value->type;
57235728
57245729 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -5738,7 +5743,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
57385743 return result_loc;
57395744}
57405745
5741static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {
5746static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapPayload *instruction) {
57425747 ZigType *wanted_type = instruction->base.value->type;
57435748
57445749 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -5769,7 +5774,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
57695774 return result_loc;
57705775}
57715776
5772static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
5777static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable, IrInstGenUnionTag *instruction) {
57735778 ZigType *union_type = instruction->value->value->type;
57745779
57755780 ZigType *tag_type = union_type->data.unionation.tag_type;
......@@ -5787,15 +5792,15 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
57875792 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
57885793}
57895794
5790static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInstructionPanic *instruction) {
5795static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutableGen *executable, IrInstGenPanic *instruction) {
57915796 bool is_llvm_alloca;
5792 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
5797 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
57935798 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);
57945799 return nullptr;
57955800}
57965801
5797static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5798 IrInstructionAtomicRmw *instruction)
5802static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable,
5803 IrInstGenAtomicRmw *instruction)
57995804{
58005805 bool is_signed;
58015806 ZigType *operand_type = instruction->operand->value->type;
......@@ -5805,8 +5810,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
58055810 } else {
58065811 is_signed = false;
58075812 }
5808 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->resolved_op, is_signed, is_float);
5809 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5813 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->op, is_signed, is_float);
5814 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
58105815 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
58115816 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
58125817
......@@ -5823,20 +5828,20 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
58235828 return LLVMBuildIntToPtr(g->builder, uncasted_result, get_llvm_type(g, operand_type), "");
58245829}
58255830
5826static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,
5827 IrInstructionAtomicLoad *instruction)
5831static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutableGen *executable,
5832 IrInstGenAtomicLoad *instruction)
58285833{
5829 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5834 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
58305835 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
58315836 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, "");
58325837 LLVMSetOrdering(load_inst, ordering);
58335838 return load_inst;
58345839}
58355840
5836static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
5837 IrInstructionAtomicStore *instruction)
5841static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutableGen *executable,
5842 IrInstGenAtomicStore *instruction)
58385843{
5839 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5844 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
58405845 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
58415846 LLVMValueRef value = ir_llvm_value(g, instruction->value);
58425847 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type);
......@@ -5844,13 +5849,13 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
58445849 return nullptr;
58455850}
58465851
5847static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) {
5852static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutableGen *executable, IrInstGenFloatOp *instruction) {
58485853 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
58495854 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->fn_id);
58505855 return LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
58515856}
58525857
5853static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrInstructionMulAdd *instruction) {
5858static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutableGen *executable, IrInstGenMulAdd *instruction) {
58545859 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
58555860 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
58565861 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);
......@@ -5865,7 +5870,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
58655870 return LLVMBuildCall(g->builder, fn_val, args, 3, "");
58665871}
58675872
5868static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) {
5873static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrInstGenBswap *instruction) {
58695874 LLVMValueRef op = ir_llvm_value(g, instruction->op);
58705875 ZigType *expr_type = instruction->base.value->type;
58715876 bool is_vector = expr_type->id == ZigTypeIdVector;
......@@ -5899,7 +5904,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst
58995904 return LLVMBuildTrunc(g->builder, shifted, get_llvm_type(g, expr_type), "");
59005905}
59015906
5902static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) {
5907static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutableGen *executable, IrInstGenBitReverse *instruction) {
59035908 LLVMValueRef op = ir_llvm_value(g, instruction->op);
59045909 ZigType *int_type = instruction->base.value->type;
59055910 assert(int_type->id == ZigTypeIdInt);
......@@ -5907,8 +5912,8 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable,
59075912 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
59085913}
59095914
5910static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable,
5911 IrInstructionVectorToArray *instruction)
5915static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *executable,
5916 IrInstGenVectorToArray *instruction)
59125917{
59135918 ZigType *array_type = instruction->base.value->type;
59145919 assert(array_type->id == ZigTypeIdArray);
......@@ -5941,8 +5946,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
59415946 return result_loc;
59425947}
59435948
5944static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable,
5945 IrInstructionArrayToVector *instruction)
5949static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *executable,
5950 IrInstGenArrayToVector *instruction)
59465951{
59475952 ZigType *vector_type = instruction->base.value->type;
59485953 assert(vector_type->id == ZigTypeIdVector);
......@@ -5978,8 +5983,8 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
59785983 }
59795984}
59805985
5981static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
5982 IrInstructionAssertZero *instruction)
5986static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutableGen *executable,
5987 IrInstGenAssertZero *instruction)
59835988{
59845989 LLVMValueRef target = ir_llvm_value(g, instruction->target);
59855990 ZigType *int_type = instruction->target->value->type;
......@@ -5989,8 +5994,8 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
59895994 return nullptr;
59905995}
59915996
5992static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executable,
5993 IrInstructionAssertNonNull *instruction)
5997static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutableGen *executable,
5998 IrInstGenAssertNonNull *instruction)
59945999{
59956000 LLVMValueRef target = ir_llvm_value(g, instruction->target);
59966001 ZigType *target_type = instruction->target->value->type;
......@@ -6014,8 +6019,8 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
60146019 return nullptr;
60156020}
60166021
6017static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,
6018 IrInstructionSuspendBegin *instruction)
6022static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutableGen *executable,
6023 IrInstGenSuspendBegin *instruction)
60196024{
60206025 if (fn_is_async(g->cur_fn)) {
60216026 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
......@@ -6023,8 +6028,8 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable
60236028 return nullptr;
60246029}
60256030
6026static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executable,
6027 IrInstructionSuspendFinish *instruction)
6031static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutableGen *executable,
6032 IrInstGenSuspendFinish *instruction)
60286033{
60296034 LLVMBuildRetVoid(g->builder);
60306035
......@@ -6032,11 +6037,11 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executabl
60326037 if (ir_want_runtime_safety(g, &instruction->base)) {
60336038 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);
60346039 }
6035 render_async_var_decls(g, instruction->base.scope);
6040 render_async_var_decls(g, instruction->base.base.scope);
60366041 return nullptr;
60376042}
60386043
6039static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
6044static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
60406045 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
60416046 LLVMValueRef result_loc, bool non_async)
60426047{
......@@ -6062,7 +6067,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
60626067 frame_index_trace_arg(g, result_type), "");
60636068 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");
60646069 bool is_llvm_alloca;
6065 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->scope, &is_llvm_alloca);
6070 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->base.scope, &is_llvm_alloca);
60666071 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };
60676072 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
60686073 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -6075,7 +6080,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
60756080 }
60766081}
60776082
6078static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInstructionAwaitGen *instruction) {
6083static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrInstGenAwait *instruction) {
60796084 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
60806085 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
60816086 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);
......@@ -6112,7 +6117,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
61126117 // supply the error return trace pointer
61136118 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {
61146119 bool is_llvm_alloca;
6115 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
6120 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
61166121 assert(my_err_ret_trace_val != nullptr);
61176122 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,
61186123 frame_index_trace_arg(g, result_type) + 1, "");
......@@ -6160,7 +6165,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
61606165 return nullptr;
61616166}
61626167
6163static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {
6168static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutableGen *executable, IrInstGenResume *instruction) {
61646169 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
61656170 ZigType *frame_type = instruction->frame->value->type;
61666171 assert(frame_type->id == ZigTypeIdAnyFrame);
......@@ -6169,15 +6174,15 @@ static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrIns
61696174 return nullptr;
61706175}
61716176
6172static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutable *executable,
6173 IrInstructionFrameSizeGen *instruction)
6177static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutableGen *executable,
6178 IrInstGenFrameSize *instruction)
61746179{
61756180 LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn);
61766181 return gen_frame_size(g, fn_val);
61776182}
61786183
6179static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,
6180 IrInstructionSpillBegin *instruction)
6184static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutableGen *executable,
6185 IrInstGenSpillBegin *instruction)
61816186{
61826187 if (!fn_is_async(g->cur_fn))
61836188 return nullptr;
......@@ -6196,7 +6201,7 @@ static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,
61966201 zig_unreachable();
61976202}
61986203
6199static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, IrInstructionSpillEnd *instruction) {
6204static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutableGen *executable, IrInstGenSpillEnd *instruction) {
62006205 if (!fn_is_async(g->cur_fn))
62016206 return ir_llvm_value(g, instruction->begin->operand);
62026207
......@@ -6212,17 +6217,17 @@ static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, Ir
62126217 zig_unreachable();
62136218}
62146219
6215static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutable *executable,
6216 IrInstructionVectorExtractElem *instruction)
6220static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutableGen *executable,
6221 IrInstGenVectorExtractElem *instruction)
62176222{
62186223 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);
62196224 LLVMValueRef index = ir_llvm_value(g, instruction->index);
62206225 return LLVMBuildExtractElement(g->builder, vector, index, "");
62216226}
62226227
6223static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
6224 AstNode *source_node = instruction->source_node;
6225 Scope *scope = instruction->scope;
6228static void set_debug_location(CodeGen *g, IrInstGen *instruction) {
6229 AstNode *source_node = instruction->base.source_node;
6230 Scope *scope = instruction->base.scope;
62266231
62276232 assert(source_node);
62286233 assert(scope);
......@@ -6231,263 +6236,183 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
62316236 (int)source_node->column + 1, get_di_scope(g, scope));
62326237}
62336238
6234static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, IrInstruction *instruction) {
6239static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executable, IrInstGen *instruction) {
62356240 switch (instruction->id) {
6236 case IrInstructionIdInvalid:
6237 case IrInstructionIdConst:
6238 case IrInstructionIdTypeOf:
6239 case IrInstructionIdFieldPtr:
6240 case IrInstructionIdSetCold:
6241 case IrInstructionIdSetRuntimeSafety:
6242 case IrInstructionIdSetFloatMode:
6243 case IrInstructionIdArrayType:
6244 case IrInstructionIdAnyFrameType:
6245 case IrInstructionIdSliceType:
6246 case IrInstructionIdSizeOf:
6247 case IrInstructionIdSwitchTarget:
6248 case IrInstructionIdContainerInitFields:
6249 case IrInstructionIdCompileErr:
6250 case IrInstructionIdCompileLog:
6251 case IrInstructionIdImport:
6252 case IrInstructionIdCImport:
6253 case IrInstructionIdCInclude:
6254 case IrInstructionIdCDefine:
6255 case IrInstructionIdCUndef:
6256 case IrInstructionIdEmbedFile:
6257 case IrInstructionIdIntType:
6258 case IrInstructionIdVectorType:
6259 case IrInstructionIdMemberCount:
6260 case IrInstructionIdMemberType:
6261 case IrInstructionIdMemberName:
6262 case IrInstructionIdAlignOf:
6263 case IrInstructionIdFnProto:
6264 case IrInstructionIdTestComptime:
6265 case IrInstructionIdCheckSwitchProngs:
6266 case IrInstructionIdCheckStatementIsVoid:
6267 case IrInstructionIdTypeName:
6268 case IrInstructionIdDeclRef:
6269 case IrInstructionIdSwitchVar:
6270 case IrInstructionIdSwitchElseVar:
6271 case IrInstructionIdByteOffsetOf:
6272 case IrInstructionIdBitOffsetOf:
6273 case IrInstructionIdTypeInfo:
6274 case IrInstructionIdType:
6275 case IrInstructionIdHasField:
6276 case IrInstructionIdTypeId:
6277 case IrInstructionIdSetEvalBranchQuota:
6278 case IrInstructionIdPtrType:
6279 case IrInstructionIdOpaqueType:
6280 case IrInstructionIdSetAlignStack:
6281 case IrInstructionIdArgType:
6282 case IrInstructionIdTagType:
6283 case IrInstructionIdExport:
6284 case IrInstructionIdErrorUnion:
6285 case IrInstructionIdAddImplicitReturnType:
6286 case IrInstructionIdIntCast:
6287 case IrInstructionIdFloatCast:
6288 case IrInstructionIdIntToFloat:
6289 case IrInstructionIdFloatToInt:
6290 case IrInstructionIdBoolToInt:
6291 case IrInstructionIdErrSetCast:
6292 case IrInstructionIdFromBytes:
6293 case IrInstructionIdToBytes:
6294 case IrInstructionIdEnumToInt:
6295 case IrInstructionIdCheckRuntimeScope:
6296 case IrInstructionIdDeclVarSrc:
6297 case IrInstructionIdPtrCastSrc:
6298 case IrInstructionIdCmpxchgSrc:
6299 case IrInstructionIdLoadPtr:
6300 case IrInstructionIdHasDecl:
6301 case IrInstructionIdUndeclaredIdent:
6302 case IrInstructionIdCallExtra:
6303 case IrInstructionIdCallSrc:
6304 case IrInstructionIdCallSrcArgs:
6305 case IrInstructionIdAllocaSrc:
6306 case IrInstructionIdEndExpr:
6307 case IrInstructionIdImplicitCast:
6308 case IrInstructionIdResolveResult:
6309 case IrInstructionIdResetResult:
6310 case IrInstructionIdContainerInitList:
6311 case IrInstructionIdSliceSrc:
6312 case IrInstructionIdRef:
6313 case IrInstructionIdBitCastSrc:
6314 case IrInstructionIdTestErrSrc:
6315 case IrInstructionIdUnionInitNamedField:
6316 case IrInstructionIdFrameType:
6317 case IrInstructionIdFrameSizeSrc:
6318 case IrInstructionIdAllocaGen:
6319 case IrInstructionIdAwaitSrc:
6320 case IrInstructionIdSplatSrc:
6321 case IrInstructionIdMergeErrSets:
6322 case IrInstructionIdAsmSrc:
6241 case IrInstGenIdInvalid:
6242 case IrInstGenIdConst:
6243 case IrInstGenIdAlloca:
63236244 zig_unreachable();
63246245
6325 case IrInstructionIdDeclVarGen:
6326 return ir_render_decl_var(g, executable, (IrInstructionDeclVarGen *)instruction);
6327 case IrInstructionIdReturn:
6328 return ir_render_return(g, executable, (IrInstructionReturn *)instruction);
6329 case IrInstructionIdBinOp:
6330 return ir_render_bin_op(g, executable, (IrInstructionBinOp *)instruction);
6331 case IrInstructionIdCast:
6332 return ir_render_cast(g, executable, (IrInstructionCast *)instruction);
6333 case IrInstructionIdUnreachable:
6334 return ir_render_unreachable(g, executable, (IrInstructionUnreachable *)instruction);
6335 case IrInstructionIdCondBr:
6336 return ir_render_cond_br(g, executable, (IrInstructionCondBr *)instruction);
6337 case IrInstructionIdBr:
6338 return ir_render_br(g, executable, (IrInstructionBr *)instruction);
6339 case IrInstructionIdUnOp:
6340 return ir_render_un_op(g, executable, (IrInstructionUnOp *)instruction);
6341 case IrInstructionIdLoadPtrGen:
6342 return ir_render_load_ptr(g, executable, (IrInstructionLoadPtrGen *)instruction);
6343 case IrInstructionIdStorePtr:
6344 return ir_render_store_ptr(g, executable, (IrInstructionStorePtr *)instruction);
6345 case IrInstructionIdVectorStoreElem:
6346 return ir_render_vector_store_elem(g, executable, (IrInstructionVectorStoreElem *)instruction);
6347 case IrInstructionIdVarPtr:
6348 return ir_render_var_ptr(g, executable, (IrInstructionVarPtr *)instruction);
6349 case IrInstructionIdReturnPtr:
6350 return ir_render_return_ptr(g, executable, (IrInstructionReturnPtr *)instruction);
6351 case IrInstructionIdElemPtr:
6352 return ir_render_elem_ptr(g, executable, (IrInstructionElemPtr *)instruction);
6353 case IrInstructionIdCallGen:
6354 return ir_render_call(g, executable, (IrInstructionCallGen *)instruction);
6355 case IrInstructionIdStructFieldPtr:
6356 return ir_render_struct_field_ptr(g, executable, (IrInstructionStructFieldPtr *)instruction);
6357 case IrInstructionIdUnionFieldPtr:
6358 return ir_render_union_field_ptr(g, executable, (IrInstructionUnionFieldPtr *)instruction);
6359 case IrInstructionIdAsmGen:
6360 return ir_render_asm_gen(g, executable, (IrInstructionAsmGen *)instruction);
6361 case IrInstructionIdTestNonNull:
6362 return ir_render_test_non_null(g, executable, (IrInstructionTestNonNull *)instruction);
6363 case IrInstructionIdOptionalUnwrapPtr:
6364 return ir_render_optional_unwrap_ptr(g, executable, (IrInstructionOptionalUnwrapPtr *)instruction);
6365 case IrInstructionIdClz:
6366 return ir_render_clz(g, executable, (IrInstructionClz *)instruction);
6367 case IrInstructionIdCtz:
6368 return ir_render_ctz(g, executable, (IrInstructionCtz *)instruction);
6369 case IrInstructionIdPopCount:
6370 return ir_render_pop_count(g, executable, (IrInstructionPopCount *)instruction);
6371 case IrInstructionIdSwitchBr:
6372 return ir_render_switch_br(g, executable, (IrInstructionSwitchBr *)instruction);
6373 case IrInstructionIdBswap:
6374 return ir_render_bswap(g, executable, (IrInstructionBswap *)instruction);
6375 case IrInstructionIdBitReverse:
6376 return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction);
6377 case IrInstructionIdPhi:
6378 return ir_render_phi(g, executable, (IrInstructionPhi *)instruction);
6379 case IrInstructionIdRefGen:
6380 return ir_render_ref(g, executable, (IrInstructionRefGen *)instruction);
6381 case IrInstructionIdErrName:
6382 return ir_render_err_name(g, executable, (IrInstructionErrName *)instruction);
6383 case IrInstructionIdCmpxchgGen:
6384 return ir_render_cmpxchg(g, executable, (IrInstructionCmpxchgGen *)instruction);
6385 case IrInstructionIdFence:
6386 return ir_render_fence(g, executable, (IrInstructionFence *)instruction);
6387 case IrInstructionIdTruncate:
6388 return ir_render_truncate(g, executable, (IrInstructionTruncate *)instruction);
6389 case IrInstructionIdBoolNot:
6390 return ir_render_bool_not(g, executable, (IrInstructionBoolNot *)instruction);
6391 case IrInstructionIdMemset:
6392 return ir_render_memset(g, executable, (IrInstructionMemset *)instruction);
6393 case IrInstructionIdMemcpy:
6394 return ir_render_memcpy(g, executable, (IrInstructionMemcpy *)instruction);
6395 case IrInstructionIdSliceGen:
6396 return ir_render_slice(g, executable, (IrInstructionSliceGen *)instruction);
6397 case IrInstructionIdBreakpoint:
6398 return ir_render_breakpoint(g, executable, (IrInstructionBreakpoint *)instruction);
6399 case IrInstructionIdReturnAddress:
6400 return ir_render_return_address(g, executable, (IrInstructionReturnAddress *)instruction);
6401 case IrInstructionIdFrameAddress:
6402 return ir_render_frame_address(g, executable, (IrInstructionFrameAddress *)instruction);
6403 case IrInstructionIdFrameHandle:
6404 return ir_render_handle(g, executable, (IrInstructionFrameHandle *)instruction);
6405 case IrInstructionIdOverflowOp:
6406 return ir_render_overflow_op(g, executable, (IrInstructionOverflowOp *)instruction);
6407 case IrInstructionIdTestErrGen:
6408 return ir_render_test_err(g, executable, (IrInstructionTestErrGen *)instruction);
6409 case IrInstructionIdUnwrapErrCode:
6410 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);
6411 case IrInstructionIdUnwrapErrPayload:
6412 return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);
6413 case IrInstructionIdOptionalWrap:
6414 return ir_render_optional_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);
6415 case IrInstructionIdErrWrapCode:
6416 return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);
6417 case IrInstructionIdErrWrapPayload:
6418 return ir_render_err_wrap_payload(g, executable, (IrInstructionErrWrapPayload *)instruction);
6419 case IrInstructionIdUnionTag:
6420 return ir_render_union_tag(g, executable, (IrInstructionUnionTag *)instruction);
6421 case IrInstructionIdPtrCastGen:
6422 return ir_render_ptr_cast(g, executable, (IrInstructionPtrCastGen *)instruction);
6423 case IrInstructionIdBitCastGen:
6424 return ir_render_bit_cast(g, executable, (IrInstructionBitCastGen *)instruction);
6425 case IrInstructionIdWidenOrShorten:
6426 return ir_render_widen_or_shorten(g, executable, (IrInstructionWidenOrShorten *)instruction);
6427 case IrInstructionIdPtrToInt:
6428 return ir_render_ptr_to_int(g, executable, (IrInstructionPtrToInt *)instruction);
6429 case IrInstructionIdIntToPtr:
6430 return ir_render_int_to_ptr(g, executable, (IrInstructionIntToPtr *)instruction);
6431 case IrInstructionIdIntToEnum:
6432 return ir_render_int_to_enum(g, executable, (IrInstructionIntToEnum *)instruction);
6433 case IrInstructionIdIntToErr:
6434 return ir_render_int_to_err(g, executable, (IrInstructionIntToErr *)instruction);
6435 case IrInstructionIdErrToInt:
6436 return ir_render_err_to_int(g, executable, (IrInstructionErrToInt *)instruction);
6437 case IrInstructionIdPanic:
6438 return ir_render_panic(g, executable, (IrInstructionPanic *)instruction);
6439 case IrInstructionIdTagName:
6440 return ir_render_enum_tag_name(g, executable, (IrInstructionTagName *)instruction);
6441 case IrInstructionIdFieldParentPtr:
6442 return ir_render_field_parent_ptr(g, executable, (IrInstructionFieldParentPtr *)instruction);
6443 case IrInstructionIdAlignCast:
6444 return ir_render_align_cast(g, executable, (IrInstructionAlignCast *)instruction);
6445 case IrInstructionIdErrorReturnTrace:
6446 return ir_render_error_return_trace(g, executable, (IrInstructionErrorReturnTrace *)instruction);
6447 case IrInstructionIdAtomicRmw:
6448 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);
6449 case IrInstructionIdAtomicLoad:
6450 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);
6451 case IrInstructionIdAtomicStore:
6452 return ir_render_atomic_store(g, executable, (IrInstructionAtomicStore *)instruction);
6453 case IrInstructionIdSaveErrRetAddr:
6454 return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);
6455 case IrInstructionIdFloatOp:
6456 return ir_render_float_op(g, executable, (IrInstructionFloatOp *)instruction);
6457 case IrInstructionIdMulAdd:
6458 return ir_render_mul_add(g, executable, (IrInstructionMulAdd *)instruction);
6459 case IrInstructionIdArrayToVector:
6460 return ir_render_array_to_vector(g, executable, (IrInstructionArrayToVector *)instruction);
6461 case IrInstructionIdVectorToArray:
6462 return ir_render_vector_to_array(g, executable, (IrInstructionVectorToArray *)instruction);
6463 case IrInstructionIdAssertZero:
6464 return ir_render_assert_zero(g, executable, (IrInstructionAssertZero *)instruction);
6465 case IrInstructionIdAssertNonNull:
6466 return ir_render_assert_non_null(g, executable, (IrInstructionAssertNonNull *)instruction);
6467 case IrInstructionIdResizeSlice:
6468 return ir_render_resize_slice(g, executable, (IrInstructionResizeSlice *)instruction);
6469 case IrInstructionIdPtrOfArrayToSlice:
6470 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstructionPtrOfArrayToSlice *)instruction);
6471 case IrInstructionIdSuspendBegin:
6472 return ir_render_suspend_begin(g, executable, (IrInstructionSuspendBegin *)instruction);
6473 case IrInstructionIdSuspendFinish:
6474 return ir_render_suspend_finish(g, executable, (IrInstructionSuspendFinish *)instruction);
6475 case IrInstructionIdResume:
6476 return ir_render_resume(g, executable, (IrInstructionResume *)instruction);
6477 case IrInstructionIdFrameSizeGen:
6478 return ir_render_frame_size(g, executable, (IrInstructionFrameSizeGen *)instruction);
6479 case IrInstructionIdAwaitGen:
6480 return ir_render_await(g, executable, (IrInstructionAwaitGen *)instruction);
6481 case IrInstructionIdSpillBegin:
6482 return ir_render_spill_begin(g, executable, (IrInstructionSpillBegin *)instruction);
6483 case IrInstructionIdSpillEnd:
6484 return ir_render_spill_end(g, executable, (IrInstructionSpillEnd *)instruction);
6485 case IrInstructionIdShuffleVector:
6486 return ir_render_shuffle_vector(g, executable, (IrInstructionShuffleVector *) instruction);
6487 case IrInstructionIdSplatGen:
6488 return ir_render_splat(g, executable, (IrInstructionSplatGen *) instruction);
6489 case IrInstructionIdVectorExtractElem:
6490 return ir_render_vector_extract_elem(g, executable, (IrInstructionVectorExtractElem *) instruction);
6246 case IrInstGenIdDeclVar:
6247 return ir_render_decl_var(g, executable, (IrInstGenDeclVar *)instruction);
6248 case IrInstGenIdReturn:
6249 return ir_render_return(g, executable, (IrInstGenReturn *)instruction);
6250 case IrInstGenIdBinOp:
6251 return ir_render_bin_op(g, executable, (IrInstGenBinOp *)instruction);
6252 case IrInstGenIdCast:
6253 return ir_render_cast(g, executable, (IrInstGenCast *)instruction);
6254 case IrInstGenIdUnreachable:
6255 return ir_render_unreachable(g, executable, (IrInstGenUnreachable *)instruction);
6256 case IrInstGenIdCondBr:
6257 return ir_render_cond_br(g, executable, (IrInstGenCondBr *)instruction);
6258 case IrInstGenIdBr:
6259 return ir_render_br(g, executable, (IrInstGenBr *)instruction);
6260 case IrInstGenIdBinaryNot:
6261 return ir_render_binary_not(g, executable, (IrInstGenBinaryNot *)instruction);
6262 case IrInstGenIdNegation:
6263 return ir_render_negation(g, executable, (IrInstGenNegation *)instruction);
6264 case IrInstGenIdNegationWrapping:
6265 return ir_render_negation_wrapping(g, executable, (IrInstGenNegationWrapping *)instruction);
6266 case IrInstGenIdLoadPtr:
6267 return ir_render_load_ptr(g, executable, (IrInstGenLoadPtr *)instruction);
6268 case IrInstGenIdStorePtr:
6269 return ir_render_store_ptr(g, executable, (IrInstGenStorePtr *)instruction);
6270 case IrInstGenIdVectorStoreElem:
6271 return ir_render_vector_store_elem(g, executable, (IrInstGenVectorStoreElem *)instruction);
6272 case IrInstGenIdVarPtr:
6273 return ir_render_var_ptr(g, executable, (IrInstGenVarPtr *)instruction);
6274 case IrInstGenIdReturnPtr:
6275 return ir_render_return_ptr(g, executable, (IrInstGenReturnPtr *)instruction);
6276 case IrInstGenIdElemPtr:
6277 return ir_render_elem_ptr(g, executable, (IrInstGenElemPtr *)instruction);
6278 case IrInstGenIdCall:
6279 return ir_render_call(g, executable, (IrInstGenCall *)instruction);
6280 case IrInstGenIdStructFieldPtr:
6281 return ir_render_struct_field_ptr(g, executable, (IrInstGenStructFieldPtr *)instruction);
6282 case IrInstGenIdUnionFieldPtr:
6283 return ir_render_union_field_ptr(g, executable, (IrInstGenUnionFieldPtr *)instruction);
6284 case IrInstGenIdAsm:
6285 return ir_render_asm_gen(g, executable, (IrInstGenAsm *)instruction);
6286 case IrInstGenIdTestNonNull:
6287 return ir_render_test_non_null(g, executable, (IrInstGenTestNonNull *)instruction);
6288 case IrInstGenIdOptionalUnwrapPtr:
6289 return ir_render_optional_unwrap_ptr(g, executable, (IrInstGenOptionalUnwrapPtr *)instruction);
6290 case IrInstGenIdClz:
6291 return ir_render_clz(g, executable, (IrInstGenClz *)instruction);
6292 case IrInstGenIdCtz:
6293 return ir_render_ctz(g, executable, (IrInstGenCtz *)instruction);
6294 case IrInstGenIdPopCount:
6295 return ir_render_pop_count(g, executable, (IrInstGenPopCount *)instruction);
6296 case IrInstGenIdSwitchBr:
6297 return ir_render_switch_br(g, executable, (IrInstGenSwitchBr *)instruction);
6298 case IrInstGenIdBswap:
6299 return ir_render_bswap(g, executable, (IrInstGenBswap *)instruction);
6300 case IrInstGenIdBitReverse:
6301 return ir_render_bit_reverse(g, executable, (IrInstGenBitReverse *)instruction);
6302 case IrInstGenIdPhi:
6303 return ir_render_phi(g, executable, (IrInstGenPhi *)instruction);
6304 case IrInstGenIdRef:
6305 return ir_render_ref(g, executable, (IrInstGenRef *)instruction);
6306 case IrInstGenIdErrName:
6307 return ir_render_err_name(g, executable, (IrInstGenErrName *)instruction);
6308 case IrInstGenIdCmpxchg:
6309 return ir_render_cmpxchg(g, executable, (IrInstGenCmpxchg *)instruction);
6310 case IrInstGenIdFence:
6311 return ir_render_fence(g, executable, (IrInstGenFence *)instruction);
6312 case IrInstGenIdTruncate:
6313 return ir_render_truncate(g, executable, (IrInstGenTruncate *)instruction);
6314 case IrInstGenIdBoolNot:
6315 return ir_render_bool_not(g, executable, (IrInstGenBoolNot *)instruction);
6316 case IrInstGenIdMemset:
6317 return ir_render_memset(g, executable, (IrInstGenMemset *)instruction);
6318 case IrInstGenIdMemcpy:
6319 return ir_render_memcpy(g, executable, (IrInstGenMemcpy *)instruction);
6320 case IrInstGenIdSlice:
6321 return ir_render_slice(g, executable, (IrInstGenSlice *)instruction);
6322 case IrInstGenIdBreakpoint:
6323 return ir_render_breakpoint(g, executable, (IrInstGenBreakpoint *)instruction);
6324 case IrInstGenIdReturnAddress:
6325 return ir_render_return_address(g, executable, (IrInstGenReturnAddress *)instruction);
6326 case IrInstGenIdFrameAddress:
6327 return ir_render_frame_address(g, executable, (IrInstGenFrameAddress *)instruction);
6328 case IrInstGenIdFrameHandle:
6329 return ir_render_handle(g, executable, (IrInstGenFrameHandle *)instruction);
6330 case IrInstGenIdOverflowOp:
6331 return ir_render_overflow_op(g, executable, (IrInstGenOverflowOp *)instruction);
6332 case IrInstGenIdTestErr:
6333 return ir_render_test_err(g, executable, (IrInstGenTestErr *)instruction);
6334 case IrInstGenIdUnwrapErrCode:
6335 return ir_render_unwrap_err_code(g, executable, (IrInstGenUnwrapErrCode *)instruction);
6336 case IrInstGenIdUnwrapErrPayload:
6337 return ir_render_unwrap_err_payload(g, executable, (IrInstGenUnwrapErrPayload *)instruction);
6338 case IrInstGenIdOptionalWrap:
6339 return ir_render_optional_wrap(g, executable, (IrInstGenOptionalWrap *)instruction);
6340 case IrInstGenIdErrWrapCode:
6341 return ir_render_err_wrap_code(g, executable, (IrInstGenErrWrapCode *)instruction);
6342 case IrInstGenIdErrWrapPayload:
6343 return ir_render_err_wrap_payload(g, executable, (IrInstGenErrWrapPayload *)instruction);
6344 case IrInstGenIdUnionTag:
6345 return ir_render_union_tag(g, executable, (IrInstGenUnionTag *)instruction);
6346 case IrInstGenIdPtrCast:
6347 return ir_render_ptr_cast(g, executable, (IrInstGenPtrCast *)instruction);
6348 case IrInstGenIdBitCast:
6349 return ir_render_bit_cast(g, executable, (IrInstGenBitCast *)instruction);
6350 case IrInstGenIdWidenOrShorten:
6351 return ir_render_widen_or_shorten(g, executable, (IrInstGenWidenOrShorten *)instruction);
6352 case IrInstGenIdPtrToInt:
6353 return ir_render_ptr_to_int(g, executable, (IrInstGenPtrToInt *)instruction);
6354 case IrInstGenIdIntToPtr:
6355 return ir_render_int_to_ptr(g, executable, (IrInstGenIntToPtr *)instruction);
6356 case IrInstGenIdIntToEnum:
6357 return ir_render_int_to_enum(g, executable, (IrInstGenIntToEnum *)instruction);
6358 case IrInstGenIdIntToErr:
6359 return ir_render_int_to_err(g, executable, (IrInstGenIntToErr *)instruction);
6360 case IrInstGenIdErrToInt:
6361 return ir_render_err_to_int(g, executable, (IrInstGenErrToInt *)instruction);
6362 case IrInstGenIdPanic:
6363 return ir_render_panic(g, executable, (IrInstGenPanic *)instruction);
6364 case IrInstGenIdTagName:
6365 return ir_render_enum_tag_name(g, executable, (IrInstGenTagName *)instruction);
6366 case IrInstGenIdFieldParentPtr:
6367 return ir_render_field_parent_ptr(g, executable, (IrInstGenFieldParentPtr *)instruction);
6368 case IrInstGenIdAlignCast:
6369 return ir_render_align_cast(g, executable, (IrInstGenAlignCast *)instruction);
6370 case IrInstGenIdErrorReturnTrace:
6371 return ir_render_error_return_trace(g, executable, (IrInstGenErrorReturnTrace *)instruction);
6372 case IrInstGenIdAtomicRmw:
6373 return ir_render_atomic_rmw(g, executable, (IrInstGenAtomicRmw *)instruction);
6374 case IrInstGenIdAtomicLoad:
6375 return ir_render_atomic_load(g, executable, (IrInstGenAtomicLoad *)instruction);
6376 case IrInstGenIdAtomicStore:
6377 return ir_render_atomic_store(g, executable, (IrInstGenAtomicStore *)instruction);
6378 case IrInstGenIdSaveErrRetAddr:
6379 return ir_render_save_err_ret_addr(g, executable, (IrInstGenSaveErrRetAddr *)instruction);
6380 case IrInstGenIdFloatOp:
6381 return ir_render_float_op(g, executable, (IrInstGenFloatOp *)instruction);
6382 case IrInstGenIdMulAdd:
6383 return ir_render_mul_add(g, executable, (IrInstGenMulAdd *)instruction);
6384 case IrInstGenIdArrayToVector:
6385 return ir_render_array_to_vector(g, executable, (IrInstGenArrayToVector *)instruction);
6386 case IrInstGenIdVectorToArray:
6387 return ir_render_vector_to_array(g, executable, (IrInstGenVectorToArray *)instruction);
6388 case IrInstGenIdAssertZero:
6389 return ir_render_assert_zero(g, executable, (IrInstGenAssertZero *)instruction);
6390 case IrInstGenIdAssertNonNull:
6391 return ir_render_assert_non_null(g, executable, (IrInstGenAssertNonNull *)instruction);
6392 case IrInstGenIdResizeSlice:
6393 return ir_render_resize_slice(g, executable, (IrInstGenResizeSlice *)instruction);
6394 case IrInstGenIdPtrOfArrayToSlice:
6395 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstGenPtrOfArrayToSlice *)instruction);
6396 case IrInstGenIdSuspendBegin:
6397 return ir_render_suspend_begin(g, executable, (IrInstGenSuspendBegin *)instruction);
6398 case IrInstGenIdSuspendFinish:
6399 return ir_render_suspend_finish(g, executable, (IrInstGenSuspendFinish *)instruction);
6400 case IrInstGenIdResume:
6401 return ir_render_resume(g, executable, (IrInstGenResume *)instruction);
6402 case IrInstGenIdFrameSize:
6403 return ir_render_frame_size(g, executable, (IrInstGenFrameSize *)instruction);
6404 case IrInstGenIdAwait:
6405 return ir_render_await(g, executable, (IrInstGenAwait *)instruction);
6406 case IrInstGenIdSpillBegin:
6407 return ir_render_spill_begin(g, executable, (IrInstGenSpillBegin *)instruction);
6408 case IrInstGenIdSpillEnd:
6409 return ir_render_spill_end(g, executable, (IrInstGenSpillEnd *)instruction);
6410 case IrInstGenIdShuffleVector:
6411 return ir_render_shuffle_vector(g, executable, (IrInstGenShuffleVector *) instruction);
6412 case IrInstGenIdSplat:
6413 return ir_render_splat(g, executable, (IrInstGenSplat *) instruction);
6414 case IrInstGenIdVectorExtractElem:
6415 return ir_render_vector_extract_elem(g, executable, (IrInstGenVectorExtractElem *) instruction);
64916416 }
64926417 zig_unreachable();
64936418}
......@@ -6495,21 +6420,21 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
64956420static void ir_render(CodeGen *g, ZigFn *fn_entry) {
64966421 assert(fn_entry);
64976422
6498 IrExecutable *executable = &fn_entry->analyzed_executable;
6423 IrExecutableGen *executable = &fn_entry->analyzed_executable;
64996424 assert(executable->basic_block_list.length > 0);
65006425
65016426 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
6502 IrBasicBlock *current_block = executable->basic_block_list.at(block_i);
6427 IrBasicBlockGen *current_block = executable->basic_block_list.at(block_i);
65036428 if (get_scope_typeof(current_block->scope) != nullptr) {
65046429 LLVMBuildBr(g->builder, current_block->llvm_block);
65056430 }
65066431 assert(current_block->llvm_block);
65076432 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);
65086433 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
6509 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
6510 if (instruction->ref_count == 0 && !ir_has_side_effects(instruction))
6434 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
6435 if (instruction->base.ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))
65116436 continue;
6512 if (get_scope_typeof(instruction->scope) != nullptr)
6437 if (get_scope_typeof(instruction->base.scope) != nullptr)
65136438 continue;
65146439
65156440 if (!g->strip_debug_symbols) {
......@@ -7401,7 +7326,7 @@ static void generate_error_name_table(CodeGen *g) {
74017326}
74027327
74037328static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
7404 IrExecutable *executable = &fn->analyzed_executable;
7329 IrExecutableGen *executable = &fn->analyzed_executable;
74057330 assert(executable->basic_block_list.length > 0);
74067331 LLVMValueRef fn_val = fn_llvm_value(g, fn);
74077332 LLVMBasicBlockRef first_bb = nullptr;
......@@ -7410,7 +7335,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
74107335 g->cur_preamble_llvm_block = first_bb;
74117336 }
74127337 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
7413 IrBasicBlock *bb = executable->basic_block_list.at(block_i);
7338 IrBasicBlockGen *bb = executable->basic_block_list.at(block_i);
74147339 bb->llvm_block = LLVMAppendBasicBlock(fn_val, bb->name_hint);
74157340 }
74167341 if (first_bb == nullptr) {
......@@ -7643,10 +7568,10 @@ static void do_code_gen(CodeGen *g) {
76437568 if (!is_async) {
76447569 // allocate async frames for noasync calls & awaits to async functions
76457570 ZigType *largest_call_frame_type = nullptr;
7646 IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn_table_entry->fndef_scope->base,
7571 IrInstGen *all_calls_alloca = ir_create_alloca(g, &fn_table_entry->fndef_scope->base,
76477572 fn_table_entry->body_node, fn_table_entry, g->builtin_types.entry_void, "@async_call_frame");
76487573 for (size_t i = 0; i < fn_table_entry->call_list.length; i += 1) {
7649 IrInstructionCallGen *call = fn_table_entry->call_list.at(i);
7574 IrInstGenCall *call = fn_table_entry->call_list.at(i);
76507575 if (call->fn_entry == nullptr)
76517576 continue;
76527577 if (!fn_is_async(call->fn_entry))
......@@ -7668,7 +7593,7 @@ static void do_code_gen(CodeGen *g) {
76687593 }
76697594 // allocate temporary stack data
76707595 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {
7671 IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
7596 IrInstGenAlloca *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
76727597 ZigType *ptr_type = instruction->base.value->type;
76737598 assert(ptr_type->id == ZigTypeIdPointer);
76747599 ZigType *child_type = ptr_type->data.pointer.child_type;
......@@ -7676,7 +7601,7 @@ static void do_code_gen(CodeGen *g) {
76767601 zig_unreachable();
76777602 if (!type_has_bits(child_type))
76787603 continue;
7679 if (instruction->base.ref_count == 0)
7604 if (instruction->base.base.ref_count == 0)
76807605 continue;
76817606 if (instruction->base.value->special != ConstValSpecialRuntime) {
76827607 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
......@@ -7793,7 +7718,7 @@ static void do_code_gen(CodeGen *g) {
77937718 ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1,
77947719 (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope));
77957720 }
7796 IrExecutable *executable = &fn_table_entry->analyzed_executable;
7721 IrExecutableGen *executable = &fn_table_entry->analyzed_executable;
77977722 LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume");
77987723 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);
77997724 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);
......@@ -7820,7 +7745,7 @@ static void do_code_gen(CodeGen *g) {
78207745 g->cur_async_switch_instr = switch_instr;
78217746
78227747 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
7823 IrBasicBlock *entry_block = executable->basic_block_list.at(0);
7748 IrBasicBlockGen *entry_block = executable->basic_block_list.at(0);
78247749 LLVMAddCase(switch_instr, zero, entry_block->llvm_block);
78257750 g->cur_resume_block_count += 1;
78267751
......@@ -7852,7 +7777,7 @@ static void do_code_gen(CodeGen *g) {
78527777
78537778 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
78547779 }
7855 render_async_var_decls(g, entry_block->instruction_list.at(0)->scope);
7780 render_async_var_decls(g, entry_block->instruction_list.at(0)->base.scope);
78567781 } else {
78577782 // create debug variable declarations for parameters
78587783 // rely on the first variables in the variable_list being parameters.
......@@ -7941,6 +7866,12 @@ static void zig_llvm_emit_output(CodeGen *g) {
79417866 default:
79427867 zig_unreachable();
79437868 }
7869 LLVMDisposeModule(g->module);
7870 g->module = nullptr;
7871 LLVMDisposeTargetData(g->target_data_ref);
7872 g->target_data_ref = nullptr;
7873 LLVMDisposeTargetMachine(g->target_machine);
7874 g->target_machine = nullptr;
79447875}
79457876
79467877struct CIntTypeInfo {
......@@ -8846,15 +8777,17 @@ static void init(CodeGen *g) {
88468777 define_builtin_types(g);
88478778 define_intern_values(g);
88488779
8849 IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);
8850 g->invalid_instruction = &sentinel_instructions[0];
8851 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");
8852 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;
8780 IrInstGen *sentinel_instructions = allocate<IrInstGen>(2);
8781 g->invalid_inst_gen = &sentinel_instructions[0];
8782 g->invalid_inst_gen->value = allocate<ZigValue>(1, "ZigValue");
8783 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;
88538784
88548785 g->unreach_instruction = &sentinel_instructions[1];
88558786 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
88568787 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
88578788
8789 g->invalid_inst_src = allocate<IrInstSrc>(1);
8790
88588791 define_builtin_fns(g);
88598792 Error err;
88608793 if ((err = define_builtin_compile_vars(g))) {
src/ir.cpp+7223-6362
......@@ -21,25 +21,31 @@ struct IrExecContext {
2121 ZigList<ZigValue *> mem_slot_list;
2222};
2323
24struct IrBuilder {
24struct IrBuilderSrc {
2525 CodeGen *codegen;
26 IrExecutable *exec;
27 IrBasicBlock *current_basic_block;
26 IrExecutableSrc *exec;
27 IrBasicBlockSrc *current_basic_block;
2828 AstNode *main_block_node;
2929};
3030
31struct IrBuilderGen {
32 CodeGen *codegen;
33 IrExecutableGen *exec;
34 IrBasicBlockGen *current_basic_block;
35};
36
3137struct IrAnalyze {
3238 CodeGen *codegen;
33 IrBuilder old_irb;
34 IrBuilder new_irb;
39 IrBuilderSrc old_irb;
40 IrBuilderGen new_irb;
3541 IrExecContext exec_context;
3642 size_t old_bb_index;
3743 size_t instruction_index;
3844 ZigType *explicit_return_type;
3945 AstNode *explicit_return_type_source_node;
40 ZigList<IrInstruction *> src_implicit_return_type_list;
46 ZigList<IrInstGen *> src_implicit_return_type_list;
4147 ZigList<IrSuspendPosition> resume_stack;
42 IrBasicBlock *const_predecessor_bb;
48 IrBasicBlockSrc *const_predecessor_bb;
4349 size_t ref_count;
4450 size_t break_debug_id; // for debugging purposes
4551
......@@ -206,412 +212,538 @@ struct DbgIrBreakPoint {
206212DbgIrBreakPoint dbg_ir_breakpoints_buf[20];
207213size_t dbg_ir_breakpoints_count = 0;
208214
209static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
210static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
215static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope);
216static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
211217 ResultLoc *result_loc);
212static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);
213static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,
214 IrInstruction *value, ZigType *expected_type);
215static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
218static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type);
219static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
220 IrInstGen *value, ZigType *expected_type);
221static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr,
216222 ResultLoc *result_loc);
217static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing);
220static void ir_assert(bool ok, IrInstruction *source_instruction);
221static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);
222static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
223static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc);
224static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);
223static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg);
224static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
225 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing);
226static void ir_assert(bool ok, IrInst* source_instruction);
227static void ir_assert_gen(bool ok, IrInstGen *source_instruction);
228static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);
229static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);
230static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc);
231static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc);
225232static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
226233static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
227234static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);
228235static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
229236static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
230237 ZigValue *out_val, ZigValue *ptr_val);
231static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
232 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
233static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
238static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
239 ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on);
240static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed);
234241static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
235static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
242static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
236243 ZigType *ptr_type);
237static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
244static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
238245 ZigType *dest_type);
239static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
240 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
246static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
247 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
241248 bool non_null_comptime, bool allow_discard);
242static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
243 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
249static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
250 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
244251 bool non_null_comptime, bool allow_discard);
245static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,
246 IrInstruction *base_ptr, bool safety_check_on, bool initializing);
247static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
248 IrInstruction *base_ptr, bool safety_check_on, bool initializing);
249static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,
250 IrInstruction *base_ptr, bool initializing);
251static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,
252 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const);
253static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
254 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,
252static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
253 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
254static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
255 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
256static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
257 IrInstGen *base_ptr, bool initializing);
258static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
259 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const);
260static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
261 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
255262 LVal lval, ResultLoc *parent_result_loc);
256263static void ir_reset_result(ResultLoc *result_loc);
257static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
264static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name,
258265 Scope *scope, AstNode *source_node, Buf *out_bare_name);
259static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
266static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
260267 ResultLoc *parent_result_loc);
261static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,
262 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing);
263static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
264 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
268static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
269 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing);
270static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
271 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);
265272static ResultLoc *no_result_loc(void);
266static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value);
273static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
274
275static void destroy_instruction_src(IrInstSrc *inst) {
276#ifdef ZIG_ENABLE_MEM_PROFILE
277 const char *name = ir_inst_src_type_str(inst->id);
278#else
279 const char *name = nullptr;
280#endif
281 switch (inst->id) {
282 case IrInstSrcIdInvalid:
283 zig_unreachable();
284 case IrInstSrcIdReturn:
285 return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name);
286 case IrInstSrcIdConst:
287 return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name);
288 case IrInstSrcIdBinOp:
289 return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name);
290 case IrInstSrcIdMergeErrSets:
291 return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name);
292 case IrInstSrcIdDeclVar:
293 return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name);
294 case IrInstSrcIdCall:
295 return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name);
296 case IrInstSrcIdCallExtra:
297 return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name);
298 case IrInstSrcIdUnOp:
299 return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name);
300 case IrInstSrcIdCondBr:
301 return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name);
302 case IrInstSrcIdBr:
303 return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name);
304 case IrInstSrcIdPhi:
305 return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name);
306 case IrInstSrcIdContainerInitList:
307 return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name);
308 case IrInstSrcIdContainerInitFields:
309 return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name);
310 case IrInstSrcIdUnreachable:
311 return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name);
312 case IrInstSrcIdElemPtr:
313 return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name);
314 case IrInstSrcIdVarPtr:
315 return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name);
316 case IrInstSrcIdLoadPtr:
317 return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name);
318 case IrInstSrcIdStorePtr:
319 return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name);
320 case IrInstSrcIdTypeOf:
321 return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name);
322 case IrInstSrcIdFieldPtr:
323 return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name);
324 case IrInstSrcIdSetCold:
325 return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name);
326 case IrInstSrcIdSetRuntimeSafety:
327 return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name);
328 case IrInstSrcIdSetFloatMode:
329 return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name);
330 case IrInstSrcIdArrayType:
331 return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name);
332 case IrInstSrcIdSliceType:
333 return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name);
334 case IrInstSrcIdAnyFrameType:
335 return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name);
336 case IrInstSrcIdAsm:
337 return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name);
338 case IrInstSrcIdSizeOf:
339 return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name);
340 case IrInstSrcIdTestNonNull:
341 return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name);
342 case IrInstSrcIdOptionalUnwrapPtr:
343 return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name);
344 case IrInstSrcIdPopCount:
345 return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name);
346 case IrInstSrcIdClz:
347 return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name);
348 case IrInstSrcIdCtz:
349 return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name);
350 case IrInstSrcIdBswap:
351 return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name);
352 case IrInstSrcIdBitReverse:
353 return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name);
354 case IrInstSrcIdSwitchBr:
355 return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name);
356 case IrInstSrcIdSwitchVar:
357 return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name);
358 case IrInstSrcIdSwitchElseVar:
359 return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name);
360 case IrInstSrcIdSwitchTarget:
361 return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name);
362 case IrInstSrcIdImport:
363 return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name);
364 case IrInstSrcIdRef:
365 return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name);
366 case IrInstSrcIdCompileErr:
367 return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name);
368 case IrInstSrcIdCompileLog:
369 return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name);
370 case IrInstSrcIdErrName:
371 return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name);
372 case IrInstSrcIdCImport:
373 return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name);
374 case IrInstSrcIdCInclude:
375 return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name);
376 case IrInstSrcIdCDefine:
377 return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name);
378 case IrInstSrcIdCUndef:
379 return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name);
380 case IrInstSrcIdEmbedFile:
381 return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name);
382 case IrInstSrcIdCmpxchg:
383 return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name);
384 case IrInstSrcIdFence:
385 return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name);
386 case IrInstSrcIdTruncate:
387 return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name);
388 case IrInstSrcIdIntCast:
389 return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name);
390 case IrInstSrcIdFloatCast:
391 return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name);
392 case IrInstSrcIdErrSetCast:
393 return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name);
394 case IrInstSrcIdFromBytes:
395 return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name);
396 case IrInstSrcIdToBytes:
397 return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name);
398 case IrInstSrcIdIntToFloat:
399 return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name);
400 case IrInstSrcIdFloatToInt:
401 return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name);
402 case IrInstSrcIdBoolToInt:
403 return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name);
404 case IrInstSrcIdIntType:
405 return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name);
406 case IrInstSrcIdVectorType:
407 return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name);
408 case IrInstSrcIdShuffleVector:
409 return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name);
410 case IrInstSrcIdSplat:
411 return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name);
412 case IrInstSrcIdBoolNot:
413 return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name);
414 case IrInstSrcIdMemset:
415 return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name);
416 case IrInstSrcIdMemcpy:
417 return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name);
418 case IrInstSrcIdSlice:
419 return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name);
420 case IrInstSrcIdMemberCount:
421 return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name);
422 case IrInstSrcIdMemberType:
423 return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name);
424 case IrInstSrcIdMemberName:
425 return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name);
426 case IrInstSrcIdBreakpoint:
427 return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name);
428 case IrInstSrcIdReturnAddress:
429 return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name);
430 case IrInstSrcIdFrameAddress:
431 return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name);
432 case IrInstSrcIdFrameHandle:
433 return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name);
434 case IrInstSrcIdFrameType:
435 return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name);
436 case IrInstSrcIdFrameSize:
437 return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name);
438 case IrInstSrcIdAlignOf:
439 return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name);
440 case IrInstSrcIdOverflowOp:
441 return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name);
442 case IrInstSrcIdTestErr:
443 return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name);
444 case IrInstSrcIdUnwrapErrCode:
445 return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name);
446 case IrInstSrcIdUnwrapErrPayload:
447 return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name);
448 case IrInstSrcIdFnProto:
449 return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name);
450 case IrInstSrcIdTestComptime:
451 return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name);
452 case IrInstSrcIdPtrCast:
453 return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name);
454 case IrInstSrcIdBitCast:
455 return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name);
456 case IrInstSrcIdPtrToInt:
457 return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name);
458 case IrInstSrcIdIntToPtr:
459 return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name);
460 case IrInstSrcIdIntToEnum:
461 return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name);
462 case IrInstSrcIdIntToErr:
463 return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name);
464 case IrInstSrcIdErrToInt:
465 return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name);
466 case IrInstSrcIdCheckSwitchProngs:
467 return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name);
468 case IrInstSrcIdCheckStatementIsVoid:
469 return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name);
470 case IrInstSrcIdTypeName:
471 return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name);
472 case IrInstSrcIdTagName:
473 return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name);
474 case IrInstSrcIdPtrType:
475 return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name);
476 case IrInstSrcIdDeclRef:
477 return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name);
478 case IrInstSrcIdPanic:
479 return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name);
480 case IrInstSrcIdFieldParentPtr:
481 return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name);
482 case IrInstSrcIdByteOffsetOf:
483 return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name);
484 case IrInstSrcIdBitOffsetOf:
485 return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name);
486 case IrInstSrcIdTypeInfo:
487 return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name);
488 case IrInstSrcIdType:
489 return destroy(reinterpret_cast<IrInstSrcType *>(inst), name);
490 case IrInstSrcIdHasField:
491 return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name);
492 case IrInstSrcIdTypeId:
493 return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name);
494 case IrInstSrcIdSetEvalBranchQuota:
495 return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name);
496 case IrInstSrcIdAlignCast:
497 return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name);
498 case IrInstSrcIdImplicitCast:
499 return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name);
500 case IrInstSrcIdResolveResult:
501 return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name);
502 case IrInstSrcIdResetResult:
503 return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name);
504 case IrInstSrcIdOpaqueType:
505 return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name);
506 case IrInstSrcIdSetAlignStack:
507 return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name);
508 case IrInstSrcIdArgType:
509 return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name);
510 case IrInstSrcIdTagType:
511 return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name);
512 case IrInstSrcIdExport:
513 return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name);
514 case IrInstSrcIdErrorReturnTrace:
515 return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name);
516 case IrInstSrcIdErrorUnion:
517 return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name);
518 case IrInstSrcIdAtomicRmw:
519 return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name);
520 case IrInstSrcIdSaveErrRetAddr:
521 return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name);
522 case IrInstSrcIdAddImplicitReturnType:
523 return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name);
524 case IrInstSrcIdFloatOp:
525 return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name);
526 case IrInstSrcIdMulAdd:
527 return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name);
528 case IrInstSrcIdAtomicLoad:
529 return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name);
530 case IrInstSrcIdAtomicStore:
531 return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name);
532 case IrInstSrcIdEnumToInt:
533 return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name);
534 case IrInstSrcIdCheckRuntimeScope:
535 return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name);
536 case IrInstSrcIdHasDecl:
537 return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name);
538 case IrInstSrcIdUndeclaredIdent:
539 return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name);
540 case IrInstSrcIdAlloca:
541 return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name);
542 case IrInstSrcIdEndExpr:
543 return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name);
544 case IrInstSrcIdUnionInitNamedField:
545 return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name);
546 case IrInstSrcIdSuspendBegin:
547 return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name);
548 case IrInstSrcIdSuspendFinish:
549 return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name);
550 case IrInstSrcIdResume:
551 return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name);
552 case IrInstSrcIdAwait:
553 return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name);
554 case IrInstSrcIdSpillBegin:
555 return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name);
556 case IrInstSrcIdSpillEnd:
557 return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name);
558 case IrInstSrcIdCallArgs:
559 return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name);
560 }
561 zig_unreachable();
562}
267563
268static void destroy_instruction(IrInstruction *inst) {
564void destroy_instruction_gen(IrInstGen *inst) {
269565#ifdef ZIG_ENABLE_MEM_PROFILE
270 const char *name = ir_instruction_type_str(inst->id);
566 const char *name = ir_inst_gen_type_str(inst->id);
271567#else
272568 const char *name = nullptr;
273569#endif
274570 switch (inst->id) {
275 case IrInstructionIdInvalid:
571 case IrInstGenIdInvalid:
276572 zig_unreachable();
277 case IrInstructionIdReturn:
278 return destroy(reinterpret_cast<IrInstructionReturn *>(inst), name);
279 case IrInstructionIdConst:
280 return destroy(reinterpret_cast<IrInstructionConst *>(inst), name);
281 case IrInstructionIdBinOp:
282 return destroy(reinterpret_cast<IrInstructionBinOp *>(inst), name);
283 case IrInstructionIdMergeErrSets:
284 return destroy(reinterpret_cast<IrInstructionMergeErrSets *>(inst), name);
285 case IrInstructionIdDeclVarSrc:
286 return destroy(reinterpret_cast<IrInstructionDeclVarSrc *>(inst), name);
287 case IrInstructionIdCast:
288 return destroy(reinterpret_cast<IrInstructionCast *>(inst), name);
289 case IrInstructionIdCallSrc:
290 return destroy(reinterpret_cast<IrInstructionCallSrc *>(inst), name);
291 case IrInstructionIdCallSrcArgs:
292 return destroy(reinterpret_cast<IrInstructionCallSrcArgs *>(inst), name);
293 case IrInstructionIdCallExtra:
294 return destroy(reinterpret_cast<IrInstructionCallExtra *>(inst), name);
295 case IrInstructionIdCallGen:
296 return destroy(reinterpret_cast<IrInstructionCallGen *>(inst), name);
297 case IrInstructionIdUnOp:
298 return destroy(reinterpret_cast<IrInstructionUnOp *>(inst), name);
299 case IrInstructionIdCondBr:
300 return destroy(reinterpret_cast<IrInstructionCondBr *>(inst), name);
301 case IrInstructionIdBr:
302 return destroy(reinterpret_cast<IrInstructionBr *>(inst), name);
303 case IrInstructionIdPhi:
304 return destroy(reinterpret_cast<IrInstructionPhi *>(inst), name);
305 case IrInstructionIdContainerInitList:
306 return destroy(reinterpret_cast<IrInstructionContainerInitList *>(inst), name);
307 case IrInstructionIdContainerInitFields:
308 return destroy(reinterpret_cast<IrInstructionContainerInitFields *>(inst), name);
309 case IrInstructionIdUnreachable:
310 return destroy(reinterpret_cast<IrInstructionUnreachable *>(inst), name);
311 case IrInstructionIdElemPtr:
312 return destroy(reinterpret_cast<IrInstructionElemPtr *>(inst), name);
313 case IrInstructionIdVarPtr:
314 return destroy(reinterpret_cast<IrInstructionVarPtr *>(inst), name);
315 case IrInstructionIdReturnPtr:
316 return destroy(reinterpret_cast<IrInstructionReturnPtr *>(inst), name);
317 case IrInstructionIdLoadPtr:
318 return destroy(reinterpret_cast<IrInstructionLoadPtr *>(inst), name);
319 case IrInstructionIdLoadPtrGen:
320 return destroy(reinterpret_cast<IrInstructionLoadPtrGen *>(inst), name);
321 case IrInstructionIdStorePtr:
322 return destroy(reinterpret_cast<IrInstructionStorePtr *>(inst), name);
323 case IrInstructionIdVectorStoreElem:
324 return destroy(reinterpret_cast<IrInstructionVectorStoreElem *>(inst), name);
325 case IrInstructionIdTypeOf:
326 return destroy(reinterpret_cast<IrInstructionTypeOf *>(inst), name);
327 case IrInstructionIdFieldPtr:
328 return destroy(reinterpret_cast<IrInstructionFieldPtr *>(inst), name);
329 case IrInstructionIdStructFieldPtr:
330 return destroy(reinterpret_cast<IrInstructionStructFieldPtr *>(inst), name);
331 case IrInstructionIdUnionFieldPtr:
332 return destroy(reinterpret_cast<IrInstructionUnionFieldPtr *>(inst), name);
333 case IrInstructionIdSetCold:
334 return destroy(reinterpret_cast<IrInstructionSetCold *>(inst), name);
335 case IrInstructionIdSetRuntimeSafety:
336 return destroy(reinterpret_cast<IrInstructionSetRuntimeSafety *>(inst), name);
337 case IrInstructionIdSetFloatMode:
338 return destroy(reinterpret_cast<IrInstructionSetFloatMode *>(inst), name);
339 case IrInstructionIdArrayType:
340 return destroy(reinterpret_cast<IrInstructionArrayType *>(inst), name);
341 case IrInstructionIdSliceType:
342 return destroy(reinterpret_cast<IrInstructionSliceType *>(inst), name);
343 case IrInstructionIdAnyFrameType:
344 return destroy(reinterpret_cast<IrInstructionAnyFrameType *>(inst), name);
345 case IrInstructionIdAsmSrc:
346 return destroy(reinterpret_cast<IrInstructionAsmSrc *>(inst), name);
347 case IrInstructionIdAsmGen:
348 return destroy(reinterpret_cast<IrInstructionAsmGen *>(inst), name);
349 case IrInstructionIdSizeOf:
350 return destroy(reinterpret_cast<IrInstructionSizeOf *>(inst), name);
351 case IrInstructionIdTestNonNull:
352 return destroy(reinterpret_cast<IrInstructionTestNonNull *>(inst), name);
353 case IrInstructionIdOptionalUnwrapPtr:
354 return destroy(reinterpret_cast<IrInstructionOptionalUnwrapPtr *>(inst), name);
355 case IrInstructionIdPopCount:
356 return destroy(reinterpret_cast<IrInstructionPopCount *>(inst), name);
357 case IrInstructionIdClz:
358 return destroy(reinterpret_cast<IrInstructionClz *>(inst), name);
359 case IrInstructionIdCtz:
360 return destroy(reinterpret_cast<IrInstructionCtz *>(inst), name);
361 case IrInstructionIdBswap:
362 return destroy(reinterpret_cast<IrInstructionBswap *>(inst), name);
363 case IrInstructionIdBitReverse:
364 return destroy(reinterpret_cast<IrInstructionBitReverse *>(inst), name);
365 case IrInstructionIdSwitchBr:
366 return destroy(reinterpret_cast<IrInstructionSwitchBr *>(inst), name);
367 case IrInstructionIdSwitchVar:
368 return destroy(reinterpret_cast<IrInstructionSwitchVar *>(inst), name);
369 case IrInstructionIdSwitchElseVar:
370 return destroy(reinterpret_cast<IrInstructionSwitchElseVar *>(inst), name);
371 case IrInstructionIdSwitchTarget:
372 return destroy(reinterpret_cast<IrInstructionSwitchTarget *>(inst), name);
373 case IrInstructionIdUnionTag:
374 return destroy(reinterpret_cast<IrInstructionUnionTag *>(inst), name);
375 case IrInstructionIdImport:
376 return destroy(reinterpret_cast<IrInstructionImport *>(inst), name);
377 case IrInstructionIdRef:
378 return destroy(reinterpret_cast<IrInstructionRef *>(inst), name);
379 case IrInstructionIdRefGen:
380 return destroy(reinterpret_cast<IrInstructionRefGen *>(inst), name);
381 case IrInstructionIdCompileErr:
382 return destroy(reinterpret_cast<IrInstructionCompileErr *>(inst), name);
383 case IrInstructionIdCompileLog:
384 return destroy(reinterpret_cast<IrInstructionCompileLog *>(inst), name);
385 case IrInstructionIdErrName:
386 return destroy(reinterpret_cast<IrInstructionErrName *>(inst), name);
387 case IrInstructionIdCImport:
388 return destroy(reinterpret_cast<IrInstructionCImport *>(inst), name);
389 case IrInstructionIdCInclude:
390 return destroy(reinterpret_cast<IrInstructionCInclude *>(inst), name);
391 case IrInstructionIdCDefine:
392 return destroy(reinterpret_cast<IrInstructionCDefine *>(inst), name);
393 case IrInstructionIdCUndef:
394 return destroy(reinterpret_cast<IrInstructionCUndef *>(inst), name);
395 case IrInstructionIdEmbedFile:
396 return destroy(reinterpret_cast<IrInstructionEmbedFile *>(inst), name);
397 case IrInstructionIdCmpxchgSrc:
398 return destroy(reinterpret_cast<IrInstructionCmpxchgSrc *>(inst), name);
399 case IrInstructionIdCmpxchgGen:
400 return destroy(reinterpret_cast<IrInstructionCmpxchgGen *>(inst), name);
401 case IrInstructionIdFence:
402 return destroy(reinterpret_cast<IrInstructionFence *>(inst), name);
403 case IrInstructionIdTruncate:
404 return destroy(reinterpret_cast<IrInstructionTruncate *>(inst), name);
405 case IrInstructionIdIntCast:
406 return destroy(reinterpret_cast<IrInstructionIntCast *>(inst), name);
407 case IrInstructionIdFloatCast:
408 return destroy(reinterpret_cast<IrInstructionFloatCast *>(inst), name);
409 case IrInstructionIdErrSetCast:
410 return destroy(reinterpret_cast<IrInstructionErrSetCast *>(inst), name);
411 case IrInstructionIdFromBytes:
412 return destroy(reinterpret_cast<IrInstructionFromBytes *>(inst), name);
413 case IrInstructionIdToBytes:
414 return destroy(reinterpret_cast<IrInstructionToBytes *>(inst), name);
415 case IrInstructionIdIntToFloat:
416 return destroy(reinterpret_cast<IrInstructionIntToFloat *>(inst), name);
417 case IrInstructionIdFloatToInt:
418 return destroy(reinterpret_cast<IrInstructionFloatToInt *>(inst), name);
419 case IrInstructionIdBoolToInt:
420 return destroy(reinterpret_cast<IrInstructionBoolToInt *>(inst), name);
421 case IrInstructionIdIntType:
422 return destroy(reinterpret_cast<IrInstructionIntType *>(inst), name);
423 case IrInstructionIdVectorType:
424 return destroy(reinterpret_cast<IrInstructionVectorType *>(inst), name);
425 case IrInstructionIdShuffleVector:
426 return destroy(reinterpret_cast<IrInstructionShuffleVector *>(inst), name);
427 case IrInstructionIdSplatSrc:
428 return destroy(reinterpret_cast<IrInstructionSplatSrc *>(inst), name);
429 case IrInstructionIdSplatGen:
430 return destroy(reinterpret_cast<IrInstructionSplatGen *>(inst), name);
431 case IrInstructionIdBoolNot:
432 return destroy(reinterpret_cast<IrInstructionBoolNot *>(inst), name);
433 case IrInstructionIdMemset:
434 return destroy(reinterpret_cast<IrInstructionMemset *>(inst), name);
435 case IrInstructionIdMemcpy:
436 return destroy(reinterpret_cast<IrInstructionMemcpy *>(inst), name);
437 case IrInstructionIdSliceSrc:
438 return destroy(reinterpret_cast<IrInstructionSliceSrc *>(inst), name);
439 case IrInstructionIdSliceGen:
440 return destroy(reinterpret_cast<IrInstructionSliceGen *>(inst), name);
441 case IrInstructionIdMemberCount:
442 return destroy(reinterpret_cast<IrInstructionMemberCount *>(inst), name);
443 case IrInstructionIdMemberType:
444 return destroy(reinterpret_cast<IrInstructionMemberType *>(inst), name);
445 case IrInstructionIdMemberName:
446 return destroy(reinterpret_cast<IrInstructionMemberName *>(inst), name);
447 case IrInstructionIdBreakpoint:
448 return destroy(reinterpret_cast<IrInstructionBreakpoint *>(inst), name);
449 case IrInstructionIdReturnAddress:
450 return destroy(reinterpret_cast<IrInstructionReturnAddress *>(inst), name);
451 case IrInstructionIdFrameAddress:
452 return destroy(reinterpret_cast<IrInstructionFrameAddress *>(inst), name);
453 case IrInstructionIdFrameHandle:
454 return destroy(reinterpret_cast<IrInstructionFrameHandle *>(inst), name);
455 case IrInstructionIdFrameType:
456 return destroy(reinterpret_cast<IrInstructionFrameType *>(inst), name);
457 case IrInstructionIdFrameSizeSrc:
458 return destroy(reinterpret_cast<IrInstructionFrameSizeSrc *>(inst), name);
459 case IrInstructionIdFrameSizeGen:
460 return destroy(reinterpret_cast<IrInstructionFrameSizeGen *>(inst), name);
461 case IrInstructionIdAlignOf:
462 return destroy(reinterpret_cast<IrInstructionAlignOf *>(inst), name);
463 case IrInstructionIdOverflowOp:
464 return destroy(reinterpret_cast<IrInstructionOverflowOp *>(inst), name);
465 case IrInstructionIdTestErrSrc:
466 return destroy(reinterpret_cast<IrInstructionTestErrSrc *>(inst), name);
467 case IrInstructionIdTestErrGen:
468 return destroy(reinterpret_cast<IrInstructionTestErrGen *>(inst), name);
469 case IrInstructionIdUnwrapErrCode:
470 return destroy(reinterpret_cast<IrInstructionUnwrapErrCode *>(inst), name);
471 case IrInstructionIdUnwrapErrPayload:
472 return destroy(reinterpret_cast<IrInstructionUnwrapErrPayload *>(inst), name);
473 case IrInstructionIdOptionalWrap:
474 return destroy(reinterpret_cast<IrInstructionOptionalWrap *>(inst), name);
475 case IrInstructionIdErrWrapCode:
476 return destroy(reinterpret_cast<IrInstructionErrWrapCode *>(inst), name);
477 case IrInstructionIdErrWrapPayload:
478 return destroy(reinterpret_cast<IrInstructionErrWrapPayload *>(inst), name);
479 case IrInstructionIdFnProto:
480 return destroy(reinterpret_cast<IrInstructionFnProto *>(inst), name);
481 case IrInstructionIdTestComptime:
482 return destroy(reinterpret_cast<IrInstructionTestComptime *>(inst), name);
483 case IrInstructionIdPtrCastSrc:
484 return destroy(reinterpret_cast<IrInstructionPtrCastSrc *>(inst), name);
485 case IrInstructionIdPtrCastGen:
486 return destroy(reinterpret_cast<IrInstructionPtrCastGen *>(inst), name);
487 case IrInstructionIdBitCastSrc:
488 return destroy(reinterpret_cast<IrInstructionBitCastSrc *>(inst), name);
489 case IrInstructionIdBitCastGen:
490 return destroy(reinterpret_cast<IrInstructionBitCastGen *>(inst), name);
491 case IrInstructionIdWidenOrShorten:
492 return destroy(reinterpret_cast<IrInstructionWidenOrShorten *>(inst), name);
493 case IrInstructionIdPtrToInt:
494 return destroy(reinterpret_cast<IrInstructionPtrToInt *>(inst), name);
495 case IrInstructionIdIntToPtr:
496 return destroy(reinterpret_cast<IrInstructionIntToPtr *>(inst), name);
497 case IrInstructionIdIntToEnum:
498 return destroy(reinterpret_cast<IrInstructionIntToEnum *>(inst), name);
499 case IrInstructionIdIntToErr:
500 return destroy(reinterpret_cast<IrInstructionIntToErr *>(inst), name);
501 case IrInstructionIdErrToInt:
502 return destroy(reinterpret_cast<IrInstructionErrToInt *>(inst), name);
503 case IrInstructionIdCheckSwitchProngs:
504 return destroy(reinterpret_cast<IrInstructionCheckSwitchProngs *>(inst), name);
505 case IrInstructionIdCheckStatementIsVoid:
506 return destroy(reinterpret_cast<IrInstructionCheckStatementIsVoid *>(inst), name);
507 case IrInstructionIdTypeName:
508 return destroy(reinterpret_cast<IrInstructionTypeName *>(inst), name);
509 case IrInstructionIdTagName:
510 return destroy(reinterpret_cast<IrInstructionTagName *>(inst), name);
511 case IrInstructionIdPtrType:
512 return destroy(reinterpret_cast<IrInstructionPtrType *>(inst), name);
513 case IrInstructionIdDeclRef:
514 return destroy(reinterpret_cast<IrInstructionDeclRef *>(inst), name);
515 case IrInstructionIdPanic:
516 return destroy(reinterpret_cast<IrInstructionPanic *>(inst), name);
517 case IrInstructionIdFieldParentPtr:
518 return destroy(reinterpret_cast<IrInstructionFieldParentPtr *>(inst), name);
519 case IrInstructionIdByteOffsetOf:
520 return destroy(reinterpret_cast<IrInstructionByteOffsetOf *>(inst), name);
521 case IrInstructionIdBitOffsetOf:
522 return destroy(reinterpret_cast<IrInstructionBitOffsetOf *>(inst), name);
523 case IrInstructionIdTypeInfo:
524 return destroy(reinterpret_cast<IrInstructionTypeInfo *>(inst), name);
525 case IrInstructionIdType:
526 return destroy(reinterpret_cast<IrInstructionType *>(inst), name);
527 case IrInstructionIdHasField:
528 return destroy(reinterpret_cast<IrInstructionHasField *>(inst), name);
529 case IrInstructionIdTypeId:
530 return destroy(reinterpret_cast<IrInstructionTypeId *>(inst), name);
531 case IrInstructionIdSetEvalBranchQuota:
532 return destroy(reinterpret_cast<IrInstructionSetEvalBranchQuota *>(inst), name);
533 case IrInstructionIdAlignCast:
534 return destroy(reinterpret_cast<IrInstructionAlignCast *>(inst), name);
535 case IrInstructionIdImplicitCast:
536 return destroy(reinterpret_cast<IrInstructionImplicitCast *>(inst), name);
537 case IrInstructionIdResolveResult:
538 return destroy(reinterpret_cast<IrInstructionResolveResult *>(inst), name);
539 case IrInstructionIdResetResult:
540 return destroy(reinterpret_cast<IrInstructionResetResult *>(inst), name);
541 case IrInstructionIdOpaqueType:
542 return destroy(reinterpret_cast<IrInstructionOpaqueType *>(inst), name);
543 case IrInstructionIdSetAlignStack:
544 return destroy(reinterpret_cast<IrInstructionSetAlignStack *>(inst), name);
545 case IrInstructionIdArgType:
546 return destroy(reinterpret_cast<IrInstructionArgType *>(inst), name);
547 case IrInstructionIdTagType:
548 return destroy(reinterpret_cast<IrInstructionTagType *>(inst), name);
549 case IrInstructionIdExport:
550 return destroy(reinterpret_cast<IrInstructionExport *>(inst), name);
551 case IrInstructionIdErrorReturnTrace:
552 return destroy(reinterpret_cast<IrInstructionErrorReturnTrace *>(inst), name);
553 case IrInstructionIdErrorUnion:
554 return destroy(reinterpret_cast<IrInstructionErrorUnion *>(inst), name);
555 case IrInstructionIdAtomicRmw:
556 return destroy(reinterpret_cast<IrInstructionAtomicRmw *>(inst), name);
557 case IrInstructionIdSaveErrRetAddr:
558 return destroy(reinterpret_cast<IrInstructionSaveErrRetAddr *>(inst), name);
559 case IrInstructionIdAddImplicitReturnType:
560 return destroy(reinterpret_cast<IrInstructionAddImplicitReturnType *>(inst), name);
561 case IrInstructionIdFloatOp:
562 return destroy(reinterpret_cast<IrInstructionFloatOp *>(inst), name);
563 case IrInstructionIdMulAdd:
564 return destroy(reinterpret_cast<IrInstructionMulAdd *>(inst), name);
565 case IrInstructionIdAtomicLoad:
566 return destroy(reinterpret_cast<IrInstructionAtomicLoad *>(inst), name);
567 case IrInstructionIdAtomicStore:
568 return destroy(reinterpret_cast<IrInstructionAtomicStore *>(inst), name);
569 case IrInstructionIdEnumToInt:
570 return destroy(reinterpret_cast<IrInstructionEnumToInt *>(inst), name);
571 case IrInstructionIdCheckRuntimeScope:
572 return destroy(reinterpret_cast<IrInstructionCheckRuntimeScope *>(inst), name);
573 case IrInstructionIdDeclVarGen:
574 return destroy(reinterpret_cast<IrInstructionDeclVarGen *>(inst), name);
575 case IrInstructionIdArrayToVector:
576 return destroy(reinterpret_cast<IrInstructionArrayToVector *>(inst), name);
577 case IrInstructionIdVectorToArray:
578 return destroy(reinterpret_cast<IrInstructionVectorToArray *>(inst), name);
579 case IrInstructionIdPtrOfArrayToSlice:
580 return destroy(reinterpret_cast<IrInstructionPtrOfArrayToSlice *>(inst), name);
581 case IrInstructionIdAssertZero:
582 return destroy(reinterpret_cast<IrInstructionAssertZero *>(inst), name);
583 case IrInstructionIdAssertNonNull:
584 return destroy(reinterpret_cast<IrInstructionAssertNonNull *>(inst), name);
585 case IrInstructionIdResizeSlice:
586 return destroy(reinterpret_cast<IrInstructionResizeSlice *>(inst), name);
587 case IrInstructionIdHasDecl:
588 return destroy(reinterpret_cast<IrInstructionHasDecl *>(inst), name);
589 case IrInstructionIdUndeclaredIdent:
590 return destroy(reinterpret_cast<IrInstructionUndeclaredIdent *>(inst), name);
591 case IrInstructionIdAllocaSrc:
592 return destroy(reinterpret_cast<IrInstructionAllocaSrc *>(inst), name);
593 case IrInstructionIdAllocaGen:
594 return destroy(reinterpret_cast<IrInstructionAllocaGen *>(inst), name);
595 case IrInstructionIdEndExpr:
596 return destroy(reinterpret_cast<IrInstructionEndExpr *>(inst), name);
597 case IrInstructionIdUnionInitNamedField:
598 return destroy(reinterpret_cast<IrInstructionUnionInitNamedField *>(inst), name);
599 case IrInstructionIdSuspendBegin:
600 return destroy(reinterpret_cast<IrInstructionSuspendBegin *>(inst), name);
601 case IrInstructionIdSuspendFinish:
602 return destroy(reinterpret_cast<IrInstructionSuspendFinish *>(inst), name);
603 case IrInstructionIdResume:
604 return destroy(reinterpret_cast<IrInstructionResume *>(inst), name);
605 case IrInstructionIdAwaitSrc:
606 return destroy(reinterpret_cast<IrInstructionAwaitSrc *>(inst), name);
607 case IrInstructionIdAwaitGen:
608 return destroy(reinterpret_cast<IrInstructionAwaitGen *>(inst), name);
609 case IrInstructionIdSpillBegin:
610 return destroy(reinterpret_cast<IrInstructionSpillBegin *>(inst), name);
611 case IrInstructionIdSpillEnd:
612 return destroy(reinterpret_cast<IrInstructionSpillEnd *>(inst), name);
613 case IrInstructionIdVectorExtractElem:
614 return destroy(reinterpret_cast<IrInstructionVectorExtractElem *>(inst), name);
573 case IrInstGenIdReturn:
574 return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name);
575 case IrInstGenIdConst:
576 return destroy(reinterpret_cast<IrInstGenConst *>(inst), name);
577 case IrInstGenIdBinOp:
578 return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name);
579 case IrInstGenIdCast:
580 return destroy(reinterpret_cast<IrInstGenCast *>(inst), name);
581 case IrInstGenIdCall:
582 return destroy(reinterpret_cast<IrInstGenCall *>(inst), name);
583 case IrInstGenIdCondBr:
584 return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name);
585 case IrInstGenIdBr:
586 return destroy(reinterpret_cast<IrInstGenBr *>(inst), name);
587 case IrInstGenIdPhi:
588 return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name);
589 case IrInstGenIdUnreachable:
590 return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name);
591 case IrInstGenIdElemPtr:
592 return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name);
593 case IrInstGenIdVarPtr:
594 return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name);
595 case IrInstGenIdReturnPtr:
596 return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name);
597 case IrInstGenIdLoadPtr:
598 return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name);
599 case IrInstGenIdStorePtr:
600 return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name);
601 case IrInstGenIdVectorStoreElem:
602 return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name);
603 case IrInstGenIdStructFieldPtr:
604 return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name);
605 case IrInstGenIdUnionFieldPtr:
606 return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name);
607 case IrInstGenIdAsm:
608 return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name);
609 case IrInstGenIdTestNonNull:
610 return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name);
611 case IrInstGenIdOptionalUnwrapPtr:
612 return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name);
613 case IrInstGenIdPopCount:
614 return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name);
615 case IrInstGenIdClz:
616 return destroy(reinterpret_cast<IrInstGenClz *>(inst), name);
617 case IrInstGenIdCtz:
618 return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name);
619 case IrInstGenIdBswap:
620 return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name);
621 case IrInstGenIdBitReverse:
622 return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name);
623 case IrInstGenIdSwitchBr:
624 return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name);
625 case IrInstGenIdUnionTag:
626 return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name);
627 case IrInstGenIdRef:
628 return destroy(reinterpret_cast<IrInstGenRef *>(inst), name);
629 case IrInstGenIdErrName:
630 return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name);
631 case IrInstGenIdCmpxchg:
632 return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name);
633 case IrInstGenIdFence:
634 return destroy(reinterpret_cast<IrInstGenFence *>(inst), name);
635 case IrInstGenIdTruncate:
636 return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name);
637 case IrInstGenIdShuffleVector:
638 return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name);
639 case IrInstGenIdSplat:
640 return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name);
641 case IrInstGenIdBoolNot:
642 return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name);
643 case IrInstGenIdMemset:
644 return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name);
645 case IrInstGenIdMemcpy:
646 return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name);
647 case IrInstGenIdSlice:
648 return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name);
649 case IrInstGenIdBreakpoint:
650 return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name);
651 case IrInstGenIdReturnAddress:
652 return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name);
653 case IrInstGenIdFrameAddress:
654 return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name);
655 case IrInstGenIdFrameHandle:
656 return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name);
657 case IrInstGenIdFrameSize:
658 return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name);
659 case IrInstGenIdOverflowOp:
660 return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name);
661 case IrInstGenIdTestErr:
662 return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name);
663 case IrInstGenIdUnwrapErrCode:
664 return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name);
665 case IrInstGenIdUnwrapErrPayload:
666 return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name);
667 case IrInstGenIdOptionalWrap:
668 return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name);
669 case IrInstGenIdErrWrapCode:
670 return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name);
671 case IrInstGenIdErrWrapPayload:
672 return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name);
673 case IrInstGenIdPtrCast:
674 return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name);
675 case IrInstGenIdBitCast:
676 return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name);
677 case IrInstGenIdWidenOrShorten:
678 return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name);
679 case IrInstGenIdPtrToInt:
680 return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name);
681 case IrInstGenIdIntToPtr:
682 return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name);
683 case IrInstGenIdIntToEnum:
684 return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name);
685 case IrInstGenIdIntToErr:
686 return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name);
687 case IrInstGenIdErrToInt:
688 return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name);
689 case IrInstGenIdTagName:
690 return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name);
691 case IrInstGenIdPanic:
692 return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name);
693 case IrInstGenIdFieldParentPtr:
694 return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name);
695 case IrInstGenIdAlignCast:
696 return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name);
697 case IrInstGenIdErrorReturnTrace:
698 return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name);
699 case IrInstGenIdAtomicRmw:
700 return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name);
701 case IrInstGenIdSaveErrRetAddr:
702 return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name);
703 case IrInstGenIdFloatOp:
704 return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name);
705 case IrInstGenIdMulAdd:
706 return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name);
707 case IrInstGenIdAtomicLoad:
708 return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name);
709 case IrInstGenIdAtomicStore:
710 return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name);
711 case IrInstGenIdDeclVar:
712 return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name);
713 case IrInstGenIdArrayToVector:
714 return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name);
715 case IrInstGenIdVectorToArray:
716 return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name);
717 case IrInstGenIdPtrOfArrayToSlice:
718 return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name);
719 case IrInstGenIdAssertZero:
720 return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name);
721 case IrInstGenIdAssertNonNull:
722 return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name);
723 case IrInstGenIdResizeSlice:
724 return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name);
725 case IrInstGenIdAlloca:
726 return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name);
727 case IrInstGenIdSuspendBegin:
728 return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name);
729 case IrInstGenIdSuspendFinish:
730 return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name);
731 case IrInstGenIdResume:
732 return destroy(reinterpret_cast<IrInstGenResume *>(inst), name);
733 case IrInstGenIdAwait:
734 return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name);
735 case IrInstGenIdSpillBegin:
736 return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name);
737 case IrInstGenIdSpillEnd:
738 return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name);
739 case IrInstGenIdVectorExtractElem:
740 return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name);
741 case IrInstGenIdBinaryNot:
742 return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name);
743 case IrInstGenIdNegation:
744 return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name);
745 case IrInstGenIdNegationWrapping:
746 return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name);
615747 }
616748 zig_unreachable();
617749}
......@@ -627,17 +759,17 @@ static void ira_deref(IrAnalyze *ira) {
627759 assert(ira->ref_count != 0);
628760
629761 for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) {
630 IrBasicBlock *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i];
762 IrBasicBlockSrc *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i];
631763 for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) {
632 IrInstruction *pass1_inst = pass1_bb->instruction_list.items[inst_i];
633 destroy_instruction(pass1_inst);
764 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];
765 destroy_instruction_src(pass1_inst);
634766 }
635 destroy(pass1_bb, "IrBasicBlock");
767 destroy(pass1_bb, "IrBasicBlockSrc");
636768 }
637769 ira->old_irb.exec->basic_block_list.deinit();
638770 ira->old_irb.exec->tld_list.deinit();
639771 // cannot destroy here because of var->owner_exec
640 //destroy(ira->old_irb.exec, "IrExecutablePass1");
772 //destroy(ira->old_irb.exec, "IrExecutableSrc");
641773 ira->src_implicit_return_type_list.deinit();
642774 ira->resume_stack.deinit();
643775 ira->exec_context.mem_slot_list.deinit();
......@@ -785,7 +917,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
785917 zig_unreachable();
786918}
787919
788static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
920static bool ir_should_inline(IrExecutableSrc *exec, Scope *scope) {
789921 if (exec->is_inline)
790922 return true;
791923
......@@ -801,29 +933,41 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
801933 return false;
802934}
803935
804static void ir_instruction_append(IrBasicBlock *basic_block, IrInstruction *instruction) {
936static void ir_instruction_append(IrBasicBlockSrc *basic_block, IrInstSrc *instruction) {
937 assert(basic_block);
938 assert(instruction);
939 basic_block->instruction_list.append(instruction);
940}
941
942static void ir_inst_gen_append(IrBasicBlockGen *basic_block, IrInstGen *instruction) {
805943 assert(basic_block);
806944 assert(instruction);
807945 basic_block->instruction_list.append(instruction);
808946}
809947
810static size_t exec_next_debug_id(IrExecutable *exec) {
948static size_t exec_next_debug_id(IrExecutableSrc *exec) {
949 size_t result = exec->next_debug_id;
950 exec->next_debug_id += 1;
951 return result;
952}
953
954static size_t exec_next_debug_id_gen(IrExecutableGen *exec) {
811955 size_t result = exec->next_debug_id;
812956 exec->next_debug_id += 1;
813957 return result;
814958}
815959
816static size_t exec_next_mem_slot(IrExecutable *exec) {
960static size_t exec_next_mem_slot(IrExecutableSrc *exec) {
817961 size_t result = exec->mem_slot_count;
818962 exec->mem_slot_count += 1;
819963 return result;
820964}
821965
822static ZigFn *exec_fn_entry(IrExecutable *exec) {
966static ZigFn *exec_fn_entry(IrExecutableSrc *exec) {
823967 return exec->fn_entry;
824968}
825969
826static Buf *exec_c_import_buf(IrExecutable *exec) {
970static Buf *exec_c_import_buf(IrExecutableSrc *exec) {
827971 return exec->c_import_buf;
828972}
829973
......@@ -831,28 +975,42 @@ static bool value_is_comptime(ZigValue *const_val) {
831975 return const_val->special != ConstValSpecialRuntime;
832976}
833977
834static bool instr_is_comptime(IrInstruction *instruction) {
978static bool instr_is_comptime(IrInstGen *instruction) {
835979 return value_is_comptime(instruction->value);
836980}
837981
838static bool instr_is_unreachable(IrInstruction *instruction) {
839 return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable;
982static bool instr_is_unreachable(IrInstSrc *instruction) {
983 return instruction->is_noreturn;
840984}
841985
842static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) {
843 new_bb->other = old_bb;
844 old_bb->other = new_bb;
986static void ir_link_new_bb(IrBasicBlockGen *new_bb, IrBasicBlockSrc *old_bb) {
987 new_bb->parent = old_bb;
988 old_bb->child = new_bb;
845989}
846990
847static void ir_ref_bb(IrBasicBlock *bb) {
991static void ir_ref_bb(IrBasicBlockSrc *bb) {
848992 bb->ref_count += 1;
849993}
850994
851static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) {
852 assert(instruction->id != IrInstructionIdInvalid);
853 instruction->ref_count += 1;
854 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))
995static void ir_ref_bb_gen(IrBasicBlockGen *bb) {
996 bb->ref_count += 1;
997}
998
999static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb) {
1000 assert(instruction->id != IrInstSrcIdInvalid);
1001 instruction->base.ref_count += 1;
1002 if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction)
1003 && instruction->id != IrInstSrcIdConst)
1004 {
8551005 ir_ref_bb(instruction->owner_bb);
1006 }
1007}
1008
1009static void ir_ref_inst_gen(IrInstGen *instruction, IrBasicBlockGen *cur_bb) {
1010 assert(instruction->id != IrInstGenIdInvalid);
1011 instruction->base.ref_count += 1;
1012 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))
1013 ir_ref_bb_gen(instruction->owner_bb);
8561014}
8571015
8581016static void ir_ref_var(ZigVar *var) {
......@@ -871,962 +1029,1259 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
8711029 return result->data.x_type;
8721030}
8731031
874static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) {
875 IrBasicBlock *result = allocate<IrBasicBlock>(1, "IrBasicBlock");
1032static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {
1033 IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc");
8761034 result->scope = scope;
8771035 result->name_hint = name_hint;
8781036 result->debug_id = exec_next_debug_id(irb->exec);
879 result->index = SIZE_MAX; // set later
1037 result->index = UINT32_MAX; // set later
8801038 return result;
8811039}
8821040
883static IrBasicBlock *ir_build_bb_from(IrBuilder *irb, IrBasicBlock *other_bb) {
884 IrBasicBlock *new_bb = ir_create_basic_block(irb, other_bb->scope, other_bb->name_hint);
1041static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) {
1042 IrBasicBlockGen *result = allocate<IrBasicBlockGen>(1, "IrBasicBlockGen");
1043 result->scope = scope;
1044 result->name_hint = name_hint;
1045 result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec);
1046 result->index = UINT32_MAX; // set later
1047 return result;
1048}
1049
1050static IrBasicBlockGen *ir_build_bb_from(IrAnalyze *ira, IrBasicBlockSrc *other_bb) {
1051 IrBasicBlockGen *new_bb = ir_create_basic_block_gen(ira, other_bb->scope, other_bb->name_hint);
8851052 ir_link_new_bb(new_bb, other_bb);
8861053 return new_bb;
8871054}
8881055
889static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarSrc *) {
890 return IrInstructionIdDeclVarSrc;
1056static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclVar *) {
1057 return IrInstSrcIdDeclVar;
1058}
1059
1060static constexpr IrInstSrcId ir_inst_id(IrInstSrcBr *) {
1061 return IrInstSrcIdBr;
1062}
1063
1064static constexpr IrInstSrcId ir_inst_id(IrInstSrcCondBr *) {
1065 return IrInstSrcIdCondBr;
1066}
1067
1068static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchBr *) {
1069 return IrInstSrcIdSwitchBr;
1070}
1071
1072static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchVar *) {
1073 return IrInstSrcIdSwitchVar;
1074}
1075
1076static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchElseVar *) {
1077 return IrInstSrcIdSwitchElseVar;
1078}
1079
1080static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchTarget *) {
1081 return IrInstSrcIdSwitchTarget;
1082}
1083
1084static constexpr IrInstSrcId ir_inst_id(IrInstSrcPhi *) {
1085 return IrInstSrcIdPhi;
1086}
1087
1088static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnOp *) {
1089 return IrInstSrcIdUnOp;
1090}
1091
1092static constexpr IrInstSrcId ir_inst_id(IrInstSrcBinOp *) {
1093 return IrInstSrcIdBinOp;
1094}
1095
1096static constexpr IrInstSrcId ir_inst_id(IrInstSrcMergeErrSets *) {
1097 return IrInstSrcIdMergeErrSets;
1098}
1099
1100static constexpr IrInstSrcId ir_inst_id(IrInstSrcLoadPtr *) {
1101 return IrInstSrcIdLoadPtr;
1102}
1103
1104static constexpr IrInstSrcId ir_inst_id(IrInstSrcStorePtr *) {
1105 return IrInstSrcIdStorePtr;
1106}
1107
1108static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldPtr *) {
1109 return IrInstSrcIdFieldPtr;
1110}
1111
1112static constexpr IrInstSrcId ir_inst_id(IrInstSrcElemPtr *) {
1113 return IrInstSrcIdElemPtr;
1114}
1115
1116static constexpr IrInstSrcId ir_inst_id(IrInstSrcVarPtr *) {
1117 return IrInstSrcIdVarPtr;
1118}
1119
1120static constexpr IrInstSrcId ir_inst_id(IrInstSrcCall *) {
1121 return IrInstSrcIdCall;
1122}
1123
1124static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallArgs *) {
1125 return IrInstSrcIdCallArgs;
1126}
1127
1128static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallExtra *) {
1129 return IrInstSrcIdCallExtra;
1130}
1131
1132static constexpr IrInstSrcId ir_inst_id(IrInstSrcConst *) {
1133 return IrInstSrcIdConst;
1134}
1135
1136static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturn *) {
1137 return IrInstSrcIdReturn;
1138}
1139
1140static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitList *) {
1141 return IrInstSrcIdContainerInitList;
1142}
1143
1144static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitFields *) {
1145 return IrInstSrcIdContainerInitFields;
1146}
1147
1148static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnreachable *) {
1149 return IrInstSrcIdUnreachable;
1150}
1151
1152static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeOf *) {
1153 return IrInstSrcIdTypeOf;
1154}
1155
1156static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetCold *) {
1157 return IrInstSrcIdSetCold;
1158}
1159
1160static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetRuntimeSafety *) {
1161 return IrInstSrcIdSetRuntimeSafety;
1162}
1163
1164static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetFloatMode *) {
1165 return IrInstSrcIdSetFloatMode;
1166}
1167
1168static constexpr IrInstSrcId ir_inst_id(IrInstSrcArrayType *) {
1169 return IrInstSrcIdArrayType;
1170}
1171
1172static constexpr IrInstSrcId ir_inst_id(IrInstSrcAnyFrameType *) {
1173 return IrInstSrcIdAnyFrameType;
1174}
1175
1176static constexpr IrInstSrcId ir_inst_id(IrInstSrcSliceType *) {
1177 return IrInstSrcIdSliceType;
1178}
1179
1180static constexpr IrInstSrcId ir_inst_id(IrInstSrcAsm *) {
1181 return IrInstSrcIdAsm;
1182}
1183
1184static constexpr IrInstSrcId ir_inst_id(IrInstSrcSizeOf *) {
1185 return IrInstSrcIdSizeOf;
1186}
1187
1188static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestNonNull *) {
1189 return IrInstSrcIdTestNonNull;
1190}
1191
1192static constexpr IrInstSrcId ir_inst_id(IrInstSrcOptionalUnwrapPtr *) {
1193 return IrInstSrcIdOptionalUnwrapPtr;
1194}
1195
1196static constexpr IrInstSrcId ir_inst_id(IrInstSrcClz *) {
1197 return IrInstSrcIdClz;
1198}
1199
1200static constexpr IrInstSrcId ir_inst_id(IrInstSrcCtz *) {
1201 return IrInstSrcIdCtz;
1202}
1203
1204static constexpr IrInstSrcId ir_inst_id(IrInstSrcPopCount *) {
1205 return IrInstSrcIdPopCount;
1206}
1207
1208static constexpr IrInstSrcId ir_inst_id(IrInstSrcBswap *) {
1209 return IrInstSrcIdBswap;
1210}
1211
1212static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitReverse *) {
1213 return IrInstSrcIdBitReverse;
1214}
1215
1216static constexpr IrInstSrcId ir_inst_id(IrInstSrcImport *) {
1217 return IrInstSrcIdImport;
1218}
1219
1220static constexpr IrInstSrcId ir_inst_id(IrInstSrcCImport *) {
1221 return IrInstSrcIdCImport;
1222}
1223
1224static constexpr IrInstSrcId ir_inst_id(IrInstSrcCInclude *) {
1225 return IrInstSrcIdCInclude;
1226}
1227
1228static constexpr IrInstSrcId ir_inst_id(IrInstSrcCDefine *) {
1229 return IrInstSrcIdCDefine;
1230}
1231
1232static constexpr IrInstSrcId ir_inst_id(IrInstSrcCUndef *) {
1233 return IrInstSrcIdCUndef;
1234}
1235
1236static constexpr IrInstSrcId ir_inst_id(IrInstSrcRef *) {
1237 return IrInstSrcIdRef;
1238}
1239
1240static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileErr *) {
1241 return IrInstSrcIdCompileErr;
1242}
1243
1244static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileLog *) {
1245 return IrInstSrcIdCompileLog;
1246}
1247
1248static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrName *) {
1249 return IrInstSrcIdErrName;
1250}
1251
1252static constexpr IrInstSrcId ir_inst_id(IrInstSrcEmbedFile *) {
1253 return IrInstSrcIdEmbedFile;
1254}
1255
1256static constexpr IrInstSrcId ir_inst_id(IrInstSrcCmpxchg *) {
1257 return IrInstSrcIdCmpxchg;
1258}
1259
1260static constexpr IrInstSrcId ir_inst_id(IrInstSrcFence *) {
1261 return IrInstSrcIdFence;
1262}
1263
1264static constexpr IrInstSrcId ir_inst_id(IrInstSrcTruncate *) {
1265 return IrInstSrcIdTruncate;
1266}
1267
1268static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntCast *) {
1269 return IrInstSrcIdIntCast;
1270}
1271
1272static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatCast *) {
1273 return IrInstSrcIdFloatCast;
1274}
1275
1276static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToFloat *) {
1277 return IrInstSrcIdIntToFloat;
1278}
1279
1280static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatToInt *) {
1281 return IrInstSrcIdFloatToInt;
1282}
1283
1284static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {
1285 return IrInstSrcIdBoolToInt;
8911286}
8921287
893static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarGen *) {
894 return IrInstructionIdDeclVarGen;
1288static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
1289 return IrInstSrcIdIntType;
8951290}
8961291
897static constexpr IrInstructionId ir_instruction_id(IrInstructionCondBr *) {
898 return IrInstructionIdCondBr;
1292static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
1293 return IrInstSrcIdVectorType;
8991294}
9001295
901static constexpr IrInstructionId ir_instruction_id(IrInstructionBr *) {
902 return IrInstructionIdBr;
1296static constexpr IrInstSrcId ir_inst_id(IrInstSrcShuffleVector *) {
1297 return IrInstSrcIdShuffleVector;
9031298}
9041299
905static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchBr *) {
906 return IrInstructionIdSwitchBr;
1300static constexpr IrInstSrcId ir_inst_id(IrInstSrcSplat *) {
1301 return IrInstSrcIdSplat;
9071302}
9081303
909static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchVar *) {
910 return IrInstructionIdSwitchVar;
1304static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolNot *) {
1305 return IrInstSrcIdBoolNot;
9111306}
9121307
913static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchElseVar *) {
914 return IrInstructionIdSwitchElseVar;
1308static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemset *) {
1309 return IrInstSrcIdMemset;
9151310}
9161311
917static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchTarget *) {
918 return IrInstructionIdSwitchTarget;
1312static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemcpy *) {
1313 return IrInstSrcIdMemcpy;
9191314}
9201315
921static constexpr IrInstructionId ir_instruction_id(IrInstructionPhi *) {
922 return IrInstructionIdPhi;
1316static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
1317 return IrInstSrcIdSlice;
9231318}
9241319
925static constexpr IrInstructionId ir_instruction_id(IrInstructionUnOp *) {
926 return IrInstructionIdUnOp;
1320static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
1321 return IrInstSrcIdMemberCount;
9271322}
9281323
929static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) {
930 return IrInstructionIdBinOp;
1324static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
1325 return IrInstSrcIdMemberType;
9311326}
9321327
933static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrSets *) {
934 return IrInstructionIdMergeErrSets;
1328static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
1329 return IrInstSrcIdMemberName;
9351330}
9361331
937static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) {
938 return IrInstructionIdExport;
1332static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
1333 return IrInstSrcIdBreakpoint;
9391334}
9401335
941static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtr *) {
942 return IrInstructionIdLoadPtr;
1336static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturnAddress *) {
1337 return IrInstSrcIdReturnAddress;
9431338}
9441339
945static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtrGen *) {
946 return IrInstructionIdLoadPtrGen;
1340static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameAddress *) {
1341 return IrInstSrcIdFrameAddress;
9471342}
9481343
949static constexpr IrInstructionId ir_instruction_id(IrInstructionStorePtr *) {
950 return IrInstructionIdStorePtr;
1344static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameHandle *) {
1345 return IrInstSrcIdFrameHandle;
9511346}
9521347
953static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorStoreElem *) {
954 return IrInstructionIdVectorStoreElem;
1348static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameType *) {
1349 return IrInstSrcIdFrameType;
9551350}
9561351
957static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldPtr *) {
958 return IrInstructionIdFieldPtr;
1352static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameSize *) {
1353 return IrInstSrcIdFrameSize;
9591354}
9601355
961static constexpr IrInstructionId ir_instruction_id(IrInstructionStructFieldPtr *) {
962 return IrInstructionIdStructFieldPtr;
1356static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignOf *) {
1357 return IrInstSrcIdAlignOf;
9631358}
9641359
965static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionFieldPtr *) {
966 return IrInstructionIdUnionFieldPtr;
1360static constexpr IrInstSrcId ir_inst_id(IrInstSrcOverflowOp *) {
1361 return IrInstSrcIdOverflowOp;
9671362}
9681363
969static constexpr IrInstructionId ir_instruction_id(IrInstructionElemPtr *) {
970 return IrInstructionIdElemPtr;
1364static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestErr *) {
1365 return IrInstSrcIdTestErr;
9711366}
9721367
973static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) {
974 return IrInstructionIdVarPtr;
1368static constexpr IrInstSrcId ir_inst_id(IrInstSrcMulAdd *) {
1369 return IrInstSrcIdMulAdd;
9751370}
9761371
977static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnPtr *) {
978 return IrInstructionIdReturnPtr;
1372static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatOp *) {
1373 return IrInstSrcIdFloatOp;
9791374}
9801375
981static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrc *) {
982 return IrInstructionIdCallSrc;
1376static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrCode *) {
1377 return IrInstSrcIdUnwrapErrCode;
9831378}
9841379
985static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrcArgs *) {
986 return IrInstructionIdCallSrcArgs;
1380static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrPayload *) {
1381 return IrInstSrcIdUnwrapErrPayload;
9871382}
9881383
989static constexpr IrInstructionId ir_instruction_id(IrInstructionCallExtra *) {
990 return IrInstructionIdCallExtra;
1384static constexpr IrInstSrcId ir_inst_id(IrInstSrcFnProto *) {
1385 return IrInstSrcIdFnProto;
9911386}
9921387
993static constexpr IrInstructionId ir_instruction_id(IrInstructionCallGen *) {
994 return IrInstructionIdCallGen;
1388static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestComptime *) {
1389 return IrInstSrcIdTestComptime;
9951390}
9961391
997static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) {
998 return IrInstructionIdConst;
1392static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrCast *) {
1393 return IrInstSrcIdPtrCast;
9991394}
10001395
1001static constexpr IrInstructionId ir_instruction_id(IrInstructionReturn *) {
1002 return IrInstructionIdReturn;
1396static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitCast *) {
1397 return IrInstSrcIdBitCast;
10031398}
10041399
1005static constexpr IrInstructionId ir_instruction_id(IrInstructionCast *) {
1006 return IrInstructionIdCast;
1400static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToPtr *) {
1401 return IrInstSrcIdIntToPtr;
10071402}
10081403
1009static constexpr IrInstructionId ir_instruction_id(IrInstructionResizeSlice *) {
1010 return IrInstructionIdResizeSlice;
1404static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrToInt *) {
1405 return IrInstSrcIdPtrToInt;
10111406}
10121407
1013static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitList *) {
1014 return IrInstructionIdContainerInitList;
1408static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToEnum *) {
1409 return IrInstSrcIdIntToEnum;
10151410}
10161411
1017static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitFields *) {
1018 return IrInstructionIdContainerInitFields;
1412static constexpr IrInstSrcId ir_inst_id(IrInstSrcEnumToInt *) {
1413 return IrInstSrcIdEnumToInt;
10191414}
10201415
1021static constexpr IrInstructionId ir_instruction_id(IrInstructionUnreachable *) {
1022 return IrInstructionIdUnreachable;
1416static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToErr *) {
1417 return IrInstSrcIdIntToErr;
10231418}
10241419
1025static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeOf *) {
1026 return IrInstructionIdTypeOf;
1420static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrToInt *) {
1421 return IrInstSrcIdErrToInt;
10271422}
10281423
1029static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) {
1030 return IrInstructionIdSetCold;
1424static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckSwitchProngs *) {
1425 return IrInstSrcIdCheckSwitchProngs;
10311426}
10321427
1033static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) {
1034 return IrInstructionIdSetRuntimeSafety;
1428static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckStatementIsVoid *) {
1429 return IrInstSrcIdCheckStatementIsVoid;
10351430}
10361431
1037static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) {
1038 return IrInstructionIdSetFloatMode;
1432static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeName *) {
1433 return IrInstSrcIdTypeName;
10391434}
10401435
1041static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) {
1042 return IrInstructionIdArrayType;
1436static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclRef *) {
1437 return IrInstSrcIdDeclRef;
10431438}
10441439
1045static constexpr IrInstructionId ir_instruction_id(IrInstructionAnyFrameType *) {
1046 return IrInstructionIdAnyFrameType;
1440static constexpr IrInstSrcId ir_inst_id(IrInstSrcPanic *) {
1441 return IrInstSrcIdPanic;
10471442}
10481443
1049static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) {
1050 return IrInstructionIdSliceType;
1444static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) {
1445 return IrInstSrcIdTagName;
10511446}
10521447
1053static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmSrc *) {
1054 return IrInstructionIdAsmSrc;
1448static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) {
1449 return IrInstSrcIdTagType;
10551450}
10561451
1057static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmGen *) {
1058 return IrInstructionIdAsmGen;
1452static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {
1453 return IrInstSrcIdFieldParentPtr;
10591454}
10601455
1061static constexpr IrInstructionId ir_instruction_id(IrInstructionSizeOf *) {
1062 return IrInstructionIdSizeOf;
1456static constexpr IrInstSrcId ir_inst_id(IrInstSrcByteOffsetOf *) {
1457 return IrInstSrcIdByteOffsetOf;
10631458}
10641459
1065static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) {
1066 return IrInstructionIdTestNonNull;
1460static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitOffsetOf *) {
1461 return IrInstSrcIdBitOffsetOf;
10671462}
10681463
1069static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalUnwrapPtr *) {
1070 return IrInstructionIdOptionalUnwrapPtr;
1464static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeInfo *) {
1465 return IrInstSrcIdTypeInfo;
10711466}
10721467
1073static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) {
1074 return IrInstructionIdClz;
1468static constexpr IrInstSrcId ir_inst_id(IrInstSrcType *) {
1469 return IrInstSrcIdType;
10751470}
10761471
1077static constexpr IrInstructionId ir_instruction_id(IrInstructionCtz *) {
1078 return IrInstructionIdCtz;
1472static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
1473 return IrInstSrcIdHasField;
10791474}
10801475
1081static constexpr IrInstructionId ir_instruction_id(IrInstructionPopCount *) {
1082 return IrInstructionIdPopCount;
1476static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
1477 return IrInstSrcIdTypeId;
10831478}
10841479
1085static constexpr IrInstructionId ir_instruction_id(IrInstructionBswap *) {
1086 return IrInstructionIdBswap;
1480static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
1481 return IrInstSrcIdSetEvalBranchQuota;
10871482}
10881483
1089static constexpr IrInstructionId ir_instruction_id(IrInstructionBitReverse *) {
1090 return IrInstructionIdBitReverse;
1484static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrType *) {
1485 return IrInstSrcIdPtrType;
10911486}
10921487
1093static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionTag *) {
1094 return IrInstructionIdUnionTag;
1488static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignCast *) {
1489 return IrInstSrcIdAlignCast;
10951490}
10961491
1097static constexpr IrInstructionId ir_instruction_id(IrInstructionImport *) {
1098 return IrInstructionIdImport;
1492static constexpr IrInstSrcId ir_inst_id(IrInstSrcImplicitCast *) {
1493 return IrInstSrcIdImplicitCast;
10991494}
11001495
1101static constexpr IrInstructionId ir_instruction_id(IrInstructionCImport *) {
1102 return IrInstructionIdCImport;
1496static constexpr IrInstSrcId ir_inst_id(IrInstSrcResolveResult *) {
1497 return IrInstSrcIdResolveResult;
11031498}
11041499
1105static constexpr IrInstructionId ir_instruction_id(IrInstructionCInclude *) {
1106 return IrInstructionIdCInclude;
1500static constexpr IrInstSrcId ir_inst_id(IrInstSrcResetResult *) {
1501 return IrInstSrcIdResetResult;
11071502}
11081503
1109static constexpr IrInstructionId ir_instruction_id(IrInstructionCDefine *) {
1110 return IrInstructionIdCDefine;
1504static constexpr IrInstSrcId ir_inst_id(IrInstSrcOpaqueType *) {
1505 return IrInstSrcIdOpaqueType;
11111506}
11121507
1113static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) {
1114 return IrInstructionIdCUndef;
1508static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) {
1509 return IrInstSrcIdSetAlignStack;
11151510}
11161511
1117static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) {
1118 return IrInstructionIdRef;
1512static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) {
1513 return IrInstSrcIdArgType;
11191514}
11201515
1121static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) {
1122 return IrInstructionIdRefGen;
1516static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) {
1517 return IrInstSrcIdExport;
11231518}
11241519
1125static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {
1126 return IrInstructionIdCompileErr;
1520static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorReturnTrace *) {
1521 return IrInstSrcIdErrorReturnTrace;
11271522}
11281523
1129static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileLog *) {
1130 return IrInstructionIdCompileLog;
1524static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorUnion *) {
1525 return IrInstSrcIdErrorUnion;
11311526}
11321527
1133static constexpr IrInstructionId ir_instruction_id(IrInstructionErrName *) {
1134 return IrInstructionIdErrName;
1528static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicRmw *) {
1529 return IrInstSrcIdAtomicRmw;
11351530}
11361531
1137static constexpr IrInstructionId ir_instruction_id(IrInstructionEmbedFile *) {
1138 return IrInstructionIdEmbedFile;
1532static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicLoad *) {
1533 return IrInstSrcIdAtomicLoad;
11391534}
11401535
1141static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgSrc *) {
1142 return IrInstructionIdCmpxchgSrc;
1536static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicStore *) {
1537 return IrInstSrcIdAtomicStore;
11431538}
11441539
1145static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgGen *) {
1146 return IrInstructionIdCmpxchgGen;
1540static constexpr IrInstSrcId ir_inst_id(IrInstSrcSaveErrRetAddr *) {
1541 return IrInstSrcIdSaveErrRetAddr;
11471542}
11481543
1149static constexpr IrInstructionId ir_instruction_id(IrInstructionFence *) {
1150 return IrInstructionIdFence;
1544static constexpr IrInstSrcId ir_inst_id(IrInstSrcAddImplicitReturnType *) {
1545 return IrInstSrcIdAddImplicitReturnType;
11511546}
11521547
1153static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) {
1154 return IrInstructionIdTruncate;
1548static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {
1549 return IrInstSrcIdErrSetCast;
11551550}
11561551
1157static constexpr IrInstructionId ir_instruction_id(IrInstructionIntCast *) {
1158 return IrInstructionIdIntCast;
1552static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) {
1553 return IrInstSrcIdToBytes;
11591554}
11601555
1161static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatCast *) {
1162 return IrInstructionIdFloatCast;
1556static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) {
1557 return IrInstSrcIdFromBytes;
11631558}
11641559
1165static constexpr IrInstructionId ir_instruction_id(IrInstructionErrSetCast *) {
1166 return IrInstructionIdErrSetCast;
1560static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {
1561 return IrInstSrcIdCheckRuntimeScope;
11671562}
11681563
1169static constexpr IrInstructionId ir_instruction_id(IrInstructionToBytes *) {
1170 return IrInstructionIdToBytes;
1564static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasDecl *) {
1565 return IrInstSrcIdHasDecl;
11711566}
11721567
1173static constexpr IrInstructionId ir_instruction_id(IrInstructionFromBytes *) {
1174 return IrInstructionIdFromBytes;
1568static constexpr IrInstSrcId ir_inst_id(IrInstSrcUndeclaredIdent *) {
1569 return IrInstSrcIdUndeclaredIdent;
11751570}
11761571
1177static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToFloat *) {
1178 return IrInstructionIdIntToFloat;
1572static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlloca *) {
1573 return IrInstSrcIdAlloca;
11791574}
11801575
1181static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatToInt *) {
1182 return IrInstructionIdFloatToInt;
1576static constexpr IrInstSrcId ir_inst_id(IrInstSrcEndExpr *) {
1577 return IrInstSrcIdEndExpr;
11831578}
11841579
1185static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolToInt *) {
1186 return IrInstructionIdBoolToInt;
1580static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnionInitNamedField *) {
1581 return IrInstSrcIdUnionInitNamedField;
11871582}
11881583
1189static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) {
1190 return IrInstructionIdIntType;
1584static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendBegin *) {
1585 return IrInstSrcIdSuspendBegin;
11911586}
11921587
1193static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorType *) {
1194 return IrInstructionIdVectorType;
1588static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendFinish *) {
1589 return IrInstSrcIdSuspendFinish;
11951590}
11961591
1197static constexpr IrInstructionId ir_instruction_id(IrInstructionShuffleVector *) {
1198 return IrInstructionIdShuffleVector;
1592static constexpr IrInstSrcId ir_inst_id(IrInstSrcAwait *) {
1593 return IrInstSrcIdAwait;
11991594}
12001595
1201static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatSrc *) {
1202 return IrInstructionIdSplatSrc;
1596static constexpr IrInstSrcId ir_inst_id(IrInstSrcResume *) {
1597 return IrInstSrcIdResume;
12031598}
12041599
1205static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatGen *) {
1206 return IrInstructionIdSplatGen;
1600static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillBegin *) {
1601 return IrInstSrcIdSpillBegin;
12071602}
12081603
1209static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolNot *) {
1210 return IrInstructionIdBoolNot;
1604static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillEnd *) {
1605 return IrInstSrcIdSpillEnd;
12111606}
12121607
1213static constexpr IrInstructionId ir_instruction_id(IrInstructionMemset *) {
1214 return IrInstructionIdMemset;
1608
1609static constexpr IrInstGenId ir_inst_id(IrInstGenDeclVar *) {
1610 return IrInstGenIdDeclVar;
12151611}
12161612
1217static constexpr IrInstructionId ir_instruction_id(IrInstructionMemcpy *) {
1218 return IrInstructionIdMemcpy;
1613static constexpr IrInstGenId ir_inst_id(IrInstGenBr *) {
1614 return IrInstGenIdBr;
12191615}
12201616
1221static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceSrc *) {
1222 return IrInstructionIdSliceSrc;
1617static constexpr IrInstGenId ir_inst_id(IrInstGenCondBr *) {
1618 return IrInstGenIdCondBr;
12231619}
12241620
1225static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceGen *) {
1226 return IrInstructionIdSliceGen;
1621static constexpr IrInstGenId ir_inst_id(IrInstGenSwitchBr *) {
1622 return IrInstGenIdSwitchBr;
12271623}
12281624
1229static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) {
1230 return IrInstructionIdMemberCount;
1625static constexpr IrInstGenId ir_inst_id(IrInstGenPhi *) {
1626 return IrInstGenIdPhi;
12311627}
12321628
1233static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberType *) {
1234 return IrInstructionIdMemberType;
1629static constexpr IrInstGenId ir_inst_id(IrInstGenBinaryNot *) {
1630 return IrInstGenIdBinaryNot;
12351631}
12361632
1237static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberName *) {
1238 return IrInstructionIdMemberName;
1633static constexpr IrInstGenId ir_inst_id(IrInstGenNegation *) {
1634 return IrInstGenIdNegation;
12391635}
12401636
1241static constexpr IrInstructionId ir_instruction_id(IrInstructionBreakpoint *) {
1242 return IrInstructionIdBreakpoint;
1637static constexpr IrInstGenId ir_inst_id(IrInstGenNegationWrapping *) {
1638 return IrInstGenIdNegationWrapping;
12431639}
12441640
1245static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnAddress *) {
1246 return IrInstructionIdReturnAddress;
1641static constexpr IrInstGenId ir_inst_id(IrInstGenBinOp *) {
1642 return IrInstGenIdBinOp;
12471643}
12481644
1249static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameAddress *) {
1250 return IrInstructionIdFrameAddress;
1645static constexpr IrInstGenId ir_inst_id(IrInstGenLoadPtr *) {
1646 return IrInstGenIdLoadPtr;
12511647}
12521648
1253static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameHandle *) {
1254 return IrInstructionIdFrameHandle;
1649static constexpr IrInstGenId ir_inst_id(IrInstGenStorePtr *) {
1650 return IrInstGenIdStorePtr;
12551651}
12561652
1257static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameType *) {
1258 return IrInstructionIdFrameType;
1653static constexpr IrInstGenId ir_inst_id(IrInstGenVectorStoreElem *) {
1654 return IrInstGenIdVectorStoreElem;
12591655}
12601656
1261static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeSrc *) {
1262 return IrInstructionIdFrameSizeSrc;
1657static constexpr IrInstGenId ir_inst_id(IrInstGenStructFieldPtr *) {
1658 return IrInstGenIdStructFieldPtr;
12631659}
12641660
1265static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeGen *) {
1266 return IrInstructionIdFrameSizeGen;
1661static constexpr IrInstGenId ir_inst_id(IrInstGenUnionFieldPtr *) {
1662 return IrInstGenIdUnionFieldPtr;
12671663}
12681664
1269static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignOf *) {
1270 return IrInstructionIdAlignOf;
1665static constexpr IrInstGenId ir_inst_id(IrInstGenElemPtr *) {
1666 return IrInstGenIdElemPtr;
12711667}
12721668
1273static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) {
1274 return IrInstructionIdOverflowOp;
1669static constexpr IrInstGenId ir_inst_id(IrInstGenVarPtr *) {
1670 return IrInstGenIdVarPtr;
12751671}
12761672
1277static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) {
1278 return IrInstructionIdTestErrSrc;
1673static constexpr IrInstGenId ir_inst_id(IrInstGenReturnPtr *) {
1674 return IrInstGenIdReturnPtr;
12791675}
12801676
1281static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) {
1282 return IrInstructionIdTestErrGen;
1677static constexpr IrInstGenId ir_inst_id(IrInstGenCall *) {
1678 return IrInstGenIdCall;
12831679}
12841680
1285static constexpr IrInstructionId ir_instruction_id(IrInstructionMulAdd *) {
1286 return IrInstructionIdMulAdd;
1681static constexpr IrInstGenId ir_inst_id(IrInstGenReturn *) {
1682 return IrInstGenIdReturn;
12871683}
12881684
1289static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) {
1290 return IrInstructionIdUnwrapErrCode;
1685static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {
1686 return IrInstGenIdCast;
12911687}
12921688
1293static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload *) {
1294 return IrInstructionIdUnwrapErrPayload;
1689static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) {
1690 return IrInstGenIdResizeSlice;
12951691}
12961692
1297static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) {
1298 return IrInstructionIdOptionalWrap;
1693static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {
1694 return IrInstGenIdUnreachable;
12991695}
13001696
1301static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) {
1302 return IrInstructionIdErrWrapPayload;
1697static constexpr IrInstGenId ir_inst_id(IrInstGenAsm *) {
1698 return IrInstGenIdAsm;
13031699}
13041700
1305static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapCode *) {
1306 return IrInstructionIdErrWrapCode;
1701static constexpr IrInstGenId ir_inst_id(IrInstGenTestNonNull *) {
1702 return IrInstGenIdTestNonNull;
13071703}
13081704
1309static constexpr IrInstructionId ir_instruction_id(IrInstructionFnProto *) {
1310 return IrInstructionIdFnProto;
1705static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalUnwrapPtr *) {
1706 return IrInstGenIdOptionalUnwrapPtr;
13111707}
13121708
1313static constexpr IrInstructionId ir_instruction_id(IrInstructionTestComptime *) {
1314 return IrInstructionIdTestComptime;
1709static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalWrap *) {
1710 return IrInstGenIdOptionalWrap;
13151711}
13161712
1317static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastSrc *) {
1318 return IrInstructionIdPtrCastSrc;
1713static constexpr IrInstGenId ir_inst_id(IrInstGenUnionTag *) {
1714 return IrInstGenIdUnionTag;
13191715}
13201716
1321static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) {
1322 return IrInstructionIdPtrCastGen;
1717static constexpr IrInstGenId ir_inst_id(IrInstGenClz *) {
1718 return IrInstGenIdClz;
13231719}
13241720
1325static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastSrc *) {
1326 return IrInstructionIdBitCastSrc;
1721static constexpr IrInstGenId ir_inst_id(IrInstGenCtz *) {
1722 return IrInstGenIdCtz;
13271723}
13281724
1329static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) {
1330 return IrInstructionIdBitCastGen;
1725static constexpr IrInstGenId ir_inst_id(IrInstGenPopCount *) {
1726 return IrInstGenIdPopCount;
13311727}
13321728
1333static constexpr IrInstructionId ir_instruction_id(IrInstructionWidenOrShorten *) {
1334 return IrInstructionIdWidenOrShorten;
1729static constexpr IrInstGenId ir_inst_id(IrInstGenBswap *) {
1730 return IrInstGenIdBswap;
13351731}
13361732
1337static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrToInt *) {
1338 return IrInstructionIdPtrToInt;
1733static constexpr IrInstGenId ir_inst_id(IrInstGenBitReverse *) {
1734 return IrInstGenIdBitReverse;
13391735}
13401736
1341static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToPtr *) {
1342 return IrInstructionIdIntToPtr;
1737static constexpr IrInstGenId ir_inst_id(IrInstGenRef *) {
1738 return IrInstGenIdRef;
13431739}
13441740
1345static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToEnum *) {
1346 return IrInstructionIdIntToEnum;
1741static constexpr IrInstGenId ir_inst_id(IrInstGenErrName *) {
1742 return IrInstGenIdErrName;
13471743}
13481744
1349static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumToInt *) {
1350 return IrInstructionIdEnumToInt;
1745static constexpr IrInstGenId ir_inst_id(IrInstGenCmpxchg *) {
1746 return IrInstGenIdCmpxchg;
13511747}
13521748
1353static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToErr *) {
1354 return IrInstructionIdIntToErr;
1749static constexpr IrInstGenId ir_inst_id(IrInstGenFence *) {
1750 return IrInstGenIdFence;
13551751}
13561752
1357static constexpr IrInstructionId ir_instruction_id(IrInstructionErrToInt *) {
1358 return IrInstructionIdErrToInt;
1753static constexpr IrInstGenId ir_inst_id(IrInstGenTruncate *) {
1754 return IrInstGenIdTruncate;
13591755}
13601756
1361static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckSwitchProngs *) {
1362 return IrInstructionIdCheckSwitchProngs;
1757static constexpr IrInstGenId ir_inst_id(IrInstGenShuffleVector *) {
1758 return IrInstGenIdShuffleVector;
13631759}
13641760
1365static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckStatementIsVoid *) {
1366 return IrInstructionIdCheckStatementIsVoid;
1761static constexpr IrInstGenId ir_inst_id(IrInstGenSplat *) {
1762 return IrInstGenIdSplat;
13671763}
13681764
1369static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) {
1370 return IrInstructionIdTypeName;
1765static constexpr IrInstGenId ir_inst_id(IrInstGenBoolNot *) {
1766 return IrInstGenIdBoolNot;
13711767}
13721768
1373static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) {
1374 return IrInstructionIdDeclRef;
1769static constexpr IrInstGenId ir_inst_id(IrInstGenMemset *) {
1770 return IrInstGenIdMemset;
13751771}
13761772
1377static constexpr IrInstructionId ir_instruction_id(IrInstructionPanic *) {
1378 return IrInstructionIdPanic;
1773static constexpr IrInstGenId ir_inst_id(IrInstGenMemcpy *) {
1774 return IrInstGenIdMemcpy;
13791775}
13801776
1381static constexpr IrInstructionId ir_instruction_id(IrInstructionTagName *) {
1382 return IrInstructionIdTagName;
1777static constexpr IrInstGenId ir_inst_id(IrInstGenSlice *) {
1778 return IrInstGenIdSlice;
13831779}
13841780
1385static constexpr IrInstructionId ir_instruction_id(IrInstructionTagType *) {
1386 return IrInstructionIdTagType;
1781static constexpr IrInstGenId ir_inst_id(IrInstGenBreakpoint *) {
1782 return IrInstGenIdBreakpoint;
13871783}
13881784
1389static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldParentPtr *) {
1390 return IrInstructionIdFieldParentPtr;
1785static constexpr IrInstGenId ir_inst_id(IrInstGenReturnAddress *) {
1786 return IrInstGenIdReturnAddress;
13911787}
13921788
1393static constexpr IrInstructionId ir_instruction_id(IrInstructionByteOffsetOf *) {
1394 return IrInstructionIdByteOffsetOf;
1789static constexpr IrInstGenId ir_inst_id(IrInstGenFrameAddress *) {
1790 return IrInstGenIdFrameAddress;
13951791}
13961792
1397static constexpr IrInstructionId ir_instruction_id(IrInstructionBitOffsetOf *) {
1398 return IrInstructionIdBitOffsetOf;
1793static constexpr IrInstGenId ir_inst_id(IrInstGenFrameHandle *) {
1794 return IrInstGenIdFrameHandle;
13991795}
14001796
1401static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) {
1402 return IrInstructionIdTypeInfo;
1797static constexpr IrInstGenId ir_inst_id(IrInstGenFrameSize *) {
1798 return IrInstGenIdFrameSize;
14031799}
14041800
1405static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) {
1406 return IrInstructionIdType;
1801static constexpr IrInstGenId ir_inst_id(IrInstGenOverflowOp *) {
1802 return IrInstGenIdOverflowOp;
14071803}
14081804
1409static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) {
1410 return IrInstructionIdHasField;
1805static constexpr IrInstGenId ir_inst_id(IrInstGenTestErr *) {
1806 return IrInstGenIdTestErr;
14111807}
14121808
1413static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeId *) {
1414 return IrInstructionIdTypeId;
1809static constexpr IrInstGenId ir_inst_id(IrInstGenMulAdd *) {
1810 return IrInstGenIdMulAdd;
14151811}
14161812
1417static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuota *) {
1418 return IrInstructionIdSetEvalBranchQuota;
1813static constexpr IrInstGenId ir_inst_id(IrInstGenFloatOp *) {
1814 return IrInstGenIdFloatOp;
14191815}
14201816
1421static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) {
1422 return IrInstructionIdPtrType;
1817static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrCode *) {
1818 return IrInstGenIdUnwrapErrCode;
14231819}
14241820
1425static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {
1426 return IrInstructionIdAlignCast;
1821static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrPayload *) {
1822 return IrInstGenIdUnwrapErrPayload;
14271823}
14281824
1429static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) {
1430 return IrInstructionIdImplicitCast;
1825static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapCode *) {
1826 return IrInstGenIdErrWrapCode;
14311827}
14321828
1433static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) {
1434 return IrInstructionIdResolveResult;
1829static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapPayload *) {
1830 return IrInstGenIdErrWrapPayload;
14351831}
14361832
1437static constexpr IrInstructionId ir_instruction_id(IrInstructionResetResult *) {
1438 return IrInstructionIdResetResult;
1833static constexpr IrInstGenId ir_inst_id(IrInstGenPtrCast *) {
1834 return IrInstGenIdPtrCast;
14391835}
14401836
1441static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) {
1442 return IrInstructionIdPtrOfArrayToSlice;
1837static constexpr IrInstGenId ir_inst_id(IrInstGenBitCast *) {
1838 return IrInstGenIdBitCast;
14431839}
14441840
1445static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) {
1446 return IrInstructionIdOpaqueType;
1841static constexpr IrInstGenId ir_inst_id(IrInstGenWidenOrShorten *) {
1842 return IrInstGenIdWidenOrShorten;
14471843}
14481844
1449static constexpr IrInstructionId ir_instruction_id(IrInstructionSetAlignStack *) {
1450 return IrInstructionIdSetAlignStack;
1845static constexpr IrInstGenId ir_inst_id(IrInstGenIntToPtr *) {
1846 return IrInstGenIdIntToPtr;
14511847}
14521848
1453static constexpr IrInstructionId ir_instruction_id(IrInstructionArgType *) {
1454 return IrInstructionIdArgType;
1849static constexpr IrInstGenId ir_inst_id(IrInstGenPtrToInt *) {
1850 return IrInstGenIdPtrToInt;
14551851}
14561852
1457static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorReturnTrace *) {
1458 return IrInstructionIdErrorReturnTrace;
1853static constexpr IrInstGenId ir_inst_id(IrInstGenIntToEnum *) {
1854 return IrInstGenIdIntToEnum;
14591855}
14601856
1461static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorUnion *) {
1462 return IrInstructionIdErrorUnion;
1857static constexpr IrInstGenId ir_inst_id(IrInstGenIntToErr *) {
1858 return IrInstGenIdIntToErr;
14631859}
14641860
1465static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) {
1466 return IrInstructionIdAtomicRmw;
1861static constexpr IrInstGenId ir_inst_id(IrInstGenErrToInt *) {
1862 return IrInstGenIdErrToInt;
14671863}
14681864
1469static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {
1470 return IrInstructionIdAtomicLoad;
1865static constexpr IrInstGenId ir_inst_id(IrInstGenPanic *) {
1866 return IrInstGenIdPanic;
14711867}
14721868
1473static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicStore *) {
1474 return IrInstructionIdAtomicStore;
1869static constexpr IrInstGenId ir_inst_id(IrInstGenTagName *) {
1870 return IrInstGenIdTagName;
14751871}
14761872
1477static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {
1478 return IrInstructionIdSaveErrRetAddr;
1873static constexpr IrInstGenId ir_inst_id(IrInstGenFieldParentPtr *) {
1874 return IrInstGenIdFieldParentPtr;
14791875}
14801876
1481static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitReturnType *) {
1482 return IrInstructionIdAddImplicitReturnType;
1877static constexpr IrInstGenId ir_inst_id(IrInstGenAlignCast *) {
1878 return IrInstGenIdAlignCast;
14831879}
14841880
1485static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatOp *) {
1486 return IrInstructionIdFloatOp;
1881static constexpr IrInstGenId ir_inst_id(IrInstGenErrorReturnTrace *) {
1882 return IrInstGenIdErrorReturnTrace;
14871883}
14881884
1489static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) {
1490 return IrInstructionIdCheckRuntimeScope;
1885static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicRmw *) {
1886 return IrInstGenIdAtomicRmw;
14911887}
14921888
1493static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorToArray *) {
1494 return IrInstructionIdVectorToArray;
1889static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicLoad *) {
1890 return IrInstGenIdAtomicLoad;
14951891}
14961892
1497static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *) {
1498 return IrInstructionIdArrayToVector;
1893static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicStore *) {
1894 return IrInstGenIdAtomicStore;
14991895}
15001896
1501static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertZero *) {
1502 return IrInstructionIdAssertZero;
1897static constexpr IrInstGenId ir_inst_id(IrInstGenSaveErrRetAddr *) {
1898 return IrInstGenIdSaveErrRetAddr;
15031899}
15041900
1505static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) {
1506 return IrInstructionIdAssertNonNull;
1901static constexpr IrInstGenId ir_inst_id(IrInstGenVectorToArray *) {
1902 return IrInstGenIdVectorToArray;
15071903}
15081904
1509static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) {
1510 return IrInstructionIdHasDecl;
1905static constexpr IrInstGenId ir_inst_id(IrInstGenArrayToVector *) {
1906 return IrInstGenIdArrayToVector;
15111907}
15121908
1513static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent *) {
1514 return IrInstructionIdUndeclaredIdent;
1909static constexpr IrInstGenId ir_inst_id(IrInstGenAssertZero *) {
1910 return IrInstGenIdAssertZero;
15151911}
15161912
1517static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaSrc *) {
1518 return IrInstructionIdAllocaSrc;
1913static constexpr IrInstGenId ir_inst_id(IrInstGenAssertNonNull *) {
1914 return IrInstGenIdAssertNonNull;
15191915}
15201916
1521static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) {
1522 return IrInstructionIdAllocaGen;
1917static constexpr IrInstGenId ir_inst_id(IrInstGenPtrOfArrayToSlice *) {
1918 return IrInstGenIdPtrOfArrayToSlice;
15231919}
15241920
1525static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) {
1526 return IrInstructionIdEndExpr;
1921static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendBegin *) {
1922 return IrInstGenIdSuspendBegin;
15271923}
15281924
1529static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInitNamedField *) {
1530 return IrInstructionIdUnionInitNamedField;
1925static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendFinish *) {
1926 return IrInstGenIdSuspendFinish;
15311927}
15321928
1533static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendBegin *) {
1534 return IrInstructionIdSuspendBegin;
1929static constexpr IrInstGenId ir_inst_id(IrInstGenAwait *) {
1930 return IrInstGenIdAwait;
15351931}
15361932
1537static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendFinish *) {
1538 return IrInstructionIdSuspendFinish;
1933static constexpr IrInstGenId ir_inst_id(IrInstGenResume *) {
1934 return IrInstGenIdResume;
15391935}
15401936
1541static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitSrc *) {
1542 return IrInstructionIdAwaitSrc;
1937static constexpr IrInstGenId ir_inst_id(IrInstGenSpillBegin *) {
1938 return IrInstGenIdSpillBegin;
15431939}
15441940
1545static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitGen *) {
1546 return IrInstructionIdAwaitGen;
1941static constexpr IrInstGenId ir_inst_id(IrInstGenSpillEnd *) {
1942 return IrInstGenIdSpillEnd;
15471943}
15481944
1549static constexpr IrInstructionId ir_instruction_id(IrInstructionResume *) {
1550 return IrInstructionIdResume;
1945static constexpr IrInstGenId ir_inst_id(IrInstGenVectorExtractElem *) {
1946 return IrInstGenIdVectorExtractElem;
15511947}
15521948
1553static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillBegin *) {
1554 return IrInstructionIdSpillBegin;
1949static constexpr IrInstGenId ir_inst_id(IrInstGenAlloca *) {
1950 return IrInstGenIdAlloca;
15551951}
15561952
1557static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillEnd *) {
1558 return IrInstructionIdSpillEnd;
1953static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {
1954 return IrInstGenIdConst;
15591955}
15601956
1561static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorExtractElem *) {
1562 return IrInstructionIdVectorExtractElem;
1957template<typename T>
1958static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1959 const char *name = nullptr;
1960#ifdef ZIG_ENABLE_MEM_PROFILE
1961 T *dummy = nullptr;
1962 name = ir_inst_src_type_str(ir_inst_id(dummy));
1963#endif
1964 T *special_instruction = allocate<T>(1, name);
1965 special_instruction->base.id = ir_inst_id(special_instruction);
1966 special_instruction->base.base.scope = scope;
1967 special_instruction->base.base.source_node = source_node;
1968 special_instruction->base.base.debug_id = exec_next_debug_id(irb->exec);
1969 special_instruction->base.owner_bb = irb->current_basic_block;
1970 return special_instruction;
15631971}
15641972
15651973template<typename T>
1566static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1974static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
15671975 const char *name = nullptr;
15681976#ifdef ZIG_ENABLE_MEM_PROFILE
15691977 T *dummy = nullptr;
1570 name = ir_instruction_type_str(ir_instruction_id(dummy));
1978 name = ir_inst_gen_type_str(ir_inst_id(dummy));
15711979#endif
15721980 T *special_instruction = allocate<T>(1, name);
1573 special_instruction->base.id = ir_instruction_id(special_instruction);
1574 special_instruction->base.scope = scope;
1575 special_instruction->base.source_node = source_node;
1576 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
1981 special_instruction->base.id = ir_inst_id(special_instruction);
1982 special_instruction->base.base.scope = scope;
1983 special_instruction->base.base.source_node = source_node;
1984 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
15771985 special_instruction->base.owner_bb = irb->current_basic_block;
15781986 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
15791987 return special_instruction;
15801988}
15811989
15821990template<typename T>
1583static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1991static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
15841992 const char *name = nullptr;
15851993#ifdef ZIG_ENABLE_MEM_PROFILE
15861994 T *dummy = nullptr;
1587 name = ir_instruction_type_str(ir_instruction_id(dummy));
1995 name = ir_inst_gen_type_str(ir_inst_id(dummy));
15881996#endif
15891997 T *special_instruction = allocate<T>(1, name);
1590 special_instruction->base.id = ir_instruction_id(special_instruction);
1591 special_instruction->base.scope = scope;
1592 special_instruction->base.source_node = source_node;
1593 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
1998 special_instruction->base.id = ir_inst_id(special_instruction);
1999 special_instruction->base.base.scope = scope;
2000 special_instruction->base.base.source_node = source_node;
2001 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
15942002 special_instruction->base.owner_bb = irb->current_basic_block;
15952003 return special_instruction;
15962004}
15972005
15982006template<typename T>
1599static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2007static T *ir_build_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
16002008 T *special_instruction = ir_create_instruction<T>(irb, scope, source_node);
16012009 ir_instruction_append(irb->current_basic_block, &special_instruction->base);
16022010 return special_instruction;
16032011}
16042012
1605static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type,
1606 IrInstruction *value, CastOp cast_op)
2013template<typename T>
2014static T *ir_build_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2015 T *special_instruction = ir_create_inst_gen<T>(irb, scope, source_node);
2016 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2017 return special_instruction;
2018}
2019
2020template<typename T>
2021static T *ir_build_inst_noreturn(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2022 T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node);
2023 special_instruction->base.value = irb->codegen->intern.for_unreachable();
2024 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2025 return special_instruction;
2026}
2027
2028template<typename T>
2029static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2030 T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node);
2031 special_instruction->base.value = irb->codegen->intern.for_void();
2032 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2033 return special_instruction;
2034}
2035
2036IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
2037 ZigType *var_type, const char *name_hint)
16072038{
1608 IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node);
1609 cast_instruction->dest_type = dest_type;
1610 cast_instruction->value = value;
1611 cast_instruction->cast_op = cast_op;
2039 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
2040 alloca_gen->base.id = IrInstGenIdAlloca;
2041 alloca_gen->base.base.source_node = source_node;
2042 alloca_gen->base.base.scope = scope;
2043 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
2044 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
2045 alloca_gen->base.base.ref_count = 1;
2046 alloca_gen->name_hint = name_hint;
2047 fn->alloca_gen_list.append(alloca_gen);
2048 return &alloca_gen->base;
2049}
16122050
1613 ir_ref_instruction(value, irb->current_basic_block);
2051static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type,
2052 IrInstGen *value, CastOp cast_op)
2053{
2054 IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2055 inst->base.value->type = dest_type;
2056 inst->value = value;
2057 inst->cast_op = cast_op;
16142058
1615 return &cast_instruction->base;
2059 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
2060
2061 return &inst->base;
16162062}
16172063
1618static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *condition,
1619 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)
2064static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition,
2065 IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime)
16202066{
1621 IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node);
1622 cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1623 cond_br_instruction->base.value->special = ConstValSpecialStatic;
1624 cond_br_instruction->condition = condition;
1625 cond_br_instruction->then_block = then_block;
1626 cond_br_instruction->else_block = else_block;
1627 cond_br_instruction->is_comptime = is_comptime;
2067 IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node);
2068 inst->base.is_noreturn = true;
2069 inst->condition = condition;
2070 inst->then_block = then_block;
2071 inst->else_block = else_block;
2072 inst->is_comptime = is_comptime;
16282073
16292074 ir_ref_instruction(condition, irb->current_basic_block);
16302075 ir_ref_bb(then_block);
16312076 ir_ref_bb(else_block);
16322077 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block);
16332078
1634 return &cond_br_instruction->base;
2079 return &inst->base;
16352080}
16362081
1637static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node,
1638 IrInstruction *operand)
2082static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition,
2083 IrBasicBlockGen *then_block, IrBasicBlockGen *else_block)
16392084{
1640 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);
1641 return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1642 return_instruction->base.value->special = ConstValSpecialStatic;
1643 return_instruction->operand = operand;
2085 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2086 inst->condition = condition;
2087 inst->then_block = then_block;
2088 inst->else_block = else_block;
2089
2090 ir_ref_inst_gen(condition, ira->new_irb.current_basic_block);
2091 ir_ref_bb_gen(then_block);
2092 ir_ref_bb_gen(else_block);
2093
2094 return &inst->base;
2095}
2096
2097static IrInstSrc *ir_build_return_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand) {
2098 IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(irb, scope, source_node);
2099 inst->base.is_noreturn = true;
2100 inst->operand = operand;
16442101
16452102 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);
16462103
1647 return &return_instruction->base;
2104 return &inst->base;
2105}
2106
2107static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) {
2108 IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb,
2109 source_inst->scope, source_inst->source_node);
2110 inst->operand = operand;
2111
2112 if (operand != nullptr) ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2113
2114 return &inst->base;
16482115}
16492116
1650static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1651 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
2117static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2118 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
16522119 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1653 const_instruction->base.value = irb->codegen->intern.for_void();
2120 const_instruction->value = irb->codegen->intern.for_void();
16542121 return &const_instruction->base;
16552122}
16562123
1657static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1658 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
2124static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2125 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
16592126 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1660 const_instruction->base.value = irb->codegen->intern.for_undefined();
2127 const_instruction->value = irb->codegen->intern.for_undefined();
16612128 return &const_instruction->base;
16622129}
16632130
1664static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1665 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1666 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1667 const_instruction->base.value->special = ConstValSpecialStatic;
1668 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
2131static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
2132 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2133 const_instruction->value = create_const_vals(1);
2134 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
2135 const_instruction->value->special = ConstValSpecialStatic;
2136 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
16692137 return &const_instruction->base;
16702138}
16712139
1672static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
1673 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1674 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1675 const_instruction->base.value->special = ConstValSpecialStatic;
1676 bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint);
2140static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
2141 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2142 const_instruction->value = create_const_vals(1);
2143 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
2144 const_instruction->value->special = ConstValSpecialStatic;
2145 bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint);
16772146 return &const_instruction->base;
16782147}
16792148
1680static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
1681 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1682 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float;
1683 const_instruction->base.value->special = ConstValSpecialStatic;
1684 bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat);
2149static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
2150 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2151 const_instruction->value = create_const_vals(1);
2152 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
2153 const_instruction->value->special = ConstValSpecialStatic;
2154 bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat);
16852155 return &const_instruction->base;
16862156}
16872157
1688static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1689 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
2158static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2159 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
16902160 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1691 const_instruction->base.value = irb->codegen->intern.for_null();
2161 const_instruction->value = irb->codegen->intern.for_null();
16922162 return &const_instruction->base;
16932163}
16942164
1695static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1696 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1697 const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize;
1698 const_instruction->base.value->special = ConstValSpecialStatic;
1699 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
2165static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
2166 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2167 const_instruction->value = create_const_vals(1);
2168 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
2169 const_instruction->value->special = ConstValSpecialStatic;
2170 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
17002171 return &const_instruction->base;
17012172}
17022173
1703static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2174static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
17042175 ZigType *type_entry)
17052176{
1706 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1707 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1708 const_instruction->base.value->special = ConstValSpecialStatic;
1709 const_instruction->base.value->data.x_type = type_entry;
2177 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2178 const_instruction->value = create_const_vals(1);
2179 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
2180 const_instruction->value->special = ConstValSpecialStatic;
2181 const_instruction->value->data.x_type = type_entry;
17102182 return &const_instruction->base;
17112183}
17122184
1713static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2185static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
17142186 ZigType *type_entry)
17152187{
1716 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
2188 IrInstSrc *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
17172189 ir_instruction_append(irb->current_basic_block, instruction);
17182190 return instruction;
17192191}
17202192
1721static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
1722 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1723 const_instruction->base.value->type = fn_entry->type_entry;
1724 const_instruction->base.value->special = ConstValSpecialStatic;
1725 const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry;
1726 const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1727 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction;
1728 return &const_instruction->base;
1729}
1730
1731static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1732 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1733 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1734 const_instruction->base.value->special = ConstValSpecialStatic;
1735 const_instruction->base.value->data.x_type = import;
1736 return &const_instruction->base;
1737}
1738
1739static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {
1740 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1741 const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool;
1742 const_instruction->base.value->special = ConstValSpecialStatic;
1743 const_instruction->base.value->data.x_bool = value;
2193static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
2194 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2195 const_instruction->value = create_const_vals(1);
2196 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
2197 const_instruction->value->special = ConstValSpecialStatic;
2198 const_instruction->value->data.x_type = import;
17442199 return &const_instruction->base;
17452200}
17462201
1747static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) {
1748 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1749 const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal;
1750 const_instruction->base.value->special = ConstValSpecialStatic;
1751 const_instruction->base.value->data.x_enum_literal = name;
2202static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
2203 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2204 const_instruction->value = create_const_vals(1);
2205 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
2206 const_instruction->value->special = ConstValSpecialStatic;
2207 const_instruction->value->data.x_bool = value;
17522208 return &const_instruction->base;
17532209}
17542210
1755static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,
1756 ZigFn *fn_entry, IrInstruction *first_arg)
1757{
1758 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1759 const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry);
1760 const_instruction->base.value->special = ConstValSpecialStatic;
1761 const_instruction->base.value->data.x_bound_fn.fn = fn_entry;
1762 const_instruction->base.value->data.x_bound_fn.first_arg = first_arg;
2211static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
2212 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2213 const_instruction->value = create_const_vals(1);
2214 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
2215 const_instruction->value->special = ConstValSpecialStatic;
2216 const_instruction->value->data.x_enum_literal = name;
17632217 return &const_instruction->base;
17642218}
17652219
1766static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
1767 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1768 init_const_str_lit(irb->codegen, const_instruction->base.value, str);
2220static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
2221 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2222 const_instruction->value = create_const_vals(1);
2223 init_const_str_lit(irb->codegen, const_instruction->value, str);
17692224
17702225 return &const_instruction->base;
17712226}
17722227
1773static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
1774 IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
2228static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
2229 IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
17752230 ir_instruction_append(irb->current_basic_block, instruction);
17762231 return instruction;
17772232}
17782233
1779static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
1780 IrInstruction *op1, IrInstruction *op2, bool safety_check_on)
2234static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
2235 IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on)
17812236{
1782 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, scope, source_node);
1783 bin_op_instruction->op_id = op_id;
1784 bin_op_instruction->op1 = op1;
1785 bin_op_instruction->op2 = op2;
1786 bin_op_instruction->safety_check_on = safety_check_on;
2237 IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node);
2238 inst->op_id = op_id;
2239 inst->op1 = op1;
2240 inst->op2 = op2;
2241 inst->safety_check_on = safety_check_on;
17872242
17882243 ir_ref_instruction(op1, irb->current_basic_block);
17892244 ir_ref_instruction(op2, irb->current_basic_block);
17902245
1791 return &bin_op_instruction->base;
2246 return &inst->base;
17922247}
17932248
1794static IrInstruction *ir_build_bin_op_gen(IrAnalyze *ira, IrInstruction *source_instr, ZigType *res_type,
1795 IrBinOp op_id, IrInstruction *op1, IrInstruction *op2, bool safety_check_on)
2249static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type,
2250 IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on)
17962251{
1797 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(&ira->new_irb,
2252 IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb,
17982253 source_instr->scope, source_instr->source_node);
1799 bin_op_instruction->base.value->type = res_type;
1800 bin_op_instruction->op_id = op_id;
1801 bin_op_instruction->op1 = op1;
1802 bin_op_instruction->op2 = op2;
1803 bin_op_instruction->safety_check_on = safety_check_on;
2254 inst->base.value->type = res_type;
2255 inst->op_id = op_id;
2256 inst->op1 = op1;
2257 inst->op2 = op2;
2258 inst->safety_check_on = safety_check_on;
18042259
1805 ir_ref_instruction(op1, ira->new_irb.current_basic_block);
1806 ir_ref_instruction(op2, ira->new_irb.current_basic_block);
2260 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
2261 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
18072262
1808 return &bin_op_instruction->base;
2263 return &inst->base;
18092264}
18102265
18112266
1812static IrInstruction *ir_build_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *source_node,
1813 IrInstruction *op1, IrInstruction *op2, Buf *type_name)
2267static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2268 IrInstSrc *op1, IrInstSrc *op2, Buf *type_name)
18142269{
1815 IrInstructionMergeErrSets *merge_err_sets_instruction = ir_build_instruction<IrInstructionMergeErrSets>(irb, scope, source_node);
1816 merge_err_sets_instruction->op1 = op1;
1817 merge_err_sets_instruction->op2 = op2;
1818 merge_err_sets_instruction->type_name = type_name;
2270 IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node);
2271 inst->op1 = op1;
2272 inst->op2 = op2;
2273 inst->type_name = type_name;
18192274
18202275 ir_ref_instruction(op1, irb->current_basic_block);
18212276 ir_ref_instruction(op2, irb->current_basic_block);
18222277
1823 return &merge_err_sets_instruction->base;
2278 return &inst->base;
18242279}
18252280
1826static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
2281static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
18272282 ScopeFnDef *crossed_fndef_scope)
18282283{
1829 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
2284 IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node);
18302285 instruction->var = var;
18312286 instruction->crossed_fndef_scope = crossed_fndef_scope;
18322287
......@@ -1835,22 +2290,31 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *
18352290 return &instruction->base;
18362291}
18372292
1838static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
2293static IrInstSrc *ir_build_var_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
18392294 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
18402295}
18412296
1842static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
1843 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,
2297static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
2298 IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2299 instruction->var = var;
2300
2301 ir_ref_var(var);
2302
2303 return &instruction->base;
2304}
2305
2306static IrInstGen *ir_build_return_ptr(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
2307 IrInstGenReturnPtr *instruction = ir_build_inst_gen<IrInstGenReturnPtr>(&ira->new_irb,
18442308 source_instruction->scope, source_instruction->source_node);
18452309 instruction->base.value->type = ty;
18462310 return &instruction->base;
18472311}
18482312
1849static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1850 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len,
2313static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2314 IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len,
18512315 AstNode *init_array_type_source_node)
18522316{
1853 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);
2317 IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node);
18542318 instruction->array_ptr = array_ptr;
18552319 instruction->elem_index = elem_index;
18562320 instruction->safety_check_on = safety_check_on;
......@@ -1863,10 +2327,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s
18632327 return &instruction->base;
18642328}
18652329
1866static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node,
1867 IrInstruction *container_ptr, IrInstruction *field_name_expr, bool initializing)
2330static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2331 IrInstGen *array_ptr, IrInstGen *elem_index, bool safety_check_on, ZigType *return_type)
2332{
2333 IrInstGenElemPtr *instruction = ir_build_inst_gen<IrInstGenElemPtr>(&ira->new_irb, scope, source_node);
2334 instruction->base.value->type = return_type;
2335 instruction->array_ptr = array_ptr;
2336 instruction->elem_index = elem_index;
2337 instruction->safety_check_on = safety_check_on;
2338
2339 ir_ref_inst_gen(array_ptr, ira->new_irb.current_basic_block);
2340 ir_ref_inst_gen(elem_index, ira->new_irb.current_basic_block);
2341
2342 return &instruction->base;
2343}
2344
2345static IrInstSrc *ir_build_field_ptr_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2346 IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing)
18682347{
1869 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);
2348 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
18702349 instruction->container_ptr = container_ptr;
18712350 instruction->field_name_buffer = nullptr;
18722351 instruction->field_name_expr = field_name_expr;
......@@ -1878,10 +2357,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop
18782357 return &instruction->base;
18792358}
18802359
1881static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1882 IrInstruction *container_ptr, Buf *field_name, bool initializing)
2360static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2361 IrInstSrc *container_ptr, Buf *field_name, bool initializing)
18832362{
1884 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);
2363 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
18852364 instruction->container_ptr = container_ptr;
18862365 instruction->field_name_buffer = field_name;
18872366 instruction->field_name_expr = nullptr;
......@@ -1892,10 +2371,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *
18922371 return &instruction->base;
18932372}
18942373
1895static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *source_node,
1896 IrInstruction *container_type, IrInstruction *field_name)
2374static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2375 IrInstSrc *container_type, IrInstSrc *field_name)
18972376{
1898 IrInstructionHasField *instruction = ir_build_instruction<IrInstructionHasField>(irb, scope, source_node);
2377 IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node);
18992378 instruction->container_type = container_type;
19002379 instruction->field_name = field_name;
19012380
......@@ -1905,36 +2384,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *
19052384 return &instruction->base;
19062385}
19072386
1908static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1909 IrInstruction *struct_ptr, TypeStructField *field)
2387static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr,
2388 IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type)
19102389{
1911 IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, scope, source_node);
1912 instruction->struct_ptr = struct_ptr;
1913 instruction->field = field;
2390 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2391 inst->base.value->type = ptr_type;
2392 inst->struct_ptr = struct_ptr;
2393 inst->field = field;
19142394
1915 ir_ref_instruction(struct_ptr, irb->current_basic_block);
2395 ir_ref_inst_gen(struct_ptr, ira->new_irb.current_basic_block);
19162396
1917 return &instruction->base;
2397 return &inst->base;
19182398}
19192399
1920static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1921 IrInstruction *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing)
2400static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,
2401 IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type)
19222402{
1923 IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node);
1924 instruction->initializing = initializing;
1925 instruction->safety_check_on = safety_check_on;
1926 instruction->union_ptr = union_ptr;
1927 instruction->field = field;
2403 IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb,
2404 source_instr->scope, source_instr->source_node);
2405 inst->base.value->type = ptr_type;
2406 inst->initializing = initializing;
2407 inst->safety_check_on = safety_check_on;
2408 inst->union_ptr = union_ptr;
2409 inst->field = field;
19282410
1929 ir_ref_instruction(union_ptr, irb->current_basic_block);
2411 ir_ref_inst_gen(union_ptr, ira->new_irb.current_basic_block);
19302412
1931 return &instruction->base;
2413 return &inst->base;
19322414}
19332415
1934static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode *source_node,
1935 IrInstruction *options, IrInstruction *fn_ref, IrInstruction *args, ResultLoc *result_loc)
2416static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2417 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc)
19362418{
1937 IrInstructionCallExtra *call_instruction = ir_build_instruction<IrInstructionCallExtra>(irb, scope, source_node);
2419 IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node);
19382420 call_instruction->options = options;
19392421 call_instruction->fn_ref = fn_ref;
19402422 call_instruction->args = args;
......@@ -1947,11 +2429,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode
19472429 return &call_instruction->base;
19482430}
19492431
1950static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNode *source_node,
1951 IrInstruction *options, IrInstruction *fn_ref, IrInstruction **args_ptr, size_t args_len,
2432static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2433 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len,
19522434 ResultLoc *result_loc)
19532435{
1954 IrInstructionCallSrcArgs *call_instruction = ir_build_instruction<IrInstructionCallSrcArgs>(irb, scope, source_node);
2436 IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node);
19552437 call_instruction->options = options;
19562438 call_instruction->fn_ref = fn_ref;
19572439 call_instruction->args_ptr = args_ptr;
......@@ -1966,12 +2448,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo
19662448 return &call_instruction->base;
19672449}
19682450
1969static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
1970 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1971 IrInstruction *ret_ptr, CallModifier modifier, bool is_async_call_builtin,
1972 IrInstruction *new_stack, ResultLoc *result_loc)
2451static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2452 ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args,
2453 IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin,
2454 IrInstSrc *new_stack, ResultLoc *result_loc)
19732455{
1974 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);
2456 IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node);
19752457 call_instruction->fn_entry = fn_entry;
19762458 call_instruction->fn_ref = fn_ref;
19772459 call_instruction->args = args;
......@@ -1991,12 +2473,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
19912473 return &call_instruction->base;
19922474}
19932475
1994static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,
1995 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1996 CallModifier modifier, IrInstruction *new_stack, bool is_async_call_builtin,
1997 IrInstruction *result_loc, ZigType *return_type)
2476static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction,
2477 ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args,
2478 CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin,
2479 IrInstGen *result_loc, ZigType *return_type)
19982480{
1999 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
2481 IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb,
20002482 source_instruction->scope, source_instruction->source_node);
20012483 call_instruction->base.value->type = return_type;
20022484 call_instruction->fn_entry = fn_entry;
......@@ -2008,23 +2490,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so
20082490 call_instruction->new_stack = new_stack;
20092491 call_instruction->result_loc = result_loc;
20102492
2011 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);
2493 if (fn_ref != nullptr) ir_ref_inst_gen(fn_ref, ira->new_irb.current_basic_block);
20122494 for (size_t i = 0; i < arg_count; i += 1)
2013 ir_ref_instruction(args[i], ira->new_irb.current_basic_block);
2014 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);
2015 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
2495 ir_ref_inst_gen(args[i], ira->new_irb.current_basic_block);
2496 if (new_stack != nullptr) ir_ref_inst_gen(new_stack, ira->new_irb.current_basic_block);
2497 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
20162498
20172499 return call_instruction;
20182500}
20192501
2020static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node,
2021 size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values,
2502static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2503 size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values,
20222504 ResultLocPeerParent *peer_parent)
20232505{
20242506 assert(incoming_count != 0);
20252507 assert(incoming_count != SIZE_MAX);
20262508
2027 IrInstructionPhi *phi_instruction = ir_build_instruction<IrInstructionPhi>(irb, scope, source_node);
2509 IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(irb, scope, source_node);
20282510 phi_instruction->incoming_count = incoming_count;
20292511 phi_instruction->incoming_blocks = incoming_blocks;
20302512 phi_instruction->incoming_values = incoming_values;
......@@ -2038,56 +2520,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source
20382520 return &phi_instruction->base;
20392521}
20402522
2041static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node,
2042 IrBasicBlock *dest_block, IrInstruction *is_comptime)
2523static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count,
2524 IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type)
2525{
2526 assert(incoming_count != 0);
2527 assert(incoming_count != SIZE_MAX);
2528
2529 IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb,
2530 source_instr->scope, source_instr->source_node);
2531 phi_instruction->base.value->type = result_type;
2532 phi_instruction->incoming_count = incoming_count;
2533 phi_instruction->incoming_blocks = incoming_blocks;
2534 phi_instruction->incoming_values = incoming_values;
2535
2536 for (size_t i = 0; i < incoming_count; i += 1) {
2537 ir_ref_bb_gen(incoming_blocks[i]);
2538 ir_ref_inst_gen(incoming_values[i], ira->new_irb.current_basic_block);
2539 }
2540
2541 return &phi_instruction->base;
2542}
2543
2544static IrInstSrc *ir_build_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2545 IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime)
20432546{
2044 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node);
2045 br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2046 br_instruction->base.value->special = ConstValSpecialStatic;
2047 br_instruction->dest_block = dest_block;
2048 br_instruction->is_comptime = is_comptime;
2547 IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node);
2548 inst->base.is_noreturn = true;
2549 inst->dest_block = dest_block;
2550 inst->is_comptime = is_comptime;
20492551
20502552 ir_ref_bb(dest_block);
20512553 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);
20522554
2053 return &br_instruction->base;
2555 return &inst->base;
20542556}
20552557
2056static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_node,
2057 IrBasicBlock *dest_block, IrInstruction *is_comptime)
2058{
2059 IrInstruction *instruction = ir_create_br(irb, scope, source_node, dest_block, is_comptime);
2060 ir_instruction_append(irb->current_basic_block, instruction);
2061 return instruction;
2558static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) {
2559 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2560 inst->dest_block = dest_block;
2561
2562 ir_ref_bb_gen(dest_block);
2563
2564 return &inst->base;
20622565}
20632566
2064static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2065 IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
2066 IrInstruction *sentinel, IrInstruction *align_value,
2567static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2568 IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
2569 IrInstSrc *sentinel, IrInstSrc *align_value,
20672570 uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero)
20682571{
2069 IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node);
2070 ptr_type_of_instruction->sentinel = sentinel;
2071 ptr_type_of_instruction->align_value = align_value;
2072 ptr_type_of_instruction->child_type = child_type;
2073 ptr_type_of_instruction->is_const = is_const;
2074 ptr_type_of_instruction->is_volatile = is_volatile;
2075 ptr_type_of_instruction->ptr_len = ptr_len;
2076 ptr_type_of_instruction->bit_offset_start = bit_offset_start;
2077 ptr_type_of_instruction->host_int_bytes = host_int_bytes;
2078 ptr_type_of_instruction->is_allow_zero = is_allow_zero;
2572 IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node);
2573 inst->sentinel = sentinel;
2574 inst->align_value = align_value;
2575 inst->child_type = child_type;
2576 inst->is_const = is_const;
2577 inst->is_volatile = is_volatile;
2578 inst->ptr_len = ptr_len;
2579 inst->bit_offset_start = bit_offset_start;
2580 inst->host_int_bytes = host_int_bytes;
2581 inst->is_allow_zero = is_allow_zero;
20792582
20802583 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);
20812584 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);
20822585 ir_ref_instruction(child_type, irb->current_basic_block);
20832586
2084 return &ptr_type_of_instruction->base;
2587 return &inst->base;
20852588}
20862589
2087static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2088 IrInstruction *value, LVal lval, ResultLoc *result_loc)
2590static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2591 IrInstSrc *value, LVal lval, ResultLoc *result_loc)
20892592{
2090 IrInstructionUnOp *instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node);
2593 IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node);
20912594 instruction->op_id = op_id;
20922595 instruction->value = value;
20932596 instruction->lval = lval;
......@@ -2098,36 +2601,73 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode
20982601 return &instruction->base;
20992602}
21002603
2101static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2102 IrInstruction *value)
2604static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2605 IrInstSrc *value)
21032606{
21042607 return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr);
21052608}
21062609
2107static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,
2108 size_t item_count, IrInstruction **elem_result_loc_list, IrInstruction *result_loc,
2109 AstNode *init_array_type_source_node)
2110{
2111 IrInstructionContainerInitList *container_init_list_instruction =
2112 ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);
2113 container_init_list_instruction->item_count = item_count;
2114 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;
2115 container_init_list_instruction->result_loc = result_loc;
2116 container_init_list_instruction->init_array_type_source_node = init_array_type_source_node;
2610static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type) {
2611 IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb,
2612 source_instr->scope, source_instr->source_node);
2613 instruction->base.value->type = expr_type;
2614 instruction->operand = operand;
21172615
2118 for (size_t i = 0; i < item_count; i += 1) {
2119 ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block);
2616 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2617
2618 return &instruction->base;
2619}
2620
2621static IrInstGen *ir_build_negation_wrapping(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
2622 ZigType *expr_type)
2623{
2624 IrInstGenNegationWrapping *instruction = ir_build_inst_gen<IrInstGenNegationWrapping>(&ira->new_irb,
2625 source_instr->scope, source_instr->source_node);
2626 instruction->base.value->type = expr_type;
2627 instruction->operand = operand;
2628
2629 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2630
2631 return &instruction->base;
2632}
2633
2634static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
2635 ZigType *expr_type)
2636{
2637 IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb,
2638 source_instr->scope, source_instr->source_node);
2639 instruction->base.value->type = expr_type;
2640 instruction->operand = operand;
2641
2642 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2643
2644 return &instruction->base;
2645}
2646
2647static IrInstSrc *ir_build_container_init_list(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2648 size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc,
2649 AstNode *init_array_type_source_node)
2650{
2651 IrInstSrcContainerInitList *container_init_list_instruction =
2652 ir_build_instruction<IrInstSrcContainerInitList>(irb, scope, source_node);
2653 container_init_list_instruction->item_count = item_count;
2654 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;
2655 container_init_list_instruction->result_loc = result_loc;
2656 container_init_list_instruction->init_array_type_source_node = init_array_type_source_node;
2657
2658 for (size_t i = 0; i < item_count; i += 1) {
2659 ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block);
21202660 }
21212661 if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block);
21222662
21232663 return &container_init_list_instruction->base;
21242664}
21252665
2126static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node,
2127 size_t field_count, IrInstructionContainerInitFieldsField *fields, IrInstruction *result_loc)
2666static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2667 size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc)
21282668{
2129 IrInstructionContainerInitFields *container_init_fields_instruction =
2130 ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node);
2669 IrInstSrcContainerInitFields *container_init_fields_instruction =
2670 ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node);
21312671 container_init_fields_instruction->field_count = field_count;
21322672 container_init_fields_instruction->fields = fields;
21332673 container_init_fields_instruction->result_loc = result_loc;
......@@ -2140,20 +2680,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
21402680 return &container_init_fields_instruction->base;
21412681}
21422682
2143static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2144 IrInstructionUnreachable *unreachable_instruction =
2145 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);
2146 unreachable_instruction->base.value->special = ConstValSpecialStatic;
2147 unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2148 return &unreachable_instruction->base;
2683static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2684 IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node);
2685 inst->base.is_noreturn = true;
2686 return &inst->base;
21492687}
21502688
2151static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
2152 IrInstruction *ptr, IrInstruction *value)
2689static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) {
2690 IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2691 return &inst->base;
2692}
2693
2694static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2695 IrInstSrc *ptr, IrInstSrc *value)
21532696{
2154 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);
2155 instruction->base.value->special = ConstValSpecialStatic;
2156 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2697 IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node);
21572698 instruction->ptr = ptr;
21582699 instruction->value = value;
21592700
......@@ -2163,76 +2704,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A
21632704 return instruction;
21642705}
21652706
2166static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *source_instruction,
2167 IrInstruction *vector_ptr, IrInstruction *index, IrInstruction *value)
2707static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) {
2708 IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb,
2709 source_instr->scope, source_instr->source_node);
2710 instruction->ptr = ptr;
2711 instruction->value = value;
2712
2713 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2714 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
2715
2716 return &instruction->base;
2717}
2718
2719static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,
2720 IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value)
21682721{
2169 IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>(
2170 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2171 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2722 IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>(
2723 &ira->new_irb, src_inst->scope, src_inst->source_node);
21722724 inst->vector_ptr = vector_ptr;
21732725 inst->index = index;
21742726 inst->value = value;
21752727
2176 ir_ref_instruction(vector_ptr, ira->new_irb.current_basic_block);
2177 ir_ref_instruction(index, ira->new_irb.current_basic_block);
2178 ir_ref_instruction(value, ira->new_irb.current_basic_block);
2728 ir_ref_inst_gen(vector_ptr, ira->new_irb.current_basic_block);
2729 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
2730 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
21792731
21802732 return &inst->base;
21812733}
21822734
2183static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2184 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)
2735static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2736 ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr)
21852737{
2186 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);
2187 decl_var_instruction->base.value->special = ConstValSpecialStatic;
2188 decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2189 decl_var_instruction->var = var;
2190 decl_var_instruction->align_value = align_value;
2191 decl_var_instruction->ptr = ptr;
2738 IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node);
2739 inst->var = var;
2740 inst->align_value = align_value;
2741 inst->ptr = ptr;
21922742
21932743 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
21942744 ir_ref_instruction(ptr, irb->current_basic_block);
21952745
2196 return &decl_var_instruction->base;
2746 return &inst->base;
21972747}
21982748
2199static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction,
2200 ZigVar *var, IrInstruction *var_ptr)
2749static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction,
2750 ZigVar *var, IrInstGen *var_ptr)
22012751{
2202 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,
2752 IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb,
22032753 source_instruction->scope, source_instruction->source_node);
2204 decl_var_instruction->base.value->special = ConstValSpecialStatic;
2205 decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void;
2206 decl_var_instruction->var = var;
2207 decl_var_instruction->var_ptr = var_ptr;
2754 inst->base.value->special = ConstValSpecialStatic;
2755 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2756 inst->var = var;
2757 inst->var_ptr = var_ptr;
22082758
2209 ir_ref_instruction(var_ptr, ira->new_irb.current_basic_block);
2759 ir_ref_inst_gen(var_ptr, ira->new_irb.current_basic_block);
22102760
2211 return &decl_var_instruction->base;
2761 return &inst->base;
22122762}
22132763
2214static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *source_instruction,
2215 IrInstruction *operand, ZigType *ty, IrInstruction *result_loc)
2764static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction,
2765 IrInstGen *operand, ZigType *ty, IrInstGen *result_loc)
22162766{
2217 IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb,
2767 IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb,
22182768 source_instruction->scope, source_instruction->source_node);
22192769 instruction->base.value->type = ty;
22202770 instruction->operand = operand;
22212771 instruction->result_loc = result_loc;
22222772
2223 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2224 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
2773 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2774 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
22252775
22262776 return &instruction->base;
22272777}
22282778
2229static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node,
2230 IrInstruction *target, IrInstruction *options)
2779static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2780 IrInstSrc *target, IrInstSrc *options)
22312781{
2232 IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(
2782 IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>(
22332783 irb, scope, source_node);
2234 export_instruction->base.value->special = ConstValSpecialStatic;
2235 export_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
22362784 export_instruction->target = target;
22372785 export_instruction->options = options;
22382786
......@@ -2242,8 +2790,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou
22422790 return &export_instruction->base;
22432791}
22442792
2245static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) {
2246 IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, scope, source_node);
2793static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) {
2794 IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node);
22472795 instruction->ptr = ptr;
22482796
22492797 ir_ref_instruction(ptr, irb->current_basic_block);
......@@ -2251,8 +2799,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s
22512799 return &instruction->base;
22522800}
22532801
2254static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2255 IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node);
2802static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction,
2803 IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc)
2804{
2805 IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>(
2806 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2807 instruction->base.value->type = ty;
2808 instruction->ptr = ptr;
2809 instruction->result_loc = result_loc;
2810
2811 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2812 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
2813
2814 return &instruction->base;
2815}
2816
2817static IrInstSrc *ir_build_typeof(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2818 IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node);
22562819 instruction->value = value;
22572820
22582821 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2260,8 +2823,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou
22602823 return &instruction->base;
22612824}
22622825
2263static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) {
2264 IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node);
2826static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) {
2827 IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node);
22652828 instruction->is_cold = is_cold;
22662829
22672830 ir_ref_instruction(is_cold, irb->current_basic_block);
......@@ -2269,21 +2832,21 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s
22692832 return &instruction->base;
22702833}
22712834
2272static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,
2273 IrInstruction *safety_on)
2835static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2836 IrInstSrc *safety_on)
22742837{
2275 IrInstructionSetRuntimeSafety *instruction = ir_build_instruction<IrInstructionSetRuntimeSafety>(irb, scope, source_node);
2276 instruction->safety_on = safety_on;
2838 IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node);
2839 inst->safety_on = safety_on;
22772840
22782841 ir_ref_instruction(safety_on, irb->current_basic_block);
22792842
2280 return &instruction->base;
2843 return &inst->base;
22812844}
22822845
2283static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node,
2284 IrInstruction *mode_value)
2846static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2847 IrInstSrc *mode_value)
22852848{
2286 IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node);
2849 IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node);
22872850 instruction->mode_value = mode_value;
22882851
22892852 ir_ref_instruction(mode_value, irb->current_basic_block);
......@@ -2291,10 +2854,10 @@ static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstN
22912854 return &instruction->base;
22922855}
22932856
2294static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *size,
2295 IrInstruction *sentinel, IrInstruction *child_type)
2857static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size,
2858 IrInstSrc *sentinel, IrInstSrc *child_type)
22962859{
2297 IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, scope, source_node);
2860 IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node);
22982861 instruction->size = size;
22992862 instruction->sentinel = sentinel;
23002863 instruction->child_type = child_type;
......@@ -2306,10 +2869,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode
23062869 return &instruction->base;
23072870}
23082871
2309static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2310 IrInstruction *payload_type)
2872static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2873 IrInstSrc *payload_type)
23112874{
2312 IrInstructionAnyFrameType *instruction = ir_build_instruction<IrInstructionAnyFrameType>(irb, scope, source_node);
2875 IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node);
23132876 instruction->payload_type = payload_type;
23142877
23152878 if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block);
......@@ -2317,11 +2880,11 @@ static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNo
23172880 return &instruction->base;
23182881}
23192882
2320static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2321 IrInstruction *child_type, bool is_const, bool is_volatile,
2322 IrInstruction *sentinel, IrInstruction *align_value, bool is_allow_zero)
2883static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2884 IrInstSrc *child_type, bool is_const, bool is_volatile,
2885 IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero)
23232886{
2324 IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node);
2887 IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node);
23252888 instruction->is_const = is_const;
23262889 instruction->is_volatile = is_volatile;
23272890 instruction->child_type = child_type;
......@@ -2336,11 +2899,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
23362899 return &instruction->base;
23372900}
23382901
2339static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2340 IrInstruction *asm_template, IrInstruction **input_list, IrInstruction **output_types,
2902static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2903 IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types,
23412904 ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global)
23422905{
2343 IrInstructionAsmSrc *instruction = ir_build_instruction<IrInstructionAsmSrc>(irb, scope, source_node);
2906 IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node);
23442907 instruction->asm_template = asm_template;
23452908 instruction->input_list = input_list;
23462909 instruction->output_types = output_types;
......@@ -2351,24 +2914,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so
23512914
23522915 assert(source_node->type == NodeTypeAsmExpr);
23532916 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
2354 IrInstruction *output_type = output_types[i];
2917 IrInstSrc *output_type = output_types[i];
23552918 if (output_type) ir_ref_instruction(output_type, irb->current_basic_block);
23562919 }
23572920
23582921 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
2359 IrInstruction *input_value = input_list[i];
2922 IrInstSrc *input_value = input_list[i];
23602923 ir_ref_instruction(input_value, irb->current_basic_block);
23612924 }
23622925
23632926 return &instruction->base;
23642927}
23652928
2366static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2929static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
23672930 Buf *asm_template, AsmToken *token_list, size_t token_list_len,
2368 IrInstruction **input_list, IrInstruction **output_types, ZigVar **output_vars, size_t return_count,
2369 bool has_side_effects)
2931 IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count,
2932 bool has_side_effects, ZigType *return_type)
23702933{
2371 IrInstructionAsmGen *instruction = ir_build_instruction<IrInstructionAsmGen>(&ira->new_irb, scope, source_node);
2934 IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2935 instruction->base.value->type = return_type;
23722936 instruction->asm_template = asm_template;
23732937 instruction->token_list = token_list;
23742938 instruction->token_list_len = token_list_len;
......@@ -2378,22 +2942,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so
23782942 instruction->return_count = return_count;
23792943 instruction->has_side_effects = has_side_effects;
23802944
2381 assert(source_node->type == NodeTypeAsmExpr);
2382 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
2383 IrInstruction *output_type = output_types[i];
2384 if (output_type) ir_ref_instruction(output_type, ira->new_irb.current_basic_block);
2945 assert(source_instr->source_node->type == NodeTypeAsmExpr);
2946 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) {
2947 IrInstGen *output_type = output_types[i];
2948 if (output_type) ir_ref_inst_gen(output_type, ira->new_irb.current_basic_block);
23852949 }
23862950
2387 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
2388 IrInstruction *input_value = input_list[i];
2389 ir_ref_instruction(input_value, ira->new_irb.current_basic_block);
2951 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) {
2952 IrInstGen *input_value = input_list[i];
2953 ir_ref_inst_gen(input_value, ira->new_irb.current_basic_block);
23902954 }
23912955
23922956 return &instruction->base;
23932957}
23942958
2395static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value, bool bit_size) {
2396 IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node);
2959static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value,
2960 bool bit_size)
2961{
2962 IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node);
23972963 instruction->type_value = type_value;
23982964 instruction->bit_size = bit_size;
23992965
......@@ -2402,8 +2968,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so
24022968 return &instruction->base;
24032969}
24042970
2405static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2406 IrInstructionTestNonNull *instruction = ir_build_instruction<IrInstructionTestNonNull>(irb, scope, source_node);
2971static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2972 IrInstSrc *value)
2973{
2974 IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node);
24072975 instruction->value = value;
24082976
24092977 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2411,10 +2979,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod
24112979 return &instruction->base;
24122980}
24132981
2414static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
2415 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
2982static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
2983 IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb,
2984 source_instr->scope, source_instr->source_node);
2985 inst->base.value->type = ira->codegen->builtin_types.entry_bool;
2986 inst->value = value;
2987
2988 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
2989
2990 return &inst->base;
2991}
2992
2993static IrInstSrc *ir_build_optional_unwrap_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2994 IrInstSrc *base_ptr, bool safety_check_on, bool initializing)
24162995{
2417 IrInstructionOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstructionOptionalUnwrapPtr>(irb, scope, source_node);
2996 IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node);
24182997 instruction->base_ptr = base_ptr;
24192998 instruction->safety_check_on = safety_check_on;
24202999 instruction->initializing = initializing;
......@@ -2424,113 +3003,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope,
24243003 return &instruction->base;
24253004}
24263005
2427static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_ty,
2428 IrInstruction *operand, IrInstruction *result_loc)
3006static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
3007 IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type)
3008{
3009 IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb,
3010 source_instr->scope, source_instr->source_node);
3011 inst->base.value->type = result_type;
3012 inst->base_ptr = base_ptr;
3013 inst->safety_check_on = safety_check_on;
3014 inst->initializing = initializing;
3015
3016 ir_ref_inst_gen(base_ptr, ira->new_irb.current_basic_block);
3017
3018 return &inst->base;
3019}
3020
3021static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty,
3022 IrInstGen *operand, IrInstGen *result_loc)
24293023{
2430 IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(
3024 IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>(
24313025 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
24323026 instruction->base.value->type = result_ty;
24333027 instruction->operand = operand;
24343028 instruction->result_loc = result_loc;
24353029
2436 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2437 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3030 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3031 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24383032
24393033 return &instruction->base;
24403034}
24413035
2442static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instruction,
2443 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)
3036static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction,
3037 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
24443038{
2445 IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(
3039 IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>(
24463040 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
24473041 instruction->base.value->type = result_type;
24483042 instruction->operand = operand;
24493043 instruction->result_loc = result_loc;
24503044
2451 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2452 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3045 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3046 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24533047
24543048 return &instruction->base;
24553049}
24563050
2457static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instruction,
2458 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)
3051static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction,
3052 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
24593053{
2460 IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(
3054 IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>(
24613055 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
24623056 instruction->base.value->type = result_type;
24633057 instruction->operand = operand;
24643058 instruction->result_loc = result_loc;
24653059
2466 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2467 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3060 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3061 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24683062
24693063 return &instruction->base;
24703064}
24713065
2472static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2473 IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, scope, source_node);
3066static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3067 IrInstSrc *op)
3068{
3069 IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node);
24743070 instruction->type = type;
24753071 instruction->op = op;
24763072
2477 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3073 ir_ref_instruction(type, irb->current_basic_block);
24783074 ir_ref_instruction(op, irb->current_basic_block);
24793075
24803076 return &instruction->base;
24813077}
24823078
2483static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2484 IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node);
3079static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
3080 IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb,
3081 source_instr->scope, source_instr->source_node);
3082 instruction->base.value->type = result_type;
3083 instruction->op = op;
3084
3085 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3086
3087 return &instruction->base;
3088}
3089
3090static IrInstSrc *ir_build_ctz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3091 IrInstSrc *op)
3092{
3093 IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(irb, scope, source_node);
24853094 instruction->type = type;
24863095 instruction->op = op;
24873096
2488 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3097 ir_ref_instruction(type, irb->current_basic_block);
24893098 ir_ref_instruction(op, irb->current_basic_block);
24903099
24913100 return &instruction->base;
24923101}
24933102
2494static IrInstruction *ir_build_pop_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2495 IrInstructionPopCount *instruction = ir_build_instruction<IrInstructionPopCount>(irb, scope, source_node);
3103static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
3104 IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb,
3105 source_instr->scope, source_instr->source_node);
3106 instruction->base.value->type = result_type;
3107 instruction->op = op;
3108
3109 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3110
3111 return &instruction->base;
3112}
3113
3114static IrInstSrc *ir_build_pop_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3115 IrInstSrc *op)
3116{
3117 IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(irb, scope, source_node);
24963118 instruction->type = type;
24973119 instruction->op = op;
24983120
2499 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3121 ir_ref_instruction(type, irb->current_basic_block);
25003122 ir_ref_instruction(op, irb->current_basic_block);
25013123
25023124 return &instruction->base;
25033125}
25043126
2505static IrInstruction *ir_build_bswap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2506 IrInstructionBswap *instruction = ir_build_instruction<IrInstructionBswap>(irb, scope, source_node);
3127static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type,
3128 IrInstGen *op)
3129{
3130 IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb,
3131 source_instr->scope, source_instr->source_node);
3132 instruction->base.value->type = result_type;
3133 instruction->op = op;
3134
3135 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3136
3137 return &instruction->base;
3138}
3139
3140static IrInstSrc *ir_build_bswap(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3141 IrInstSrc *op)
3142{
3143 IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(irb, scope, source_node);
25073144 instruction->type = type;
25083145 instruction->op = op;
25093146
2510 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3147 ir_ref_instruction(type, irb->current_basic_block);
25113148 ir_ref_instruction(op, irb->current_basic_block);
25123149
25133150 return &instruction->base;
25143151}
25153152
2516static IrInstruction *ir_build_bit_reverse(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2517 IrInstructionBitReverse *instruction = ir_build_instruction<IrInstructionBitReverse>(irb, scope, source_node);
3153static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type,
3154 IrInstGen *op)
3155{
3156 IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb,
3157 source_instr->scope, source_instr->source_node);
3158 instruction->base.value->type = op_type;
3159 instruction->op = op;
3160
3161 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3162
3163 return &instruction->base;
3164}
3165
3166static IrInstSrc *ir_build_bit_reverse(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3167 IrInstSrc *op)
3168{
3169 IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(irb, scope, source_node);
25183170 instruction->type = type;
25193171 instruction->op = op;
25203172
2521 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3173 ir_ref_instruction(type, irb->current_basic_block);
25223174 ir_ref_instruction(op, irb->current_basic_block);
25233175
25243176 return &instruction->base;
25253177}
25263178
2527static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target_value,
2528 IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime,
2529 IrInstruction *switch_prongs_void)
3179static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type,
3180 IrInstGen *op)
3181{
3182 IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb,
3183 source_instr->scope, source_instr->source_node);
3184 instruction->base.value->type = int_type;
3185 instruction->op = op;
3186
3187 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3188
3189 return &instruction->base;
3190}
3191
3192static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3193 IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases,
3194 IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void)
25303195{
2531 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);
2532 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2533 instruction->base.value->special = ConstValSpecialStatic;
3196 IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(irb, scope, source_node);
3197 instruction->base.is_noreturn = true;
25343198 instruction->target_value = target_value;
25353199 instruction->else_block = else_block;
25363200 instruction->case_count = case_count;
......@@ -2539,9 +3203,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
25393203 instruction->switch_prongs_void = switch_prongs_void;
25403204
25413205 ir_ref_instruction(target_value, irb->current_basic_block);
2542 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);
3206 ir_ref_instruction(is_comptime, irb->current_basic_block);
25433207 ir_ref_bb(else_block);
2544 if (switch_prongs_void) ir_ref_instruction(switch_prongs_void, irb->current_basic_block);
3208 ir_ref_instruction(switch_prongs_void, irb->current_basic_block);
25453209
25463210 for (size_t i = 0; i < case_count; i += 1) {
25473211 ir_ref_instruction(cases[i].value, irb->current_basic_block);
......@@ -2551,10 +3215,31 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
25513215 return instruction;
25523216}
25533217
2554static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node,
2555 IrInstruction *target_value_ptr)
3218static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr,
3219 IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases)
25563220{
2557 IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, scope, source_node);
3221 IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb,
3222 source_instr->scope, source_instr->source_node);
3223 instruction->target_value = target_value;
3224 instruction->else_block = else_block;
3225 instruction->case_count = case_count;
3226 instruction->cases = cases;
3227
3228 ir_ref_inst_gen(target_value, ira->new_irb.current_basic_block);
3229 ir_ref_bb_gen(else_block);
3230
3231 for (size_t i = 0; i < case_count; i += 1) {
3232 ir_ref_inst_gen(cases[i].value, ira->new_irb.current_basic_block);
3233 ir_ref_bb_gen(cases[i].block);
3234 }
3235
3236 return instruction;
3237}
3238
3239static IrInstSrc *ir_build_switch_target(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3240 IrInstSrc *target_value_ptr)
3241{
3242 IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(irb, scope, source_node);
25583243 instruction->target_value_ptr = target_value_ptr;
25593244
25603245 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
......@@ -2562,10 +3247,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo
25623247 return &instruction->base;
25633248}
25643249
2565static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode *source_node,
2566 IrInstruction *target_value_ptr, IrInstruction **prongs_ptr, size_t prongs_len)
3250static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3251 IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len)
25673252{
2568 IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, scope, source_node);
3253 IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node);
25693254 instruction->target_value_ptr = target_value_ptr;
25703255 instruction->prongs_ptr = prongs_ptr;
25713256 instruction->prongs_len = prongs_len;
......@@ -2579,10 +3264,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode
25793264}
25803265
25813266// For this instruction the switch_br must be set later.
2582static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scope *scope, AstNode *source_node,
2583 IrInstruction *target_value_ptr)
3267static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3268 IrInstSrc *target_value_ptr)
25843269{
2585 IrInstructionSwitchElseVar *instruction = ir_build_instruction<IrInstructionSwitchElseVar>(irb, scope, source_node);
3270 IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node);
25863271 instruction->target_value_ptr = target_value_ptr;
25873272
25883273 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
......@@ -2590,17 +3275,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop
25903275 return instruction;
25913276}
25923277
2593static IrInstruction *ir_build_union_tag(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2594 IrInstructionUnionTag *instruction = ir_build_instruction<IrInstructionUnionTag>(irb, scope, source_node);
3278static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
3279 ZigType *tag_type)
3280{
3281 IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb,
3282 source_instr->scope, source_instr->source_node);
25953283 instruction->value = value;
3284 instruction->base.value->type = tag_type;
25963285
2597 ir_ref_instruction(value, irb->current_basic_block);
3286 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
25983287
25993288 return &instruction->base;
26003289}
26013290
2602static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2603 IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, scope, source_node);
3291static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3292 IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node);
26043293 instruction->name = name;
26053294
26063295 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2608,10 +3297,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou
26083297 return &instruction->base;
26093298}
26103299
2611static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value,
3300static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value,
26123301 bool is_const, bool is_volatile)
26133302{
2614 IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, scope, source_node);
3303 IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node);
26153304 instruction->value = value;
26163305 instruction->is_const = is_const;
26173306 instruction->is_volatile = is_volatile;
......@@ -2621,23 +3310,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source
26213310 return &instruction->base;
26223311}
26233312
2624static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,
2625 IrInstruction *operand, IrInstruction *result_loc)
3313static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
3314 IrInstGen *operand, IrInstGen *result_loc)
26263315{
2627 IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb,
3316 IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb,
26283317 source_instruction->scope, source_instruction->source_node);
26293318 instruction->base.value->type = result_type;
26303319 instruction->operand = operand;
26313320 instruction->result_loc = result_loc;
26323321
2633 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2634 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3322 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3323 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
26353324
26363325 return &instruction->base;
26373326}
26383327
2639static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
2640 IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node);
3328static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
3329 IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node);
26413330 instruction->msg = msg;
26423331
26433332 ir_ref_instruction(msg, irb->current_basic_block);
......@@ -2645,10 +3334,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode
26453334 return &instruction->base;
26463335}
26473336
2648static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode *source_node,
2649 size_t msg_count, IrInstruction **msg_list)
3337static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3338 size_t msg_count, IrInstSrc **msg_list)
26503339{
2651 IrInstructionCompileLog *instruction = ir_build_instruction<IrInstructionCompileLog>(irb, scope, source_node);
3340 IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node);
26523341 instruction->msg_count = msg_count;
26533342 instruction->msg_list = msg_list;
26543343
......@@ -2659,8 +3348,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode
26593348 return &instruction->base;
26603349}
26613350
2662static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2663 IrInstructionErrName *instruction = ir_build_instruction<IrInstructionErrName>(irb, scope, source_node);
3351static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
3352 IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node);
26643353 instruction->value = value;
26653354
26663355 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2668,13 +3357,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s
26683357 return &instruction->base;
26693358}
26703359
2671static IrInstruction *ir_build_c_import(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2672 IrInstructionCImport *instruction = ir_build_instruction<IrInstructionCImport>(irb, scope, source_node);
3360static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
3361 ZigType *str_type)
3362{
3363 IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb,
3364 source_instr->scope, source_instr->source_node);
3365 instruction->base.value->type = str_type;
3366 instruction->value = value;
3367
3368 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
3369
3370 return &instruction->base;
3371}
3372
3373static IrInstSrc *ir_build_c_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3374 IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(irb, scope, source_node);
26733375 return &instruction->base;
26743376}
26753377
2676static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2677 IrInstructionCInclude *instruction = ir_build_instruction<IrInstructionCInclude>(irb, scope, source_node);
3378static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3379 IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node);
26783380 instruction->name = name;
26793381
26803382 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2682,8 +3384,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *
26823384 return &instruction->base;
26833385}
26843386
2685static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name, IrInstruction *value) {
2686 IrInstructionCDefine *instruction = ir_build_instruction<IrInstructionCDefine>(irb, scope, source_node);
3387static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) {
3388 IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node);
26873389 instruction->name = name;
26883390 instruction->value = value;
26893391
......@@ -2693,8 +3395,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s
26933395 return &instruction->base;
26943396}
26953397
2696static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2697 IrInstructionCUndef *instruction = ir_build_instruction<IrInstructionCUndef>(irb, scope, source_node);
3398static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3399 IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node);
26983400 instruction->name = name;
26993401
27003402 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2702,8 +3404,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so
27023404 return &instruction->base;
27033405}
27043406
2705static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2706 IrInstructionEmbedFile *instruction = ir_build_instruction<IrInstructionEmbedFile>(irb, scope, source_node);
3407static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3408 IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node);
27073409 instruction->name = name;
27083410
27093411 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2711,11 +3413,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode
27113413 return &instruction->base;
27123414}
27133415
2714static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2715 IrInstruction *type_value, IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,
2716 IrInstruction *success_order_value, IrInstruction *failure_order_value, bool is_weak, ResultLoc *result_loc)
3416static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3417 IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value,
3418 IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc)
27173419{
2718 IrInstructionCmpxchgSrc *instruction = ir_build_instruction<IrInstructionCmpxchgSrc>(irb, scope, source_node);
3420 IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node);
27193421 instruction->type_value = type_value;
27203422 instruction->ptr = ptr;
27213423 instruction->cmp_value = cmp_value;
......@@ -2735,11 +3437,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode
27353437 return &instruction->base;
27363438}
27373439
2738static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,
2739 IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,
2740 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstruction *result_loc)
3440static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
3441 IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value,
3442 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc)
27413443{
2742 IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb,
3444 IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb,
27433445 source_instruction->scope, source_instruction->source_node);
27443446 instruction->base.value->type = result_type;
27453447 instruction->ptr = ptr;
......@@ -2750,26 +3452,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source
27503452 instruction->is_weak = is_weak;
27513453 instruction->result_loc = result_loc;
27523454
2753 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
2754 ir_ref_instruction(cmp_value, ira->new_irb.current_basic_block);
2755 ir_ref_instruction(new_value, ira->new_irb.current_basic_block);
2756 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3455 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
3456 ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block);
3457 ir_ref_inst_gen(new_value, ira->new_irb.current_basic_block);
3458 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
27573459
27583460 return &instruction->base;
27593461}
27603462
2761static IrInstruction *ir_build_fence(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *order_value, AtomicOrder order) {
2762 IrInstructionFence *instruction = ir_build_instruction<IrInstructionFence>(irb, scope, source_node);
2763 instruction->order_value = order_value;
3463static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) {
3464 IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node);
27643465 instruction->order = order;
27653466
2766 ir_ref_instruction(order_value, irb->current_basic_block);
3467 ir_ref_instruction(order, irb->current_basic_block);
27673468
27683469 return &instruction->base;
27693470}
27703471
2771static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2772 IrInstructionTruncate *instruction = ir_build_instruction<IrInstructionTruncate>(irb, scope, source_node);
3472static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) {
3473 IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb,
3474 source_instr->scope, source_instr->source_node);
3475 instruction->order = order;
3476
3477 return &instruction->base;
3478}
3479
3480static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3481 IrInstSrc *dest_type, IrInstSrc *target)
3482{
3483 IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node);
27733484 instruction->dest_type = dest_type;
27743485 instruction->target = target;
27753486
......@@ -2779,8 +3490,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s
27793490 return &instruction->base;
27803491}
27813492
2782static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2783 IrInstructionIntCast *instruction = ir_build_instruction<IrInstructionIntCast>(irb, scope, source_node);
3493static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type,
3494 IrInstGen *target)
3495{
3496 IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb,
3497 source_instr->scope, source_instr->source_node);
3498 instruction->base.value->type = dest_type;
3499 instruction->target = target;
3500
3501 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
3502
3503 return &instruction->base;
3504}
3505
3506static IrInstSrc *ir_build_int_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
3507 IrInstSrc *target)
3508{
3509 IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(irb, scope, source_node);
27843510 instruction->dest_type = dest_type;
27853511 instruction->target = target;
27863512
......@@ -2790,8 +3516,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s
27903516 return &instruction->base;
27913517}
27923518
2793static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2794 IrInstructionFloatCast *instruction = ir_build_instruction<IrInstructionFloatCast>(irb, scope, source_node);
3519static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
3520 IrInstSrc *target)
3521{
3522 IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node);
27953523 instruction->dest_type = dest_type;
27963524 instruction->target = target;
27973525
......@@ -2801,8 +3529,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode
28013529 return &instruction->base;
28023530}
28033531
2804static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2805 IrInstructionErrSetCast *instruction = ir_build_instruction<IrInstructionErrSetCast>(irb, scope, source_node);
3532static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3533 IrInstSrc *dest_type, IrInstSrc *target)
3534{
3535 IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node);
28063536 instruction->dest_type = dest_type;
28073537 instruction->target = target;
28083538
......@@ -2812,10 +3542,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod
28123542 return &instruction->base;
28133543}
28143544
2815static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target,
3545static IrInstSrc *ir_build_to_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target,
28163546 ResultLoc *result_loc)
28173547{
2818 IrInstructionToBytes *instruction = ir_build_instruction<IrInstructionToBytes>(irb, scope, source_node);
3548 IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node);
28193549 instruction->target = target;
28203550 instruction->result_loc = result_loc;
28213551
......@@ -2824,10 +3554,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s
28243554 return &instruction->base;
28253555}
28263556
2827static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node,
2828 IrInstruction *dest_child_type, IrInstruction *target, ResultLoc *result_loc)
3557static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3558 IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc)
28293559{
2830 IrInstructionFromBytes *instruction = ir_build_instruction<IrInstructionFromBytes>(irb, scope, source_node);
3560 IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node);
28313561 instruction->dest_child_type = dest_child_type;
28323562 instruction->target = target;
28333563 instruction->result_loc = result_loc;
......@@ -2838,8 +3568,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode
28383568 return &instruction->base;
28393569}
28403570
2841static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2842 IrInstructionIntToFloat *instruction = ir_build_instruction<IrInstructionIntToFloat>(irb, scope, source_node);
3571static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3572 IrInstSrc *dest_type, IrInstSrc *target)
3573{
3574 IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node);
28433575 instruction->dest_type = dest_type;
28443576 instruction->target = target;
28453577
......@@ -2849,8 +3581,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod
28493581 return &instruction->base;
28503582}
28513583
2852static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2853 IrInstructionFloatToInt *instruction = ir_build_instruction<IrInstructionFloatToInt>(irb, scope, source_node);
3584static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3585 IrInstSrc *dest_type, IrInstSrc *target)
3586{
3587 IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node);
28543588 instruction->dest_type = dest_type;
28553589 instruction->target = target;
28563590
......@@ -2860,8 +3594,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod
28603594 return &instruction->base;
28613595}
28623596
2863static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target) {
2864 IrInstructionBoolToInt *instruction = ir_build_instruction<IrInstructionBoolToInt>(irb, scope, source_node);
3597static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
3598 IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node);
28653599 instruction->target = target;
28663600
28673601 ir_ref_instruction(target, irb->current_basic_block);
......@@ -2869,8 +3603,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode
28693603 return &instruction->base;
28703604}
28713605
2872static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_signed, IrInstruction *bit_count) {
2873 IrInstructionIntType *instruction = ir_build_instruction<IrInstructionIntType>(irb, scope, source_node);
3606static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed,
3607 IrInstSrc *bit_count)
3608{
3609 IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node);
28743610 instruction->is_signed = is_signed;
28753611 instruction->bit_count = bit_count;
28763612
......@@ -2880,10 +3616,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s
28803616 return &instruction->base;
28813617}
28823618
2883static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *len,
2884 IrInstruction *elem_type)
3619static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
3620 IrInstSrc *elem_type)
28853621{
2886 IrInstructionVectorType *instruction = ir_build_instruction<IrInstructionVectorType>(irb, scope, source_node);
3622 IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node);
28873623 instruction->len = len;
28883624 instruction->elem_type = elem_type;
28893625
......@@ -2893,18 +3629,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode
28933629 return &instruction->base;
28943630}
28953631
2896static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstNode *source_node,
2897 IrInstruction *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)
3632static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3633 IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask)
28983634{
2899 IrInstructionShuffleVector *instruction = ir_build_instruction<IrInstructionShuffleVector>(irb, scope, source_node);
3635 IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node);
29003636 instruction->scalar_type = scalar_type;
29013637 instruction->a = a;
29023638 instruction->b = b;
29033639 instruction->mask = mask;
29043640
2905 if (scalar_type != nullptr) {
2906 ir_ref_instruction(scalar_type, irb->current_basic_block);
2907 }
3641 if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block);
29083642 ir_ref_instruction(a, irb->current_basic_block);
29093643 ir_ref_instruction(b, irb->current_basic_block);
29103644 ir_ref_instruction(mask, irb->current_basic_block);
......@@ -2912,10 +3646,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN
29123646 return &instruction->base;
29133647}
29143648
2915static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2916 IrInstruction *len, IrInstruction *scalar)
3649static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
3650 ZigType *result_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
29173651{
2918 IrInstructionSplatSrc *instruction = ir_build_instruction<IrInstructionSplatSrc>(irb, scope, source_node);
3652 IrInstGenShuffleVector *inst = ir_build_inst_gen<IrInstGenShuffleVector>(&ira->new_irb, scope, source_node);
3653 inst->base.value->type = result_type;
3654 inst->a = a;
3655 inst->b = b;
3656 inst->mask = mask;
3657
3658 ir_ref_inst_gen(a, ira->new_irb.current_basic_block);
3659 ir_ref_inst_gen(b, ira->new_irb.current_basic_block);
3660 ir_ref_inst_gen(mask, ira->new_irb.current_basic_block);
3661
3662 return &inst->base;
3663}
3664
3665static IrInstSrc *ir_build_splat_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3666 IrInstSrc *len, IrInstSrc *scalar)
3667{
3668 IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(irb, scope, source_node);
29193669 instruction->len = len;
29203670 instruction->scalar = scalar;
29213671
......@@ -2925,8 +3675,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *
29253675 return &instruction->base;
29263676}
29273677
2928static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2929 IrInstructionBoolNot *instruction = ir_build_instruction<IrInstructionBoolNot>(irb, scope, source_node);
3678static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
3679 IrInstGen *scalar)
3680{
3681 IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>(
3682 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3683 instruction->base.value->type = result_type;
3684 instruction->scalar = scalar;
3685
3686 ir_ref_inst_gen(scalar, ira->new_irb.current_basic_block);
3687
3688 return &instruction->base;
3689}
3690
3691static IrInstSrc *ir_build_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
3692 IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(irb, scope, source_node);
29303693 instruction->value = value;
29313694
29323695 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2934,10 +3697,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s
29343697 return &instruction->base;
29353698}
29363699
2937static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *source_node,
2938 IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count)
3700static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
3701 IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb,
3702 source_instr->scope, source_instr->source_node);
3703 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3704 instruction->value = value;
3705
3706 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
3707
3708 return &instruction->base;
3709}
3710
3711static IrInstSrc *ir_build_memset_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3712 IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count)
29393713{
2940 IrInstructionMemset *instruction = ir_build_instruction<IrInstructionMemset>(irb, scope, source_node);
3714 IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node);
29413715 instruction->dest_ptr = dest_ptr;
29423716 instruction->byte = byte;
29433717 instruction->count = count;
......@@ -2949,10 +3723,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou
29493723 return &instruction->base;
29503724}
29513725
2952static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *source_node,
2953 IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count)
3726static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,
3727 IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count)
3728{
3729 IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb,
3730 source_instr->scope, source_instr->source_node);
3731 instruction->dest_ptr = dest_ptr;
3732 instruction->byte = byte;
3733 instruction->count = count;
3734
3735 ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block);
3736 ir_ref_inst_gen(byte, ira->new_irb.current_basic_block);
3737 ir_ref_inst_gen(count, ira->new_irb.current_basic_block);
3738
3739 return &instruction->base;
3740}
3741
3742static IrInstSrc *ir_build_memcpy_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3743 IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count)
29543744{
2955 IrInstructionMemcpy *instruction = ir_build_instruction<IrInstructionMemcpy>(irb, scope, source_node);
3745 IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node);
29563746 instruction->dest_ptr = dest_ptr;
29573747 instruction->src_ptr = src_ptr;
29583748 instruction->count = count;
......@@ -2964,11 +3754,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou
29643754 return &instruction->base;
29653755}
29663756
2967static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2968 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, IrInstruction *sentinel,
3757static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,
3758 IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count)
3759{
3760 IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb,
3761 source_instr->scope, source_instr->source_node);
3762 instruction->dest_ptr = dest_ptr;
3763 instruction->src_ptr = src_ptr;
3764 instruction->count = count;
3765
3766 ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block);
3767 ir_ref_inst_gen(src_ptr, ira->new_irb.current_basic_block);
3768 ir_ref_inst_gen(count, ira->new_irb.current_basic_block);
3769
3770 return &instruction->base;
3771}
3772
3773static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3774 IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel,
29693775 bool safety_check_on, ResultLoc *result_loc)
29703776{
2971 IrInstructionSliceSrc *instruction = ir_build_instruction<IrInstructionSliceSrc>(irb, scope, source_node);
3777 IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node);
29723778 instruction->ptr = ptr;
29733779 instruction->start = start;
29743780 instruction->end = end;
......@@ -2984,23 +3790,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *
29843790 return &instruction->base;
29853791}
29863792
2987static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,
2988 IrInstruction *scalar)
2989{
2990 IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>(
2991 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2992 instruction->base.value->type = result_type;
2993 instruction->scalar = scalar;
2994
2995 ir_ref_instruction(scalar, ira->new_irb.current_basic_block);
2996
2997 return &instruction->base;
2998}
2999
3000static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *slice_type,
3001 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool safety_check_on, IrInstruction *result_loc)
3793static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type,
3794 IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc)
30023795{
3003 IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>(
3796 IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>(
30043797 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
30053798 instruction->base.value->type = slice_type;
30063799 instruction->ptr = ptr;
......@@ -3009,16 +3802,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i
30093802 instruction->safety_check_on = safety_check_on;
30103803 instruction->result_loc = result_loc;
30113804
3012 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
3013 ir_ref_instruction(start, ira->new_irb.current_basic_block);
3014 if (end) ir_ref_instruction(end, ira->new_irb.current_basic_block);
3015 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3805 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
3806 ir_ref_inst_gen(start, ira->new_irb.current_basic_block);
3807 if (end) ir_ref_inst_gen(end, ira->new_irb.current_basic_block);
3808 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
30163809
30173810 return &instruction->base;
30183811}
30193812
3020static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *container) {
3021 IrInstructionMemberCount *instruction = ir_build_instruction<IrInstructionMemberCount>(irb, scope, source_node);
3813static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
3814 IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
30223815 instruction->container = container;
30233816
30243817 ir_ref_instruction(container, irb->current_basic_block);
......@@ -3026,10 +3819,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod
30263819 return &instruction->base;
30273820}
30283821
3029static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3030 IrInstruction *container_type, IrInstruction *member_index)
3822static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3823 IrInstSrc *container_type, IrInstSrc *member_index)
30313824{
3032 IrInstructionMemberType *instruction = ir_build_instruction<IrInstructionMemberType>(irb, scope, source_node);
3825 IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
30333826 instruction->container_type = container_type;
30343827 instruction->member_index = member_index;
30353828
......@@ -3039,10 +3832,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode
30393832 return &instruction->base;
30403833}
30413834
3042static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode *source_node,
3043 IrInstruction *container_type, IrInstruction *member_index)
3835static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3836 IrInstSrc *container_type, IrInstSrc *member_index)
30443837{
3045 IrInstructionMemberName *instruction = ir_build_instruction<IrInstructionMemberName>(irb, scope, source_node);
3838 IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
30463839 instruction->container_type = container_type;
30473840 instruction->member_index = member_index;
30483841
......@@ -3052,65 +3845,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode
30523845 return &instruction->base;
30533846}
30543847
3055static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3056 IrInstructionBreakpoint *instruction = ir_build_instruction<IrInstructionBreakpoint>(irb, scope, source_node);
3848static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3849 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
30573850 return &instruction->base;
30583851}
30593852
3060static IrInstruction *ir_build_return_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3061 IrInstructionReturnAddress *instruction = ir_build_instruction<IrInstructionReturnAddress>(irb, scope, source_node);
3853static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) {
3854 IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb,
3855 source_instr->scope, source_instr->source_node);
30623856 return &instruction->base;
30633857}
30643858
3065static IrInstruction *ir_build_frame_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3066 IrInstructionFrameAddress *instruction = ir_build_instruction<IrInstructionFrameAddress>(irb, scope, source_node);
3859static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3860 IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node);
30673861 return &instruction->base;
30683862}
30693863
3070static IrInstruction *ir_build_handle(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3071 IrInstructionFrameHandle *instruction = ir_build_instruction<IrInstructionFrameHandle>(irb, scope, source_node);
3072 return &instruction->base;
3864static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) {
3865 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3866 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3867 return &inst->base;
3868}
3869
3870static IrInstSrc *ir_build_frame_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3871 IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(irb, scope, source_node);
3872 return &inst->base;
3873}
3874
3875static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) {
3876 IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3877 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3878 return &inst->base;
3879}
3880
3881static IrInstSrc *ir_build_handle_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3882 IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(irb, scope, source_node);
3883 return &inst->base;
30733884}
30743885
3075static IrInstruction *ir_build_frame_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {
3076 IrInstructionFrameType *instruction = ir_build_instruction<IrInstructionFrameType>(irb, scope, source_node);
3077 instruction->fn = fn;
3886static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) {
3887 IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3888 inst->base.value->type = ty;
3889 return &inst->base;
3890}
3891
3892static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3893 IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node);
3894 inst->fn = fn;
30783895
30793896 ir_ref_instruction(fn, irb->current_basic_block);
30803897
3081 return &instruction->base;
3898 return &inst->base;
30823899}
30833900
3084static IrInstruction *ir_build_frame_size_src(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {
3085 IrInstructionFrameSizeSrc *instruction = ir_build_instruction<IrInstructionFrameSizeSrc>(irb, scope, source_node);
3086 instruction->fn = fn;
3901static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3902 IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node);
3903 inst->fn = fn;
30873904
30883905 ir_ref_instruction(fn, irb->current_basic_block);
30893906
3090 return &instruction->base;
3907 return &inst->base;
30913908}
30923909
3093static IrInstruction *ir_build_frame_size_gen(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn)
3910static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn)
30943911{
3095 IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node);
3096 instruction->fn = fn;
3912 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3913 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3914 inst->fn = fn;
30973915
3098 ir_ref_instruction(fn, irb->current_basic_block);
3916 ir_ref_inst_gen(fn, ira->new_irb.current_basic_block);
30993917
3100 return &instruction->base;
3918 return &inst->base;
31013919}
31023920
3103static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,
3104 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,
3105 IrInstruction *result_ptr, ZigType *result_ptr_type)
3921static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3922 IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr)
31063923{
3107 IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);
3924 IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node);
31083925 instruction->op = op;
31093926 instruction->type_value = type_value;
31103927 instruction->op1 = op1;
31113928 instruction->op2 = op2;
31123929 instruction->result_ptr = result_ptr;
3113 instruction->result_ptr_type = result_ptr_type;
31143930
31153931 ir_ref_instruction(type_value, irb->current_basic_block);
31163932 ir_ref_instruction(op1, irb->current_basic_block);
......@@ -3120,49 +3936,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode
31203936 return &instruction->base;
31213937}
31223938
3939static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,
3940 IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr,
3941 ZigType *result_ptr_type)
3942{
3943 IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb,
3944 source_instr->scope, source_instr->source_node);
3945 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3946 instruction->op = op;
3947 instruction->op1 = op1;
3948 instruction->op2 = op2;
3949 instruction->result_ptr = result_ptr;
3950 instruction->result_ptr_type = result_ptr_type;
31233951
3124//TODO Powi, Pow, minnum, maxnum, maximum, minimum, copysign,
3125// lround, llround, lrint, llrint
3126// So far this is only non-complicated type functions.
3127const char *float_op_to_name(BuiltinFnId op) {
3128 switch (op) {
3129 case BuiltinFnIdSqrt:
3130 return "sqrt";
3131 case BuiltinFnIdSin:
3132 return "sin";
3133 case BuiltinFnIdCos:
3134 return "cos";
3135 case BuiltinFnIdExp:
3136 return "exp";
3137 case BuiltinFnIdExp2:
3138 return "exp2";
3139 case BuiltinFnIdLog:
3140 return "log";
3141 case BuiltinFnIdLog10:
3142 return "log10";
3143 case BuiltinFnIdLog2:
3144 return "log2";
3145 case BuiltinFnIdFabs:
3146 return "fabs";
3147 case BuiltinFnIdFloor:
3148 return "floor";
3149 case BuiltinFnIdCeil:
3150 return "ceil";
3151 case BuiltinFnIdTrunc:
3152 return "trunc";
3153 case BuiltinFnIdNearbyInt:
3154 return "nearbyint";
3155 case BuiltinFnIdRound:
3156 return "round";
3157 default:
3158 zig_unreachable();
3159 }
3952 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
3953 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
3954 ir_ref_inst_gen(result_ptr, ira->new_irb.current_basic_block);
3955
3956 return &instruction->base;
31603957}
31613958
3162static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *operand,
3959static IrInstSrc *ir_build_float_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand,
31633960 BuiltinFnId fn_id)
31643961{
3165 IrInstructionFloatOp *instruction = ir_build_instruction<IrInstructionFloatOp>(irb, scope, source_node);
3962 IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node);
31663963 instruction->operand = operand;
31673964 instruction->fn_id = fn_id;
31683965
......@@ -3171,9 +3968,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s
31713968 return &instruction->base;
31723969}
31733970
3174static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *source_node,
3175 IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, IrInstruction *op3) {
3176 IrInstructionMulAdd *instruction = ir_build_instruction<IrInstructionMulAdd>(irb, scope, source_node);
3971static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
3972 BuiltinFnId fn_id, ZigType *operand_type)
3973{
3974 IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb,
3975 source_instr->scope, source_instr->source_node);
3976 instruction->base.value->type = operand_type;
3977 instruction->operand = operand;
3978 instruction->fn_id = fn_id;
3979
3980 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3981
3982 return &instruction->base;
3983}
3984
3985static IrInstSrc *ir_build_mul_add_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3986 IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3)
3987{
3988 IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(irb, scope, source_node);
31773989 instruction->type_value = type_value;
31783990 instruction->op1 = op1;
31793991 instruction->op2 = op2;
......@@ -3187,8 +3999,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so
31873999 return &instruction->base;
31884000}
31894001
3190static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) {
3191 IrInstructionAlignOf *instruction = ir_build_instruction<IrInstructionAlignOf>(irb, scope, source_node);
4002static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,
4003 IrInstGen *op3, ZigType *expr_type)
4004{
4005 IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb,
4006 source_instr->scope, source_instr->source_node);
4007 instruction->base.value->type = expr_type;
4008 instruction->op1 = op1;
4009 instruction->op2 = op2;
4010 instruction->op3 = op3;
4011
4012 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
4013 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
4014 ir_ref_inst_gen(op3, ira->new_irb.current_basic_block);
4015
4016 return &instruction->base;
4017}
4018
4019static IrInstSrc *ir_build_align_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4020 IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(irb, scope, source_node);
31924021 instruction->type_value = type_value;
31934022
31944023 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3196,10 +4025,10 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s
31964025 return &instruction->base;
31974026}
31984027
3199static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3200 IrInstruction *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)
4028static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4029 IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)
32014030{
3202 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);
4031 IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node);
32034032 instruction->base_ptr = base_ptr;
32044033 instruction->resolve_err_set = resolve_err_set;
32054034 instruction->base_ptr_is_payload = base_ptr_is_payload;
......@@ -3209,48 +4038,72 @@ static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNod
32094038 return &instruction->base;
32104039}
32114040
3212static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3213 IrInstruction *err_union)
3214{
3215 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(
4041static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) {
4042 IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>(
32164043 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
32174044 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
32184045 instruction->err_union = err_union;
32194046
3220 ir_ref_instruction(err_union, ira->new_irb.current_basic_block);
4047 ir_ref_inst_gen(err_union, ira->new_irb.current_basic_block);
32214048
32224049 return &instruction->base;
32234050}
32244051
3225static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node,
3226 IrInstruction *err_union_ptr)
4052static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4053 IrInstSrc *err_union_ptr)
32274054{
3228 IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node);
3229 instruction->err_union_ptr = err_union_ptr;
4055 IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node);
4056 inst->err_union_ptr = err_union_ptr;
32304057
32314058 ir_ref_instruction(err_union_ptr, irb->current_basic_block);
32324059
3233 return &instruction->base;
4060 return &inst->base;
32344061}
32354062
3236static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, AstNode *source_node,
3237 IrInstruction *value, bool safety_check_on, bool initializing)
4063static IrInstGen *ir_build_unwrap_err_code_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4064 IrInstGen *err_union_ptr, ZigType *result_type)
32384065{
3239 IrInstructionUnwrapErrPayload *instruction = ir_build_instruction<IrInstructionUnwrapErrPayload>(irb, scope, source_node);
3240 instruction->value = value;
3241 instruction->safety_check_on = safety_check_on;
3242 instruction->initializing = initializing;
4066 IrInstGenUnwrapErrCode *inst = ir_build_inst_gen<IrInstGenUnwrapErrCode>(&ira->new_irb, scope, source_node);
4067 inst->base.value->type = result_type;
4068 inst->err_union_ptr = err_union_ptr;
4069
4070 ir_ref_inst_gen(err_union_ptr, ira->new_irb.current_basic_block);
4071
4072 return &inst->base;
4073}
4074
4075static IrInstSrc *ir_build_unwrap_err_payload_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4076 IrInstSrc *value, bool safety_check_on, bool initializing)
4077{
4078 IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(irb, scope, source_node);
4079 inst->value = value;
4080 inst->safety_check_on = safety_check_on;
4081 inst->initializing = initializing;
32434082
32444083 ir_ref_instruction(value, irb->current_basic_block);
32454084
3246 return &instruction->base;
4085 return &inst->base;
4086}
4087
4088static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4089 IrInstGen *value, bool safety_check_on, bool initializing, ZigType *result_type)
4090{
4091 IrInstGenUnwrapErrPayload *inst = ir_build_inst_gen<IrInstGenUnwrapErrPayload>(&ira->new_irb, scope, source_node);
4092 inst->base.value->type = result_type;
4093 inst->value = value;
4094 inst->safety_check_on = safety_check_on;
4095 inst->initializing = initializing;
4096
4097 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
4098
4099 return &inst->base;
32474100}
32484101
3249static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,
3250 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *callconv_value,
3251 IrInstruction *return_type, bool is_var_args)
4102static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4103 IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value,
4104 IrInstSrc *return_type, bool is_var_args)
32524105{
3253 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);
4106 IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node);
32544107 instruction->param_types = param_types;
32554108 instruction->align_value = align_value;
32564109 instruction->callconv_value = callconv_value;
......@@ -3270,8 +4123,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s
32704123 return &instruction->base;
32714124}
32724125
3273static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
3274 IrInstructionTestComptime *instruction = ir_build_instruction<IrInstructionTestComptime>(irb, scope, source_node);
4126static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
4127 IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node);
32754128 instruction->value = value;
32764129
32774130 ir_ref_instruction(value, irb->current_basic_block);
......@@ -3279,10 +4132,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo
32794132 return &instruction->base;
32804133}
32814134
3282static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3283 IrInstruction *dest_type, IrInstruction *ptr, bool safety_check_on)
4135static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4136 IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on)
32844137{
3285 IrInstructionPtrCastSrc *instruction = ir_build_instruction<IrInstructionPtrCastSrc>(
4138 IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>(
32864139 irb, scope, source_node);
32874140 instruction->dest_type = dest_type;
32884141 instruction->ptr = ptr;
......@@ -3294,39 +4147,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod
32944147 return &instruction->base;
32954148}
32964149
3297static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3298 ZigType *ptr_type, IrInstruction *ptr, bool safety_check_on)
4150static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
4151 ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on)
32994152{
3300 IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>(
4153 IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>(
33014154 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
33024155 instruction->base.value->type = ptr_type;
33034156 instruction->ptr = ptr;
33044157 instruction->safety_check_on = safety_check_on;
33054158
3306 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
4159 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
33074160
33084161 return &instruction->base;
33094162}
33104163
3311static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3312 IrInstruction *ptr, ZigType *ty, IrInstruction *result_loc)
4164static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4165 IrInstSrc *operand, ResultLocCast *result_loc_cast)
33134166{
3314 IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>(
3315 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3316 instruction->base.value->type = ty;
3317 instruction->ptr = ptr;
3318 instruction->result_loc = result_loc;
3319
3320 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
3321 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3322
3323 return &instruction->base;
3324}
3325
3326static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
3327 IrInstruction *operand, ResultLocCast *result_loc_cast)
3328{
3329 IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node);
4167 IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node);
33304168 instruction->operand = operand;
33314169 instruction->result_loc_cast = result_loc_cast;
33324170
......@@ -3335,10 +4173,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo
33354173 return &instruction->base;
33364174}
33374175
3338static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3339 IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast)
4176static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4177 IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast)
33404178{
3341 IrInstructionBitCastSrc *instruction = ir_build_instruction<IrInstructionBitCastSrc>(irb, scope, source_node);
4179 IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node);
33424180 instruction->operand = operand;
33434181 instruction->result_loc_bit_cast = result_loc_bit_cast;
33444182
......@@ -3347,62 +4185,81 @@ static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNod
33474185 return &instruction->base;
33484186}
33494187
3350static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3351 IrInstruction *operand, ZigType *ty)
4188static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
4189 IrInstGen *operand, ZigType *ty)
33524190{
3353 IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>(
4191 IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>(
33544192 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
33554193 instruction->base.value->type = ty;
33564194 instruction->operand = operand;
33574195
3358 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
4196 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
33594197
33604198 return &instruction->base;
33614199}
33624200
3363static IrInstruction *ir_build_widen_or_shorten(IrBuilder *irb, Scope *scope, AstNode *source_node,
3364 IrInstruction *target)
4201static IrInstGen *ir_build_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4202 ZigType *result_type)
33654203{
3366 IrInstructionWidenOrShorten *instruction = ir_build_instruction<IrInstructionWidenOrShorten>(
3367 irb, scope, source_node);
3368 instruction->target = target;
4204 IrInstGenWidenOrShorten *inst = ir_build_inst_gen<IrInstGenWidenOrShorten>(&ira->new_irb, scope, source_node);
4205 inst->base.value->type = result_type;
4206 inst->target = target;
33694207
3370 ir_ref_instruction(target, irb->current_basic_block);
4208 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
33714209
3372 return &instruction->base;
4210 return &inst->base;
33734211}
33744212
3375static IrInstruction *ir_build_int_to_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
3376 IrInstruction *dest_type, IrInstruction *target)
4213static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4214 IrInstSrc *dest_type, IrInstSrc *target)
33774215{
3378 IrInstructionIntToPtr *instruction = ir_build_instruction<IrInstructionIntToPtr>(
3379 irb, scope, source_node);
4216 IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node);
33804217 instruction->dest_type = dest_type;
33814218 instruction->target = target;
33824219
3383 if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block);
4220 ir_ref_instruction(dest_type, irb->current_basic_block);
33844221 ir_ref_instruction(target, irb->current_basic_block);
33854222
33864223 return &instruction->base;
33874224}
33884225
3389static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,
3390 IrInstruction *target)
4226static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4227 IrInstGen *target, ZigType *ptr_type)
33914228{
3392 IrInstructionPtrToInt *instruction = ir_build_instruction<IrInstructionPtrToInt>(
3393 irb, scope, source_node);
4229 IrInstGenIntToPtr *instruction = ir_build_inst_gen<IrInstGenIntToPtr>(&ira->new_irb, scope, source_node);
4230 instruction->base.value->type = ptr_type;
33944231 instruction->target = target;
33954232
3396 ir_ref_instruction(target, irb->current_basic_block);
4233 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
33974234
33984235 return &instruction->base;
33994236}
34004237
3401static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode *source_node,
3402 IrInstruction *dest_type, IrInstruction *target)
4238static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4239 IrInstSrc *target)
34034240{
3404 IrInstructionIntToEnum *instruction = ir_build_instruction<IrInstructionIntToEnum>(
3405 irb, scope, source_node);
4241 IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node);
4242 inst->target = target;
4243
4244 ir_ref_instruction(target, irb->current_basic_block);
4245
4246 return &inst->base;
4247}
4248
4249static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
4250 IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node);
4251 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
4252 inst->target = target;
4253
4254 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4255
4256 return &inst->base;
4257}
4258
4259static IrInstSrc *ir_build_int_to_enum_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4260 IrInstSrc *dest_type, IrInstSrc *target)
4261{
4262 IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(irb, scope, source_node);
34064263 instruction->dest_type = dest_type;
34074264 instruction->target = target;
34084265
......@@ -3412,12 +4269,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode
34124269 return &instruction->base;
34134270}
34144271
4272static IrInstGen *ir_build_int_to_enum_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4273 ZigType *dest_type, IrInstGen *target)
4274{
4275 IrInstGenIntToEnum *instruction = ir_build_inst_gen<IrInstGenIntToEnum>(&ira->new_irb, scope, source_node);
4276 instruction->base.value->type = dest_type;
4277 instruction->target = target;
34154278
4279 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
34164280
3417static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,
3418 IrInstruction *target)
4281 return &instruction->base;
4282}
4283
4284static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4285 IrInstSrc *target)
34194286{
3420 IrInstructionEnumToInt *instruction = ir_build_instruction<IrInstructionEnumToInt>(
4287 IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>(
34214288 irb, scope, source_node);
34224289 instruction->target = target;
34234290
......@@ -3426,11 +4293,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode
34264293 return &instruction->base;
34274294}
34284295
3429static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode *source_node,
3430 IrInstruction *target)
4296static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4297 IrInstSrc *target)
34314298{
3432 IrInstructionIntToErr *instruction = ir_build_instruction<IrInstructionIntToErr>(
3433 irb, scope, source_node);
4299 IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node);
34344300 instruction->target = target;
34354301
34364302 ir_ref_instruction(target, irb->current_basic_block);
......@@ -3438,10 +4304,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode
34384304 return &instruction->base;
34394305}
34404306
3441static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,
3442 IrInstruction *target)
4307static IrInstGen *ir_build_int_to_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4308 ZigType *wanted_type)
4309{
4310 IrInstGenIntToErr *instruction = ir_build_inst_gen<IrInstGenIntToErr>(&ira->new_irb, scope, source_node);
4311 instruction->base.value->type = wanted_type;
4312 instruction->target = target;
4313
4314 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4315
4316 return &instruction->base;
4317}
4318
4319static IrInstSrc *ir_build_err_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4320 IrInstSrc *target)
34434321{
3444 IrInstructionErrToInt *instruction = ir_build_instruction<IrInstructionErrToInt>(
4322 IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>(
34454323 irb, scope, source_node);
34464324 instruction->target = target;
34474325
......@@ -3450,11 +4328,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode
34504328 return &instruction->base;
34514329}
34524330
3453static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, AstNode *source_node,
3454 IrInstruction *target_value, IrInstructionCheckSwitchProngsRange *ranges, size_t range_count,
4331static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4332 ZigType *wanted_type)
4333{
4334 IrInstGenErrToInt *instruction = ir_build_inst_gen<IrInstGenErrToInt>(&ira->new_irb, scope, source_node);
4335 instruction->base.value->type = wanted_type;
4336 instruction->target = target;
4337
4338 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4339
4340 return &instruction->base;
4341}
4342
4343static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4344 IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count,
34554345 bool have_else_prong, bool have_underscore_prong)
34564346{
3457 IrInstructionCheckSwitchProngs *instruction = ir_build_instruction<IrInstructionCheckSwitchProngs>(
4347 IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>(
34584348 irb, scope, source_node);
34594349 instruction->target_value = target_value;
34604350 instruction->ranges = ranges;
......@@ -3471,10 +4361,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,
34714361 return &instruction->base;
34724362}
34734363
3474static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,
3475 IrInstruction* statement_value)
4364static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4365 IrInstSrc* statement_value)
34764366{
3477 IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(
4367 IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>(
34784368 irb, scope, source_node);
34794369 instruction->statement_value = statement_value;
34804370
......@@ -3483,11 +4373,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc
34834373 return &instruction->base;
34844374}
34854375
3486static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *source_node,
3487 IrInstruction *type_value)
4376static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4377 IrInstSrc *type_value)
34884378{
3489 IrInstructionTypeName *instruction = ir_build_instruction<IrInstructionTypeName>(
3490 irb, scope, source_node);
4379 IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node);
34914380 instruction->type_value = type_value;
34924381
34934382 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3495,18 +4384,17 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *
34954384 return &instruction->base;
34964385}
34974386
3498static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
3499 IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(irb, scope, source_node);
4387static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
4388 IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node);
35004389 instruction->tld = tld;
35014390 instruction->lval = lval;
35024391
35034392 return &instruction->base;
35044393}
35054394
3506static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
3507 IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node);
3508 instruction->base.value->special = ConstValSpecialStatic;
3509 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
4395static IrInstSrc *ir_build_panic_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
4396 IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(irb, scope, source_node);
4397 instruction->base.is_noreturn = true;
35104398 instruction->msg = msg;
35114399
35124400 ir_ref_instruction(msg, irb->current_basic_block);
......@@ -3514,10 +4402,18 @@ static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *sour
35144402 return &instruction->base;
35154403}
35164404
3517static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *source_node,
3518 IrInstruction *target)
3519{
3520 IrInstructionTagName *instruction = ir_build_instruction<IrInstructionTagName>(irb, scope, source_node);
4405static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) {
4406 IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb,
4407 source_instr->scope, source_instr->source_node);
4408 instruction->msg = msg;
4409
4410 ir_ref_inst_gen(msg, ira->new_irb.current_basic_block);
4411
4412 return &instruction->base;
4413}
4414
4415static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
4416 IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node);
35214417 instruction->target = target;
35224418
35234419 ir_ref_instruction(target, irb->current_basic_block);
......@@ -3525,10 +4421,23 @@ static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *s
35254421 return &instruction->base;
35264422}
35274423
3528static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3529 IrInstruction *target)
4424static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target,
4425 ZigType *result_type)
35304426{
3531 IrInstructionTagType *instruction = ir_build_instruction<IrInstructionTagType>(irb, scope, source_node);
4427 IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb,
4428 source_instr->scope, source_instr->source_node);
4429 instruction->base.value->type = result_type;
4430 instruction->target = target;
4431
4432 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4433
4434 return &instruction->base;
4435}
4436
4437static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4438 IrInstSrc *target)
4439{
4440 IrInstSrcTagType *instruction = ir_build_instruction<IrInstSrcTagType>(irb, scope, source_node);
35324441 instruction->target = target;
35334442
35344443 ir_ref_instruction(target, irb->current_basic_block);
......@@ -3536,27 +4445,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s
35364445 return &instruction->base;
35374446}
35384447
3539static IrInstruction *ir_build_field_parent_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
3540 IrInstruction *type_value, IrInstruction *field_name, IrInstruction *field_ptr, TypeStructField *field)
4448static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4449 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)
35414450{
3542 IrInstructionFieldParentPtr *instruction = ir_build_instruction<IrInstructionFieldParentPtr>(
4451 IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>(
35434452 irb, scope, source_node);
3544 instruction->type_value = type_value;
3545 instruction->field_name = field_name;
3546 instruction->field_ptr = field_ptr;
3547 instruction->field = field;
4453 inst->type_value = type_value;
4454 inst->field_name = field_name;
4455 inst->field_ptr = field_ptr;
35484456
35494457 ir_ref_instruction(type_value, irb->current_basic_block);
35504458 ir_ref_instruction(field_name, irb->current_basic_block);
35514459 ir_ref_instruction(field_ptr, irb->current_basic_block);
35524460
3553 return &instruction->base;
4461 return &inst->base;
4462}
4463
4464static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
4465 IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type)
4466{
4467 IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb,
4468 source_instr->scope, source_instr->source_node);
4469 inst->base.value->type = result_type;
4470 inst->field_ptr = field_ptr;
4471 inst->field = field;
4472
4473 ir_ref_inst_gen(field_ptr, ira->new_irb.current_basic_block);
4474
4475 return &inst->base;
35544476}
35554477
3556static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,
3557 IrInstruction *type_value, IrInstruction *field_name)
4478static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4479 IrInstSrc *type_value, IrInstSrc *field_name)
35584480{
3559 IrInstructionByteOffsetOf *instruction = ir_build_instruction<IrInstructionByteOffsetOf>(irb, scope, source_node);
4481 IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node);
35604482 instruction->type_value = type_value;
35614483 instruction->field_name = field_name;
35624484
......@@ -3566,10 +4488,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN
35664488 return &instruction->base;
35674489}
35684490
3569static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,
3570 IrInstruction *type_value, IrInstruction *field_name)
4491static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4492 IrInstSrc *type_value, IrInstSrc *field_name)
35714493{
3572 IrInstructionBitOffsetOf *instruction = ir_build_instruction<IrInstructionBitOffsetOf>(irb, scope, source_node);
4494 IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node);
35734495 instruction->type_value = type_value;
35744496 instruction->field_name = field_name;
35754497
......@@ -3579,9 +4501,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo
35794501 return &instruction->base;
35804502}
35814503
3582static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *source_node,
3583 IrInstruction *type_value) {
3584 IrInstructionTypeInfo *instruction = ir_build_instruction<IrInstructionTypeInfo>(irb, scope, source_node);
4504static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4505 IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node);
35854506 instruction->type_value = type_value;
35864507
35874508 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3589,8 +4510,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *
35894510 return &instruction->base;
35904511}
35914512
3592static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_info) {
3593 IrInstructionType *instruction = ir_build_instruction<IrInstructionType>(irb, scope, source_node);
4513static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) {
4514 IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node);
35944515 instruction->type_info = type_info;
35954516
35964517 ir_ref_instruction(type_info, irb->current_basic_block);
......@@ -3598,10 +4519,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc
35984519 return &instruction->base;
35994520}
36004521
3601static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *source_node,
3602 IrInstruction *type_value)
3603{
3604 IrInstructionTypeId *instruction = ir_build_instruction<IrInstructionTypeId>(irb, scope, source_node);
4522static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4523 IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
36054524 instruction->type_value = type_value;
36064525
36074526 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3609,10 +4528,10 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so
36094528 return &instruction->base;
36104529}
36114530
3612static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node,
3613 IrInstruction *new_quota)
4531static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4532 IrInstSrc *new_quota)
36144533{
3615 IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node);
4534 IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node);
36164535 instruction->new_quota = new_quota;
36174536
36184537 ir_ref_instruction(new_quota, irb->current_basic_block);
......@@ -3620,23 +4539,35 @@ static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scop
36204539 return &instruction->base;
36214540}
36224541
3623static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
3624 IrInstruction *align_bytes, IrInstruction *target)
4542static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4543 IrInstSrc *align_bytes, IrInstSrc *target)
36254544{
3626 IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node);
4545 IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node);
36274546 instruction->align_bytes = align_bytes;
36284547 instruction->target = target;
36294548
3630 if (align_bytes) ir_ref_instruction(align_bytes, irb->current_basic_block);
4549 ir_ref_instruction(align_bytes, irb->current_basic_block);
36314550 ir_ref_instruction(target, irb->current_basic_block);
36324551
36334552 return &instruction->base;
36344553}
36354554
3636static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node,
3637 ResultLoc *result_loc, IrInstruction *ty)
4555static IrInstGen *ir_build_align_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4556 ZigType *result_type)
4557{
4558 IrInstGenAlignCast *instruction = ir_build_inst_gen<IrInstGenAlignCast>(&ira->new_irb, scope, source_node);
4559 instruction->base.value->type = result_type;
4560 instruction->target = target;
4561
4562 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4563
4564 return &instruction->base;
4565}
4566
4567static IrInstSrc *ir_build_resolve_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4568 ResultLoc *result_loc, IrInstSrc *ty)
36384569{
3639 IrInstructionResolveResult *instruction = ir_build_instruction<IrInstructionResolveResult>(irb, scope, source_node);
4570 IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node);
36404571 instruction->result_loc = result_loc;
36414572 instruction->ty = ty;
36424573
......@@ -3645,25 +4576,25 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN
36454576 return &instruction->base;
36464577}
36474578
3648static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNode *source_node,
4579static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
36494580 ResultLoc *result_loc)
36504581{
3651 IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node);
4582 IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node);
36524583 instruction->result_loc = result_loc;
36534584
36544585 return &instruction->base;
36554586}
36564587
3657static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3658 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);
4588static IrInstSrc *ir_build_opaque_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
4589 IrInstSrcOpaqueType *instruction = ir_build_instruction<IrInstSrcOpaqueType>(irb, scope, source_node);
36594590
36604591 return &instruction->base;
36614592}
36624593
3663static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node,
3664 IrInstruction *align_bytes)
4594static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4595 IrInstSrc *align_bytes)
36654596{
3666 IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node);
4597 IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node);
36674598 instruction->align_bytes = align_bytes;
36684599
36694600 ir_ref_instruction(align_bytes, irb->current_basic_block);
......@@ -3671,10 +4602,10 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast
36714602 return &instruction->base;
36724603}
36734604
3674static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3675 IrInstruction *fn_type, IrInstruction *arg_index, bool allow_var)
4605static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4606 IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var)
36764607{
3677 IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node);
4608 IrInstSrcArgType *instruction = ir_build_instruction<IrInstSrcArgType>(irb, scope, source_node);
36784609 instruction->fn_type = fn_type;
36794610 instruction->arg_index = arg_index;
36804611 instruction->allow_var = allow_var;
......@@ -3685,17 +4616,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s
36854616 return &instruction->base;
36864617}
36874618
3688static IrInstruction *ir_build_error_return_trace(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstructionErrorReturnTrace::Optional optional) {
3689 IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node);
3690 instruction->optional = optional;
4619static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4620 IrInstErrorReturnTraceOptional optional)
4621{
4622 IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(irb, scope, source_node);
4623 inst->optional = optional;
4624
4625 return &inst->base;
4626}
4627
4628static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4629 IrInstErrorReturnTraceOptional optional, ZigType *result_type)
4630{
4631 IrInstGenErrorReturnTrace *inst = ir_build_inst_gen<IrInstGenErrorReturnTrace>(&ira->new_irb, scope, source_node);
4632 inst->base.value->type = result_type;
4633 inst->optional = optional;
36914634
3692 return &instruction->base;
4635 return &inst->base;
36934636}
36944637
3695static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode *source_node,
3696 IrInstruction *err_set, IrInstruction *payload)
4638static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4639 IrInstSrc *err_set, IrInstSrc *payload)
36974640{
3698 IrInstructionErrorUnion *instruction = ir_build_instruction<IrInstructionErrorUnion>(irb, scope, source_node);
4641 IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node);
36994642 instruction->err_set = err_set;
37004643 instruction->payload = payload;
37014644
......@@ -3705,85 +4648,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode
37054648 return &instruction->base;
37064649}
37074650
3708static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node,
3709 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand,
3710 IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering)
4651static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4652 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand,
4653 IrInstSrc *ordering)
37114654{
3712 IrInstructionAtomicRmw *instruction = ir_build_instruction<IrInstructionAtomicRmw>(irb, scope, source_node);
4655 IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node);
37134656 instruction->operand_type = operand_type;
37144657 instruction->ptr = ptr;
3715 instruction->op = op;
3716 instruction->operand = operand;
4658 instruction->op = op;
4659 instruction->operand = operand;
4660 instruction->ordering = ordering;
4661
4662 ir_ref_instruction(operand_type, irb->current_basic_block);
4663 ir_ref_instruction(ptr, irb->current_basic_block);
4664 ir_ref_instruction(op, irb->current_basic_block);
4665 ir_ref_instruction(operand, irb->current_basic_block);
4666 ir_ref_instruction(ordering, irb->current_basic_block);
4667
4668 return &instruction->base;
4669}
4670
4671static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,
4672 IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type)
4673{
4674 IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node);
4675 instruction->base.value->type = operand_type;
4676 instruction->ptr = ptr;
4677 instruction->op = op;
4678 instruction->operand = operand;
4679 instruction->ordering = ordering;
4680
4681 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
4682 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
4683
4684 return &instruction->base;
4685}
4686
4687static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4688 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering)
4689{
4690 IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node);
4691 instruction->operand_type = operand_type;
4692 instruction->ptr = ptr;
4693 instruction->ordering = ordering;
4694
4695 ir_ref_instruction(operand_type, irb->current_basic_block);
4696 ir_ref_instruction(ptr, irb->current_basic_block);
4697 ir_ref_instruction(ordering, irb->current_basic_block);
4698
4699 return &instruction->base;
4700}
4701
4702static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,
4703 IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type)
4704{
4705 IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb,
4706 source_instr->scope, source_instr->source_node);
4707 instruction->base.value->type = operand_type;
4708 instruction->ptr = ptr;
37174709 instruction->ordering = ordering;
3718 instruction->resolved_op = resolved_op;
3719 instruction->resolved_ordering = resolved_ordering;
37204710
3721 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);
3722 ir_ref_instruction(ptr, irb->current_basic_block);
3723 if (op != nullptr) ir_ref_instruction(op, irb->current_basic_block);
3724 ir_ref_instruction(operand, irb->current_basic_block);
3725 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);
4711 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
37264712
37274713 return &instruction->base;
37284714}
37294715
3730static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode *source_node,
3731 IrInstruction *operand_type, IrInstruction *ptr,
3732 IrInstruction *ordering, AtomicOrder resolved_ordering)
4716static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4717 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering)
37334718{
3734 IrInstructionAtomicLoad *instruction = ir_build_instruction<IrInstructionAtomicLoad>(irb, scope, source_node);
4719 IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node);
37354720 instruction->operand_type = operand_type;
37364721 instruction->ptr = ptr;
4722 instruction->value = value;
37374723 instruction->ordering = ordering;
3738 instruction->resolved_ordering = resolved_ordering;
37394724
3740 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);
4725 ir_ref_instruction(operand_type, irb->current_basic_block);
37414726 ir_ref_instruction(ptr, irb->current_basic_block);
3742 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);
4727 ir_ref_instruction(value, irb->current_basic_block);
4728 ir_ref_instruction(ordering, irb->current_basic_block);
37434729
37444730 return &instruction->base;
37454731}
37464732
3747static IrInstruction *ir_build_atomic_store(IrBuilder *irb, Scope *scope, AstNode *source_node,
3748 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *value,
3749 IrInstruction *ordering, AtomicOrder resolved_ordering)
4733static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr,
4734 IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering)
37504735{
3751 IrInstructionAtomicStore *instruction = ir_build_instruction<IrInstructionAtomicStore>(irb, scope, source_node);
3752 instruction->operand_type = operand_type;
4736 IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb,
4737 source_instr->scope, source_instr->source_node);
37534738 instruction->ptr = ptr;
37544739 instruction->value = value;
37554740 instruction->ordering = ordering;
3756 instruction->resolved_ordering = resolved_ordering;
37574741
3758 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);
3759 ir_ref_instruction(ptr, irb->current_basic_block);
3760 ir_ref_instruction(value, irb->current_basic_block);
3761 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);
4742 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
4743 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
37624744
37634745 return &instruction->base;
37644746}
37654747
3766static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3767 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);
3768 return &instruction->base;
4748static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
4749 IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(irb, scope, source_node);
4750 return &inst->base;
4751}
4752
4753static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) {
4754 IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb,
4755 source_instr->scope, source_instr->source_node);
4756 return &inst->base;
37694757}
37704758
3771static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3772 IrInstruction *value, ResultLocReturn *result_loc_ret)
4759static IrInstSrc *ir_build_add_implicit_return_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4760 IrInstSrc *value, ResultLocReturn *result_loc_ret)
37734761{
3774 IrInstructionAddImplicitReturnType *instruction = ir_build_instruction<IrInstructionAddImplicitReturnType>(irb, scope, source_node);
3775 instruction->value = value;
3776 instruction->result_loc_ret = result_loc_ret;
4762 IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node);
4763 inst->value = value;
4764 inst->result_loc_ret = result_loc_ret;
37774765
37784766 ir_ref_instruction(value, irb->current_basic_block);
37794767
3780 return &instruction->base;
4768 return &inst->base;
37814769}
37824770
3783static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,
3784 IrInstruction *container, IrInstruction *name)
4771static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4772 IrInstSrc *container, IrInstSrc *name)
37854773{
3786 IrInstructionHasDecl *instruction = ir_build_instruction<IrInstructionHasDecl>(irb, scope, source_node);
4774 IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node);
37874775 instruction->container = container;
37884776 instruction->name = name;
37894777
......@@ -3793,17 +4781,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s
37934781 return &instruction->base;
37944782}
37954783
3796static IrInstruction *ir_build_undeclared_identifier(IrBuilder *irb, Scope *scope, AstNode *source_node,
3797 Buf *name)
3798{
3799 IrInstructionUndeclaredIdent *instruction = ir_build_instruction<IrInstructionUndeclaredIdent>(irb, scope, source_node);
4784static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
4785 IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node);
38004786 instruction->name = name;
38014787
38024788 return &instruction->base;
38034789}
38044790
3805static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) {
3806 IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node);
4791static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) {
4792 IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node);
38074793 instruction->scope_is_comptime = scope_is_comptime;
38084794 instruction->is_comptime = is_comptime;
38094795
......@@ -3813,10 +4799,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope,
38134799 return &instruction->base;
38144800}
38154801
3816static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *scope, AstNode *source_node,
3817 IrInstruction *union_type, IrInstruction *field_name, IrInstruction *field_result_loc, IrInstruction *result_loc)
4802static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4803 IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc)
38184804{
3819 IrInstructionUnionInitNamedField *instruction = ir_build_instruction<IrInstructionUnionInitNamedField>(irb, scope, source_node);
4805 IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node);
38204806 instruction->union_type = union_type;
38214807 instruction->field_name = field_name;
38224808 instruction->field_result_loc = field_result_loc;
......@@ -3831,79 +4817,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco
38314817}
38324818
38334819
3834static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction,
3835 ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc)
4820static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction,
4821 ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc)
38364822{
3837 IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb,
4823 IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb,
38384824 source_instruction->scope, source_instruction->source_node);
38394825 instruction->base.value->type = result_type;
38404826 instruction->vector = vector;
38414827 instruction->result_loc = result_loc;
38424828
3843 ir_ref_instruction(vector, ira->new_irb.current_basic_block);
3844 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
4829 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
4830 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38454831
38464832 return &instruction->base;
38474833}
38484834
3849static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instruction,
3850 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)
4835static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction,
4836 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
38514837{
3852 IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb,
4838 IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb,
38534839 source_instruction->scope, source_instruction->source_node);
38544840 instruction->base.value->type = result_type;
38554841 instruction->operand = operand;
38564842 instruction->result_loc = result_loc;
38574843
3858 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
3859 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
4844 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
4845 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38604846
38614847 return &instruction->base;
38624848}
38634849
3864static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *source_instruction,
3865 IrInstruction *array, ZigType *result_type)
4850static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction,
4851 IrInstGen *array, ZigType *result_type)
38664852{
3867 IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb,
4853 IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb,
38684854 source_instruction->scope, source_instruction->source_node);
38694855 instruction->base.value->type = result_type;
38704856 instruction->array = array;
38714857
3872 ir_ref_instruction(array, ira->new_irb.current_basic_block);
4858 ir_ref_inst_gen(array, ira->new_irb.current_basic_block);
38734859
38744860 return &instruction->base;
38754861}
38764862
3877static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source_instruction,
3878 IrInstruction *target)
4863static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction,
4864 IrInstGen *target)
38794865{
3880 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,
4866 IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb,
38814867 source_instruction->scope, source_instruction->source_node);
38824868 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
38834869 instruction->target = target;
38844870
3885 ir_ref_instruction(target, ira->new_irb.current_basic_block);
4871 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
38864872
38874873 return &instruction->base;
38884874}
38894875
3890static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *source_instruction,
3891 IrInstruction *target)
4876static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction,
4877 IrInstGen *target)
38924878{
3893 IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb,
4879 IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb,
38944880 source_instruction->scope, source_instruction->source_node);
38954881 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
38964882 instruction->target = target;
38974883
3898 ir_ref_instruction(target, ira->new_irb.current_basic_block);
4884 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
38994885
39004886 return &instruction->base;
39014887}
39024888
3903static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3904 IrInstruction *align, const char *name_hint, IrInstruction *is_comptime)
4889static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4890 IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime)
39054891{
3906 IrInstructionAllocaSrc *instruction = ir_build_instruction<IrInstructionAllocaSrc>(irb, scope, source_node);
4892 IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node);
39074893 instruction->base.is_gen = true;
39084894 instruction->align = align;
39094895 instruction->name_hint = name_hint;
......@@ -3915,10 +4901,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode
39154901 return &instruction->base;
39164902}
39174903
3918static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction *source_instruction,
4904static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction,
39194905 uint32_t align, const char *name_hint)
39204906{
3921 IrInstructionAllocaGen *instruction = ir_create_instruction<IrInstructionAllocaGen>(&ira->new_irb,
4907 IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb,
39224908 source_instruction->scope, source_instruction->source_node);
39234909 instruction->align = align;
39244910 instruction->name_hint = name_hint;
......@@ -3926,10 +4912,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction
39264912 return instruction;
39274913}
39284914
3929static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
3930 IrInstruction *value, ResultLoc *result_loc)
4915static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4916 IrInstSrc *value, ResultLoc *result_loc)
39314917{
3932 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);
4918 IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node);
39334919 instruction->base.is_gen = true;
39344920 instruction->value = value;
39354921 instruction->result_loc = result_loc;
......@@ -3939,29 +4925,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s
39394925 return &instruction->base;
39404926}
39414927
3942static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3943 IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node);
3944 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
4928static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
4929 return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node);
4930}
39454931
3946 return instruction;
4932static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) {
4933 IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb,
4934 source_instr->scope, source_instr->source_node);
4935 return &inst->base;
39474936}
39484937
3949static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstNode *source_node,
3950 IrInstructionSuspendBegin *begin)
4938static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4939 IrInstSrcSuspendBegin *begin)
39514940{
3952 IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node);
3953 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
3954 instruction->begin = begin;
4941 IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node);
4942 inst->begin = begin;
39554943
39564944 ir_ref_instruction(&begin->base, irb->current_basic_block);
39574945
3958 return &instruction->base;
4946 return &inst->base;
4947}
4948
4949static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) {
4950 IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb,
4951 source_instr->scope, source_instr->source_node);
4952 inst->begin = begin;
4953
4954 ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block);
4955
4956 return &inst->base;
39594957}
39604958
3961static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3962 IrInstruction *frame, ResultLoc *result_loc)
4959static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4960 IrInstSrc *frame, ResultLoc *result_loc)
39634961{
3964 IrInstructionAwaitSrc *instruction = ir_build_instruction<IrInstructionAwaitSrc>(irb, scope, source_node);
4962 IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node);
39654963 instruction->frame = frame;
39664964 instruction->result_loc = result_loc;
39674965
......@@ -3970,24 +4968,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *
39704968 return &instruction->base;
39714969}
39724970
3973static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3974 IrInstruction *frame, ZigType *result_type, IrInstruction *result_loc)
4971static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction,
4972 IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc)
39754973{
3976 IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb,
4974 IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,
39774975 source_instruction->scope, source_instruction->source_node);
39784976 instruction->base.value->type = result_type;
39794977 instruction->frame = frame;
39804978 instruction->result_loc = result_loc;
39814979
3982 ir_ref_instruction(frame, ira->new_irb.current_basic_block);
3983 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
4980 ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
4981 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
39844982
39854983 return instruction;
39864984}
39874985
3988static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {
3989 IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node);
3990 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
4986static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) {
4987 IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node);
39914988 instruction->frame = frame;
39924989
39934990 ir_ref_instruction(frame, irb->current_basic_block);
......@@ -3995,12 +4992,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou
39954992 return &instruction->base;
39964993}
39974994
3998static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scope, AstNode *source_node,
3999 IrInstruction *operand, SpillId spill_id)
4995static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) {
4996 IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb,
4997 source_instr->scope, source_instr->source_node);
4998 instruction->frame = frame;
4999
5000 ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
5001
5002 return &instruction->base;
5003}
5004
5005static IrInstSrcSpillBegin *ir_build_spill_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5006 IrInstSrc *operand, SpillId spill_id)
40005007{
4001 IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node);
4002 instruction->base.value->special = ConstValSpecialStatic;
4003 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
5008 IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node);
40045009 instruction->operand = operand;
40055010 instruction->spill_id = spill_id;
40065011
......@@ -4009,10 +5014,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop
40095014 return instruction;
40105015}
40115016
4012static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *source_node,
4013 IrInstructionSpillBegin *begin)
5017static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
5018 SpillId spill_id)
5019{
5020 IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb,
5021 source_instr->scope, source_instr->source_node);
5022 instruction->operand = operand;
5023 instruction->spill_id = spill_id;
5024
5025 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
5026
5027 return &instruction->base;
5028}
5029
5030static IrInstSrc *ir_build_spill_end_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5031 IrInstSrcSpillBegin *begin)
40145032{
4015 IrInstructionSpillEnd *instruction = ir_build_instruction<IrInstructionSpillEnd>(irb, scope, source_node);
5033 IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node);
40165034 instruction->begin = begin;
40175035
40185036 ir_ref_instruction(&begin->base, irb->current_basic_block);
......@@ -4020,22 +5038,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *
40205038 return &instruction->base;
40215039}
40225040
4023static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction *source_instruction,
4024 IrInstruction *vector, IrInstruction *index)
5041static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin,
5042 ZigType *result_type)
5043{
5044 IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb,
5045 source_instr->scope, source_instr->source_node);
5046 instruction->base.value->type = result_type;
5047 instruction->begin = begin;
5048
5049 ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block);
5050
5051 return &instruction->base;
5052}
5053
5054static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction,
5055 IrInstGen *vector, IrInstGen *index)
40255056{
4026 IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>(
5057 IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>(
40275058 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
40285059 instruction->base.value->type = vector->value->type->data.vector.elem_type;
40295060 instruction->vector = vector;
40305061 instruction->index = index;
40315062
4032 ir_ref_instruction(vector, ira->new_irb.current_basic_block);
4033 ir_ref_instruction(index, ira->new_irb.current_basic_block);
5063 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
5064 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
40345065
40355066 return &instruction->base;
40365067}
40375068
4038static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
5069static void ir_count_defers(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
40395070 results[ReturnKindUnconditional] = 0;
40405071 results[ReturnKindError] = 0;
40415072
......@@ -4072,12 +5103,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
40725103 }
40735104}
40745105
4075static IrInstruction *ir_mark_gen(IrInstruction *instruction) {
5106static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) {
40765107 instruction->is_gen = true;
40775108 return instruction;
40785109}
40795110
4080static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) {
5111static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) {
40815112 Scope *scope = inner_scope;
40825113 bool is_noreturn = false;
40835114 while (scope != outer_scope) {
......@@ -4094,11 +5125,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
40945125 {
40955126 AstNode *defer_expr_node = defer_node->data.defer.expr;
40965127 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
4097 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
4098 if (defer_expr_value != irb->codegen->invalid_instruction) {
4099 if (defer_expr_value->value->type != nullptr &&
4100 defer_expr_value->value->type->id == ZigTypeIdUnreachable)
4101 {
5128 IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
5129 if (defer_expr_value != irb->codegen->invalid_inst_src) {
5130 if (defer_expr_value->is_noreturn) {
41025131 is_noreturn = true;
41035132 } else {
41045133 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node,
......@@ -4130,13 +5159,17 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
41305159 return is_noreturn;
41315160}
41325161
4133static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) {
5162static void ir_set_cursor_at_end_gen(IrBuilderGen *irb, IrBasicBlockGen *basic_block) {
41345163 assert(basic_block);
5164 irb->current_basic_block = basic_block;
5165}
41355166
5167static void ir_set_cursor_at_end(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
5168 assert(basic_block);
41365169 irb->current_basic_block = basic_block;
41375170}
41385171
4139static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) {
5172static void ir_set_cursor_at_end_and_append_block(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
41405173 basic_block->index = irb->exec->basic_block_list.length;
41415174 irb->exec->basic_block_list.append(basic_block);
41425175 ir_set_cursor_at_end(irb, basic_block);
......@@ -4166,13 +5199,13 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
41665199 return nullptr;
41675200}
41685201
4169static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
5202static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
41705203 assert(node->type == NodeTypeReturnExpr);
41715204
41725205 ZigFn *fn_entry = exec_fn_entry(irb->exec);
41735206 if (!fn_entry) {
41745207 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));
4175 return irb->codegen->invalid_instruction;
5208 return irb->codegen->invalid_inst_src;
41765209 }
41775210
41785211 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);
......@@ -4181,7 +5214,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
41815214 add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression"));
41825215 scope_defer_expr->reported_err = true;
41835216 }
4184 return irb->codegen->invalid_instruction;
5217 return irb->codegen->invalid_inst_src;
41855218 }
41865219
41875220 Scope *outer_scope = irb->exec->begin_scope;
......@@ -4194,15 +5227,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
41945227 result_loc_ret->base.id = ResultLocIdReturn;
41955228 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
41965229
4197 IrInstruction *return_value;
5230 IrInstSrc *return_value;
41985231 if (expr_node) {
41995232 // Temporarily set this so that if we return a type it gets the name of the function
42005233 ZigFn *prev_name_fn = irb->exec->name_fn;
42015234 irb->exec->name_fn = exec_fn_entry(irb->exec);
42025235 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);
42035236 irb->exec->name_fn = prev_name_fn;
4204 if (return_value == irb->codegen->invalid_instruction)
4205 return irb->codegen->invalid_instruction;
5237 if (return_value == irb->codegen->invalid_inst_src)
5238 return irb->codegen->invalid_inst_src;
42065239 } else {
42075240 return_value = ir_build_const_void(irb, scope, node);
42085241 }
......@@ -4215,22 +5248,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42155248 if (!have_err_defers && !irb->codegen->have_err_ret_tracing) {
42165249 // only generate unconditional defers
42175250 ir_gen_defers_for_block(irb, scope, outer_scope, false);
4218 IrInstruction *result = ir_build_return(irb, scope, node, return_value);
5251 IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value);
42195252 result_loc_ret->base.source_instruction = result;
42205253 return result;
42215254 }
42225255 bool should_inline = ir_should_inline(irb->exec, scope);
42235256
4224 IrBasicBlock *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");
4225 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");
5257 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");
5258 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");
42265259
42275260 if (!have_err_defers) {
42285261 ir_gen_defers_for_block(irb, scope, outer_scope, false);
42295262 }
42305263
4231 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true);
5264 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true);
42325265
4233 IrInstruction *is_comptime;
5266 IrInstSrc *is_comptime;
42345267 if (should_inline) {
42355268 is_comptime = ir_build_const_bool(irb, scope, node, should_inline);
42365269 } else {
......@@ -4238,14 +5271,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42385271 }
42395272
42405273 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime));
4241 IrBasicBlock *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");
5274 IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");
42425275
42435276 ir_set_cursor_at_end_and_append_block(irb, err_block);
42445277 if (have_err_defers) {
42455278 ir_gen_defers_for_block(irb, scope, outer_scope, true);
42465279 }
42475280 if (irb->codegen->have_err_ret_tracing && !should_inline) {
4248 ir_build_save_err_ret_addr(irb, scope, node);
5281 ir_build_save_err_ret_addr_src(irb, scope, node);
42495282 }
42505283 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
42515284
......@@ -4256,21 +5289,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42565289 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
42575290
42585291 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);
4259 IrInstruction *result = ir_build_return(irb, scope, node, return_value);
5292 IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value);
42605293 result_loc_ret->base.source_instruction = result;
42615294 return result;
42625295 }
42635296 case ReturnKindError:
42645297 {
42655298 assert(expr_node);
4266 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
4267 if (err_union_ptr == irb->codegen->invalid_instruction)
4268 return irb->codegen->invalid_instruction;
4269 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);
4270
4271 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
4272 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
4273 IrInstruction *is_comptime;
5299 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
5300 if (err_union_ptr == irb->codegen->invalid_inst_src)
5301 return irb->codegen->invalid_inst_src;
5302 IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);
5303
5304 IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
5305 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
5306 IrInstSrc *is_comptime;
42745307 bool should_inline = ir_should_inline(irb->exec, scope);
42755308 if (should_inline) {
42765309 is_comptime = ir_build_const_bool(irb, scope, node, true);
......@@ -4280,10 +5313,10 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42805313 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime));
42815314
42825315 ir_set_cursor_at_end_and_append_block(irb, return_block);
4283 IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr);
4284 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
5316 IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr);
5317 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
42855318 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
4286 IrInstructionSpillBegin *spill_begin = ir_build_spill_begin(irb, scope, node, err_val,
5319 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,
42875320 SpillIdRetErrCode);
42885321 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
42895322 result_loc_ret->base.id = ResultLocIdReturn;
......@@ -4291,15 +5324,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42915324 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
42925325 if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) {
42935326 if (irb->codegen->have_err_ret_tracing && !should_inline) {
4294 ir_build_save_err_ret_addr(irb, scope, node);
5327 ir_build_save_err_ret_addr_src(irb, scope, node);
42955328 }
4296 err_val = ir_build_spill_end(irb, scope, node, spill_begin);
4297 IrInstruction *ret_inst = ir_build_return(irb, scope, node, err_val);
5329 err_val = ir_build_spill_end_src(irb, scope, node, spill_begin);
5330 IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val);
42985331 result_loc_ret->base.source_instruction = ret_inst;
42995332 }
43005333
43015334 ir_set_cursor_at_end_and_append_block(irb, continue_block);
4302 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false, false);
5335 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, scope, node, err_union_ptr, false, false);
43035336 if (lval == LValPtr)
43045337 return unwrapped_ptr;
43055338 else
......@@ -4310,7 +5343,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
43105343}
43115344
43125345static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
4313 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,
5346 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime,
43145347 bool skip_name_check)
43155348{
43165349 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");
......@@ -4322,7 +5355,7 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
43225355 variable_entry->const_value = create_const_vals(1);
43235356
43245357 if (is_comptime != nullptr) {
4325 is_comptime->ref_count += 1;
5358 is_comptime->base.ref_count += 1;
43265359 }
43275360
43285361 if (name) {
......@@ -4372,8 +5405,8 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
43725405
43735406// Set name to nullptr to make the variable anonymous (not visible to programmer).
43745407// After you call this function var->child_scope has the variable in scope
4375static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
4376 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)
5408static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name,
5409 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime)
43775410{
43785411 bool is_underscored = name ? buf_eql_str(name, "_") : false;
43795412 ZigVar *var = create_local_var(irb->codegen, node, scope,
......@@ -4396,13 +5429,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
43965429 return result;
43975430}
43985431
4399static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node, LVal lval,
5432static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *block_node, LVal lval,
44005433 ResultLoc *result_loc)
44015434{
44025435 assert(block_node->type == NodeTypeBlock);
44035436
4404 ZigList<IrInstruction *> incoming_values = {0};
4405 ZigList<IrBasicBlock *> incoming_blocks = {0};
5437 ZigList<IrInstSrc *> incoming_values = {0};
5438 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
44065439
44075440 ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope);
44085441
......@@ -4438,11 +5471,11 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44385471 }
44395472
44405473 bool is_continuation_unreachable = false;
4441 IrInstruction *noreturn_return_value = nullptr;
5474 IrInstSrc *noreturn_return_value = nullptr;
44425475 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
44435476 AstNode *statement_node = block_node->data.block.statements.at(i);
44445477
4445 IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope);
5478 IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope);
44465479 is_continuation_unreachable = instr_is_unreachable(statement_value);
44475480 if (is_continuation_unreachable) {
44485481 // keep the last noreturn statement value around in case we need to return it
......@@ -4450,15 +5483,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44505483 }
44515484 // This logic must be kept in sync with
44525485 // [STMT_EXPR_TEST_THING] <--- (search this token)
4453 if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_instruction) {
5486 if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_inst_src) {
44545487 // defer starts a new scope
44555488 child_scope = statement_node->data.defer.child_scope;
44565489 assert(child_scope);
4457 } else if (statement_value->id == IrInstructionIdDeclVarSrc) {
5490 } else if (statement_value->id == IrInstSrcIdDeclVar) {
44585491 // variable declarations start a new scope
4459 IrInstructionDeclVarSrc *decl_var_instruction = (IrInstructionDeclVarSrc *)statement_value;
5492 IrInstSrcDeclVar *decl_var_instruction = (IrInstSrcDeclVar *)statement_value;
44605493 child_scope = decl_var_instruction->var->child_scope;
4461 } else if (statement_value != irb->codegen->invalid_instruction && !is_continuation_unreachable) {
5494 } else if (statement_value != irb->codegen->invalid_inst_src && !is_continuation_unreachable) {
44625495 // this statement's value must be void
44635496 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
44645497 }
......@@ -4474,12 +5507,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44745507 scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block;
44755508 }
44765509 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
4477 IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
5510 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
44785511 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
44795512 return ir_expr_wrap(irb, parent_scope, phi, result_loc);
44805513 } else {
44815514 incoming_blocks.append(irb->current_basic_block);
4482 IrInstruction *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node));
5515 IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node));
44835516
44845517 if (scope_block->peer_parent != nullptr) {
44855518 ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent);
......@@ -4499,15 +5532,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44995532 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
45005533 }
45015534
4502 IrInstruction *result;
5535 IrInstSrc *result;
45035536 if (block_node->data.block.name != nullptr) {
45045537 ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime));
45055538 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
4506 IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
5539 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
45075540 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
45085541 result = ir_expr_wrap(irb, parent_scope, phi, result_loc);
45095542 } else {
4510 IrInstruction *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
5543 IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
45115544 result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc);
45125545 }
45135546 if (!is_return_from_fn)
......@@ -4518,30 +5551,30 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
45185551
45195552 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));
45205553 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
4521 return ir_mark_gen(ir_build_return(irb, child_scope, result->source_node, result));
5554 return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result));
45225555}
45235556
4524static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
5557static IrInstSrc *ir_gen_bin_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
45255558 Scope *inner_scope = scope;
45265559 if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) {
45275560 inner_scope = create_comptime_scope(irb->codegen, node, scope);
45285561 }
45295562
4530 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);
4531 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope);
5563 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);
5564 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope);
45325565
4533 if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction)
4534 return irb->codegen->invalid_instruction;
5566 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
5567 return irb->codegen->invalid_inst_src;
45355568
45365569 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
45375570}
45385571
4539static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {
4540 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4541 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5572static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5573 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
5574 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
45425575
4543 if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction)
4544 return irb->codegen->invalid_instruction;
5576 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
5577 return irb->codegen->invalid_inst_src;
45455578
45465579 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr
45475580 Buf bare_name = BUF_INIT;
......@@ -4550,10 +5583,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod
45505583 return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name);
45515584}
45525585
4553static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
4554 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4555 if (lvalue == irb->codegen->invalid_instruction)
4556 return irb->codegen->invalid_instruction;
5586static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5587 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
5588 if (lvalue == irb->codegen->invalid_inst_src)
5589 return irb->codegen->invalid_inst_src;
45575590
45585591 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");
45595592 result_loc_inst->base.id = ResultLocIdInstruction;
......@@ -4561,49 +5594,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)
45615594 ir_ref_instruction(lvalue, irb->current_basic_block);
45625595 ir_build_reset_result(irb, scope, node, &result_loc_inst->base);
45635596
4564 IrInstruction *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone,
5597 IrInstSrc *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone,
45655598 &result_loc_inst->base);
4566 if (rvalue == irb->codegen->invalid_instruction)
4567 return irb->codegen->invalid_instruction;
5599 if (rvalue == irb->codegen->invalid_inst_src)
5600 return irb->codegen->invalid_inst_src;
45685601
45695602 return ir_build_const_void(irb, scope, node);
45705603}
45715604
4572static IrInstruction *ir_gen_assign_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {
4573 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4574 if (lvalue == irb->codegen->invalid_instruction)
5605static IrInstSrc *ir_gen_assign_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5606 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
5607 if (lvalue == irb->codegen->invalid_inst_src)
45755608 return lvalue;
4576 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
4577 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4578 if (op2 == irb->codegen->invalid_instruction)
5609 IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
5610 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5611 if (op2 == irb->codegen->invalid_inst_src)
45795612 return op2;
4580 IrInstruction *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr);
5613 IrInstSrc *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr);
45815614 ir_build_store_ptr(irb, scope, node, lvalue, result);
45825615 return ir_build_const_void(irb, scope, node);
45835616}
45845617
4585static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
4586 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4587 if (lvalue == irb->codegen->invalid_instruction)
5618static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
5619 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
5620 if (lvalue == irb->codegen->invalid_inst_src)
45885621 return lvalue;
4589 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
4590 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4591 if (op2 == irb->codegen->invalid_instruction)
5622 IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
5623 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5624 if (op2 == irb->codegen->invalid_inst_src)
45925625 return op2;
4593 IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
5626 IrInstSrc *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
45945627 ir_build_store_ptr(irb, scope, node, lvalue, result);
45955628 return ir_build_const_void(irb, scope, node);
45965629}
45975630
4598static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node) {
5631static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
45995632 assert(node->type == NodeTypeBinOpExpr);
46005633
4601 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4602 if (val1 == irb->codegen->invalid_instruction)
4603 return irb->codegen->invalid_instruction;
4604 IrBasicBlock *post_val1_block = irb->current_basic_block;
5634 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
5635 if (val1 == irb->codegen->invalid_inst_src)
5636 return irb->codegen->invalid_inst_src;
5637 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46055638
4606 IrInstruction *is_comptime;
5639 IrInstSrc *is_comptime;
46075640 if (ir_should_inline(irb->exec, scope)) {
46085641 is_comptime = ir_build_const_bool(irb, scope, node, true);
46095642 } else {
......@@ -4611,41 +5644,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node
46115644 }
46125645
46135646 // block for when val1 == false
4614 IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse");
5647 IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse");
46155648 // block for when val1 == true (don't even evaluate the second part)
4616 IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue");
5649 IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue");
46175650
46185651 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46195652
46205653 ir_set_cursor_at_end_and_append_block(irb, false_block);
4621 IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4622 if (val2 == irb->codegen->invalid_instruction)
4623 return irb->codegen->invalid_instruction;
4624 IrBasicBlock *post_val2_block = irb->current_basic_block;
5654 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5655 if (val2 == irb->codegen->invalid_inst_src)
5656 return irb->codegen->invalid_inst_src;
5657 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46255658
46265659 ir_build_br(irb, scope, node, true_block, is_comptime);
46275660
46285661 ir_set_cursor_at_end_and_append_block(irb, true_block);
46295662
4630 IrInstruction **incoming_values = allocate<IrInstruction *>(2, "IrInstruction *");
5663 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2, "IrInstSrc *");
46315664 incoming_values[0] = val1;
46325665 incoming_values[1] = val2;
4633 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
5666 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
46345667 incoming_blocks[0] = post_val1_block;
46355668 incoming_blocks[1] = post_val2_block;
46365669
46375670 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
46385671}
46395672
4640static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *node) {
5673static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
46415674 assert(node->type == NodeTypeBinOpExpr);
46425675
4643 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4644 if (val1 == irb->codegen->invalid_instruction)
4645 return irb->codegen->invalid_instruction;
4646 IrBasicBlock *post_val1_block = irb->current_basic_block;
5676 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
5677 if (val1 == irb->codegen->invalid_inst_src)
5678 return irb->codegen->invalid_inst_src;
5679 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46475680
4648 IrInstruction *is_comptime;
5681 IrInstSrc *is_comptime;
46495682 if (ir_should_inline(irb->exec, scope)) {
46505683 is_comptime = ir_build_const_bool(irb, scope, node, true);
46515684 } else {
......@@ -4653,34 +5686,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod
46535686 }
46545687
46555688 // block for when val1 == true
4656 IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue");
5689 IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue");
46575690 // block for when val1 == false (don't even evaluate the second part)
4658 IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse");
5691 IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse");
46595692
46605693 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46615694
46625695 ir_set_cursor_at_end_and_append_block(irb, true_block);
4663 IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4664 if (val2 == irb->codegen->invalid_instruction)
4665 return irb->codegen->invalid_instruction;
4666 IrBasicBlock *post_val2_block = irb->current_basic_block;
5696 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5697 if (val2 == irb->codegen->invalid_inst_src)
5698 return irb->codegen->invalid_inst_src;
5699 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46675700
46685701 ir_build_br(irb, scope, node, false_block, is_comptime);
46695702
46705703 ir_set_cursor_at_end_and_append_block(irb, false_block);
46715704
4672 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
5705 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
46735706 incoming_values[0] = val1;
46745707 incoming_values[1] = val2;
4675 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
5708 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
46765709 incoming_blocks[0] = post_val1_block;
46775710 incoming_blocks[1] = post_val2_block;
46785711
46795712 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
46805713}
46815714
4682static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,
4683 IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)
5715static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
5716 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
46845717{
46855718 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
46865719 peer_parent->base.id = ResultLocIdPeerParent;
......@@ -4690,17 +5723,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction
46905723 peer_parent->is_comptime = is_comptime;
46915724 peer_parent->parent = parent;
46925725
4693 IrInstruction *popped_inst = irb->current_basic_block->instruction_list.pop();
4694 ir_assert(popped_inst == cond_br_inst, cond_br_inst);
5726 IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop();
5727 ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base);
46955728
4696 ir_build_reset_result(irb, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base);
5729 ir_build_reset_result(irb, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base);
46975730 irb->current_basic_block->instruction_list.append(popped_inst);
46985731
46995732 return peer_parent;
47005733}
47015734
4702static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,
4703 IrBasicBlock *else_block, IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)
5735static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
5736 IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
47045737{
47055738 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime);
47065739
......@@ -4713,7 +5746,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstr
47135746 return peer_parent;
47145747}
47155748
4716static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,
5749static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
47175750 ResultLoc *result_loc)
47185751{
47195752 assert(node->type == NodeTypeBinOpExpr);
......@@ -4721,73 +5754,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode
47215754 AstNode *op1_node = node->data.bin_op_expr.op1;
47225755 AstNode *op2_node = node->data.bin_op_expr.op2;
47235756
4724 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
4725 if (maybe_ptr == irb->codegen->invalid_instruction)
4726 return irb->codegen->invalid_instruction;
5757 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
5758 if (maybe_ptr == irb->codegen->invalid_inst_src)
5759 return irb->codegen->invalid_inst_src;
47275760
4728 IrInstruction *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);
4729 IrInstruction *is_non_null = ir_build_test_nonnull(irb, parent_scope, node, maybe_val);
5761 IrInstSrc *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);
5762 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, parent_scope, node, maybe_val);
47305763
4731 IrInstruction *is_comptime;
5764 IrInstSrc *is_comptime;
47325765 if (ir_should_inline(irb->exec, parent_scope)) {
47335766 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
47345767 } else {
47355768 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);
47365769 }
47375770
4738 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
4739 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
4740 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");
4741 IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
5771 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
5772 IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
5773 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");
5774 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
47425775
47435776 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block,
47445777 result_loc, is_comptime);
47455778
47465779 ir_set_cursor_at_end_and_append_block(irb, null_block);
4747 IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,
5780 IrInstSrc *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,
47485781 &peer_parent->peers.at(0)->base);
4749 if (null_result == irb->codegen->invalid_instruction)
4750 return irb->codegen->invalid_instruction;
4751 IrBasicBlock *after_null_block = irb->current_basic_block;
5782 if (null_result == irb->codegen->invalid_inst_src)
5783 return irb->codegen->invalid_inst_src;
5784 IrBasicBlockSrc *after_null_block = irb->current_basic_block;
47525785 if (!instr_is_unreachable(null_result))
47535786 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
47545787
47555788 ir_set_cursor_at_end_and_append_block(irb, ok_block);
4756 IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false);
4757 IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
5789 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false);
5790 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
47585791 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
4759 IrBasicBlock *after_ok_block = irb->current_basic_block;
5792 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
47605793 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
47615794
47625795 ir_set_cursor_at_end_and_append_block(irb, end_block);
4763 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
5796 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
47645797 incoming_values[0] = null_result;
47655798 incoming_values[1] = unwrapped_payload;
4766 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
5799 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
47675800 incoming_blocks[0] = after_null_block;
47685801 incoming_blocks[1] = after_ok_block;
4769 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
5802 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
47705803 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
47715804}
47725805
4773static IrInstruction *ir_gen_error_union(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
5806static IrInstSrc *ir_gen_error_union(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
47745807 assert(node->type == NodeTypeBinOpExpr);
47755808
47765809 AstNode *op1_node = node->data.bin_op_expr.op1;
47775810 AstNode *op2_node = node->data.bin_op_expr.op2;
47785811
4779 IrInstruction *err_set = ir_gen_node(irb, op1_node, parent_scope);
4780 if (err_set == irb->codegen->invalid_instruction)
4781 return irb->codegen->invalid_instruction;
5812 IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope);
5813 if (err_set == irb->codegen->invalid_inst_src)
5814 return irb->codegen->invalid_inst_src;
47825815
4783 IrInstruction *payload = ir_gen_node(irb, op2_node, parent_scope);
4784 if (payload == irb->codegen->invalid_instruction)
4785 return irb->codegen->invalid_instruction;
5816 IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope);
5817 if (payload == irb->codegen->invalid_inst_src)
5818 return irb->codegen->invalid_inst_src;
47865819
47875820 return ir_build_error_union(irb, parent_scope, node, err_set, payload);
47885821}
47895822
4790static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
5823static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
47915824 assert(node->type == NodeTypeBinOpExpr);
47925825
47935826 BinOpType bin_op_type = node->data.bin_op_expr.bin_op;
......@@ -4880,30 +5913,30 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,
48805913 zig_unreachable();
48815914}
48825915
4883static IrInstruction *ir_gen_int_lit(IrBuilder *irb, Scope *scope, AstNode *node) {
5916static IrInstSrc *ir_gen_int_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
48845917 assert(node->type == NodeTypeIntLiteral);
48855918
48865919 return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint);
48875920}
48885921
4889static IrInstruction *ir_gen_float_lit(IrBuilder *irb, Scope *scope, AstNode *node) {
5922static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
48905923 assert(node->type == NodeTypeFloatLiteral);
48915924
48925925 if (node->data.float_literal.overflow) {
48935926 add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type"));
4894 return irb->codegen->invalid_instruction;
5927 return irb->codegen->invalid_inst_src;
48955928 }
48965929
48975930 return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat);
48985931}
48995932
4900static IrInstruction *ir_gen_char_lit(IrBuilder *irb, Scope *scope, AstNode *node) {
5933static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
49015934 assert(node->type == NodeTypeCharLiteral);
49025935
49035936 return ir_build_const_uint(irb, scope, node, node->data.char_literal.value);
49045937}
49055938
4906static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
5939static IrInstSrc *ir_gen_null_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
49075940 assert(node->type == NodeTypeNullLiteral);
49085941
49095942 return ir_build_const_null(irb, scope, node);
......@@ -4921,11 +5954,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
49215954 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
49225955 tld_var->base.resolution = TldResolutionInvalid;
49235956 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,
4924 g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid);
5957 g->invalid_inst_gen->value, &tld_var->base, g->builtin_types.entry_invalid);
49255958 scope_decls->decl_table.put(var_name, &tld_var->base);
49265959}
49275960
4928static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
5961static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
49295962 Error err;
49305963 assert(node->type == NodeTypeSymbol);
49315964
......@@ -4933,15 +5966,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49335966
49345967 if (buf_eql_str(variable_name, "_")) {
49355968 if (lval == LValPtr) {
4936 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);
4937 const_instruction->base.value->type = get_pointer_to_type(irb->codegen,
5969 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);
5970 const_instruction->value = create_const_vals(1);
5971 const_instruction->value->type = get_pointer_to_type(irb->codegen,
49385972 irb->codegen->builtin_types.entry_void, false);
4939 const_instruction->base.value->special = ConstValSpecialStatic;
4940 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard;
5973 const_instruction->value->special = ConstValSpecialStatic;
5974 const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard;
49415975 return &const_instruction->base;
49425976 } else {
49435977 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));
4944 return irb->codegen->invalid_instruction;
5978 return irb->codegen->invalid_inst_src;
49455979 }
49465980 }
49475981
......@@ -4951,13 +5985,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49515985 add_node_error(irb->codegen, node,
49525986 buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",
49535987 buf_ptr(variable_name)));
4954 return irb->codegen->invalid_instruction;
5988 return irb->codegen->invalid_inst_src;
49555989 }
49565990 assert(err == ErrorPrimitiveTypeNotFound);
49575991 } else {
4958 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);
5992 IrInstSrc *value = ir_build_const_type(irb, scope, node, primitive_type);
49595993 if (lval == LValPtr) {
4960 return ir_build_ref(irb, scope, node, value, false, false);
5994 return ir_build_ref_src(irb, scope, node, value, false, false);
49615995 } else {
49625996 return ir_expr_wrap(irb, scope, value, result_loc);
49635997 }
......@@ -4966,7 +6000,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49666000 ScopeFnDef *crossed_fndef_scope;
49676001 ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);
49686002 if (var) {
4969 IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);
6003 IrInstSrc *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);
49706004 if (lval == LValPtr) {
49716005 return var_ptr;
49726006 } else {
......@@ -4976,7 +6010,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49766010
49776011 Tld *tld = find_decl(irb->codegen, scope, variable_name);
49786012 if (tld) {
4979 IrInstruction *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval);
6013 IrInstSrc *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval);
49806014 if (lval == LValPtr) {
49816015 return decl_ref;
49826016 } else {
......@@ -4987,50 +6021,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49876021 if (get_container_scope(node->owner)->any_imports_failed) {
49886022 // skip the error message since we had a failing import in this file
49896023 // if an import breaks we don't need redundant undeclared identifier errors
4990 return irb->codegen->invalid_instruction;
6024 return irb->codegen->invalid_inst_src;
49916025 }
49926026
49936027 return ir_build_undeclared_identifier(irb, scope, node, variable_name);
49946028}
49956029
4996static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
6030static IrInstSrc *ir_gen_array_access(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
49976031 ResultLoc *result_loc)
49986032{
49996033 assert(node->type == NodeTypeArrayAccessExpr);
50006034
50016035 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;
5002 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);
5003 if (array_ref_instruction == irb->codegen->invalid_instruction)
6036 IrInstSrc *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);
6037 if (array_ref_instruction == irb->codegen->invalid_inst_src)
50046038 return array_ref_instruction;
50056039
50066040 AstNode *subscript_node = node->data.array_access_expr.subscript;
5007 IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, scope);
5008 if (subscript_instruction == irb->codegen->invalid_instruction)
6041 IrInstSrc *subscript_instruction = ir_gen_node(irb, subscript_node, scope);
6042 if (subscript_instruction == irb->codegen->invalid_inst_src)
50096043 return subscript_instruction;
50106044
5011 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
6045 IrInstSrc *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
50126046 subscript_instruction, true, PtrLenSingle, nullptr);
50136047 if (lval == LValPtr)
50146048 return ptr_instruction;
50156049
5016 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
6050 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
50176051 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
50186052}
50196053
5020static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode *node) {
6054static IrInstSrc *ir_gen_field_access(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
50216055 assert(node->type == NodeTypeFieldAccessExpr);
50226056
50236057 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
50246058 Buf *field_name = node->data.field_access_expr.field_name;
50256059
5026 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
5027 if (container_ref_instruction == irb->codegen->invalid_instruction)
6060 IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
6061 if (container_ref_instruction == irb->codegen->invalid_inst_src)
50286062 return container_ref_instruction;
50296063
50306064 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false);
50316065}
50326066
5033static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) {
6067static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrOverflowOp op) {
50346068 assert(node->type == NodeTypeFnCallExpr);
50356069
50366070 AstNode *type_node = node->data.fn_call_expr.params.at(0);
......@@ -5039,26 +6073,26 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *
50396073 AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3);
50406074
50416075
5042 IrInstruction *type_value = ir_gen_node(irb, type_node, scope);
5043 if (type_value == irb->codegen->invalid_instruction)
5044 return irb->codegen->invalid_instruction;
6076 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
6077 if (type_value == irb->codegen->invalid_inst_src)
6078 return irb->codegen->invalid_inst_src;
50456079
5046 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);
5047 if (op1 == irb->codegen->invalid_instruction)
5048 return irb->codegen->invalid_instruction;
6080 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
6081 if (op1 == irb->codegen->invalid_inst_src)
6082 return irb->codegen->invalid_inst_src;
50496083
5050 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);
5051 if (op2 == irb->codegen->invalid_instruction)
5052 return irb->codegen->invalid_instruction;
6084 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
6085 if (op2 == irb->codegen->invalid_inst_src)
6086 return irb->codegen->invalid_inst_src;
50536087
5054 IrInstruction *result_ptr = ir_gen_node(irb, result_ptr_node, scope);
5055 if (result_ptr == irb->codegen->invalid_instruction)
5056 return irb->codegen->invalid_instruction;
6088 IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope);
6089 if (result_ptr == irb->codegen->invalid_inst_src)
6090 return irb->codegen->invalid_inst_src;
50576091
5058 return ir_build_overflow_op(irb, scope, node, op, type_value, op1, op2, result_ptr, nullptr);
6092 return ir_build_overflow_op_src(irb, scope, node, op, type_value, op1, op2, result_ptr);
50596093}
50606094
5061static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node) {
6095static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
50626096 assert(node->type == NodeTypeFnCallExpr);
50636097
50646098 AstNode *type_node = node->data.fn_call_expr.params.at(0);
......@@ -5066,26 +6100,26 @@ static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node
50666100 AstNode *op2_node = node->data.fn_call_expr.params.at(2);
50676101 AstNode *op3_node = node->data.fn_call_expr.params.at(3);
50686102
5069 IrInstruction *type_value = ir_gen_node(irb, type_node, scope);
5070 if (type_value == irb->codegen->invalid_instruction)
5071 return irb->codegen->invalid_instruction;
6103 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
6104 if (type_value == irb->codegen->invalid_inst_src)
6105 return irb->codegen->invalid_inst_src;
50726106
5073 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);
5074 if (op1 == irb->codegen->invalid_instruction)
5075 return irb->codegen->invalid_instruction;
6107 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
6108 if (op1 == irb->codegen->invalid_inst_src)
6109 return irb->codegen->invalid_inst_src;
50766110
5077 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);
5078 if (op2 == irb->codegen->invalid_instruction)
5079 return irb->codegen->invalid_instruction;
6111 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
6112 if (op2 == irb->codegen->invalid_inst_src)
6113 return irb->codegen->invalid_inst_src;
50806114
5081 IrInstruction *op3 = ir_gen_node(irb, op3_node, scope);
5082 if (op3 == irb->codegen->invalid_instruction)
5083 return irb->codegen->invalid_instruction;
6115 IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope);
6116 if (op3 == irb->codegen->invalid_inst_src)
6117 return irb->codegen->invalid_inst_src;
50846118
5085 return ir_build_mul_add(irb, scope, node, type_value, op1, op2, op3);
6119 return ir_build_mul_add_src(irb, scope, node, type_value, op1, op2, op3);
50866120}
50876121
5088static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *node) {
6122static IrInstSrc *ir_gen_this(IrBuilderSrc *irb, Scope *orig_scope, AstNode *node) {
50896123 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {
50906124 if (it_scope->id == ScopeIdDecls) {
50916125 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;
......@@ -5100,7 +6134,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no
51006134 zig_unreachable();
51016135}
51026136
5103static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *await_node, AstNode *call_node,
6137static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *await_node, AstNode *call_node,
51046138 LVal lval, ResultLoc *result_loc)
51056139{
51066140 size_t arg_offset = 3;
......@@ -5108,71 +6142,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a
51086142 add_node_error(irb->codegen, call_node,
51096143 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
51106144 arg_offset, call_node->data.fn_call_expr.params.length));
5111 return irb->codegen->invalid_instruction;
6145 return irb->codegen->invalid_inst_src;
51126146 }
51136147
51146148 AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0);
5115 IrInstruction *bytes = ir_gen_node(irb, bytes_node, scope);
5116 if (bytes == irb->codegen->invalid_instruction)
6149 IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope);
6150 if (bytes == irb->codegen->invalid_inst_src)
51176151 return bytes;
51186152
51196153 AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1);
5120 IrInstruction *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope);
5121 if (ret_ptr == irb->codegen->invalid_instruction)
6154 IrInstSrc *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope);
6155 if (ret_ptr == irb->codegen->invalid_inst_src)
51226156 return ret_ptr;
51236157
51246158 AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2);
5125 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5126 if (fn_ref == irb->codegen->invalid_instruction)
6159 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6160 if (fn_ref == irb->codegen->invalid_inst_src)
51276161 return fn_ref;
51286162
51296163 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;
5130 IrInstruction **args = allocate<IrInstruction*>(arg_count);
6164 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
51316165 for (size_t i = 0; i < arg_count; i += 1) {
51326166 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);
5133 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);
5134 if (arg == irb->codegen->invalid_instruction)
6167 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
6168 if (arg == irb->codegen->invalid_inst_src)
51356169 return arg;
51366170 args[i] = arg;
51376171 }
51386172
51396173 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;
51406174 bool is_async_call_builtin = true;
5141 IrInstruction *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args,
6175 IrInstSrc *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args,
51426176 ret_ptr, modifier, is_async_call_builtin, bytes, result_loc);
51436177 return ir_lval_wrap(irb, scope, call, lval, result_loc);
51446178}
51456179
5146static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, AstNode *source_node,
5147 AstNode *fn_ref_node, CallModifier modifier, IrInstruction *options,
6180static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
6181 AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options,
51486182 AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc)
51496183{
5150 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5151 if (fn_ref == irb->codegen->invalid_instruction)
6184 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6185 if (fn_ref == irb->codegen->invalid_inst_src)
51526186 return fn_ref;
51536187
5154 IrInstruction *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);
6188 IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);
51556189
5156 IrInstruction **args = allocate<IrInstruction*>(args_len);
6190 IrInstSrc **args = allocate<IrInstSrc*>(args_len);
51576191 for (size_t i = 0; i < args_len; i += 1) {
51586192 AstNode *arg_node = args_ptr[i];
51596193
5160 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
5161 IrInstruction *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);
6194 IrInstSrc *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
6195 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);
51626196 ResultLoc *no_result = no_result_loc();
51636197 ir_build_reset_result(irb, scope, source_node, no_result);
51646198 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result);
51656199
5166 IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
5167 if (arg == irb->codegen->invalid_instruction)
6200 IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
6201 if (arg == irb->codegen->invalid_inst_src)
51686202 return arg;
51696203
51706204 args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast);
51716205 }
51726206
5173 IrInstruction *fn_call;
6207 IrInstSrc *fn_call;
51746208 if (options != nullptr) {
5175 fn_call = ir_build_call_src_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc);
6209 fn_call = ir_build_call_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc);
51766210 } else {
51776211 fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr,
51786212 modifier, false, nullptr, result_loc);
......@@ -5180,7 +6214,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast
51806214 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
51816215}
51826216
5183static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
6217static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
51846218 ResultLoc *result_loc)
51856219{
51866220 assert(node->type == NodeTypeFnCallExpr);
......@@ -5192,7 +6226,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
51926226 if (!entry) {
51936227 add_node_error(irb->codegen, node,
51946228 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));
5195 return irb->codegen->invalid_instruction;
6229 return irb->codegen->invalid_inst_src;
51966230 }
51976231
51986232 BuiltinFnEntry *builtin_fn = entry->value;
......@@ -5202,7 +6236,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
52026236 add_node_error(irb->codegen, node,
52036237 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
52046238 builtin_fn->param_count, actual_param_count));
5205 return irb->codegen->invalid_instruction;
6239 return irb->codegen->invalid_inst_src;
52066240 }
52076241
52086242 switch (builtin_fn->id) {
......@@ -5213,197 +6247,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
52136247 Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope);
52146248
52156249 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5216 IrInstruction *arg = ir_gen_node(irb, arg_node, sub_scope);
5217 if (arg == irb->codegen->invalid_instruction)
6250 IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope);
6251 if (arg == irb->codegen->invalid_inst_src)
52186252 return arg;
52196253
5220 IrInstruction *type_of = ir_build_typeof(irb, scope, node, arg);
6254 IrInstSrc *type_of = ir_build_typeof(irb, scope, node, arg);
52216255 return ir_lval_wrap(irb, scope, type_of, lval, result_loc);
52226256 }
52236257 case BuiltinFnIdSetCold:
52246258 {
52256259 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5227 if (arg0_value == irb->codegen->invalid_instruction)
6260 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6261 if (arg0_value == irb->codegen->invalid_inst_src)
52286262 return arg0_value;
52296263
5230 IrInstruction *set_cold = ir_build_set_cold(irb, scope, node, arg0_value);
6264 IrInstSrc *set_cold = ir_build_set_cold(irb, scope, node, arg0_value);
52316265 return ir_lval_wrap(irb, scope, set_cold, lval, result_loc);
52326266 }
52336267 case BuiltinFnIdSetRuntimeSafety:
52346268 {
52356269 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5236 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5237 if (arg0_value == irb->codegen->invalid_instruction)
6270 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6271 if (arg0_value == irb->codegen->invalid_inst_src)
52386272 return arg0_value;
52396273
5240 IrInstruction *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value);
6274 IrInstSrc *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value);
52416275 return ir_lval_wrap(irb, scope, set_safety, lval, result_loc);
52426276 }
52436277 case BuiltinFnIdSetFloatMode:
52446278 {
52456279 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5246 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5247 if (arg0_value == irb->codegen->invalid_instruction)
6280 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6281 if (arg0_value == irb->codegen->invalid_inst_src)
52486282 return arg0_value;
52496283
5250 IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);
6284 IrInstSrc *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);
52516285 return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc);
52526286 }
52536287 case BuiltinFnIdSizeof:
52546288 case BuiltinFnIdBitSizeof:
52556289 {
52566290 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5257 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5258 if (arg0_value == irb->codegen->invalid_instruction)
6291 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6292 if (arg0_value == irb->codegen->invalid_inst_src)
52596293 return arg0_value;
52606294
5261 IrInstruction *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);
6295 IrInstSrc *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);
52626296 return ir_lval_wrap(irb, scope, size_of, lval, result_loc);
52636297 }
52646298 case BuiltinFnIdImport:
52656299 {
52666300 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5267 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5268 if (arg0_value == irb->codegen->invalid_instruction)
6301 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6302 if (arg0_value == irb->codegen->invalid_inst_src)
52696303 return arg0_value;
52706304
5271 IrInstruction *import = ir_build_import(irb, scope, node, arg0_value);
6305 IrInstSrc *import = ir_build_import(irb, scope, node, arg0_value);
52726306 return ir_lval_wrap(irb, scope, import, lval, result_loc);
52736307 }
52746308 case BuiltinFnIdCImport:
52756309 {
5276 IrInstruction *c_import = ir_build_c_import(irb, scope, node);
6310 IrInstSrc *c_import = ir_build_c_import(irb, scope, node);
52776311 return ir_lval_wrap(irb, scope, c_import, lval, result_loc);
52786312 }
52796313 case BuiltinFnIdCInclude:
52806314 {
52816315 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5282 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5283 if (arg0_value == irb->codegen->invalid_instruction)
6316 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6317 if (arg0_value == irb->codegen->invalid_inst_src)
52846318 return arg0_value;
52856319
52866320 if (!exec_c_import_buf(irb->exec)) {
52876321 add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block"));
5288 return irb->codegen->invalid_instruction;
6322 return irb->codegen->invalid_inst_src;
52896323 }
52906324
5291 IrInstruction *c_include = ir_build_c_include(irb, scope, node, arg0_value);
6325 IrInstSrc *c_include = ir_build_c_include(irb, scope, node, arg0_value);
52926326 return ir_lval_wrap(irb, scope, c_include, lval, result_loc);
52936327 }
52946328 case BuiltinFnIdCDefine:
52956329 {
52966330 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5297 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5298 if (arg0_value == irb->codegen->invalid_instruction)
6331 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6332 if (arg0_value == irb->codegen->invalid_inst_src)
52996333 return arg0_value;
53006334
53016335 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5302 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5303 if (arg1_value == irb->codegen->invalid_instruction)
6336 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6337 if (arg1_value == irb->codegen->invalid_inst_src)
53046338 return arg1_value;
53056339
53066340 if (!exec_c_import_buf(irb->exec)) {
53076341 add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block"));
5308 return irb->codegen->invalid_instruction;
6342 return irb->codegen->invalid_inst_src;
53096343 }
53106344
5311 IrInstruction *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value);
6345 IrInstSrc *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value);
53126346 return ir_lval_wrap(irb, scope, c_define, lval, result_loc);
53136347 }
53146348 case BuiltinFnIdCUndef:
53156349 {
53166350 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5317 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5318 if (arg0_value == irb->codegen->invalid_instruction)
6351 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6352 if (arg0_value == irb->codegen->invalid_inst_src)
53196353 return arg0_value;
53206354
53216355 if (!exec_c_import_buf(irb->exec)) {
53226356 add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block"));
5323 return irb->codegen->invalid_instruction;
6357 return irb->codegen->invalid_inst_src;
53246358 }
53256359
5326 IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
6360 IrInstSrc *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
53276361 return ir_lval_wrap(irb, scope, c_undef, lval, result_loc);
53286362 }
53296363 case BuiltinFnIdCompileErr:
53306364 {
53316365 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5332 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5333 if (arg0_value == irb->codegen->invalid_instruction)
6366 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6367 if (arg0_value == irb->codegen->invalid_inst_src)
53346368 return arg0_value;
53356369
5336 IrInstruction *compile_err = ir_build_compile_err(irb, scope, node, arg0_value);
6370 IrInstSrc *compile_err = ir_build_compile_err(irb, scope, node, arg0_value);
53376371 return ir_lval_wrap(irb, scope, compile_err, lval, result_loc);
53386372 }
53396373 case BuiltinFnIdCompileLog:
53406374 {
5341 IrInstruction **args = allocate<IrInstruction*>(actual_param_count);
6375 IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count);
53426376
53436377 for (size_t i = 0; i < actual_param_count; i += 1) {
53446378 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
53456379 args[i] = ir_gen_node(irb, arg_node, scope);
5346 if (args[i] == irb->codegen->invalid_instruction)
5347 return irb->codegen->invalid_instruction;
6380 if (args[i] == irb->codegen->invalid_inst_src)
6381 return irb->codegen->invalid_inst_src;
53486382 }
53496383
5350 IrInstruction *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args);
6384 IrInstSrc *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args);
53516385 return ir_lval_wrap(irb, scope, compile_log, lval, result_loc);
53526386 }
53536387 case BuiltinFnIdErrName:
53546388 {
53556389 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5356 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5357 if (arg0_value == irb->codegen->invalid_instruction)
6390 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6391 if (arg0_value == irb->codegen->invalid_inst_src)
53586392 return arg0_value;
53596393
5360 IrInstruction *err_name = ir_build_err_name(irb, scope, node, arg0_value);
6394 IrInstSrc *err_name = ir_build_err_name(irb, scope, node, arg0_value);
53616395 return ir_lval_wrap(irb, scope, err_name, lval, result_loc);
53626396 }
53636397 case BuiltinFnIdEmbedFile:
53646398 {
53656399 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5366 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5367 if (arg0_value == irb->codegen->invalid_instruction)
6400 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6401 if (arg0_value == irb->codegen->invalid_inst_src)
53686402 return arg0_value;
53696403
5370 IrInstruction *embed_file = ir_build_embed_file(irb, scope, node, arg0_value);
6404 IrInstSrc *embed_file = ir_build_embed_file(irb, scope, node, arg0_value);
53716405 return ir_lval_wrap(irb, scope, embed_file, lval, result_loc);
53726406 }
53736407 case BuiltinFnIdCmpxchgWeak:
53746408 case BuiltinFnIdCmpxchgStrong:
53756409 {
53766410 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5377 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5378 if (arg0_value == irb->codegen->invalid_instruction)
6411 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6412 if (arg0_value == irb->codegen->invalid_inst_src)
53796413 return arg0_value;
53806414
53816415 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5382 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5383 if (arg1_value == irb->codegen->invalid_instruction)
6416 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6417 if (arg1_value == irb->codegen->invalid_inst_src)
53846418 return arg1_value;
53856419
53866420 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5387 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5388 if (arg2_value == irb->codegen->invalid_instruction)
6421 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6422 if (arg2_value == irb->codegen->invalid_inst_src)
53896423 return arg2_value;
53906424
53916425 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5392 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
5393 if (arg3_value == irb->codegen->invalid_instruction)
6426 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6427 if (arg3_value == irb->codegen->invalid_inst_src)
53946428 return arg3_value;
53956429
53966430 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
5397 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);
5398 if (arg4_value == irb->codegen->invalid_instruction)
6431 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
6432 if (arg4_value == irb->codegen->invalid_inst_src)
53996433 return arg4_value;
54006434
54016435 AstNode *arg5_node = node->data.fn_call_expr.params.at(5);
5402 IrInstruction *arg5_value = ir_gen_node(irb, arg5_node, scope);
5403 if (arg5_value == irb->codegen->invalid_instruction)
6436 IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope);
6437 if (arg5_value == irb->codegen->invalid_inst_src)
54046438 return arg5_value;
54056439
5406 IrInstruction *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value,
6440 IrInstSrc *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value,
54076441 arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak),
54086442 result_loc);
54096443 return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc);
......@@ -5411,86 +6445,86 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
54116445 case BuiltinFnIdFence:
54126446 {
54136447 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5414 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5415 if (arg0_value == irb->codegen->invalid_instruction)
6448 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6449 if (arg0_value == irb->codegen->invalid_inst_src)
54166450 return arg0_value;
54176451
5418 IrInstruction *fence = ir_build_fence(irb, scope, node, arg0_value, AtomicOrderUnordered);
6452 IrInstSrc *fence = ir_build_fence(irb, scope, node, arg0_value);
54196453 return ir_lval_wrap(irb, scope, fence, lval, result_loc);
54206454 }
54216455 case BuiltinFnIdDivExact:
54226456 {
54236457 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5424 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5425 if (arg0_value == irb->codegen->invalid_instruction)
6458 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6459 if (arg0_value == irb->codegen->invalid_inst_src)
54266460 return arg0_value;
54276461
54286462 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5429 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5430 if (arg1_value == irb->codegen->invalid_instruction)
6463 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6464 if (arg1_value == irb->codegen->invalid_inst_src)
54316465 return arg1_value;
54326466
5433 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);
6467 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);
54346468 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54356469 }
54366470 case BuiltinFnIdDivTrunc:
54376471 {
54386472 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5439 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5440 if (arg0_value == irb->codegen->invalid_instruction)
6473 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6474 if (arg0_value == irb->codegen->invalid_inst_src)
54416475 return arg0_value;
54426476
54436477 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5444 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5445 if (arg1_value == irb->codegen->invalid_instruction)
6478 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6479 if (arg1_value == irb->codegen->invalid_inst_src)
54466480 return arg1_value;
54476481
5448 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);
6482 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);
54496483 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54506484 }
54516485 case BuiltinFnIdDivFloor:
54526486 {
54536487 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5454 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5455 if (arg0_value == irb->codegen->invalid_instruction)
6488 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6489 if (arg0_value == irb->codegen->invalid_inst_src)
54566490 return arg0_value;
54576491
54586492 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5459 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5460 if (arg1_value == irb->codegen->invalid_instruction)
6493 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6494 if (arg1_value == irb->codegen->invalid_inst_src)
54616495 return arg1_value;
54626496
5463 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);
6497 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);
54646498 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54656499 }
54666500 case BuiltinFnIdRem:
54676501 {
54686502 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5469 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5470 if (arg0_value == irb->codegen->invalid_instruction)
6503 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6504 if (arg0_value == irb->codegen->invalid_inst_src)
54716505 return arg0_value;
54726506
54736507 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5474 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5475 if (arg1_value == irb->codegen->invalid_instruction)
6508 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6509 if (arg1_value == irb->codegen->invalid_inst_src)
54766510 return arg1_value;
54776511
5478 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);
6512 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);
54796513 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54806514 }
54816515 case BuiltinFnIdMod:
54826516 {
54836517 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5484 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5485 if (arg0_value == irb->codegen->invalid_instruction)
6518 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6519 if (arg0_value == irb->codegen->invalid_inst_src)
54866520 return arg0_value;
54876521
54886522 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5489 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5490 if (arg1_value == irb->codegen->invalid_instruction)
6523 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6524 if (arg1_value == irb->codegen->invalid_inst_src)
54916525 return arg1_value;
54926526
5493 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);
6527 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);
54946528 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54956529 }
54966530 case BuiltinFnIdSqrt:
......@@ -5509,406 +6543,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
55096543 case BuiltinFnIdRound:
55106544 {
55116545 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5512 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5513 if (arg0_value == irb->codegen->invalid_instruction)
6546 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6547 if (arg0_value == irb->codegen->invalid_inst_src)
55146548 return arg0_value;
55156549
5516 IrInstruction *inst = ir_build_float_op(irb, scope, node, arg0_value, builtin_fn->id);
6550 IrInstSrc *inst = ir_build_float_op_src(irb, scope, node, arg0_value, builtin_fn->id);
55176551 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
55186552 }
55196553 case BuiltinFnIdTruncate:
55206554 {
55216555 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5522 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5523 if (arg0_value == irb->codegen->invalid_instruction)
6556 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6557 if (arg0_value == irb->codegen->invalid_inst_src)
55246558 return arg0_value;
55256559
55266560 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5527 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5528 if (arg1_value == irb->codegen->invalid_instruction)
6561 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6562 if (arg1_value == irb->codegen->invalid_inst_src)
55296563 return arg1_value;
55306564
5531 IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);
6565 IrInstSrc *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);
55326566 return ir_lval_wrap(irb, scope, truncate, lval, result_loc);
55336567 }
55346568 case BuiltinFnIdIntCast:
55356569 {
55366570 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5537 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5538 if (arg0_value == irb->codegen->invalid_instruction)
6571 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6572 if (arg0_value == irb->codegen->invalid_inst_src)
55396573 return arg0_value;
55406574
55416575 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5542 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5543 if (arg1_value == irb->codegen->invalid_instruction)
6576 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6577 if (arg1_value == irb->codegen->invalid_inst_src)
55446578 return arg1_value;
55456579
5546 IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);
6580 IrInstSrc *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);
55476581 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55486582 }
55496583 case BuiltinFnIdFloatCast:
55506584 {
55516585 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5552 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5553 if (arg0_value == irb->codegen->invalid_instruction)
6586 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6587 if (arg0_value == irb->codegen->invalid_inst_src)
55546588 return arg0_value;
55556589
55566590 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5557 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5558 if (arg1_value == irb->codegen->invalid_instruction)
6591 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6592 if (arg1_value == irb->codegen->invalid_inst_src)
55596593 return arg1_value;
55606594
5561 IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);
6595 IrInstSrc *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);
55626596 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55636597 }
55646598 case BuiltinFnIdErrSetCast:
55656599 {
55666600 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5567 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5568 if (arg0_value == irb->codegen->invalid_instruction)
6601 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6602 if (arg0_value == irb->codegen->invalid_inst_src)
55696603 return arg0_value;
55706604
55716605 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5572 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5573 if (arg1_value == irb->codegen->invalid_instruction)
6606 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6607 if (arg1_value == irb->codegen->invalid_inst_src)
55746608 return arg1_value;
55756609
5576 IrInstruction *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
6610 IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
55776611 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55786612 }
55796613 case BuiltinFnIdFromBytes:
55806614 {
55816615 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5582 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5583 if (arg0_value == irb->codegen->invalid_instruction)
6616 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6617 if (arg0_value == irb->codegen->invalid_inst_src)
55846618 return arg0_value;
55856619
55866620 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5587 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5588 if (arg1_value == irb->codegen->invalid_instruction)
6621 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6622 if (arg1_value == irb->codegen->invalid_inst_src)
55896623 return arg1_value;
55906624
5591 IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);
6625 IrInstSrc *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);
55926626 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55936627 }
55946628 case BuiltinFnIdToBytes:
55956629 {
55966630 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5597 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5598 if (arg0_value == irb->codegen->invalid_instruction)
6631 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6632 if (arg0_value == irb->codegen->invalid_inst_src)
55996633 return arg0_value;
56006634
5601 IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);
6635 IrInstSrc *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);
56026636 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56036637 }
56046638 case BuiltinFnIdIntToFloat:
56056639 {
56066640 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5607 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5608 if (arg0_value == irb->codegen->invalid_instruction)
6641 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6642 if (arg0_value == irb->codegen->invalid_inst_src)
56096643 return arg0_value;
56106644
56116645 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5612 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5613 if (arg1_value == irb->codegen->invalid_instruction)
6646 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6647 if (arg1_value == irb->codegen->invalid_inst_src)
56146648 return arg1_value;
56156649
5616 IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);
6650 IrInstSrc *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);
56176651 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56186652 }
56196653 case BuiltinFnIdFloatToInt:
56206654 {
56216655 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5622 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5623 if (arg0_value == irb->codegen->invalid_instruction)
6656 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6657 if (arg0_value == irb->codegen->invalid_inst_src)
56246658 return arg0_value;
56256659
56266660 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5627 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5628 if (arg1_value == irb->codegen->invalid_instruction)
6661 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6662 if (arg1_value == irb->codegen->invalid_inst_src)
56296663 return arg1_value;
56306664
5631 IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);
6665 IrInstSrc *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);
56326666 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56336667 }
56346668 case BuiltinFnIdErrToInt:
56356669 {
56366670 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5637 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5638 if (arg0_value == irb->codegen->invalid_instruction)
6671 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6672 if (arg0_value == irb->codegen->invalid_inst_src)
56396673 return arg0_value;
56406674
5641 IrInstruction *result = ir_build_err_to_int(irb, scope, node, arg0_value);
6675 IrInstSrc *result = ir_build_err_to_int_src(irb, scope, node, arg0_value);
56426676 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56436677 }
56446678 case BuiltinFnIdIntToErr:
56456679 {
56466680 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5647 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5648 if (arg0_value == irb->codegen->invalid_instruction)
6681 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6682 if (arg0_value == irb->codegen->invalid_inst_src)
56496683 return arg0_value;
56506684
5651 IrInstruction *result = ir_build_int_to_err(irb, scope, node, arg0_value);
6685 IrInstSrc *result = ir_build_int_to_err_src(irb, scope, node, arg0_value);
56526686 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56536687 }
56546688 case BuiltinFnIdBoolToInt:
56556689 {
56566690 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5657 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5658 if (arg0_value == irb->codegen->invalid_instruction)
6691 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6692 if (arg0_value == irb->codegen->invalid_inst_src)
56596693 return arg0_value;
56606694
5661 IrInstruction *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
6695 IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
56626696 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56636697 }
56646698 case BuiltinFnIdIntType:
56656699 {
56666700 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5667 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5668 if (arg0_value == irb->codegen->invalid_instruction)
6701 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6702 if (arg0_value == irb->codegen->invalid_inst_src)
56696703 return arg0_value;
56706704
56716705 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5672 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5673 if (arg1_value == irb->codegen->invalid_instruction)
6706 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6707 if (arg1_value == irb->codegen->invalid_inst_src)
56746708 return arg1_value;
56756709
5676 IrInstruction *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
6710 IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
56776711 return ir_lval_wrap(irb, scope, int_type, lval, result_loc);
56786712 }
56796713 case BuiltinFnIdVectorType:
56806714 {
56816715 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5682 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5683 if (arg0_value == irb->codegen->invalid_instruction)
6716 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6717 if (arg0_value == irb->codegen->invalid_inst_src)
56846718 return arg0_value;
56856719
56866720 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5687 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5688 if (arg1_value == irb->codegen->invalid_instruction)
6721 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6722 if (arg1_value == irb->codegen->invalid_inst_src)
56896723 return arg1_value;
56906724
5691 IrInstruction *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value);
6725 IrInstSrc *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value);
56926726 return ir_lval_wrap(irb, scope, vector_type, lval, result_loc);
56936727 }
56946728 case BuiltinFnIdShuffle:
56956729 {
56966730 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5697 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5698 if (arg0_value == irb->codegen->invalid_instruction)
6731 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6732 if (arg0_value == irb->codegen->invalid_inst_src)
56996733 return arg0_value;
57006734
57016735 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5702 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5703 if (arg1_value == irb->codegen->invalid_instruction)
6736 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6737 if (arg1_value == irb->codegen->invalid_inst_src)
57046738 return arg1_value;
57056739
57066740 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5707 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5708 if (arg2_value == irb->codegen->invalid_instruction)
6741 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6742 if (arg2_value == irb->codegen->invalid_inst_src)
57096743 return arg2_value;
57106744
57116745 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5712 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
5713 if (arg3_value == irb->codegen->invalid_instruction)
6746 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6747 if (arg3_value == irb->codegen->invalid_inst_src)
57146748 return arg3_value;
57156749
5716 IrInstruction *shuffle_vector = ir_build_shuffle_vector(irb, scope, node,
6750 IrInstSrc *shuffle_vector = ir_build_shuffle_vector(irb, scope, node,
57176751 arg0_value, arg1_value, arg2_value, arg3_value);
57186752 return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc);
57196753 }
57206754 case BuiltinFnIdSplat:
57216755 {
57226756 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5723 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5724 if (arg0_value == irb->codegen->invalid_instruction)
6757 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6758 if (arg0_value == irb->codegen->invalid_inst_src)
57256759 return arg0_value;
57266760
57276761 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5728 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5729 if (arg1_value == irb->codegen->invalid_instruction)
6762 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6763 if (arg1_value == irb->codegen->invalid_inst_src)
57306764 return arg1_value;
57316765
5732 IrInstruction *splat = ir_build_splat_src(irb, scope, node,
6766 IrInstSrc *splat = ir_build_splat_src(irb, scope, node,
57336767 arg0_value, arg1_value);
57346768 return ir_lval_wrap(irb, scope, splat, lval, result_loc);
57356769 }
57366770 case BuiltinFnIdMemcpy:
57376771 {
57386772 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5739 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5740 if (arg0_value == irb->codegen->invalid_instruction)
6773 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6774 if (arg0_value == irb->codegen->invalid_inst_src)
57416775 return arg0_value;
57426776
57436777 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5744 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5745 if (arg1_value == irb->codegen->invalid_instruction)
6778 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6779 if (arg1_value == irb->codegen->invalid_inst_src)
57466780 return arg1_value;
57476781
57486782 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5749 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5750 if (arg2_value == irb->codegen->invalid_instruction)
6783 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6784 if (arg2_value == irb->codegen->invalid_inst_src)
57516785 return arg2_value;
57526786
5753 IrInstruction *ir_memcpy = ir_build_memcpy(irb, scope, node, arg0_value, arg1_value, arg2_value);
6787 IrInstSrc *ir_memcpy = ir_build_memcpy_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
57546788 return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc);
57556789 }
57566790 case BuiltinFnIdMemset:
57576791 {
57586792 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5759 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5760 if (arg0_value == irb->codegen->invalid_instruction)
6793 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6794 if (arg0_value == irb->codegen->invalid_inst_src)
57616795 return arg0_value;
57626796
57636797 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5764 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5765 if (arg1_value == irb->codegen->invalid_instruction)
6798 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6799 if (arg1_value == irb->codegen->invalid_inst_src)
57666800 return arg1_value;
57676801
57686802 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5769 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5770 if (arg2_value == irb->codegen->invalid_instruction)
6803 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6804 if (arg2_value == irb->codegen->invalid_inst_src)
57716805 return arg2_value;
57726806
5773 IrInstruction *ir_memset = ir_build_memset(irb, scope, node, arg0_value, arg1_value, arg2_value);
6807 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
57746808 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
57756809 }
57766810 case BuiltinFnIdMemberCount:
57776811 {
57786812 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5779 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5780 if (arg0_value == irb->codegen->invalid_instruction)
6813 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6814 if (arg0_value == irb->codegen->invalid_inst_src)
57816815 return arg0_value;
57826816
5783 IrInstruction *member_count = ir_build_member_count(irb, scope, node, arg0_value);
6817 IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value);
57846818 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
57856819 }
57866820 case BuiltinFnIdMemberType:
57876821 {
57886822 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5789 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5790 if (arg0_value == irb->codegen->invalid_instruction)
6823 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6824 if (arg0_value == irb->codegen->invalid_inst_src)
57916825 return arg0_value;
57926826
57936827 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5794 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5795 if (arg1_value == irb->codegen->invalid_instruction)
6828 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6829 if (arg1_value == irb->codegen->invalid_inst_src)
57966830 return arg1_value;
57976831
57986832
5799 IrInstruction *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
6833 IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
58006834 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
58016835 }
58026836 case BuiltinFnIdMemberName:
58036837 {
58046838 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5805 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5806 if (arg0_value == irb->codegen->invalid_instruction)
6839 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6840 if (arg0_value == irb->codegen->invalid_inst_src)
58076841 return arg0_value;
58086842
58096843 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5810 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5811 if (arg1_value == irb->codegen->invalid_instruction)
6844 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6845 if (arg1_value == irb->codegen->invalid_inst_src)
58126846 return arg1_value;
58136847
58146848
5815 IrInstruction *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
6849 IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
58166850 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
58176851 }
58186852 case BuiltinFnIdField:
58196853 {
58206854 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5821 IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);
5822 if (arg0_value == irb->codegen->invalid_instruction)
6855 IrInstSrc *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);
6856 if (arg0_value == irb->codegen->invalid_inst_src)
58236857 return arg0_value;
58246858
58256859 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5826 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5827 if (arg1_value == irb->codegen->invalid_instruction)
6860 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6861 if (arg1_value == irb->codegen->invalid_inst_src)
58286862 return arg1_value;
58296863
5830 IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node,
6864 IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node,
58316865 arg0_value, arg1_value, false);
58326866
58336867 if (lval == LValPtr)
58346868 return ptr_instruction;
58356869
5836 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
6870 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
58376871 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
58386872 }
58396873 case BuiltinFnIdHasField:
58406874 {
58416875 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5842 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5843 if (arg0_value == irb->codegen->invalid_instruction)
6876 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6877 if (arg0_value == irb->codegen->invalid_inst_src)
58446878 return arg0_value;
58456879
58466880 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5847 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5848 if (arg1_value == irb->codegen->invalid_instruction)
6881 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6882 if (arg1_value == irb->codegen->invalid_inst_src)
58496883 return arg1_value;
58506884
5851 IrInstruction *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value);
6885 IrInstSrc *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value);
58526886 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
58536887 }
58546888 case BuiltinFnIdTypeInfo:
58556889 {
58566890 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5857 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5858 if (arg0_value == irb->codegen->invalid_instruction)
6891 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6892 if (arg0_value == irb->codegen->invalid_inst_src)
58596893 return arg0_value;
58606894
5861 IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value);
6895 IrInstSrc *type_info = ir_build_type_info(irb, scope, node, arg0_value);
58626896 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
58636897 }
58646898 case BuiltinFnIdType:
58656899 {
58666900 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5867 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);
5868 if (arg == irb->codegen->invalid_instruction)
6901 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
6902 if (arg == irb->codegen->invalid_inst_src)
58696903 return arg;
58706904
5871 IrInstruction *type = ir_build_type(irb, scope, node, arg);
6905 IrInstSrc *type = ir_build_type(irb, scope, node, arg);
58726906 return ir_lval_wrap(irb, scope, type, lval, result_loc);
58736907 }
58746908 case BuiltinFnIdBreakpoint:
58756909 return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc);
58766910 case BuiltinFnIdReturnAddress:
5877 return ir_lval_wrap(irb, scope, ir_build_return_address(irb, scope, node), lval, result_loc);
6911 return ir_lval_wrap(irb, scope, ir_build_return_address_src(irb, scope, node), lval, result_loc);
58786912 case BuiltinFnIdFrameAddress:
5879 return ir_lval_wrap(irb, scope, ir_build_frame_address(irb, scope, node), lval, result_loc);
6913 return ir_lval_wrap(irb, scope, ir_build_frame_address_src(irb, scope, node), lval, result_loc);
58806914 case BuiltinFnIdFrameHandle:
58816915 if (!irb->exec->fn_entry) {
58826916 add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition"));
5883 return irb->codegen->invalid_instruction;
6917 return irb->codegen->invalid_inst_src;
58846918 }
5885 return ir_lval_wrap(irb, scope, ir_build_handle(irb, scope, node), lval, result_loc);
6919 return ir_lval_wrap(irb, scope, ir_build_handle_src(irb, scope, node), lval, result_loc);
58866920 case BuiltinFnIdFrameType: {
58876921 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5888 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5889 if (arg0_value == irb->codegen->invalid_instruction)
6922 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6923 if (arg0_value == irb->codegen->invalid_inst_src)
58906924 return arg0_value;
58916925
5892 IrInstruction *frame_type = ir_build_frame_type(irb, scope, node, arg0_value);
6926 IrInstSrc *frame_type = ir_build_frame_type(irb, scope, node, arg0_value);
58936927 return ir_lval_wrap(irb, scope, frame_type, lval, result_loc);
58946928 }
58956929 case BuiltinFnIdFrameSize: {
58966930 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5897 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5898 if (arg0_value == irb->codegen->invalid_instruction)
6931 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6932 if (arg0_value == irb->codegen->invalid_inst_src)
58996933 return arg0_value;
59006934
5901 IrInstruction *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value);
6935 IrInstSrc *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value);
59026936 return ir_lval_wrap(irb, scope, frame_size, lval, result_loc);
59036937 }
59046938 case BuiltinFnIdAlignOf:
59056939 {
59066940 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5907 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5908 if (arg0_value == irb->codegen->invalid_instruction)
6941 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6942 if (arg0_value == irb->codegen->invalid_inst_src)
59096943 return arg0_value;
59106944
5911 IrInstruction *align_of = ir_build_align_of(irb, scope, node, arg0_value);
6945 IrInstSrc *align_of = ir_build_align_of(irb, scope, node, arg0_value);
59126946 return ir_lval_wrap(irb, scope, align_of, lval, result_loc);
59136947 }
59146948 case BuiltinFnIdAddWithOverflow:
......@@ -5924,43 +6958,43 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
59246958 case BuiltinFnIdTypeName:
59256959 {
59266960 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5927 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5928 if (arg0_value == irb->codegen->invalid_instruction)
6961 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6962 if (arg0_value == irb->codegen->invalid_inst_src)
59296963 return arg0_value;
59306964
5931 IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value);
6965 IrInstSrc *type_name = ir_build_type_name(irb, scope, node, arg0_value);
59326966 return ir_lval_wrap(irb, scope, type_name, lval, result_loc);
59336967 }
59346968 case BuiltinFnIdPanic:
59356969 {
59366970 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5937 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5938 if (arg0_value == irb->codegen->invalid_instruction)
6971 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6972 if (arg0_value == irb->codegen->invalid_inst_src)
59396973 return arg0_value;
59406974
5941 IrInstruction *panic = ir_build_panic(irb, scope, node, arg0_value);
6975 IrInstSrc *panic = ir_build_panic_src(irb, scope, node, arg0_value);
59426976 return ir_lval_wrap(irb, scope, panic, lval, result_loc);
59436977 }
59446978 case BuiltinFnIdPtrCast:
59456979 {
59466980 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5947 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5948 if (arg0_value == irb->codegen->invalid_instruction)
6981 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6982 if (arg0_value == irb->codegen->invalid_inst_src)
59496983 return arg0_value;
59506984
59516985 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5952 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5953 if (arg1_value == irb->codegen->invalid_instruction)
6986 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6987 if (arg1_value == irb->codegen->invalid_inst_src)
59546988 return arg1_value;
59556989
5956 IrInstruction *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true);
6990 IrInstSrc *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true);
59576991 return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc);
59586992 }
59596993 case BuiltinFnIdBitCast:
59606994 {
59616995 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5962 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
5963 if (dest_type == irb->codegen->invalid_instruction)
6996 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
6997 if (dest_type == irb->codegen->invalid_inst_src)
59646998 return dest_type;
59656999
59667000 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);
......@@ -5972,125 +7006,126 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
59727006 ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base);
59737007
59747008 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5975 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
7009 IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
59767010 &result_loc_bit_cast->base);
5977 if (arg1_value == irb->codegen->invalid_instruction)
7011 if (arg1_value == irb->codegen->invalid_inst_src)
59787012 return arg1_value;
59797013
5980 IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
7014 IrInstSrc *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
59817015 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
59827016 }
59837017 case BuiltinFnIdAs:
59847018 {
59857019 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5986 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
5987 if (dest_type == irb->codegen->invalid_instruction)
7020 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
7021 if (dest_type == irb->codegen->invalid_inst_src)
59887022 return dest_type;
59897023
59907024 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);
59917025
59927026 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5993 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
7027 IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
59947028 &result_loc_cast->base);
5995 if (arg1_value == irb->codegen->invalid_instruction)
7029 if (arg1_value == irb->codegen->invalid_inst_src)
59967030 return arg1_value;
59977031
5998 IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
7032 IrInstSrc *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
59997033 return ir_lval_wrap(irb, scope, result, lval, result_loc);
60007034 }
60017035 case BuiltinFnIdIntToPtr:
60027036 {
60037037 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6004 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6005 if (arg0_value == irb->codegen->invalid_instruction)
7038 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7039 if (arg0_value == irb->codegen->invalid_inst_src)
60067040 return arg0_value;
60077041
60087042 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6009 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6010 if (arg1_value == irb->codegen->invalid_instruction)
7043 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7044 if (arg1_value == irb->codegen->invalid_inst_src)
60117045 return arg1_value;
60127046
6013 IrInstruction *int_to_ptr = ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value);
7047 IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(irb, scope, node, arg0_value, arg1_value);
60147048 return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc);
60157049 }
60167050 case BuiltinFnIdPtrToInt:
60177051 {
60187052 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6019 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6020 if (arg0_value == irb->codegen->invalid_instruction)
7053 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7054 if (arg0_value == irb->codegen->invalid_inst_src)
60217055 return arg0_value;
60227056
6023 IrInstruction *ptr_to_int = ir_build_ptr_to_int(irb, scope, node, arg0_value);
7057 IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(irb, scope, node, arg0_value);
60247058 return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc);
60257059 }
60267060 case BuiltinFnIdTagName:
60277061 {
60287062 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6029 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6030 if (arg0_value == irb->codegen->invalid_instruction)
7063 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7064 if (arg0_value == irb->codegen->invalid_inst_src)
60317065 return arg0_value;
60327066
6033 IrInstruction *tag_name = ir_build_tag_name(irb, scope, node, arg0_value);
7067 IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value);
60347068 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);
60357069 }
60367070 case BuiltinFnIdTagType:
60377071 {
60387072 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6039 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6040 if (arg0_value == irb->codegen->invalid_instruction)
7073 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7074 if (arg0_value == irb->codegen->invalid_inst_src)
60417075 return arg0_value;
60427076
6043 IrInstruction *tag_type = ir_build_tag_type(irb, scope, node, arg0_value);
7077 IrInstSrc *tag_type = ir_build_tag_type(irb, scope, node, arg0_value);
60447078 return ir_lval_wrap(irb, scope, tag_type, lval, result_loc);
60457079 }
60467080 case BuiltinFnIdFieldParentPtr:
60477081 {
60487082 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6049 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6050 if (arg0_value == irb->codegen->invalid_instruction)
7083 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7084 if (arg0_value == irb->codegen->invalid_inst_src)
60517085 return arg0_value;
60527086
60537087 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6054 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6055 if (arg1_value == irb->codegen->invalid_instruction)
7088 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7089 if (arg1_value == irb->codegen->invalid_inst_src)
60567090 return arg1_value;
60577091
60587092 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6059 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6060 if (arg2_value == irb->codegen->invalid_instruction)
7093 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7094 if (arg2_value == irb->codegen->invalid_inst_src)
60617095 return arg2_value;
60627096
6063 IrInstruction *field_parent_ptr = ir_build_field_parent_ptr(irb, scope, node, arg0_value, arg1_value, arg2_value, nullptr);
7097 IrInstSrc *field_parent_ptr = ir_build_field_parent_ptr_src(irb, scope, node,
7098 arg0_value, arg1_value, arg2_value);
60647099 return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc);
60657100 }
60667101 case BuiltinFnIdByteOffsetOf:
60677102 {
60687103 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6069 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6070 if (arg0_value == irb->codegen->invalid_instruction)
7104 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7105 if (arg0_value == irb->codegen->invalid_inst_src)
60717106 return arg0_value;
60727107
60737108 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6074 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6075 if (arg1_value == irb->codegen->invalid_instruction)
7109 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7110 if (arg1_value == irb->codegen->invalid_inst_src)
60767111 return arg1_value;
60777112
6078 IrInstruction *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value);
7113 IrInstSrc *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value);
60797114 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
60807115 }
60817116 case BuiltinFnIdBitOffsetOf:
60827117 {
60837118 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6084 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6085 if (arg0_value == irb->codegen->invalid_instruction)
7119 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7120 if (arg0_value == irb->codegen->invalid_inst_src)
60867121 return arg0_value;
60877122
60887123 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6089 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6090 if (arg1_value == irb->codegen->invalid_instruction)
7124 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7125 if (arg1_value == irb->codegen->invalid_inst_src)
60917126 return arg1_value;
60927127
6093 IrInstruction *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
7128 IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
60947129 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
60957130 }
60967131 case BuiltinFnIdNewStackCall:
......@@ -6099,45 +7134,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
60997134 add_node_error(irb->codegen, node,
61007135 buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,
61017136 node->data.fn_call_expr.params.length));
6102 return irb->codegen->invalid_instruction;
7137 return irb->codegen->invalid_inst_src;
61037138 }
61047139
61057140 AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);
6106 IrInstruction *new_stack = ir_gen_node(irb, new_stack_node, scope);
6107 if (new_stack == irb->codegen->invalid_instruction)
7141 IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope);
7142 if (new_stack == irb->codegen->invalid_inst_src)
61087143 return new_stack;
61097144
61107145 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
6111 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6112 if (fn_ref == irb->codegen->invalid_instruction)
7146 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
7147 if (fn_ref == irb->codegen->invalid_inst_src)
61137148 return fn_ref;
61147149
61157150 size_t arg_count = node->data.fn_call_expr.params.length - 2;
61167151
6117 IrInstruction **args = allocate<IrInstruction*>(arg_count);
7152 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
61187153 for (size_t i = 0; i < arg_count; i += 1) {
61197154 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
61207155 args[i] = ir_gen_node(irb, arg_node, scope);
6121 if (args[i] == irb->codegen->invalid_instruction)
7156 if (args[i] == irb->codegen->invalid_inst_src)
61227157 return args[i];
61237158 }
61247159
6125 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,
7160 IrInstSrc *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,
61267161 nullptr, CallModifierNone, false, new_stack, result_loc);
61277162 return ir_lval_wrap(irb, scope, call, lval, result_loc);
61287163 }
61297164 case BuiltinFnIdCall: {
61307165 // Cast the options parameter to the options type
61317166 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");
6132 IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
7167 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
61337168 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
61347169
61357170 AstNode *options_node = node->data.fn_call_expr.params.at(0);
6136 IrInstruction *options_inner = ir_gen_node_extra(irb, options_node, scope,
7171 IrInstSrc *options_inner = ir_gen_node_extra(irb, options_node, scope,
61377172 LValNone, &result_loc_cast->base);
6138 if (options_inner == irb->codegen->invalid_instruction)
7173 if (options_inner == irb->codegen->invalid_inst_src)
61397174 return options_inner;
6140 IrInstruction *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast);
7175 IrInstSrc *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast);
61417176
61427177 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
61437178 AstNode *args_node = node->data.fn_call_expr.params.at(2);
......@@ -6153,18 +7188,18 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
61537188 } else {
61547189 exec_add_error_node(irb->codegen, irb->exec, args_node,
61557190 buf_sprintf("TODO: @call with anon struct literal"));
6156 return irb->codegen->invalid_instruction;
7191 return irb->codegen->invalid_inst_src;
61577192 }
61587193 } else {
6159 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6160 if (fn_ref == irb->codegen->invalid_instruction)
7194 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
7195 if (fn_ref == irb->codegen->invalid_inst_src)
61617196 return fn_ref;
61627197
6163 IrInstruction *args = ir_gen_node(irb, args_node, scope);
6164 if (args == irb->codegen->invalid_instruction)
7198 IrInstSrc *args = ir_gen_node(irb, args_node, scope);
7199 if (args == irb->codegen->invalid_inst_src)
61657200 return args;
61667201
6167 IrInstruction *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc);
7202 IrInstSrc *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc);
61687203 return ir_lval_wrap(irb, scope, call, lval, result_loc);
61697204 }
61707205 }
......@@ -6173,237 +7208,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
61737208 case BuiltinFnIdTypeId:
61747209 {
61757210 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6176 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6177 if (arg0_value == irb->codegen->invalid_instruction)
7211 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7212 if (arg0_value == irb->codegen->invalid_inst_src)
61787213 return arg0_value;
61797214
6180 IrInstruction *type_id = ir_build_type_id(irb, scope, node, arg0_value);
7215 IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value);
61817216 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
61827217 }
61837218 case BuiltinFnIdShlExact:
61847219 {
61857220 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6186 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6187 if (arg0_value == irb->codegen->invalid_instruction)
7221 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7222 if (arg0_value == irb->codegen->invalid_inst_src)
61887223 return arg0_value;
61897224
61907225 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6191 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6192 if (arg1_value == irb->codegen->invalid_instruction)
7226 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7227 if (arg1_value == irb->codegen->invalid_inst_src)
61937228 return arg1_value;
61947229
6195 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);
7230 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);
61967231 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
61977232 }
61987233 case BuiltinFnIdShrExact:
61997234 {
62007235 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6201 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6202 if (arg0_value == irb->codegen->invalid_instruction)
7236 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7237 if (arg0_value == irb->codegen->invalid_inst_src)
62037238 return arg0_value;
62047239
62057240 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6206 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6207 if (arg1_value == irb->codegen->invalid_instruction)
7241 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7242 if (arg1_value == irb->codegen->invalid_inst_src)
62087243 return arg1_value;
62097244
6210 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);
7245 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);
62117246 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
62127247 }
62137248 case BuiltinFnIdSetEvalBranchQuota:
62147249 {
62157250 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6216 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6217 if (arg0_value == irb->codegen->invalid_instruction)
7251 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7252 if (arg0_value == irb->codegen->invalid_inst_src)
62187253 return arg0_value;
62197254
6220 IrInstruction *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value);
7255 IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value);
62217256 return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc);
62227257 }
62237258 case BuiltinFnIdAlignCast:
62247259 {
62257260 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6227 if (arg0_value == irb->codegen->invalid_instruction)
7261 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7262 if (arg0_value == irb->codegen->invalid_inst_src)
62287263 return arg0_value;
62297264
62307265 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6231 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6232 if (arg1_value == irb->codegen->invalid_instruction)
7266 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7267 if (arg1_value == irb->codegen->invalid_inst_src)
62337268 return arg1_value;
62347269
6235 IrInstruction *align_cast = ir_build_align_cast(irb, scope, node, arg0_value, arg1_value);
7270 IrInstSrc *align_cast = ir_build_align_cast_src(irb, scope, node, arg0_value, arg1_value);
62367271 return ir_lval_wrap(irb, scope, align_cast, lval, result_loc);
62377272 }
62387273 case BuiltinFnIdOpaqueType:
62397274 {
6240 IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node);
7275 IrInstSrc *opaque_type = ir_build_opaque_type(irb, scope, node);
62417276 return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc);
62427277 }
62437278 case BuiltinFnIdThis:
62447279 {
6245 IrInstruction *this_inst = ir_gen_this(irb, scope, node);
7280 IrInstSrc *this_inst = ir_gen_this(irb, scope, node);
62467281 return ir_lval_wrap(irb, scope, this_inst, lval, result_loc);
62477282 }
62487283 case BuiltinFnIdSetAlignStack:
62497284 {
62507285 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6251 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6252 if (arg0_value == irb->codegen->invalid_instruction)
7286 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7287 if (arg0_value == irb->codegen->invalid_inst_src)
62537288 return arg0_value;
62547289
6255 IrInstruction *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
7290 IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
62567291 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
62577292 }
62587293 case BuiltinFnIdArgType:
62597294 {
62607295 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6261 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6262 if (arg0_value == irb->codegen->invalid_instruction)
7296 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7297 if (arg0_value == irb->codegen->invalid_inst_src)
62637298 return arg0_value;
62647299
62657300 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6266 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6267 if (arg1_value == irb->codegen->invalid_instruction)
7301 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7302 if (arg1_value == irb->codegen->invalid_inst_src)
62687303 return arg1_value;
62697304
6270 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
7305 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
62717306 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
62727307 }
62737308 case BuiltinFnIdExport:
62747309 {
62757310 // Cast the options parameter to the options type
62767311 ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions");
6277 IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
7312 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
62787313 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
62797314
62807315 AstNode *target_node = node->data.fn_call_expr.params.at(0);
6281 IrInstruction *target_value = ir_gen_node(irb, target_node, scope);
6282 if (target_value == irb->codegen->invalid_instruction)
7316 IrInstSrc *target_value = ir_gen_node(irb, target_node, scope);
7317 if (target_value == irb->codegen->invalid_inst_src)
62837318 return target_value;
62847319
62857320 AstNode *options_node = node->data.fn_call_expr.params.at(1);
6286 IrInstruction *options_value = ir_gen_node_extra(irb, options_node,
7321 IrInstSrc *options_value = ir_gen_node_extra(irb, options_node,
62877322 scope, LValNone, &result_loc_cast->base);
6288 if (options_value == irb->codegen->invalid_instruction)
7323 if (options_value == irb->codegen->invalid_inst_src)
62897324 return options_value;
62907325
6291 IrInstruction *casted_options_value = ir_build_implicit_cast(
7326 IrInstSrc *casted_options_value = ir_build_implicit_cast(
62927327 irb, scope, options_node, options_value, result_loc_cast);
62937328
6294 IrInstruction *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);
7329 IrInstSrc *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);
62957330 return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);
62967331 }
62977332 case BuiltinFnIdErrorReturnTrace:
62987333 {
6299 IrInstruction *error_return_trace = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::Null);
7334 IrInstSrc *error_return_trace = ir_build_error_return_trace_src(irb, scope, node,
7335 IrInstErrorReturnTraceNull);
63007336 return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc);
63017337 }
63027338 case BuiltinFnIdAtomicRmw:
63037339 {
63047340 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6305 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6306 if (arg0_value == irb->codegen->invalid_instruction)
7341 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7342 if (arg0_value == irb->codegen->invalid_inst_src)
63077343 return arg0_value;
63087344
63097345 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6310 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6311 if (arg1_value == irb->codegen->invalid_instruction)
7346 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7347 if (arg1_value == irb->codegen->invalid_inst_src)
63127348 return arg1_value;
63137349
63147350 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6315 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6316 if (arg2_value == irb->codegen->invalid_instruction)
7351 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7352 if (arg2_value == irb->codegen->invalid_inst_src)
63177353 return arg2_value;
63187354
63197355 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6320 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
6321 if (arg3_value == irb->codegen->invalid_instruction)
7356 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
7357 if (arg3_value == irb->codegen->invalid_inst_src)
63227358 return arg3_value;
63237359
63247360 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
6325 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);
6326 if (arg4_value == irb->codegen->invalid_instruction)
7361 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
7362 if (arg4_value == irb->codegen->invalid_inst_src)
63277363 return arg4_value;
63287364
6329 IrInstruction *inst = ir_build_atomic_rmw(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,
6330 arg4_value,
6331 // these 2 values don't mean anything since we passed non-null values for other args
6332 AtomicRmwOp_xchg, AtomicOrderMonotonic);
7365 IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node,
7366 arg0_value, arg1_value, arg2_value, arg3_value, arg4_value);
63337367 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
63347368 }
63357369 case BuiltinFnIdAtomicLoad:
63367370 {
63377371 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6338 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6339 if (arg0_value == irb->codegen->invalid_instruction)
7372 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7373 if (arg0_value == irb->codegen->invalid_inst_src)
63407374 return arg0_value;
63417375
63427376 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6343 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6344 if (arg1_value == irb->codegen->invalid_instruction)
7377 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7378 if (arg1_value == irb->codegen->invalid_inst_src)
63457379 return arg1_value;
63467380
63477381 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6348 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6349 if (arg2_value == irb->codegen->invalid_instruction)
7382 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7383 if (arg2_value == irb->codegen->invalid_inst_src)
63507384 return arg2_value;
63517385
6352 IrInstruction *inst = ir_build_atomic_load(irb, scope, node, arg0_value, arg1_value, arg2_value,
6353 // this value does not mean anything since we passed non-null values for other arg
6354 AtomicOrderMonotonic);
7386 IrInstSrc *inst = ir_build_atomic_load_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
63557387 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
63567388 }
63577389 case BuiltinFnIdAtomicStore:
63587390 {
63597391 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6360 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6361 if (arg0_value == irb->codegen->invalid_instruction)
7392 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7393 if (arg0_value == irb->codegen->invalid_inst_src)
63627394 return arg0_value;
63637395
63647396 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6365 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6366 if (arg1_value == irb->codegen->invalid_instruction)
7397 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7398 if (arg1_value == irb->codegen->invalid_inst_src)
63677399 return arg1_value;
63687400
63697401 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6370 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6371 if (arg2_value == irb->codegen->invalid_instruction)
7402 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7403 if (arg2_value == irb->codegen->invalid_inst_src)
63727404 return arg2_value;
63737405
63747406 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6375 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
6376 if (arg3_value == irb->codegen->invalid_instruction)
7407 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
7408 if (arg3_value == irb->codegen->invalid_inst_src)
63777409 return arg3_value;
63787410
6379 IrInstruction *inst = ir_build_atomic_store(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,
6380 // this value does not mean anything since we passed non-null values for other arg
6381 AtomicOrderMonotonic);
7411 IrInstSrc *inst = ir_build_atomic_store_src(irb, scope, node, arg0_value, arg1_value,
7412 arg2_value, arg3_value);
63827413 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
63837414 }
63847415 case BuiltinFnIdIntToEnum:
63857416 {
63867417 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6387 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6388 if (arg0_value == irb->codegen->invalid_instruction)
7418 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7419 if (arg0_value == irb->codegen->invalid_inst_src)
63897420 return arg0_value;
63907421
63917422 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6392 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6393 if (arg1_value == irb->codegen->invalid_instruction)
7423 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7424 if (arg1_value == irb->codegen->invalid_inst_src)
63947425 return arg1_value;
63957426
6396 IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value);
7427 IrInstSrc *result = ir_build_int_to_enum_src(irb, scope, node, arg0_value, arg1_value);
63977428 return ir_lval_wrap(irb, scope, result, lval, result_loc);
63987429 }
63997430 case BuiltinFnIdEnumToInt:
64007431 {
64017432 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6402 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6403 if (arg0_value == irb->codegen->invalid_instruction)
7433 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7434 if (arg0_value == irb->codegen->invalid_inst_src)
64047435 return arg0_value;
64057436
6406 IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value);
7437 IrInstSrc *result = ir_build_enum_to_int(irb, scope, node, arg0_value);
64077438 return ir_lval_wrap(irb, scope, result, lval, result_loc);
64087439 }
64097440 case BuiltinFnIdCtz:
......@@ -6413,16 +7444,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
64137444 case BuiltinFnIdBitReverse:
64147445 {
64157446 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6416 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6417 if (arg0_value == irb->codegen->invalid_instruction)
7447 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7448 if (arg0_value == irb->codegen->invalid_inst_src)
64187449 return arg0_value;
64197450
64207451 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6421 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6422 if (arg1_value == irb->codegen->invalid_instruction)
7452 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7453 if (arg1_value == irb->codegen->invalid_inst_src)
64237454 return arg1_value;
64247455
6425 IrInstruction *result;
7456 IrInstSrc *result;
64267457 switch (builtin_fn->id) {
64277458 case BuiltinFnIdCtz:
64287459 result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value);
......@@ -6447,28 +7478,28 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
64477478 case BuiltinFnIdHasDecl:
64487479 {
64497480 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6450 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6451 if (arg0_value == irb->codegen->invalid_instruction)
7481 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7482 if (arg0_value == irb->codegen->invalid_inst_src)
64527483 return arg0_value;
64537484
64547485 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6455 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6456 if (arg1_value == irb->codegen->invalid_instruction)
7486 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7487 if (arg1_value == irb->codegen->invalid_inst_src)
64577488 return arg1_value;
64587489
6459 IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value);
7490 IrInstSrc *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value);
64607491 return ir_lval_wrap(irb, scope, has_decl, lval, result_loc);
64617492 }
64627493 case BuiltinFnIdUnionInit:
64637494 {
64647495 AstNode *union_type_node = node->data.fn_call_expr.params.at(0);
6465 IrInstruction *union_type_inst = ir_gen_node(irb, union_type_node, scope);
6466 if (union_type_inst == irb->codegen->invalid_instruction)
7496 IrInstSrc *union_type_inst = ir_gen_node(irb, union_type_node, scope);
7497 if (union_type_inst == irb->codegen->invalid_inst_src)
64677498 return union_type_inst;
64687499
64697500 AstNode *name_node = node->data.fn_call_expr.params.at(1);
6470 IrInstruction *name_inst = ir_gen_node(irb, name_node, scope);
6471 if (name_inst == irb->codegen->invalid_instruction)
7501 IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope);
7502 if (name_inst == irb->codegen->invalid_inst_src)
64727503 return name_inst;
64737504
64747505 AstNode *init_node = node->data.fn_call_expr.params.at(2);
......@@ -6480,7 +7511,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
64807511 zig_unreachable();
64817512}
64827513
6483static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7514static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
64847515 ResultLoc *result_loc)
64857516{
64867517 assert(node->type == NodeTypeFnCallExpr);
......@@ -6493,16 +7524,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
64937524 nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc);
64947525}
64957526
6496static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7527static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
64977528 ResultLoc *result_loc)
64987529{
64997530 assert(node->type == NodeTypeIfBoolExpr);
65007531
6501 IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);
6502 if (condition == irb->codegen->invalid_instruction)
6503 return irb->codegen->invalid_instruction;
7532 IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);
7533 if (condition == irb->codegen->invalid_inst_src)
7534 return irb->codegen->invalid_inst_src;
65047535
6505 IrInstruction *is_comptime;
7536 IrInstSrc *is_comptime;
65067537 if (ir_should_inline(irb->exec, scope)) {
65077538 is_comptime = ir_build_const_bool(irb, scope, node, true);
65087539 } else {
......@@ -6512,11 +7543,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
65127543 AstNode *then_node = node->data.if_bool_expr.then_block;
65137544 AstNode *else_node = node->data.if_bool_expr.else_node;
65147545
6515 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "Then");
6516 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");
6517 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf");
7546 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then");
7547 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else");
7548 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "EndIf");
65187549
6519 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,
7550 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,
65207551 then_block, else_block, is_comptime);
65217552 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
65227553 result_loc, is_comptime);
......@@ -6524,70 +7555,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
65247555 ir_set_cursor_at_end_and_append_block(irb, then_block);
65257556
65267557 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
6527 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval,
7558 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval,
65287559 &peer_parent->peers.at(0)->base);
6529 if (then_expr_result == irb->codegen->invalid_instruction)
6530 return irb->codegen->invalid_instruction;
6531 IrBasicBlock *after_then_block = irb->current_basic_block;
7560 if (then_expr_result == irb->codegen->invalid_inst_src)
7561 return irb->codegen->invalid_inst_src;
7562 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
65327563 if (!instr_is_unreachable(then_expr_result))
65337564 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65347565
65357566 ir_set_cursor_at_end_and_append_block(irb, else_block);
6536 IrInstruction *else_expr_result;
7567 IrInstSrc *else_expr_result;
65377568 if (else_node) {
65387569 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
6539 if (else_expr_result == irb->codegen->invalid_instruction)
6540 return irb->codegen->invalid_instruction;
7570 if (else_expr_result == irb->codegen->invalid_inst_src)
7571 return irb->codegen->invalid_inst_src;
65417572 } else {
65427573 else_expr_result = ir_build_const_void(irb, scope, node);
65437574 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
65447575 }
6545 IrBasicBlock *after_else_block = irb->current_basic_block;
7576 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
65467577 if (!instr_is_unreachable(else_expr_result))
65477578 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65487579
65497580 ir_set_cursor_at_end_and_append_block(irb, endif_block);
6550 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
7581 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
65517582 incoming_values[0] = then_expr_result;
65527583 incoming_values[1] = else_expr_result;
6553 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
7584 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
65547585 incoming_blocks[0] = after_then_block;
65557586 incoming_blocks[1] = after_else_block;
65567587
6557 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
7588 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
65587589 return ir_expr_wrap(irb, scope, phi, result_loc);
65597590}
65607591
6561static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
7592static IrInstSrc *ir_gen_prefix_op_id_lval(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
65627593 assert(node->type == NodeTypePrefixOpExpr);
65637594 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
65647595
6565 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
6566 if (value == irb->codegen->invalid_instruction)
7596 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
7597 if (value == irb->codegen->invalid_inst_src)
65677598 return value;
65687599
65697600 return ir_build_un_op(irb, scope, node, op_id, value);
65707601}
65717602
6572static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) {
7603static IrInstSrc *ir_gen_prefix_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id) {
65737604 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);
65747605}
65757606
6576static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) {
6577 if (inst == irb->codegen->invalid_instruction) return inst;
6578 ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc);
7607static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
7608 if (inst == irb->codegen->invalid_inst_src) return inst;
7609 ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc);
65797610 return inst;
65807611}
65817612
6582static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval,
7613static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval,
65837614 ResultLoc *result_loc)
65847615{
65857616 // This logic must be kept in sync with
65867617 // [STMT_EXPR_TEST_THING] <--- (search this token)
6587 if (value == irb->codegen->invalid_instruction ||
7618 if (value == irb->codegen->invalid_inst_src ||
65887619 instr_is_unreachable(value) ||
6589 value->source_node->type == NodeTypeDefer ||
6590 value->id == IrInstructionIdDeclVarSrc)
7620 value->base.source_node->type == NodeTypeDefer ||
7621 value->id == IrInstSrcIdDeclVar)
65917622 {
65927623 return value;
65937624 }
......@@ -6595,7 +7626,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
65957626 if (lval == LValPtr) {
65967627 // We needed a pointer to a value, but we got a value. So we create
65977628 // an instruction which just makes a pointer of it.
6598 return ir_build_ref(irb, scope, value->source_node, value, false, false);
7629 return ir_build_ref_src(irb, scope, value->base.source_node, value, false, false);
65997630 } else if (result_loc != nullptr) {
66007631 return ir_expr_wrap(irb, scope, value, result_loc);
66017632 } else {
......@@ -6618,7 +7649,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) {
66187649 }
66197650}
66207651
6621static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
7652static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
66227653 assert(node->type == NodeTypePointerType);
66237654
66247655 PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id);
......@@ -6630,26 +7661,26 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66307661 AstNode *expr_node = node->data.pointer_type.op_expr;
66317662 AstNode *align_expr = node->data.pointer_type.align_expr;
66327663
6633 IrInstruction *sentinel;
7664 IrInstSrc *sentinel;
66347665 if (sentinel_expr != nullptr) {
66357666 sentinel = ir_gen_node(irb, sentinel_expr, scope);
6636 if (sentinel == irb->codegen->invalid_instruction)
7667 if (sentinel == irb->codegen->invalid_inst_src)
66377668 return sentinel;
66387669 } else {
66397670 sentinel = nullptr;
66407671 }
66417672
6642 IrInstruction *align_value;
7673 IrInstSrc *align_value;
66437674 if (align_expr != nullptr) {
66447675 align_value = ir_gen_node(irb, align_expr, scope);
6645 if (align_value == irb->codegen->invalid_instruction)
7676 if (align_value == irb->codegen->invalid_inst_src)
66467677 return align_value;
66477678 } else {
66487679 align_value = nullptr;
66497680 }
66507681
6651 IrInstruction *child_type = ir_gen_node(irb, expr_node, scope);
6652 if (child_type == irb->codegen->invalid_instruction)
7682 IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope);
7683 if (child_type == irb->codegen->invalid_inst_src)
66537684 return child_type;
66547685
66557686 uint32_t bit_offset_start = 0;
......@@ -6659,7 +7690,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66597690 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);
66607691 exec_add_error_node(irb->codegen, irb->exec, node,
66617692 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
6662 return irb->codegen->invalid_instruction;
7693 return irb->codegen->invalid_inst_src;
66637694 }
66647695 bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);
66657696 }
......@@ -6671,7 +7702,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66717702 bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10);
66727703 exec_add_error_node(irb->codegen, irb->exec, node,
66737704 buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));
6674 return irb->codegen->invalid_instruction;
7705 return irb->codegen->invalid_inst_src;
66757706 }
66767707 host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);
66777708 }
......@@ -6679,43 +7710,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66797710 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {
66807711 exec_add_error_node(irb->codegen, irb->exec, node,
66817712 buf_sprintf("bit offset starts after end of host integer"));
6682 return irb->codegen->invalid_instruction;
7713 return irb->codegen->invalid_inst_src;
66837714 }
66847715
66857716 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,
66867717 ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero);
66877718}
66887719
6689static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node,
7720static IrInstSrc *ir_gen_catch_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
66907721 AstNode *expr_node, LVal lval, ResultLoc *result_loc)
66917722{
6692 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
6693 if (err_union_ptr == irb->codegen->invalid_instruction)
6694 return irb->codegen->invalid_instruction;
7723 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7724 if (err_union_ptr == irb->codegen->invalid_inst_src)
7725 return irb->codegen->invalid_inst_src;
66957726
6696 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, scope, source_node, err_union_ptr, true, false);
6697 if (payload_ptr == irb->codegen->invalid_instruction)
6698 return irb->codegen->invalid_instruction;
7727 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false);
7728 if (payload_ptr == irb->codegen->invalid_inst_src)
7729 return irb->codegen->invalid_inst_src;
66997730
67007731 if (lval == LValPtr)
67017732 return payload_ptr;
67027733
6703 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr);
7734 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr);
67047735 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
67057736}
67067737
6707static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) {
7738static IrInstSrc *ir_gen_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
67087739 assert(node->type == NodeTypePrefixOpExpr);
67097740 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
67107741
6711 IrInstruction *value = ir_gen_node(irb, expr_node, scope);
6712 if (value == irb->codegen->invalid_instruction)
6713 return irb->codegen->invalid_instruction;
7742 IrInstSrc *value = ir_gen_node(irb, expr_node, scope);
7743 if (value == irb->codegen->invalid_inst_src)
7744 return irb->codegen->invalid_inst_src;
67147745
67157746 return ir_build_bool_not(irb, scope, node, value);
67167747}
67177748
6718static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7749static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
67197750 ResultLoc *result_loc)
67207751{
67217752 assert(node->type == NodeTypePrefixOpExpr);
......@@ -6743,12 +7774,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
67437774 zig_unreachable();
67447775}
67457776
6746static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
6747 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,
7777static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
7778 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
67487779 LVal lval, ResultLoc *parent_result_loc)
67497780{
6750 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);
6751 IrInstruction *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
7781 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);
7782 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
67527783 field_name, true);
67537784
67547785 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
......@@ -6757,18 +7788,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo
67577788 ir_ref_instruction(field_ptr, irb->current_basic_block);
67587789 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
67597790
6760 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
7791 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
67617792 &result_loc_inst->base);
6762 if (expr_value == irb->codegen->invalid_instruction)
7793 if (expr_value == irb->codegen->invalid_inst_src)
67637794 return expr_value;
67647795
6765 IrInstruction *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type,
7796 IrInstSrc *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type,
67667797 field_name, field_ptr, container_ptr);
67677798
67687799 return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc);
67697800}
67707801
6771static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7802static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
67727803 ResultLoc *parent_result_loc)
67737804{
67747805 assert(node->type == NodeTypeContainerInitExpr);
......@@ -6780,42 +7811,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
67807811 ResultLoc *child_result_loc;
67817812 AstNode *init_array_type_source_node;
67827813 if (container_init_expr->type != nullptr) {
6783 IrInstruction *container_type;
7814 IrInstSrc *container_type;
67847815 if (container_init_expr->type->type == NodeTypeInferredArrayType) {
67857816 if (kind == ContainerInitKindStruct) {
67867817 add_node_error(irb->codegen, container_init_expr->type,
67877818 buf_sprintf("initializing array with struct syntax"));
6788 return irb->codegen->invalid_instruction;
7819 return irb->codegen->invalid_inst_src;
67897820 }
6790 IrInstruction *sentinel;
7821 IrInstSrc *sentinel;
67917822 if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) {
67927823 sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope);
6793 if (sentinel == irb->codegen->invalid_instruction)
7824 if (sentinel == irb->codegen->invalid_inst_src)
67947825 return sentinel;
67957826 } else {
67967827 sentinel = nullptr;
67977828 }
67987829
6799 IrInstruction *elem_type = ir_gen_node(irb,
7830 IrInstSrc *elem_type = ir_gen_node(irb,
68007831 container_init_expr->type->data.inferred_array_type.child_type, scope);
6801 if (elem_type == irb->codegen->invalid_instruction)
7832 if (elem_type == irb->codegen->invalid_inst_src)
68027833 return elem_type;
68037834 size_t item_count = container_init_expr->entries.length;
6804 IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
7835 IrInstSrc *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
68057836 container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type);
68067837 } else {
68077838 container_type = ir_gen_node(irb, container_init_expr->type, scope);
6808 if (container_type == irb->codegen->invalid_instruction)
7839 if (container_type == irb->codegen->invalid_inst_src)
68097840 return container_type;
68107841 }
68117842
68127843 result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc);
68137844 child_result_loc = &result_loc_cast->base;
6814 init_array_type_source_node = container_type->source_node;
7845 init_array_type_source_node = container_type->base.source_node;
68157846 } else {
68167847 child_result_loc = parent_result_loc;
68177848 if (parent_result_loc->source_instruction != nullptr) {
6818 init_array_type_source_node = parent_result_loc->source_instruction->source_node;
7849 init_array_type_source_node = parent_result_loc->source_instruction->base.source_node;
68197850 } else {
68207851 init_array_type_source_node = node;
68217852 }
......@@ -6823,11 +7854,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68237854
68247855 switch (kind) {
68257856 case ContainerInitKindStruct: {
6826 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
7857 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
68277858 nullptr);
68287859
68297860 size_t field_count = container_init_expr->entries.length;
6830 IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);
7861 IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count);
68317862 for (size_t i = 0; i < field_count; i += 1) {
68327863 AstNode *entry_node = container_init_expr->entries.at(i);
68337864 assert(entry_node->type == NodeTypeStructValueField);
......@@ -6835,7 +7866,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68357866 Buf *name = entry_node->data.struct_val_field.name;
68367867 AstNode *expr_node = entry_node->data.struct_val_field.expr;
68377868
6838 IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
7869 IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
68397870 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
68407871 result_loc_inst->base.id = ResultLocIdInstruction;
68417872 result_loc_inst->base.source_instruction = field_ptr;
......@@ -6843,16 +7874,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68437874 ir_ref_instruction(field_ptr, irb->current_basic_block);
68447875 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
68457876
6846 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
7877 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
68477878 &result_loc_inst->base);
6848 if (expr_value == irb->codegen->invalid_instruction)
7879 if (expr_value == irb->codegen->invalid_inst_src)
68497880 return expr_value;
68507881
68517882 fields[i].name = name;
68527883 fields[i].source_node = entry_node;
68537884 fields[i].result_loc = field_ptr;
68547885 }
6855 IrInstruction *result = ir_build_container_init_fields(irb, scope, node, field_count,
7886 IrInstSrc *result = ir_build_container_init_fields(irb, scope, node, field_count,
68567887 fields, container_ptr);
68577888
68587889 if (result_loc_cast != nullptr) {
......@@ -6863,15 +7894,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68637894 case ContainerInitKindArray: {
68647895 size_t item_count = container_init_expr->entries.length;
68657896
6866 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
7897 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
68677898 nullptr);
68687899
6869 IrInstruction **result_locs = allocate<IrInstruction *>(item_count);
7900 IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count);
68707901 for (size_t i = 0; i < item_count; i += 1) {
68717902 AstNode *expr_node = container_init_expr->entries.at(i);
68727903
6873 IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
6874 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
7904 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
7905 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
68757906 elem_index, false, PtrLenSingle, init_array_type_source_node);
68767907 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
68777908 result_loc_inst->base.id = ResultLocIdInstruction;
......@@ -6880,14 +7911,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68807911 ir_ref_instruction(elem_ptr, irb->current_basic_block);
68817912 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
68827913
6883 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
7914 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
68847915 &result_loc_inst->base);
6885 if (expr_value == irb->codegen->invalid_instruction)
7916 if (expr_value == irb->codegen->invalid_inst_src)
68867917 return expr_value;
68877918
68887919 result_locs[i] = elem_ptr;
68897920 }
6890 IrInstruction *result = ir_build_container_init_list(irb, scope, node, item_count,
7921 IrInstSrc *result = ir_build_container_init_list(irb, scope, node, item_count,
68917922 result_locs, container_ptr, init_array_type_source_node);
68927923 if (result_loc_cast != nullptr) {
68937924 result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast);
......@@ -6898,19 +7929,19 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68987929 zig_unreachable();
68997930}
69007931
6901static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *alloca, ZigVar *var) {
7932static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) {
69027933 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
69037934 result_loc_var->base.id = ResultLocIdVar;
69047935 result_loc_var->base.source_instruction = alloca;
69057936 result_loc_var->base.allow_write_through_const = true;
69067937 result_loc_var->var = var;
69077938
6908 ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base);
7939 ir_build_reset_result(irb, alloca->base.scope, alloca->base.source_node, &result_loc_var->base);
69097940
69107941 return result_loc_var;
69117942}
69127943
6913static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
7944static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
69147945 ResultLoc *parent_result_loc)
69157946{
69167947 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
......@@ -6920,37 +7951,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de
69207951 ir_ref_instruction(dest_type, irb->current_basic_block);
69217952 result_loc_cast->parent = parent_result_loc;
69227953
6923 ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base);
7954 ir_build_reset_result(irb, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base);
69247955
69257956 return result_loc_cast;
69267957}
69277958
6928static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
6929 IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)
7959static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
7960 IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime)
69307961{
6931 IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);
7962 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);
69327963 ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var);
69337964 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);
69347965 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);
69357966}
69367967
6937static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) {
7968static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
69387969 assert(node->type == NodeTypeVariableDeclaration);
69397970
69407971 AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;
69417972
69427973 if (buf_eql_str(variable_declaration->symbol, "_")) {
69437974 add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol"));
6944 return irb->codegen->invalid_instruction;
7975 return irb->codegen->invalid_inst_src;
69457976 }
69467977
69477978 // Used for the type expr and the align expr
69487979 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
69497980
6950 IrInstruction *type_instruction;
7981 IrInstSrc *type_instruction;
69517982 if (variable_declaration->type != nullptr) {
69527983 type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope);
6953 if (type_instruction == irb->codegen->invalid_instruction)
7984 if (type_instruction == irb->codegen->invalid_inst_src)
69547985 return type_instruction;
69557986 } else {
69567987 type_instruction = nullptr;
......@@ -6961,22 +7992,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
69617992 bool is_extern = variable_declaration->is_extern;
69627993
69637994 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;
6964 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
7995 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
69657996 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
69667997 is_const, is_const, is_shadowable, is_comptime);
6967 // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node
7998 // we detect IrInstSrcDeclVar in gen_block to make sure the next node
69687999 // is inside var->child_scope
69698000
69708001 if (!is_extern && !variable_declaration->expr) {
69718002 var->var_type = irb->codegen->builtin_types.entry_invalid;
69728003 add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized"));
6973 return irb->codegen->invalid_instruction;
8004 return irb->codegen->invalid_inst_src;
69748005 }
69758006
6976 IrInstruction *align_value = nullptr;
8007 IrInstSrc *align_value = nullptr;
69778008 if (variable_declaration->align_expr != nullptr) {
69788009 align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope);
6979 if (align_value == irb->codegen->invalid_instruction)
8010 if (align_value == irb->codegen->invalid_inst_src)
69808011 return align_value;
69818012 }
69828013
......@@ -6988,7 +8019,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
69888019 // Parser should ensure that this never happens
69898020 assert(variable_declaration->threadlocal_tok == nullptr);
69908021
6991 IrInstruction *alloca = ir_build_alloca_src(irb, scope, node, align_value,
8022 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, node, align_value,
69928023 buf_ptr(variable_declaration->symbol), is_comptime);
69938024
69948025 // Create a result location for the initialization expression.
......@@ -7006,19 +8037,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
70068037 Scope *init_scope = is_comptime_scalar ?
70078038 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;
70088039
7009 // Temporarily set the name of the IrExecutable to the VariableDeclaration
8040 // Temporarily set the name of the IrExecutableSrc to the VariableDeclaration
70108041 // so that the struct or enum from the init expression inherits the name.
70118042 Buf *old_exec_name = irb->exec->name;
70128043 irb->exec->name = variable_declaration->symbol;
7013 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,
8044 IrInstSrc *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,
70148045 LValNone, init_result_loc);
70158046 irb->exec->name = old_exec_name;
70168047
7017 if (init_value == irb->codegen->invalid_instruction)
7018 return irb->codegen->invalid_instruction;
8048 if (init_value == irb->codegen->invalid_inst_src)
8049 return irb->codegen->invalid_inst_src;
70198050
70208051 if (result_loc_cast != nullptr) {
7021 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node,
8052 IrInstSrc *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->base.source_node,
70228053 init_value, result_loc_cast);
70238054 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
70248055 }
......@@ -7026,7 +8057,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
70268057 return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca);
70278058}
70288059
7029static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
8060static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
70308061 ResultLoc *result_loc)
70318062{
70328063 assert(node->type == NodeTypeWhileExpr);
......@@ -7034,15 +8065,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70348065 AstNode *continue_expr_node = node->data.while_expr.continue_expr;
70358066 AstNode *else_node = node->data.while_expr.else_node;
70368067
7037 IrBasicBlock *cond_block = ir_create_basic_block(irb, scope, "WhileCond");
7038 IrBasicBlock *body_block = ir_create_basic_block(irb, scope, "WhileBody");
7039 IrBasicBlock *continue_block = continue_expr_node ?
8068 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond");
8069 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody");
8070 IrBasicBlockSrc *continue_block = continue_expr_node ?
70408071 ir_create_basic_block(irb, scope, "WhileContinue") : cond_block;
7041 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "WhileEnd");
7042 IrBasicBlock *else_block = else_node ?
8072 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd");
8073 IrBasicBlockSrc *else_block = else_node ?
70438074 ir_create_basic_block(irb, scope, "WhileElse") : end_block;
70448075
7045 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,
8076 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node,
70468077 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
70478078 ir_build_br(irb, scope, node, cond_block, is_comptime);
70488079
......@@ -7063,15 +8094,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70638094 } else {
70648095 payload_scope = subexpr_scope;
70658096 }
7066 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
8097 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
70678098 LValPtr, nullptr);
7068 if (err_val_ptr == irb->codegen->invalid_instruction)
8099 if (err_val_ptr == irb->codegen->invalid_inst_src)
70698100 return err_val_ptr;
7070 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr,
8101 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr,
70718102 true, false);
7072 IrBasicBlock *after_cond_block = irb->current_basic_block;
7073 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7074 IrInstruction *cond_br_inst;
8103 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8104 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
8105 IrInstSrc *cond_br_inst;
70758106 if (!instr_is_unreachable(is_err)) {
70768107 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err,
70778108 else_block, body_block, is_comptime);
......@@ -7086,15 +8117,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70868117
70878118 ir_set_cursor_at_end_and_append_block(irb, body_block);
70888119 if (var_symbol) {
7089 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node,
8120 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, payload_scope, symbol_node,
70908121 err_val_ptr, false, false);
7091 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?
7092 ir_build_ref(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
8122 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
8123 ir_build_ref_src(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
70938124 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr);
70948125 }
70958126
7096 ZigList<IrInstruction *> incoming_values = {0};
7097 ZigList<IrBasicBlock *> incoming_blocks = {0};
8127 ZigList<IrInstSrc *> incoming_values = {0};
8128 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
70988129
70998130 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope);
71008131 loop_scope->break_block = end_block;
......@@ -7108,8 +8139,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71088139 // Note the body block of the loop is not the place that lval and result_loc are used -
71098140 // it's actually in break statements, handled similarly to return statements.
71108141 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7111 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7112 if (body_result == irb->codegen->invalid_instruction)
8142 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
8143 if (body_result == irb->codegen->invalid_inst_src)
71138144 return body_result;
71148145
71158146 if (!instr_is_unreachable(body_result)) {
......@@ -7119,8 +8150,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71198150
71208151 if (continue_expr_node) {
71218152 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7122 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
7123 if (expr_result == irb->codegen->invalid_instruction)
8153 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
8154 if (expr_result == irb->codegen->invalid_inst_src)
71248155 return expr_result;
71258156 if (!instr_is_unreachable(expr_result)) {
71268157 ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));
......@@ -7136,7 +8167,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71368167 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
71378168 true, false, false, is_comptime);
71388169 Scope *err_scope = err_var->child_scope;
7139 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);
8170 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, err_symbol_node, err_val_ptr);
71408171 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr);
71418172
71428173 if (peer_parent->peers.length != 0) {
......@@ -7144,12 +8175,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71448175 }
71458176 ResultLocPeer *peer_result = create_peer_result(peer_parent);
71468177 peer_parent->peers.append(peer_result);
7147 IrInstruction *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);
7148 if (else_result == irb->codegen->invalid_instruction)
8178 IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);
8179 if (else_result == irb->codegen->invalid_inst_src)
71498180 return else_result;
71508181 if (!instr_is_unreachable(else_result))
71518182 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
7152 IrBasicBlock *after_else_block = irb->current_basic_block;
8183 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
71538184 ir_set_cursor_at_end_and_append_block(irb, end_block);
71548185 if (else_result) {
71558186 incoming_blocks.append(after_else_block);
......@@ -7162,7 +8193,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71628193 peer_parent->peers.last()->next_bb = end_block;
71638194 }
71648195
7165 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
8196 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
71668197 incoming_blocks.items, incoming_values.items, peer_parent);
71678198 return ir_expr_wrap(irb, scope, phi, result_loc);
71688199 } else if (var_symbol != nullptr) {
......@@ -7174,15 +8205,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71748205 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
71758206 true, false, false, is_comptime);
71768207 Scope *child_scope = payload_var->child_scope;
7177 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
8208 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
71788209 LValPtr, nullptr);
7179 if (maybe_val_ptr == irb->codegen->invalid_instruction)
8210 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
71808211 return maybe_val_ptr;
7181 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
7182 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node->data.while_expr.condition, maybe_val);
7183 IrBasicBlock *after_cond_block = irb->current_basic_block;
7184 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7185 IrInstruction *cond_br_inst;
8212 IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
8213 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node->data.while_expr.condition, maybe_val);
8214 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8215 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
8216 IrInstSrc *cond_br_inst;
71868217 if (!instr_is_unreachable(is_non_null)) {
71878218 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,
71888219 body_block, else_block, is_comptime);
......@@ -7196,13 +8227,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71968227 is_comptime);
71978228
71988229 ir_set_cursor_at_end_and_append_block(irb, body_block);
7199 IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false);
7200 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?
7201 ir_build_ref(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
8230 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false);
8231 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
8232 ir_build_ref_src(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
72028233 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr);
72038234
7204 ZigList<IrInstruction *> incoming_values = {0};
7205 ZigList<IrBasicBlock *> incoming_blocks = {0};
8235 ZigList<IrInstSrc *> incoming_values = {0};
8236 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72068237
72078238 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
72088239 loop_scope->break_block = end_block;
......@@ -7216,8 +8247,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72168247 // Note the body block of the loop is not the place that lval and result_loc are used -
72178248 // it's actually in break statements, handled similarly to return statements.
72188249 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7219 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7220 if (body_result == irb->codegen->invalid_instruction)
8250 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
8251 if (body_result == irb->codegen->invalid_inst_src)
72218252 return body_result;
72228253
72238254 if (!instr_is_unreachable(body_result)) {
......@@ -7227,8 +8258,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72278258
72288259 if (continue_expr_node) {
72298260 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7230 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
7231 if (expr_result == irb->codegen->invalid_instruction)
8261 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
8262 if (expr_result == irb->codegen->invalid_inst_src)
72328263 return expr_result;
72338264 if (!instr_is_unreachable(expr_result)) {
72348265 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));
......@@ -7236,7 +8267,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72368267 }
72378268 }
72388269
7239 IrInstruction *else_result = nullptr;
8270 IrInstSrc *else_result = nullptr;
72408271 if (else_node) {
72418272 ir_set_cursor_at_end_and_append_block(irb, else_block);
72428273
......@@ -7246,12 +8277,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72468277 ResultLocPeer *peer_result = create_peer_result(peer_parent);
72478278 peer_parent->peers.append(peer_result);
72488279 else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base);
7249 if (else_result == irb->codegen->invalid_instruction)
8280 if (else_result == irb->codegen->invalid_inst_src)
72508281 return else_result;
72518282 if (!instr_is_unreachable(else_result))
72528283 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
72538284 }
7254 IrBasicBlock *after_else_block = irb->current_basic_block;
8285 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
72558286 ir_set_cursor_at_end_and_append_block(irb, end_block);
72568287 if (else_result) {
72578288 incoming_blocks.append(after_else_block);
......@@ -7264,17 +8295,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72648295 peer_parent->peers.last()->next_bb = end_block;
72658296 }
72668297
7267 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
8298 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
72688299 incoming_blocks.items, incoming_values.items, peer_parent);
72698300 return ir_expr_wrap(irb, scope, phi, result_loc);
72708301 } else {
72718302 ir_set_cursor_at_end_and_append_block(irb, cond_block);
7272 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
7273 if (cond_val == irb->codegen->invalid_instruction)
8303 IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
8304 if (cond_val == irb->codegen->invalid_inst_src)
72748305 return cond_val;
7275 IrBasicBlock *after_cond_block = irb->current_basic_block;
7276 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7277 IrInstruction *cond_br_inst;
8306 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8307 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
8308 IrInstSrc *cond_br_inst;
72788309 if (!instr_is_unreachable(cond_val)) {
72798310 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
72808311 body_block, else_block, is_comptime);
......@@ -7288,8 +8319,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72888319 is_comptime);
72898320 ir_set_cursor_at_end_and_append_block(irb, body_block);
72908321
7291 ZigList<IrInstruction *> incoming_values = {0};
7292 ZigList<IrBasicBlock *> incoming_blocks = {0};
8322 ZigList<IrInstSrc *> incoming_values = {0};
8323 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72938324
72948325 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
72958326
......@@ -7305,8 +8336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73058336 // Note the body block of the loop is not the place that lval and result_loc are used -
73068337 // it's actually in break statements, handled similarly to return statements.
73078338 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7308 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7309 if (body_result == irb->codegen->invalid_instruction)
8339 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
8340 if (body_result == irb->codegen->invalid_inst_src)
73108341 return body_result;
73118342
73128343 if (!instr_is_unreachable(body_result)) {
......@@ -7316,8 +8347,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73168347
73178348 if (continue_expr_node) {
73188349 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7319 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
7320 if (expr_result == irb->codegen->invalid_instruction)
8350 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
8351 if (expr_result == irb->codegen->invalid_inst_src)
73218352 return expr_result;
73228353 if (!instr_is_unreachable(expr_result)) {
73238354 ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));
......@@ -7325,7 +8356,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73258356 }
73268357 }
73278358
7328 IrInstruction *else_result = nullptr;
8359 IrInstSrc *else_result = nullptr;
73298360 if (else_node) {
73308361 ir_set_cursor_at_end_and_append_block(irb, else_block);
73318362
......@@ -7336,12 +8367,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73368367 peer_parent->peers.append(peer_result);
73378368
73388369 else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base);
7339 if (else_result == irb->codegen->invalid_instruction)
8370 if (else_result == irb->codegen->invalid_inst_src)
73408371 return else_result;
73418372 if (!instr_is_unreachable(else_result))
73428373 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
73438374 }
7344 IrBasicBlock *after_else_block = irb->current_basic_block;
8375 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
73458376 ir_set_cursor_at_end_and_append_block(irb, end_block);
73468377 if (else_result) {
73478378 incoming_blocks.append(after_else_block);
......@@ -7354,13 +8385,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73548385 peer_parent->peers.last()->next_bb = end_block;
73558386 }
73568387
7357 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
8388 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
73588389 incoming_blocks.items, incoming_values.items, peer_parent);
73598390 return ir_expr_wrap(irb, scope, phi, result_loc);
73608391 }
73618392}
73628393
7363static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,
8394static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
73648395 ResultLoc *result_loc)
73658396{
73668397 assert(node->type == NodeTypeForExpr);
......@@ -7373,17 +8404,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
73738404
73748405 if (!elem_node) {
73758406 add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter"));
7376 return irb->codegen->invalid_instruction;
8407 return irb->codegen->invalid_inst_src;
73778408 }
73788409 assert(elem_node->type == NodeTypeSymbol);
73798410
73808411 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope);
73818412
7382 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
7383 if (array_val_ptr == irb->codegen->invalid_instruction)
8413 IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
8414 if (array_val_ptr == irb->codegen->invalid_inst_src)
73848415 return array_val_ptr;
73858416
7386 IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node,
8417 IrInstSrc *is_comptime = ir_build_const_bool(irb, parent_scope, node,
73878418 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);
73888419
73898420 AstNode *index_var_source_node;
......@@ -7400,50 +8431,50 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74008431 index_var_name = "i";
74018432 }
74028433
7403 IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0);
8434 IrInstSrc *zero = ir_build_const_usize(irb, parent_scope, node, 0);
74048435 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);
74058436 parent_scope = index_var->child_scope;
74068437
7407 IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1);
7408 IrInstruction *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);
8438 IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1);
8439 IrInstSrc *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);
74098440
74108441
7411 IrBasicBlock *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");
7412 IrBasicBlock *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");
7413 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");
7414 IrBasicBlock *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block;
7415 IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
8442 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");
8443 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");
8444 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");
8445 IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block;
8446 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
74168447
74178448 Buf *len_field_name = buf_create_from_str("len");
7418 IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);
7419 IrInstruction *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
8449 IrInstSrc *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);
8450 IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
74208451 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);
74218452
74228453 ir_set_cursor_at_end_and_append_block(irb, cond_block);
7423 IrInstruction *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);
7424 IrInstruction *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
7425 IrBasicBlock *after_cond_block = irb->current_basic_block;
7426 IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
7427 IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,
8454 IrInstSrc *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);
8455 IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
8456 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8457 IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
8458 IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,
74288459 body_block, else_block, is_comptime));
74298460
74308461 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime);
74318462
74328463 ir_set_cursor_at_end_and_append_block(irb, body_block);
74338464 Scope *elem_ptr_scope = node->data.for_expr.elem_is_ptr ? parent_scope : &spill_scope->base;
7434 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false,
8465 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false,
74358466 PtrLenSingle, nullptr);
74368467 // TODO make it an error to write to element variable or i variable.
74378468 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
74388469 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
74398470 Scope *child_scope = elem_var->child_scope;
74408471
7441 IrInstruction *var_ptr = node->data.for_expr.elem_is_ptr ?
7442 ir_build_ref(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
8472 IrInstSrc *var_ptr = node->data.for_expr.elem_is_ptr ?
8473 ir_build_ref_src(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
74438474 ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);
74448475
7445 ZigList<IrInstruction *> incoming_values = {0};
7446 ZigList<IrBasicBlock *> incoming_blocks = {0};
8476 ZigList<IrInstSrc *> incoming_values = {0};
8477 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
74478478 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
74488479 loop_scope->break_block = end_block;
74498480 loop_scope->continue_block = continue_block;
......@@ -7457,9 +8488,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74578488 // Note the body block of the loop is not the place that lval and result_loc are used -
74588489 // it's actually in break statements, handled similarly to return statements.
74598490 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7460 IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base);
7461 if (body_result == irb->codegen->invalid_instruction)
7462 return irb->codegen->invalid_instruction;
8491 IrInstSrc *body_result = ir_gen_node(irb, body_node, &loop_scope->base);
8492 if (body_result == irb->codegen->invalid_inst_src)
8493 return irb->codegen->invalid_inst_src;
74638494
74648495 if (!instr_is_unreachable(body_result)) {
74658496 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result));
......@@ -7467,11 +8498,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74678498 }
74688499
74698500 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7470 IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);
8501 IrInstSrc *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);
74718502 ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true;
74728503 ir_build_br(irb, child_scope, node, cond_block, is_comptime);
74738504
7474 IrInstruction *else_result = nullptr;
8505 IrInstSrc *else_result = nullptr;
74758506 if (else_node) {
74768507 ir_set_cursor_at_end_and_append_block(irb, else_block);
74778508
......@@ -7481,12 +8512,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74818512 ResultLocPeer *peer_result = create_peer_result(peer_parent);
74828513 peer_parent->peers.append(peer_result);
74838514 else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base);
7484 if (else_result == irb->codegen->invalid_instruction)
8515 if (else_result == irb->codegen->invalid_inst_src)
74858516 return else_result;
74868517 if (!instr_is_unreachable(else_result))
74878518 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
74888519 }
7489 IrBasicBlock *after_else_block = irb->current_basic_block;
8520 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
74908521 ir_set_cursor_at_end_and_append_block(irb, end_block);
74918522
74928523 if (else_result) {
......@@ -7500,29 +8531,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
75008531 peer_parent->peers.last()->next_bb = end_block;
75018532 }
75028533
7503 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length,
8534 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length,
75048535 incoming_blocks.items, incoming_values.items, peer_parent);
75058536 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
75068537}
75078538
7508static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8539static IrInstSrc *ir_gen_bool_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75098540 assert(node->type == NodeTypeBoolLiteral);
75108541 return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value);
75118542}
75128543
7513static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8544static IrInstSrc *ir_gen_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75148545 assert(node->type == NodeTypeEnumLiteral);
75158546 Buf *name = &node->data.enum_literal.identifier->data.str_lit.str;
75168547 return ir_build_const_enum_literal(irb, scope, node, name);
75178548}
75188549
7519static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8550static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75208551 assert(node->type == NodeTypeStringLiteral);
75218552
75228553 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);
75238554}
75248555
7525static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) {
8556static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75268557 assert(node->type == NodeTypeArrayType);
75278558
75288559 AstNode *size_node = node->data.array_type.size;
......@@ -7535,10 +8566,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75358566
75368567 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
75378568
7538 IrInstruction *sentinel;
8569 IrInstSrc *sentinel;
75398570 if (sentinel_expr != nullptr) {
75408571 sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope);
7541 if (sentinel == irb->codegen->invalid_instruction)
8572 if (sentinel == irb->codegen->invalid_inst_src)
75428573 return sentinel;
75438574 } else {
75448575 sentinel = nullptr;
......@@ -7547,42 +8578,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75478578 if (size_node) {
75488579 if (is_const) {
75498580 add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type"));
7550 return irb->codegen->invalid_instruction;
8581 return irb->codegen->invalid_inst_src;
75518582 }
75528583 if (is_volatile) {
75538584 add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type"));
7554 return irb->codegen->invalid_instruction;
8585 return irb->codegen->invalid_inst_src;
75558586 }
75568587 if (is_allow_zero) {
75578588 add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type"));
7558 return irb->codegen->invalid_instruction;
8589 return irb->codegen->invalid_inst_src;
75598590 }
75608591 if (align_expr != nullptr) {
75618592 add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type"));
7562 return irb->codegen->invalid_instruction;
8593 return irb->codegen->invalid_inst_src;
75638594 }
75648595
7565 IrInstruction *size_value = ir_gen_node(irb, size_node, comptime_scope);
7566 if (size_value == irb->codegen->invalid_instruction)
8596 IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope);
8597 if (size_value == irb->codegen->invalid_inst_src)
75678598 return size_value;
75688599
7569 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7570 if (child_type == irb->codegen->invalid_instruction)
8600 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
8601 if (child_type == irb->codegen->invalid_inst_src)
75718602 return child_type;
75728603
75738604 return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type);
75748605 } else {
7575 IrInstruction *align_value;
8606 IrInstSrc *align_value;
75768607 if (align_expr != nullptr) {
75778608 align_value = ir_gen_node(irb, align_expr, comptime_scope);
7578 if (align_value == irb->codegen->invalid_instruction)
8609 if (align_value == irb->codegen->invalid_inst_src)
75798610 return align_value;
75808611 } else {
75818612 align_value = nullptr;
75828613 }
75838614
7584 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7585 if (child_type == irb->codegen->invalid_instruction)
8615 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
8616 if (child_type == irb->codegen->invalid_inst_src)
75868617 return child_type;
75878618
75888619 return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel,
......@@ -7590,15 +8621,15 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75908621 }
75918622}
75928623
7593static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *node) {
8624static IrInstSrc *ir_gen_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75948625 assert(node->type == NodeTypeAnyFrameType);
75958626
75968627 AstNode *payload_type_node = node->data.anyframe_type.payload_type;
7597 IrInstruction *payload_type_value = nullptr;
8628 IrInstSrc *payload_type_value = nullptr;
75988629
75998630 if (payload_type_node != nullptr) {
76008631 payload_type_value = ir_gen_node(irb, payload_type_node, scope);
7601 if (payload_type_value == irb->codegen->invalid_instruction)
8632 if (payload_type_value == irb->codegen->invalid_inst_src)
76028633 return payload_type_value;
76038634
76048635 }
......@@ -7606,7 +8637,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode
76068637 return ir_build_anyframe_type(irb, scope, node, payload_type_value);
76078638}
76088639
7609static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8640static IrInstSrc *ir_gen_undefined_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
76108641 assert(node->type == NodeTypeUndefinedLiteral);
76118642 return ir_build_const_undefined(irb, scope, node);
76128643}
......@@ -7723,13 +8754,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
77238754 return SIZE_MAX;
77248755}
77258756
7726static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
8757static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
77278758 assert(node->type == NodeTypeAsmExpr);
77288759 AstNodeAsmExpr *asm_expr = &node->data.asm_expr;
77298760
7730 IrInstruction *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);
7731 if (asm_template == irb->codegen->invalid_instruction)
7732 return irb->codegen->invalid_instruction;
8761 IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);
8762 if (asm_template == irb->codegen->invalid_inst_src)
8763 return irb->codegen->invalid_inst_src;
77338764
77348765 bool is_volatile = asm_expr->volatile_token != nullptr;
77358766 bool in_fn_scope = (scope_fn_entry(scope) != nullptr);
......@@ -7738,7 +8769,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77388769 if (is_volatile) {
77398770 add_token_error(irb->codegen, node->owner, asm_expr->volatile_token,
77408771 buf_sprintf("volatile is meaningless on global assembly"));
7741 return irb->codegen->invalid_instruction;
8772 return irb->codegen->invalid_inst_src;
77428773 }
77438774
77448775 if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 ||
......@@ -7746,34 +8777,34 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77468777 {
77478778 add_node_error(irb->codegen, node,
77488779 buf_sprintf("global assembly cannot have inputs, outputs, or clobbers"));
7749 return irb->codegen->invalid_instruction;
8780 return irb->codegen->invalid_inst_src;
77508781 }
77518782
77528783 return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr,
77538784 nullptr, 0, is_volatile, true);
77548785 }
77558786
7756 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);
7757 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);
8787 IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length);
8788 IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length);
77588789 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);
77598790 size_t return_count = 0;
77608791 if (!is_volatile && asm_expr->output_list.length == 0) {
77618792 add_node_error(irb->codegen, node,
77628793 buf_sprintf("assembly expression with no output must be marked volatile"));
7763 return irb->codegen->invalid_instruction;
8794 return irb->codegen->invalid_inst_src;
77648795 }
77658796 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
77668797 AsmOutput *asm_output = asm_expr->output_list.at(i);
77678798 if (asm_output->return_type) {
77688799 return_count += 1;
77698800
7770 IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, scope);
7771 if (return_type == irb->codegen->invalid_instruction)
7772 return irb->codegen->invalid_instruction;
8801 IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope);
8802 if (return_type == irb->codegen->invalid_inst_src)
8803 return irb->codegen->invalid_inst_src;
77738804 if (return_count > 1) {
77748805 add_node_error(irb->codegen, node,
77758806 buf_sprintf("inline assembly allows up to one output value"));
7776 return irb->codegen->invalid_instruction;
8807 return irb->codegen->invalid_inst_src;
77778808 }
77788809 output_types[i] = return_type;
77798810 } else {
......@@ -7786,7 +8817,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77868817 } else {
77878818 add_node_error(irb->codegen, node,
77888819 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));
7789 return irb->codegen->invalid_instruction;
8820 return irb->codegen->invalid_inst_src;
77908821 }
77918822 }
77928823
......@@ -7796,14 +8827,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77968827 buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported."
77978828 " Compiler TODO: see https://github.com/ziglang/zig/issues/215",
77988829 buf_ptr(asm_output->asm_symbolic_name), modifier));
7799 return irb->codegen->invalid_instruction;
8830 return irb->codegen->invalid_inst_src;
78008831 }
78018832 }
78028833 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
78038834 AsmInput *asm_input = asm_expr->input_list.at(i);
7804 IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, scope);
7805 if (input_value == irb->codegen->invalid_instruction)
7806 return irb->codegen->invalid_instruction;
8835 IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope);
8836 if (input_value == irb->codegen->invalid_inst_src)
8837 return irb->codegen->invalid_inst_src;
78078838
78088839 input_list[i] = input_value;
78098840 }
......@@ -7812,7 +8843,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
78128843 output_vars, return_count, is_volatile, false);
78138844}
78148845
7815static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
8846static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
78168847 ResultLoc *result_loc)
78178848{
78188849 assert(node->type == NodeTypeIfOptional);
......@@ -7823,24 +8854,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
78238854 AstNode *else_node = node->data.test_expr.else_node;
78248855 bool var_is_ptr = node->data.test_expr.var_is_ptr;
78258856
7826 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7827 if (maybe_val_ptr == irb->codegen->invalid_instruction)
8857 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
8858 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
78288859 return maybe_val_ptr;
78298860
7830 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
7831 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val);
8861 IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
8862 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node, maybe_val);
78328863
7833 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
7834 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
7835 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
8864 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
8865 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
8866 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
78368867
7837 IrInstruction *is_comptime;
8868 IrInstSrc *is_comptime;
78388869 if (ir_should_inline(irb->exec, scope)) {
78398870 is_comptime = ir_build_const_bool(irb, scope, node, true);
78408871 } else {
78418872 is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null);
78428873 }
7843 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null,
8874 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null,
78448875 then_block, else_block, is_comptime);
78458876
78468877 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
......@@ -7856,48 +8887,48 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
78568887 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
78578888 var_symbol, is_const, is_const, is_shadowable, is_comptime);
78588889
7859 IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false);
7860 IrInstruction *var_ptr = var_is_ptr ? ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
8890 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false);
8891 IrInstSrc *var_ptr = var_is_ptr ? ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
78618892 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
78628893 var_scope = var->child_scope;
78638894 } else {
78648895 var_scope = subexpr_scope;
78658896 }
7866 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
8897 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
78678898 &peer_parent->peers.at(0)->base);
7868 if (then_expr_result == irb->codegen->invalid_instruction)
8899 if (then_expr_result == irb->codegen->invalid_inst_src)
78698900 return then_expr_result;
7870 IrBasicBlock *after_then_block = irb->current_basic_block;
8901 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
78718902 if (!instr_is_unreachable(then_expr_result))
78728903 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78738904
78748905 ir_set_cursor_at_end_and_append_block(irb, else_block);
7875 IrInstruction *else_expr_result;
8906 IrInstSrc *else_expr_result;
78768907 if (else_node) {
78778908 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
7878 if (else_expr_result == irb->codegen->invalid_instruction)
8909 if (else_expr_result == irb->codegen->invalid_inst_src)
78798910 return else_expr_result;
78808911 } else {
78818912 else_expr_result = ir_build_const_void(irb, scope, node);
78828913 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
78838914 }
7884 IrBasicBlock *after_else_block = irb->current_basic_block;
8915 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
78858916 if (!instr_is_unreachable(else_expr_result))
78868917 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78878918
78888919 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7889 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
8920 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
78908921 incoming_values[0] = then_expr_result;
78918922 incoming_values[1] = else_expr_result;
7892 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
8923 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
78938924 incoming_blocks[0] = after_then_block;
78948925 incoming_blocks[1] = after_else_block;
78958926
7896 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
8927 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
78978928 return ir_expr_wrap(irb, scope, phi, result_loc);
78988929}
78998930
7900static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
8931static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
79018932 ResultLoc *result_loc)
79028933{
79038934 assert(node->type == NodeTypeIfErrorExpr);
......@@ -7910,20 +8941,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
79108941 Buf *var_symbol = node->data.if_err_expr.var_symbol;
79118942 Buf *err_symbol = node->data.if_err_expr.err_symbol;
79128943
7913 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
7914 if (err_val_ptr == irb->codegen->invalid_instruction)
8944 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
8945 if (err_val_ptr == irb->codegen->invalid_inst_src)
79158946 return err_val_ptr;
79168947
7917 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
7918 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false);
8948 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
8949 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false);
79198950
7920 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");
7921 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");
7922 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "TryEnd");
8951 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk");
8952 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse");
8953 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd");
79238954
79248955 bool force_comptime = ir_should_inline(irb->exec, scope);
7925 IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err);
7926 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
8956 IrInstSrc *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err);
8957 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
79278958
79288959 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
79298960 result_loc, is_comptime);
......@@ -7934,29 +8965,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
79348965 Scope *var_scope;
79358966 if (var_symbol) {
79368967 bool is_shadowable = false;
7937 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
8968 IrInstSrc *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
79388969 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
79398970 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
79408971
7941 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false, false);
7942 IrInstruction *var_ptr = var_is_ptr ?
7943 ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
8972 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false);
8973 IrInstSrc *var_ptr = var_is_ptr ?
8974 ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
79448975 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
79458976 var_scope = var->child_scope;
79468977 } else {
79478978 var_scope = subexpr_scope;
79488979 }
7949 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
8980 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
79508981 &peer_parent->peers.at(0)->base);
7951 if (then_expr_result == irb->codegen->invalid_instruction)
8982 if (then_expr_result == irb->codegen->invalid_inst_src)
79528983 return then_expr_result;
7953 IrBasicBlock *after_then_block = irb->current_basic_block;
8984 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
79548985 if (!instr_is_unreachable(then_expr_result))
79558986 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79568987
79578988 ir_set_cursor_at_end_and_append_block(irb, else_block);
79588989
7959 IrInstruction *else_expr_result;
8990 IrInstSrc *else_expr_result;
79608991 if (else_node) {
79618992 Scope *err_var_scope;
79628993 if (err_symbol) {
......@@ -7965,40 +8996,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
79658996 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
79668997 err_symbol, is_const, is_const, is_shadowable, is_comptime);
79678998
7968 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);
8999 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr);
79699000 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr);
79709001 err_var_scope = var->child_scope;
79719002 } else {
79729003 err_var_scope = subexpr_scope;
79739004 }
79749005 else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base);
7975 if (else_expr_result == irb->codegen->invalid_instruction)
9006 if (else_expr_result == irb->codegen->invalid_inst_src)
79769007 return else_expr_result;
79779008 } else {
79789009 else_expr_result = ir_build_const_void(irb, scope, node);
79799010 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
79809011 }
7981 IrBasicBlock *after_else_block = irb->current_basic_block;
9012 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
79829013 if (!instr_is_unreachable(else_expr_result))
79839014 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79849015
79859016 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7986 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
9017 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
79879018 incoming_values[0] = then_expr_result;
79889019 incoming_values[1] = else_expr_result;
7989 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
9020 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
79909021 incoming_blocks[0] = after_then_block;
79919022 incoming_blocks[1] = after_else_block;
79929023
7993 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
9024 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
79949025 return ir_expr_wrap(irb, scope, phi, result_loc);
79959026}
79969027
7997static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
7998 IrBasicBlock *end_block, IrInstruction *is_comptime, IrInstruction *var_is_comptime,
7999 IrInstruction *target_value_ptr, IrInstruction **prong_values, size_t prong_values_len,
8000 ZigList<IrBasicBlock *> *incoming_blocks, ZigList<IrInstruction *> *incoming_values,
8001 IrInstructionSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)
9028static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
9029 IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime,
9030 IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len,
9031 ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values,
9032 IrInstSrcSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)
80029033{
80039034 assert(switch_node->type == NodeTypeSwitchExpr);
80049035 assert(prong_node->type == NodeTypeSwitchProng);
......@@ -8016,28 +9047,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
80169047 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
80179048 var_name, is_const, is_const, is_shadowable, var_is_comptime);
80189049 child_scope = var->child_scope;
8019 IrInstruction *var_ptr;
9050 IrInstSrc *var_ptr;
80209051 if (out_switch_else_var != nullptr) {
8021 IrInstructionSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,
9052 IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,
80229053 target_value_ptr);
80239054 *out_switch_else_var = switch_else_var;
8024 IrInstruction *payload_ptr = &switch_else_var->base;
8025 var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
9055 IrInstSrc *payload_ptr = &switch_else_var->base;
9056 var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
80269057 } else if (prong_values != nullptr) {
8027 IrInstruction *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr,
9058 IrInstSrc *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr,
80289059 prong_values, prong_values_len);
8029 var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
9060 var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
80309061 } else {
80319062 var_ptr = var_is_ptr ?
8032 ir_build_ref(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr;
9063 ir_build_ref_src(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr;
80339064 }
80349065 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr);
80359066 } else {
80369067 child_scope = scope;
80379068 }
80389069
8039 IrInstruction *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);
8040 if (expr_result == irb->codegen->invalid_instruction)
9070 IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);
9071 if (expr_result == irb->codegen->invalid_inst_src)
80419072 return false;
80429073 if (!instr_is_unreachable(expr_result))
80439074 ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime));
......@@ -8046,25 +9077,25 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
80469077 return true;
80479078}
80489079
8049static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
9080static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
80509081 ResultLoc *result_loc)
80519082{
80529083 assert(node->type == NodeTypeSwitchExpr);
80539084
80549085 AstNode *target_node = node->data.switch_expr.expr;
8055 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
8056 if (target_value_ptr == irb->codegen->invalid_instruction)
9086 IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
9087 if (target_value_ptr == irb->codegen->invalid_inst_src)
80579088 return target_value_ptr;
8058 IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);
9089 IrInstSrc *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);
80599090
8060 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "SwitchElse");
8061 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");
9091 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse");
9092 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");
80629093
80639094 size_t prong_count = node->data.switch_expr.prongs.length;
8064 ZigList<IrInstructionSwitchBrCase> cases = {0};
9095 ZigList<IrInstSrcSwitchBrCase> cases = {0};
80659096
8066 IrInstruction *is_comptime;
8067 IrInstruction *var_is_comptime;
9097 IrInstSrc *is_comptime;
9098 IrInstSrc *var_is_comptime;
80689099 if (ir_should_inline(irb->exec, scope)) {
80699100 is_comptime = ir_build_const_bool(irb, scope, node, true);
80709101 var_is_comptime = is_comptime;
......@@ -8073,11 +9104,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
80739104 var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr);
80749105 }
80759106
8076 ZigList<IrInstruction *> incoming_values = {0};
8077 ZigList<IrBasicBlock *> incoming_blocks = {0};
8078 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};
9107 ZigList<IrInstSrc *> incoming_values = {0};
9108 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
9109 ZigList<IrInstSrcCheckSwitchProngsRange> check_ranges = {0};
80799110
8080 IrInstructionSwitchElseVar *switch_else_var = nullptr;
9111 IrInstSrcSwitchElseVar *switch_else_var = nullptr;
80819112
80829113 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
80839114 peer_parent->base.id = ResultLocIdPeerParent;
......@@ -8099,7 +9130,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
80999130 if (prong_node->data.switch_prong.any_items_are_range) {
81009131 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
81019132
8102 IrInstruction *ok_bit = nullptr;
9133 IrInstSrc *ok_bit = nullptr;
81039134 AstNode *last_item_node = nullptr;
81049135 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
81059136 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
......@@ -8108,23 +9139,23 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81089139 AstNode *start_node = item_node->data.switch_range.start;
81099140 AstNode *end_node = item_node->data.switch_range.end;
81109141
8111 IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope);
8112 if (start_value == irb->codegen->invalid_instruction)
8113 return irb->codegen->invalid_instruction;
9142 IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope);
9143 if (start_value == irb->codegen->invalid_inst_src)
9144 return irb->codegen->invalid_inst_src;
81149145
8115 IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope);
8116 if (end_value == irb->codegen->invalid_instruction)
8117 return irb->codegen->invalid_instruction;
9146 IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope);
9147 if (end_value == irb->codegen->invalid_inst_src)
9148 return irb->codegen->invalid_inst_src;
81189149
8119 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();
9150 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
81209151 check_range->start = start_value;
81219152 check_range->end = end_value;
81229153
8123 IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,
9154 IrInstSrc *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,
81249155 target_value, start_value, false);
8125 IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,
9156 IrInstSrc *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,
81269157 target_value, end_value, false);
8127 IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,
9158 IrInstSrc *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,
81289159 lower_range_ok, upper_range_ok, false);
81299160 if (ok_bit) {
81309161 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false);
......@@ -8132,15 +9163,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81329163 ok_bit = both_ok;
81339164 }
81349165 } else {
8135 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);
8136 if (item_value == irb->codegen->invalid_instruction)
8137 return irb->codegen->invalid_instruction;
9166 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
9167 if (item_value == irb->codegen->invalid_inst_src)
9168 return irb->codegen->invalid_inst_src;
81389169
8139 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();
9170 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
81409171 check_range->start = item_value;
81419172 check_range->end = item_value;
81429173
8143 IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq,
9174 IrInstSrc *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq,
81449175 item_value, target_value, false);
81459176 if (ok_bit) {
81469177 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false);
......@@ -8150,12 +9181,12 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81509181 }
81519182 }
81529183
8153 IrBasicBlock *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");
8154 IrBasicBlock *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");
9184 IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");
9185 IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");
81559186
81569187 assert(ok_bit);
81579188 assert(last_item_node);
8158 IrInstruction *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit,
9189 IrInstSrc *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit,
81599190 range_block_yes, range_block_no, is_comptime));
81609191 if (peer_parent->base.source_instruction == nullptr) {
81619192 peer_parent->base.source_instruction = br_inst;
......@@ -8170,7 +9201,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81709201 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,
81719202 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
81729203 {
8173 return irb->codegen->invalid_instruction;
9204 return irb->codegen->invalid_inst_src;
81749205 }
81759206
81769207 ir_set_cursor_at_end_and_append_block(irb, range_block_no);
......@@ -8181,7 +9212,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81819212 buf_sprintf("multiple else prongs in switch expression"));
81829213 add_error_note(irb->codegen, msg, else_prong,
81839214 buf_sprintf("previous else prong is here"));
8184 return irb->codegen->invalid_instruction;
9215 return irb->codegen->invalid_inst_src;
81859216 }
81869217 else_prong = prong_node;
81879218 } else if (prong_item_count == 1 &&
......@@ -8192,7 +9223,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81929223 buf_sprintf("multiple '_' prongs in switch expression"));
81939224 add_error_note(irb->codegen, msg, underscore_prong,
81949225 buf_sprintf("previous '_' prong is here"));
8195 return irb->codegen->invalid_instruction;
9226 return irb->codegen->invalid_inst_src;
81969227 }
81979228 underscore_prong = prong_node;
81989229 } else {
......@@ -8207,11 +9238,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82079238 else
82089239 add_error_note(irb->codegen, msg, underscore_prong,
82099240 buf_sprintf("'_' prong is here"));
8210 return irb->codegen->invalid_instruction;
9241 return irb->codegen->invalid_inst_src;
82119242 }
82129243 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
82139244
8214 IrBasicBlock *prev_block = irb->current_basic_block;
9245 IrBasicBlockSrc *prev_block = irb->current_basic_block;
82159246 if (peer_parent->peers.length > 0) {
82169247 peer_parent->peers.last()->next_bb = else_block;
82179248 }
......@@ -8221,7 +9252,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82219252 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,
82229253 &switch_else_var, LValNone, &this_peer_result_loc->base))
82239254 {
8224 return irb->codegen->invalid_instruction;
9255 return irb->codegen->invalid_inst_src;
82259256 }
82269257 ir_set_cursor_at_end(irb, prev_block);
82279258 }
......@@ -8240,29 +9271,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82409271
82419272 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
82429273
8243 IrBasicBlock *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
8244 IrInstruction **items = allocate<IrInstruction *>(prong_item_count);
9274 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
9275 IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count);
82459276
82469277 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
82479278 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
82489279 assert(item_node->type != NodeTypeSwitchRange);
82499280
8250 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);
8251 if (item_value == irb->codegen->invalid_instruction)
8252 return irb->codegen->invalid_instruction;
9281 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
9282 if (item_value == irb->codegen->invalid_inst_src)
9283 return irb->codegen->invalid_inst_src;
82539284
8254 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();
9285 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
82559286 check_range->start = item_value;
82569287 check_range->end = item_value;
82579288
8258 IrInstructionSwitchBrCase *this_case = cases.add_one();
9289 IrInstSrcSwitchBrCase *this_case = cases.add_one();
82599290 this_case->value = item_value;
82609291 this_case->block = prong_block;
82619292
82629293 items[item_i] = item_value;
82639294 }
82649295
8265 IrBasicBlock *prev_block = irb->current_basic_block;
9296 IrBasicBlockSrc *prev_block = irb->current_basic_block;
82669297 if (peer_parent->peers.length > 0) {
82679298 peer_parent->peers.last()->next_bb = prong_block;
82689299 }
......@@ -8272,21 +9303,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82729303 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,
82739304 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
82749305 {
8275 return irb->codegen->invalid_instruction;
9306 return irb->codegen->invalid_inst_src;
82769307 }
82779308
82789309 ir_set_cursor_at_end(irb, prev_block);
82799310
82809311 }
82819312
8282 IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
9313 IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
82839314 check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);
82849315
8285 IrInstruction *br_instruction;
9316 IrInstSrc *br_instruction;
82869317 if (cases.length == 0) {
82879318 br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime);
82889319 } else {
8289 IrInstructionSwitchBr *switch_br = ir_build_switch_br(irb, scope, node, target_value, else_block,
9320 IrInstSrcSwitchBr *switch_br = ir_build_switch_br_src(irb, scope, node, target_value, else_block,
82909321 cases.length, cases.items, is_comptime, switch_prongs_void);
82919322 if (switch_else_var != nullptr) {
82929323 switch_else_var->switch_br = switch_br;
......@@ -8314,7 +9345,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
83149345
83159346 ir_set_cursor_at_end_and_append_block(irb, end_block);
83169347 assert(incoming_blocks.length == incoming_values.length);
8317 IrInstruction *result_instruction;
9348 IrInstSrc *result_instruction;
83189349 if (incoming_blocks.length == 0) {
83199350 result_instruction = ir_build_const_void(irb, scope, node);
83209351 } else {
......@@ -8324,7 +9355,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
83249355 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);
83259356}
83269357
8327static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) {
9358static IrInstSrc *ir_gen_comptime(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) {
83289359 assert(node->type == NodeTypeCompTime);
83299360
83309361 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);
......@@ -8332,28 +9363,28 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo
83329363 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr);
83339364}
83349365
8335static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
8336 IrInstruction *is_comptime;
9366static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
9367 IrInstSrc *is_comptime;
83379368 if (ir_should_inline(irb->exec, break_scope)) {
83389369 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
83399370 } else {
83409371 is_comptime = block_scope->is_comptime;
83419372 }
83429373
8343 IrInstruction *result_value;
9374 IrInstSrc *result_value;
83449375 if (node->data.break_expr.expr) {
83459376 ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent);
83469377 block_scope->peer_parent->peers.append(peer_result);
83479378
83489379 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval,
83499380 &peer_result->base);
8350 if (result_value == irb->codegen->invalid_instruction)
8351 return irb->codegen->invalid_instruction;
9381 if (result_value == irb->codegen->invalid_inst_src)
9382 return irb->codegen->invalid_inst_src;
83529383 } else {
83539384 result_value = ir_build_const_void(irb, break_scope, node);
83549385 }
83559386
8356 IrBasicBlock *dest_block = block_scope->end_block;
9387 IrBasicBlockSrc *dest_block = block_scope->end_block;
83579388 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
83589389
83599390 block_scope->incoming_blocks->append(irb->current_basic_block);
......@@ -8361,7 +9392,7 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop
83619392 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
83629393}
83639394
8364static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) {
9395static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *node) {
83659396 assert(node->type == NodeTypeBreak);
83669397
83679398 // Search up the scope. We'll find one of these things first:
......@@ -8376,14 +9407,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
83769407 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
83779408 if (node->data.break_expr.name != nullptr) {
83789409 add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));
8379 return irb->codegen->invalid_instruction;
9410 return irb->codegen->invalid_inst_src;
83809411 } else {
83819412 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));
8382 return irb->codegen->invalid_instruction;
9413 return irb->codegen->invalid_inst_src;
83839414 }
83849415 } else if (search_scope->id == ScopeIdDeferExpr) {
83859416 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression"));
8386 return irb->codegen->invalid_instruction;
9417 return irb->codegen->invalid_inst_src;
83879418 } else if (search_scope->id == ScopeIdLoop) {
83889419 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
83899420 if (node->data.break_expr.name == nullptr ||
......@@ -8402,32 +9433,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
84029433 }
84039434 } else if (search_scope->id == ScopeIdSuspend) {
84049435 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block"));
8405 return irb->codegen->invalid_instruction;
9436 return irb->codegen->invalid_inst_src;
84069437 }
84079438 search_scope = search_scope->parent;
84089439 }
84099440
8410 IrInstruction *is_comptime;
9441 IrInstSrc *is_comptime;
84119442 if (ir_should_inline(irb->exec, break_scope)) {
84129443 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
84139444 } else {
84149445 is_comptime = loop_scope->is_comptime;
84159446 }
84169447
8417 IrInstruction *result_value;
9448 IrInstSrc *result_value;
84189449 if (node->data.break_expr.expr) {
84199450 ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent);
84209451 loop_scope->peer_parent->peers.append(peer_result);
84219452
84229453 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope,
84239454 loop_scope->lval, &peer_result->base);
8424 if (result_value == irb->codegen->invalid_instruction)
8425 return irb->codegen->invalid_instruction;
9455 if (result_value == irb->codegen->invalid_inst_src)
9456 return irb->codegen->invalid_inst_src;
84269457 } else {
84279458 result_value = ir_build_const_void(irb, break_scope, node);
84289459 }
84299460
8430 IrBasicBlock *dest_block = loop_scope->break_block;
9461 IrBasicBlockSrc *dest_block = loop_scope->break_block;
84319462 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
84329463
84339464 loop_scope->incoming_blocks->append(irb->current_basic_block);
......@@ -8435,7 +9466,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
84359466 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
84369467}
84379468
8438static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, AstNode *node) {
9469static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstNode *node) {
84399470 assert(node->type == NodeTypeContinue);
84409471
84419472 // Search up the scope. We'll find one of these things first:
......@@ -8451,14 +9482,14 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
84519482 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
84529483 if (node->data.continue_expr.name != nullptr) {
84539484 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));
8454 return irb->codegen->invalid_instruction;
9485 return irb->codegen->invalid_inst_src;
84559486 } else {
84569487 add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop"));
8457 return irb->codegen->invalid_instruction;
9488 return irb->codegen->invalid_inst_src;
84589489 }
84599490 } else if (search_scope->id == ScopeIdDeferExpr) {
84609491 add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression"));
8461 return irb->codegen->invalid_instruction;
9492 return irb->codegen->invalid_inst_src;
84629493 } else if (search_scope->id == ScopeIdLoop) {
84639494 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
84649495 if (node->data.continue_expr.name == nullptr ||
......@@ -8474,7 +9505,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
84749505 search_scope = search_scope->parent;
84759506 }
84769507
8477 IrInstruction *is_comptime;
9508 IrInstSrc *is_comptime;
84789509 if (ir_should_inline(irb->exec, continue_scope)) {
84799510 is_comptime = ir_build_const_bool(irb, continue_scope, node, true);
84809511 } else {
......@@ -8486,17 +9517,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
84869517 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
84879518 }
84889519
8489 IrBasicBlock *dest_block = loop_scope->continue_block;
9520 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
84909521 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
84919522 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
84929523}
84939524
8494static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) {
9525static IrInstSrc *ir_gen_error_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
84959526 assert(node->type == NodeTypeErrorType);
84969527 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set);
84979528}
84989529
8499static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9530static IrInstSrc *ir_gen_defer(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
85009531 assert(node->type == NodeTypeDefer);
85019532
85029533 ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope);
......@@ -8508,7 +9539,7 @@ static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode
85089539 return ir_build_const_void(irb, parent_scope, node);
85099540}
85109541
8511static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
9542static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
85129543 assert(node->type == NodeTypeSliceExpr);
85139544
85149545 AstNodeSliceExpr *slice_expr = &node->data.slice_expr;
......@@ -8517,38 +9548,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node,
85179548 AstNode *end_node = slice_expr->end;
85189549 AstNode *sentinel_node = slice_expr->sentinel;
85199550
8520 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
8521 if (ptr_value == irb->codegen->invalid_instruction)
8522 return irb->codegen->invalid_instruction;
9551 IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
9552 if (ptr_value == irb->codegen->invalid_inst_src)
9553 return irb->codegen->invalid_inst_src;
85239554
8524 IrInstruction *start_value = ir_gen_node(irb, start_node, scope);
8525 if (start_value == irb->codegen->invalid_instruction)
8526 return irb->codegen->invalid_instruction;
9555 IrInstSrc *start_value = ir_gen_node(irb, start_node, scope);
9556 if (start_value == irb->codegen->invalid_inst_src)
9557 return irb->codegen->invalid_inst_src;
85279558
8528 IrInstruction *end_value;
9559 IrInstSrc *end_value;
85299560 if (end_node) {
85309561 end_value = ir_gen_node(irb, end_node, scope);
8531 if (end_value == irb->codegen->invalid_instruction)
8532 return irb->codegen->invalid_instruction;
9562 if (end_value == irb->codegen->invalid_inst_src)
9563 return irb->codegen->invalid_inst_src;
85339564 } else {
85349565 end_value = nullptr;
85359566 }
85369567
8537 IrInstruction *sentinel_value;
9568 IrInstSrc *sentinel_value;
85389569 if (sentinel_node) {
85399570 sentinel_value = ir_gen_node(irb, sentinel_node, scope);
8540 if (sentinel_value == irb->codegen->invalid_instruction)
8541 return irb->codegen->invalid_instruction;
9571 if (sentinel_value == irb->codegen->invalid_inst_src)
9572 return irb->codegen->invalid_inst_src;
85429573 } else {
85439574 sentinel_value = nullptr;
85449575 }
85459576
8546 IrInstruction *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value,
9577 IrInstSrc *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value,
85479578 sentinel_value, true, result_loc);
85489579 return ir_lval_wrap(irb, scope, slice, lval, result_loc);
85499580}
85509581
8551static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,
9582static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
85529583 ResultLoc *result_loc)
85539584{
85549585 assert(node->type == NodeTypeCatchExpr);
......@@ -8562,29 +9593,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
85629593 assert(var_node->type == NodeTypeSymbol);
85639594 Buf *var_name = var_node->data.symbol_expr.symbol;
85649595 add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
8565 return irb->codegen->invalid_instruction;
9596 return irb->codegen->invalid_inst_src;
85669597 }
85679598 return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc);
85689599 }
85699600
85709601
8571 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
8572 if (err_union_ptr == irb->codegen->invalid_instruction)
8573 return irb->codegen->invalid_instruction;
9602 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
9603 if (err_union_ptr == irb->codegen->invalid_inst_src)
9604 return irb->codegen->invalid_inst_src;
85749605
8575 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false);
9606 IrInstSrc *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false);
85769607
8577 IrInstruction *is_comptime;
9608 IrInstSrc *is_comptime;
85789609 if (ir_should_inline(irb->exec, parent_scope)) {
85799610 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
85809611 } else {
85819612 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err);
85829613 }
85839614
8584 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");
8585 IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");
8586 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");
8587 IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);
9615 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");
9616 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");
9617 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");
9618 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);
85889619
85899620 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc,
85909621 is_comptime);
......@@ -8600,33 +9631,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
86009631 ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name,
86019632 is_const, is_const, is_shadowable, is_comptime);
86029633 err_scope = var->child_scope;
8603 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
9634 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr);
86049635 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);
86059636 } else {
86069637 err_scope = subexpr_scope;
86079638 }
8608 IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
8609 if (err_result == irb->codegen->invalid_instruction)
8610 return irb->codegen->invalid_instruction;
8611 IrBasicBlock *after_err_block = irb->current_basic_block;
9639 IrInstSrc *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
9640 if (err_result == irb->codegen->invalid_inst_src)
9641 return irb->codegen->invalid_inst_src;
9642 IrBasicBlockSrc *after_err_block = irb->current_basic_block;
86129643 if (!instr_is_unreachable(err_result))
86139644 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
86149645
86159646 ir_set_cursor_at_end_and_append_block(irb, ok_block);
8616 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false, false);
8617 IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
9647 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false);
9648 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
86189649 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
8619 IrBasicBlock *after_ok_block = irb->current_basic_block;
9650 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
86209651 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
86219652
86229653 ir_set_cursor_at_end_and_append_block(irb, end_block);
8623 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
9654 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
86249655 incoming_values[0] = err_result;
86259656 incoming_values[1] = unwrapped_payload;
8626 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
9657 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
86279658 incoming_blocks[0] = after_err_block;
86289659 incoming_blocks[1] = after_ok_block;
8629 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
9660 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
86309661 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
86319662}
86329663
......@@ -8644,7 +9675,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o
86449675 return true;
86459676}
86469677
8647static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
9678static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name,
86489679 Scope *scope, AstNode *source_node, Buf *out_bare_name)
86499680{
86509681 if (exec != nullptr && exec->name) {
......@@ -8673,7 +9704,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char
86739704 }
86749705}
86759706
8676static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9707static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
86779708 assert(node->type == NodeTypeContainerDecl);
86789709
86799710 ContainerKind kind = node->data.container_decl.kind;
......@@ -8798,7 +9829,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {
87989829 }
87999830}
88009831
8801static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9832static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
88029833 assert(node->type == NodeTypeErrorSetDecl);
88039834
88049835 uint32_t err_count = node->data.err_set_decl.decls.length;
......@@ -8841,7 +9872,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
88419872 buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));
88429873 add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node),
88439874 buf_sprintf("other error here"));
8844 return irb->codegen->invalid_instruction;
9875 return irb->codegen->invalid_inst_src;
88459876 }
88469877 errors[err->value] = err;
88479878 }
......@@ -8849,11 +9880,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
88499880 return ir_build_const_type(irb, parent_scope, node, err_set_type);
88509881}
88519882
8852static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9883static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
88539884 assert(node->type == NodeTypeFnProto);
88549885
88559886 size_t param_count = node->data.fn_proto.params.length;
8856 IrInstruction **param_types = allocate<IrInstruction*>(param_count);
9887 IrInstSrc **param_types = allocate<IrInstSrc*>(param_count);
88579888
88589889 bool is_var_args = false;
88599890 for (size_t i = 0; i < param_count; i += 1) {
......@@ -8864,59 +9895,59 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
88649895 }
88659896 if (param_node->data.param_decl.var_token == nullptr) {
88669897 AstNode *type_node = param_node->data.param_decl.type;
8867 IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope);
8868 if (type_value == irb->codegen->invalid_instruction)
8869 return irb->codegen->invalid_instruction;
9898 IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope);
9899 if (type_value == irb->codegen->invalid_inst_src)
9900 return irb->codegen->invalid_inst_src;
88709901 param_types[i] = type_value;
88719902 } else {
88729903 param_types[i] = nullptr;
88739904 }
88749905 }
88759906
8876 IrInstruction *align_value = nullptr;
9907 IrInstSrc *align_value = nullptr;
88779908 if (node->data.fn_proto.align_expr != nullptr) {
88789909 align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope);
8879 if (align_value == irb->codegen->invalid_instruction)
8880 return irb->codegen->invalid_instruction;
9910 if (align_value == irb->codegen->invalid_inst_src)
9911 return irb->codegen->invalid_inst_src;
88819912 }
88829913
8883 IrInstruction *callconv_value = nullptr;
9914 IrInstSrc *callconv_value = nullptr;
88849915 if (node->data.fn_proto.callconv_expr != nullptr) {
88859916 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);
8886 if (callconv_value == irb->codegen->invalid_instruction)
8887 return irb->codegen->invalid_instruction;
9917 if (callconv_value == irb->codegen->invalid_inst_src)
9918 return irb->codegen->invalid_inst_src;
88889919 }
88899920
8890 IrInstruction *return_type;
9921 IrInstSrc *return_type;
88919922 if (node->data.fn_proto.return_var_token == nullptr) {
88929923 if (node->data.fn_proto.return_type == nullptr) {
88939924 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
88949925 } else {
88959926 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
8896 if (return_type == irb->codegen->invalid_instruction)
8897 return irb->codegen->invalid_instruction;
9927 if (return_type == irb->codegen->invalid_inst_src)
9928 return irb->codegen->invalid_inst_src;
88989929 }
88999930 } else {
89009931 add_node_error(irb->codegen, node,
89019932 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));
8902 return irb->codegen->invalid_instruction;
9933 return irb->codegen->invalid_inst_src;
89039934 //return_type = nullptr;
89049935 }
89059936
89069937 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);
89079938}
89089939
8909static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {
9940static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
89109941 assert(node->type == NodeTypeResume);
89119942
8912 IrInstruction *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);
8913 if (target_inst == irb->codegen->invalid_instruction)
8914 return irb->codegen->invalid_instruction;
9943 IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);
9944 if (target_inst == irb->codegen->invalid_inst_src)
9945 return irb->codegen->invalid_inst_src;
89159946
8916 return ir_build_resume(irb, scope, node, target_inst);
9947 return ir_build_resume_src(irb, scope, node, target_inst);
89179948}
89189949
8919static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
9950static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
89209951 ResultLoc *result_loc)
89219952{
89229953 assert(node->type == NodeTypeAwaitExpr);
......@@ -8937,7 +9968,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
89379968 ZigFn *fn_entry = exec_fn_entry(irb->exec);
89389969 if (!fn_entry) {
89399970 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
8940 return irb->codegen->invalid_instruction;
9971 return irb->codegen->invalid_inst_src;
89419972 }
89429973 ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope);
89439974 if (existing_suspend_scope) {
......@@ -8946,24 +9977,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
89469977 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here"));
89479978 existing_suspend_scope->reported_err = true;
89489979 }
8949 return irb->codegen->invalid_instruction;
9980 return irb->codegen->invalid_inst_src;
89509981 }
89519982
8952 IrInstruction *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
8953 if (target_inst == irb->codegen->invalid_instruction)
8954 return irb->codegen->invalid_instruction;
9983 IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
9984 if (target_inst == irb->codegen->invalid_inst_src)
9985 return irb->codegen->invalid_inst_src;
89559986
8956 IrInstruction *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc);
9987 IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc);
89579988 return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);
89589989}
89599990
8960static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9991static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
89619992 assert(node->type == NodeTypeSuspend);
89629993
89639994 ZigFn *fn_entry = exec_fn_entry(irb->exec);
89649995 if (!fn_entry) {
89659996 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
8966 return irb->codegen->invalid_instruction;
9997 return irb->codegen->invalid_inst_src;
89679998 }
89689999 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);
896910000 if (existing_suspend_scope) {
......@@ -8972,21 +10003,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
897210003 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));
897310004 existing_suspend_scope->reported_err = true;
897410005 }
8975 return irb->codegen->invalid_instruction;
10006 return irb->codegen->invalid_inst_src;
897610007 }
897710008
8978 IrInstructionSuspendBegin *begin = ir_build_suspend_begin(irb, parent_scope, node);
10009 IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node);
897910010 if (node->data.suspend.block != nullptr) {
898010011 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);
898110012 Scope *child_scope = &suspend_scope->base;
8982 IrInstruction *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);
10013 IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);
898310014 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
898410015 }
898510016
8986 return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin));
10017 return ir_mark_gen(ir_build_suspend_finish_src(irb, parent_scope, node, begin));
898710018}
898810019
8989static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,
10020static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope,
899010021 LVal lval, ResultLoc *result_loc)
899110022{
899210023 assert(scope);
......@@ -9035,39 +10066,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
903510066 return ir_gen_return(irb, scope, node, lval, result_loc);
903610067 case NodeTypeFieldAccessExpr:
903710068 {
9038 IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node);
9039 if (ptr_instruction == irb->codegen->invalid_instruction)
10069 IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node);
10070 if (ptr_instruction == irb->codegen->invalid_inst_src)
904010071 return ptr_instruction;
904110072 if (lval == LValPtr)
904210073 return ptr_instruction;
904310074
9044 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
10075 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
904510076 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
904610077 }
904710078 case NodeTypePtrDeref: {
904810079 AstNode *expr_node = node->data.ptr_deref_expr.target;
9049 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
9050 if (value == irb->codegen->invalid_instruction)
10080 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
10081 if (value == irb->codegen->invalid_inst_src)
905110082 return value;
905210083
905310084 // We essentially just converted any lvalue from &(x.*) to (&x).*;
905410085 // this inhibits checking that x is a pointer later, so we directly
905510086 // record whether the pointer check is needed
9056 IrInstruction *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc);
10087 IrInstSrc *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc);
905710088 return ir_expr_wrap(irb, scope, un_op, result_loc);
905810089 }
905910090 case NodeTypeUnwrapOptional: {
906010091 AstNode *expr_node = node->data.unwrap_optional.expr;
906110092
9062 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
9063 if (maybe_ptr == irb->codegen->invalid_instruction)
9064 return irb->codegen->invalid_instruction;
10093 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
10094 if (maybe_ptr == irb->codegen->invalid_inst_src)
10095 return irb->codegen->invalid_inst_src;
906510096
9066 IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false);
10097 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false);
906710098 if (lval == LValPtr)
906810099 return unwrapped_ptr;
906910100
9070 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
10101 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
907110102 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
907210103 }
907310104 case NodeTypeBoolLiteral:
......@@ -9125,7 +10156,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
912510156 case NodeTypeInferredArrayType:
912610157 add_node_error(irb->codegen, node,
912710158 buf_sprintf("inferred array size invalid here"));
9128 return irb->codegen->invalid_instruction;
10159 return irb->codegen->invalid_inst_src;
912910160 case NodeTypeVarFieldType:
913010161 return ir_lval_wrap(irb, scope,
913110162 ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc);
......@@ -9139,7 +10170,7 @@ static ResultLoc *no_result_loc(void) {
913910170 return &result_loc_none->base;
914010171}
914110172
9142static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
10173static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
914310174 ResultLoc *result_loc)
914410175{
914510176 if (result_loc == nullptr) {
......@@ -9156,8 +10187,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
915610187 } else {
915710188 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;
915810189 }
9159 IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
9160 if (result == irb->codegen->invalid_instruction) {
10190 IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
10191 if (result == irb->codegen->invalid_inst_src) {
916110192 if (irb->exec->first_err_trace_msg == nullptr) {
916210193 irb->exec->first_err_trace_msg = irb->codegen->trace_err;
916310194 }
......@@ -9165,11 +10196,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
916510196 return result;
916610197}
916710198
9168static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {
10199static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) {
916910200 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
917010201}
917110202
9172static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {
10203static void invalidate_exec(IrExecutableSrc *exec, ErrorMsg *msg) {
10204 if (exec->first_err_trace_msg != nullptr)
10205 return;
10206
10207 exec->first_err_trace_msg = msg;
10208
10209 for (size_t i = 0; i < exec->tld_list.length; i += 1) {
10210 exec->tld_list.items[i]->resolution = TldResolutionInvalid;
10211 }
10212}
10213
10214static void invalidate_exec_gen(IrExecutableGen *exec, ErrorMsg *msg) {
917310215 if (exec->first_err_trace_msg != nullptr)
917410216 return;
917510217
......@@ -9183,24 +10225,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {
918310225 invalidate_exec(exec->source_exec, msg);
918410226}
918510227
9186bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) {
10228
10229bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable) {
918710230 assert(node->owner);
918810231
9189 IrBuilder ir_builder = {0};
9190 IrBuilder *irb = &ir_builder;
10232 IrBuilderSrc ir_builder = {0};
10233 IrBuilderSrc *irb = &ir_builder;
919110234
919210235 irb->codegen = codegen;
919310236 irb->exec = ir_executable;
919410237 irb->main_block_node = node;
919510238
9196 IrBasicBlock *entry_block = ir_create_basic_block(irb, scope, "Entry");
10239 IrBasicBlockSrc *entry_block = ir_create_basic_block(irb, scope, "Entry");
919710240 ir_set_cursor_at_end_and_append_block(irb, entry_block);
919810241 // Entry block gets a reference because we enter it to begin.
919910242 ir_ref_bb(irb->current_basic_block);
920010243
9201 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
10244 IrInstSrc *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
920210245
9203 if (result == irb->codegen->invalid_instruction)
10246 if (result == irb->codegen->invalid_inst_src)
920410247 return false;
920510248
920610249 if (irb->exec->first_err_trace_msg != nullptr) {
......@@ -9209,9 +10252,9 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
920910252 }
921010253
921110254 if (!instr_is_unreachable(result)) {
9212 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr));
10255 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr));
921310256 // no need for save_err_ret_addr because this cannot return error
9214 ir_mark_gen(ir_build_return(irb, scope, result->source_node, result));
10257 ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result));
921510258 }
921610259
921710260 return true;
......@@ -9220,7 +10263,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
922010263bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
922110264 assert(fn_entry);
922210265
9223 IrExecutable *ir_executable = fn_entry->ir_executable;
10266 IrExecutableSrc *ir_executable = fn_entry->ir_executable;
922410267 AstNode *body_node = fn_entry->body_node;
922510268
922610269 assert(fn_entry->child_scope);
......@@ -9228,14 +10271,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
922810271 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);
922910272}
923010273
9231static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) {
10274static void ir_add_call_stack_errors_gen(CodeGen *codegen, IrExecutableGen *exec, ErrorMsg *err_msg, int limit) {
10275 if (!exec || !exec->source_node || limit < 0) return;
10276 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
10277
10278 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
10279}
10280
10281static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutableSrc *exec, ErrorMsg *err_msg, int limit) {
923210282 if (!exec || !exec->source_node || limit < 0) return;
923310283 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
923410284
9235 ir_add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);
10285 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
923610286}
923710287
9238static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg) {
10288static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg) {
923910289 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
924010290 invalidate_exec(exec, err_msg);
924110291 if (exec->parent_exec) {
......@@ -9244,26 +10294,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo
924410294 return err_msg;
924510295}
924610296
10297static ErrorMsg *exec_add_error_node_gen(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, Buf *msg) {
10298 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
10299 invalidate_exec_gen(exec, err_msg);
10300 if (exec->parent_exec) {
10301 ir_add_call_stack_errors_gen(codegen, exec, err_msg, 10);
10302 }
10303 return err_msg;
10304}
10305
924710306static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) {
9248 return exec_add_error_node(ira->codegen, ira->new_irb.exec, source_node, msg);
10307 return exec_add_error_node_gen(ira->codegen, ira->new_irb.exec, source_node, msg);
924910308}
925010309
925110310static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) {
925210311 if (ira != nullptr)
9253 return exec_add_error_node(codegen, ira->new_irb.exec, source_node, msg);
10312 return exec_add_error_node_gen(codegen, ira->new_irb.exec, source_node, msg);
925410313 else
925510314 return add_node_error(codegen, source_node, msg);
925610315}
925710316
9258static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
10317static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) {
925910318 return ir_add_error_node(ira, source_instruction->source_node, msg);
926010319}
926110320
9262static void ir_assert(bool ok, IrInstruction *source_instruction) {
10321static void ir_assert(bool ok, IrInst *source_instruction) {
926310322 if (ok) return;
926410323 src_assert(ok, source_instruction->source_node);
926510324}
926610325
10326static void ir_assert_gen(bool ok, IrInstGen *source_instruction) {
10327 if (ok) return;
10328 src_assert(ok, source_instruction->base.source_node);
10329}
10330
926710331// This function takes a comptime ptr and makes the child const value conform to the type
926810332// described by the pointer.
926910333static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
......@@ -9309,43 +10373,43 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
930910373 return val;
931010374}
931110375
9312static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
9313 IrBasicBlock *bb = exec->basic_block_list.at(0);
10376static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutableGen *exec) {
10377 IrBasicBlockGen *bb = exec->basic_block_list.at(0);
931410378 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
9315 IrInstruction *instruction = bb->instruction_list.at(i);
9316 if (instruction->id == IrInstructionIdReturn) {
9317 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
9318 IrInstruction *operand = ret_inst->operand;
10379 IrInstGen *instruction = bb->instruction_list.at(i);
10380 if (instruction->id == IrInstGenIdReturn) {
10381 IrInstGenReturn *ret_inst = (IrInstGenReturn *)instruction;
10382 IrInstGen *operand = ret_inst->operand;
931910383 if (operand->value->special == ConstValSpecialRuntime) {
9320 exec_add_error_node(codegen, exec, operand->source_node,
10384 exec_add_error_node_gen(codegen, exec, operand->base.source_node,
932110385 buf_sprintf("unable to evaluate constant expression"));
9322 return codegen->invalid_instruction->value;
10386 return codegen->invalid_inst_gen->value;
932310387 }
932410388 return operand->value;
9325 } else if (ir_has_side_effects(instruction)) {
10389 } else if (ir_inst_gen_has_side_effects(instruction)) {
932610390 if (instr_is_comptime(instruction)) {
932710391 switch (instruction->id) {
9328 case IrInstructionIdUnwrapErrPayload:
9329 case IrInstructionIdUnionFieldPtr:
10392 case IrInstGenIdUnwrapErrPayload:
10393 case IrInstGenIdUnionFieldPtr:
933010394 continue;
933110395 default:
933210396 break;
933310397 }
933410398 }
9335 if (get_scope_typeof(instruction->scope) != nullptr) {
10399 if (get_scope_typeof(instruction->base.scope) != nullptr) {
933610400 // doesn't count, it's inside a @TypeOf()
933710401 continue;
933810402 }
9339 exec_add_error_node(codegen, exec, instruction->source_node,
10403 exec_add_error_node_gen(codegen, exec, instruction->base.source_node,
934010404 buf_sprintf("unable to evaluate constant expression"));
9341 return codegen->invalid_instruction->value;
10405 return codegen->invalid_inst_gen->value;
934210406 }
934310407 }
934410408 zig_unreachable();
934510409}
934610410
9347static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) {
9348 if (ir_should_inline(ira->new_irb.exec, source_instruction->scope)) {
10411static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) {
10412 if (ir_should_inline(ira->old_irb.exec, source_instruction->scope)) {
934910413 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));
935010414 return false;
935110415 }
......@@ -10079,7 +11143,7 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {
1007911143 }
1008011144}
1008111145
10082static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type,
11146static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction, ZigType *other_type,
1008311147 bool explicit_cast)
1008411148{
1008511149 if (type_is_invalid(other_type)) {
......@@ -10173,7 +11237,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1017311237 }
1017411238 Buf *val_buf = buf_alloc();
1017511239 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10176 ir_add_error(ira, instruction,
11240 ir_add_error_node(ira, instruction->base.source_node,
1017711241 buf_sprintf("integer value %s has no representation in type '%s'",
1017811242 buf_ptr(val_buf),
1017911243 buf_ptr(&other_type->name)));
......@@ -10268,7 +11332,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1026811332 }
1026911333 Buf *val_buf = buf_alloc();
1027011334 float_append_buf(val_buf, const_val);
10271 ir_add_error(ira, instruction,
11335 ir_add_error_node(ira, instruction->base.source_node,
1027211336 buf_sprintf("cast of value %s to type '%s' loses information",
1027311337 buf_ptr(val_buf),
1027411338 buf_ptr(&other_type->name)));
......@@ -10277,7 +11341,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1027711341 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
1027811342 Buf *val_buf = buf_alloc();
1027911343 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10280 ir_add_error(ira, instruction,
11344 ir_add_error_node(ira, instruction->base.source_node,
1028111345 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
1028211346 buf_ptr(val_buf),
1028311347 buf_ptr(&other_type->name)));
......@@ -10298,7 +11362,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1029811362 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
1029911363 Buf *val_buf = buf_alloc();
1030011364 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10301 ir_add_error(ira, instruction,
11365 ir_add_error_node(ira, instruction->base.source_node,
1030211366 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
1030311367 buf_ptr(val_buf),
1030411368 buf_ptr(&child_type->name)));
......@@ -10321,7 +11385,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1032111385 Buf *val_buf = buf_alloc();
1032211386 float_append_buf(val_buf, const_val);
1032311387
10324 ir_add_error(ira, instruction,
11388 ir_add_error_node(ira, instruction->base.source_node,
1032511389 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",
1032611390 buf_ptr(val_buf),
1032711391 buf_ptr(&other_type->name)));
......@@ -10351,7 +11415,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1035111415 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
1035211416 }
1035311417
10354 ir_add_error(ira, instruction,
11418 ir_add_error_node(ira, instruction->base.source_node,
1035511419 buf_sprintf("%s value %s cannot be coerced to type '%s'",
1035611420 num_lit_str,
1035711421 buf_ptr(val_buf),
......@@ -10805,11 +11869,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *
1080511869}
1080611870
1080711871static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,
10808 IrInstruction **instructions, size_t instruction_count)
11872 IrInstGen **instructions, size_t instruction_count)
1080911873{
1081011874 Error err;
1081111875 assert(instruction_count >= 1);
10812 IrInstruction *prev_inst;
11876 IrInstGen *prev_inst;
1081311877 size_t i = 0;
1081411878 for (;;) {
1081511879 prev_inst = instructions[i];
......@@ -10829,7 +11893,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1082911893 size_t errors_count = 0;
1083011894 ZigType *err_set_type = nullptr;
1083111895 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
10832 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) {
11896 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) {
1083311897 return ira->codegen->builtin_types.entry_invalid;
1083411898 }
1083511899 if (type_is_global_error_set(prev_inst->value->type)) {
......@@ -10849,7 +11913,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1084911913 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);
1085011914 bool convert_to_const_slice = false;
1085111915 for (; i < instruction_count; i += 1) {
10852 IrInstruction *cur_inst = instructions[i];
11916 IrInstGen *cur_inst = instructions[i];
1085311917 ZigType *cur_type = cur_inst->value->type;
1085411918 ZigType *prev_type = prev_inst->value->type;
1085511919
......@@ -10871,14 +11935,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1087111935 }
1087211936
1087311937 if (prev_type->id == ZigTypeIdErrorSet) {
10874 ir_assert(err_set_type != nullptr, prev_inst);
11938 ir_assert_gen(err_set_type != nullptr, prev_inst);
1087511939 if (cur_type->id == ZigTypeIdErrorSet) {
1087611940 if (type_is_global_error_set(err_set_type)) {
1087711941 continue;
1087811942 }
1087911943 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
1088011944 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
10881 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
11945 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
1088211946 return ira->codegen->builtin_types.entry_invalid;
1088311947 }
1088411948 if (!allow_infer && type_is_global_error_set(cur_type)) {
......@@ -10946,7 +12010,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1094612010 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
1094712011 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
1094812012 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
10949 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
12013 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
1095012014 return ira->codegen->builtin_types.entry_invalid;
1095112015 }
1095212016 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {
......@@ -11001,7 +12065,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1100112065 if (cur_type->id == ZigTypeIdErrorSet) {
1100212066 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
1100312067 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
11004 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
12068 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
1100512069 return ira->codegen->builtin_types.entry_invalid;
1100612070 }
1100712071 if (!allow_infer && type_is_global_error_set(cur_type)) {
......@@ -11024,7 +12088,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1102412088 err_set_type = cur_type;
1102512089 }
1102612090
11027 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) {
12091 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) {
1102812092 return ira->codegen->builtin_types.entry_invalid;
1102912093 }
1103012094
......@@ -11087,11 +12151,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1108712151 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&
1108812152 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
1108912153
11090 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
12154 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) {
1109112155 return ira->codegen->builtin_types.entry_invalid;
1109212156 }
1109312157
11094 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
12158 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
1109512159 return ira->codegen->builtin_types.entry_invalid;
1109612160 }
1109712161
......@@ -11268,7 +12332,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1126812332 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
1126912333 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
1127012334 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
11271 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
12335 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
1127212336 return ira->codegen->builtin_types.entry_invalid;
1127312337 }
1127412338 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||
......@@ -11463,9 +12527,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1146312527 ErrorMsg *msg = ir_add_error_node(ira, source_node,
1146412528 buf_sprintf("incompatible types: '%s' and '%s'",
1146512529 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));
11466 add_error_note(ira->codegen, msg, prev_inst->source_node,
12530 add_error_note(ira->codegen, msg, prev_inst->base.source_node,
1146712531 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));
11468 add_error_note(ira->codegen, msg, cur_inst->source_node,
12532 add_error_note(ira->codegen, msg, cur_inst->base.source_node,
1146912533 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));
1147012534
1147112535 return ira->codegen->builtin_types.entry_invalid;
......@@ -11535,7 +12599,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1153512599 }
1153612600}
1153712601
11538static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
12602static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
1153912603 CastOp cast_op,
1154012604 ZigValue *other_val, ZigType *other_type,
1154112605 ZigValue *const_val, ZigType *new_type)
......@@ -11635,58 +12699,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
1163512699 return true;
1163612700}
1163712701
11638static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, ZigType *ty) {
11639 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
11640 old_instruction->scope, old_instruction->source_node);
11641 IrInstruction *new_instruction = &const_instruction->base;
12702static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
12703 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
12704 inst->scope, inst->source_node);
12705 IrInstGen *new_instruction = &const_instruction->base;
1164212706 new_instruction->value->type = ty;
1164312707 new_instruction->value->special = ConstValSpecialStatic;
1164412708 return new_instruction;
1164512709}
1164612710
11647static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) {
11648 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb,
12711static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) {
12712 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
1164912713 old_instruction->scope, old_instruction->source_node);
1165012714 return &const_instruction->base;
1165112715}
1165212716
11653// This function initializes the new IrInstruction with the provided ZigValue,
12717// This function initializes the new IrInstGen with the provided ZigValue,
1165412718// rather than creating a new one.
11655static IrInstruction *ir_const_move(IrAnalyze *ira, IrInstruction *old_instruction, ZigValue *val) {
11656 IrInstruction *result = ir_const_noval(ira, old_instruction);
12719static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) {
12720 IrInstGen *result = ir_const_noval(ira, old_instruction);
1165712721 result->value = val;
1165812722 return result;
1165912723}
1166012724
11661static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
12725static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
1166212726 ZigType *wanted_type, CastOp cast_op)
1166312727{
1166412728 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
11665 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12729 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1166612730 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
1166712731 result->value, wanted_type))
1166812732 {
11669 return ira->codegen->invalid_instruction;
12733 return ira->codegen->invalid_inst_gen;
1167012734 }
1167112735 return result;
1167212736 } else {
11673 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);
11674 result->value->type = wanted_type;
11675 return result;
12737 return ir_build_cast(ira, source_instr, wanted_type, value, cast_op);
1167612738 }
1167712739}
1167812740
11679static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,
11680 IrInstruction *value, ZigType *wanted_type)
12741static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr,
12742 IrInstGen *value, ZigType *wanted_type)
1168112743{
11682 assert(value->value->type->id == ZigTypeIdPointer);
12744 ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr);
1168312745
1168412746 Error err;
1168512747
1168612748 if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type,
1168712749 ResolveStatusAlignmentKnown)))
1168812750 {
11689 return ira->codegen->invalid_instruction;
12751 return ira->codegen->invalid_inst_gen;
1169012752 }
1169112753
1169212754 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));
......@@ -11694,9 +12756,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
1169412756 if (instr_is_comptime(value)) {
1169512757 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);
1169612758 if (pointee == nullptr)
11697 return ira->codegen->invalid_instruction;
12759 return ira->codegen->invalid_inst_gen;
1169812760 if (pointee->special != ConstValSpecialRuntime) {
11699 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12761 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1170012762 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
1170112763 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
1170212764 result->value->data.x_ptr.data.base_array.array_val = pointee;
......@@ -11705,21 +12767,18 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
1170512767 }
1170612768 }
1170712769
11708 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
11709 wanted_type, value, CastOpBitCast);
11710 result->value->type = wanted_type;
11711 return result;
12770 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
1171212771}
1171312772
11714static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
11715 IrInstruction *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
12773static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr,
12774 IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
1171612775{
1171712776 Error err;
1171812777
1171912778 if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type,
1172012779 ResolveStatusAlignmentKnown)))
1172112780 {
11722 return ira->codegen->invalid_instruction;
12781 return ira->codegen->invalid_inst_gen;
1172312782 }
1172412783
1172512784 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type));
......@@ -11727,14 +12786,14 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1172712786 if (instr_is_comptime(array_ptr)) {
1172812787 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node);
1172912788 if (pointee == nullptr)
11730 return ira->codegen->invalid_instruction;
12789 return ira->codegen->invalid_inst_gen;
1173112790 if (pointee->special != ConstValSpecialRuntime) {
1173212791 assert(array_ptr->value->type->id == ZigTypeIdPointer);
1173312792 ZigType *array_type = array_ptr->value->type->data.pointer.child_type;
1173412793 assert(is_slice(wanted_type));
1173512794 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1173612795
11737 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12796 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1173812797 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);
1173912798 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut;
1174012799 result->value->type = wanted_type;
......@@ -11743,32 +12802,34 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1174312802 }
1174412803
1174512804 if (result_loc == nullptr) result_loc = no_result_loc();
11746 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,
12805 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,
1174712806 false, true);
11748 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
12807 if (type_is_invalid(result_loc_inst->value->type) ||
12808 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
12809 {
1174912810 return result_loc_inst;
1175012811 }
1175112812 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);
1175212813}
1175312814
11754static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
12815static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) {
1175512816 assert(old_bb);
1175612817
11757 if (old_bb->other) {
11758 if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) {
11759 return old_bb->other;
12818 if (old_bb->child) {
12819 if (ref_old_instruction == nullptr || old_bb->child->ref_instruction != ref_old_instruction) {
12820 return old_bb->child;
1176012821 }
1176112822 }
1176212823
11763 IrBasicBlock *new_bb = ir_build_bb_from(&ira->new_irb, old_bb);
12824 IrBasicBlockGen *new_bb = ir_build_bb_from(ira, old_bb);
1176412825 new_bb->ref_instruction = ref_old_instruction;
1176512826
1176612827 return new_bb;
1176712828}
1176812829
11769static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
12830static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) {
1177012831 assert(ref_old_instruction != nullptr);
11771 IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
12832 IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
1177212833 if (new_bb->must_be_comptime_source_instr) {
1177312834 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,
1177412835 buf_sprintf("control flow attempts to use compile-time variable at runtime"));
......@@ -11779,24 +12840,24 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb,
1177912840 return new_bb;
1178012841}
1178112842
11782static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {
11783 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? old_bb->instruction_list.at(0) : nullptr);
12843static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) {
12844 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr);
1178412845 ira->instruction_index = 0;
1178512846 ira->old_irb.current_basic_block = old_bb;
1178612847 ira->const_predecessor_bb = const_predecessor_bb;
1178712848 ira->old_bb_index = old_bb->index;
1178812849}
1178912850
11790static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,
12851static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, IrBasicBlockSrc *next_bb,
1179112852 IrSuspendPosition *suspend_pos)
1179212853{
1179312854 if (ira->codegen->verbose_ir) {
11794 fprintf(stderr, "suspend %s_%zu %s_%zu #%" PRIu32 " (%zu,%zu)\n",
12855 fprintf(stderr, "suspend %s_%" PRIu32 " %s_%" PRIu32 " #%" PRIu32 " (%zu,%zu)\n",
1179512856 ira->old_irb.current_basic_block->name_hint,
1179612857 ira->old_irb.current_basic_block->debug_id,
1179712858 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
1179812859 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,
11799 ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
12860 ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id,
1180012861 ira->old_bb_index, ira->instruction_index);
1180112862 }
1180212863 suspend_pos->basic_block_index = ira->old_bb_index;
......@@ -11811,13 +12872,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
1181112872 assert(ira->old_irb.current_basic_block == next_bb);
1181212873 ira->instruction_index = 0;
1181312874 ira->const_predecessor_bb = nullptr;
11814 next_bb->other = ir_get_new_bb_runtime(ira, next_bb, old_instruction);
11815 ira->new_irb.current_basic_block = next_bb->other;
12875 next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction);
12876 ira->new_irb.current_basic_block = next_bb->child;
1181612877 }
1181712878 return ira->codegen->unreach_instruction;
1181812879}
1181912880
11820static IrInstruction *ira_resume(IrAnalyze *ira) {
12881static IrInstGen *ira_resume(IrAnalyze *ira) {
1182112882 IrSuspendPosition pos = ira->resume_stack.pop();
1182212883 if (ira->codegen->verbose_ir) {
1182312884 fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
......@@ -11830,12 +12891,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) {
1183012891 ira->instruction_index = pos.instruction_index;
1183112892 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);
1183212893 if (ira->codegen->verbose_ir) {
11833 fprintf(stderr, "%s_%zu #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint,
12894 fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint,
1183412895 ira->old_irb.current_basic_block->debug_id,
11835 ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
12896 ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id);
1183612897 }
1183712898 ira->const_predecessor_bb = nullptr;
11838 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;
12899 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->child;
1183912900 assert(ira->new_irb.current_basic_block != nullptr);
1184012901 return ira->codegen->unreach_instruction;
1184112902}
......@@ -11846,8 +12907,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
1184612907 bool need_repeat = true;
1184712908 for (;;) {
1184812909 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {
11849 IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
11850 if (old_bb->other == nullptr && old_bb->suspend_instruction_ref == nullptr) {
12910 IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
12911 if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) {
1185112912 ira->old_bb_index += 1;
1185212913 continue;
1185312914 }
......@@ -11855,8 +12916,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
1185512916 // if it's a suspended block,
1185612917 // then skip it
1185712918 if (old_bb->suspended ||
11858 (old_bb->other != nullptr && old_bb->other->instruction_list.length != 0) ||
11859 (old_bb->other != nullptr && old_bb->other->already_appended))
12919 (old_bb->child != nullptr && old_bb->child->instruction_list.length != 0) ||
12920 (old_bb->child != nullptr && old_bb->child->already_appended))
1186012921 {
1186112922 ira->old_bb_index += 1;
1186212923 continue;
......@@ -11870,10 +12931,10 @@ static void ir_start_next_bb(IrAnalyze *ira) {
1187012931 return;
1187112932 }
1187212933
11873 if (old_bb->other == nullptr) {
11874 old_bb->other = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);
12934 if (old_bb->child == nullptr) {
12935 old_bb->child = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);
1187512936 }
11876 ira->new_irb.current_basic_block = old_bb->other;
12937 ira->new_irb.current_basic_block = old_bb->child;
1187712938 ir_start_bb(ira, old_bb, nullptr);
1187812939 return;
1187912940 }
......@@ -11893,16 +12954,16 @@ static void ir_finish_bb(IrAnalyze *ira) {
1189312954 if (!ira->new_irb.current_basic_block->already_appended) {
1189412955 ira->new_irb.current_basic_block->already_appended = true;
1189512956 if (ira->codegen->verbose_ir) {
11896 fprintf(stderr, "append new bb %s_%zu\n", ira->new_irb.current_basic_block->name_hint,
12957 fprintf(stderr, "append new bb %s_%" PRIu32 "\n", ira->new_irb.current_basic_block->name_hint,
1189712958 ira->new_irb.current_basic_block->debug_id);
1189812959 }
1189912960 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
1190012961 }
1190112962 ira->instruction_index += 1;
1190212963 while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) {
11903 IrInstruction *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
12964 IrInstSrc *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
1190412965 if (!next_instruction->is_gen) {
11905 ir_add_error(ira, next_instruction, buf_sprintf("unreachable code"));
12966 ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code"));
1190612967 break;
1190712968 }
1190812969 ira->instruction_index += 1;
......@@ -11911,7 +12972,7 @@ static void ir_finish_bb(IrAnalyze *ira) {
1191112972 ir_start_next_bb(ira);
1191212973}
1191312974
11914static IrInstruction *ir_unreach_error(IrAnalyze *ira) {
12975static IrInstGen *ir_unreach_error(IrAnalyze *ira) {
1191512976 ira->old_bb_index = SIZE_MAX;
1191612977 if (ira->new_irb.exec->first_err_trace_msg == nullptr) {
1191712978 ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err;
......@@ -11919,7 +12980,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) {
1191912980 return ira->codegen->unreach_instruction;
1192012981}
1192112982
11922static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) {
12983static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) {
1192312984 size_t *bbc = ira->new_irb.exec->backward_branch_count;
1192412985 size_t *quota = ira->new_irb.exec->backward_branch_quota;
1192512986
......@@ -11938,66 +12999,82 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
1193812999 return true;
1193913000}
1194013001
11941static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) {
13002static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, IrBasicBlockSrc *old_bb) {
1194213003 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {
1194313004 if (!ir_emit_backward_branch(ira, source_instruction))
1194413005 return ir_unreach_error(ira);
1194513006 }
1194613007
11947 old_bb->other = ira->old_irb.current_basic_block->other;
13008 old_bb->child = ira->old_irb.current_basic_block->child;
1194813009 ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);
1194913010 return ira->codegen->unreach_instruction;
1195013011}
1195113012
11952static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) {
13013static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) {
1195313014 if (instruction->value->type->id == ZigTypeIdUnreachable)
1195413015 ir_finish_bb(ira);
1195513016 return instruction;
1195613017}
1195713018
11958static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
11959 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);
13019static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) {
13020 IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry);
13021 result->value->special = ConstValSpecialStatic;
13022 result->value->data.x_ptr.data.fn.fn_entry = fn_entry;
13023 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
13024 result->value->data.x_ptr.special = ConstPtrSpecialFunction;
13025 return result;
13026}
13027
13028static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg) {
13029 IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry));
13030 result->value->data.x_bound_fn.fn = fn_entry;
13031 result->value->data.x_bound_fn.first_arg = first_arg;
13032 return result;
13033}
13034
13035static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
13036 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);
1196013037 result->value->data.x_type = ty;
1196113038 return result;
1196213039}
1196313040
11964static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) {
11965 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
13041static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) {
13042 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
1196613043 result->value->data.x_bool = value;
1196713044 return result;
1196813045}
1196913046
11970static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
11971 IrInstruction *result = ir_const(ira, source_instruction, ty);
13047static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
13048 IrInstGen *result = ir_const(ira, source_instruction, ty);
1197213049 result->value->special = ConstValSpecialUndef;
1197313050 return result;
1197413051}
1197513052
11976static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {
11977 IrInstruction *result = ir_const_noval(ira, source_instruction);
13053static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) {
13054 IrInstGen *result = ir_const_noval(ira, source_instruction);
1197813055 result->value = ira->codegen->intern.for_unreachable();
1197913056 return result;
1198013057}
1198113058
11982static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) {
11983 IrInstruction *result = ir_const_noval(ira, source_instruction);
13059static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) {
13060 IrInstGen *result = ir_const_noval(ira, source_instruction);
1198413061 result->value = ira->codegen->intern.for_void();
1198513062 return result;
1198613063}
1198713064
11988static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) {
11989 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
13065static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) {
13066 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
1199013067 bigint_init_unsigned(&result->value->data.x_bigint, value);
1199113068 return result;
1199213069}
1199313070
11994static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
13071static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction,
1199513072 ZigValue *pointee, ZigType *pointee_type,
1199613073 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
1199713074{
1199813075 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
1199913076 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
12000 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);
13077 IrInstGen *const_instr = ir_const(ira, instruction, ptr_type);
1200113078 ZigValue *const_val = const_instr->value;
1200213079 const_val->data.x_ptr.special = ConstPtrSpecialRef;
1200313080 const_val->data.x_ptr.mut = ptr_mut;
......@@ -12005,7 +13082,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
1200513082 return const_instr;
1200613083}
1200713084
12008static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
13085static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
1200913086 ZigValue *val, UndefAllowed undef_allowed)
1201013087{
1201113088 Error err;
......@@ -12017,14 +13094,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
1201713094 if (!type_has_bits(val->type))
1201813095 return ErrorNone;
1201913096
12020 exec_add_error_node(codegen, exec, source_node,
13097 exec_add_error_node_gen(codegen, exec, source_node,
1202113098 buf_sprintf("unable to evaluate constant expression"));
1202213099 return ErrorSemanticAnalyzeFail;
1202313100 case ConstValSpecialUndef:
1202413101 if (undef_allowed == UndefOk || undef_allowed == LazyOk)
1202513102 return ErrorNone;
1202613103
12027 exec_add_error_node(codegen, exec, source_node,
13104 exec_add_error_node_gen(codegen, exec, source_node,
1202813105 buf_sprintf("use of undefined value here causes undefined behavior"));
1202913106 return ErrorSemanticAnalyzeFail;
1203013107 case ConstValSpecialLazy:
......@@ -12039,9 +13116,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
1203913116 }
1204013117}
1204113118
12042static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {
13119static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) {
1204313120 Error err;
12044 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,
13121 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node,
1204513122 value->value, undef_allowed)))
1204613123 {
1204713124 return nullptr;
......@@ -12052,14 +13129,14 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll
1205213129ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1205313130 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
1205413131 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
12055 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
13132 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
1205613133{
1205713134 Error err;
1205813135
1205913136 if (expected_type != nullptr && type_is_invalid(expected_type))
12060 return codegen->invalid_instruction->value;
13137 return codegen->invalid_inst_gen->value;
1206113138
12062 IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");
13139 IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
1206313140 ir_executable->source_node = source_node;
1206413141 ir_executable->parent_exec = parent_exec;
1206513142 ir_executable->name = exec_name;
......@@ -12069,21 +13146,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1206913146 ir_executable->begin_scope = scope;
1207013147
1207113148 if (!ir_gen(codegen, node, scope, ir_executable))
12072 return codegen->invalid_instruction->value;
13149 return codegen->invalid_inst_gen->value;
1207313150
1207413151 if (ir_executable->first_err_trace_msg != nullptr) {
1207513152 codegen->trace_err = ir_executable->first_err_trace_msg;
12076 return codegen->invalid_instruction->value;
13153 return codegen->invalid_inst_gen->value;
1207713154 }
1207813155
1207913156 if (codegen->verbose_ir) {
1208013157 fprintf(stderr, "\nSource: ");
1208113158 ast_render(stderr, node, 4);
1208213159 fprintf(stderr, "\n{ // (IR)\n");
12083 ir_print(codegen, stderr, ir_executable, 2, IrPassSrc);
13160 ir_print_src(codegen, stderr, ir_executable, 2);
1208413161 fprintf(stderr, "}\n");
1208513162 }
12086 IrExecutable *analyzed_executable = allocate<IrExecutable>(1, "IrExecutablePass2");
13163 IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen");
1208713164 analyzed_executable->source_node = source_node;
1208813165 analyzed_executable->parent_exec = parent_exec;
1208913166 analyzed_executable->source_exec = ir_executable;
......@@ -12096,31 +13173,31 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1209613173 analyzed_executable->begin_scope = scope;
1209713174 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);
1209813175 if (type_is_invalid(result_type)) {
12099 return codegen->invalid_instruction->value;
13176 return codegen->invalid_inst_gen->value;
1210013177 }
1210113178
1210213179 if (codegen->verbose_ir) {
1210313180 fprintf(stderr, "{ // (analyzed)\n");
12104 ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen);
13181 ir_print_gen(codegen, stderr, analyzed_executable, 2);
1210513182 fprintf(stderr, "}\n");
1210613183 }
1210713184
1210813185 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);
1210913186 if (type_is_invalid(result->type))
12110 return codegen->invalid_instruction->value;
13187 return codegen->invalid_inst_gen->value;
1211113188
1211213189 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))
12113 return codegen->invalid_instruction->value;
13190 return codegen->invalid_inst_gen->value;
1211413191
1211513192 return result;
1211613193}
1211713194
12118static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) {
13195static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {
1211913196 if (type_is_invalid(err_value->value->type))
1212013197 return nullptr;
1212113198
1212213199 if (err_value->value->type->id != ZigTypeIdErrorSet) {
12123 ir_add_error(ira, err_value,
13200 ir_add_error_node(ira, err_value->base.source_node,
1212413201 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));
1212513202 return nullptr;
1212613203 }
......@@ -12133,7 +13210,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
1213313210 return const_val->data.x_err_set;
1213413211}
1213513212
12136static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
13213static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
1213713214 ZigValue *val)
1213813215{
1213913216 Error err;
......@@ -12144,18 +13221,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN
1214413221 return val->data.x_type;
1214513222}
1214613223
12147static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {
13224static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
1214813225 if (type_is_invalid(type_value->value->type))
1214913226 return nullptr;
1215013227
1215113228 if (type_value->value->type->id != ZigTypeIdMetaType) {
12152 ir_add_error(ira, type_value,
13229 ir_add_error_node(ira, type_value->base.source_node,
1215313230 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));
1215413231 return nullptr;
1215513232 }
1215613233
1215713234 Error err;
12158 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node,
13235 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,
1215913236 type_value->value, LazyOk)))
1216013237 {
1216113238 return nullptr;
......@@ -12164,17 +13241,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value)
1216413241 return type_value->value;
1216513242}
1216613243
12167static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
13244static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
1216813245 ZigValue *val = ir_resolve_type_lazy(ira, type_value);
1216913246 if (val == nullptr)
1217013247 return ira->codegen->builtin_types.entry_invalid;
1217113248
12172 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val);
13249 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val);
1217313250}
1217413251
12175static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *elem_type) {
13252static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {
1217613253 if (!is_valid_vector_elem_type(elem_type)) {
12177 ir_add_error(ira, source_instr,
13254 ir_add_error_node(ira, source_node,
1217813255 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",
1217913256 buf_ptr(&elem_type->name)));
1218013257 return ErrorSemanticAnalyzeFail;
......@@ -12182,28 +13259,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_
1218213259 return ErrorNone;
1218313260}
1218413261
12185static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstruction *elem_type_value) {
13262static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type_value) {
1218613263 Error err;
1218713264 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);
1218813265 if (type_is_invalid(elem_type))
1218913266 return ira->codegen->builtin_types.entry_invalid;
12190 if ((err = ir_validate_vector_elem_type(ira, elem_type_value, elem_type)))
13267 if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type)))
1219113268 return ira->codegen->builtin_types.entry_invalid;
1219213269 return elem_type;
1219313270}
1219413271
12195static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
13272static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
1219613273 ZigType *ty = ir_resolve_type(ira, type_value);
1219713274 if (type_is_invalid(ty))
1219813275 return ira->codegen->builtin_types.entry_invalid;
1219913276
1220013277 if (ty->id != ZigTypeIdInt) {
12201 ErrorMsg *msg = ir_add_error(ira, type_value,
13278 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
1220213279 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));
1220313280 if (ty->id == ZigTypeIdVector &&
1220413281 ty->data.vector.elem_type->id == ZigTypeIdInt)
1220513282 {
12206 add_error_note(ira->codegen, msg, type_value->source_node,
13283 add_error_note(ira->codegen, msg, type_value->base.source_node,
1220713284 buf_sprintf("represent vectors with their element types, i.e. '%s'",
1220813285 buf_ptr(&ty->data.vector.elem_type->name)));
1220913286 }
......@@ -12213,12 +13290,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
1221313290 return ty;
1221413291}
1221513292
12216static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) {
13293static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) {
1221713294 if (type_is_invalid(type_value->value->type))
1221813295 return ira->codegen->builtin_types.entry_invalid;
1221913296
1222013297 if (type_value->value->type->id != ZigTypeIdMetaType) {
12221 ErrorMsg *msg = ir_add_error(ira, type_value,
13298 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
1222213299 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));
1222313300 add_error_note(ira->codegen, msg, op_source->source_node,
1222413301 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
......@@ -12232,7 +13309,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
1223213309 assert(const_val->data.x_type != nullptr);
1223313310 ZigType *result_type = const_val->data.x_type;
1223413311 if (result_type->id != ZigTypeIdErrorSet) {
12235 ErrorMsg *msg = ir_add_error(ira, type_value,
13312 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
1223613313 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));
1223713314 add_error_note(ira->codegen, msg, op_source->source_node,
1223813315 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
......@@ -12241,15 +13318,12 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
1224113318 return result_type;
1224213319}
1224313320
12244static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
12245 if (fn_value == ira->codegen->invalid_instruction)
12246 return nullptr;
12247
13321static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
1224813322 if (type_is_invalid(fn_value->value->type))
1224913323 return nullptr;
1225013324
1225113325 if (fn_value->value->type->id != ZigTypeIdFn) {
12252 ir_add_error_node(ira, fn_value->source_node,
13326 ir_add_error_node(ira, fn_value->base.source_node,
1225313327 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));
1225413328 return nullptr;
1225513329 }
......@@ -12265,22 +13339,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
1226513339 return const_val->data.x_ptr.data.fn.fn_entry;
1226613340}
1226713341
12268static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
12269 ZigType *wanted_type, ResultLoc *result_loc)
13342static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
13343 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
1227013344{
1227113345 assert(wanted_type->id == ZigTypeIdOptional);
1227213346
1227313347 if (instr_is_comptime(value)) {
1227413348 ZigType *payload_type = wanted_type->data.maybe.child_type;
12275 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
13349 IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type);
1227613350 if (type_is_invalid(casted_payload->value->type))
12277 return ira->codegen->invalid_instruction;
13351 return ira->codegen->invalid_inst_gen;
1227813352
1227913353 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
1228013354 if (!val)
12281 return ira->codegen->invalid_instruction;
13355 return ira->codegen->invalid_inst_gen;
1228213356
12283 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13357 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1228413358 source_instr->scope, source_instr->source_node);
1228513359 const_instruction->base.value->special = ConstValSpecialStatic;
1228613360 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
......@@ -12295,40 +13369,42 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1229513369 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {
1229613370 result_loc = no_result_loc();
1229713371 }
12298 IrInstruction *result_loc_inst = nullptr;
13372 IrInstGen *result_loc_inst = nullptr;
1229913373 if (result_loc != nullptr) {
1230013374 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
12301 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13375 if (type_is_invalid(result_loc_inst->value->type) ||
13376 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
13377 {
1230213378 return result_loc_inst;
1230313379 }
1230413380 }
12305 IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
13381 IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
1230613382 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;
1230713383 return result;
1230813384}
1230913385
12310static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,
12311 IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc)
13386static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr,
13387 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
1231213388{
1231313389 assert(wanted_type->id == ZigTypeIdErrorUnion);
1231413390
1231513391 ZigType *payload_type = wanted_type->data.error_union.payload_type;
1231613392 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
1231713393 if (instr_is_comptime(value)) {
12318 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
13394 IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type);
1231913395 if (type_is_invalid(casted_payload->value->type))
12320 return ira->codegen->invalid_instruction;
13396 return ira->codegen->invalid_inst_gen;
1232113397
1232213398 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
1232313399 if (!val)
12324 return ira->codegen->invalid_instruction;
13400 return ira->codegen->invalid_inst_gen;
1232513401
1232613402 ZigValue *err_set_val = create_const_vals(1);
1232713403 err_set_val->type = err_set_type;
1232813404 err_set_val->special = ConstValSpecialStatic;
1232913405 err_set_val->data.x_err_set = nullptr;
1233013406
12331 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13407 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1233213408 source_instr->scope, source_instr->source_node);
1233313409 const_instruction->base.value->type = wanted_type;
1233413410 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -12337,23 +13413,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1233713413 return &const_instruction->base;
1233813414 }
1233913415
12340 IrInstruction *result_loc_inst;
13416 IrInstGen *result_loc_inst;
1234113417 if (handle_is_ptr(wanted_type)) {
1234213418 if (result_loc == nullptr) result_loc = no_result_loc();
1234313419 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
12344 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13420 if (type_is_invalid(result_loc_inst->value->type) ||
13421 result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
1234513422 return result_loc_inst;
1234613423 }
1234713424 } else {
1234813425 result_loc_inst = nullptr;
1234913426 }
1235013427
12351 IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);
13428 IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);
1235213429 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;
1235313430 return result;
1235413431}
1235513432
12356static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
13433static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
1235713434 ZigType *wanted_type)
1235813435{
1235913436 assert(value->value->type->id == ZigTypeIdErrorSet);
......@@ -12362,10 +13439,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1236213439 if (instr_is_comptime(value)) {
1236313440 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1236413441 if (!val)
12365 return ira->codegen->invalid_instruction;
13442 return ira->codegen->invalid_inst_gen;
1236613443
1236713444 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
12368 return ira->codegen->invalid_instruction;
13445 return ira->codegen->invalid_inst_gen;
1236913446 }
1237013447 if (!type_is_global_error_set(wanted_type)) {
1237113448 bool subset = false;
......@@ -12379,11 +13456,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1237913456 ir_add_error(ira, source_instr,
1238013457 buf_sprintf("error.%s not a member of error set '%s'",
1238113458 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));
12382 return ira->codegen->invalid_instruction;
13459 return ira->codegen->invalid_inst_gen;
1238313460 }
1238413461 }
1238513462
12386 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13463 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1238713464 source_instr->scope, source_instr->source_node);
1238813465 const_instruction->base.value->type = wanted_type;
1238913466 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -12391,18 +13468,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1239113468 return &const_instruction->base;
1239213469 }
1239313470
12394 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet);
12395 result->value->type = wanted_type;
12396 return result;
13471 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet);
1239713472}
1239813473
12399static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,
12400 IrInstruction *frame_ptr, ZigType *wanted_type)
13474static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
13475 IrInstGen *frame_ptr, ZigType *wanted_type)
1240113476{
1240213477 if (instr_is_comptime(frame_ptr)) {
1240313478 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);
1240413479 if (ptr_val == nullptr)
12405 return ira->codegen->invalid_instruction;
13480 return ira->codegen->invalid_inst_gen;
1240613481
1240713482 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);
1240813483 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
......@@ -12410,44 +13485,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
1241013485 }
1241113486 }
1241213487
12413 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
12414 wanted_type, frame_ptr, CastOpBitCast);
12415 result->value->type = wanted_type;
12416 return result;
13488 return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast);
1241713489}
1241813490
12419static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,
12420 IrInstruction *value, ZigType *wanted_type)
13491static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
13492 IrInstGen *value, ZigType *wanted_type)
1242113493{
1242213494 if (instr_is_comptime(value)) {
1242313495 zig_panic("TODO comptime anyframe->T to anyframe");
1242413496 }
1242513497
12426 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
12427 wanted_type, value, CastOpBitCast);
12428 result->value->type = wanted_type;
12429 return result;
13498 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
1243013499}
1243113500
1243213501
12433static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
13502static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
1243413503 ZigType *wanted_type, ResultLoc *result_loc)
1243513504{
1243613505 assert(wanted_type->id == ZigTypeIdErrorUnion);
1243713506
12438 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
13507 IrInstGen *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
1243913508
1244013509 if (instr_is_comptime(casted_value)) {
1244113510 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
1244213511 if (!val)
12443 return ira->codegen->invalid_instruction;
13512 return ira->codegen->invalid_inst_gen;
1244413513
1244513514 ZigValue *err_set_val = create_const_vals(1);
1244613515 err_set_val->special = ConstValSpecialStatic;
1244713516 err_set_val->type = wanted_type->data.error_union.err_set_type;
1244813517 err_set_val->data.x_err_set = val->data.x_err_set;
1244913518
12450 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13519 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1245113520 source_instr->scope, source_instr->source_node);
1245213521 const_instruction->base.value->type = wanted_type;
1245313522 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -12456,11 +13525,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1245613525 return &const_instruction->base;
1245713526 }
1245813527
12459 IrInstruction *result_loc_inst;
13528 IrInstGen *result_loc_inst;
1246013529 if (handle_is_ptr(wanted_type)) {
1246113530 if (result_loc == nullptr) result_loc = no_result_loc();
1246213531 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
12463 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13532 if (type_is_invalid(result_loc_inst->value->type) ||
13533 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
13534 {
1246413535 return result_loc_inst;
1246513536 }
1246613537 } else {
......@@ -12468,19 +13539,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1246813539 }
1246913540
1247013541
12471 IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);
13542 IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);
1247213543 result->value->data.rh_error_union = RuntimeHintErrorUnionError;
1247313544 return result;
1247413545}
1247513546
12476static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
13547static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) {
1247713548 assert(wanted_type->id == ZigTypeIdOptional);
1247813549 assert(instr_is_comptime(value));
1247913550
1248013551 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1248113552 assert(val != nullptr);
1248213553
12483 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13554 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1248413555 result->value->special = ConstValSpecialStatic;
1248513556 if (get_codegen_ptr_type(wanted_type) != nullptr) {
1248613557 result->value->data.x_ptr.special = ConstPtrSpecialNull;
......@@ -12492,8 +13563,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
1249213563 return result;
1249313564}
1249413565
12495static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction *source_instr,
12496 IrInstruction *value, ZigType *wanted_type)
13566static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr,
13567 IrInstGen *value, ZigType *wanted_type)
1249713568{
1249813569 assert(wanted_type->id == ZigTypeIdPointer);
1249913570 assert(wanted_type->data.pointer.ptr_len == PtrLenC);
......@@ -12502,24 +13573,24 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction
1250213573 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1250313574 assert(val != nullptr);
1250413575
12505 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13576 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1250613577 result->value->data.x_ptr.special = ConstPtrSpecialNull;
1250713578 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1250813579 return result;
1250913580}
1251013581
12511static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
13582static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,
1251213583 bool is_const, bool is_volatile)
1251313584{
1251413585 Error err;
1251513586
1251613587 if (type_is_invalid(value->value->type))
12517 return ira->codegen->invalid_instruction;
13588 return ira->codegen->invalid_inst_gen;
1251813589
1251913590 if (instr_is_comptime(value)) {
1252013591 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
1252113592 if (!val)
12522 return ira->codegen->invalid_instruction;
13593 return ira->codegen->invalid_inst_gen;
1252313594 return ir_get_const_ptr(ira, source_instruction, val, value->value->type,
1252413595 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
1252513596 }
......@@ -12528,9 +13599,9 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1252813599 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1252913600
1253013601 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))
12531 return ira->codegen->invalid_instruction;
13602 return ira->codegen->invalid_inst_gen;
1253213603
12533 IrInstruction *result_loc;
13604 IrInstGen *result_loc;
1253413605 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) {
1253513606 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true,
1253613607 false, true);
......@@ -12538,12 +13609,12 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1253813609 result_loc = nullptr;
1253913610 }
1254013611
12541 IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);
13612 IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);
1254213613 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;
1254313614 return new_instruction;
1254413615}
1254513616
12546static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {
13617static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) {
1254713618 assert(union_type->id == ZigTypeIdUnion);
1254813619
1254913620 Error err;
......@@ -12555,36 +13626,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_
1255513626 assert(union_type->data.unionation.tag_type != nullptr);
1255613627 return union_type->data.unionation.tag_type;
1255713628 } else {
12558 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union '%s' has no tag",
13629 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union '%s' has no tag",
1255913630 buf_ptr(&union_type->name)));
1256013631 add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here"));
1256113632 return ira->codegen->builtin_types.entry_invalid;
1256213633 }
1256313634}
1256413635
12565static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target) {
13636static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
1256613637 Error err;
1256713638
12568 IrInstruction *enum_target;
13639 IrInstGen *enum_target;
1256913640 ZigType *enum_type;
1257013641 if (target->value->type->id == ZigTypeIdUnion) {
12571 enum_type = ir_resolve_union_tag_type(ira, target, target->value->type);
13642 enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type);
1257213643 if (type_is_invalid(enum_type))
12573 return ira->codegen->invalid_instruction;
13644 return ira->codegen->invalid_inst_gen;
1257413645 enum_target = ir_implicit_cast(ira, target, enum_type);
1257513646 if (type_is_invalid(enum_target->value->type))
12576 return ira->codegen->invalid_instruction;
13647 return ira->codegen->invalid_inst_gen;
1257713648 } else if (target->value->type->id == ZigTypeIdEnum) {
1257813649 enum_target = target;
1257913650 enum_type = target->value->type;
1258013651 } else {
12581 ir_add_error(ira, target,
13652 ir_add_error_node(ira, target->base.source_node,
1258213653 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));
12583 return ira->codegen->invalid_instruction;
13654 return ira->codegen->invalid_inst_gen;
1258413655 }
1258513656
1258613657 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
12587 return ira->codegen->invalid_instruction;
13658 return ira->codegen->invalid_inst_gen;
1258813659
1258913660 ZigType *tag_type = enum_type->data.enumeration.tag_int_type;
1259013661 assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt);
......@@ -12593,7 +13664,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1259313664 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&
1259413665 enum_type->data.enumeration.src_field_count == 1)
1259513666 {
12596 IrInstruction *result = ir_const(ira, source_instr, tag_type);
13667 IrInstGen *result = ir_const(ira, source_instr, tag_type);
1259713668 init_const_bigint(result->value, tag_type,
1259813669 &enum_type->data.enumeration.fields[0].value);
1259913670 return result;
......@@ -12602,20 +13673,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1260213673 if (instr_is_comptime(enum_target)) {
1260313674 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
1260413675 if (!val)
12605 return ira->codegen->invalid_instruction;
12606 IrInstruction *result = ir_const(ira, source_instr, tag_type);
13676 return ira->codegen->invalid_inst_gen;
13677 IrInstGen *result = ir_const(ira, source_instr, tag_type);
1260713678 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);
1260813679 return result;
1260913680 }
1261013681
12611 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
12612 source_instr->source_node, enum_target);
12613 result->value->type = tag_type;
12614 return result;
13682 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type);
1261513683}
1261613684
12617static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
12618 IrInstruction *target, ZigType *wanted_type)
13685static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
13686 IrInstGen *target, ZigType *wanted_type)
1261913687{
1262013688 assert(target->value->type->id == ZigTypeIdUnion);
1262113689 assert(wanted_type->id == ZigTypeIdEnum);
......@@ -12624,8 +13692,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1262413692 if (instr_is_comptime(target)) {
1262513693 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1262613694 if (!val)
12627 return ira->codegen->invalid_instruction;
12628 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13695 return ira->codegen->invalid_inst_gen;
13696 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1262913697 result->value->special = ConstValSpecialStatic;
1263013698 result->value->type = wanted_type;
1263113699 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);
......@@ -12636,7 +13704,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1263613704 if (wanted_type->data.enumeration.layout == ContainerLayoutAuto &&
1263713705 wanted_type->data.enumeration.src_field_count == 1)
1263813706 {
12639 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13707 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1264013708 result->value->special = ConstValSpecialStatic;
1264113709 result->value->type = wanted_type;
1264213710 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;
......@@ -12644,48 +13712,45 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1264413712 return result;
1264513713 }
1264613714
12647 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope,
12648 source_instr->source_node, target);
12649 result->value->type = wanted_type;
12650 return result;
13715 return ir_build_union_tag(ira, source_instr, target, wanted_type);
1265113716}
1265213717
12653static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,
12654 IrInstruction *target, ZigType *wanted_type)
13718static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr,
13719 IrInstGen *target, ZigType *wanted_type)
1265513720{
12656 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13721 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1265713722 result->value->special = ConstValSpecialUndef;
1265813723 return result;
1265913724}
1266013725
12661static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,
12662 IrInstruction *uncasted_target, ZigType *wanted_type)
13726static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
13727 IrInstGen *uncasted_target, ZigType *wanted_type)
1266313728{
1266413729 Error err;
1266513730 assert(wanted_type->id == ZigTypeIdUnion);
1266613731
1266713732 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))
12668 return ira->codegen->invalid_instruction;
13733 return ira->codegen->invalid_inst_gen;
1266913734
12670 IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);
13735 IrInstGen *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);
1267113736 if (type_is_invalid(target->value->type))
12672 return ira->codegen->invalid_instruction;
13737 return ira->codegen->invalid_inst_gen;
1267313738
1267413739 if (instr_is_comptime(target)) {
1267513740 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1267613741 if (!val)
12677 return ira->codegen->invalid_instruction;
13742 return ira->codegen->invalid_inst_gen;
1267813743 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
1267913744 assert(union_field != nullptr);
1268013745 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
1268113746 if (field_type == nullptr)
12682 return ira->codegen->invalid_instruction;
13747 return ira->codegen->invalid_inst_gen;
1268313748 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
12684 return ira->codegen->invalid_instruction;
13749 return ira->codegen->invalid_inst_gen;
1268513750
1268613751 switch (type_has_one_possible_value(ira->codegen, field_type)) {
1268713752 case OnePossibleValueInvalid:
12688 return ira->codegen->invalid_instruction;
13753 return ira->codegen->invalid_inst_gen;
1268913754 case OnePossibleValueNo: {
1269013755 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
1269113756 union_field->enum_field->decl_index);
......@@ -12696,13 +13761,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1269613761 buf_ptr(union_field->name)));
1269713762 add_error_note(ira->codegen, msg, field_node,
1269813763 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));
12699 return ira->codegen->invalid_instruction;
13764 return ira->codegen->invalid_inst_gen;
1270013765 }
1270113766 case OnePossibleValueYes:
1270213767 break;
1270313768 }
1270413769
12705 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13770 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1270613771 result->value->special = ConstValSpecialStatic;
1270713772 result->value->type = wanted_type;
1270813773 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
......@@ -12715,9 +13780,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1271513780 // if the union has all fields 0 bits, we can do it
1271613781 // and in fact it's a noop cast because the union value is just the enum value
1271713782 if (wanted_type->data.unionation.gen_field_count == 0) {
12718 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop);
12719 result->value->type = wanted_type;
12720 return result;
13783 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop);
1272113784 }
1272213785
1272313786 ErrorMsg *msg = ir_add_error(ira, source_instr,
......@@ -12727,10 +13790,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1272713790 TypeUnionField *union_field = &wanted_type->data.unionation.fields[i];
1272813791 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
1272913792 if (field_type == nullptr)
12730 return ira->codegen->invalid_instruction;
13793 return ira->codegen->invalid_inst_gen;
1273113794 bool has_bits;
1273213795 if ((err = type_has_bits2(ira->codegen, field_type, &has_bits)))
12733 return ira->codegen->invalid_instruction;
13796 return ira->codegen->invalid_inst_gen;
1273413797 if (has_bits) {
1273513798 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i);
1273613799 add_error_note(ira->codegen, msg, field_node,
......@@ -12739,23 +13802,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1273913802 buf_ptr(&field_type->name)));
1274013803 }
1274113804 }
12742 return ira->codegen->invalid_instruction;
13805 return ira->codegen->invalid_inst_gen;
1274313806}
1274413807
12745static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,
12746 IrInstruction *target, ZigType *wanted_type)
13808static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr,
13809 IrInstGen *target, ZigType *wanted_type)
1274713810{
1274813811 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1274913812
1275013813 if (instr_is_comptime(target)) {
1275113814 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1275213815 if (!val)
12753 return ira->codegen->invalid_instruction;
13816 return ira->codegen->invalid_inst_gen;
1275413817 if (wanted_type->id == ZigTypeIdInt) {
1275513818 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
1275613819 ir_add_error(ira, source_instr,
1275713820 buf_sprintf("attempt to cast negative value to unsigned integer"));
12758 return ira->codegen->invalid_instruction;
13821 return ira->codegen->invalid_inst_gen;
1275913822 }
1276013823 if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count,
1276113824 wanted_type->data.integral.is_signed))
......@@ -12763,10 +13826,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1276313826 ir_add_error(ira, source_instr,
1276413827 buf_sprintf("cast from '%s' to '%s' truncates bits",
1276513828 buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name)));
12766 return ira->codegen->invalid_instruction;
13829 return ira->codegen->invalid_inst_gen;
1276713830 }
1276813831 }
12769 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13832 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1277013833 result->value->type = wanted_type;
1277113834 if (wanted_type->id == ZigTypeIdInt) {
1277213835 bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint);
......@@ -12783,19 +13846,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1278313846 assert(wanted_type->id == ZigTypeIdInt);
1278413847 assert(type_has_bits(target->value->type));
1278513848 ir_build_assert_zero(ira, source_instr, target);
12786 IrInstruction *result = ir_const_unsigned(ira, source_instr, 0);
13849 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);
1278713850 result->value->type = wanted_type;
1278813851 return result;
1278913852 }
1279013853
12791 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
12792 source_instr->source_node, target);
12793 result->value->type = wanted_type;
12794 return result;
13854 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
1279513855}
1279613856
12797static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,
12798 IrInstruction *target, ZigType *wanted_type)
13857static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
13858 IrInstGen *target, ZigType *wanted_type)
1279913859{
1280013860 Error err;
1280113861 assert(wanted_type->id == ZigTypeIdEnum);
......@@ -12803,14 +13863,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1280313863 ZigType *actual_type = target->value->type;
1280413864
1280513865 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))
12806 return ira->codegen->invalid_instruction;
13866 return ira->codegen->invalid_inst_gen;
1280713867
1280813868 if (actual_type != wanted_type->data.enumeration.tag_int_type) {
1280913869 ir_add_error(ira, source_instr,
1281013870 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",
1281113871 buf_ptr(&actual_type->name),
1281213872 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));
12813 return ira->codegen->invalid_instruction;
13873 return ira->codegen->invalid_inst_gen;
1281413874 }
1281513875
1281613876 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
......@@ -12818,7 +13878,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1281813878 if (instr_is_comptime(target)) {
1281913879 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1282013880 if (!val)
12821 return ira->codegen->invalid_instruction;
13881 return ira->codegen->invalid_inst_gen;
1282213882
1282313883 TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint);
1282413884 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {
......@@ -12829,28 +13889,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1282913889 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));
1283013890 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,
1283113891 buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name)));
12832 return ira->codegen->invalid_instruction;
13892 return ira->codegen->invalid_inst_gen;
1283313893 }
1283413894
12835 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13895 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1283613896 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);
1283713897 return result;
1283813898 }
1283913899
12840 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,
12841 source_instr->source_node, nullptr, target);
12842 result->value->type = wanted_type;
12843 return result;
13900 return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target);
1284413901}
1284513902
12846static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
12847 IrInstruction *target, ZigType *wanted_type)
13903static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr,
13904 IrInstGen *target, ZigType *wanted_type)
1284813905{
1284913906 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1285013907 if (!val)
12851 return ira->codegen->invalid_instruction;
13908 return ira->codegen->invalid_inst_gen;
1285213909
12853 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13910 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1285413911 if (wanted_type->id == ZigTypeIdComptimeFloat) {
1285513912 float_init_float(result->value, val);
1285613913 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
......@@ -12861,7 +13918,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
1286113918 return result;
1286213919}
1286313920
12864static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
13921static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
1286513922 ZigType *wanted_type)
1286613923{
1286713924 assert(target->value->type->id == ZigTypeIdInt);
......@@ -12871,12 +13928,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1287113928 if (instr_is_comptime(target)) {
1287213929 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1287313930 if (!val)
12874 return ira->codegen->invalid_instruction;
13931 return ira->codegen->invalid_inst_gen;
1287513932
12876 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13933 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1287713934
1287813935 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
12879 return ira->codegen->invalid_instruction;
13936 return ira->codegen->invalid_inst_gen;
1288013937 }
1288113938
1288213939 if (type_is_global_error_set(wanted_type)) {
......@@ -12888,7 +13945,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1288813945 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
1288913946 ir_add_error(ira, source_instr,
1289013947 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));
12891 return ira->codegen->invalid_instruction;
13948 return ira->codegen->invalid_inst_gen;
1289213949 }
1289313950
1289413951 size_t index = bigint_as_usize(&val->data.x_bigint);
......@@ -12912,7 +13969,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1291213969 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
1291313970 ir_add_error(ira, source_instr,
1291413971 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));
12915 return ira->codegen->invalid_instruction;
13972 return ira->codegen->invalid_inst_gen;
1291613973 }
1291713974
1291813975 result->value->data.x_err_set = err;
......@@ -12920,12 +13977,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1292013977 }
1292113978 }
1292213979
12923 IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target);
12924 result->value->type = wanted_type;
12925 return result;
13980 return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
1292613981}
1292713982
12928static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
13983static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
1292913984 ZigType *wanted_type)
1293013985{
1293113986 assert(wanted_type->id == ZigTypeIdInt);
......@@ -12935,9 +13990,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1293513990 if (instr_is_comptime(target)) {
1293613991 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1293713992 if (!val)
12938 return ira->codegen->invalid_instruction;
13993 return ira->codegen->invalid_inst_gen;
1293913994
12940 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13995 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1294113996
1294213997 ErrorTableEntry *err;
1294313998 if (err_type->id == ZigTypeIdErrorUnion) {
......@@ -12957,7 +14012,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1295714012 ir_add_error_node(ira, source_instr->source_node,
1295814013 buf_sprintf("error code '%s' does not fit in '%s'",
1295914014 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));
12960 return ira->codegen->invalid_instruction;
14015 return ira->codegen->invalid_inst_gen;
1296114016 }
1296214017
1296314018 return result;
......@@ -12973,14 +14028,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1297314028 }
1297414029 if (!type_is_global_error_set(err_set_type)) {
1297514030 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {
12976 return ira->codegen->invalid_instruction;
14031 return ira->codegen->invalid_inst_gen;
1297714032 }
1297814033 if (err_set_type->data.error_set.err_count == 0) {
12979 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14034 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1298014035 bigint_init_unsigned(&result->value->data.x_bigint, 0);
1298114036 return result;
1298214037 } else if (err_set_type->data.error_set.err_count == 1) {
12983 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14038 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1298414039 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];
1298514040 bigint_init_unsigned(&result->value->data.x_bigint, err->value);
1298614041 return result;
......@@ -12992,21 +14047,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1299214047 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {
1299314048 ir_add_error_node(ira, source_instr->source_node,
1299414049 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));
12995 return ira->codegen->invalid_instruction;
14050 return ira->codegen->invalid_inst_gen;
1299614051 }
1299714052
12998 IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target);
12999 result->value->type = wanted_type;
13000 return result;
14053 return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
1300114054}
1300214055
13003static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
14056static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
1300414057 ZigType *wanted_type)
1300514058{
1300614059 assert(wanted_type->id == ZigTypeIdPointer);
1300714060 Error err;
1300814061 if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13009 return ira->codegen->invalid_instruction;
14062 return ira->codegen->invalid_inst_gen;
1301014063 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);
1301114064 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));
1301214065 ZigType *array_type = wanted_type->data.pointer.child_type;
......@@ -13016,12 +14069,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1301614069 if (instr_is_comptime(target)) {
1301714070 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1301814071 if (!val)
13019 return ira->codegen->invalid_instruction;
14072 return ira->codegen->invalid_inst_gen;
1302014073
1302114074 assert(val->type->id == ZigTypeIdPointer);
1302214075 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
1302314076 if (pointee == nullptr)
13024 return ira->codegen->invalid_instruction;
14077 return ira->codegen->invalid_inst_gen;
1302514078 if (pointee->special != ConstValSpecialRuntime) {
1302614079 ZigValue *array_val = create_const_vals(1);
1302714080 array_val->special = ConstValSpecialStatic;
......@@ -13031,7 +14084,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1303114084 array_val->parent.id = ConstParentIdScalar;
1303214085 array_val->parent.data.p_scalar.scalar_val = pointee;
1303314086
13034 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
14087 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1303514088 source_instr->scope, source_instr->source_node);
1303614089 const_instruction->base.value->type = wanted_type;
1303714090 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -13043,10 +14096,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1304314096 }
1304414097
1304514098 // pointer to array and pointer to single item are represented the same way at runtime
13046 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node,
13047 wanted_type, target, CastOpBitCast);
13048 result->value->type = wanted_type;
13049 return result;
14099 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast);
1305014100}
1305114101
1305214102static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,
......@@ -13234,12 +14284,12 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
1323414284 }
1323514285}
1323614286
13237static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *source_instr,
13238 IrInstruction *array, ZigType *vector_type)
14287static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr,
14288 IrInstGen *array, ZigType *vector_type)
1323914289{
1324014290 if (instr_is_comptime(array)) {
1324114291 // arrays and vectors have the same ZigValue representation
13242 IrInstruction *result = ir_const(ira, source_instr, vector_type);
14292 IrInstGen *result = ir_const(ira, source_instr, vector_type);
1324314293 copy_const_val(result->value, array->value);
1324414294 result->value->type = vector_type;
1324514295 return result;
......@@ -13247,12 +14297,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
1324714297 return ir_build_array_to_vector(ira, source_instr, array, vector_type);
1324814298}
1324914299
13250static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *source_instr,
13251 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)
14300static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr,
14301 IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc)
1325214302{
1325314303 if (instr_is_comptime(vector)) {
1325414304 // arrays and vectors have the same ZigValue representation
13255 IrInstruction *result = ir_const(ira, source_instr, array_type);
14305 IrInstGen *result = ir_const(ira, source_instr, array_type);
1325614306 copy_const_val(result->value, vector->value);
1325714307 result->value->type = array_type;
1325814308 return result;
......@@ -13260,18 +14310,18 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
1326014310 if (result_loc == nullptr) {
1326114311 result_loc = no_result_loc();
1326214312 }
13263 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,
14313 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,
1326414314 true, false, true);
13265 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
14315 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
1326614316 return result_loc_inst;
1326714317 }
1326814318 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);
1326914319}
1327014320
13271static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *source_instr,
13272 IrInstruction *integer, ZigType *dest_type)
14321static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
14322 IrInstGen *integer, ZigType *dest_type)
1327314323{
13274 IrInstruction *unsigned_integer;
14324 IrInstGen *unsigned_integer;
1327514325 if (instr_is_comptime(integer)) {
1327614326 unsigned_integer = integer;
1327714327 } else {
......@@ -13284,7 +14334,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
1328414334 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
1328514335 buf_ptr(&integer->value->type->name),
1328614336 buf_ptr(&dest_type->name)));
13287 return ira->codegen->invalid_instruction;
14337 return ira->codegen->invalid_inst_gen;
1328814338 }
1328914339
1329014340 if (integer->value->type->data.integral.is_signed) {
......@@ -13292,7 +14342,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
1329214342 integer->value->type->data.integral.bit_count);
1329314343 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);
1329414344 if (type_is_invalid(unsigned_integer->value->type))
13295 return ira->codegen->invalid_instruction;
14345 return ira->codegen->invalid_inst_gen;
1329614346 } else {
1329714347 unsigned_integer = integer;
1329814348 }
......@@ -13312,14 +14362,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
1331214362 return false;
1331314363}
1331414364
13315static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
14365static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
1331614366 ZigType *enum_type)
1331714367{
1331814368 assert(enum_type->id == ZigTypeIdEnum);
1331914369
1332014370 Error err;
1332114371 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))
13322 return ira->codegen->invalid_instruction;
14372 return ira->codegen->invalid_inst_gen;
1332314373
1332414374 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);
1332514375 if (field == nullptr) {
......@@ -13327,40 +14377,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou
1332714377 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));
1332814378 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
1332914379 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
13330 return ira->codegen->invalid_instruction;
14380 return ira->codegen->invalid_inst_gen;
1333114381 }
13332 IrInstruction *result = ir_const(ira, source_instr, enum_type);
14382 IrInstGen *result = ir_const(ira, source_instr, enum_type);
1333314383 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);
1333414384
1333514385 return result;
1333614386}
1333714387
13338static IrInstruction *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInstruction *source_instr,
13339 IrInstruction *value, ZigType *wanted_type)
14388static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr,
14389 IrInstGen *value, ZigType *wanted_type)
1334014390{
1334114391 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array"));
13342 return ira->codegen->invalid_instruction;
14392 return ira->codegen->invalid_inst_gen;
1334314393}
1334414394
13345static IrInstruction *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInstruction *source_instr,
13346 IrInstruction *value, ZigType *wanted_type)
14395static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr,
14396 IrInstGen *value, ZigType *wanted_type)
1334714397{
1334814398 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct"));
13349 return ira->codegen->invalid_instruction;
14399 return ira->codegen->invalid_inst_gen;
1335014400}
1335114401
13352static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstruction *source_instr,
13353 IrInstruction *value, ZigType *wanted_type)
14402static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr,
14403 IrInstGen *value, ZigType *wanted_type)
1335414404{
1335514405 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union"));
13356 return ira->codegen->invalid_instruction;
14406 return ira->codegen->invalid_inst_gen;
1335714407}
1335814408
1335914409// Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work,
1336014410// otherwise return ErrorNone. Does not emit any instructions.
1336114411// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the
1336214412// pointer types' alignments if both of the pointer types are ABI aligned.
13363static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigType *dest_ptr_type,
14413static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type,
1336414414 ZigType *src_ptr_type, AstNode *src_source_node)
1336514415{
1336614416 Error err;
......@@ -13394,37 +14444,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT
1339414444 return ErrorNone;
1339514445}
1339614446
13397static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInstruction *source_instr,
13398 IrInstruction *struct_operand, TypeStructField *field)
14447static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,
14448 IrInstGen *struct_operand, TypeStructField *field)
1339914449{
13400 IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
14450 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
1340114451 if (type_is_invalid(struct_ptr->value->type))
13402 return ira->codegen->invalid_instruction;
13403 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
14452 return ira->codegen->invalid_inst_gen;
14453 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
1340414454 struct_operand->value->type, false);
1340514455 if (type_is_invalid(field_ptr->value->type))
13406 return ira->codegen->invalid_instruction;
14456 return ira->codegen->invalid_inst_gen;
1340714457 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
1340814458}
1340914459
13410static IrInstruction *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInstruction *source_instr,
13411 IrInstruction *optional_operand, bool safety_check_on)
14460static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr,
14461 IrInstGen *optional_operand, bool safety_check_on)
1341214462{
13413 IrInstruction *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);
13414 IrInstruction *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,
14463 IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);
14464 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,
1341514465 safety_check_on, false);
1341614466 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);
1341714467}
1341814468
13419static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
13420 ZigType *wanted_type, IrInstruction *value)
14469static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
14470 ZigType *wanted_type, IrInstGen *value)
1342114471{
1342214472 Error err;
1342314473 ZigType *actual_type = value->value->type;
1342414474 AstNode *source_node = source_instr->source_node;
1342514475
1342614476 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
13427 return ira->codegen->invalid_instruction;
14477 return ira->codegen->invalid_inst_gen;
1342814478 }
1342914479
1343014480 // This means the wanted type is anything.
......@@ -13436,7 +14486,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1343614486 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type,
1343714487 source_node, false);
1343814488 if (const_cast_result.id == ConstCastResultIdInvalid)
13439 return ira->codegen->invalid_instruction;
14489 return ira->codegen->invalid_inst_gen;
1344014490 if (const_cast_result.id == ConstCastResultIdOk) {
1344114491 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
1344214492 }
......@@ -13470,7 +14520,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1347014520 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
1347114521 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
1347214522 } else {
13473 return ira->codegen->invalid_instruction;
14523 return ira->codegen->invalid_inst_gen;
1347414524 }
1347514525 } else if (
1347614526 wanted_child_type->id == ZigTypeIdPointer &&
......@@ -13480,18 +14530,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1348014530 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1348114531 {
1348214532 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13483 return ira->codegen->invalid_instruction;
14533 return ira->codegen->invalid_inst_gen;
1348414534 if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13485 return ira->codegen->invalid_instruction;
14535 return ira->codegen->invalid_inst_gen;
1348614536 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) &&
1348714537 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
1348814538 actual_type->data.pointer.child_type->data.array.child_type, source_node,
1348914539 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
1349014540 {
13491 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
14541 IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
1349214542 wanted_child_type);
1349314543 if (type_is_invalid(cast1->value->type))
13494 return ira->codegen->invalid_instruction;
14544 return ira->codegen->invalid_inst_gen;
1349514545 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
1349614546 }
1349714547 }
......@@ -13509,7 +14559,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1350914559 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
1351014560 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
1351114561 } else {
13512 return ira->codegen->invalid_instruction;
14562 return ira->codegen->invalid_inst_gen;
1351314563 }
1351414564 }
1351514565 }
......@@ -13525,13 +14575,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1352514575 actual_type->id == ZigTypeIdComptimeInt ||
1352614576 actual_type->id == ZigTypeIdComptimeFloat)
1352714577 {
13528 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
14578 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
1352914579 if (type_is_invalid(cast1->value->type))
13530 return ira->codegen->invalid_instruction;
14580 return ira->codegen->invalid_inst_gen;
1353114581
13532 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
14582 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1353314583 if (type_is_invalid(cast2->value->type))
13534 return ira->codegen->invalid_instruction;
14584 return ira->codegen->invalid_inst_gen;
1353514585
1353614586 return cast2;
1353714587 }
......@@ -13546,13 +14596,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1354614596 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
1354714597 {
1354814598 if (value->value->special == ConstValSpecialUndef) {
13549 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14599 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1355014600 result->value->special = ConstValSpecialUndef;
1355114601 return result;
1355214602 }
1355314603 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
1355414604 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
13555 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14605 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1355614606 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
1355714607 copy_const_val(result->value, value->value);
1355814608 result->value->type = wanted_type;
......@@ -13561,7 +14611,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1356114611 }
1356214612 return result;
1356314613 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {
13564 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14614 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1356514615 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
1356614616 BigFloat bf;
1356714617 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
......@@ -13573,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1357314623 }
1357414624 zig_unreachable();
1357514625 } else {
13576 return ira->codegen->invalid_instruction;
14626 return ira->codegen->invalid_inst_gen;
1357714627 }
1357814628 }
1357914629
......@@ -13609,13 +14659,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1360914659 actual_type->data.pointer.ptr_len == PtrLenSingle &&
1361014660 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1361114661 {
13612 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
14662 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
1361314663 if (type_is_invalid(cast1->value->type))
13614 return ira->codegen->invalid_instruction;
14664 return ira->codegen->invalid_inst_gen;
1361514665
13616 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
14666 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1361714667 if (type_is_invalid(cast2->value->type))
13618 return ira->codegen->invalid_instruction;
14668 return ira->codegen->invalid_inst_gen;
1361914669
1362014670 return cast2;
1362114671 }
......@@ -13636,9 +14686,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1363614686 actual_array_type->data.array.sentinel)))
1363714687 {
1363814688 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13639 return ira->codegen->invalid_instruction;
14689 return ira->codegen->invalid_inst_gen;
1364014690 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13641 return ira->codegen->invalid_instruction;
14691 return ira->codegen->invalid_inst_gen;
1364214692 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&
1364314693 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
1364414694 actual_type->data.pointer.child_type->data.array.child_type, source_node,
......@@ -13679,24 +14729,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1367914729 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
1368014730 ResolveStatusAlignmentKnown)))
1368114731 {
13682 return ira->codegen->invalid_instruction;
14732 return ira->codegen->invalid_inst_gen;
1368314733 }
1368414734 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
1368514735 ResolveStatusAlignmentKnown)))
1368614736 {
13687 return ira->codegen->invalid_instruction;
14737 return ira->codegen->invalid_inst_gen;
1368814738 }
1368914739 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
1369014740 }
1369114741 if (ok_align) {
1369214742 if (wanted_type->id == ZigTypeIdErrorUnion) {
13693 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
14743 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
1369414744 if (type_is_invalid(cast1->value->type))
13695 return ira->codegen->invalid_instruction;
14745 return ira->codegen->invalid_inst_gen;
1369614746
13697 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
14747 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1369814748 if (type_is_invalid(cast2->value->type))
13699 return ira->codegen->invalid_instruction;
14749 return ira->codegen->invalid_inst_gen;
1370014750
1370114751 return cast2;
1370214752 } else {
......@@ -13731,12 +14781,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1373114781 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
1373214782 ResolveStatusAlignmentKnown)))
1373314783 {
13734 return ira->codegen->invalid_instruction;
14784 return ira->codegen->invalid_inst_gen;
1373514785 }
1373614786 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
1373714787 ResolveStatusAlignmentKnown)))
1373814788 {
13739 return ira->codegen->invalid_instruction;
14789 return ira->codegen->invalid_inst_gen;
1374014790 }
1374114791 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
1374214792 }
......@@ -13777,7 +14827,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1377714827 }
1377814828 }
1377914829 if (ok) {
13780 IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
14830 IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
1378114831 if (anyframe_type == wanted_type)
1378214832 return cast1;
1378314833 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
......@@ -13832,28 +14882,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1383214882 if (actual_type->id == ZigTypeIdEnumLiteral &&
1383314883 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
1383414884 {
13835 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
13836 if (result == ira->codegen->invalid_instruction)
14885 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
14886 if (type_is_invalid(result->value->type))
1383714887 return result;
1383814888
13839 return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr);
14889 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
1384014890 }
1384114891
1384214892 // cast from enum literal to error union when payload is an enum
1384314893 if (actual_type->id == ZigTypeIdEnumLiteral &&
1384414894 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
1384514895 {
13846 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
13847 if (result == ira->codegen->invalid_instruction)
14896 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
14897 if (type_is_invalid(result->value->type))
1384814898 return result;
1384914899
13850 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr);
14900 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
1385114901 }
1385214902
1385314903 // cast from union to the enum type of the union
1385414904 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {
1385514905 if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown)))
13856 return ira->codegen->invalid_instruction;
14906 return ira->codegen->invalid_inst_gen;
1385714907
1385814908 if (actual_type->data.unionation.tag_type == wanted_type) {
1385914909 return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type);
......@@ -13881,8 +14931,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1388114931 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
1388214932 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
1388314933 {
13884 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->source_node)))
13885 return ira->codegen->invalid_instruction;
14934 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node)))
14935 return ira->codegen->invalid_inst_gen;
1388614936
1388714937 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);
1388814938 }
......@@ -13905,7 +14955,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1390514955 slice_ptr_type->data.pointer.sentinel))))
1390614956 {
1390714957 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];
13908 IrInstruction *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);
14958 IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);
1390914959 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);
1391014960 }
1391114961 }
......@@ -13936,7 +14986,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1393614986 {
1393714987 bool has_bits;
1393814988 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))
13939 return ira->codegen->invalid_instruction;
14989 return ira->codegen->invalid_inst_gen;
1394014990 if (!has_bits) {
1394114991 return ir_get_ref(ira, source_instr, value, false, false);
1394214992 }
......@@ -14003,9 +15053,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1400315053
1400415054 // T to ?U, where T implicitly casts to U
1400515055 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {
14006 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
15056 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
1400715057 if (type_is_invalid(cast1->value->type))
14008 return ira->codegen->invalid_instruction;
15058 return ira->codegen->invalid_inst_gen;
1400915059 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
1401015060 }
1401115061
......@@ -14013,9 +15063,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1401315063 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&
1401415064 actual_type->id != ZigTypeIdErrorSet)
1401515065 {
14016 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);
15066 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);
1401715067 if (type_is_invalid(cast1->value->type))
14018 return ira->codegen->invalid_instruction;
15068 return ira->codegen->invalid_inst_gen;
1401915069 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
1402015070 }
1402115071
......@@ -14024,14 +15074,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1402415074 buf_ptr(&wanted_type->name),
1402515075 buf_ptr(&actual_type->name)));
1402615076 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);
14027 return ira->codegen->invalid_instruction;
15077 return ira->codegen->invalid_inst_gen;
1402815078}
1402915079
14030static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,
14031 IrInstruction *value, ZigType *expected_type)
15080static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
15081 IrInstGen *value, ZigType *expected_type)
1403215082{
1403315083 assert(value);
14034 assert(value != ira->codegen->invalid_instruction);
1403515084 assert(!expected_type || !type_is_invalid(expected_type));
1403615085 assert(value->value->type);
1403715086 assert(!type_is_invalid(value->value->type));
......@@ -14045,17 +15094,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou
1404515094 return ir_analyze_cast(ira, value_source_instr, expected_type, value);
1404615095}
1404715096
14048static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
14049 return ir_implicit_cast2(ira, value, value, expected_type);
15097static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) {
15098 return ir_implicit_cast2(ira, &value->base, value, expected_type);
1405015099}
1405115100
14052static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
14053 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);
15101static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
15102 ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr);
1405415103 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
1405515104 if (elem_type != g->builtin_types.entry_var)
1405615105 return elem_type;
1405715106
14058 if (ir_resolve_lazy(g, ptr->source_node, ptr->value))
15107 if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value))
1405915108 return g->builtin_types.entry_invalid;
1406015109
1406115110 assert(value_is_comptime(ptr->value));
......@@ -14063,28 +15112,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
1406315112 return pointee->type;
1406415113}
1406515114
14066static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
15115static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr,
1406715116 ResultLoc *result_loc)
1406815117{
1406915118 Error err;
1407015119 ZigType *ptr_type = ptr->value->type;
1407115120 if (type_is_invalid(ptr_type))
14072 return ira->codegen->invalid_instruction;
15121 return ira->codegen->invalid_inst_gen;
1407315122
1407415123 if (ptr_type->id != ZigTypeIdPointer) {
1407515124 ir_add_error_node(ira, source_instruction->source_node,
1407615125 buf_sprintf("attempt to dereference non-pointer type '%s'",
1407715126 buf_ptr(&ptr_type->name)));
14078 return ira->codegen->invalid_instruction;
15127 return ira->codegen->invalid_inst_gen;
1407915128 }
1408015129
1408115130 ZigType *child_type = ptr_type->data.pointer.child_type;
1408215131 if (type_is_invalid(child_type))
14083 return ira->codegen->invalid_instruction;
15132 return ira->codegen->invalid_inst_gen;
1408415133 // if the child type has one possible value, the deref is comptime
1408515134 switch (type_has_one_possible_value(ira->codegen, child_type)) {
1408615135 case OnePossibleValueInvalid:
14087 return ira->codegen->invalid_instruction;
15136 return ira->codegen->invalid_inst_gen;
1408815137 case OnePossibleValueYes:
1408915138 return ir_const_move(ira, source_instruction,
1409015139 get_the_one_possible_value(ira->codegen, child_type));
......@@ -14093,8 +15142,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1409315142 }
1409415143 if (instr_is_comptime(ptr)) {
1409515144 if (ptr->value->special == ConstValSpecialUndef) {
14096 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));
14097 return ira->codegen->invalid_instruction;
15145 ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value"));
15146 return ira->codegen->invalid_inst_gen;
1409815147 }
1409915148 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
1410015149 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
......@@ -14102,12 +15151,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1410215151 child_type = pointee->type;
1410315152 }
1410415153 if (pointee->special != ConstValSpecialRuntime) {
14105 IrInstruction *result = ir_const(ira, source_instruction, child_type);
15154 IrInstGen *result = ir_const(ira, source_instruction, child_type);
1410615155
1410715156 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,
1410815157 ptr->value)))
1410915158 {
14110 return ira->codegen->invalid_instruction;
15159 return ira->codegen->invalid_inst_gen;
1411115160 }
1411215161 result->value->type = child_type;
1411315162 return result;
......@@ -14116,38 +15165,38 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1411615165 }
1411715166
1411815167 // if the instruction is a const ref instruction we can skip it
14119 if (ptr->id == IrInstructionIdRef) {
14120 IrInstructionRef *ref_inst = reinterpret_cast<IrInstructionRef *>(ptr);
14121 return ref_inst->value;
15168 if (ptr->id == IrInstGenIdRef) {
15169 IrInstGenRef *ref_inst = reinterpret_cast<IrInstGenRef *>(ptr);
15170 return ref_inst->operand;
1412215171 }
1412315172
1412415173 // If the instruction is a element pointer instruction to a vector, we emit
1412515174 // vector element extract instruction rather than load pointer. If the
1412615175 // pointer type has non-VECTOR_INDEX_RUNTIME value, it would have been
14127 // possible to implement this in the codegen for IrInstructionLoadPtrGen.
15176 // possible to implement this in the codegen for IrInstGenLoadPtr.
1412815177 // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error
1412915178 // if the vector index cannot be determined right here, right now, because
1413015179 // the type information does not contain enough information to actually
1413115180 // perform a dereference.
1413215181 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
14133 if (ptr->id == IrInstructionIdElemPtr) {
14134 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;
14135 IrInstruction *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr,
15182 if (ptr->id == IrInstGenIdElemPtr) {
15183 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
15184 IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base,
1413615185 elem_ptr->array_ptr, nullptr);
14137 IrInstruction *elem_index = elem_ptr->elem_index;
15186 IrInstGen *elem_index = elem_ptr->elem_index;
1413815187 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);
1413915188 }
14140 ir_add_error(ira, ptr,
15189 ir_add_error(ira, &ptr->base,
1414115190 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));
14142 return ira->codegen->invalid_instruction;
15191 return ira->codegen->invalid_inst_gen;
1414315192 }
1414415193
14145 IrInstruction *result_loc_inst;
15194 IrInstGen *result_loc_inst;
1414615195 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {
1414715196 if (result_loc == nullptr) result_loc = no_result_loc();
1414815197 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,
1414915198 true, false, true);
14150 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
15199 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
1415115200 return result_loc_inst;
1415215201 }
1415315202 } else {
......@@ -14157,7 +15206,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1415715206 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);
1415815207}
1415915208
14160static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
15209static bool ir_resolve_const_align(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
1416115210 ZigValue *const_val, uint32_t *out)
1416215211{
1416315212 Error err;
......@@ -14166,12 +15215,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
1416615215
1416715216 uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);
1416815217 if (align_bytes == 0) {
14169 exec_add_error_node(codegen, exec, source_node, buf_sprintf("alignment must be >= 1"));
15218 exec_add_error_node_gen(codegen, exec, source_node, buf_sprintf("alignment must be >= 1"));
1417015219 return false;
1417115220 }
1417215221
1417315222 if (!is_power_of_2(align_bytes)) {
14174 exec_add_error_node(codegen, exec, source_node,
15223 exec_add_error_node_gen(codegen, exec, source_node,
1417515224 buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes));
1417615225 return false;
1417715226 }
......@@ -14180,7 +15229,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
1418015229 return true;
1418115230}
1418215231
14183static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) {
15232static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_type, uint32_t *out) {
1418415233 if (type_is_invalid(value->value->type))
1418515234 return false;
1418615235
......@@ -14201,19 +15250,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem
1420115250 }
1420215251 }
1420315252
14204 IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));
15253 IrInstGen *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));
1420515254 if (type_is_invalid(casted_value->value->type))
1420615255 return false;
1420715256
14208 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,
15257 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node,
1420915258 casted_value->value, out);
1421015259}
1421115260
14212static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) {
15261static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstGen *value, ZigType *int_type, uint64_t *out) {
1421315262 if (type_is_invalid(value->value->type))
1421415263 return false;
1421515264
14216 IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type);
15265 IrInstGen *casted_value = ir_implicit_cast(ira, value, int_type);
1421715266 if (type_is_invalid(casted_value->value->type))
1421815267 return false;
1421915268
......@@ -14225,15 +15274,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
1422515274 return true;
1422615275}
1422715276
14228static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {
15277static bool ir_resolve_usize(IrAnalyze *ira, IrInstGen *value, uint64_t *out) {
1422915278 return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out);
1423015279}
1423115280
14232static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
15281static bool ir_resolve_bool(IrAnalyze *ira, IrInstGen *value, bool *out) {
1423315282 if (type_is_invalid(value->value->type))
1423415283 return false;
1423515284
14236 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
15285 IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
1423715286 if (type_is_invalid(casted_value->value->type))
1423815287 return false;
1423915288
......@@ -14245,7 +15294,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
1424515294 return true;
1424615295}
1424715296
14248static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) {
15297static bool ir_resolve_comptime(IrAnalyze *ira, IrInstGen *value, bool *out) {
1424915298 if (!value) {
1425015299 *out = false;
1425115300 return true;
......@@ -14253,13 +15302,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
1425315302 return ir_resolve_bool(ira, value, out);
1425415303}
1425515304
14256static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
15305static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstGen *value, AtomicOrder *out) {
1425715306 if (type_is_invalid(value->value->type))
1425815307 return false;
1425915308
1426015309 ZigType *atomic_order_type = get_builtin_type(ira->codegen, "AtomicOrder");
1426115310
14262 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
15311 IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
1426315312 if (type_is_invalid(casted_value->value->type))
1426415313 return false;
1426515314
......@@ -14271,13 +15320,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
1427115320 return true;
1427215321}
1427315322
14274static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) {
15323static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstGen *value, AtomicRmwOp *out) {
1427515324 if (type_is_invalid(value->value->type))
1427615325 return false;
1427715326
1427815327 ZigType *atomic_rmw_op_type = get_builtin_type(ira->codegen, "AtomicRmwOp");
1427915328
14280 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
15329 IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
1428115330 if (type_is_invalid(casted_value->value->type))
1428215331 return false;
1428315332
......@@ -14289,13 +15338,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
1428915338 return true;
1429015339}
1429115340
14292static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) {
15341static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstGen *value, GlobalLinkageId *out) {
1429315342 if (type_is_invalid(value->value->type))
1429415343 return false;
1429515344
1429615345 ZigType *global_linkage_type = get_builtin_type(ira->codegen, "GlobalLinkage");
1429715346
14298 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
15347 IrInstGen *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
1429915348 if (type_is_invalid(casted_value->value->type))
1430015349 return false;
1430115350
......@@ -14307,13 +15356,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
1430715356 return true;
1430815357}
1430915358
14310static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) {
15359static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstGen *value, FloatMode *out) {
1431115360 if (type_is_invalid(value->value->type))
1431215361 return false;
1431315362
1431415363 ZigType *float_mode_type = get_builtin_type(ira->codegen, "FloatMode");
1431515364
14316 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);
15365 IrInstGen *casted_value = ir_implicit_cast(ira, value, float_mode_type);
1431715366 if (type_is_invalid(casted_value->value->type))
1431815367 return false;
1431915368
......@@ -14325,14 +15374,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
1432515374 return true;
1432615375}
1432715376
14328static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
15377static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) {
1432915378 if (type_is_invalid(value->value->type))
1433015379 return nullptr;
1433115380
1433215381 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1433315382 true, false, PtrLenUnknown, 0, 0, 0, false);
1433415383 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
14335 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
15384 IrInstGen *casted_value = ir_implicit_cast(ira, value, str_type);
1433615385 if (type_is_invalid(casted_value->value->type))
1433715386 return nullptr;
1433815387
......@@ -14356,7 +15405,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1435615405 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
1435715406 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
1435815407 if (char_val->special == ConstValSpecialUndef) {
14359 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
15408 ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value"));
1436015409 return nullptr;
1436115410 }
1436215411 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
......@@ -14367,10 +15416,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1436715416 return result;
1436815417}
1436915418
14370static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
14371 IrInstructionAddImplicitReturnType *instruction)
15419static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
15420 IrInstSrcAddImplicitReturnType *instruction)
1437215421{
14373 IrInstruction *value = instruction->value->child;
15422 IrInstGen *value = instruction->value->child;
1437415423 if (type_is_invalid(value->value->type))
1437515424 return ir_unreach_error(ira);
1437615425
......@@ -14378,15 +15427,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
1437815427 ira->src_implicit_return_type_list.append(value);
1437915428 }
1438015429
14381 return ir_const_void(ira, &instruction->base);
15430 return ir_const_void(ira, &instruction->base.base);
1438215431}
1438315432
14384static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) {
14385 IrInstruction *operand = instruction->operand->child;
15433static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) {
15434 IrInstGen *operand = instruction->operand->child;
1438615435 if (type_is_invalid(operand->value->type))
1438715436 return ir_unreach_error(ira);
1438815437
14389 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
15438 IrInstGen *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
1439015439 if (type_is_invalid(casted_operand->value->type)) {
1439115440 AstNode *source_node = ira->explicit_return_type_source_node;
1439215441 if (source_node != nullptr) {
......@@ -14401,9 +15450,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1440115450 handle_is_ptr(ira->explicit_return_type))
1440215451 {
1440315452 // result location mechanism took care of it.
14404 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
14405 instruction->base.source_node, nullptr);
14406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
15453 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);
1440715454 return ir_finish_anal(ira, result);
1440815455 }
1440915456
......@@ -14411,47 +15458,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1441115458 casted_operand->value->type->id == ZigTypeIdPointer &&
1441215459 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
1441315460 {
14414 ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable"));
15461 ir_add_error(ira, &casted_operand->base, buf_sprintf("function returns address of local variable"));
1441515462 return ir_unreach_error(ira);
1441615463 }
1441715464
14418 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
14419 instruction->base.source_node, casted_operand);
14420 result->value->type = ira->codegen->builtin_types.entry_unreachable;
15465 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand);
1442115466 return ir_finish_anal(ira, result);
1442215467}
1442315468
14424static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {
14425 return ir_const_move(ira, &instruction->base, instruction->base.value);
15469static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) {
15470 return ir_const_move(ira, &instruction->base.base, instruction->value);
1442615471}
1442715472
14428static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
14429 IrInstruction *op1 = bin_op_instruction->op1->child;
15473static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
15474 IrInstGen *op1 = bin_op_instruction->op1->child;
1443015475 if (type_is_invalid(op1->value->type))
14431 return ira->codegen->invalid_instruction;
15476 return ira->codegen->invalid_inst_gen;
1443215477
14433 IrInstruction *op2 = bin_op_instruction->op2->child;
15478 IrInstGen *op2 = bin_op_instruction->op2->child;
1443415479 if (type_is_invalid(op2->value->type))
14435 return ira->codegen->invalid_instruction;
15480 return ira->codegen->invalid_inst_gen;
1443615481
1443715482 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1443815483
14439 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
14440 if (casted_op1 == ira->codegen->invalid_instruction)
14441 return ira->codegen->invalid_instruction;
15484 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
15485 if (type_is_invalid(casted_op1->value->type))
15486 return ira->codegen->invalid_inst_gen;
1444215487
14443 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type);
14444 if (casted_op2 == ira->codegen->invalid_instruction)
14445 return ira->codegen->invalid_instruction;
15488 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, bool_type);
15489 if (type_is_invalid(casted_op2->value->type))
15490 return ira->codegen->invalid_inst_gen;
1444615491
1444715492 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
1444815493 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
1444915494 if (op1_val == nullptr)
14450 return ira->codegen->invalid_instruction;
15495 return ira->codegen->invalid_inst_gen;
1445115496
1445215497 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1445315498 if (op2_val == nullptr)
14454 return ira->codegen->invalid_instruction;
15499 return ira->codegen->invalid_inst_gen;
1445515500
1445615501 assert(casted_op1->value->type->id == ZigTypeIdBool);
1445715502 assert(casted_op2->value->type->id == ZigTypeIdBool);
......@@ -14463,14 +15508,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
1446315508 } else {
1446415509 zig_unreachable();
1446515510 }
14466 return ir_const_bool(ira, &bin_op_instruction->base, result_bool);
15511 return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool);
1446715512 }
1446815513
14469 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
14470 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
15514 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type,
1447115515 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
14472 result->value->type = bool_type;
14473 return result;
1447415516}
1447515517
1447615518static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
......@@ -14535,12 +15577,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
1453515577 }
1453615578}
1453715579
14538static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
14539 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,
14540 bool one_possible_value) {
15580static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
15581 ZigValue *op1_val, ZigValue *op2_val, IrInstSrcBinOp *bin_op_instruction, IrBinOp op_id,
15582 bool one_possible_value)
15583{
1454115584 if (op1_val->special == ConstValSpecialUndef ||
1454215585 op2_val->special == ConstValSpecialUndef)
14543 return ir_const_undef(ira, &bin_op_instruction->base, resolved_type);
15586 return ir_const_undef(ira, &bin_op_instruction->base.base, resolved_type);
1454415587 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {
1454515588 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
1454615589 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&
......@@ -14560,7 +15603,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
1456015603 cmp_result = CmpEQ;
1456115604 }
1456215605 bool answer = resolve_cmp_op_id(op_id, cmp_result);
14563 return ir_const_bool(ira, &bin_op_instruction->base, answer);
15606 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1456415607 }
1456515608 } else {
1456615609 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);
......@@ -14572,7 +15615,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
1457215615 } else {
1457315616 zig_unreachable();
1457415617 }
14575 return ir_const_bool(ira, &bin_op_instruction->base, answer);
15618 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1457615619 }
1457715620 zig_unreachable();
1457815621}
......@@ -14626,7 +15669,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {
1462615669 zig_unreachable();
1462715670}
1462815671
14629static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source_instr,
15672static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
1463015673 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
1463115674{
1463215675 Error err;
......@@ -14704,14 +15747,14 @@ never_mind_just_calculate_it_normally:
1470415747 return nullptr;
1470515748 }
1470615749 if (op1_val->type->id == ZigTypeIdComptimeFloat) {
14707 IrInstruction *tmp = ir_const_noval(ira, source_instr);
15750 IrInstGen *tmp = ir_const_noval(ira, source_instr);
1470815751 tmp->value = op1_val;
14709 IrInstruction *casted = ir_implicit_cast(ira, tmp, op2_val->type);
15752 IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type);
1471015753 op1_val = casted->value;
1471115754 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {
14712 IrInstruction *tmp = ir_const_noval(ira, source_instr);
15755 IrInstGen *tmp = ir_const_noval(ira, source_instr);
1471315756 tmp->value = op2_val;
14714 IrInstruction *casted = ir_implicit_cast(ira, tmp, op1_val->type);
15757 IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type);
1471515758 op2_val = casted->value;
1471615759 }
1471715760 Cmp cmp_result = float_cmp(op1_val, op2_val);
......@@ -14753,8 +15796,8 @@ never_mind_just_calculate_it_normally:
1475315796 return nullptr;
1475415797}
1475515798
14756static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstruction *source_instr,
14757 IrInstruction *op1, IrInstruction *op2, IrBinOp op_id)
15799static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr,
15800 IrInstGen *op1, IrInstGen *op2, IrBinOp op_id)
1475815801{
1475915802 Error err;
1476015803
......@@ -14767,7 +15810,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1476715810 ir_add_error(ira, source_instr,
1476815811 buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32,
1476915812 op1->value->type->data.vector.len, op2->value->type->data.vector.len));
14770 return ira->codegen->invalid_instruction;
15813 return ira->codegen->invalid_inst_gen;
1477115814 }
1477215815 result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type);
1477315816 op1_scalar_type = op1->value->type->data.vector.elem_type;
......@@ -14776,13 +15819,13 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1477615819 ir_add_error(ira, source_instr,
1477715820 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",
1477815821 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
14779 return ira->codegen->invalid_instruction;
15822 return ira->codegen->invalid_inst_gen;
1478015823 }
1478115824
1478215825 bool opv_op1;
1478315826 switch (type_has_one_possible_value(ira->codegen, op1->value->type)) {
1478415827 case OnePossibleValueInvalid:
14785 return ira->codegen->invalid_instruction;
15828 return ira->codegen->invalid_inst_gen;
1478615829 case OnePossibleValueYes:
1478715830 opv_op1 = true;
1478815831 break;
......@@ -14793,7 +15836,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1479315836 bool opv_op2;
1479415837 switch (type_has_one_possible_value(ira->codegen, op2->value->type)) {
1479515838 case OnePossibleValueInvalid:
14796 return ira->codegen->invalid_instruction;
15839 return ira->codegen->invalid_inst_gen;
1479715840 case OnePossibleValueYes:
1479815841 opv_op2 = true;
1479915842 break;
......@@ -14804,21 +15847,21 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1480415847 Cmp op1_cmp_zero;
1480515848 bool have_op1_cmp_zero = false;
1480615849 if ((err = lazy_cmp_zero(source_instr->source_node, op1->value, &op1_cmp_zero))) {
14807 if (err != ErrorNotLazy) return ira->codegen->invalid_instruction;
15850 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
1480815851 } else {
1480915852 have_op1_cmp_zero = true;
1481015853 }
1481115854 Cmp op2_cmp_zero;
1481215855 bool have_op2_cmp_zero = false;
1481315856 if ((err = lazy_cmp_zero(source_instr->source_node, op2->value, &op2_cmp_zero))) {
14814 if (err != ErrorNotLazy) return ira->codegen->invalid_instruction;
15857 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
1481515858 } else {
1481615859 have_op2_cmp_zero = true;
1481715860 }
1481815861 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||
1481915862 (have_op1_cmp_zero && have_op2_cmp_zero))
1482015863 {
14821 IrInstruction *result_instruction = ir_const(ira, source_instr, result_type);
15864 IrInstGen *result_instruction = ir_const(ira, source_instr, result_type);
1482215865 ZigValue *out_val = result_instruction->value;
1482315866 if (result_type->id == ZigTypeIdVector) {
1482415867 size_t len = result_type->data.vector.len;
......@@ -14836,7 +15879,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1483615879 if (msg != nullptr) {
1483715880 add_error_note(ira->codegen, msg, source_instr->source_node,
1483815881 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
14839 return ira->codegen->invalid_instruction;
15882 return ira->codegen->invalid_inst_gen;
1484015883 }
1484115884 }
1484215885 out_val->type = result_type;
......@@ -14845,7 +15888,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1484515888 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,
1484615889 op2->value, out_val) != nullptr)
1484715890 {
14848 return ira->codegen->invalid_instruction;
15891 return ira->codegen->invalid_inst_gen;
1484915892 }
1485015893 }
1485115894 return result_instruction;
......@@ -14939,10 +15982,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1493915982 }
1494015983 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
1494115984 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;
14942 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
14943 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
15985 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
15986 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
1494415987 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))
14945 return ira->codegen->invalid_instruction;
15988 return ira->codegen->invalid_inst_gen;
1494615989 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
1494715990 }
1494815991
......@@ -14972,12 +16015,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1497216015 if (instr_is_comptime(op1)) {
1497316016 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
1497416017 if (op1_val == nullptr)
14975 return ira->codegen->invalid_instruction;
16018 return ira->codegen->invalid_inst_gen;
1497616019 if (op1_val->special == ConstValSpecialUndef)
1497716020 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
1497816021 if (result_type->id == ZigTypeIdVector) {
14979 ir_add_error(ira, op1, buf_sprintf("compiler bug: TODO: support comptime vector here"));
14980 return ira->codegen->invalid_instruction;
16022 ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16023 return ira->codegen->invalid_inst_gen;
1498116024 }
1498216025 bool is_unsigned;
1498316026 if (op1_is_float) {
......@@ -15016,12 +16059,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1501616059 if (instr_is_comptime(op2)) {
1501716060 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
1501816061 if (op2_val == nullptr)
15019 return ira->codegen->invalid_instruction;
16062 return ira->codegen->invalid_inst_gen;
1502016063 if (op2_val->special == ConstValSpecialUndef)
1502116064 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
1502216065 if (result_type->id == ZigTypeIdVector) {
15023 ir_add_error(ira, op2, buf_sprintf("compiler bug: TODO: support comptime vector here"));
15024 return ira->codegen->invalid_instruction;
16066 ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16067 return ira->codegen->invalid_inst_gen;
1502516068 }
1502616069 bool is_unsigned;
1502716070 if (op2_is_float) {
......@@ -15062,35 +16105,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1506216105 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
1506316106 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;
1506416107
15065 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
16108 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
1506616109 if (type_is_invalid(casted_op1->value->type))
15067 return ira->codegen->invalid_instruction;
15068 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
16110 return ira->codegen->invalid_inst_gen;
16111 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
1506916112 if (type_is_invalid(casted_op2->value->type))
15070 return ira->codegen->invalid_instruction;
16113 return ira->codegen->invalid_inst_gen;
1507116114 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
1507216115}
1507316116
15074static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
15075 IrInstruction *op1 = bin_op_instruction->op1->child;
16117static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
16118 IrInstGen *op1 = bin_op_instruction->op1->child;
1507616119 if (type_is_invalid(op1->value->type))
15077 return ira->codegen->invalid_instruction;
16120 return ira->codegen->invalid_inst_gen;
1507816121
15079 IrInstruction *op2 = bin_op_instruction->op2->child;
16122 IrInstGen *op2 = bin_op_instruction->op2->child;
1508016123 if (type_is_invalid(op2->value->type))
15081 return ira->codegen->invalid_instruction;
16124 return ira->codegen->invalid_inst_gen;
1508216125
15083 AstNode *source_node = bin_op_instruction->base.source_node;
16126 AstNode *source_node = bin_op_instruction->base.base.source_node;
1508416127
1508516128 IrBinOp op_id = bin_op_instruction->op_id;
1508616129 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
1508716130 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {
15088 return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq));
16131 return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq));
1508916132 } else if (is_equality_cmp &&
1509016133 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
1509116134 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
1509216135 {
15093 IrInstruction *maybe_op;
16136 IrInstGen *maybe_op;
1509416137 if (op1->value->type->id == ZigTypeIdNull) {
1509516138 maybe_op = op2;
1509616139 } else if (op2->value->type->id == ZigTypeIdNull) {
......@@ -15101,21 +16144,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1510116144 if (instr_is_comptime(maybe_op)) {
1510216145 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
1510316146 if (!maybe_val)
15104 return ira->codegen->invalid_instruction;
16147 return ira->codegen->invalid_inst_gen;
1510516148 bool is_null = optional_value_is_null(maybe_val);
1510616149 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
15107 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);
16150 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
1510816151 }
1510916152
15110 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
15111 source_node, maybe_op);
15112 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
16153 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op);
1511316154
1511416155 if (op_id == IrBinOpCmpEq) {
15115 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
15116 bin_op_instruction->base.source_node, is_non_null);
15117 result->value->type = ira->codegen->builtin_types.entry_bool;
15118 return result;
16156 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
1511916157 } else {
1512016158 return is_non_null;
1512116159 }
......@@ -15125,7 +16163,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1512516163 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&
1512616164 op1->value->type->data.pointer.ptr_len == PtrLenC)))
1512716165 {
15128 IrInstruction *c_ptr_op;
16166 IrInstGen *c_ptr_op;
1512916167 if (op1->value->type->id == ZigTypeIdNull) {
1513016168 c_ptr_op = op2;
1513116169 } else if (op2->value->type->id == ZigTypeIdNull) {
......@@ -15136,24 +16174,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1513616174 if (instr_is_comptime(c_ptr_op)) {
1513716175 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);
1513816176 if (!c_ptr_val)
15139 return ira->codegen->invalid_instruction;
16177 return ira->codegen->invalid_inst_gen;
1514016178 if (c_ptr_val->special == ConstValSpecialUndef)
15141 return ir_const_undef(ira, &bin_op_instruction->base, ira->codegen->builtin_types.entry_bool);
16179 return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool);
1514216180 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
1514316181 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
1514416182 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
1514516183 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
15146 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);
16184 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
1514716185 }
15148 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
15149 source_node, c_ptr_op);
15150 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
16186 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op);
1515116187
1515216188 if (op_id == IrBinOpCmpEq) {
15153 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
15154 bin_op_instruction->base.source_node, is_non_null);
15155 result->value->type = ira->codegen->builtin_types.entry_bool;
15156 return result;
16189 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
1515716190 } else {
1515816191 return is_non_null;
1515916192 }
......@@ -15161,61 +16194,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1516116194 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
1516216195 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
1516316196 buf_ptr(&non_null_type->name)));
15164 return ira->codegen->invalid_instruction;
16197 return ira->codegen->invalid_inst_gen;
1516516198 } else if (is_equality_cmp && (
1516616199 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||
1516716200 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))
1516816201 {
1516916202 // Support equality comparison between a union's tag value and a enum literal
15170 IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
15171 IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
16203 IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
16204 IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
1517216205
1517316206 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;
1517416207 assert(tag_type != nullptr);
1517516208
15176 IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type);
16209 IrInstGen *casted_union = ir_implicit_cast(ira, union_val, tag_type);
1517716210 if (type_is_invalid(casted_union->value->type))
15178 return ira->codegen->invalid_instruction;
16211 return ira->codegen->invalid_inst_gen;
1517916212
15180 IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type);
16213 IrInstGen *casted_val = ir_implicit_cast(ira, enum_val, tag_type);
1518116214 if (type_is_invalid(casted_val->value->type))
15182 return ira->codegen->invalid_instruction;
16215 return ira->codegen->invalid_inst_gen;
1518316216
1518416217 if (instr_is_comptime(casted_union)) {
1518516218 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);
1518616219 if (!const_union_val)
15187 return ira->codegen->invalid_instruction;
16220 return ira->codegen->invalid_inst_gen;
1518816221
1518916222 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);
1519016223 if (!const_enum_val)
15191 return ira->codegen->invalid_instruction;
16224 return ira->codegen->invalid_inst_gen;
1519216225
1519316226 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);
1519416227 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;
1519516228
15196 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);
16229 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
1519716230 }
1519816231
15199 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
15200 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
16232 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
1520116233 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);
15202 result->value->type = ira->codegen->builtin_types.entry_bool;
15203
15204 return result;
1520516234 }
1520616235
1520716236 if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) {
1520816237 if (!is_equality_cmp) {
1520916238 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
15210 return ira->codegen->invalid_instruction;
16239 return ira->codegen->invalid_inst_gen;
1521116240 }
1521216241 ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node);
1521316242 if (type_is_invalid(intersect_type)) {
15214 return ira->codegen->invalid_instruction;
16243 return ira->codegen->invalid_inst_gen;
1521516244 }
1521616245
1521716246 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {
15218 return ira->codegen->invalid_instruction;
16247 return ira->codegen->invalid_inst_gen;
1521916248 }
1522016249
1522116250 // exception if one of the operators has the type of the empty error set, we allow the comparison
......@@ -15232,7 +16261,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1523216261 } else {
1523316262 zig_unreachable();
1523416263 }
15235 return ir_const_bool(ira, &bin_op_instruction->base, answer);
16264 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1523616265 }
1523716266
1523816267 if (!type_is_global_error_set(intersect_type)) {
......@@ -15240,7 +16269,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1524016269 ir_add_error_node(ira, source_node,
1524116270 buf_sprintf("error sets '%s' and '%s' have no common errors",
1524216271 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
15243 return ira->codegen->invalid_instruction;
16272 return ira->codegen->invalid_inst_gen;
1524416273 }
1524516274 if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) {
1524616275 bool are_equal = true;
......@@ -15252,17 +16281,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1525216281 } else {
1525316282 zig_unreachable();
1525416283 }
15255 return ir_const_bool(ira, &bin_op_instruction->base, answer);
16284 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1525616285 }
1525716286 }
1525816287
1525916288 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
1526016289 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1526116290 if (op1_val == nullptr)
15262 return ira->codegen->invalid_instruction;
16291 return ira->codegen->invalid_inst_gen;
1526316292 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1526416293 if (op2_val == nullptr)
15265 return ira->codegen->invalid_instruction;
16294 return ira->codegen->invalid_inst_gen;
1526616295
1526716296 bool answer;
1526816297 bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value;
......@@ -15274,27 +16303,24 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1527416303 zig_unreachable();
1527516304 }
1527616305
15277 return ir_const_bool(ira, &bin_op_instruction->base, answer);
16306 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1527816307 }
1527916308
15280 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
15281 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
16309 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
1528216310 op_id, op1, op2, bin_op_instruction->safety_check_on);
15283 result->value->type = ira->codegen->builtin_types.entry_bool;
15284 return result;
1528516311 }
1528616312
1528716313 if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) {
1528816314 // This operation allows any combination of integer and float types, regardless of the
1528916315 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
1529016316 // numeric types.
15291 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base, op1, op2, op_id);
16317 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id);
1529216318 }
1529316319
15294 IrInstruction *instructions[] = {op1, op2};
16320 IrInstGen *instructions[] = {op1, op2};
1529516321 ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
1529616322 if (type_is_invalid(resolved_type))
15297 return ira->codegen->invalid_instruction;
16323 return ira->codegen->invalid_inst_gen;
1529816324
1529916325 bool operator_allowed;
1530016326 switch (resolved_type->id) {
......@@ -15342,21 +16368,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1534216368 if (!operator_allowed) {
1534316369 ir_add_error_node(ira, source_node,
1534416370 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
15345 return ira->codegen->invalid_instruction;
16371 return ira->codegen->invalid_inst_gen;
1534616372 }
1534716373
15348 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
15349 if (casted_op1 == ira->codegen->invalid_instruction)
15350 return ira->codegen->invalid_instruction;
16374 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
16375 if (type_is_invalid(casted_op1->value->type))
16376 return ira->codegen->invalid_inst_gen;
1535116377
15352 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15353 if (casted_op2 == ira->codegen->invalid_instruction)
15354 return ira->codegen->invalid_instruction;
16378 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16379 if (type_is_invalid(casted_op2->value->type))
16380 return ira->codegen->invalid_inst_gen;
1535516381
1535616382 bool one_possible_value;
1535716383 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
1535816384 case OnePossibleValueInvalid:
15359 return ira->codegen->invalid_instruction;
16385 return ira->codegen->invalid_inst_gen;
1536016386 case OnePossibleValueYes:
1536116387 one_possible_value = true;
1536216388 break;
......@@ -15368,20 +16394,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1536816394 if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) {
1536916395 ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);
1537016396 if (op1_val == nullptr)
15371 return ira->codegen->invalid_instruction;
16397 return ira->codegen->invalid_inst_gen;
1537216398 ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);
1537316399 if (op2_val == nullptr)
15374 return ira->codegen->invalid_instruction;
16400 return ira->codegen->invalid_inst_gen;
1537516401 if (resolved_type->id != ZigTypeIdVector)
1537616402 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);
15377 IrInstruction *result = ir_const(ira, &bin_op_instruction->base,
16403 IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base,
1537816404 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
1537916405 result->value->data.x_array.data.s_none.elements =
1538016406 create_const_vals(resolved_type->data.vector.len);
1538116407
1538216408 expand_undef_array(ira->codegen, result->value);
1538316409 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {
15384 IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
16410 IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
1538516411 &op1_val->data.x_array.data.s_none.elements[i],
1538616412 &op2_val->data.x_array.data.s_none.elements[i],
1538716413 bin_op_instruction, op_id, one_possible_value);
......@@ -15390,19 +16416,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1539016416 return result;
1539116417 }
1539216418
15393 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
15394 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
16419 ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ?
16420 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) :
16421 ira->codegen->builtin_types.entry_bool;
16422 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type,
1539516423 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
15396 if (resolved_type->id == ZigTypeIdVector) {
15397 result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len,
15398 ira->codegen->builtin_types.entry_bool);
15399 } else {
15400 result->value->type = ira->codegen->builtin_types.entry_bool;
15401 }
15402 return result;
1540316424}
1540416425
15405static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
16426static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
1540616427 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
1540716428{
1540816429 bool is_int;
......@@ -15582,10 +16603,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
1558216603}
1558316604
1558416605// This works on operands that have already been checked to be comptime known.
15585static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr,
16606static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
1558616607 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
1558716608{
15588 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);
16609 IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry);
1558916610 ZigValue *out_val = result_instruction->value;
1559016611 if (type_entry->id == ZigTypeIdVector) {
1559116612 expand_undef_array(ira->codegen, op1_val);
......@@ -15606,43 +16627,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
1560616627 if (msg != nullptr) {
1560716628 add_error_note(ira->codegen, msg, source_instr->source_node,
1560816629 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
15609 return ira->codegen->invalid_instruction;
16630 return ira->codegen->invalid_inst_gen;
1561016631 }
1561116632 }
1561216633 out_val->type = type_entry;
1561316634 out_val->special = ConstValSpecialStatic;
1561416635 } else {
1561516636 if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {
15616 return ira->codegen->invalid_instruction;
16637 return ira->codegen->invalid_inst_gen;
1561716638 }
1561816639 }
1561916640 return ir_implicit_cast(ira, result_instruction, type_entry);
1562016641}
1562116642
15622static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
15623 IrInstruction *op1 = bin_op_instruction->op1->child;
16643static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
16644 IrInstGen *op1 = bin_op_instruction->op1->child;
1562416645 if (type_is_invalid(op1->value->type))
15625 return ira->codegen->invalid_instruction;
16646 return ira->codegen->invalid_inst_gen;
1562616647
1562716648 if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) {
15628 ir_add_error(ira, bin_op_instruction->op1,
16649 ir_add_error(ira, &bin_op_instruction->op1->base,
1562916650 buf_sprintf("bit shifting operation expected integer type, found '%s'",
1563016651 buf_ptr(&op1->value->type->name)));
15631 return ira->codegen->invalid_instruction;
16652 return ira->codegen->invalid_inst_gen;
1563216653 }
1563316654
15634 IrInstruction *op2 = bin_op_instruction->op2->child;
16655 IrInstGen *op2 = bin_op_instruction->op2->child;
1563516656 if (type_is_invalid(op2->value->type))
15636 return ira->codegen->invalid_instruction;
16657 return ira->codegen->invalid_inst_gen;
1563716658
1563816659 if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) {
15639 ir_add_error(ira, bin_op_instruction->op2,
16660 ir_add_error(ira, &bin_op_instruction->op2->base,
1564016661 buf_sprintf("shift amount has to be an integer type, but found '%s'",
1564116662 buf_ptr(&op2->value->type->name)));
15642 return ira->codegen->invalid_instruction;
16663 return ira->codegen->invalid_inst_gen;
1564316664 }
1564416665
15645 IrInstruction *casted_op2;
16666 IrInstGen *casted_op2;
1564616667 IrBinOp op_id = bin_op_instruction->op_id;
1564716668 if (op1->value->type->id == ZigTypeIdComptimeInt) {
1564816669 casted_op2 = op2;
......@@ -15654,8 +16675,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1565416675 if (casted_op2->value->data.x_bigint.is_negative) {
1565516676 Buf *val_buf = buf_alloc();
1565616677 bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10);
15657 ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
15658 return ira->codegen->invalid_instruction;
16678 ir_add_error(ira, &casted_op2->base, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
16679 return ira->codegen->invalid_inst_gen;
1565916680 }
1566016681 } else {
1566116682 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
......@@ -15665,57 +16686,51 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1566516686
1566616687 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1566716688 if (op2_val == nullptr)
15668 return ira->codegen->invalid_instruction;
16689 return ira->codegen->invalid_inst_gen;
1566916690 if (!bigint_fits_in_bits(&op2_val->data.x_bigint,
1567016691 shift_amt_type->data.integral.bit_count,
1567116692 op2_val->data.x_bigint.is_negative)) {
1567216693 Buf *val_buf = buf_alloc();
1567316694 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);
1567416695 ErrorMsg* msg = ir_add_error(ira,
15675 &bin_op_instruction->base,
16696 &bin_op_instruction->base.base,
1567616697 buf_sprintf("RHS of shift is too large for LHS type"));
1567716698 add_error_note(
1567816699 ira->codegen,
1567916700 msg,
15680 op2->source_node,
16701 op2->base.source_node,
1568116702 buf_sprintf("value %s cannot fit into type %s",
1568216703 buf_ptr(val_buf),
1568316704 buf_ptr(&shift_amt_type->name)));
15684 return ira->codegen->invalid_instruction;
16705 return ira->codegen->invalid_inst_gen;
1568516706 }
1568616707 }
1568716708
1568816709 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);
15689 if (casted_op2 == ira->codegen->invalid_instruction)
15690 return ira->codegen->invalid_instruction;
16710 if (type_is_invalid(casted_op2->value->type))
16711 return ira->codegen->invalid_inst_gen;
1569116712 }
1569216713
1569316714 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
1569416715 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1569516716 if (op1_val == nullptr)
15696 return ira->codegen->invalid_instruction;
16717 return ira->codegen->invalid_inst_gen;
1569716718
1569816719 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1569916720 if (op2_val == nullptr)
15700 return ira->codegen->invalid_instruction;
16721 return ira->codegen->invalid_inst_gen;
1570116722
15702 return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val);
16723 return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1->value->type, op1_val, op_id, op2_val);
1570316724 } else if (op1->value->type->id == ZigTypeIdComptimeInt) {
15704 ir_add_error(ira, &bin_op_instruction->base,
16725 ir_add_error(ira, &bin_op_instruction->base.base,
1570516726 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
15706 return ira->codegen->invalid_instruction;
16727 return ira->codegen->invalid_inst_gen;
1570716728 } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) {
15708 IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope,
15709 bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop);
15710 result->value->type = op1->value->type;
15711 return result;
16729 return ir_build_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1, CastOpNoop);
1571216730 }
1571316731
15714 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,
15715 bin_op_instruction->base.source_node, op_id,
15716 op1, casted_op2, bin_op_instruction->safety_check_on);
15717 result->value->type = op1->value->type;
15718 return result;
16732 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type,
16733 op_id, op1, casted_op2, bin_op_instruction->safety_check_on);
1571916734}
1572016735
1572116736static bool ok_float_op(IrBinOp op) {
......@@ -15779,24 +16794,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
1577916794 zig_unreachable();
1578016795}
1578116796
15782static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) {
16797static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
1578316798 Error err;
1578416799
15785 IrInstruction *op1 = instruction->op1->child;
16800 IrInstGen *op1 = instruction->op1->child;
1578616801 if (type_is_invalid(op1->value->type))
15787 return ira->codegen->invalid_instruction;
16802 return ira->codegen->invalid_inst_gen;
1578816803
15789 IrInstruction *op2 = instruction->op2->child;
16804 IrInstGen *op2 = instruction->op2->child;
1579016805 if (type_is_invalid(op2->value->type))
15791 return ira->codegen->invalid_instruction;
16806 return ira->codegen->invalid_inst_gen;
1579216807
1579316808 IrBinOp op_id = instruction->op_id;
1579416809
1579516810 // look for pointer math
1579616811 if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) {
15797 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
16812 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
1579816813 if (type_is_invalid(casted_op2->value->type))
15799 return ira->codegen->invalid_instruction;
16814 return ira->codegen->invalid_inst_gen;
1580016815
1580116816 // If either operand is undef, result is undef.
1580216817 ZigValue *op1_val = nullptr;
......@@ -15804,28 +16819,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1580416819 if (instr_is_comptime(op1)) {
1580516820 op1_val = ir_resolve_const(ira, op1, UndefOk);
1580616821 if (op1_val == nullptr)
15807 return ira->codegen->invalid_instruction;
16822 return ira->codegen->invalid_inst_gen;
1580816823 if (op1_val->special == ConstValSpecialUndef)
15809 return ir_const_undef(ira, &instruction->base, op1->value->type);
16824 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
1581016825 }
1581116826 if (instr_is_comptime(casted_op2)) {
1581216827 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
1581316828 if (op2_val == nullptr)
15814 return ira->codegen->invalid_instruction;
16829 return ira->codegen->invalid_inst_gen;
1581516830 if (op2_val->special == ConstValSpecialUndef)
15816 return ir_const_undef(ira, &instruction->base, op1->value->type);
16831 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
1581716832 }
1581816833
1581916834 ZigType *elem_type = op1->value->type->data.pointer.child_type;
1582016835 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown)))
15821 return ira->codegen->invalid_instruction;
16836 return ira->codegen->invalid_inst_gen;
1582216837
1582316838 // NOTE: this variable is meaningful iff op2_val is not null!
1582416839 uint64_t byte_offset;
1582516840 if (op2_val != nullptr) {
1582616841 uint64_t elem_offset;
1582716842 if (!ir_resolve_usize(ira, casted_op2, &elem_offset))
15828 return ira->codegen->invalid_instruction;
16843 return ira->codegen->invalid_inst_gen;
1582916844
1583016845 byte_offset = type_size(ira->codegen, elem_type) * elem_offset;
1583116846 }
......@@ -15840,7 +16855,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1584016855 {
1584116856 uint32_t align_bytes;
1584216857 if ((err = resolve_ptr_align(ira, op1->value->type, &align_bytes)))
15843 return ira->codegen->invalid_instruction;
16858 return ira->codegen->invalid_inst_gen;
1584416859
1584516860 // If the addend is not a comptime-known value we can still count on
1584616861 // it being a multiple of the type size
......@@ -15869,23 +16884,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1586916884 } else {
1587016885 zig_unreachable();
1587116886 }
15872 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
16887 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
1587316888 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1587416889 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
1587516890 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
1587616891 return result;
1587716892 }
1587816893
15879 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
15880 instruction->base.source_node, op_id, op1, casted_op2, true);
15881 result->value->type = result_type;
15882 return result;
16894 return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true);
1588316895 }
1588416896
15885 IrInstruction *instructions[] = {op1, op2};
15886 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2);
16897 IrInstGen *instructions[] = {op1, op2};
16898 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2);
1588716899 if (type_is_invalid(resolved_type))
15888 return ira->codegen->invalid_instruction;
16900 return ira->codegen->invalid_inst_gen;
1588916901
1589016902 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
1589116903 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;
......@@ -15905,11 +16917,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1590516917 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
1590616918 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1590716919 if (op1_val == nullptr)
15908 return ira->codegen->invalid_instruction;
16920 return ira->codegen->invalid_inst_gen;
1590916921
1591016922 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1591116923 if (op2_val == nullptr)
15912 return ira->codegen->invalid_instruction;
16924 return ira->codegen->invalid_inst_gen;
1591316925
1591416926 if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) {
1591516927 // the division by zero error will be caught later, but we don't have a
......@@ -15928,11 +16940,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1592816940 }
1592916941 }
1593016942 if (!ok) {
15931 ir_add_error(ira, &instruction->base,
16943 ir_add_error(ira, &instruction->base.base,
1593216944 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
1593316945 buf_ptr(&op1->value->type->name),
1593416946 buf_ptr(&op2->value->type->name)));
15935 return ira->codegen->invalid_instruction;
16947 return ira->codegen->invalid_inst_gen;
1593616948 }
1593716949 } else {
1593816950 op_id = IrBinOpDivTrunc;
......@@ -15943,12 +16955,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1594316955 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
1594416956 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1594516957 if (op1_val == nullptr)
15946 return ira->codegen->invalid_instruction;
16958 return ira->codegen->invalid_inst_gen;
1594716959
1594816960 if (is_int) {
1594916961 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1595016962 if (op2_val == nullptr)
15951 return ira->codegen->invalid_instruction;
16963 return ira->codegen->invalid_inst_gen;
1595216964
1595316965 if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) {
1595416966 // the division by zero error will be caught later, but we don't
......@@ -15962,13 +16974,13 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1596216974 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;
1596316975 }
1596416976 } else {
15965 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15966 if (casted_op2 == ira->codegen->invalid_instruction)
15967 return ira->codegen->invalid_instruction;
16977 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16978 if (type_is_invalid(casted_op2->value->type))
16979 return ira->codegen->invalid_inst_gen;
1596816980
1596916981 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1597016982 if (op2_val == nullptr)
15971 return ira->codegen->invalid_instruction;
16983 return ira->codegen->invalid_inst_gen;
1597216984
1597316985 if (float_cmp_zero(casted_op2->value) == CmpEQ) {
1597416986 // the division by zero error will be caught later, but we don't
......@@ -15984,11 +16996,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1598416996 }
1598516997 }
1598616998 if (!ok) {
15987 ir_add_error(ira, &instruction->base,
16999 ir_add_error(ira, &instruction->base.base,
1598817000 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
1598917001 buf_ptr(&op1->value->type->name),
1599017002 buf_ptr(&op2->value->type->name)));
15991 return ira->codegen->invalid_instruction;
17003 return ira->codegen->invalid_inst_gen;
1599217004 }
1599317005 }
1599417006 op_id = IrBinOpRemRem;
......@@ -16008,12 +17020,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1600817020 }
1600917021 }
1601017022 if (!ok) {
16011 AstNode *source_node = instruction->base.source_node;
17023 AstNode *source_node = instruction->base.base.source_node;
1601217024 ir_add_error_node(ira, source_node,
1601317025 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
1601417026 buf_ptr(&op1->value->type->name),
1601517027 buf_ptr(&op2->value->type->name)));
16016 return ira->codegen->invalid_instruction;
17028 return ira->codegen->invalid_inst_gen;
1601717029 }
1601817030
1601917031 if (resolved_type->id == ZigTypeIdComptimeInt) {
......@@ -16026,33 +17038,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1602617038 }
1602717039 }
1602817040
16029 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
16030 if (casted_op1 == ira->codegen->invalid_instruction)
16031 return ira->codegen->invalid_instruction;
17041 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
17042 if (type_is_invalid(casted_op1->value->type))
17043 return ira->codegen->invalid_inst_gen;
1603217044
16033 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16034 if (casted_op2 == ira->codegen->invalid_instruction)
16035 return ira->codegen->invalid_instruction;
17045 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
17046 if (type_is_invalid(casted_op2->value->type))
17047 return ira->codegen->invalid_inst_gen;
1603617048
1603717049 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
1603817050 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
1603917051 if (op1_val == nullptr)
16040 return ira->codegen->invalid_instruction;
17052 return ira->codegen->invalid_inst_gen;
1604117053 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1604217054 if (op2_val == nullptr)
16043 return ira->codegen->invalid_instruction;
17055 return ira->codegen->invalid_inst_gen;
1604417056
16045 return ir_analyze_math_op(ira, &instruction->base, resolved_type, op1_val, op_id, op2_val);
17057 return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val);
1604617058 }
1604717059
16048 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
16049 instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on);
16050 result->value->type = resolved_type;
16051 return result;
17060 return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type,
17061 op_id, casted_op1, casted_op2, instruction->safety_check_on);
1605217062}
1605317063
16054static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source_instr,
16055 IrInstruction *op1, IrInstruction *op2)
17064static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
17065 IrInstGen *op1, IrInstGen *op2)
1605617066{
1605717067 Error err;
1605817068 ZigType *op1_type = op1->value->type;
......@@ -16069,9 +17079,9 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
1606917079 new_type->data.structure.special = StructSpecialInferredTuple;
1607017080 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
1607117081
16072 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instr->scope);
17082 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope);
1607317083
16074 IrInstruction *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
17084 IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
1607517085 new_type, nullptr, false, false, true);
1607617086 uint32_t new_field_count = op1_field_count + op2_field_count;
1607717087
......@@ -16095,13 +17105,13 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
1609517105 new_field->is_comptime = src_field->is_comptime;
1609617106 }
1609717107 if ((err = type_resolve(ira->codegen, new_type, ResolveStatusZeroBitsKnown)))
16098 return ira->codegen->invalid_instruction;
17108 return ira->codegen->invalid_inst_gen;
1609917109
16100 ZigList<IrInstruction *> const_ptrs = {};
16101 IrInstruction *first_non_const_instruction = nullptr;
17110 ZigList<IrInstGen *> const_ptrs = {};
17111 IrInstGen *first_non_const_instruction = nullptr;
1610217112 for (uint32_t i = 0; i < new_field_count; i += 1) {
1610317113 TypeStructField *dst_field = new_type->data.structure.fields[i];
16104 IrInstruction *src_struct_op;
17114 IrInstGen *src_struct_op;
1610517115 TypeStructField *src_field;
1610617116 if (i < op1_field_count) {
1610717117 src_field = op1_type->data.structure.fields[i];
......@@ -16110,73 +17120,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
1611017120 src_field = op2_type->data.structure.fields[i - op1_field_count];
1611117121 src_struct_op = op2;
1611217122 }
16113 IrInstruction *field_value = ir_analyze_struct_value_field_value(ira, source_instr,
17123 IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr,
1611417124 src_struct_op, src_field);
1611517125 if (type_is_invalid(field_value->value->type))
16116 return ira->codegen->invalid_instruction;
16117 IrInstruction *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,
17126 return ira->codegen->invalid_inst_gen;
17127 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,
1611817128 new_struct_ptr, new_type, true);
1611917129 if (type_is_invalid(dest_ptr->value->type))
16120 return ira->codegen->invalid_instruction;
17130 return ira->codegen->invalid_inst_gen;
1612117131 if (instr_is_comptime(field_value)) {
1612217132 const_ptrs.append(dest_ptr);
1612317133 } else {
1612417134 first_non_const_instruction = field_value;
1612517135 }
16126 IrInstruction *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,
17136 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,
1612717137 true);
1612817138 if (type_is_invalid(store_ptr_inst->value->type))
16129 return ira->codegen->invalid_instruction;
17139 return ira->codegen->invalid_inst_gen;
1613017140 }
1613117141 if (const_ptrs.length != new_field_count) {
1613217142 new_struct_ptr->value->special = ConstValSpecialRuntime;
1613317143 for (size_t i = 0; i < const_ptrs.length; i += 1) {
16134 IrInstruction *elem_result_loc = const_ptrs.at(i);
17144 IrInstGen *elem_result_loc = const_ptrs.at(i);
1613517145 assert(elem_result_loc->value->special == ConstValSpecialStatic);
1613617146 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
1613717147 // This field will be generated comptime; no need to do this.
1613817148 continue;
1613917149 }
16140 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);
17150 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
1614117151 elem_result_loc->value->special = ConstValSpecialRuntime;
16142 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);
17152 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);
1614317153 }
1614417154 }
16145 IrInstruction *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);
17155 IrInstGen *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);
1614617156 if (instr_is_comptime(result))
1614717157 return result;
1614817158
1614917159 if (is_comptime) {
16150 ir_add_error_node(ira, first_non_const_instruction->source_node,
17160 ir_add_error(ira, &first_non_const_instruction->base,
1615117161 buf_sprintf("unable to evaluate constant expression"));
16152 return ira->codegen->invalid_instruction;
17162 return ira->codegen->invalid_inst_gen;
1615317163 }
1615417164
1615517165 return result;
1615617166}
1615717167
16158static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
16159 IrInstruction *op1 = instruction->op1->child;
17168static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
17169 IrInstGen *op1 = instruction->op1->child;
1616017170 ZigType *op1_type = op1->value->type;
1616117171 if (type_is_invalid(op1_type))
16162 return ira->codegen->invalid_instruction;
17172 return ira->codegen->invalid_inst_gen;
1616317173
16164 IrInstruction *op2 = instruction->op2->child;
17174 IrInstGen *op2 = instruction->op2->child;
1616517175 ZigType *op2_type = op2->value->type;
1616617176 if (type_is_invalid(op2_type))
16167 return ira->codegen->invalid_instruction;
17177 return ira->codegen->invalid_inst_gen;
1616817178
1616917179 if (is_tuple(op1_type) && is_tuple(op2_type)) {
16170 return ir_analyze_tuple_cat(ira, &instruction->base, op1, op2);
17180 return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2);
1617117181 }
1617217182
1617317183 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1617417184 if (!op1_val)
16175 return ira->codegen->invalid_instruction;
17185 return ira->codegen->invalid_inst_gen;
1617617186
1617717187 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1617817188 if (!op2_val)
16179 return ira->codegen->invalid_instruction;
17189 return ira->codegen->invalid_inst_gen;
1618017190
1618117191 ZigValue *sentinel1 = nullptr;
1618217192 ZigValue *op1_array_val;
......@@ -16214,15 +17224,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1621417224 {
1621517225 ZigType *array_type = op1_type->data.pointer.child_type;
1621617226 child_type = array_type->data.array.child_type;
16217 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node);
17227 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node);
1621817228 if (op1_array_val == nullptr)
16219 return ira->codegen->invalid_instruction;
17229 return ira->codegen->invalid_inst_gen;
1622017230 op1_array_index = 0;
1622117231 op1_array_end = array_type->data.array.len;
1622217232 sentinel1 = array_type->data.array.sentinel;
1622317233 } else {
16224 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
16225 return ira->codegen->invalid_instruction;
17234 ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
17235 return ira->codegen->invalid_inst_gen;
1622617236 }
1622717237
1622817238 ZigValue *sentinel2 = nullptr;
......@@ -16262,23 +17272,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1626217272 {
1626317273 ZigType *array_type = op2_type->data.pointer.child_type;
1626417274 op2_type_valid = array_type->data.array.child_type == child_type;
16265 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node);
17275 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node);
1626617276 if (op2_array_val == nullptr)
16267 return ira->codegen->invalid_instruction;
17277 return ira->codegen->invalid_inst_gen;
1626817278 op2_array_index = 0;
1626917279 op2_array_end = array_type->data.array.len;
1627017280
1627117281 sentinel2 = array_type->data.array.sentinel;
1627217282 } else {
16273 ir_add_error(ira, op2,
17283 ir_add_error(ira, &op2->base,
1627417284 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));
16275 return ira->codegen->invalid_instruction;
17285 return ira->codegen->invalid_inst_gen;
1627617286 }
1627717287 if (!op2_type_valid) {
16278 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
17288 ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'",
1627917289 buf_ptr(&child_type->name),
1628017290 buf_ptr(&op2->value->type->name)));
16281 return ira->codegen->invalid_instruction;
17291 return ira->codegen->invalid_inst_gen;
1628217292 }
1628317293
1628417294 ZigValue *sentinel;
......@@ -16295,7 +17305,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1629517305 }
1629617306
1629717307 // The type of result is populated in the following if blocks
16298 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
17308 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
1629917309 ZigValue *out_val = result->value;
1630017310
1630117311 ZigValue *out_array_val;
......@@ -16383,14 +17393,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1638317393 return result;
1638417394}
1638517395
16386static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
16387 IrInstruction *op1 = instruction->op1->child;
17396static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
17397 IrInstGen *op1 = instruction->op1->child;
1638817398 if (type_is_invalid(op1->value->type))
16389 return ira->codegen->invalid_instruction;
17399 return ira->codegen->invalid_inst_gen;
1639017400
16391 IrInstruction *op2 = instruction->op2->child;
17401 IrInstGen *op2 = instruction->op2->child;
1639217402 if (type_is_invalid(op2->value->type))
16393 return ira->codegen->invalid_instruction;
17403 return ira->codegen->invalid_inst_gen;
1639417404
1639517405 bool want_ptr_to_array = false;
1639617406 ZigType *array_type;
......@@ -16399,49 +17409,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1639917409 array_type = op1->value->type;
1640017410 array_val = ir_resolve_const(ira, op1, UndefOk);
1640117411 if (array_val == nullptr)
16402 return ira->codegen->invalid_instruction;
17412 return ira->codegen->invalid_inst_gen;
1640317413 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&
1640417414 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
1640517415 {
1640617416 array_type = op1->value->type->data.pointer.child_type;
16407 IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr);
17417 IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr);
1640817418 if (type_is_invalid(array_inst->value->type))
16409 return ira->codegen->invalid_instruction;
17419 return ira->codegen->invalid_inst_gen;
1641017420 array_val = ir_resolve_const(ira, array_inst, UndefOk);
1641117421 if (array_val == nullptr)
16412 return ira->codegen->invalid_instruction;
17422 return ira->codegen->invalid_inst_gen;
1641317423 want_ptr_to_array = true;
1641417424 } else {
16415 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
16416 return ira->codegen->invalid_instruction;
17425 ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
17426 return ira->codegen->invalid_inst_gen;
1641717427 }
1641817428
1641917429 uint64_t mult_amt;
1642017430 if (!ir_resolve_usize(ira, op2, &mult_amt))
16421 return ira->codegen->invalid_instruction;
17431 return ira->codegen->invalid_inst_gen;
1642217432
1642317433 uint64_t old_array_len = array_type->data.array.len;
1642417434 uint64_t new_array_len;
1642517435
1642617436 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {
16427 ir_add_error(ira, &instruction->base, buf_sprintf("operation results in overflow"));
16428 return ira->codegen->invalid_instruction;
17437 ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow"));
17438 return ira->codegen->invalid_inst_gen;
1642917439 }
1643017440
1643117441 ZigType *child_type = array_type->data.array.child_type;
1643217442 ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len,
1643317443 array_type->data.array.sentinel);
1643417444
16435 IrInstruction *array_result;
17445 IrInstGen *array_result;
1643617446 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {
16437 array_result = ir_const_undef(ira, &instruction->base, result_array_type);
17447 array_result = ir_const_undef(ira, &instruction->base.base, result_array_type);
1643817448 } else {
16439 array_result = ir_const(ira, &instruction->base, result_array_type);
17449 array_result = ir_const(ira, &instruction->base.base, result_array_type);
1644017450 ZigValue *out_val = array_result->value;
1644117451
1644217452 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
1644317453 case OnePossibleValueInvalid:
16444 return ira->codegen->invalid_instruction;
17454 return ira->codegen->invalid_inst_gen;
1644517455 case OnePossibleValueYes:
1644617456 goto skip_computation;
1644717457 case OnePossibleValueNo:
......@@ -16477,35 +17487,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1647717487 }
1647817488skip_computation:
1647917489 if (want_ptr_to_array) {
16480 return ir_get_ref(ira, &instruction->base, array_result, true, false);
17490 return ir_get_ref(ira, &instruction->base.base, array_result, true, false);
1648117491 } else {
1648217492 return array_result;
1648317493 }
1648417494}
1648517495
16486static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
16487 IrInstructionMergeErrSets *instruction)
17496static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
17497 IrInstSrcMergeErrSets *instruction)
1648817498{
16489 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op1->child);
17499 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child);
1649017500 if (type_is_invalid(op1_type))
16491 return ira->codegen->invalid_instruction;
17501 return ira->codegen->invalid_inst_gen;
1649217502
16493 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op2->child);
17503 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child);
1649417504 if (type_is_invalid(op2_type))
16495 return ira->codegen->invalid_instruction;
17505 return ira->codegen->invalid_inst_gen;
1649617506
1649717507 if (type_is_global_error_set(op1_type) ||
1649817508 type_is_global_error_set(op2_type))
1649917509 {
16500 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_global_error_set);
17510 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set);
1650117511 }
1650217512
16503 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) {
16504 return ira->codegen->invalid_instruction;
17513 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) {
17514 return ira->codegen->invalid_inst_gen;
1650517515 }
1650617516
16507 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) {
16508 return ira->codegen->invalid_instruction;
17517 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) {
17518 return ira->codegen->invalid_inst_gen;
1650917519 }
1651017520
1651117521 size_t errors_count = ira->codegen->errors_by_index.length;
......@@ -16518,11 +17528,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
1651817528 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
1651917529 deallocate(errors, errors_count, "ErrorTableEntry *");
1652017530
16521 return ir_const_type(ira, &instruction->base, result_type);
17531 return ir_const_type(ira, &instruction->base.base, result_type);
1652217532}
1652317533
1652417534
16525static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
17535static IrInstGen *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
1652617536 IrBinOp op_id = bin_op_instruction->op_id;
1652717537 switch (op_id) {
1652817538 case IrBinOpInvalid:
......@@ -16567,41 +17577,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio
1656717577 zig_unreachable();
1656817578}
1656917579
16570static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16571 IrInstructionDeclVarSrc *decl_var_instruction)
16572{
17580static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclVar *decl_var_instruction) {
1657317581 Error err;
1657417582 ZigVar *var = decl_var_instruction->var;
1657517583
1657617584 ZigType *explicit_type = nullptr;
16577 IrInstruction *var_type = nullptr;
17585 IrInstGen *var_type = nullptr;
1657817586 if (decl_var_instruction->var_type != nullptr) {
1657917587 var_type = decl_var_instruction->var_type->child;
1658017588 ZigType *proposed_type = ir_resolve_type(ira, var_type);
16581 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
17589 explicit_type = validate_var_type(ira->codegen, var_type->base.source_node, proposed_type);
1658217590 if (type_is_invalid(explicit_type)) {
1658317591 var->var_type = ira->codegen->builtin_types.entry_invalid;
16584 return ira->codegen->invalid_instruction;
17592 return ira->codegen->invalid_inst_gen;
1658517593 }
1658617594 }
1658717595
16588 AstNode *source_node = decl_var_instruction->base.source_node;
17596 AstNode *source_node = decl_var_instruction->base.base.source_node;
1658917597
1659017598 bool is_comptime_var = ir_get_var_is_comptime(var);
1659117599
1659217600 bool var_class_requires_const = false;
1659317601
16594 IrInstruction *var_ptr = decl_var_instruction->ptr->child;
17602 IrInstGen *var_ptr = decl_var_instruction->ptr->child;
1659517603 // if this is null, a compiler error happened and did not initialize the variable.
1659617604 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
1659717605 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {
16598 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base);
17606 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base);
1659917607 var->var_type = ira->codegen->builtin_types.entry_invalid;
16600 return ira->codegen->invalid_instruction;
17608 return ira->codegen->invalid_inst_gen;
1660117609 }
1660217610
1660317611 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.
16604 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base);
17612 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base);
1660517613
1660617614 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;
1660717615 if (type_is_invalid(result_type)) {
......@@ -16612,7 +17620,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1661217620
1661317621 ZigValue *init_val = nullptr;
1661417622 if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
16615 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node);
17623 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.base.source_node);
1661617624 if (is_comptime_var) {
1661717625 if (var->gen_is_const) {
1661817626 var->const_value = init_val;
......@@ -16639,7 +17647,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1663917647 case ReqCompTimeNo:
1664017648 if (init_val != nullptr && value_is_comptime(init_val)) {
1664117649 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
16642 decl_var_instruction->base.source_node, init_val, UndefOk)))
17650 decl_var_instruction->base.base.source_node, init_val, UndefOk)))
1664317651 {
1664417652 result_type = ira->codegen->builtin_types.entry_invalid;
1664517653 } else if (init_val->type->id == ZigTypeIdFn &&
......@@ -16687,13 +17695,13 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1668717695 assert(var->var_type);
1668817696
1668917697 if (type_is_invalid(result_type)) {
16690 return ir_const_void(ira, &decl_var_instruction->base);
17698 return ir_const_void(ira, &decl_var_instruction->base.base);
1669117699 }
1669217700
1669317701 if (decl_var_instruction->align_value == nullptr) {
1669417702 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {
1669517703 var->var_type = ira->codegen->builtin_types.entry_invalid;
16696 return ir_const_void(ira, &decl_var_instruction->base);
17704 return ir_const_void(ira, &decl_var_instruction->base.base);
1669717705 }
1669817706 var->align_bytes = get_abi_alignment(ira->codegen, result_type);
1669917707 } else {
......@@ -16712,17 +17720,17 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1671217720 // we need a runtime ptr but we have a comptime val.
1671317721 // since it's a comptime val there are no instructions for it.
1671417722 // we memcpy the init value here
16715 IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr);
17723 IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr);
1671617724 if (type_is_invalid(deref->value->type)) {
1671717725 var->var_type = ira->codegen->builtin_types.entry_invalid;
16718 return ira->codegen->invalid_instruction;
17726 return ira->codegen->invalid_inst_gen;
1671917727 }
1672017728 // If this assertion trips, something is wrong with the IR instructions, because
1672117729 // we expected the above deref to return a constant value, but it created a runtime
1672217730 // instruction.
1672317731 assert(deref->value->special != ConstValSpecialRuntime);
1672417732 var_ptr->value->special = ConstValSpecialRuntime;
16725 ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false);
17733 ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false);
1672617734 }
1672717735
1672817736 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
......@@ -16732,84 +17740,84 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1673217740 ira_ref(var->owner_exec->analysis);
1673317741
1673417742 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
16735 return ir_const_void(ira, &decl_var_instruction->base);
17743 return ir_const_void(ira, &decl_var_instruction->base.base);
1673617744 }
1673717745 }
1673817746 } else if (is_comptime_var) {
16739 ir_add_error(ira, &decl_var_instruction->base,
17747 ir_add_error(ira, &decl_var_instruction->base.base,
1674017748 buf_sprintf("cannot store runtime value in compile time variable"));
1674117749 var->var_type = ira->codegen->builtin_types.entry_invalid;
16742 return ira->codegen->invalid_instruction;
17750 return ira->codegen->invalid_inst_gen;
1674317751 }
1674417752
16745 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
17753 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1674617754 if (fn_entry)
1674717755 fn_entry->variable_list.append(var);
1674817756
16749 return ir_build_var_decl_gen(ira, &decl_var_instruction->base, var, var_ptr);
17757 return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr);
1675017758}
1675117759
16752static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
16753 IrInstruction *target = instruction->target->child;
17760static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) {
17761 IrInstGen *target = instruction->target->child;
1675417762 if (type_is_invalid(target->value->type))
16755 return ira->codegen->invalid_instruction;
17763 return ira->codegen->invalid_inst_gen;
1675617764
16757 IrInstruction *options = instruction->options->child;
17765 IrInstGen *options = instruction->options->child;
1675817766 if (type_is_invalid(options->value->type))
16759 return ira->codegen->invalid_instruction;
17767 return ira->codegen->invalid_inst_gen;
1676017768
1676117769 ZigType *options_type = options->value->type;
1676217770 assert(options_type->id == ZigTypeIdStruct);
1676317771
1676417772 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
16765 ir_assert(name_field != nullptr, &instruction->base);
16766 IrInstruction *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, name_field);
17773 ir_assert(name_field != nullptr, &instruction->base.base);
17774 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);
1676717775 if (type_is_invalid(name_inst->value->type))
16768 return ira->codegen->invalid_instruction;
17776 return ira->codegen->invalid_inst_gen;
1676917777
1677017778 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
16771 ir_assert(linkage_field != nullptr, &instruction->base);
16772 IrInstruction *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, linkage_field);
17779 ir_assert(linkage_field != nullptr, &instruction->base.base);
17780 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);
1677317781 if (type_is_invalid(linkage_inst->value->type))
16774 return ira->codegen->invalid_instruction;
17782 return ira->codegen->invalid_inst_gen;
1677517783
1677617784 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));
16777 ir_assert(section_field != nullptr, &instruction->base);
16778 IrInstruction *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, section_field);
17785 ir_assert(section_field != nullptr, &instruction->base.base);
17786 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field);
1677917787 if (type_is_invalid(section_inst->value->type))
16780 return ira->codegen->invalid_instruction;
17788 return ira->codegen->invalid_inst_gen;
1678117789
1678217790 // The `section` field is optional, we have to unwrap it first
16783 IrInstruction *non_null_check = ir_analyze_test_non_null(ira, &instruction->base, section_inst);
17791 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst);
1678417792 bool is_non_null;
1678517793 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
16786 return ira->codegen->invalid_instruction;
17794 return ira->codegen->invalid_inst_gen;
1678717795
16788 IrInstruction *section_str_inst = nullptr;
17796 IrInstGen *section_str_inst = nullptr;
1678917797 if (is_non_null) {
16790 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base, section_inst, false);
17798 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false);
1679117799 if (type_is_invalid(section_str_inst->value->type))
16792 return ira->codegen->invalid_instruction;
17800 return ira->codegen->invalid_inst_gen;
1679317801 }
1679417802
1679517803 // Resolve all the comptime values
1679617804 Buf *symbol_name = ir_resolve_str(ira, name_inst);
1679717805 if (!symbol_name)
16798 return ira->codegen->invalid_instruction;
17806 return ira->codegen->invalid_inst_gen;
1679917807
1680017808 if (buf_len(symbol_name) < 1) {
16801 ir_add_error(ira, name_inst,
17809 ir_add_error(ira, &name_inst->base,
1680217810 buf_sprintf("exported symbol name cannot be empty"));
16803 return ira->codegen->invalid_instruction;
17811 return ira->codegen->invalid_inst_gen;
1680417812 }
1680517813
1680617814 GlobalLinkageId global_linkage_id;
1680717815 if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id))
16808 return ira->codegen->invalid_instruction;
17816 return ira->codegen->invalid_inst_gen;
1680917817
1681017818 Buf *section_name = nullptr;
1681117819 if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst)))
16812 return ira->codegen->invalid_instruction;
17820 return ira->codegen->invalid_inst_gen;
1681317821
1681417822 // TODO: This function needs to be audited.
1681517823 // It's not clear how all the different types are supposed to be handled.
......@@ -16817,15 +17825,15 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1681717825 // in another file.
1681817826 TldFn *tld_fn = allocate<TldFn>(1);
1681917827 tld_fn->base.id = TldIdFn;
16820 tld_fn->base.source_node = instruction->base.source_node;
17828 tld_fn->base.source_node = instruction->base.base.source_node;
1682117829
1682217830 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);
1682317831 if (entry) {
1682417832 AstNode *other_export_node = entry->value->source_node;
16825 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
17833 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
1682617834 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));
1682717835 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here"));
16828 return ira->codegen->invalid_instruction;
17836 return ira->codegen->invalid_inst_gen;
1682917837 }
1683017838
1683117839 Error err;
......@@ -16841,12 +17849,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1684117849 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
1684217850 switch (cc) {
1684317851 case CallingConventionUnspecified: {
16844 ErrorMsg *msg = ir_add_error(ira, target,
17852 ErrorMsg *msg = ir_add_error(ira, &target->base,
1684517853 buf_sprintf("exported function must specify calling convention"));
1684617854 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
1684717855 } break;
1684817856 case CallingConventionAsync: {
16849 ErrorMsg *msg = ir_add_error(ira, target,
17857 ErrorMsg *msg = ir_add_error(ira, &target->base,
1685017858 buf_sprintf("exported function cannot be async"));
1685117859 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
1685217860 } break;
......@@ -16869,10 +17877,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1686917877 } break;
1687017878 case ZigTypeIdStruct:
1687117879 if (is_slice(target->value->type)) {
16872 ir_add_error(ira, target,
17880 ir_add_error(ira, &target->base,
1687317881 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
1687417882 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {
16875 ErrorMsg *msg = ir_add_error(ira, target,
17883 ErrorMsg *msg = ir_add_error(ira, &target->base,
1687617884 buf_sprintf("exported struct value must be declared extern"));
1687717885 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));
1687817886 } else {
......@@ -16881,7 +17889,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1688117889 break;
1688217890 case ZigTypeIdUnion:
1688317891 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {
16884 ErrorMsg *msg = ir_add_error(ira, target,
17892 ErrorMsg *msg = ir_add_error(ira, &target->base,
1688517893 buf_sprintf("exported union value must be declared extern"));
1688617894 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));
1688717895 } else {
......@@ -16890,7 +17898,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1689017898 break;
1689117899 case ZigTypeIdEnum:
1689217900 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {
16893 ErrorMsg *msg = ir_add_error(ira, target,
17901 ErrorMsg *msg = ir_add_error(ira, &target->base,
1689417902 buf_sprintf("exported enum value must be declared extern"));
1689517903 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));
1689617904 } else {
......@@ -16900,10 +17908,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1690017908 case ZigTypeIdArray: {
1690117909 bool ok_type;
1690217910 if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type)))
16903 return ira->codegen->invalid_instruction;
17911 return ira->codegen->invalid_inst_gen;
1690417912
1690517913 if (!ok_type) {
16906 ir_add_error(ira, target,
17914 ir_add_error(ira, &target->base,
1690717915 buf_sprintf("array element type '%s' not extern-compatible",
1690817916 buf_ptr(&target->value->type->data.array.child_type->name)));
1690917917 } else {
......@@ -16918,31 +17926,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1691817926 zig_unreachable();
1691917927 case ZigTypeIdStruct:
1692017928 if (is_slice(type_value)) {
16921 ir_add_error(ira, target,
17929 ir_add_error(ira, &target->base,
1692217930 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
1692317931 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {
16924 ErrorMsg *msg = ir_add_error(ira, target,
17932 ErrorMsg *msg = ir_add_error(ira, &target->base,
1692517933 buf_sprintf("exported struct must be declared extern"));
1692617934 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
1692717935 }
1692817936 break;
1692917937 case ZigTypeIdUnion:
1693017938 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
16931 ErrorMsg *msg = ir_add_error(ira, target,
17939 ErrorMsg *msg = ir_add_error(ira, &target->base,
1693217940 buf_sprintf("exported union must be declared extern"));
1693317941 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
1693417942 }
1693517943 break;
1693617944 case ZigTypeIdEnum:
1693717945 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
16938 ErrorMsg *msg = ir_add_error(ira, target,
17946 ErrorMsg *msg = ir_add_error(ira, &target->base,
1693917947 buf_sprintf("exported enum must be declared extern"));
1694017948 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
1694117949 }
1694217950 break;
1694317951 case ZigTypeIdFn: {
1694417952 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
16945 ir_add_error(ira, target,
17953 ir_add_error(ira, &target->base,
1694617954 buf_sprintf("exported function type must specify calling convention"));
1694717955 }
1694817956 } break;
......@@ -16968,7 +17976,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1696817976 case ZigTypeIdOpaque:
1696917977 case ZigTypeIdFnFrame:
1697017978 case ZigTypeIdAnyFrame:
16971 ir_add_error(ira, target,
17979 ir_add_error(ira, &target->base,
1697217980 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
1697317981 break;
1697417982 }
......@@ -16993,61 +18001,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1699318001 case ZigTypeIdEnumLiteral:
1699418002 case ZigTypeIdFnFrame:
1699518003 case ZigTypeIdAnyFrame:
16996 ir_add_error(ira, target,
18004 ir_add_error(ira, &target->base,
1699718005 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));
1699818006 break;
1699918007 }
1700018008
1700118009 // TODO audit the various ways to use @export
17002 if (want_var_export && target->id == IrInstructionIdLoadPtrGen) {
17003 IrInstructionLoadPtrGen *load_ptr = reinterpret_cast<IrInstructionLoadPtrGen *>(target);
17004 if (load_ptr->ptr->id == IrInstructionIdVarPtr) {
17005 IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr);
18010 if (want_var_export && target->id == IrInstGenIdLoadPtr) {
18011 IrInstGenLoadPtr *load_ptr = reinterpret_cast<IrInstGenLoadPtr *>(target);
18012 if (load_ptr->ptr->id == IrInstGenIdVarPtr) {
18013 IrInstGenVarPtr *var_ptr = reinterpret_cast<IrInstGenVarPtr *>(load_ptr->ptr);
1700618014 ZigVar *var = var_ptr->var;
1700718015 add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);
1700818016 var->section_name = section_name;
1700918017 }
1701018018 }
1701118019
17012 return ir_const_void(ira, &instruction->base);
18020 return ir_const_void(ira, &instruction->base.base);
1701318021}
1701418022
17015static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {
18023static bool exec_has_err_ret_trace(CodeGen *g, IrExecutableSrc *exec) {
1701618024 ZigFn *fn_entry = exec_fn_entry(exec);
1701718025 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;
1701818026}
1701918027
17020static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
17021 IrInstructionErrorReturnTrace *instruction)
18028static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
18029 IrInstSrcErrorReturnTrace *instruction)
1702218030{
1702318031 ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false);
17024 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {
18032 if (instruction->optional == IrInstErrorReturnTraceNull) {
1702518033 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
17026 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
17027 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);
18034 if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) {
18035 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);
1702818036 ZigValue *out_val = result->value;
1702918037 assert(get_codegen_ptr_type(optional_type) != nullptr);
1703018038 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1703118039 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
1703218040 return result;
1703318041 }
17034 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
17035 instruction->base.source_node, instruction->optional);
17036 new_instruction->value->type = optional_type;
17037 return new_instruction;
18042 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
18043 instruction->base.base.source_node, instruction->optional, optional_type);
1703818044 } else {
1703918045 assert(ira->codegen->have_err_ret_tracing);
17040 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
17041 instruction->base.source_node, instruction->optional);
17042 new_instruction->value->type = ptr_to_stack_trace_type;
17043 return new_instruction;
18046 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
18047 instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type);
1704418048 }
1704518049}
1704618050
17047static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
17048 IrInstructionErrorUnion *instruction)
17049{
17050 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
18051static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) {
18052 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
1705118053 result->value->special = ConstValSpecialLazy;
1705218054
1705318055 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");
......@@ -17057,16 +18059,16 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
1705718059
1705818060 lazy_err_union_type->err_set_type = instruction->err_set->child;
1705918061 if (ir_resolve_type_lazy(ira, lazy_err_union_type->err_set_type) == nullptr)
17060 return ira->codegen->invalid_instruction;
18062 return ira->codegen->invalid_inst_gen;
1706118063
1706218064 lazy_err_union_type->payload_type = instruction->payload->child;
1706318065 if (ir_resolve_type_lazy(ira, lazy_err_union_type->payload_type) == nullptr)
17064 return ira->codegen->invalid_instruction;
18066 return ira->codegen->invalid_inst_gen;
1706518067
1706618068 return result;
1706718069}
1706818070
17069static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type,
18071static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type,
1707018072 uint32_t align, const char *name_hint, bool force_comptime)
1707118073{
1707218074 Error err;
......@@ -17074,7 +18076,7 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1707418076 ZigValue *pointee = create_const_vals(1);
1707518077 pointee->special = ConstValSpecialUndef;
1707618078
17077 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
18079 IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
1707818080 result->base.value->special = ConstValSpecialStatic;
1707918081 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
1708018082 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
......@@ -17082,15 +18084,15 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1708218084
1708318085 bool var_type_has_bits;
1708418086 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))
17085 return ira->codegen->invalid_instruction;
18087 return ira->codegen->invalid_inst_gen;
1708618088 if (align != 0) {
1708718089 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
17088 return ira->codegen->invalid_instruction;
18090 return ira->codegen->invalid_inst_gen;
1708918091 if (!var_type_has_bits) {
1709018092 ir_add_error(ira, source_inst,
1709118093 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
1709218094 name_hint, buf_ptr(&var_type->name)));
17093 return ira->codegen->invalid_instruction;
18095 return ira->codegen->invalid_inst_gen;
1709418096 }
1709518097 }
1709618098 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);
......@@ -17099,15 +18101,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1709918101 result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,
1710018102 PtrLenSingle, align, 0, 0, false);
1710118103
17102 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
18104 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1710318105 if (fn_entry != nullptr) {
1710418106 fn_entry->alloca_gen_list.append(result);
1710518107 }
17106 result->base.is_gen = true;
1710718108 return &result->base;
1710818109}
1710918110
17110static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspend_source_instr,
18111static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr,
1711118112 ResultLoc *result_loc)
1711218113{
1711318114 switch (result_loc->id) {
......@@ -17150,7 +18151,7 @@ static bool type_can_bit_cast(ZigType *t) {
1715018151 }
1715118152}
1715218153
17153static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
18154static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) {
1715418155 ZigValue *undef_child = create_const_vals(1);
1715518156 undef_child->type = ptr->value->type->data.pointer.child_type;
1715618157 undef_child->special = ConstValSpecialUndef;
......@@ -17189,16 +18190,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out
1718918190 zig_unreachable();
1719018191}
1719118192
17192static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr,
18193static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr,
1719318194 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
1719418195{
1719518196 if (type_is_invalid(value_type))
17196 return ira->codegen->invalid_instruction;
17197 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
18197 return ira->codegen->invalid_inst_gen;
18198 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
1719818199 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
1719918200 PtrLenSingle, 0, 0, 0, false);
1720018201 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
17201 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
18202 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1720218203 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
1720318204 fn_entry->alloca_gen_list.append(alloca_gen);
1720418205 }
......@@ -17208,8 +18209,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
1720818209}
1720918210
1721018211// when calling this function, at the callsite must check for result type noreturn and propagate it up
17211static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
17212 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
18212static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
18213 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
1721318214 bool non_null_comptime, bool allow_discard)
1721418215{
1721518216 Error err;
......@@ -17235,35 +18236,34 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1723518236 }
1723618237 case ResultLocIdVar: {
1723718238 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
17238 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);
18239 assert(result_loc->source_instruction->id == IrInstSrcIdAlloca);
1723918240
1724018241 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {
17241 ir_add_error(ira, result_loc->source_instruction,
18242 ir_add_error(ira, &result_loc->source_instruction->base,
1724218243 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));
17243 return ira->codegen->invalid_instruction;
18244 return ira->codegen->invalid_inst_gen;
1724418245 }
1724518246
17246 IrInstructionAllocaSrc *alloca_src =
17247 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
18247 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
1724818248 bool force_comptime;
1724918249 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
17250 return ira->codegen->invalid_instruction;
18250 return ira->codegen->invalid_inst_gen;
1725118251 bool is_comptime = force_comptime || (!force_runtime && value != nullptr &&
1725218252 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
1725318253
1725418254 if (alloca_src->base.child == nullptr || is_comptime) {
1725518255 uint32_t align = 0;
1725618256 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {
17257 return ira->codegen->invalid_instruction;
18257 return ira->codegen->invalid_inst_gen;
1725818258 }
17259 IrInstruction *alloca_gen;
18259 IrInstGen *alloca_gen;
1726018260 if (is_comptime && value != nullptr) {
1726118261 if (align > value->value->llvm_align) {
1726218262 value->value->llvm_align = align;
1726318263 }
17264 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
18264 alloca_gen = ir_get_ref(ira, &result_loc->source_instruction->base, value, true, false);
1726518265 } else {
17266 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
18266 alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type, align,
1726718267 alloca_src->name_hint, force_comptime);
1726818268 if (force_runtime) {
1726918269 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
......@@ -17271,7 +18271,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1727118271 }
1727218272 }
1727318273 if (alloca_src->base.child != nullptr && !result_loc->written) {
17274 alloca_src->base.child->ref_count = 0;
18274 alloca_src->base.child->base.ref_count = 0;
1727518275 }
1727618276 alloca_src->base.child = alloca_gen;
1727718277 }
......@@ -17296,9 +18296,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1729618296 }
1729718297 bool has_bits;
1729818298 if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits)))
17299 return ira->codegen->invalid_instruction;
18299 return ira->codegen->invalid_inst_gen;
1730018300 if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) {
17301 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
18301 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1730218302 if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) {
1730318303 return nullptr;
1730418304 }
......@@ -17306,8 +18306,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1730618306
1730718307 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);
1730818308 result_loc->written = true;
17309 result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);
17310 if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->scope)) {
18309 result_loc->resolved_loc = ir_build_return_ptr(ira, &result_loc->source_instruction->base, ptr_return_type);
18310 if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->base.scope)) {
1731118311 set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc);
1731218312 }
1731318313 return result_loc->resolved_loc;
......@@ -17317,7 +18317,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1731718317 ResultLocPeerParent *peer_parent = result_peer->parent;
1731818318
1731918319 if (peer_parent->peers.length == 1) {
17320 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
18320 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1732118321 value_type, value, force_runtime, non_null_comptime, true);
1732218322 result_peer->suspend_pos.basic_block_index = SIZE_MAX;
1732318323 result_peer->suspend_pos.instruction_index = SIZE_MAX;
......@@ -17333,7 +18333,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1733318333
1733418334 bool is_condition_comptime;
1733518335 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime))
17336 return ira->codegen->invalid_instruction;
18336 return ira->codegen->invalid_inst_gen;
1733718337 if (is_condition_comptime) {
1733818338 peer_parent->skipped = true;
1733918339 if (non_null_comptime) {
......@@ -17344,10 +18344,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1734418344 }
1734518345 bool peer_parent_has_type;
1734618346 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
17347 return ira->codegen->invalid_instruction;
18347 return ira->codegen->invalid_inst_gen;
1734818348 if (peer_parent_has_type) {
1734918349 peer_parent->skipped = true;
17350 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
18350 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1735118351 value_type, value, force_runtime || !is_condition_comptime, true, true);
1735218352 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1735318353 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17364,7 +18364,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1736418364 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {
1736518365 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;
1736618366 }
17367 IrInstruction *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb,
18367 IrInstGen *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb,
1736818368 &result_peer->suspend_pos);
1736918369 if (result_peer->next_bb == nullptr) {
1737018370 ir_start_next_bb(ira);
......@@ -17372,7 +18372,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1737218372 return unreach_inst;
1737318373 }
1737418374
17375 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
18375 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1737618376 peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true);
1737718377 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1737818378 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17391,24 +18391,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1739118391 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
1739218392 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
1739318393 if (type_is_invalid(dest_type))
17394 return ira->codegen->invalid_instruction;
18394 return ira->codegen->invalid_inst_gen;
1739518395
1739618396 if (dest_type == ira->codegen->builtin_types.entry_var) {
1739718397 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
1739818398 force_runtime, non_null_comptime);
1739918399 }
1740018400
17401 IrInstruction *casted_value;
18401 IrInstGen *casted_value;
1740218402 if (value != nullptr) {
1740318403 casted_value = ir_implicit_cast(ira, value, dest_type);
1740418404 if (type_is_invalid(casted_value->value->type))
17405 return ira->codegen->invalid_instruction;
18405 return ira->codegen->invalid_inst_gen;
1740618406 dest_type = casted_value->value->type;
1740718407 } else {
1740818408 casted_value = nullptr;
1740918409 }
1741018410
17411 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
18411 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
1741218412 dest_type, casted_value, force_runtime, non_null_comptime, true);
1741318413 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1741418414 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17422,11 +18422,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1742218422 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
1742318423 ResolveStatusAlignmentKnown)))
1742418424 {
17425 return ira->codegen->invalid_instruction;
18425 return ira->codegen->invalid_inst_gen;
1742618426 }
1742718427 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
1742818428 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
17429 return ira->codegen->invalid_instruction;
18429 return ira->codegen->invalid_inst_gen;
1743018430 }
1743118431 if (!type_has_bits(value_type)) {
1743218432 parent_ptr_align = 0;
......@@ -17449,9 +18449,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1744918449
1745018450 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
1745118451 parent_result_loc->value->type, ptr_type,
17452 result_cast->base.source_instruction->source_node, false);
18452 result_cast->base.source_instruction->base.source_node, false);
1745318453 if (const_cast_result.id == ConstCastResultIdInvalid)
17454 return ira->codegen->invalid_instruction;
18454 return ira->codegen->invalid_inst_gen;
1745518455 if (const_cast_result.id != ConstCastResultIdOk) {
1745618456 if (allow_discard) {
1745718457 return parent_result_loc;
......@@ -17465,42 +18465,42 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1746518465
1746618466 result_loc->written = true;
1746718467 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
17468 ptr_type, result_cast->base.source_instruction, false);
18468 ptr_type, &result_cast->base.source_instruction->base, false);
1746918469 return result_loc->resolved_loc;
1747018470 }
1747118471 case ResultLocIdBitCast: {
1747218472 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
1747318473 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);
1747418474 if (type_is_invalid(dest_type))
17475 return ira->codegen->invalid_instruction;
18475 return ira->codegen->invalid_inst_gen;
1747618476
1747718477 if (get_codegen_ptr_type(dest_type) != nullptr) {
17478 ir_add_error(ira, result_loc->source_instruction,
18478 ir_add_error(ira, &result_loc->source_instruction->base,
1747918479 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
17480 return ira->codegen->invalid_instruction;
18480 return ira->codegen->invalid_inst_gen;
1748118481 }
1748218482
1748318483 if (!type_can_bit_cast(dest_type)) {
17484 ir_add_error(ira, result_loc->source_instruction,
18484 ir_add_error(ira, &result_loc->source_instruction->base,
1748518485 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
17486 return ira->codegen->invalid_instruction;
18486 return ira->codegen->invalid_inst_gen;
1748718487 }
1748818488
1748918489 if (get_codegen_ptr_type(value_type) != nullptr) {
1749018490 ir_add_error(ira, suspend_source_instr,
1749118491 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
17492 return ira->codegen->invalid_instruction;
18492 return ira->codegen->invalid_inst_gen;
1749318493 }
1749418494
1749518495 if (!type_can_bit_cast(value_type)) {
1749618496 ir_add_error(ira, suspend_source_instr,
1749718497 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));
17498 return ira->codegen->invalid_instruction;
18498 return ira->codegen->invalid_inst_gen;
1749918499 }
1750018500
17501 IrInstruction *bitcasted_value;
18501 IrInstGen *bitcasted_value;
1750218502 if (value != nullptr) {
17503 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type);
18503 bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type);
1750418504 dest_type = bitcasted_value->value->type;
1750518505 } else {
1750618506 bitcasted_value = nullptr;
......@@ -17510,7 +18510,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1751018510 return bitcasted_value;
1751118511 }
1751218512
17513 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
18513 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
1751418514 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);
1751518515 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1751618516 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17523,7 +18523,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1752318523
1752418524 bool has_bits;
1752518525 if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) {
17526 return ira->codegen->invalid_instruction;
18526 return ira->codegen->invalid_inst_gen;
1752718527 }
1752818528
1752918529 // This happens when the bitCast result is assigned to _
......@@ -17533,12 +18533,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1753318533 }
1753418534
1753518535 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) {
17536 return ira->codegen->invalid_instruction;
18536 return ira->codegen->invalid_inst_gen;
1753718537 }
1753818538
1753918539 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
1754018540 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
17541 return ira->codegen->invalid_instruction;
18541 return ira->codegen->invalid_inst_gen;
1754218542 }
1754318543 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
1754418544 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
......@@ -17546,29 +18546,33 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1754618546
1754718547 result_loc->written = true;
1754818548 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
17549 ptr_type, result_bit_cast->base.source_instruction, false);
18549 ptr_type, &result_bit_cast->base.source_instruction->base, false);
1755018550 return result_loc->resolved_loc;
1755118551 }
1755218552 }
1755318553 zig_unreachable();
1755418554}
1755518555
17556static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
17557 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime,
18556static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
18557 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime,
1755818558 bool non_null_comptime, bool allow_discard)
1755918559{
1756018560 Error err;
1756118561 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&
17562 instr_is_comptime(result_loc_pass1->source_instruction) &&
17563 result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer &&
17564 result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard)
18562 result_loc_pass1->source_instruction->id == IrInstSrcIdConst)
1756518563 {
17566 result_loc_pass1 = no_result_loc();
18564 IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(result_loc_pass1->source_instruction);
18565 if (value_is_comptime(const_inst->value) &&
18566 const_inst->value->type->id == ZigTypeIdPointer &&
18567 const_inst->value->data.x_ptr.special == ConstPtrSpecialDiscard)
18568 {
18569 result_loc_pass1 = no_result_loc();
18570 }
1756718571 }
1756818572 bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr;
17569 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
18573 IrInstGen *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
1757018574 value, force_runtime, non_null_comptime, allow_discard);
17571 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
18575 if (result_loc == nullptr || (result_loc->value->type->id == ZigTypeIdUnreachable || type_is_invalid(result_loc->value->type)))
1757218576 return result_loc;
1757318577
1757418578 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&
......@@ -17591,11 +18595,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1759118595 field->type_entry = value_type;
1759218596 field->type_val = create_const_type(ira->codegen, field->type_entry);
1759318597 field->src_index = old_field_count;
17594 field->decl_node = value ? value->source_node : suspend_source_instr->source_node;
18598 field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node;
1759518599 if (value && instr_is_comptime(value)) {
1759618600 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
1759718601 if (!val)
17598 return ira->codegen->invalid_instruction;
18602 return ira->codegen->invalid_inst_gen;
1759918603 field->is_comptime = true;
1760018604 field->init_val = create_const_vals(1);
1760118605 copy_const_val(field->init_val, val);
......@@ -17603,7 +18607,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1760318607 }
1760418608
1760518609 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
17606 IrInstruction *casted_ptr;
18610 IrInstGen *casted_ptr;
1760718611 if (instr_is_comptime(result_loc)) {
1760818612 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
1760918613 copy_const_val(casted_ptr->value, result_loc->value);
......@@ -17614,7 +18618,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1761418618 if (instr_is_comptime(casted_ptr)) {
1761518619 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
1761618620 if (!ptr_val)
17617 return ira->codegen->invalid_instruction;
18621 return ira->codegen->invalid_inst_gen;
1761818622 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1761918623 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
1762018624 suspend_source_instr->source_node);
......@@ -17644,7 +18648,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1764418648 {
1764518649 bool has_bits;
1764618650 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
17647 return ira->codegen->invalid_instruction;
18651 return ira->codegen->invalid_inst_gen;
1764818652 if (has_bits) {
1764918653 result_loc_pass1->written = false;
1765018654 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
......@@ -17652,12 +18656,12 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1765218656 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {
1765318657 bool has_bits;
1765418658 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
17655 return ira->codegen->invalid_instruction;
18659 return ira->codegen->invalid_inst_gen;
1765618660 if (has_bits) {
1765718661 if (value_type->id == ZigTypeIdErrorSet) {
1765818662 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
1765918663 } else {
17660 IrInstruction *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,
18664 IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,
1766118665 result_loc, false, true);
1766218666 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
1766318667 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
......@@ -17672,37 +18676,35 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1767218676 return result_loc;
1767318677}
1767418678
17675static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
17676 IrInstructionResolveResult *instruction)
17677{
18679static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSrcResolveResult *instruction) {
1767818680 ZigType *implicit_elem_type;
1767918681 if (instruction->ty == nullptr) {
1768018682 if (instruction->result_loc->id == ResultLocIdCast) {
1768118683 implicit_elem_type = ir_resolve_type(ira,
1768218684 instruction->result_loc->source_instruction->child);
1768318685 if (type_is_invalid(implicit_elem_type))
17684 return ira->codegen->invalid_instruction;
18686 return ira->codegen->invalid_inst_gen;
1768518687 } else if (instruction->result_loc->id == ResultLocIdReturn) {
1768618688 implicit_elem_type = ira->explicit_return_type;
1768718689 if (type_is_invalid(implicit_elem_type))
17688 return ira->codegen->invalid_instruction;
18690 return ira->codegen->invalid_inst_gen;
1768918691 } else {
1769018692 implicit_elem_type = ira->codegen->builtin_types.entry_var;
1769118693 }
1769218694 if (implicit_elem_type == ira->codegen->builtin_types.entry_var) {
1769318695 Buf *bare_name = buf_alloc();
1769418696 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
17695 instruction->base.scope, instruction->base.source_node, bare_name);
18697 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
1769618698
1769718699 StructSpecial struct_special = StructSpecialInferredStruct;
17698 if (instruction->base.source_node->type == NodeTypeContainerInitExpr &&
17699 instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
18700 if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr &&
18701 instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
1770018702 {
1770118703 struct_special = StructSpecialInferredTuple;
1770218704 }
1770318705
1770418706 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,
17705 instruction->base.scope, ContainerKindStruct, instruction->base.source_node,
18707 instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node,
1770618708 buf_ptr(name), bare_name, ContainerLayoutAuto);
1770718709 inferred_struct_type->data.structure.special = struct_special;
1770818710 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
......@@ -17711,21 +18713,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
1771118713 } else {
1771218714 implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
1771318715 if (type_is_invalid(implicit_elem_type))
17714 return ira->codegen->invalid_instruction;
18716 return ira->codegen->invalid_inst_gen;
1771518717 }
17716 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
18718 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
1771718719 implicit_elem_type, nullptr, false, true, true);
1771818720 if (result_loc != nullptr)
1771918721 return result_loc;
1772018722
17721 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);
18723 ZigFn *fn = ira->new_irb.exec->fn_entry;
1772218724 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&
1772318725 instruction->result_loc->id == ResultLocIdReturn)
1772418726 {
17725 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),
18727 result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(),
1772618728 implicit_elem_type, nullptr, false, true, true);
1772718729 if (result_loc != nullptr &&
17728 (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
18730 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
1772918731 {
1773018732 return result_loc;
1773118733 }
......@@ -17733,9 +18735,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
1773318735 return result_loc;
1773418736 }
1773518737
17736 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);
18738 IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type);
1773718739 result->value->special = ConstValSpecialUndef;
17738 IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false);
18740 IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false);
1773918741 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
1774018742 return ptr;
1774118743}
......@@ -17759,8 +18761,7 @@ static void ir_reset_result(ResultLoc *result_loc) {
1775918761 break;
1776018762 }
1776118763 case ResultLocIdVar: {
17762 IrInstructionAllocaSrc *alloca_src =
17763 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
18764 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
1776418765 alloca_src->base.child = nullptr;
1776518766 break;
1776618767 }
......@@ -17776,18 +18777,18 @@ static void ir_reset_result(ResultLoc *result_loc) {
1777618777 }
1777718778}
1777818779
17779static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstructionResetResult *instruction) {
18780static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) {
1778018781 ir_reset_result(instruction->result_loc);
17781 return ir_const_void(ira, &instruction->base);
18782 return ir_const_void(ira, &instruction->base.base);
1778218783}
1778318784
17784static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *source_instr,
17785 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstruction **args_ptr, size_t args_len,
17786 IrInstruction *ret_ptr_uncasted)
18785static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr,
18786 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len,
18787 IrInstGen *ret_ptr_uncasted)
1778718788{
1778818789 ir_assert(is_async_call_builtin, source_instr);
1778918790 if (type_is_invalid(ret_ptr_uncasted->value->type))
17790 return ira->codegen->invalid_instruction;
18791 return ira->codegen->invalid_inst_gen;
1779118792 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
1779218793 // Result location will be inside the async frame.
1779318794 return nullptr;
......@@ -17795,57 +18796,57 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s
1779518796 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));
1779618797}
1779718798
17798static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstruction *source_instr, ZigFn *fn_entry,
17799 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,
17800 IrInstruction *casted_new_stack, bool is_async_call_builtin, IrInstruction *ret_ptr_uncasted,
18799static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry,
18800 ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count,
18801 IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted,
1780118802 ResultLoc *call_result_loc)
1780218803{
1780318804 if (fn_entry == nullptr) {
1780418805 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {
17805 ir_add_error(ira, fn_ref,
18806 ir_add_error(ira, &fn_ref->base,
1780618807 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));
17807 return ira->codegen->invalid_instruction;
18808 return ira->codegen->invalid_inst_gen;
1780818809 }
1780918810 if (casted_new_stack == nullptr) {
17810 ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required"));
17811 return ira->codegen->invalid_instruction;
18811 ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required"));
18812 return ira->codegen->invalid_inst_gen;
1781218813 }
1781318814 }
1781418815 if (casted_new_stack != nullptr) {
1781518816 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;
17816 IrInstruction *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,
18817 IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,
1781718818 casted_args, arg_count, ret_ptr_uncasted);
1781818819 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))
17819 return ira->codegen->invalid_instruction;
18820 return ira->codegen->invalid_inst_gen;
1782018821
1782118822 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);
1782218823
17823 IrInstructionCallGen *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
18824 IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
1782418825 arg_count, casted_args, CallModifierAsync, casted_new_stack,
1782518826 is_async_call_builtin, ret_ptr, anyframe_type);
1782618827 return &call_gen->base;
1782718828 } else {
1782818829 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
17829 IrInstruction *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
18830 IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1783018831 frame_type, nullptr, true, true, false);
17831 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
18832 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1783218833 return result_loc;
1783318834 }
1783418835 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));
1783518836 if (type_is_invalid(result_loc->value->type))
17836 return ira->codegen->invalid_instruction;
18837 return ira->codegen->invalid_inst_gen;
1783718838 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,
1783818839 casted_args, CallModifierAsync, casted_new_stack,
1783918840 is_async_call_builtin, result_loc, frame_type)->base;
1784018841 }
1784118842}
1784218843static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,
17843 IrInstruction *arg, Scope **exec_scope, size_t *next_proto_i)
18844 IrInstGen *arg, Scope **exec_scope, size_t *next_proto_i)
1784418845{
1784518846 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
1784618847 assert(param_decl_node->type == NodeTypeParamDecl);
1784718848
17848 IrInstruction *casted_arg;
18849 IrInstGen *casted_arg;
1784918850 if (param_decl_node->data.param_decl.var_token == nullptr) {
1785018851 AstNode *param_type_node = param_decl_node->data.param_decl.type;
1785118852 ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node);
......@@ -17873,15 +18874,15 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
1787318874}
1787418875
1787518876static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
17876 IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,
17877 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,
18877 IrInstGen *arg, Scope **child_scope, size_t *next_proto_i,
18878 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,
1787818879 ZigFn *impl_fn)
1787918880{
1788018881 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
1788118882 assert(param_decl_node->type == NodeTypeParamDecl);
1788218883 bool is_var_args = param_decl_node->data.param_decl.is_var_args;
1788318884 bool arg_part_of_generic_id = false;
17884 IrInstruction *casted_arg;
18885 IrInstGen *casted_arg;
1788518886 if (is_var_args) {
1788618887 arg_part_of_generic_id = true;
1788718888 casted_arg = arg;
......@@ -17941,7 +18942,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1794118942 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
1794218943 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
1794318944 {
17944 ir_add_error(ira, casted_arg,
18945 ir_add_error(ira, &casted_arg->base,
1794518946 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
1794618947 return false;
1794718948 }
......@@ -17958,17 +18959,17 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1795818959 return true;
1795918960}
1796018961
17961static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) {
18962static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
1796218963 while (var->next_var != nullptr) {
1796318964 var = var->next_var;
1796418965 }
1796518966
1796618967 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
1796718968 assert(ira->codegen->errors.length != 0);
17968 return ira->codegen->invalid_instruction;
18969 return ira->codegen->invalid_inst_gen;
1796918970 }
1797018971 if (var->var_type == nullptr || type_is_invalid(var->var_type))
17971 return ira->codegen->invalid_instruction;
18972 return ira->codegen->invalid_inst_gen;
1797218973
1797318974 ZigValue *mem_slot = nullptr;
1797418975
......@@ -17976,8 +18977,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1797618977 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
1797718978 bool is_volatile = false;
1797818979
17979 IrInstruction *result = ir_build_var_ptr(&ira->new_irb,
17980 instruction->scope, instruction->source_node, var);
18980 IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var);
1798118981 result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type,
1798218982 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);
1798318983
......@@ -18030,7 +19030,7 @@ no_mem_slot:
1803019030}
1803119031
1803219032// This function is called when a comptime value becomes accessible at runtime.
18033static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) {
19033static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) {
1803419034 ir_assert(value_is_comptime(val), source_instr);
1803519035 if (val->special == ConstValSpecialUndef)
1803619036 return;
......@@ -18043,8 +19043,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins
1804319043 }
1804419044}
1804519045
18046static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,
18047 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)
19046static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
19047 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const)
1804819048{
1804919049 assert(ptr->value->type->id == ZigTypeIdPointer);
1805019050
......@@ -18053,24 +19053,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1805319053 uncasted_value->value->type->id == ZigTypeIdErrorSet)
1805419054 {
1805519055 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));
18056 return ira->codegen->invalid_instruction;
19056 return ira->codegen->invalid_inst_gen;
1805719057 }
1805819058 return ir_const_void(ira, source_instr);
1805919059 }
1806019060
1806119061 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {
1806219062 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
18063 return ira->codegen->invalid_instruction;
19063 return ira->codegen->invalid_inst_gen;
1806419064 }
1806519065
1806619066 ZigType *child_type = ptr->value->type->data.pointer.child_type;
18067 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);
18068 if (value == ira->codegen->invalid_instruction)
18069 return ira->codegen->invalid_instruction;
19067 IrInstGen *value = ir_implicit_cast(ira, uncasted_value, child_type);
19068 if (type_is_invalid(value->value->type))
19069 return ira->codegen->invalid_inst_gen;
1807019070
1807119071 switch (type_has_one_possible_value(ira->codegen, child_type)) {
1807219072 case OnePossibleValueInvalid:
18073 return ira->codegen->invalid_instruction;
19073 return ira->codegen->invalid_inst_gen;
1807419074 case OnePossibleValueYes:
1807519075 return ir_const_void(ira, source_instr);
1807619076 case OnePossibleValueNo:
......@@ -18080,7 +19080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1808019080 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1808119081 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
1808219082 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
18083 return ira->codegen->invalid_instruction;
19083 return ira->codegen->invalid_inst_gen;
1808419084 }
1808519085 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||
1808619086 ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||
......@@ -18089,7 +19089,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1808919089 if (instr_is_comptime(value)) {
1809019090 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);
1809119091 if (dest_val == nullptr)
18092 return ira->codegen->invalid_instruction;
19092 return ira->codegen->invalid_inst_gen;
1809319093 if (dest_val->special != ConstValSpecialRuntime) {
1809419094 copy_const_val(dest_val, value->value);
1809519095
......@@ -18109,7 +19109,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1810919109 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
1811019110 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1811119111
18112 return ira->codegen->invalid_instruction;
19112 return ira->codegen->invalid_inst_gen;
1811319113 }
1811419114 }
1811519115 }
......@@ -18122,15 +19122,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1812219122
1812319123 switch (type_requires_comptime(ira->codegen, child_type)) {
1812419124 case ReqCompTimeInvalid:
18125 return ira->codegen->invalid_instruction;
19125 return ira->codegen->invalid_inst_gen;
1812619126 case ReqCompTimeYes:
1812719127 switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) {
1812819128 case OnePossibleValueInvalid:
18129 return ira->codegen->invalid_instruction;
19129 return ira->codegen->invalid_inst_gen;
1813019130 case OnePossibleValueNo:
1813119131 ir_add_error(ira, source_instr,
1813219132 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));
18133 return ira->codegen->invalid_instruction;
19133 return ira->codegen->invalid_inst_gen;
1813419134 case OnePossibleValueYes:
1813519135 return ir_const_void(ira, source_instr);
1813619136 }
......@@ -18144,30 +19144,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1814419144 }
1814519145
1814619146 // If this is a store to a pointer with a runtime-known vector index,
18147 // we have to figure out the IrInstruction which represents the index and
18148 // emit a IrInstructionVectorStoreElem, or emit a compile error
19147 // we have to figure out the IrInstGen which represents the index and
19148 // emit a IrInstGenVectorStoreElem, or emit a compile error
1814919149 // explaining why it is impossible for this store to work. Which is that
1815019150 // the pointer address is of the vector; without the element index being known
1815119151 // we cannot properly perform the insertion.
1815219152 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
18153 if (ptr->id == IrInstructionIdElemPtr) {
18154 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;
19153 if (ptr->id == IrInstGenIdElemPtr) {
19154 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
1815519155 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,
1815619156 elem_ptr->elem_index, value);
1815719157 }
18158 ir_add_error(ira, ptr,
19158 ir_add_error(ira, &ptr->base,
1815919159 buf_sprintf("unable to determine vector element index of type '%s'",
1816019160 buf_ptr(&ptr->value->type->name)));
18161 return ira->codegen->invalid_instruction;
19161 return ira->codegen->invalid_inst_gen;
1816219162 }
1816319163
18164 IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope,
18165 source_instr->source_node, ptr, value);
18166 return &store_ptr->base;
19164 return ir_build_store_ptr_gen(ira, source_instr, ptr, value);
1816719165}
1816819166
18169static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *source_instr,
18170 IrInstruction *new_stack, bool is_async_call_builtin, ZigFn *fn_entry)
19167static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
19168 IrInstGen *new_stack, bool is_async_call_builtin, ZigFn *fn_entry)
1817119169{
1817219170 if (new_stack == nullptr)
1817319171 return nullptr;
......@@ -18196,11 +19194,11 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so
1819619194 }
1819719195}
1819819196
18199static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_instr,
18200 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
18201 IrInstruction *first_arg_ptr, CallModifier modifier,
18202 IrInstruction *new_stack, bool is_async_call_builtin,
18203 IrInstruction **args_ptr, size_t args_len, IrInstruction *ret_ptr, ResultLoc *call_result_loc)
19197static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19198 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
19199 IrInstGen *first_arg_ptr, CallModifier modifier,
19200 IrInstGen *new_stack, bool is_async_call_builtin,
19201 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)
1820419202{
1820519203 Error err;
1820619204 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
......@@ -18221,11 +19219,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1822119219 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
1822219220
1822319221 if (fn_type_id->cc == CallingConventionNaked) {
18224 ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention"));
19222 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention"));
1822519223 if (fn_proto_node) {
1822619224 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));
1822719225 }
18228 return ira->codegen->invalid_instruction;
19226 return ira->codegen->invalid_inst_gen;
1822919227 }
1823019228
1823119229 if (fn_type_id->is_var_args) {
......@@ -18236,7 +19234,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1823619234 add_error_note(ira->codegen, msg, fn_proto_node,
1823719235 buf_sprintf("declared here"));
1823819236 }
18239 return ira->codegen->invalid_instruction;
19237 return ira->codegen->invalid_inst_gen;
1824019238 }
1824119239 } else if (src_param_count != call_param_count) {
1824219240 ErrorMsg *msg = ir_add_error_node(ira, source_node,
......@@ -18245,18 +19243,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1824519243 add_error_note(ira->codegen, msg, fn_proto_node,
1824619244 buf_sprintf("declared here"));
1824719245 }
18248 return ira->codegen->invalid_instruction;
19246 return ira->codegen->invalid_inst_gen;
1824919247 }
1825019248
1825119249 if (modifier == CallModifierCompileTime) {
1825219250 // No special handling is needed for compile time evaluation of generic functions.
1825319251 if (!fn_entry || fn_entry->body_node == nullptr) {
18254 ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression"));
18255 return ira->codegen->invalid_instruction;
19252 ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression"));
19253 return ira->codegen->invalid_inst_gen;
1825619254 }
1825719255
1825819256 if (!ir_emit_backward_branch(ira, source_instr))
18259 return ira->codegen->invalid_instruction;
19257 return ira->codegen->invalid_inst_gen;
1826019258
1826119259 // Fork a scope of the function with known values for the parameters.
1826219260 Scope *exec_scope = &fn_entry->fndef_scope->base;
......@@ -18269,47 +19267,47 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1826919267 if (fn_type_id->next_param_index >= 1) {
1827019268 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
1827119269 if (type_is_invalid(param_type))
18272 return ira->codegen->invalid_instruction;
19270 return ira->codegen->invalid_inst_gen;
1827319271 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
1827419272 }
1827519273
18276 IrInstruction *first_arg;
19274 IrInstGen *first_arg;
1827719275 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
1827819276 first_arg = first_arg_ptr;
1827919277 } else {
18280 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
19278 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
1828119279 if (type_is_invalid(first_arg->value->type))
18282 return ira->codegen->invalid_instruction;
19280 return ira->codegen->invalid_inst_gen;
1828319281 }
1828419282
1828519283 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i))
18286 return ira->codegen->invalid_instruction;
19284 return ira->codegen->invalid_inst_gen;
1828719285 }
1828819286
1828919287 if (fn_proto_node->data.fn_proto.is_var_args) {
1829019288 ir_add_error(ira, source_instr,
1829119289 buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313"));
18292 return ira->codegen->invalid_instruction;
19290 return ira->codegen->invalid_inst_gen;
1829319291 }
1829419292
1829519293
1829619294 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18297 IrInstruction *old_arg = args_ptr[call_i];
19295 IrInstGen *old_arg = args_ptr[call_i];
1829819296
1829919297 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))
18300 return ira->codegen->invalid_instruction;
19298 return ira->codegen->invalid_inst_gen;
1830119299 }
1830219300
1830319301 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
1830419302 ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node);
1830519303 if (type_is_invalid(specified_return_type))
18306 return ira->codegen->invalid_instruction;
19304 return ira->codegen->invalid_inst_gen;
1830719305 ZigType *return_type;
1830819306 ZigType *inferred_err_set_type = nullptr;
1830919307 if (fn_proto_node->data.fn_proto.auto_err_set) {
1831019308 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);
1831119309 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18312 return ira->codegen->invalid_instruction;
19310 return ira->codegen->invalid_inst_gen;
1831319311 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
1831419312 } else {
1831519313 return_type = specified_return_type;
......@@ -18354,24 +19352,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1835419352 }
1835519353
1835619354 if (type_is_invalid(result->type)) {
18357 return ira->codegen->invalid_instruction;
19355 return ira->codegen->invalid_inst_gen;
1835819356 }
1835919357 }
1836019358
18361 IrInstruction *new_instruction = ir_const_move(ira, source_instr, result);
19359 IrInstGen *new_instruction = ir_const_move(ira, source_instr, result);
1836219360 return ir_finish_anal(ira, new_instruction);
1836319361 }
1836419362
1836519363 if (fn_type->data.fn.is_generic) {
1836619364 if (!fn_entry) {
18367 ir_add_error(ira, fn_ref,
19365 ir_add_error(ira, &fn_ref->base,
1836819366 buf_sprintf("calling a generic function requires compile-time known function value"));
18369 return ira->codegen->invalid_instruction;
19367 return ira->codegen->invalid_inst_gen;
1837019368 }
1837119369
1837219370 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;
1837319371
18374 IrInstruction **casted_args = allocate<IrInstruction *>(new_fn_arg_count);
19372 IrInstGen **casted_args = allocate<IrInstGen *>(new_fn_arg_count);
1837519373
1837619374 // Fork a scope of the function with known values for the parameters.
1837719375 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
......@@ -18400,30 +19398,30 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1840019398 if (fn_type_id->next_param_index >= 1) {
1840119399 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
1840219400 if (type_is_invalid(param_type))
18403 return ira->codegen->invalid_instruction;
19401 return ira->codegen->invalid_inst_gen;
1840419402 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
1840519403 }
1840619404
18407 IrInstruction *first_arg;
19405 IrInstGen *first_arg;
1840819406 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
1840919407 first_arg = first_arg_ptr;
1841019408 } else {
18411 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
19409 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
1841219410 if (type_is_invalid(first_arg->value->type))
18413 return ira->codegen->invalid_instruction;
19411 return ira->codegen->invalid_inst_gen;
1841419412 }
1841519413
1841619414 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,
1841719415 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
1841819416 {
18419 return ira->codegen->invalid_instruction;
19417 return ira->codegen->invalid_inst_gen;
1842019418 }
1842119419 }
1842219420
18423 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
19421 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
1842419422 assert(parent_fn_entry);
1842519423 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18426 IrInstruction *arg = args_ptr[call_i];
19424 IrInstGen *arg = args_ptr[call_i];
1842719425
1842819426 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
1842919427 assert(param_decl_node->type == NodeTypeParamDecl);
......@@ -18431,7 +19429,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1843119429 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,
1843219430 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
1843319431 {
18434 return ira->codegen->invalid_instruction;
19432 return ira->codegen->invalid_inst_gen;
1843519433 }
1843619434 }
1843719435
......@@ -18441,7 +19439,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1844119439 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
1844219440 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
1844319441 nullptr, UndefBad);
18444 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
19442 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1844519443 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
1844619444 copy_const_val(const_instruction->base.value, align_result);
1844719445
......@@ -18455,11 +19453,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1845519453 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
1845619454 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);
1845719455 if (type_is_invalid(specified_return_type))
18458 return ira->codegen->invalid_instruction;
19456 return ira->codegen->invalid_inst_gen;
1845919457 if (fn_proto_node->data.fn_proto.auto_err_set) {
1846019458 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
1846119459 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18462 return ira->codegen->invalid_instruction;
19460 return ira->codegen->invalid_inst_gen;
1846319461 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
1846419462 } else {
1846519463 inst_fn_type_id.return_type = specified_return_type;
......@@ -18472,7 +19470,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1847219470 CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len,
1847319471 ret_ptr, call_result_loc);
1847419472 case ReqCompTimeInvalid:
18475 return ira->codegen->invalid_instruction;
19473 return ira->codegen->invalid_inst_gen;
1847619474 case ReqCompTimeNo:
1847719475 break;
1847819476 }
......@@ -18486,7 +19484,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1848619484 // finish instantiating the function
1848719485 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);
1848819486 if (type_is_invalid(impl_fn->type_entry))
18489 return ira->codegen->invalid_instruction;
19487 return ira->codegen->invalid_inst_gen;
1849019488
1849119489 impl_fn->ir_executable->source_node = source_instr->source_node;
1849219490 impl_fn->ir_executable->parent_exec = ira->new_irb.exec;
......@@ -18504,25 +19502,25 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1850419502 parent_fn_entry->calls_or_awaits_errorable_fn = true;
1850519503 }
1850619504
18507 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
19505 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
1850819506 is_async_call_builtin, impl_fn);
1850919507 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
18510 return ira->codegen->invalid_instruction;
19508 return ira->codegen->invalid_inst_gen;
1851119509
1851219510 size_t impl_param_count = impl_fn_type_id->param_count;
1851319511 if (modifier == CallModifierAsync) {
18514 IrInstruction *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,
19512 IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,
1851519513 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,
1851619514 call_result_loc);
1851719515 return ir_finish_anal(ira, result);
1851819516 }
1851919517
18520 IrInstruction *result_loc;
19518 IrInstGen *result_loc;
1852119519 if (handle_is_ptr(impl_fn_type_id->return_type)) {
1852219520 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1852319521 impl_fn_type_id->return_type, nullptr, true, true, false);
1852419522 if (result_loc != nullptr) {
18525 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
19523 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1852619524 return result_loc;
1852719525 }
1852819526 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
......@@ -18538,7 +19536,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1853819536 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,
1853919537 is_async_call_builtin, args_ptr, args_len, ret_ptr);
1854019538 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18541 return ira->codegen->invalid_instruction;
19539 return ira->codegen->invalid_inst_gen;
1854219540 } else {
1854319541 result_loc = nullptr;
1854419542 }
......@@ -18547,11 +19545,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1854719545 parent_fn_entry->inferred_async_node == nullptr &&
1854819546 modifier != CallModifierNoAsync)
1854919547 {
18550 parent_fn_entry->inferred_async_node = fn_ref->source_node;
19548 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
1855119549 parent_fn_entry->inferred_async_fn = impl_fn;
1855219550 }
1855319551
18554 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr,
19552 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr,
1855519553 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,
1855619554 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);
1855719555
......@@ -18562,7 +19560,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1856219560 return ir_finish_anal(ira, &new_call_instruction->base);
1856319561 }
1856419562
18565 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
19563 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
1856619564 assert(fn_type_id->return_type != nullptr);
1856719565 assert(parent_fn_entry != nullptr);
1856819566 if (fn_type_can_fail(fn_type_id)) {
......@@ -18570,46 +19568,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1857019568 }
1857119569
1857219570
18573 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
19571 IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count);
1857419572 size_t next_arg_index = 0;
1857519573 if (first_arg_ptr) {
1857619574 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1857719575
1857819576 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
1857919577 if (type_is_invalid(param_type))
18580 return ira->codegen->invalid_instruction;
19578 return ira->codegen->invalid_inst_gen;
1858119579
18582 IrInstruction *first_arg;
19580 IrInstGen *first_arg;
1858319581 if (param_type->id == ZigTypeIdPointer &&
1858419582 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))
1858519583 {
1858619584 first_arg = first_arg_ptr;
1858719585 } else {
18588 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
19586 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
1858919587 if (type_is_invalid(first_arg->value->type))
18590 return ira->codegen->invalid_instruction;
19588 return ira->codegen->invalid_inst_gen;
1859119589 }
1859219590
18593 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
19591 IrInstGen *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
1859419592 if (type_is_invalid(casted_arg->value->type))
18595 return ira->codegen->invalid_instruction;
19593 return ira->codegen->invalid_inst_gen;
1859619594
1859719595 casted_args[next_arg_index] = casted_arg;
1859819596 next_arg_index += 1;
1859919597 }
1860019598 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18601 IrInstruction *old_arg = args_ptr[call_i];
19599 IrInstGen *old_arg = args_ptr[call_i];
1860219600 if (type_is_invalid(old_arg->value->type))
18603 return ira->codegen->invalid_instruction;
19601 return ira->codegen->invalid_inst_gen;
1860419602
18605 IrInstruction *casted_arg;
19603 IrInstGen *casted_arg;
1860619604 if (next_arg_index < src_param_count) {
1860719605 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
1860819606 if (type_is_invalid(param_type))
18609 return ira->codegen->invalid_instruction;
19607 return ira->codegen->invalid_inst_gen;
1861019608 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
1861119609 if (type_is_invalid(casted_arg->value->type))
18612 return ira->codegen->invalid_instruction;
19610 return ira->codegen->invalid_inst_gen;
1861319611 } else {
1861419612 casted_arg = old_arg;
1861519613 }
......@@ -18622,21 +19620,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1862219620
1862319621 ZigType *return_type = fn_type_id->return_type;
1862419622 if (type_is_invalid(return_type))
18625 return ira->codegen->invalid_instruction;
19623 return ira->codegen->invalid_inst_gen;
1862619624
1862719625 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) {
1862819626 ir_add_error(ira, source_instr,
1862919627 buf_sprintf("no-inline call of inline function"));
18630 return ira->codegen->invalid_instruction;
19628 return ira->codegen->invalid_inst_gen;
1863119629 }
1863219630
18633 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
19631 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
1863419632 is_async_call_builtin, fn_entry);
1863519633 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
18636 return ira->codegen->invalid_instruction;
19634 return ira->codegen->invalid_inst_gen;
1863719635
1863819636 if (modifier == CallModifierAsync) {
18639 IrInstruction *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,
19637 IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,
1864019638 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);
1864119639 return ir_finish_anal(ira, result);
1864219640 }
......@@ -18645,16 +19643,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1864519643 parent_fn_entry->inferred_async_node == nullptr &&
1864619644 modifier != CallModifierNoAsync)
1864719645 {
18648 parent_fn_entry->inferred_async_node = fn_ref->source_node;
19646 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
1864919647 parent_fn_entry->inferred_async_fn = fn_entry;
1865019648 }
1865119649
18652 IrInstruction *result_loc;
19650 IrInstGen *result_loc;
1865319651 if (handle_is_ptr(return_type)) {
1865419652 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1865519653 return_type, nullptr, true, true, false);
1865619654 if (result_loc != nullptr) {
18657 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
19655 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1865819656 return result_loc;
1865919657 }
1866019658 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
......@@ -18670,12 +19668,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1867019668 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,
1867119669 args_ptr, args_len, ret_ptr);
1867219670 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18673 return ira->codegen->invalid_instruction;
19671 return ira->codegen->invalid_inst_gen;
1867419672 } else {
1867519673 result_loc = nullptr;
1867619674 }
1867719675
18678 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
19676 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
1867919677 call_param_count, casted_args, modifier, casted_new_stack,
1868019678 is_async_call_builtin, result_loc, return_type);
1868119679 if (get_scope_typeof(source_instr->scope) == nullptr) {
......@@ -18684,62 +19682,62 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1868419682 return ir_finish_anal(ira, &new_call_instruction->base);
1868519683}
1868619684
18687static IrInstruction *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstructionCallSrc *call_instruction,
18688 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
18689 IrInstruction *first_arg_ptr, CallModifier modifier)
19685static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,
19686 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
19687 IrInstGen *first_arg_ptr, CallModifier modifier)
1869019688{
18691 IrInstruction *new_stack = nullptr;
19689 IrInstGen *new_stack = nullptr;
1869219690 if (call_instruction->new_stack) {
1869319691 new_stack = call_instruction->new_stack->child;
1869419692 if (type_is_invalid(new_stack->value->type))
18695 return ira->codegen->invalid_instruction;
19693 return ira->codegen->invalid_inst_gen;
1869619694 }
18697 IrInstruction **args_ptr = allocate<IrInstruction *>(call_instruction->arg_count, "IrInstruction *");
19695 IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *");
1869819696 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
1869919697 args_ptr[i] = call_instruction->args[i]->child;
1870019698 if (type_is_invalid(args_ptr[i]->value->type))
18701 return ira->codegen->invalid_instruction;
19699 return ira->codegen->invalid_inst_gen;
1870219700 }
18703 IrInstruction *ret_ptr = nullptr;
19701 IrInstGen *ret_ptr = nullptr;
1870419702 if (call_instruction->ret_ptr != nullptr) {
1870519703 ret_ptr = call_instruction->ret_ptr->child;
1870619704 if (type_is_invalid(ret_ptr->value->type))
18707 return ira->codegen->invalid_instruction;
19705 return ira->codegen->invalid_inst_gen;
1870819706 }
18709 IrInstruction *result = ir_analyze_fn_call(ira, &call_instruction->base, fn_entry, fn_type, fn_ref,
19707 IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref,
1871019708 first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin,
1871119709 args_ptr, call_instruction->arg_count, ret_ptr, call_instruction->result_loc);
18712 deallocate(args_ptr, call_instruction->arg_count, "IrInstruction *");
19710 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");
1871319711 return result;
1871419712}
1871519713
18716static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *source_instr,
18717 IrInstruction *pass1_options, IrInstruction *pass1_fn_ref, IrInstruction **args_ptr, size_t args_len,
19714static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
19715 IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len,
1871819716 ResultLoc *result_loc)
1871919717{
18720 IrInstruction *options = pass1_options->child;
19718 IrInstGen *options = pass1_options->child;
1872119719 if (type_is_invalid(options->value->type))
18722 return ira->codegen->invalid_instruction;
19720 return ira->codegen->invalid_inst_gen;
1872319721
18724 IrInstruction *fn_ref = pass1_fn_ref->child;
19722 IrInstGen *fn_ref = pass1_fn_ref->child;
1872519723 if (type_is_invalid(fn_ref->value->type))
18726 return ira->codegen->invalid_instruction;
19724 return ira->codegen->invalid_inst_gen;
1872719725
1872819726 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));
1872919727 ir_assert(modifier_field != nullptr, source_instr);
18730 IrInstruction *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);
19728 IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);
1873119729 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);
1873219730 if (modifier_val == nullptr)
18733 return ira->codegen->invalid_instruction;
19731 return ira->codegen->invalid_inst_gen;
1873419732 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);
1873519733
18736 if (ir_should_inline(ira->new_irb.exec, source_instr->scope)) {
19734 if (ir_should_inline(ira->old_irb.exec, source_instr->scope)) {
1873719735 switch (modifier) {
1873819736 case CallModifierBuiltin:
1873919737 zig_unreachable();
1874019738 case CallModifierAsync:
1874119739 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier"));
18742 return ira->codegen->invalid_instruction;
19740 return ira->codegen->invalid_inst_gen;
1874319741 case CallModifierCompileTime:
1874419742 case CallModifierNone:
1874519743 case CallModifierAlwaysInline:
......@@ -18750,15 +19748,15 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1875019748 case CallModifierNeverInline:
1875119749 ir_add_error(ira, source_instr,
1875219750 buf_sprintf("unable to perform 'never_inline' call at compile-time"));
18753 return ira->codegen->invalid_instruction;
19751 return ira->codegen->invalid_inst_gen;
1875419752 case CallModifierNeverTail:
1875519753 ir_add_error(ira, source_instr,
1875619754 buf_sprintf("unable to perform 'never_tail' call at compile-time"));
18757 return ira->codegen->invalid_instruction;
19755 return ira->codegen->invalid_inst_gen;
1875819756 }
1875919757 }
1876019758
18761 IrInstruction *first_arg_ptr = nullptr;
19759 IrInstGen *first_arg_ptr = nullptr;
1876219760 ZigFn *fn = nullptr;
1876319761 if (instr_is_comptime(fn_ref)) {
1876419762 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
......@@ -18766,7 +19764,7 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1876619764 fn = fn_ref->value->data.x_bound_fn.fn;
1876719765 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
1876819766 if (type_is_invalid(first_arg_ptr->value->type))
18769 return ira->codegen->invalid_instruction;
19767 return ira->codegen->invalid_inst_gen;
1877019768 } else {
1877119769 fn = ir_resolve_fn(ira, fn_ref);
1877219770 }
......@@ -18778,9 +19776,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1877819776 case CallModifierAlwaysInline:
1877919777 case CallModifierAsync:
1878019778 if (fn == nullptr) {
18781 ir_add_error(ira, modifier_inst,
19779 ir_add_error(ira, &modifier_inst->base,
1878219780 buf_sprintf("the specified modifier requires a comptime-known function"));
18783 return ira->codegen->invalid_instruction;
19781 return ira->codegen->invalid_inst_gen;
1878419782 }
1878519783 default:
1878619784 break;
......@@ -18790,93 +19788,93 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1879019788
1879119789 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));
1879219790 ir_assert(stack_field != nullptr, source_instr);
18793 IrInstruction *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);
19791 IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);
1879419792 if (type_is_invalid(opt_stack->value->type))
18795 return ira->codegen->invalid_instruction;
19793 return ira->codegen->invalid_inst_gen;
1879619794
18797 IrInstruction *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);
19795 IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);
1879819796 bool stack_is_non_null;
1879919797 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))
18800 return ira->codegen->invalid_instruction;
19798 return ira->codegen->invalid_inst_gen;
1880119799
18802 IrInstruction *stack = nullptr;
19800 IrInstGen *stack = nullptr;
1880319801 if (stack_is_non_null) {
1880419802 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);
1880519803 if (type_is_invalid(stack->value->type))
18806 return ira->codegen->invalid_instruction;
19804 return ira->codegen->invalid_inst_gen;
1880719805 }
1880819806
1880919807 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr,
1881019808 modifier, stack, false, args_ptr, args_len, nullptr, result_loc);
1881119809}
1881219810
18813static IrInstruction *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstructionCallExtra *instruction) {
18814 IrInstruction *args = instruction->args->child;
19811static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) {
19812 IrInstGen *args = instruction->args->child;
1881519813 ZigType *args_type = args->value->type;
1881619814 if (type_is_invalid(args_type))
18817 return ira->codegen->invalid_instruction;
19815 return ira->codegen->invalid_inst_gen;
1881819816
1881919817 if (args_type->id != ZigTypeIdStruct) {
18820 ir_add_error(ira, args,
19818 ir_add_error(ira, &args->base,
1882119819 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));
18822 return ira->codegen->invalid_instruction;
19820 return ira->codegen->invalid_inst_gen;
1882319821 }
1882419822
18825 IrInstruction **args_ptr = nullptr;
19823 IrInstGen **args_ptr = nullptr;
1882619824 size_t args_len = 0;
1882719825
1882819826 if (is_tuple(args_type)) {
1882919827 args_len = args_type->data.structure.src_field_count;
18830 args_ptr = allocate<IrInstruction *>(args_len, "IrInstruction *");
19828 args_ptr = allocate<IrInstGen *>(args_len, "IrInstGen *");
1883119829 for (size_t i = 0; i < args_len; i += 1) {
1883219830 TypeStructField *arg_field = args_type->data.structure.fields[i];
18833 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base, args, arg_field);
19831 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field);
1883419832 if (type_is_invalid(args_ptr[i]->value->type))
18835 return ira->codegen->invalid_instruction;
19833 return ira->codegen->invalid_inst_gen;
1883619834 }
1883719835 } else {
18838 ir_add_error(ira, args, buf_sprintf("TODO: struct args"));
18839 return ira->codegen->invalid_instruction;
19836 ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args"));
19837 return ira->codegen->invalid_inst_gen;
1884019838 }
18841 IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options,
19839 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1884219840 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
18843 deallocate(args_ptr, args_len, "IrInstruction *");
19841 deallocate(args_ptr, args_len, "IrInstGen *");
1884419842 return result;
1884519843}
1884619844
18847static IrInstruction *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstructionCallSrcArgs *instruction) {
18848 IrInstruction **args_ptr = allocate<IrInstruction *>(instruction->args_len, "IrInstruction *");
19845static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) {
19846 IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *");
1884919847 for (size_t i = 0; i < instruction->args_len; i += 1) {
1885019848 args_ptr[i] = instruction->args_ptr[i]->child;
1885119849 if (type_is_invalid(args_ptr[i]->value->type))
18852 return ira->codegen->invalid_instruction;
19850 return ira->codegen->invalid_inst_gen;
1885319851 }
1885419852
18855 IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options,
19853 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1885619854 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);
18857 deallocate(args_ptr, instruction->args_len, "IrInstruction *");
19855 deallocate(args_ptr, instruction->args_len, "IrInstGen *");
1885819856 return result;
1885919857}
1886019858
18861static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {
18862 IrInstruction *fn_ref = call_instruction->fn_ref->child;
19859static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *call_instruction) {
19860 IrInstGen *fn_ref = call_instruction->fn_ref->child;
1886319861 if (type_is_invalid(fn_ref->value->type))
18864 return ira->codegen->invalid_instruction;
19862 return ira->codegen->invalid_inst_gen;
1886519863
1886619864 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||
18867 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
19865 ir_should_inline(ira->old_irb.exec, call_instruction->base.base.scope);
1886819866 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1886919867
1887019868 if (is_comptime || instr_is_comptime(fn_ref)) {
1887119869 if (fn_ref->value->type->id == ZigTypeIdMetaType) {
1887219870 ZigType *ty = ir_resolve_type(ira, fn_ref);
1887319871 if (ty == nullptr)
18874 return ira->codegen->invalid_instruction;
18875 ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node,
19872 return ira->codegen->invalid_inst_gen;
19873 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base,
1887619874 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
18877 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
19875 add_error_note(ira->codegen, msg, call_instruction->base.base.source_node,
1887819876 buf_sprintf("use @as builtin for type coercion"));
18879 return ira->codegen->invalid_instruction;
19877 return ira->codegen->invalid_inst_gen;
1888019878 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
1888119879 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
1888219880 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;
......@@ -18886,14 +19884,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1888619884 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
1888719885 assert(fn_ref->value->special == ConstValSpecialStatic);
1888819886 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
18889 IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
19887 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
1889019888 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1889119889 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
1889219890 fn_ref, first_arg_ptr, modifier);
1889319891 } else {
18894 ir_add_error_node(ira, fn_ref->source_node,
19892 ir_add_error(ira, &fn_ref->base,
1889519893 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
18896 return ira->codegen->invalid_instruction;
19894 return ira->codegen->invalid_inst_gen;
1889719895 }
1889819896 }
1889919897
......@@ -18901,9 +19899,9 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1890119899 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,
1890219900 fn_ref, nullptr, modifier);
1890319901 } else {
18904 ir_add_error_node(ira, fn_ref->source_node,
19902 ir_add_error(ira, &fn_ref->base,
1890519903 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
18906 return ira->codegen->invalid_instruction;
19904 return ira->codegen->invalid_inst_gen;
1890719905 }
1890819906}
1890919907
......@@ -18992,8 +19990,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1899219990 zig_unreachable();
1899319991}
1899419992
18995static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) {
18996 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
19993static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19994 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
1899719995 result->value->special = ConstValSpecialLazy;
1899819996
1899919997 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");
......@@ -19003,12 +20001,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
1900320001
1900420002 lazy_opt_type->payload_type = instruction->value->child;
1900520003 if (ir_resolve_type_lazy(ira, lazy_opt_type->payload_type) == nullptr)
19006 return ira->codegen->invalid_instruction;
20004 return ira->codegen->invalid_inst_gen;
1900720005
1900820006 return result;
1900920007}
1901020008
19011static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type,
20009static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type,
1901220010 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
1901320011{
1901420012 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);
......@@ -19043,19 +20041,19 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i
1904320041 return nullptr;
1904420042}
1904520043
19046static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) {
19047 IrInstruction *value = instruction->value->child;
20044static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
20045 IrInstGen *value = instruction->value->child;
1904820046 ZigType *expr_type = value->value->type;
1904920047 if (type_is_invalid(expr_type))
19050 return ira->codegen->invalid_instruction;
20048 return ira->codegen->invalid_inst_gen;
1905120049
1905220050 if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt ||
1905320051 expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat ||
1905420052 expr_type->id == ZigTypeIdVector))
1905520053 {
19056 ir_add_error(ira, &instruction->base,
20054 ir_add_error(ira, &instruction->base.base,
1905720055 buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name)));
19058 return ira->codegen->invalid_instruction;
20056 return ira->codegen->invalid_inst_gen;
1905920057 }
1906020058
1906120059 bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap);
......@@ -19065,9 +20063,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
1906520063 if (instr_is_comptime(value)) {
1906620064 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);
1906720065 if (!operand_val)
19068 return ira->codegen->invalid_instruction;
20066 return ira->codegen->invalid_inst_gen;
1906920067
19070 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);
20068 IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type);
1907120069 ZigValue *out_val = result_instruction->value;
1907220070 if (expr_type->id == ZigTypeIdVector) {
1907320071 expand_undef_array(ira->codegen, operand_val);
......@@ -19079,63 +20077,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
1907920077 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
1908020078 assert(scalar_operand_val->type == scalar_type);
1908120079 assert(scalar_out_val->type == scalar_type);
19082 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,
20080 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type,
1908320081 scalar_operand_val, scalar_out_val, is_wrap_op);
1908420082 if (msg != nullptr) {
19085 add_error_note(ira->codegen, msg, instruction->base.source_node,
20083 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
1908620084 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
19087 return ira->codegen->invalid_instruction;
20085 return ira->codegen->invalid_inst_gen;
1908820086 }
1908920087 }
1909020088 out_val->type = expr_type;
1909120089 out_val->special = ConstValSpecialStatic;
1909220090 } else {
19093 if (ir_eval_negation_scalar(ira, &instruction->base, scalar_type, operand_val, out_val,
20091 if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val,
1909420092 is_wrap_op) != nullptr)
1909520093 {
19096 return ira->codegen->invalid_instruction;
20094 return ira->codegen->invalid_inst_gen;
1909720095 }
1909820096 }
1909920097 return result_instruction;
1910020098 }
1910120099
19102 IrInstruction *result = ir_build_un_op(&ira->new_irb,
19103 instruction->base.scope, instruction->base.source_node,
19104 instruction->op_id, value);
19105 result->value->type = expr_type;
19106 return result;
20100 if (is_wrap_op) {
20101 return ir_build_negation_wrapping(ira, &instruction->base.base, value, expr_type);
20102 } else {
20103 return ir_build_negation(ira, &instruction->base.base, value, expr_type);
20104 }
1910720105}
1910820106
19109static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
19110 IrInstruction *value = instruction->value->child;
20107static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
20108 IrInstGen *value = instruction->value->child;
1911120109 ZigType *expr_type = value->value->type;
1911220110 if (type_is_invalid(expr_type))
19113 return ira->codegen->invalid_instruction;
20111 return ira->codegen->invalid_inst_gen;
1911420112
1911520113 if (expr_type->id == ZigTypeIdInt) {
1911620114 if (instr_is_comptime(value)) {
1911720115 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
1911820116 if (target_const_val == nullptr)
19119 return ira->codegen->invalid_instruction;
20117 return ira->codegen->invalid_inst_gen;
1912020118
19121 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
20119 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
1912220120 bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint,
1912320121 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);
1912420122 return result;
1912520123 }
1912620124
19127 IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope,
19128 instruction->base.source_node, IrUnOpBinNot, value);
19129 result->value->type = expr_type;
19130 return result;
20125 return ir_build_binary_not(ira, &instruction->base.base, value, expr_type);
1913120126 }
1913220127
19133 ir_add_error(ira, &instruction->base,
20128 ir_add_error(ira, &instruction->base.base,
1913420129 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));
19135 return ira->codegen->invalid_instruction;
20130 return ira->codegen->invalid_inst_gen;
1913620131}
1913720132
19138static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *instruction) {
20133static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
1913920134 IrUnOp op_id = instruction->op_id;
1914020135 switch (op_id) {
1914120136 case IrUnOpInvalid:
......@@ -19146,26 +20141,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
1914620141 case IrUnOpNegationWrap:
1914720142 return ir_analyze_negation(ira, instruction);
1914820143 case IrUnOpDereference: {
19149 IrInstruction *ptr = instruction->value->child;
20144 IrInstGen *ptr = instruction->value->child;
1915020145 if (type_is_invalid(ptr->value->type))
19151 return ira->codegen->invalid_instruction;
20146 return ira->codegen->invalid_inst_gen;
1915220147 ZigType *ptr_type = ptr->value->type;
1915320148 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
19154 ir_add_error_node(ira, instruction->base.source_node,
20149 ir_add_error_node(ira, instruction->base.base.source_node,
1915520150 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
1915620151 buf_ptr(&ptr_type->name)));
19157 return ira->codegen->invalid_instruction;
20152 return ira->codegen->invalid_inst_gen;
1915820153 }
1915920154
19160 IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr, instruction->result_loc);
19161 if (result == ira->codegen->invalid_instruction)
19162 return ira->codegen->invalid_instruction;
20155 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc);
20156 if (type_is_invalid(result->value->type))
20157 return ira->codegen->invalid_inst_gen;
1916320158
1916420159 // If the result needs to be an lvalue, type check it
1916520160 if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) {
19166 ir_add_error(ira, &instruction->base,
20161 ir_add_error(ira, &instruction->base.base,
1916720162 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));
19168 return ira->codegen->invalid_instruction;
20163 return ira->codegen->invalid_inst_gen;
1916920164 }
1917020165
1917120166 return result;
......@@ -19177,42 +20172,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
1917720172}
1917820173
1917920174static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) {
19180 IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index);
20175 IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index);
1918120176 if (old_bb->in_resume_stack) return;
1918220177 ira->resume_stack.append(pos);
1918320178 old_bb->in_resume_stack = true;
1918420179}
1918520180
19186static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlock *old_bb) {
20181static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlockSrc *old_bb) {
1918720182 if (ira->resume_stack.length != 0) {
1918820183 ir_push_resume(ira, {old_bb->index, 0});
1918920184 }
1919020185}
1919120186
19192static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
19193 IrBasicBlock *old_dest_block = br_instruction->dest_block;
20187static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_instruction) {
20188 IrBasicBlockSrc *old_dest_block = br_instruction->dest_block;
1919420189
1919520190 bool is_comptime;
1919620191 if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime))
1919720192 return ir_unreach_error(ira);
1919820193
1919920194 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
19200 return ir_inline_bb(ira, &br_instruction->base, old_dest_block);
20195 return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block);
1920120196
19202 IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);
20197 IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base);
1920320198 if (new_bb == nullptr)
1920420199 return ir_unreach_error(ira);
1920520200
1920620201 ir_push_resume_block(ira, old_dest_block);
1920720202
19208 IrInstruction *result = ir_build_br(&ira->new_irb,
19209 br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr);
19210 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20203 IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb);
1921120204 return ir_finish_anal(ira, result);
1921220205}
1921320206
19214static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
19215 IrInstruction *condition = cond_br_instruction->condition->child;
20207static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr *cond_br_instruction) {
20208 IrInstGen *condition = cond_br_instruction->condition->child;
1921620209 if (type_is_invalid(condition->value->type))
1921720210 return ir_unreach_error(ira);
1921820211
......@@ -19221,7 +20214,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1922120214 return ir_unreach_error(ira);
1922220215
1922320216 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
19224 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);
20217 IrInstGen *casted_condition = ir_implicit_cast(ira, condition, bool_type);
1922520218 if (type_is_invalid(casted_condition->value->type))
1922620219 return ir_unreach_error(ira);
1922720220
......@@ -19230,67 +20223,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1923020223 if (!ir_resolve_bool(ira, casted_condition, &cond_is_true))
1923120224 return ir_unreach_error(ira);
1923220225
19233 IrBasicBlock *old_dest_block = cond_is_true ?
20226 IrBasicBlockSrc *old_dest_block = cond_is_true ?
1923420227 cond_br_instruction->then_block : cond_br_instruction->else_block;
1923520228
1923620229 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
19237 return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block);
20230 return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block);
1923820231
19239 IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);
20232 IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base);
1924020233 if (new_dest_block == nullptr)
1924120234 return ir_unreach_error(ira);
1924220235
1924320236 ir_push_resume_block(ira, old_dest_block);
1924420237
19245 IrInstruction *result = ir_build_br(&ira->new_irb,
19246 cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr);
19247 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20238 IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block);
1924820239 return ir_finish_anal(ira, result);
1924920240 }
1925020241
1925120242 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);
19252 IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
20243 IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base);
1925320244 if (new_then_block == nullptr)
1925420245 return ir_unreach_error(ira);
1925520246
19256 IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
20247 IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base);
1925720248 if (new_else_block == nullptr)
1925820249 return ir_unreach_error(ira);
1925920250
1926020251 ir_push_resume_block(ira, cond_br_instruction->else_block);
1926120252 ir_push_resume_block(ira, cond_br_instruction->then_block);
1926220253
19263 IrInstruction *result = ir_build_cond_br(&ira->new_irb,
19264 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,
19265 casted_condition, new_then_block, new_else_block, nullptr);
19266 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20254 IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base,
20255 casted_condition, new_then_block, new_else_block);
1926720256 return ir_finish_anal(ira, result);
1926820257}
1926920258
19270static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,
19271 IrInstructionUnreachable *unreachable_instruction)
20259static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira,
20260 IrInstSrcUnreachable *unreachable_instruction)
1927220261{
19273 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
19274 unreachable_instruction->base.scope, unreachable_instruction->base.source_node);
19275 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20262 IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base);
1927620263 return ir_finish_anal(ira, result);
1927720264}
1927820265
19279static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
20266static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_instruction) {
1928020267 Error err;
1928120268
1928220269 if (ira->const_predecessor_bb) {
1928320270 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
19284 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
20271 IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i];
1928520272 if (predecessor != ira->const_predecessor_bb)
1928620273 continue;
19287 IrInstruction *value = phi_instruction->incoming_values[i]->child;
20274 IrInstGen *value = phi_instruction->incoming_values[i]->child;
1928820275 assert(value->value->type);
1928920276 if (type_is_invalid(value->value->type))
19290 return ira->codegen->invalid_instruction;
20277 return ira->codegen->invalid_inst_gen;
1929120278
1929220279 if (value->value->special != ConstValSpecialRuntime) {
19293 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);
20280 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);
1929420281 copy_const_val(result->value, value->value);
1929520282 return result;
1929620283 } else {
......@@ -19305,17 +20292,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1930520292 peer_parent->peers.length >= 2)
1930620293 {
1930720294 if (peer_parent->resolved_type == nullptr) {
19308 IrInstruction **instructions = allocate<IrInstruction *>(peer_parent->peers.length);
20295 IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length);
1930920296 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
1931020297 ResultLocPeer *this_peer = peer_parent->peers.at(i);
1931120298
19312 IrInstruction *gen_instruction = this_peer->base.gen_instruction;
20299 IrInstGen *gen_instruction = this_peer->base.gen_instruction;
1931320300 if (gen_instruction == nullptr) {
1931420301 // unreachable instructions will cause implicit_elem_type to be null
1931520302 if (this_peer->base.implicit_elem_type == nullptr) {
19316 instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction);
20303 instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base);
1931720304 } else {
19318 instructions[i] = ir_const(ira, this_peer->base.source_instruction,
20305 instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base,
1931920306 this_peer->base.implicit_elem_type);
1932020307 instructions[i]->value->special = ConstValSpecialRuntime;
1932120308 }
......@@ -19324,34 +20311,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1932420311 }
1932520312
1932620313 }
19327 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base, peer_parent->parent);
20314 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent);
1932820315 peer_parent->resolved_type = ir_resolve_peer_types(ira,
19329 peer_parent->base.source_instruction->source_node, expected_type, instructions,
20316 peer_parent->base.source_instruction->base.source_node, expected_type, instructions,
1933020317 peer_parent->peers.length);
1933120318 if (type_is_invalid(peer_parent->resolved_type))
19332 return ira->codegen->invalid_instruction;
20319 return ira->codegen->invalid_inst_gen;
1933320320
1933420321 // the logic below assumes there are no instructions in the new current basic block yet
19335 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base);
20322 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base);
1933620323
1933720324 // In case resolving the parent activates a suspend, do it now
19338 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
20325 IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent,
1933920326 peer_parent->resolved_type, nullptr, false, false, true);
1934020327 if (parent_result_loc != nullptr &&
19341 (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc)))
20328 (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable))
1934220329 {
1934320330 return parent_result_loc;
1934420331 }
1934520332 // If the above code generated any instructions in the current basic block, we need
1934620333 // to move them to the peer parent predecessor.
19347 ZigList<IrInstruction *> instrs_to_move = {};
20334 ZigList<IrInstGen *> instrs_to_move = {};
1934820335 while (ira->new_irb.current_basic_block->instruction_list.length != 0) {
1934920336 instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());
1935020337 }
1935120338 if (instrs_to_move.length != 0) {
19352 IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb;
19353 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
19354 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base);
20339 IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb;
20340 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
20341 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base);
1935520342 while (instrs_to_move.length != 0) {
1935620343 predecessor->instruction_list.append(instrs_to_move.pop());
1935720344 }
......@@ -19360,7 +20347,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1936020347 }
1936120348
1936220349 IrSuspendPosition suspend_pos;
19363 ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos);
20350 ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos);
1936420351 ir_push_resume(ira, suspend_pos);
1936520352
1936620353 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
......@@ -19376,34 +20363,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1937620363 return ira_resume(ira);
1937720364 }
1937820365
19379 ZigList<IrBasicBlock*> new_incoming_blocks = {0};
19380 ZigList<IrInstruction*> new_incoming_values = {0};
20366 ZigList<IrBasicBlockGen*> new_incoming_blocks = {0};
20367 ZigList<IrInstGen*> new_incoming_values = {0};
1938120368
1938220369 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
19383 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
20370 IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i];
1938420371 if (predecessor->ref_count == 0)
1938520372 continue;
1938620373
1938720374
19388 IrInstruction *old_value = phi_instruction->incoming_values[i];
20375 IrInstSrc *old_value = phi_instruction->incoming_values[i];
1938920376 assert(old_value);
19390 IrInstruction *new_value = old_value->child;
19391 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)
20377 IrInstGen *new_value = old_value->child;
20378 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->child == nullptr)
1939220379 continue;
1939320380
1939420381 if (type_is_invalid(new_value->value->type))
19395 return ira->codegen->invalid_instruction;
20382 return ira->codegen->invalid_inst_gen;
1939620383
1939720384
19398 assert(predecessor->other);
19399 new_incoming_blocks.append(predecessor->other);
20385 assert(predecessor->child);
20386 new_incoming_blocks.append(predecessor->child);
1940020387 new_incoming_values.append(new_value);
1940120388 }
1940220389
1940320390 if (new_incoming_blocks.length == 0) {
19404 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
19405 phi_instruction->base.scope, phi_instruction->base.source_node);
19406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20391 IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base);
1940720392 return ir_finish_anal(ira, result);
1940820393 }
1940920394
......@@ -19415,7 +20400,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1941520400 if (peer_parent != nullptr) {
1941620401 bool peer_parent_has_type;
1941720402 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
19418 return ira->codegen->invalid_instruction;
20403 return ira->codegen->invalid_inst_gen;
1941920404 if (peer_parent_has_type) {
1942020405 if (peer_parent->parent->id == ResultLocIdReturn) {
1942120406 resolved_type = ira->explicit_return_type;
......@@ -19423,27 +20408,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1942320408 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
1942420409 } else if (peer_parent->parent->resolved_loc) {
1942520410 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;
19426 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
20411 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base);
1942720412 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
1942820413 }
1942920414
1943020415 if (resolved_type != nullptr && type_is_invalid(resolved_type))
19431 return ira->codegen->invalid_instruction;
20416 return ira->codegen->invalid_inst_gen;
1943220417 }
1943320418 }
1943420419
1943520420 if (resolved_type == nullptr) {
19436 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
20421 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr,
1943720422 new_incoming_values.items, new_incoming_values.length);
1943820423 if (type_is_invalid(resolved_type))
19439 return ira->codegen->invalid_instruction;
20424 return ira->codegen->invalid_inst_gen;
1944020425 }
1944120426
1944220427 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
1944320428 case OnePossibleValueInvalid:
19444 return ira->codegen->invalid_instruction;
20429 return ira->codegen->invalid_inst_gen;
1944520430 case OnePossibleValueYes:
19446 return ir_const_move(ira, &phi_instruction->base,
20431 return ir_const_move(ira, &phi_instruction->base.base,
1944720432 get_the_one_possible_value(ira->codegen, resolved_type));
1944820433 case OnePossibleValueNo:
1944920434 break;
......@@ -19451,11 +20436,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1945120436
1945220437 switch (type_requires_comptime(ira->codegen, resolved_type)) {
1945320438 case ReqCompTimeInvalid:
19454 return ira->codegen->invalid_instruction;
20439 return ira->codegen->invalid_inst_gen;
1945520440 case ReqCompTimeYes:
19456 ir_add_error_node(ira, phi_instruction->base.source_node,
20441 ir_add_error(ira, &phi_instruction->base.base,
1945720442 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));
19458 return ira->codegen->invalid_instruction;
20443 return ira->codegen->invalid_inst_gen;
1945920444 case ReqCompTimeNo:
1946020445 break;
1946120446 }
......@@ -19465,16 +20450,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1946520450 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
1946620451 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and
1946720452 // then make sure the branch instruction is preserved.
19468 IrBasicBlock *cur_bb = ira->new_irb.current_basic_block;
20453 IrBasicBlockGen *cur_bb = ira->new_irb.current_basic_block;
1946920454 for (size_t i = 0; i < new_incoming_values.length; i += 1) {
19470 IrInstruction *new_value = new_incoming_values.at(i);
19471 IrBasicBlock *predecessor = new_incoming_blocks.at(i);
19472 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base);
19473 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
19474 ir_set_cursor_at_end(&ira->new_irb, predecessor);
19475 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
20455 IrInstGen *new_value = new_incoming_values.at(i);
20456 IrBasicBlockGen *predecessor = new_incoming_blocks.at(i);
20457 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base);
20458 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
20459 ir_set_cursor_at_end_gen(&ira->new_irb, predecessor);
20460 IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
1947620461 if (type_is_invalid(casted_value->value->type)) {
19477 return ira->codegen->invalid_instruction;
20462 return ira->codegen->invalid_inst_gen;
1947820463 }
1947920464 new_incoming_values.items[i] = casted_value;
1948020465 predecessor->instruction_list.append(branch_instruction);
......@@ -19485,12 +20470,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1948520470 all_stack_ptrs = false;
1948620471 }
1948720472 }
19488 ir_set_cursor_at_end(&ira->new_irb, cur_bb);
20473 ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb);
1948920474
19490 IrInstruction *result = ir_build_phi(&ira->new_irb,
19491 phi_instruction->base.scope, phi_instruction->base.source_node,
19492 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr);
19493 result->value->type = resolved_type;
20475 IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base,
20476 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type);
1949420477
1949520478 if (all_stack_ptrs) {
1949620479 assert(result->value->special == ConstValSpecialRuntime);
......@@ -19500,17 +20483,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1950020483 return result;
1950120484}
1950220485
19503static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) {
20486static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) {
1950420487 ZigVar *var = instruction->var;
19505 IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var);
20488 IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var);
1950620489 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
19507 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
20490 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
1950820491 buf_sprintf("'%s' not accessible from inner function", var->name));
1950920492 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
1951020493 buf_sprintf("crossed function definition here"));
1951120494 add_error_note(ira->codegen, msg, var->decl_node,
1951220495 buf_sprintf("declared here"));
19513 return ira->codegen->invalid_instruction;
20496 return ira->codegen->invalid_inst_gen;
1951420497 }
1951520498 return result;
1951620499}
......@@ -19561,17 +20544,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
1956120544 ptr_type->data.pointer.allow_zero);
1956220545}
1956320546
19564static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
20547static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemPtr *elem_ptr_instruction) {
1956520548 Error err;
19566 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child;
20549 IrInstGen *array_ptr = elem_ptr_instruction->array_ptr->child;
1956720550 if (type_is_invalid(array_ptr->value->type))
19568 return ira->codegen->invalid_instruction;
20551 return ira->codegen->invalid_inst_gen;
1956920552
1957020553 ZigValue *orig_array_ptr_val = array_ptr->value;
1957120554
19572 IrInstruction *elem_index = elem_ptr_instruction->elem_index->child;
20555 IrInstGen *elem_index = elem_ptr_instruction->elem_index->child;
1957320556 if (type_is_invalid(elem_index->value->type))
19574 return ira->codegen->invalid_instruction;
20557 return ira->codegen->invalid_inst_gen;
1957520558
1957620559 ZigType *ptr_type = orig_array_ptr_val->type;
1957720560 assert(ptr_type->id == ZigTypeIdPointer);
......@@ -19583,7 +20566,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1958320566 ZigType *return_type;
1958420567
1958520568 if (type_is_invalid(array_type)) {
19586 return ira->codegen->invalid_instruction;
20569 return ira->codegen->invalid_inst_gen;
1958720570 } else if (array_type->id == ZigTypeIdArray ||
1958820571 (array_type->id == ZigTypeIdPointer &&
1958920572 array_type->data.pointer.ptr_len == PtrLenSingle &&
......@@ -19594,15 +20577,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1959420577 ptr_type = ptr_type->data.pointer.child_type;
1959520578 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
1959620579 orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
19597 elem_ptr_instruction->base.source_node);
20580 elem_ptr_instruction->base.base.source_node);
1959820581 if (orig_array_ptr_val == nullptr)
19599 return ira->codegen->invalid_instruction;
20582 return ira->codegen->invalid_inst_gen;
1960020583 }
1960120584 }
1960220585 if (array_type->data.array.len == 0) {
19603 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20586 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1960420587 buf_sprintf("index 0 outside array of size 0"));
19605 return ira->codegen->invalid_instruction;
20588 return ira->codegen->invalid_inst_gen;
1960620589 }
1960720590 ZigType *child_type = array_type->data.array.child_type;
1960820591 if (ptr_type->data.pointer.host_int_bytes == 0) {
......@@ -19613,7 +20596,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1961320596 } else {
1961420597 uint64_t elem_val_scalar;
1961520598 if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar))
19616 return ira->codegen->invalid_instruction;
20599 return ira->codegen->invalid_inst_gen;
1961720600
1961820601 size_t bit_width = type_size_bits(ira->codegen, child_type);
1961920602 size_t bit_offset = bit_width * elem_val_scalar;
......@@ -19625,9 +20608,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1962520608 }
1962620609 } else if (array_type->id == ZigTypeIdPointer) {
1962720610 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
19628 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20611 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1962920612 buf_sprintf("index of single-item pointer"));
19630 return ira->codegen->invalid_instruction;
20613 return ira->codegen->invalid_inst_gen;
1963120614 }
1963220615 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);
1963320616 } else if (is_slice(array_type)) {
......@@ -19641,38 +20624,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1964120624 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)
1964220625 {
1964320626 ZigType *usize = ira->codegen->builtin_types.entry_usize;
19644 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
20627 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
1964520628 if (type_is_invalid(casted_elem_index->value->type))
19646 return ira->codegen->invalid_instruction;
19647 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);
20629 return ira->codegen->invalid_inst_gen;
20630 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base);
1964820631 Buf *field_name = buf_alloc();
1964920632 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);
19650 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base,
20633 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base,
1965120634 array_ptr, array_type);
1965220635 } else if (is_tuple(array_type)) {
1965320636 uint64_t elem_index_scalar;
1965420637 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))
19655 return ira->codegen->invalid_instruction;
20638 return ira->codegen->invalid_inst_gen;
1965620639 if (elem_index_scalar >= array_type->data.structure.src_field_count) {
19657 ir_add_error(ira, &elem_ptr_instruction->base, buf_sprintf(
20640 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf(
1965820641 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",
1965920642 elem_index_scalar, buf_ptr(&array_type->name),
1966020643 array_type->data.structure.src_field_count));
19661 return ira->codegen->invalid_instruction;
20644 return ira->codegen->invalid_inst_gen;
1966220645 }
1966320646 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];
19664 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base, field, array_ptr,
20647 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr,
1966520648 array_type, false);
1966620649 } else {
19667 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20650 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1966820651 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
19669 return ira->codegen->invalid_instruction;
20652 return ira->codegen->invalid_inst_gen;
1967020653 }
1967120654
1967220655 ZigType *usize = ira->codegen->builtin_types.entry_usize;
19673 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
19674 if (casted_elem_index == ira->codegen->invalid_instruction)
19675 return ira->codegen->invalid_instruction;
20656 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
20657 if (type_is_invalid(casted_elem_index->value->type))
20658 return ira->codegen->invalid_inst_gen;
1967620659
1967720660 bool safety_check_on = elem_ptr_instruction->safety_check_on;
1967820661 if (instr_is_comptime(casted_elem_index)) {
......@@ -19681,15 +20664,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1968120664 uint64_t array_len = array_type->data.array.len;
1968220665 if (index == array_len && array_type->data.array.sentinel != nullptr) {
1968320666 ZigType *elem_type = array_type->data.array.child_type;
19684 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);
20667 IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);
1968520668 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);
19686 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);
20669 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
1968720670 }
1968820671 if (index >= array_len) {
19689 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20672 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1969020673 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
1969120674 index, array_len));
19692 return ira->codegen->invalid_instruction;
20675 return ira->codegen->invalid_inst_gen;
1969320676 }
1969420677 safety_check_on = false;
1969520678 }
......@@ -19705,7 +20688,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1970520688 // figure out the largest alignment possible
1970620689
1970720690 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))
19708 return ira->codegen->invalid_instruction;
20691 return ira->codegen->invalid_inst_gen;
1970920692
1971020693 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
1971120694 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
......@@ -19735,9 +20718,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1973520718 array_type->id == ZigTypeIdArray))
1973620719 {
1973720720 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
19738 elem_ptr_instruction->base.source_node);
20721 elem_ptr_instruction->base.base.source_node);
1973920722 if (array_ptr_val == nullptr)
19740 return ira->codegen->invalid_instruction;
20723 return ira->codegen->invalid_inst_gen;
1974120724
1974220725 if (array_ptr_val->special == ConstValSpecialUndef &&
1974320726 elem_ptr_instruction->init_array_type_source_node != nullptr)
......@@ -19755,16 +20738,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1975520738 elem_val->parent.data.p_array.elem_index = i;
1975620739 }
1975720740 } else if (is_slice(array_type)) {
19758 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base);
20741 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base);
1975920742 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1976020743
1976120744 if (type_is_invalid(actual_array_type))
19762 return ira->codegen->invalid_instruction;
20745 return ira->codegen->invalid_inst_gen;
1976320746 if (actual_array_type->id != ZigTypeIdArray) {
1976420747 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
1976520748 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
1976620749 buf_ptr(&actual_array_type->name)));
19767 return ira->codegen->invalid_instruction;
20750 return ira->codegen->invalid_inst_gen;
1976820751 }
1976920752
1977020753 ZigValue *array_init_val = create_const_vals(1);
......@@ -19789,7 +20772,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1978920772 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
1979020773 buf_sprintf("expected array type or [_], found '%s'",
1979120774 buf_ptr(&array_type->name)));
19792 return ira->codegen->invalid_instruction;
20775 return ira->codegen->invalid_inst_gen;
1979320776 }
1979420777 }
1979520778
......@@ -19798,7 +20781,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1979820781 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
1979920782 {
1980020783 if (array_type->id == ZigTypeIdPointer) {
19801 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
20784 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
1980220785 ZigValue *out_val = result->value;
1980320786 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
1980420787 size_t new_index;
......@@ -19867,33 +20850,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1986720850 zig_panic("TODO elem ptr on a null pointer");
1986820851 }
1986920852 if (new_index >= mem_size) {
19870 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20853 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1987120854 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
19872 return ira->codegen->invalid_instruction;
20855 return ira->codegen->invalid_inst_gen;
1987320856 }
1987420857 return result;
1987520858 } else if (is_slice(array_type)) {
1987620859 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
19877 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
20860 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base);
1987820861 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
19879 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
19880 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
19881 elem_ptr_instruction->ptr_len, nullptr);
19882 result->value->type = return_type;
19883 return result;
20862 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20863 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false,
20864 return_type);
1988420865 }
1988520866 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
19886 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
20867 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
1988720868 ZigValue *out_val = result->value;
1988820869 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
1988920870 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
1989020871 uint64_t full_slice_len = slice_len +
1989120872 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);
1989220873 if (index >= full_slice_len) {
19893 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20874 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1989420875 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
1989520876 index, slice_len));
19896 return ira->codegen->invalid_instruction;
20877 return ira->codegen->invalid_inst_gen;
1989720878 }
1989820879 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
1989920880 switch (ptr_field->data.x_ptr.special) {
......@@ -19913,7 +20894,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1991320894 {
1991420895 ir_assert(new_index <
1991520896 ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len,
19916 &elem_ptr_instruction->base);
20897 &elem_ptr_instruction->base.base);
1991720898 }
1991820899 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
1991920900 out_val->data.x_ptr.data.base_array.array_val =
......@@ -19938,15 +20919,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1993820919 }
1993920920 return result;
1994020921 } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
19941 IrInstruction *result;
20922 IrInstGen *result;
1994220923 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
19943 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
19944 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
19945 false, elem_ptr_instruction->ptr_len, nullptr);
19946 result->value->type = return_type;
20924 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20925 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index,
20926 false, return_type);
1994720927 result->value->special = ConstValSpecialStatic;
1994820928 } else {
19949 result = ir_const(ira, &elem_ptr_instruction->base, return_type);
20929 result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
1995020930 }
1995120931 ZigValue *out_val = result->value;
1995220932 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
......@@ -19972,19 +20952,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1997220952 // runtime known element index
1997320953 switch (type_requires_comptime(ira->codegen, return_type)) {
1997420954 case ReqCompTimeYes:
19975 ir_add_error(ira, elem_index,
20955 ir_add_error(ira, &elem_index->base,
1997620956 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",
1997720957 buf_ptr(&return_type->data.pointer.child_type->name)));
19978 return ira->codegen->invalid_instruction;
20958 return ira->codegen->invalid_inst_gen;
1997920959 case ReqCompTimeInvalid:
19980 return ira->codegen->invalid_instruction;
20960 return ira->codegen->invalid_inst_gen;
1998120961 case ReqCompTimeNo:
1998220962 break;
1998320963 }
1998420964
1998520965 if (return_type->data.pointer.explicit_alignment != 0) {
1998620966 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))
19987 return ira->codegen->invalid_instruction;
20967 return ira->codegen->invalid_inst_gen;
1998820968
1998920969 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
1999020970 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
......@@ -20002,16 +20982,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
2000220982 }
2000320983 }
2000420984
20005 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
20006 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,
20007 elem_ptr_instruction->ptr_len, nullptr);
20008 result->value->type = return_type;
20009 return result;
20985 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20986 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);
2001020987}
2001120988
20012static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20013 ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr,
20014 IrInstruction *container_ptr, ZigType *container_type)
20989static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20990 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,
20991 IrInstGen *container_ptr, ZigType *container_type)
2001520992{
2001620993 if (!is_slice(bare_struct_type)) {
2001720994 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
......@@ -20021,29 +20998,27 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2002120998 if (tld->id == TldIdFn) {
2002220999 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
2002321000 if (tld->resolution == TldResolutionInvalid)
20024 return ira->codegen->invalid_instruction;
21001 return ira->codegen->invalid_inst_gen;
2002521002 TldFn *tld_fn = (TldFn *)tld;
2002621003 ZigFn *fn_entry = tld_fn->fn_entry;
2002721004 if (type_is_invalid(fn_entry->type_entry))
20028 return ira->codegen->invalid_instruction;
21005 return ira->codegen->invalid_inst_gen;
2002921006
20030 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope,
20031 source_instr->source_node, fn_entry, container_ptr);
21007 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr);
2003221008 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
2003321009 } else if (tld->id == TldIdVar) {
2003421010 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
2003521011 if (tld->resolution == TldResolutionInvalid)
20036 return ira->codegen->invalid_instruction;
21012 return ira->codegen->invalid_inst_gen;
2003721013 TldVar *tld_var = (TldVar *)tld;
2003821014 ZigVar *var = tld_var->var;
2003921015 if (type_is_invalid(var->var_type))
20040 return ira->codegen->invalid_instruction;
21016 return ira->codegen->invalid_inst_gen;
2004121017
2004221018 if (var->const_value->type->id == ZigTypeIdFn) {
2004321019 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
2004421020 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;
20045 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope,
20046 source_instr->source_node, fn, container_ptr);
21021 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr);
2004721022 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
2004821023 }
2004921024 }
......@@ -20063,7 +21038,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2006321038 }
2006421039 ir_add_error_node(ira, source_instr->source_node,
2006521040 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));
20066 return ira->codegen->invalid_instruction;
21041 return ira->codegen->invalid_inst_gen;
2006721042}
2006821043
2006921044static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field) {
......@@ -20078,24 +21053,24 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty
2007821053 field->type_entry, nullptr, UndefOk);
2007921054}
2008021055
20081static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,
20082 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing)
21056static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
21057 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing)
2008321058{
2008421059 Error err;
2008521060 ZigType *field_type = resolve_struct_field_type(ira->codegen, field);
2008621061 if (field_type == nullptr)
20087 return ira->codegen->invalid_instruction;
21062 return ira->codegen->invalid_inst_gen;
2008821063 if (field->is_comptime) {
20089 IrInstruction *elem = ir_const(ira, source_instr, field_type);
21064 IrInstGen *elem = ir_const(ira, source_instr, field_type);
2009021065 memoize_field_init_val(ira->codegen, struct_type, field);
2009121066 copy_const_val(elem->value, field->init_val);
2009221067 return ir_get_ref(ira, source_instr, elem, true, false);
2009321068 }
2009421069 switch (type_has_one_possible_value(ira->codegen, field_type)) {
2009521070 case OnePossibleValueInvalid:
20096 return ira->codegen->invalid_instruction;
21071 return ira->codegen->invalid_inst_gen;
2009721072 case OnePossibleValueYes: {
20098 IrInstruction *elem = ir_const_move(ira, source_instr,
21073 IrInstGen *elem = ir_const_move(ira, source_instr,
2009921074 get_the_one_possible_value(ira->codegen, field_type));
2010021075 return ir_get_ref(ira, source_instr, elem, false, false);
2010121076 }
......@@ -20113,7 +21088,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2011321088 (struct_type->data.structure.layout == ContainerLayoutAuto) ?
2011421089 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
2011521090 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
20116 return ira->codegen->invalid_instruction;
21091 return ira->codegen->invalid_inst_gen;
2011721092 assert(struct_ptr->value->type->id == ZigTypeIdPointer);
2011821093 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;
2011921094 uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes;
......@@ -20127,14 +21102,14 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2012721102 if (instr_is_comptime(struct_ptr)) {
2012821103 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);
2012921104 if (!ptr_val)
20130 return ira->codegen->invalid_instruction;
21105 return ira->codegen->invalid_inst_gen;
2013121106
2013221107 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
2013321108 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2013421109 if (struct_val == nullptr)
20135 return ira->codegen->invalid_instruction;
21110 return ira->codegen->invalid_inst_gen;
2013621111 if (type_is_invalid(struct_val->type))
20137 return ira->codegen->invalid_instruction;
21112 return ira->codegen->invalid_inst_gen;
2013821113 if (initializing && struct_val->special == ConstValSpecialUndef) {
2013921114 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
2014021115 struct_val->special = ConstValSpecialStatic;
......@@ -20148,11 +21123,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2014821123 field_val->parent.data.p_struct.field_index = i;
2014921124 }
2015021125 }
20151 IrInstruction *result;
21126 IrInstGen *result;
2015221127 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20153 result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope,
20154 source_instr->source_node, struct_ptr, field);
20155 result->value->type = ptr_type;
21128 result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
2015621129 result->value->special = ConstValSpecialStatic;
2015721130 } else {
2015821131 result = ir_const(ira, source_instr, ptr_type);
......@@ -20165,14 +21138,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2016521138 return result;
2016621139 }
2016721140 }
20168 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,
20169 struct_ptr, field);
20170 result->value->type = ptr_type;
20171 return result;
21141 return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
2017221142}
2017321143
20174static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
20175 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)
21144static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
21145 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type)
2017621146{
2017721147 // The type of the field is not available until a store using this pointer happens.
2017821148 // So, here we create a special pointer type which has the inferred struct type and
......@@ -20195,12 +21165,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
2019521165 if (instr_is_comptime(container_ptr)) {
2019621166 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
2019721167 if (ptr_val == nullptr)
20198 return ira->codegen->invalid_instruction;
21168 return ira->codegen->invalid_inst_gen;
2019921169
20200 IrInstruction *result;
21170 IrInstGen *result;
2020121171 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20202 result = ir_build_cast(&ira->new_irb, source_instr->scope,
20203 source_instr->source_node, container_ptr_type, container_ptr, CastOpNoop);
21172 result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop);
2020421173 } else {
2020521174 result = ir_const(ira, source_instr, field_ptr_type);
2020621175 }
......@@ -20209,14 +21178,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
2020921178 return result;
2021021179 }
2021121180
20212 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,
20213 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);
20214 result->value->type = field_ptr_type;
20215 return result;
21181 return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop);
2021621182}
2021721183
20218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
20219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing)
21184static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
21185 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing)
2022021186{
2022121187 Error err;
2022221188
......@@ -20229,7 +21195,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2022921195 }
2023021196
2023121197 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
20232 return ira->codegen->invalid_instruction;
21198 return ira->codegen->invalid_inst_gen;
2023321199
2023421200 assert(container_ptr->value->type->id == ZigTypeIdPointer);
2023521201 if (bare_type->id == ZigTypeIdStruct) {
......@@ -20259,22 +21225,22 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2025921225
2026021226 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
2026121227 if (field_type == nullptr)
20262 return ira->codegen->invalid_instruction;
21228 return ira->codegen->invalid_inst_gen;
2026321229
2026421230 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
2026521231 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
2026621232 if (instr_is_comptime(container_ptr)) {
2026721233 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
2026821234 if (!ptr_val)
20269 return ira->codegen->invalid_instruction;
21235 return ira->codegen->invalid_inst_gen;
2027021236
2027121237 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
2027221238 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
2027321239 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2027421240 if (union_val == nullptr)
20275 return ira->codegen->invalid_instruction;
21241 return ira->codegen->invalid_inst_gen;
2027621242 if (type_is_invalid(union_val->type))
20277 return ira->codegen->invalid_instruction;
21243 return ira->codegen->invalid_inst_gen;
2027821244
2027921245 if (initializing) {
2028021246 ZigValue *payload_val = create_const_vals(1);
......@@ -20295,17 +21261,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2029521261 ir_add_error_node(ira, source_instr->source_node,
2029621262 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),
2029721263 buf_ptr(actual_field->name)));
20298 return ira->codegen->invalid_instruction;
21264 return ira->codegen->invalid_inst_gen;
2029921265 }
2030021266 }
2030121267
2030221268 ZigValue *payload_val = union_val->data.x_union.payload;
2030321269
20304 IrInstruction *result;
21270 IrInstGen *result;
2030521271 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20306 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
20307 source_instr->source_node, container_ptr, field, true, initializing);
20308 result->value->type = ptr_type;
21272 result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true,
21273 initializing, ptr_type);
2030921274 result->value->special = ConstValSpecialStatic;
2031021275 } else {
2031121276 result = ir_const(ira, source_instr, ptr_type);
......@@ -20318,10 +21283,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2031821283 }
2031921284 }
2032021285
20321 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
20322 source_instr->source_node, container_ptr, field, true, initializing);
20323 result->value->type = ptr_type;
20324 return result;
21286 return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type);
2032521287 }
2032621288
2032721289 zig_unreachable();
......@@ -20362,15 +21324,15 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
2036221324 link_lib->symbols.append(symbol_name);
2036321325}
2036421326
20365static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {
21327static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {
2036621328 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
20367 return ira->codegen->invalid_instruction;
21329 return ira->codegen->invalid_inst_gen;
2036821330}
2036921331
20370static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
21332static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) {
2037121333 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);
2037221334 if (tld->resolution == TldResolutionInvalid) {
20373 return ira->codegen->invalid_instruction;
21335 return ira->codegen->invalid_inst_gen;
2037421336 }
2037521337
2037621338 switch (tld->id) {
......@@ -20397,14 +21359,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
2039721359 assert(fn_entry->type_entry);
2039821360
2039921361 if (type_is_invalid(fn_entry->type_entry))
20400 return ira->codegen->invalid_instruction;
21362 return ira->codegen->invalid_inst_gen;
2040121363
2040221364 if (tld_fn->extern_lib_name != nullptr) {
2040321365 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);
2040421366 }
2040521367
20406 IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope,
20407 source_instruction->source_node, fn_entry);
21368 IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry);
2040821369 return ir_get_ref(ira, source_instruction, fn_inst, true, false);
2040921370 }
2041021371 }
......@@ -20422,40 +21383,40 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n
2042221383 return nullptr;
2042321384}
2042421385
20425static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
21386static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFieldPtr *field_ptr_instruction) {
2042621387 Error err;
20427 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child;
21388 IrInstGen *container_ptr = field_ptr_instruction->container_ptr->child;
2042821389 if (type_is_invalid(container_ptr->value->type))
20429 return ira->codegen->invalid_instruction;
21390 return ira->codegen->invalid_inst_gen;
2043021391
2043121392 ZigType *container_type = container_ptr->value->type->data.pointer.child_type;
2043221393
2043321394 Buf *field_name = field_ptr_instruction->field_name_buffer;
2043421395 if (!field_name) {
20435 IrInstruction *field_name_expr = field_ptr_instruction->field_name_expr->child;
21396 IrInstGen *field_name_expr = field_ptr_instruction->field_name_expr->child;
2043621397 field_name = ir_resolve_str(ira, field_name_expr);
2043721398 if (!field_name)
20438 return ira->codegen->invalid_instruction;
21399 return ira->codegen->invalid_inst_gen;
2043921400 }
2044021401
2044121402
20442 AstNode *source_node = field_ptr_instruction->base.source_node;
21403 AstNode *source_node = field_ptr_instruction->base.base.source_node;
2044321404
2044421405 if (type_is_invalid(container_type)) {
20445 return ira->codegen->invalid_instruction;
21406 return ira->codegen->invalid_inst_gen;
2044621407 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {
20447 IrInstruction *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base,
21408 IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base,
2044821409 container_type->data.structure.src_field_count);
20449 return ir_get_ref(ira, &field_ptr_instruction->base, len_inst, true, false);
21410 return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false);
2045021411 } else if (is_slice(container_type) || is_container_ref(container_type)) {
2045121412 assert(container_ptr->value->type->id == ZigTypeIdPointer);
2045221413 if (container_type->id == ZigTypeIdPointer) {
2045321414 ZigType *bare_type = container_ref_type(container_type);
20454 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr);
20455 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type, field_ptr_instruction->initializing);
21415 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr);
21416 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_child, bare_type, field_ptr_instruction->initializing);
2045621417 return result;
2045721418 } else {
20458 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);
21419 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_ptr, container_type, field_ptr_instruction->initializing);
2045921420 return result;
2046021421 }
2046121422 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
......@@ -20470,42 +21431,42 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2047021431 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2047121432 bool ptr_is_const = true;
2047221433 bool ptr_is_volatile = false;
20473 return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val,
21434 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val,
2047421435 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2047521436 } else {
2047621437 ir_add_error_node(ira, source_node,
2047721438 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
2047821439 buf_ptr(&container_type->name)));
20479 return ira->codegen->invalid_instruction;
21440 return ira->codegen->invalid_inst_gen;
2048021441 }
2048121442 } else if (container_type->id == ZigTypeIdMetaType) {
2048221443 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
2048321444 if (!container_ptr_val)
20484 return ira->codegen->invalid_instruction;
21445 return ira->codegen->invalid_inst_gen;
2048521446
2048621447 assert(container_ptr->value->type->id == ZigTypeIdPointer);
2048721448 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
2048821449 if (child_val == nullptr)
20489 return ira->codegen->invalid_instruction;
21450 return ira->codegen->invalid_inst_gen;
2049021451 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
20491 field_ptr_instruction->base.source_node, child_val, UndefBad)))
21452 field_ptr_instruction->base.base.source_node, child_val, UndefBad)))
2049221453 {
20493 return ira->codegen->invalid_instruction;
21454 return ira->codegen->invalid_inst_gen;
2049421455 }
2049521456 ZigType *child_type = child_val->data.x_type;
2049621457
2049721458 if (type_is_invalid(child_type)) {
20498 return ira->codegen->invalid_instruction;
21459 return ira->codegen->invalid_inst_gen;
2049921460 } else if (is_container(child_type)) {
2050021461 if (child_type->id == ZigTypeIdEnum) {
2050121462 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20502 return ira->codegen->invalid_instruction;
21463 return ira->codegen->invalid_inst_gen;
2050321464
2050421465 TypeEnumField *field = find_enum_type_field(child_type, field_name);
2050521466 if (field) {
2050621467 bool ptr_is_const = true;
2050721468 bool ptr_is_volatile = false;
20508 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21469 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2050921470 create_const_enum(child_type, &field->value), child_type,
2051021471 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2051121472 }
......@@ -20514,37 +21475,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2051421475 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
2051521476 if (tld) {
2051621477 if (tld->visib_mod == VisibModPrivate &&
20517 tld->import != get_scope_import(field_ptr_instruction->base.scope))
21478 tld->import != get_scope_import(field_ptr_instruction->base.base.scope))
2051821479 {
20519 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base,
21480 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base,
2052021481 buf_sprintf("'%s' is private", buf_ptr(field_name)));
2052121482 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
20522 return ira->codegen->invalid_instruction;
21483 return ira->codegen->invalid_inst_gen;
2052321484 }
20524 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
21485 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld);
2052521486 }
2052621487 if (child_type->id == ZigTypeIdUnion &&
2052721488 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
2052821489 child_type->data.unionation.decl_node->data.container_decl.auto_enum))
2052921490 {
2053021491 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20531 return ira->codegen->invalid_instruction;
21492 return ira->codegen->invalid_inst_gen;
2053221493 TypeUnionField *field = find_union_type_field(child_type, field_name);
2053321494 if (field) {
2053421495 ZigType *enum_type = child_type->data.unionation.tag_type;
2053521496 bool ptr_is_const = true;
2053621497 bool ptr_is_volatile = false;
20537 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21498 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2053821499 create_const_enum(enum_type, &field->enum_field->value), enum_type,
2053921500 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2054021501 }
2054121502 }
2054221503 const char *container_name = (child_type == ira->codegen->root_import) ?
2054321504 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));
20544 ir_add_error(ira, &field_ptr_instruction->base,
21505 ir_add_error(ira, &field_ptr_instruction->base.base,
2054521506 buf_sprintf("%s has no member called '%s'",
2054621507 container_name, buf_ptr(field_name)));
20547 return ira->codegen->invalid_instruction;
21508 return ira->codegen->invalid_inst_gen;
2054821509 } else if (child_type->id == ZigTypeIdErrorSet) {
2054921510 ErrorTableEntry *err_entry;
2055021511 ZigType *err_set_type;
......@@ -20554,7 +21515,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2055421515 err_entry = existing_entry->value;
2055521516 } else {
2055621517 err_entry = allocate<ErrorTableEntry>(1);
20557 err_entry->decl_node = field_ptr_instruction->base.source_node;
21518 err_entry->decl_node = field_ptr_instruction->base.base.source_node;
2055821519 buf_init_from_buf(&err_entry->name, field_name);
2055921520 size_t error_value_count = ira->codegen->errors_by_index.length;
2056021521 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));
......@@ -20564,19 +21525,19 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2056421525 }
2056521526 if (err_entry->set_with_only_this_in_it == nullptr) {
2056621527 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,
20567 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
21528 field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node,
2056821529 err_entry);
2056921530 }
2057021531 err_set_type = err_entry->set_with_only_this_in_it;
2057121532 } else {
20572 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) {
20573 return ira->codegen->invalid_instruction;
21533 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) {
21534 return ira->codegen->invalid_inst_gen;
2057421535 }
2057521536 err_entry = find_err_table_entry(child_type, field_name);
2057621537 if (err_entry == nullptr) {
20577 ir_add_error(ira, &field_ptr_instruction->base,
21538 ir_add_error(ira, &field_ptr_instruction->base.base,
2057821539 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));
20579 return ira->codegen->invalid_instruction;
21540 return ira->codegen->invalid_inst_gen;
2058021541 }
2058121542 err_set_type = child_type;
2058221543 }
......@@ -20587,13 +21548,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2058721548
2058821549 bool ptr_is_const = true;
2058921550 bool ptr_is_volatile = false;
20590 return ir_get_const_ptr(ira, &field_ptr_instruction->base, const_val,
21551 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val,
2059121552 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2059221553 } else if (child_type->id == ZigTypeIdInt) {
2059321554 if (buf_eql_str(field_name, "bit_count")) {
2059421555 bool ptr_is_const = true;
2059521556 bool ptr_is_volatile = false;
20596 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21557 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2059721558 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2059821559 child_type->data.integral.bit_count, false),
2059921560 ira->codegen->builtin_types.entry_num_lit_int,
......@@ -20601,36 +21562,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2060121562 } else if (buf_eql_str(field_name, "is_signed")) {
2060221563 bool ptr_is_const = true;
2060321564 bool ptr_is_volatile = false;
20604 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21565 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2060521566 create_const_bool(ira->codegen, child_type->data.integral.is_signed),
2060621567 ira->codegen->builtin_types.entry_bool,
2060721568 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2060821569 } else {
20609 ir_add_error(ira, &field_ptr_instruction->base,
21570 ir_add_error(ira, &field_ptr_instruction->base.base,
2061021571 buf_sprintf("type '%s' has no member called '%s'",
2061121572 buf_ptr(&child_type->name), buf_ptr(field_name)));
20612 return ira->codegen->invalid_instruction;
21573 return ira->codegen->invalid_inst_gen;
2061321574 }
2061421575 } else if (child_type->id == ZigTypeIdFloat) {
2061521576 if (buf_eql_str(field_name, "bit_count")) {
2061621577 bool ptr_is_const = true;
2061721578 bool ptr_is_volatile = false;
20618 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21579 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2061921580 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2062021581 child_type->data.floating.bit_count, false),
2062121582 ira->codegen->builtin_types.entry_num_lit_int,
2062221583 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2062321584 } else {
20624 ir_add_error(ira, &field_ptr_instruction->base,
21585 ir_add_error(ira, &field_ptr_instruction->base.base,
2062521586 buf_sprintf("type '%s' has no member called '%s'",
2062621587 buf_ptr(&child_type->name), buf_ptr(field_name)));
20627 return ira->codegen->invalid_instruction;
21588 return ira->codegen->invalid_inst_gen;
2062821589 }
2062921590 } else if (child_type->id == ZigTypeIdPointer) {
2063021591 if (buf_eql_str(field_name, "Child")) {
2063121592 bool ptr_is_const = true;
2063221593 bool ptr_is_volatile = false;
20633 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21594 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2063421595 create_const_type(ira->codegen, child_type->data.pointer.child_type),
2063521596 ira->codegen->builtin_types.entry_type,
2063621597 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -20640,75 +21601,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2064021601 if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type,
2064121602 ResolveStatusAlignmentKnown)))
2064221603 {
20643 return ira->codegen->invalid_instruction;
21604 return ira->codegen->invalid_inst_gen;
2064421605 }
20645 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21606 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2064621607 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2064721608 get_ptr_align(ira->codegen, child_type), false),
2064821609 ira->codegen->builtin_types.entry_num_lit_int,
2064921610 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2065021611 } else {
20651 ir_add_error(ira, &field_ptr_instruction->base,
21612 ir_add_error(ira, &field_ptr_instruction->base.base,
2065221613 buf_sprintf("type '%s' has no member called '%s'",
2065321614 buf_ptr(&child_type->name), buf_ptr(field_name)));
20654 return ira->codegen->invalid_instruction;
21615 return ira->codegen->invalid_inst_gen;
2065521616 }
2065621617 } else if (child_type->id == ZigTypeIdArray) {
2065721618 if (buf_eql_str(field_name, "Child")) {
2065821619 bool ptr_is_const = true;
2065921620 bool ptr_is_volatile = false;
20660 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21621 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2066121622 create_const_type(ira->codegen, child_type->data.array.child_type),
2066221623 ira->codegen->builtin_types.entry_type,
2066321624 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2066421625 } else if (buf_eql_str(field_name, "len")) {
2066521626 bool ptr_is_const = true;
2066621627 bool ptr_is_volatile = false;
20667 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21628 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2066821629 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2066921630 child_type->data.array.len, false),
2067021631 ira->codegen->builtin_types.entry_num_lit_int,
2067121632 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2067221633 } else {
20673 ir_add_error(ira, &field_ptr_instruction->base,
21634 ir_add_error(ira, &field_ptr_instruction->base.base,
2067421635 buf_sprintf("type '%s' has no member called '%s'",
2067521636 buf_ptr(&child_type->name), buf_ptr(field_name)));
20676 return ira->codegen->invalid_instruction;
21637 return ira->codegen->invalid_inst_gen;
2067721638 }
2067821639 } else if (child_type->id == ZigTypeIdErrorUnion) {
2067921640 if (buf_eql_str(field_name, "Payload")) {
2068021641 bool ptr_is_const = true;
2068121642 bool ptr_is_volatile = false;
20682 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21643 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2068321644 create_const_type(ira->codegen, child_type->data.error_union.payload_type),
2068421645 ira->codegen->builtin_types.entry_type,
2068521646 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2068621647 } else if (buf_eql_str(field_name, "ErrorSet")) {
2068721648 bool ptr_is_const = true;
2068821649 bool ptr_is_volatile = false;
20689 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21650 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2069021651 create_const_type(ira->codegen, child_type->data.error_union.err_set_type),
2069121652 ira->codegen->builtin_types.entry_type,
2069221653 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2069321654 } else {
20694 ir_add_error(ira, &field_ptr_instruction->base,
21655 ir_add_error(ira, &field_ptr_instruction->base.base,
2069521656 buf_sprintf("type '%s' has no member called '%s'",
2069621657 buf_ptr(&child_type->name), buf_ptr(field_name)));
20697 return ira->codegen->invalid_instruction;
21658 return ira->codegen->invalid_inst_gen;
2069821659 }
2069921660 } else if (child_type->id == ZigTypeIdOptional) {
2070021661 if (buf_eql_str(field_name, "Child")) {
2070121662 bool ptr_is_const = true;
2070221663 bool ptr_is_volatile = false;
20703 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21664 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2070421665 create_const_type(ira->codegen, child_type->data.maybe.child_type),
2070521666 ira->codegen->builtin_types.entry_type,
2070621667 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2070721668 } else {
20708 ir_add_error(ira, &field_ptr_instruction->base,
21669 ir_add_error(ira, &field_ptr_instruction->base.base,
2070921670 buf_sprintf("type '%s' has no member called '%s'",
2071021671 buf_ptr(&child_type->name), buf_ptr(field_name)));
20711 return ira->codegen->invalid_instruction;
21672 return ira->codegen->invalid_inst_gen;
2071221673 }
2071321674 } else if (child_type->id == ZigTypeIdFn) {
2071421675 if (buf_eql_str(field_name, "ReturnType")) {
......@@ -20716,121 +21677,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2071621677 // Return type can only ever be null, if the function is generic
2071721678 assert(child_type->data.fn.is_generic);
2071821679
20719 ir_add_error(ira, &field_ptr_instruction->base,
21680 ir_add_error(ira, &field_ptr_instruction->base.base,
2072021681 buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name)));
20721 return ira->codegen->invalid_instruction;
21682 return ira->codegen->invalid_inst_gen;
2072221683 }
2072321684
2072421685 bool ptr_is_const = true;
2072521686 bool ptr_is_volatile = false;
20726 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21687 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2072721688 create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type),
2072821689 ira->codegen->builtin_types.entry_type,
2072921690 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2073021691 } else if (buf_eql_str(field_name, "is_var_args")) {
2073121692 bool ptr_is_const = true;
2073221693 bool ptr_is_volatile = false;
20733 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21694 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2073421695 create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args),
2073521696 ira->codegen->builtin_types.entry_bool,
2073621697 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2073721698 } else if (buf_eql_str(field_name, "arg_count")) {
2073821699 bool ptr_is_const = true;
2073921700 bool ptr_is_volatile = false;
20740 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21701 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2074121702 create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count),
2074221703 ira->codegen->builtin_types.entry_usize,
2074321704 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2074421705 } else {
20745 ir_add_error(ira, &field_ptr_instruction->base,
21706 ir_add_error(ira, &field_ptr_instruction->base.base,
2074621707 buf_sprintf("type '%s' has no member called '%s'",
2074721708 buf_ptr(&child_type->name), buf_ptr(field_name)));
20748 return ira->codegen->invalid_instruction;
21709 return ira->codegen->invalid_inst_gen;
2074921710 }
2075021711 } else {
20751 ir_add_error(ira, &field_ptr_instruction->base,
21712 ir_add_error(ira, &field_ptr_instruction->base.base,
2075221713 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
20753 return ira->codegen->invalid_instruction;
21714 return ira->codegen->invalid_inst_gen;
2075421715 }
2075521716 } else if (field_ptr_instruction->initializing) {
20756 ir_add_error(ira, &field_ptr_instruction->base,
21717 ir_add_error(ira, &field_ptr_instruction->base.base,
2075721718 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));
20758 return ira->codegen->invalid_instruction;
21719 return ira->codegen->invalid_inst_gen;
2075921720 } else {
20760 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
21721 ir_add_error_node(ira, field_ptr_instruction->base.base.source_node,
2076121722 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
20762 return ira->codegen->invalid_instruction;
21723 return ira->codegen->invalid_inst_gen;
2076321724 }
2076421725}
2076521726
20766static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) {
20767 IrInstruction *ptr = instruction->ptr->child;
21727static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStorePtr *instruction) {
21728 IrInstGen *ptr = instruction->ptr->child;
2076821729 if (type_is_invalid(ptr->value->type))
20769 return ira->codegen->invalid_instruction;
21730 return ira->codegen->invalid_inst_gen;
2077021731
20771 IrInstruction *value = instruction->value->child;
21732 IrInstGen *value = instruction->value->child;
2077221733 if (type_is_invalid(value->value->type))
20773 return ira->codegen->invalid_instruction;
21734 return ira->codegen->invalid_inst_gen;
2077421735
20775 return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const);
21736 return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const);
2077621737}
2077721738
20778static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) {
20779 IrInstruction *ptr = instruction->ptr->child;
21739static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) {
21740 IrInstGen *ptr = instruction->ptr->child;
2078021741 if (type_is_invalid(ptr->value->type))
20781 return ira->codegen->invalid_instruction;
20782 return ir_get_deref(ira, &instruction->base, ptr, nullptr);
21742 return ira->codegen->invalid_inst_gen;
21743 return ir_get_deref(ira, &instruction->base.base, ptr, nullptr);
2078321744}
2078421745
20785static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
20786 IrInstruction *expr_value = typeof_instruction->value->child;
21746static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) {
21747 IrInstGen *expr_value = typeof_instruction->value->child;
2078721748 ZigType *type_entry = expr_value->value->type;
2078821749 if (type_is_invalid(type_entry))
20789 return ira->codegen->invalid_instruction;
20790 return ir_const_type(ira, &typeof_instruction->base, type_entry);
21750 return ira->codegen->invalid_inst_gen;
21751 return ir_const_type(ira, &typeof_instruction->base.base, type_entry);
2079121752}
2079221753
20793static IrInstruction *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {
21754static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) {
2079421755 if (ira->new_irb.exec->is_inline) {
2079521756 // ignore setCold when running functions at compile time
20796 return ir_const_void(ira, &instruction->base);
21757 return ir_const_void(ira, &instruction->base.base);
2079721758 }
2079821759
20799 IrInstruction *is_cold_value = instruction->is_cold->child;
21760 IrInstGen *is_cold_value = instruction->is_cold->child;
2080021761 bool want_cold;
2080121762 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
20802 return ira->codegen->invalid_instruction;
21763 return ira->codegen->invalid_inst_gen;
2080321764
20804 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
21765 ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope);
2080521766 if (fn_entry == nullptr) {
20806 ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));
20807 return ira->codegen->invalid_instruction;
21767 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function"));
21768 return ira->codegen->invalid_inst_gen;
2080821769 }
2080921770
2081021771 if (fn_entry->set_cold_node != nullptr) {
20811 ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cold set twice in same function"));
21772 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function"));
2081221773 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));
20813 return ira->codegen->invalid_instruction;
21774 return ira->codegen->invalid_inst_gen;
2081421775 }
2081521776
20816 fn_entry->set_cold_node = instruction->base.source_node;
21777 fn_entry->set_cold_node = instruction->base.base.source_node;
2081721778 fn_entry->is_cold = want_cold;
2081821779
20819 return ir_const_void(ira, &instruction->base);
21780 return ir_const_void(ira, &instruction->base.base);
2082021781}
2082121782
20822static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
20823 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
21783static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
21784 IrInstSrcSetRuntimeSafety *set_runtime_safety_instruction)
2082421785{
2082521786 if (ira->new_irb.exec->is_inline) {
2082621787 // ignore setRuntimeSafety when running functions at compile time
20827 return ir_const_void(ira, &set_runtime_safety_instruction->base);
21788 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
2082821789 }
2082921790
2083021791 bool *safety_off_ptr;
2083121792 AstNode **safety_set_node_ptr;
2083221793
20833 Scope *scope = set_runtime_safety_instruction->base.scope;
21794 Scope *scope = set_runtime_safety_instruction->base.base.scope;
2083421795 while (scope != nullptr) {
2083521796 if (scope->id == ScopeIdBlock) {
2083621797 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -20856,36 +21817,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
2085621817 }
2085721818 assert(scope != nullptr);
2085821819
20859 IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->child;
21820 IrInstGen *safety_on_value = set_runtime_safety_instruction->safety_on->child;
2086021821 bool want_runtime_safety;
2086121822 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))
20862 return ira->codegen->invalid_instruction;
21823 return ira->codegen->invalid_inst_gen;
2086321824
20864 AstNode *source_node = set_runtime_safety_instruction->base.source_node;
21825 AstNode *source_node = set_runtime_safety_instruction->base.base.source_node;
2086521826 if (*safety_set_node_ptr) {
2086621827 ErrorMsg *msg = ir_add_error_node(ira, source_node,
2086721828 buf_sprintf("runtime safety set twice for same scope"));
2086821829 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));
20869 return ira->codegen->invalid_instruction;
21830 return ira->codegen->invalid_inst_gen;
2087021831 }
2087121832 *safety_set_node_ptr = source_node;
2087221833 *safety_off_ptr = !want_runtime_safety;
2087321834
20874 return ir_const_void(ira, &set_runtime_safety_instruction->base);
21835 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
2087521836}
2087621837
20877static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
20878 IrInstructionSetFloatMode *instruction)
21838static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
21839 IrInstSrcSetFloatMode *instruction)
2087921840{
2088021841 if (ira->new_irb.exec->is_inline) {
2088121842 // ignore setFloatMode when running functions at compile time
20882 return ir_const_void(ira, &instruction->base);
21843 return ir_const_void(ira, &instruction->base.base);
2088321844 }
2088421845
2088521846 bool *fast_math_on_ptr;
2088621847 AstNode **fast_math_set_node_ptr;
2088721848
20888 Scope *scope = instruction->base.scope;
21849 Scope *scope = instruction->base.base.scope;
2088921850 while (scope != nullptr) {
2089021851 if (scope->id == ScopeIdBlock) {
2089121852 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -20911,42 +21872,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
2091121872 }
2091221873 assert(scope != nullptr);
2091321874
20914 IrInstruction *float_mode_value = instruction->mode_value->child;
21875 IrInstGen *float_mode_value = instruction->mode_value->child;
2091521876 FloatMode float_mode_scalar;
2091621877 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))
20917 return ira->codegen->invalid_instruction;
21878 return ira->codegen->invalid_inst_gen;
2091821879
20919 AstNode *source_node = instruction->base.source_node;
21880 AstNode *source_node = instruction->base.base.source_node;
2092021881 if (*fast_math_set_node_ptr) {
2092121882 ErrorMsg *msg = ir_add_error_node(ira, source_node,
2092221883 buf_sprintf("float mode set twice for same scope"));
2092321884 add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here"));
20924 return ira->codegen->invalid_instruction;
21885 return ira->codegen->invalid_inst_gen;
2092521886 }
2092621887 *fast_math_set_node_ptr = source_node;
2092721888 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);
2092821889
20929 return ir_const_void(ira, &instruction->base);
21890 return ir_const_void(ira, &instruction->base.base);
2093021891}
2093121892
20932static IrInstruction *ir_analyze_instruction_any_frame_type(IrAnalyze *ira,
20933 IrInstructionAnyFrameType *instruction)
20934{
21893static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) {
2093521894 ZigType *payload_type = nullptr;
2093621895 if (instruction->payload_type != nullptr) {
2093721896 payload_type = ir_resolve_type(ira, instruction->payload_type->child);
2093821897 if (type_is_invalid(payload_type))
20939 return ira->codegen->invalid_instruction;
21898 return ira->codegen->invalid_inst_gen;
2094021899 }
2094121900
2094221901 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);
20943 return ir_const_type(ira, &instruction->base, any_frame_type);
21902 return ir_const_type(ira, &instruction->base.base, any_frame_type);
2094421903}
2094521904
20946static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
20947 IrInstructionSliceType *slice_type_instruction)
20948{
20949 IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type);
21905static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) {
21906 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2095021907 result->value->special = ConstValSpecialLazy;
2095121908
2095221909 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");
......@@ -20957,18 +21914,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
2095721914 if (slice_type_instruction->align_value != nullptr) {
2095821915 lazy_slice_type->align_inst = slice_type_instruction->align_value->child;
2095921916 if (ir_resolve_const(ira, lazy_slice_type->align_inst, LazyOk) == nullptr)
20960 return ira->codegen->invalid_instruction;
21917 return ira->codegen->invalid_inst_gen;
2096121918 }
2096221919
2096321920 if (slice_type_instruction->sentinel != nullptr) {
2096421921 lazy_slice_type->sentinel = slice_type_instruction->sentinel->child;
2096521922 if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr)
20966 return ira->codegen->invalid_instruction;
21923 return ira->codegen->invalid_inst_gen;
2096721924 }
2096821925
2096921926 lazy_slice_type->elem_type = slice_type_instruction->child_type->child;
2097021927 if (ir_resolve_type_lazy(ira, lazy_slice_type->elem_type) == nullptr)
20971 return ira->codegen->invalid_instruction;
21928 return ira->codegen->invalid_inst_gen;
2097221929
2097321930 lazy_slice_type->is_const = slice_type_instruction->is_const;
2097421931 lazy_slice_type->is_volatile = slice_type_instruction->is_volatile;
......@@ -20977,31 +21934,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
2097721934 return result;
2097821935}
2097921936
20980static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsmSrc *asm_instruction) {
21937static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) {
2098121938 Error err;
2098221939
20983 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);
21940 assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr);
2098421941
20985 AstNode *node = asm_instruction->base.source_node;
20986 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;
21942 AstNode *node = asm_instruction->base.base.source_node;
21943 AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr;
2098721944
2098821945 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);
2098921946 if (template_buf == nullptr)
20990 return ira->codegen->invalid_instruction;
21947 return ira->codegen->invalid_inst_gen;
2099121948
2099221949 if (asm_instruction->is_global) {
2099321950 buf_append_char(&ira->codegen->global_asm, '\n');
2099421951 buf_append_buf(&ira->codegen->global_asm, template_buf);
2099521952
20996 return ir_const_void(ira, &asm_instruction->base);
21953 return ir_const_void(ira, &asm_instruction->base.base);
2099721954 }
2099821955
20999 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base))
21000 return ira->codegen->invalid_instruction;
21956 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base))
21957 return ira->codegen->invalid_inst_gen;
2100121958
2100221959 ZigList<AsmToken> tok_list = {};
2100321960 if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) {
21004 return ira->codegen->invalid_instruction;
21961 return ira->codegen->invalid_inst_gen;
2100521962 }
2100621963
2100721964 for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) {
......@@ -21015,15 +21972,15 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
2101521972 add_node_error(ira->codegen, node,
2101621973 buf_sprintf("could not find '%.*s' in the inputs or outputs",
2101721974 len, ptr));
21018 return ira->codegen->invalid_instruction;
21975 return ira->codegen->invalid_inst_gen;
2101921976 }
2102021977 }
2102121978 }
2102221979
2102321980 // TODO validate the output types and variable types
2102421981
21025 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);
21026 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);
21982 IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length);
21983 IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length);
2102721984
2102821985 ZigType *return_type = ira->codegen->builtin_types.entry_void;
2102921986 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
......@@ -21032,39 +21989,34 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
2103221989 output_types[i] = asm_instruction->output_types[i]->child;
2103321990 return_type = ir_resolve_type(ira, output_types[i]);
2103421991 if (type_is_invalid(return_type))
21035 return ira->codegen->invalid_instruction;
21992 return ira->codegen->invalid_inst_gen;
2103621993 }
2103721994 }
2103821995
2103921996 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
21040 IrInstruction *const input_value = asm_instruction->input_list[i]->child;
21997 IrInstGen *const input_value = asm_instruction->input_list[i]->child;
2104121998 if (type_is_invalid(input_value->value->type))
21042 return ira->codegen->invalid_instruction;
21999 return ira->codegen->invalid_inst_gen;
2104322000
2104422001 if (instr_is_comptime(input_value) &&
2104522002 (input_value->value->type->id == ZigTypeIdComptimeInt ||
2104622003 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
21047 ir_add_error_node(ira, input_value->source_node,
22004 ir_add_error(ira, &input_value->base,
2104822005 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));
21049 return ira->codegen->invalid_instruction;
22006 return ira->codegen->invalid_inst_gen;
2105022007 }
2105122008
2105222009 input_list[i] = input_value;
2105322010 }
2105422011
21055 IrInstruction *result = ir_build_asm_gen(ira,
21056 asm_instruction->base.scope, asm_instruction->base.source_node,
22012 return ir_build_asm_gen(ira, &asm_instruction->base.base,
2105722013 template_buf, tok_list.items, tok_list.length,
2105822014 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
21059 asm_instruction->has_side_effects);
21060 result->value->type = return_type;
21061 return result;
22015 asm_instruction->has_side_effects, return_type);
2106222016}
2106322017
21064static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
21065 IrInstructionArrayType *array_type_instruction)
21066{
21067 IrInstruction *result = ir_const(ira, &array_type_instruction->base, ira->codegen->builtin_types.entry_type);
22018static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) {
22019 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2106822020 result->value->special = ConstValSpecialLazy;
2106922021
2107022022 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");
......@@ -21074,22 +22026,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
2107422026
2107522027 lazy_array_type->elem_type = array_type_instruction->child_type->child;
2107622028 if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr)
21077 return ira->codegen->invalid_instruction;
22029 return ira->codegen->invalid_inst_gen;
2107822030
2107922031 if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length))
21080 return ira->codegen->invalid_instruction;
22032 return ira->codegen->invalid_inst_gen;
2108122033
2108222034 if (array_type_instruction->sentinel != nullptr) {
2108322035 lazy_array_type->sentinel = array_type_instruction->sentinel->child;
2108422036 if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr)
21085 return ira->codegen->invalid_instruction;
22037 return ira->codegen->invalid_inst_gen;
2108622038 }
2108722039
2108822040 return result;
2108922041}
2109022042
21091static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) {
21092 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22043static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) {
22044 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2109322045 result->value->special = ConstValSpecialLazy;
2109422046
2109522047 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");
......@@ -21100,19 +22052,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi
2110022052
2110122053 lazy_size_of->target_type = instruction->type_value->child;
2110222054 if (ir_resolve_type_lazy(ira, lazy_size_of->target_type) == nullptr)
21103 return ira->codegen->invalid_instruction;
22055 return ira->codegen->invalid_inst_gen;
2110422056
2110522057 return result;
2110622058}
2110722059
21108static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) {
22060static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) {
2110922061 ZigType *type_entry = value->value->type;
2111022062
2111122063 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
2111222064 if (instr_is_comptime(value)) {
2111322065 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);
2111422066 if (c_ptr_val == nullptr)
21115 return ira->codegen->invalid_instruction;
22067 return ira->codegen->invalid_inst_gen;
2111622068 if (c_ptr_val->special == ConstValSpecialUndef)
2111722069 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
2111822070 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
......@@ -21121,25 +22073,19 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
2112122073 return ir_const_bool(ira, source_inst, !is_null);
2112222074 }
2112322075
21124 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
21125 source_inst->scope, source_inst->source_node, value);
21126 result->value->type = ira->codegen->builtin_types.entry_bool;
21127 return result;
22076 return ir_build_test_non_null_gen(ira, source_inst, value);
2112822077 } else if (type_entry->id == ZigTypeIdOptional) {
2112922078 if (instr_is_comptime(value)) {
2113022079 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
2113122080 if (maybe_val == nullptr)
21132 return ira->codegen->invalid_instruction;
22081 return ira->codegen->invalid_inst_gen;
2113322082 if (maybe_val->special == ConstValSpecialUndef)
2113422083 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
2113522084
2113622085 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));
2113722086 }
2113822087
21139 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
21140 source_inst->scope, source_inst->source_node, value);
21141 result->value->type = ira->codegen->builtin_types.entry_bool;
21142 return result;
22088 return ir_build_test_non_null_gen(ira, source_inst, value);
2114322089 } else if (type_entry->id == ZigTypeIdNull) {
2114422090 return ir_const_bool(ira, source_inst, false);
2114522091 } else {
......@@ -21147,51 +22093,51 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
2114722093 }
2114822094}
2114922095
21150static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
21151 IrInstruction *value = instruction->value->child;
22096static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrcTestNonNull *instruction) {
22097 IrInstGen *value = instruction->value->child;
2115222098 if (type_is_invalid(value->value->type))
21153 return ira->codegen->invalid_instruction;
22099 return ira->codegen->invalid_inst_gen;
2115422100
21155 return ir_analyze_test_non_null(ira, &instruction->base, value);
22101 return ir_analyze_test_non_null(ira, &instruction->base.base, value);
2115622102}
2115722103
21158static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,
21159 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
22104static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
22105 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
2116022106{
2116122107 ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr);
2116222108 if (type_is_invalid(type_entry))
21163 return ira->codegen->invalid_instruction;
22109 return ira->codegen->invalid_inst_gen;
2116422110
2116522111 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {
2116622112 if (instr_is_comptime(base_ptr)) {
2116722113 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);
2116822114 if (!val)
21169 return ira->codegen->invalid_instruction;
22115 return ira->codegen->invalid_inst_gen;
2117022116 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2117122117 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
2117222118 if (c_ptr_val == nullptr)
21173 return ira->codegen->invalid_instruction;
22119 return ira->codegen->invalid_inst_gen;
2117422120 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
2117522121 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
2117622122 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
2117722123 if (is_null) {
2117822124 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
21179 return ira->codegen->invalid_instruction;
22125 return ira->codegen->invalid_inst_gen;
2118022126 }
2118122127 return base_ptr;
2118222128 }
2118322129 }
2118422130 if (!safety_check_on)
2118522131 return base_ptr;
21186 IrInstruction *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);
22132 IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);
2118722133 ir_build_assert_non_null(ira, source_instr, c_ptr_val);
2118822134 return base_ptr;
2118922135 }
2119022136
2119122137 if (type_entry->id != ZigTypeIdOptional) {
21192 ir_add_error_node(ira, base_ptr->source_node,
22138 ir_add_error(ira, &base_ptr->base,
2119322139 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
21194 return ira->codegen->invalid_instruction;
22140 return ira->codegen->invalid_inst_gen;
2119522141 }
2119622142
2119722143 ZigType *child_type = type_entry->data.maybe.child_type;
......@@ -21204,16 +22150,16 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2120422150 if (instr_is_comptime(base_ptr)) {
2120522151 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
2120622152 if (!ptr_val)
21207 return ira->codegen->invalid_instruction;
22153 return ira->codegen->invalid_inst_gen;
2120822154 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2120922155 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2121022156 if (optional_val == nullptr)
21211 return ira->codegen->invalid_instruction;
22157 return ira->codegen->invalid_inst_gen;
2121222158
2121322159 if (initializing) {
2121422160 switch (type_has_one_possible_value(ira->codegen, child_type)) {
2121522161 case OnePossibleValueInvalid:
21216 return ira->codegen->invalid_instruction;
22162 return ira->codegen->invalid_inst_gen;
2121722163 case OnePossibleValueNo:
2121822164 if (!same_comptime_repr) {
2121922165 ZigValue *payload_val = create_const_vals(1);
......@@ -21240,14 +22186,13 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2124022186 }
2124122187 } else if (optional_value_is_null(optional_val)) {
2124222188 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
21243 return ira->codegen->invalid_instruction;
22189 return ira->codegen->invalid_inst_gen;
2124422190 }
2124522191
21246 IrInstruction *result;
22192 IrInstGen *result;
2124722193 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21248 result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
21249 source_instr->source_node, base_ptr, false, initializing);
21250 result->value->type = result_type;
22194 result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false,
22195 initializing, result_type);
2125122196 result->value->special = ConstValSpecialStatic;
2125222197 } else {
2125322198 result = ir_const(ira, source_instr, result_type);
......@@ -21257,7 +22202,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2125722202 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
2125822203 switch (type_has_one_possible_value(ira->codegen, child_type)) {
2125922204 case OnePossibleValueInvalid:
21260 return ira->codegen->invalid_instruction;
22205 return ira->codegen->invalid_inst_gen;
2126122206 case OnePossibleValueNo:
2126222207 if (same_comptime_repr) {
2126322208 result_val->data.x_ptr.data.ref.pointee = optional_val;
......@@ -21275,131 +22220,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2127522220 }
2127622221 }
2127722222
21278 IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
21279 source_instr->source_node, base_ptr, safety_check_on, initializing);
21280 result->value->type = result_type;
21281 return result;
22223 return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on,
22224 initializing, result_type);
2128222225}
2128322226
21284static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
21285 IrInstructionOptionalUnwrapPtr *instruction)
22227static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
22228 IrInstSrcOptionalUnwrapPtr *instruction)
2128622229{
21287 IrInstruction *base_ptr = instruction->base_ptr->child;
22230 IrInstGen *base_ptr = instruction->base_ptr->child;
2128822231 if (type_is_invalid(base_ptr->value->type))
21289 return ira->codegen->invalid_instruction;
22232 return ira->codegen->invalid_inst_gen;
2129022233
21291 return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr,
22234 return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr,
2129222235 instruction->safety_check_on, false);
2129322236}
2129422237
21295static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *instruction) {
22238static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instruction) {
2129622239 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2129722240 if (type_is_invalid(int_type))
21298 return ira->codegen->invalid_instruction;
22241 return ira->codegen->invalid_inst_gen;
2129922242
21300 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
22243 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2130122244 if (type_is_invalid(op->value->type))
21302 return ira->codegen->invalid_instruction;
22245 return ira->codegen->invalid_inst_gen;
2130322246
2130422247 if (int_type->data.integral.bit_count == 0)
21305 return ir_const_unsigned(ira, &instruction->base, 0);
22248 return ir_const_unsigned(ira, &instruction->base.base, 0);
2130622249
2130722250 if (instr_is_comptime(op)) {
2130822251 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2130922252 if (val == nullptr)
21310 return ira->codegen->invalid_instruction;
22253 return ira->codegen->invalid_inst_gen;
2131122254 if (val->special == ConstValSpecialUndef)
21312 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22255 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2131322256 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
21314 return ir_const_unsigned(ira, &instruction->base, result_usize);
22257 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
2131522258 }
2131622259
2131722260 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21318 IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope,
21319 instruction->base.source_node, nullptr, op);
21320 result->value->type = return_type;
21321 return result;
22261 return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op);
2132222262}
2132322263
21324static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *instruction) {
22264static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) {
2132522265 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2132622266 if (type_is_invalid(int_type))
21327 return ira->codegen->invalid_instruction;
22267 return ira->codegen->invalid_inst_gen;
2132822268
21329 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
22269 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2133022270 if (type_is_invalid(op->value->type))
21331 return ira->codegen->invalid_instruction;
22271 return ira->codegen->invalid_inst_gen;
2133222272
2133322273 if (int_type->data.integral.bit_count == 0)
21334 return ir_const_unsigned(ira, &instruction->base, 0);
22274 return ir_const_unsigned(ira, &instruction->base.base, 0);
2133522275
2133622276 if (instr_is_comptime(op)) {
2133722277 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2133822278 if (val == nullptr)
21339 return ira->codegen->invalid_instruction;
22279 return ira->codegen->invalid_inst_gen;
2134022280 if (val->special == ConstValSpecialUndef)
21341 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22281 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2134222282 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
21343 return ir_const_unsigned(ira, &instruction->base, result_usize);
22283 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
2134422284 }
2134522285
2134622286 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21347 IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope,
21348 instruction->base.source_node, nullptr, op);
21349 result->value->type = return_type;
21350 return result;
22287 return ir_build_clz_gen(ira, &instruction->base.base, return_type, op);
2135122288}
2135222289
21353static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {
22290static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) {
2135422291 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2135522292 if (type_is_invalid(int_type))
21356 return ira->codegen->invalid_instruction;
22293 return ira->codegen->invalid_inst_gen;
2135722294
21358 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
22295 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2135922296 if (type_is_invalid(op->value->type))
21360 return ira->codegen->invalid_instruction;
22297 return ira->codegen->invalid_inst_gen;
2136122298
2136222299 if (int_type->data.integral.bit_count == 0)
21363 return ir_const_unsigned(ira, &instruction->base, 0);
22300 return ir_const_unsigned(ira, &instruction->base.base, 0);
2136422301
2136522302 if (instr_is_comptime(op)) {
2136622303 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2136722304 if (val == nullptr)
21368 return ira->codegen->invalid_instruction;
22305 return ira->codegen->invalid_inst_gen;
2136922306 if (val->special == ConstValSpecialUndef)
21370 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22307 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2137122308
2137222309 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {
2137322310 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);
21374 return ir_const_unsigned(ira, &instruction->base, result);
22311 return ir_const_unsigned(ira, &instruction->base.base, result);
2137522312 }
2137622313 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);
21377 return ir_const_unsigned(ira, &instruction->base, result);
22314 return ir_const_unsigned(ira, &instruction->base.base, result);
2137822315 }
2137922316
2138022317 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21381 IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope,
21382 instruction->base.source_node, nullptr, op);
21383 result->value->type = return_type;
21384 return result;
22318 return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op);
2138522319}
2138622320
21387static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {
22321static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, bool is_gen) {
2138822322 if (type_is_invalid(value->value->type))
21389 return ira->codegen->invalid_instruction;
22323 return ira->codegen->invalid_inst_gen;
2139022324
2139122325 if (value->value->type->id != ZigTypeIdUnion) {
21392 ir_add_error(ira, value,
22326 ir_add_error(ira, &value->base,
2139322327 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));
21394 return ira->codegen->invalid_instruction;
22328 return ira->codegen->invalid_inst_gen;
2139522329 }
21396 if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) {
22330 if (!value->value->type->data.unionation.have_explicit_tag_type && !is_gen) {
2139722331 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));
2139822332 if (value->value->type->data.unionation.decl_node != nullptr) {
2139922333 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
2140022334 buf_sprintf("declared here"));
2140122335 }
21402 return ira->codegen->invalid_instruction;
22336 return ira->codegen->invalid_inst_gen;
2140322337 }
2140422338
2140522339 ZigType *tag_type = value->value->type->data.unionation.tag_type;
......@@ -21408,9 +22342,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
2140822342 if (instr_is_comptime(value)) {
2140922343 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
2141022344 if (!val)
21411 return ira->codegen->invalid_instruction;
22345 return ira->codegen->invalid_inst_gen;
2141222346
21413 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
22347 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
2141422348 source_instr->scope, source_instr->source_node);
2141522349 const_instruction->base.value->type = tag_type;
2141622350 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -21418,15 +22352,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
2141822352 return &const_instruction->base;
2141922353 }
2142022354
21421 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
21422 result->value->type = tag_type;
21423 return result;
22355 return ir_build_union_tag(ira, source_instr, value, tag_type);
2142422356}
2142522357
21426static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21427 IrInstructionSwitchBr *switch_br_instruction)
22358static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
22359 IrInstSrcSwitchBr *switch_br_instruction)
2142822360{
21429 IrInstruction *target_value = switch_br_instruction->target_value->child;
22361 IrInstGen *target_value = switch_br_instruction->target_value->child;
2143022362 if (type_is_invalid(target_value->value->type))
2143122363 return ir_unreach_error(ira);
2143222364
......@@ -21441,21 +22373,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2144122373
2144222374 bool is_comptime;
2144322375 if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime))
21444 return ira->codegen->invalid_instruction;
22376 return ira->codegen->invalid_inst_gen;
2144522377
2144622378 if (is_comptime || instr_is_comptime(target_value)) {
2144722379 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);
2144822380 if (!target_val)
2144922381 return ir_unreach_error(ira);
2145022382
21451 IrBasicBlock *old_dest_block = switch_br_instruction->else_block;
22383 IrBasicBlockSrc *old_dest_block = switch_br_instruction->else_block;
2145222384 for (size_t i = 0; i < case_count; i += 1) {
21453 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21454 IrInstruction *case_value = old_case->value->child;
22385 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
22386 IrInstGen *case_value = old_case->value->child;
2145522387 if (type_is_invalid(case_value->value->type))
2145622388 return ir_unreach_error(ira);
2145722389
21458 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);
22390 IrInstGen *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);
2145922391 if (type_is_invalid(casted_case_value->value->type))
2146022392 return ir_unreach_error(ira);
2146122393
......@@ -21470,23 +22402,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2147022402 }
2147122403
2147222404 if (is_comptime || old_dest_block->ref_count == 1) {
21473 return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block);
22405 return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block);
2147422406 } else {
21475 IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base);
21476 IrInstruction *result = ir_build_br(&ira->new_irb,
21477 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
21478 new_dest_block, nullptr);
21479 result->value->type = ira->codegen->builtin_types.entry_unreachable;
22407 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base);
22408 IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block);
2148022409 return ir_finish_anal(ira, result);
2148122410 }
2148222411 }
2148322412
21484 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(case_count);
22413 IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count);
2148522414 for (size_t i = 0; i < case_count; i += 1) {
21486 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21487 IrInstructionSwitchBrCase *new_case = &cases[i];
21488 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base);
21489 new_case->value = ira->codegen->invalid_instruction;
22415 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
22416 IrInstGenSwitchBrCase *new_case = &cases[i];
22417 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base);
22418 new_case->value = ira->codegen->invalid_inst_gen;
2149022419
2149122420 // Calling ir_get_new_bb set the ref_instruction on the new basic block.
2149222421 // However a switch br may branch to the same basic block which would trigger an
......@@ -21494,12 +22423,12 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2149422423 // it back after the loop.
2149522424 new_case->block->ref_instruction = nullptr;
2149622425
21497 IrInstruction *old_value = old_case->value;
21498 IrInstruction *new_value = old_value->child;
22426 IrInstSrc *old_value = old_case->value;
22427 IrInstGen *new_value = old_value->child;
2149922428 if (type_is_invalid(new_value->value->type))
2150022429 continue;
2150122430
21502 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);
22431 IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);
2150322432 if (type_is_invalid(casted_new_value->value->type))
2150422433 continue;
2150522434
......@@ -21510,47 +22439,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2151022439 }
2151122440
2151222441 for (size_t i = 0; i < case_count; i += 1) {
21513 IrInstructionSwitchBrCase *new_case = &cases[i];
21514 if (new_case->value == ira->codegen->invalid_instruction)
22442 IrInstGenSwitchBrCase *new_case = &cases[i];
22443 if (type_is_invalid(new_case->value->value->type))
2151522444 return ir_unreach_error(ira);
21516 new_case->block->ref_instruction = &switch_br_instruction->base;
22445 new_case->block->ref_instruction = &switch_br_instruction->base.base;
2151722446 }
2151822447
21519 IrBasicBlock *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base);
21520 IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb,
21521 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
21522 target_value, new_else_block, case_count, cases, nullptr, nullptr);
21523 switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable;
22448 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base);
22449 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base,
22450 target_value, new_else_block, case_count, cases);
2152422451 return ir_finish_anal(ira, &switch_br->base);
2152522452}
2152622453
21527static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21528 IrInstructionSwitchTarget *switch_target_instruction)
22454static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
22455 IrInstSrcSwitchTarget *switch_target_instruction)
2152922456{
2153022457 Error err;
21531 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child;
22458 IrInstGen *target_value_ptr = switch_target_instruction->target_value_ptr->child;
2153222459 if (type_is_invalid(target_value_ptr->value->type))
21533 return ira->codegen->invalid_instruction;
22460 return ira->codegen->invalid_inst_gen;
2153422461
2153522462 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {
2153622463 assert(instr_is_comptime(target_value_ptr));
2153722464 ZigType *ptr_type = target_value_ptr->value->data.x_type;
2153822465 assert(ptr_type->id == ZigTypeIdPointer);
21539 return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type);
22466 return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type);
2154022467 }
2154122468
2154222469 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
2154322470 ZigValue *pointee_val = nullptr;
2154422471 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21545 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node);
22472 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node);
2154622473 if (pointee_val == nullptr)
21547 return ira->codegen->invalid_instruction;
22474 return ira->codegen->invalid_inst_gen;
2154822475
2154922476 if (pointee_val->special == ConstValSpecialRuntime)
2155022477 pointee_val = nullptr;
2155122478 }
2155222479 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown)))
21553 return ira->codegen->invalid_instruction;
22480 return ira->codegen->invalid_inst_gen;
2155422481
2155522482 switch (target_type->id) {
2155622483 case ZigTypeIdInvalid:
......@@ -21567,13 +22494,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2156722494 case ZigTypeIdFn:
2156822495 case ZigTypeIdErrorSet: {
2156922496 if (pointee_val) {
21570 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
22497 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);
2157122498 copy_const_val(result->value, pointee_val);
2157222499 result->value->type = target_type;
2157322500 return result;
2157422501 }
2157522502
21576 IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
22503 IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
2157722504 result->value->type = target_type;
2157822505 return result;
2157922506 }
......@@ -21582,52 +22509,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2158222509 if (!decl_node->data.container_decl.auto_enum &&
2158322510 decl_node->data.container_decl.init_arg_expr == nullptr)
2158422511 {
21585 ErrorMsg *msg = ir_add_error(ira, target_value_ptr,
22512 ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base,
2158622513 buf_sprintf("switch on union which has no attached enum"));
2158722514 add_error_note(ira->codegen, msg, decl_node,
2158822515 buf_sprintf("consider 'union(enum)' here"));
21589 return ira->codegen->invalid_instruction;
22516 return ira->codegen->invalid_inst_gen;
2159022517 }
2159122518 ZigType *tag_type = target_type->data.unionation.tag_type;
2159222519 assert(tag_type != nullptr);
2159322520 assert(tag_type->id == ZigTypeIdEnum);
2159422521 if (pointee_val) {
21595 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);
22522 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
2159622523 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);
2159722524 return result;
2159822525 }
2159922526 if (tag_type->data.enumeration.src_field_count == 1) {
21600 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);
22527 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
2160122528 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];
2160222529 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
2160322530 return result;
2160422531 }
2160522532
21606 IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
22533 IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
2160722534 union_value->value->type = target_type;
2160822535
21609 IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope,
21610 switch_target_instruction->base.source_node, union_value);
21611 union_tag_inst->value->type = tag_type;
21612 return union_tag_inst;
22536 return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type);
2161322537 }
2161422538 case ZigTypeIdEnum: {
2161522539 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))
21616 return ira->codegen->invalid_instruction;
22540 return ira->codegen->invalid_inst_gen;
2161722541 if (target_type->data.enumeration.src_field_count == 1) {
2161822542 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
21619 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);
22543 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
2162022544 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
2162122545 return result;
2162222546 }
2162322547
2162422548 if (pointee_val) {
21625 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);
22549 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
2162622550 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);
2162722551 return result;
2162822552 }
2162922553
21630 IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
22554 IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
2163122555 enum_value->value->type = target_type;
2163222556 return enum_value;
2163322557 }
......@@ -21643,17 +22567,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2164322567 case ZigTypeIdVector:
2164422568 case ZigTypeIdFnFrame:
2164522569 case ZigTypeIdAnyFrame:
21646 ir_add_error(ira, &switch_target_instruction->base,
22570 ir_add_error(ira, &switch_target_instruction->base.base,
2164722571 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
21648 return ira->codegen->invalid_instruction;
22572 return ira->codegen->invalid_inst_gen;
2164922573 }
2165022574 zig_unreachable();
2165122575}
2165222576
21653static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
21654 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;
22577static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwitchVar *instruction) {
22578 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
2165522579 if (type_is_invalid(target_value_ptr->value->type))
21656 return ira->codegen->invalid_instruction;
22580 return ira->codegen->invalid_inst_gen;
2165722581
2165822582 ZigType *ref_type = target_value_ptr->value->type;
2165922583 assert(ref_type->id == ZigTypeIdPointer);
......@@ -21664,62 +22588,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2166422588 assert(enum_type->id == ZigTypeIdEnum);
2166522589 assert(instruction->prongs_len > 0);
2166622590
21667 IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child;
22591 IrInstGen *first_prong_value = instruction->prongs_ptr[0]->child;
2166822592 if (type_is_invalid(first_prong_value->value->type))
21669 return ira->codegen->invalid_instruction;
22593 return ira->codegen->invalid_inst_gen;
2167022594
21671 IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);
22595 IrInstGen *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);
2167222596 if (type_is_invalid(first_casted_prong_value->value->type))
21673 return ira->codegen->invalid_instruction;
22597 return ira->codegen->invalid_inst_gen;
2167422598
2167522599 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);
2167622600 if (first_prong_val == nullptr)
21677 return ira->codegen->invalid_instruction;
22601 return ira->codegen->invalid_inst_gen;
2167822602
2167922603 TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag);
2168022604
2168122605 ErrorMsg *invalid_payload_msg = nullptr;
2168222606 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {
21683 IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child;
22607 IrInstGen *this_prong_inst = instruction->prongs_ptr[prong_i]->child;
2168422608 if (type_is_invalid(this_prong_inst->value->type))
21685 return ira->codegen->invalid_instruction;
22609 return ira->codegen->invalid_inst_gen;
2168622610
21687 IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);
22611 IrInstGen *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);
2168822612 if (type_is_invalid(this_casted_prong_value->value->type))
21689 return ira->codegen->invalid_instruction;
22613 return ira->codegen->invalid_inst_gen;
2169022614
2169122615 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);
2169222616 if (this_prong == nullptr)
21693 return ira->codegen->invalid_instruction;
22617 return ira->codegen->invalid_inst_gen;
2169422618
2169522619 TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag);
2169622620 ZigType *payload_type = payload_field->type_entry;
2169722621 if (first_field->type_entry != payload_type) {
2169822622 if (invalid_payload_msg == nullptr) {
21699 invalid_payload_msg = ir_add_error(ira, &instruction->base,
22623 invalid_payload_msg = ir_add_error(ira, &instruction->base.base,
2170022624 buf_sprintf("capture group with incompatible types"));
21701 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node,
22625 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node,
2170222626 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));
2170322627 }
21704 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node,
22628 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node,
2170522629 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));
2170622630 }
2170722631 }
2170822632
2170922633 if (invalid_payload_msg != nullptr) {
21710 return ira->codegen->invalid_instruction;
22634 return ira->codegen->invalid_inst_gen;
2171122635 }
2171222636
2171322637 if (instr_is_comptime(target_value_ptr)) {
2171422638 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);
2171522639 if (!target_value_ptr)
21716 return ira->codegen->invalid_instruction;
22640 return ira->codegen->invalid_inst_gen;
2171722641
21718 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);
22642 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node);
2171922643 if (pointee_val == nullptr)
21720 return ira->codegen->invalid_instruction;
22644 return ira->codegen->invalid_inst_gen;
2172122645
21722 IrInstruction *result = ir_const(ira, &instruction->base,
22646 IrInstGen *result = ir_const(ira, &instruction->base.base,
2172322647 get_pointer_to_type(ira->codegen, first_field->type_entry,
2172422648 target_val_ptr->type->data.pointer.is_const));
2172522649 ZigValue *out_val = result->value;
......@@ -21729,11 +22653,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2172922653 return result;
2173022654 }
2173122655
21732 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,
21733 instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false);
21734 result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry,
22656 ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry,
2173522657 target_value_ptr->value->type->data.pointer.is_const);
21736 return result;
22658 return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field,
22659 false, false, result_type);
2173722660 } else if (target_type->id == ZigTypeIdErrorSet) {
2173822661 // construct an error set from the prong values
2173922662 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
......@@ -21746,7 +22669,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2174622669 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
2174722670 ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child);
2174822671 if (err == nullptr)
21749 return ira->codegen->invalid_instruction;
22672 return ira->codegen->invalid_inst_gen;
2175022673 error_list.append(err);
2175122674 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name));
2175222675 }
......@@ -21762,29 +22685,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2176222685 ref_type->data.pointer.explicit_alignment,
2176322686 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
2176422687 ref_type->data.pointer.allow_zero);
21765 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,
21766 &instruction->base, false);
22688 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type,
22689 &instruction->base.base, false);
2176722690 } else {
21768 ir_add_error(ira, &instruction->base,
22691 ir_add_error(ira, &instruction->base.base,
2176922692 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));
21770 return ira->codegen->invalid_instruction;
22693 return ira->codegen->invalid_inst_gen;
2177122694 }
2177222695}
2177322696
21774static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21775 IrInstructionSwitchElseVar *instruction)
22697static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
22698 IrInstSrcSwitchElseVar *instruction)
2177622699{
21777 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;
22700 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
2177822701 if (type_is_invalid(target_value_ptr->value->type))
21779 return ira->codegen->invalid_instruction;
22702 return ira->codegen->invalid_inst_gen;
2178022703
2178122704 ZigType *ref_type = target_value_ptr->value->type;
2178222705 assert(ref_type->id == ZigTypeIdPointer);
2178322706 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
2178422707 if (target_type->id == ZigTypeIdErrorSet) {
2178522708 // make a new set that has the other cases removed
21786 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {
21787 return ira->codegen->invalid_instruction;
22709 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) {
22710 return ira->codegen->invalid_inst_gen;
2178822711 }
2178922712 if (type_is_global_error_set(target_type)) {
2179022713 // the type of the else capture variable still has to be the global error set.
......@@ -21794,17 +22717,17 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2179422717 // Make note of the errors handled by other cases
2179522718 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
2179622719 for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) {
21797 IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
21798 IrInstruction *case_expr = br_case->value->child;
22720 IrInstSrcSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
22721 IrInstGen *case_expr = br_case->value->child;
2179922722 if (case_expr->value->type->id == ZigTypeIdErrorSet) {
2180022723 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);
2180122724 if (err == nullptr)
21802 return ira->codegen->invalid_instruction;
22725 return ira->codegen->invalid_inst_gen;
2180322726 errors[err->value] = err;
2180422727 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {
2180522728 ZigType *err_set_type = ir_resolve_type(ira, case_expr);
2180622729 if (type_is_invalid(err_set_type))
21807 return ira->codegen->invalid_instruction;
22730 return ira->codegen->invalid_inst_gen;
2180822731 populate_error_set_table(errors, err_set_type);
2180922732 } else {
2181022733 zig_unreachable();
......@@ -21843,27 +22766,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2184322766 ref_type->data.pointer.explicit_alignment,
2184422767 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
2184522768 ref_type->data.pointer.allow_zero);
21846 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,
21847 &instruction->base, false);
22769 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type,
22770 &instruction->base.base, false);
2184822771 }
2184922772
2185022773 return target_value_ptr;
2185122774}
2185222775
21853static IrInstruction *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {
21854 IrInstruction *value = instruction->value->child;
21855 return ir_analyze_union_tag(ira, &instruction->base, value);
21856}
21857
21858static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
22776static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport *import_instruction) {
2185922777 Error err;
2186022778
21861 IrInstruction *name_value = import_instruction->name->child;
22779 IrInstGen *name_value = import_instruction->name->child;
2186222780 Buf *import_target_str = ir_resolve_str(ira, name_value);
2186322781 if (!import_target_str)
21864 return ira->codegen->invalid_instruction;
22782 return ira->codegen->invalid_inst_gen;
2186522783
21866 AstNode *source_node = import_instruction->base.source_node;
22784 AstNode *source_node = import_instruction->base.base.source_node;
2186722785 ZigType *import = source_node->owner;
2186822786
2186922787 ZigType *target_import;
......@@ -21876,48 +22794,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
2187622794 ir_add_error_node(ira, source_node,
2187722795 buf_sprintf("import of file outside package path: '%s'",
2187822796 buf_ptr(import_target_path)));
21879 return ira->codegen->invalid_instruction;
22797 return ira->codegen->invalid_inst_gen;
2188022798 } else if (err == ErrorFileNotFound) {
2188122799 ir_add_error_node(ira, source_node,
2188222800 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
21883 return ira->codegen->invalid_instruction;
22801 return ira->codegen->invalid_inst_gen;
2188422802 } else {
2188522803 ir_add_error_node(ira, source_node,
2188622804 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
21887 return ira->codegen->invalid_instruction;
22805 return ira->codegen->invalid_inst_gen;
2188822806 }
2188922807 }
2189022808
21891 return ir_const_type(ira, &import_instruction->base, target_import);
22809 return ir_const_type(ira, &import_instruction->base.base, target_import);
2189222810}
2189322811
21894static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
21895 IrInstruction *value = ref_instruction->value->child;
22812static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) {
22813 IrInstGen *value = ref_instruction->value->child;
2189622814 if (type_is_invalid(value->value->type))
21897 return ira->codegen->invalid_instruction;
21898 return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);
22815 return ira->codegen->invalid_inst_gen;
22816 return ir_get_ref(ira, &ref_instruction->base.base, value, ref_instruction->is_const, ref_instruction->is_volatile);
2189922817}
2190022818
21901static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *source_instruction,
21902 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstruction *field_result_loc,
21903 IrInstruction *result_loc)
22819static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,
22820 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
22821 IrInstGen *result_loc)
2190422822{
2190522823 Error err;
2190622824 assert(union_type->id == ZigTypeIdUnion);
2190722825
2190822826 if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown)))
21909 return ira->codegen->invalid_instruction;
22827 return ira->codegen->invalid_inst_gen;
2191022828
2191122829 TypeUnionField *type_field = find_union_type_field(union_type, field_name);
2191222830 if (type_field == nullptr) {
2191322831 ir_add_error_node(ira, field_source_node,
2191422832 buf_sprintf("no member named '%s' in union '%s'",
2191522833 buf_ptr(field_name), buf_ptr(&union_type->name)));
21916 return ira->codegen->invalid_instruction;
22834 return ira->codegen->invalid_inst_gen;
2191722835 }
2191822836
2191922837 if (type_is_invalid(type_field->type_entry))
21920 return ira->codegen->invalid_instruction;
22838 return ira->codegen->invalid_inst_gen;
2192122839
2192222840 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
2192322841 if (instr_is_comptime(field_result_loc) &&
......@@ -21929,42 +22847,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc
2192922847 }
2193022848 }
2193122849
21932 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instruction->scope)
22850 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instruction->scope)
2193322851 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;
2193422852
21935 IrInstruction *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);
22853 IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);
2193622854 if (is_comptime && !instr_is_comptime(result)) {
21937 ir_add_error(ira, field_result_loc,
22855 ir_add_error(ira, &field_result_loc->base,
2193822856 buf_sprintf("unable to evaluate constant expression"));
21939 return ira->codegen->invalid_instruction;
22857 return ira->codegen->invalid_inst_gen;
2194022858 }
2194122859 return result;
2194222860}
2194322861
21944static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
21945 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields,
21946 IrInstruction *result_loc)
22862static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr,
22863 ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields,
22864 IrInstGen *result_loc)
2194722865{
2194822866 Error err;
2194922867 if (container_type->id == ZigTypeIdUnion) {
2195022868 if (instr_field_count != 1) {
21951 ir_add_error(ira, instruction,
22869 ir_add_error(ira, source_instr,
2195222870 buf_sprintf("union initialization expects exactly one field"));
21953 return ira->codegen->invalid_instruction;
22871 return ira->codegen->invalid_inst_gen;
2195422872 }
21955 IrInstructionContainerInitFieldsField *field = &fields[0];
21956 IrInstruction *field_result_loc = field->result_loc->child;
22873 IrInstSrcContainerInitFieldsField *field = &fields[0];
22874 IrInstGen *field_result_loc = field->result_loc->child;
2195722875 if (type_is_invalid(field_result_loc->value->type))
21958 return ira->codegen->invalid_instruction;
22876 return ira->codegen->invalid_inst_gen;
2195922877
21960 return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name,
22878 return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name,
2196122879 field_result_loc, result_loc);
2196222880 }
2196322881 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
21964 ir_add_error(ira, instruction,
22882 ir_add_error(ira, source_instr,
2196522883 buf_sprintf("type '%s' does not support struct initialization syntax",
2196622884 buf_ptr(&container_type->name)));
21967 return ira->codegen->invalid_instruction;
22885 return ira->codegen->invalid_inst_gen;
2196822886 }
2196922887
2197022888 if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) {
......@@ -21973,16 +22891,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2197322891 }
2197422892
2197522893 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
21976 return ira->codegen->invalid_instruction;
22894 return ira->codegen->invalid_inst_gen;
2197722895
2197822896 size_t actual_field_count = container_type->data.structure.src_field_count;
2197922897
21980 IrInstruction *first_non_const_instruction = nullptr;
22898 IrInstGen *first_non_const_instruction = nullptr;
2198122899
2198222900 AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count);
21983 ZigList<IrInstruction *> const_ptrs = {};
22901 ZigList<IrInstGen *> const_ptrs = {};
2198422902
21985 bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope)
22903 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope)
2198622904 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;
2198722905
2198822906
......@@ -21998,29 +22916,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2199822916 // comptime-known values.
2199922917
2200022918 for (size_t i = 0; i < instr_field_count; i += 1) {
22001 IrInstructionContainerInitFieldsField *field = &fields[i];
22919 IrInstSrcContainerInitFieldsField *field = &fields[i];
2200222920
22003 IrInstruction *field_result_loc = field->result_loc->child;
22921 IrInstGen *field_result_loc = field->result_loc->child;
2200422922 if (type_is_invalid(field_result_loc->value->type))
22005 return ira->codegen->invalid_instruction;
22923 return ira->codegen->invalid_inst_gen;
2200622924
2200722925 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
2200822926 if (!type_field) {
2200922927 ir_add_error_node(ira, field->source_node,
2201022928 buf_sprintf("no member named '%s' in struct '%s'",
2201122929 buf_ptr(field->name), buf_ptr(&container_type->name)));
22012 return ira->codegen->invalid_instruction;
22930 return ira->codegen->invalid_inst_gen;
2201322931 }
2201422932
2201522933 if (type_is_invalid(type_field->type_entry))
22016 return ira->codegen->invalid_instruction;
22934 return ira->codegen->invalid_inst_gen;
2201722935
2201822936 size_t field_index = type_field->src_index;
2201922937 AstNode *existing_assign_node = field_assign_nodes[field_index];
2202022938 if (existing_assign_node) {
2202122939 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));
2202222940 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));
22023 return ira->codegen->invalid_instruction;
22941 return ira->codegen->invalid_inst_gen;
2202422942 }
2202522943 field_assign_nodes[field_index] = field->source_node;
2202622944
......@@ -22041,20 +22959,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2204122959 TypeStructField *field = container_type->data.structure.fields[i];
2204222960 memoize_field_init_val(ira->codegen, container_type, field);
2204322961 if (field->init_val == nullptr) {
22044 ir_add_error_node(ira, instruction->source_node,
22962 ir_add_error(ira, source_instr,
2204522963 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name)));
2204622964 any_missing = true;
2204722965 continue;
2204822966 }
2204922967 if (type_is_invalid(field->init_val->type))
22050 return ira->codegen->invalid_instruction;
22968 return ira->codegen->invalid_inst_gen;
2205122969
22052 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);
22970 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);
2205322971 copy_const_val(runtime_inst->value, field->init_val);
2205422972
22055 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,
22973 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,
2205622974 container_type, true);
22057 ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false);
22975 ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false);
2205822976 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2205922977 const_ptrs.append(field_ptr);
2206022978 } else {
......@@ -22062,39 +22980,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2206222980 }
2206322981 }
2206422982 if (any_missing)
22065 return ira->codegen->invalid_instruction;
22983 return ira->codegen->invalid_inst_gen;
2206622984
2206722985 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
2206822986 if (const_ptrs.length != actual_field_count) {
2206922987 result_loc->value->special = ConstValSpecialRuntime;
2207022988 for (size_t i = 0; i < const_ptrs.length; i += 1) {
22071 IrInstruction *field_result_loc = const_ptrs.at(i);
22072 IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr);
22989 IrInstGen *field_result_loc = const_ptrs.at(i);
22990 IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr);
2207322991 field_result_loc->value->special = ConstValSpecialRuntime;
22074 ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false);
22992 ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false);
2207522993 }
2207622994 }
2207722995 }
2207822996
22079 IrInstruction *result = ir_get_deref(ira, instruction, result_loc, nullptr);
22997 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);
2208022998
2208122999 if (is_comptime && !instr_is_comptime(result)) {
22082 ir_add_error_node(ira, first_non_const_instruction->source_node,
23000 ir_add_error_node(ira, first_non_const_instruction->base.source_node,
2208323001 buf_sprintf("unable to evaluate constant expression"));
22084 return ira->codegen->invalid_instruction;
23002 return ira->codegen->invalid_inst_gen;
2208523003 }
2208623004
2208723005 return result;
2208823006}
2208923007
22090static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22091 IrInstructionContainerInitList *instruction)
23008static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
23009 IrInstSrcContainerInitList *instruction)
2209223010{
22093 ir_assert(instruction->result_loc != nullptr, &instruction->base);
22094 IrInstruction *result_loc = instruction->result_loc->child;
23011 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
23012 IrInstGen *result_loc = instruction->result_loc->child;
2209523013 if (type_is_invalid(result_loc->value->type))
2209623014 return result_loc;
22097 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);
23015 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
2209823016
2209923017 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2210023018
......@@ -22104,24 +23022,24 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2210423022 ir_add_error_node(ira, instruction->init_array_type_source_node,
2210523023 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
2210623024 buf_ptr(&container_type->name)));
22107 return ira->codegen->invalid_instruction;
23025 return ira->codegen->invalid_inst_gen;
2210823026 }
2210923027
2211023028 if (container_type->id == ZigTypeIdVoid) {
2211123029 if (elem_count != 0) {
22112 ir_add_error_node(ira, instruction->base.source_node,
23030 ir_add_error_node(ira, instruction->base.base.source_node,
2211323031 buf_sprintf("void expression expects no arguments"));
22114 return ira->codegen->invalid_instruction;
23032 return ira->codegen->invalid_inst_gen;
2211523033 }
22116 return ir_const_void(ira, &instruction->base);
23034 return ir_const_void(ira, &instruction->base.base);
2211723035 }
2211823036
2211923037 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
22120 ir_assert(instruction->result_loc != nullptr, &instruction->base);
22121 IrInstruction *result_loc = instruction->result_loc->child;
23038 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
23039 IrInstGen *result_loc = instruction->result_loc->child;
2212223040 if (type_is_invalid(result_loc->value->type))
2212323041 return result_loc;
22124 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc);
23042 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc);
2212523043 }
2212623044
2212723045 if (container_type->id == ZigTypeIdArray) {
......@@ -22129,10 +23047,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2212923047 if (container_type->data.array.len != elem_count) {
2213023048 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);
2213123049
22132 ir_add_error(ira, &instruction->base,
23050 ir_add_error(ira, &instruction->base.base,
2213323051 buf_sprintf("expected %s literal, found %s literal",
2213423052 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
22135 return ira->codegen->invalid_instruction;
23053 return ira->codegen->invalid_inst_gen;
2213623054 }
2213723055 } else if (container_type->id == ZigTypeIdStruct &&
2213823056 container_type->data.structure.resolve_status == ResolveStatusBeingInferred)
......@@ -22142,17 +23060,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2214223060 } else if (container_type->id == ZigTypeIdVector) {
2214323061 // OK
2214423062 } else {
22145 ir_add_error_node(ira, instruction->base.source_node,
23063 ir_add_error(ira, &instruction->base.base,
2214623064 buf_sprintf("type '%s' does not support array initialization",
2214723065 buf_ptr(&container_type->name)));
22148 return ira->codegen->invalid_instruction;
23066 return ira->codegen->invalid_inst_gen;
2214923067 }
2215023068
2215123069 switch (type_has_one_possible_value(ira->codegen, container_type)) {
2215223070 case OnePossibleValueInvalid:
22153 return ira->codegen->invalid_instruction;
23071 return ira->codegen->invalid_inst_gen;
2215423072 case OnePossibleValueYes:
22155 return ir_const_move(ira, &instruction->base,
23073 return ir_const_move(ira, &instruction->base.base,
2215623074 get_the_one_possible_value(ira->codegen, container_type));
2215723075 case OnePossibleValueNo:
2215823076 break;
......@@ -22161,16 +23079,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2216123079 bool is_comptime;
2216223080 switch (type_requires_comptime(ira->codegen, container_type)) {
2216323081 case ReqCompTimeInvalid:
22164 return ira->codegen->invalid_instruction;
23082 return ira->codegen->invalid_inst_gen;
2216523083 case ReqCompTimeNo:
22166 is_comptime = ir_should_inline(ira->new_irb.exec, instruction->base.scope);
23084 is_comptime = ir_should_inline(ira->old_irb.exec, instruction->base.base.scope);
2216723085 break;
2216823086 case ReqCompTimeYes:
2216923087 is_comptime = true;
2217023088 break;
2217123089 }
2217223090
22173 IrInstruction *first_non_const_instruction = nullptr;
23091 IrInstGen *first_non_const_instruction = nullptr;
2217423092
2217523093 // The Result Location Mechanism has already emitted runtime instructions to
2217623094 // initialize runtime elements and has omitted instructions for the comptime
......@@ -22179,12 +23097,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2217923097 // array initialization can be a comptime value, overwrite ConstPtrMutInfer with
2218023098 // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the
2218123099 // elements that have comptime-known values.
22182 ZigList<IrInstruction *> const_ptrs = {};
23100 ZigList<IrInstGen *> const_ptrs = {};
2218323101
2218423102 for (size_t i = 0; i < elem_count; i += 1) {
22185 IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child;
23103 IrInstGen *elem_result_loc = instruction->elem_result_loc_list[i]->child;
2218623104 if (type_is_invalid(elem_result_loc->value->type))
22187 return ira->codegen->invalid_instruction;
23105 return ira->codegen->invalid_inst_gen;
2218823106
2218923107 assert(elem_result_loc->value->type->id == ZigTypeIdPointer);
2219023108
......@@ -22201,81 +23119,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2220123119 if (const_ptrs.length != elem_count) {
2220223120 result_loc->value->special = ConstValSpecialRuntime;
2220323121 for (size_t i = 0; i < const_ptrs.length; i += 1) {
22204 IrInstruction *elem_result_loc = const_ptrs.at(i);
23122 IrInstGen *elem_result_loc = const_ptrs.at(i);
2220523123 assert(elem_result_loc->value->special == ConstValSpecialStatic);
2220623124 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
2220723125 // This field will be generated comptime; no need to do this.
2220823126 continue;
2220923127 }
22210 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);
23128 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
2221123129 elem_result_loc->value->special = ConstValSpecialRuntime;
22212 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);
23130 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);
2221323131 }
2221423132 }
2221523133 }
2221623134
22217 IrInstruction *result = ir_get_deref(ira, &instruction->base, result_loc, nullptr);
23135 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr);
2221823136 if (instr_is_comptime(result))
2221923137 return result;
2222023138
2222123139 if (is_comptime) {
22222 ir_add_error_node(ira, first_non_const_instruction->source_node,
23140 ir_add_error(ira, &first_non_const_instruction->base,
2222323141 buf_sprintf("unable to evaluate constant expression"));
22224 return ira->codegen->invalid_instruction;
23142 return ira->codegen->invalid_inst_gen;
2222523143 }
2222623144
2222723145 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;
2222823146 if (is_slice(result_elem_type)) {
22229 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
23147 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2223023148 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",
2223123149 buf_ptr(&result_elem_type->name)));
22232 add_error_note(ira->codegen, msg, first_non_const_instruction->source_node,
23150 add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node,
2223323151 buf_sprintf("this value is not comptime-known"));
22234 return ira->codegen->invalid_instruction;
23152 return ira->codegen->invalid_inst_gen;
2223523153 }
2223623154 return result;
2223723155}
2223823156
22239static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
22240 IrInstructionContainerInitFields *instruction)
23157static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
23158 IrInstSrcContainerInitFields *instruction)
2224123159{
22242 ir_assert(instruction->result_loc != nullptr, &instruction->base);
22243 IrInstruction *result_loc = instruction->result_loc->child;
23160 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
23161 IrInstGen *result_loc = instruction->result_loc->child;
2224423162 if (type_is_invalid(result_loc->value->type))
2224523163 return result_loc;
2224623164
22247 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);
23165 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
2224823166 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2224923167
22250 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
23168 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type,
2225123169 instruction->field_count, instruction->fields, result_loc);
2225223170}
2225323171
22254static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,
22255 IrInstructionCompileErr *instruction)
22256{
22257 IrInstruction *msg_value = instruction->msg->child;
23172static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCompileErr *instruction) {
23173 IrInstGen *msg_value = instruction->msg->child;
2225823174 Buf *msg_buf = ir_resolve_str(ira, msg_value);
2225923175 if (!msg_buf)
22260 return ira->codegen->invalid_instruction;
23176 return ira->codegen->invalid_inst_gen;
2226123177
22262 ir_add_error(ira, &instruction->base, msg_buf);
23178 ir_add_error(ira, &instruction->base.base, msg_buf);
2226323179
22264 return ira->codegen->invalid_instruction;
23180 return ira->codegen->invalid_inst_gen;
2226523181}
2226623182
22267static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {
23183static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCompileLog *instruction) {
2226823184 Buf buf = BUF_INIT;
2226923185 fprintf(stderr, "| ");
2227023186 for (size_t i = 0; i < instruction->msg_count; i += 1) {
22271 IrInstruction *msg = instruction->msg_list[i]->child;
23187 IrInstGen *msg = instruction->msg_list[i]->child;
2227223188 if (type_is_invalid(msg->value->type))
22273 return ira->codegen->invalid_instruction;
23189 return ira->codegen->invalid_inst_gen;
2227423190 buf_resize(&buf, 0);
2227523191 if (msg->value->special == ConstValSpecialLazy) {
2227623192 // Resolve any lazy value that's passed, we need its value
22277 if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value))
22278 return ira->codegen->invalid_instruction;
23193 if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value))
23194 return ira->codegen->invalid_inst_gen;
2227923195 }
2228023196 render_const_value(ira->codegen, &buf, msg->value);
2228123197 const char *comma_str = (i != 0) ? ", " : "";
......@@ -22283,25 +23199,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
2228323199 }
2228423200 fprintf(stderr, "\n");
2228523201
22286 auto *expr = &instruction->base.source_node->data.fn_call_expr;
23202 auto *expr = &instruction->base.base.source_node->data.fn_call_expr;
2228723203 if (!expr->seen) {
2228823204 // Here we bypass higher level functions such as ir_add_error because we do not want
2228923205 // invalidate_exec to be called.
22290 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));
23206 add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement"));
2229123207 }
2229223208 expr->seen = true;
2229323209
22294 return ir_const_void(ira, &instruction->base);
23210 return ir_const_void(ira, &instruction->base.base);
2229523211}
2229623212
22297static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
22298 IrInstruction *value = instruction->value->child;
23213static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) {
23214 IrInstGen *value = instruction->value->child;
2229923215 if (type_is_invalid(value->value->type))
22300 return ira->codegen->invalid_instruction;
23216 return ira->codegen->invalid_inst_gen;
2230123217
22302 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);
23218 IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);
2230323219 if (type_is_invalid(casted_value->value->type))
22304 return ira->codegen->invalid_instruction;
23220 return ira->codegen->invalid_inst_gen;
2230523221
2230623222 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
2230723223 true, false, PtrLenUnknown, 0, 0, 0, false);
......@@ -22309,13 +23225,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2230923225 if (instr_is_comptime(casted_value)) {
2231023226 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
2231123227 if (val == nullptr)
22312 return ira->codegen->invalid_instruction;
23228 return ira->codegen->invalid_inst_gen;
2231323229 ErrorTableEntry *err = casted_value->value->data.x_err_set;
2231423230 if (!err->cached_error_name_val) {
2231523231 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;
2231623232 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2231723233 }
22318 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23234 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2231923235 copy_const_val(result->value, err->cached_error_name_val);
2232023236 result->value->type = str_type;
2232123237 return result;
......@@ -22323,20 +23239,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2232323239
2232423240 ira->codegen->generate_error_name_table = true;
2232523241
22326 IrInstruction *result = ir_build_err_name(&ira->new_irb,
22327 instruction->base.scope, instruction->base.source_node, value);
22328 result->value->type = str_type;
22329 return result;
23242 return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type);
2233023243}
2233123244
22332static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
23245static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) {
2233323246 Error err;
22334 IrInstruction *target = instruction->target->child;
23247 IrInstGen *target = instruction->target->child;
2233523248 if (type_is_invalid(target->value->type))
22336 return ira->codegen->invalid_instruction;
23249 return ira->codegen->invalid_inst_gen;
2233723250
2233823251 if (target->value->type->id == ZigTypeIdEnumLiteral) {
22339 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23252 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2234023253 Buf *field_name = target->value->data.x_enum_literal;
2234123254 ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee;
2234223255 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field_name), true);
......@@ -22344,9 +23257,9 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
2234423257 }
2234523258
2234623259 if (target->value->type->id == ZigTypeIdUnion) {
22347 target = ir_analyze_union_tag(ira, &instruction->base, target);
23260 target = ir_analyze_union_tag(ira, &instruction->base.base, target, instruction->base.is_gen);
2234823261 if (type_is_invalid(target->value->type))
22349 return ira->codegen->invalid_instruction;
23262 return ira->codegen->invalid_inst_gen;
2235023263 }
2235123264
2235223265 assert(target->value->type->id == ZigTypeIdEnum);
......@@ -22355,75 +23268,73 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
2235523268 !target->value->type->data.enumeration.non_exhaustive) {
2235623269 TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0];
2235723270 ZigValue *array_val = create_const_str_lit(ira->codegen, only_field->name)->data.x_ptr.data.ref.pointee;
22358 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23271 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2235923272 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true);
2236023273 return result;
2236123274 }
2236223275
2236323276 if (instr_is_comptime(target)) {
2236423277 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
22365 return ira->codegen->invalid_instruction;
23278 return ira->codegen->invalid_inst_gen;
2236623279 if (target->value->type->data.enumeration.non_exhaustive) {
22367 add_node_error(ira->codegen, instruction->base.source_node,
23280 ir_add_error(ira, &instruction->base.base,
2236823281 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));
22369 return ira->codegen->invalid_instruction;
23282 return ira->codegen->invalid_inst_gen;
2237023283 }
2237123284 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);
2237223285 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
22373 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23286 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2237423287 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true);
2237523288 return result;
2237623289 }
2237723290
22378 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
22379 instruction->base.source_node, target);
2238023291 ZigType *u8_ptr_type = get_pointer_to_type_extra(
2238123292 ira->codegen, ira->codegen->builtin_types.entry_u8,
2238223293 true, false, PtrLenUnknown,
2238323294 0, 0, 0, false);
22384 result->value->type = get_slice_type(ira->codegen, u8_ptr_type);
22385 return result;
23295 ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type);
23296 return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type);
2238623297}
2238723298
22388static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22389 IrInstructionFieldParentPtr *instruction)
23299static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
23300 IrInstSrcFieldParentPtr *instruction)
2239023301{
2239123302 Error err;
22392 IrInstruction *type_value = instruction->type_value->child;
23303 IrInstGen *type_value = instruction->type_value->child;
2239323304 ZigType *container_type = ir_resolve_type(ira, type_value);
2239423305 if (type_is_invalid(container_type))
22395 return ira->codegen->invalid_instruction;
23306 return ira->codegen->invalid_inst_gen;
2239623307
22397 IrInstruction *field_name_value = instruction->field_name->child;
23308 IrInstGen *field_name_value = instruction->field_name->child;
2239823309 Buf *field_name = ir_resolve_str(ira, field_name_value);
2239923310 if (!field_name)
22400 return ira->codegen->invalid_instruction;
23311 return ira->codegen->invalid_inst_gen;
2240123312
22402 IrInstruction *field_ptr = instruction->field_ptr->child;
23313 IrInstGen *field_ptr = instruction->field_ptr->child;
2240323314 if (type_is_invalid(field_ptr->value->type))
22404 return ira->codegen->invalid_instruction;
23315 return ira->codegen->invalid_inst_gen;
2240523316
2240623317 if (container_type->id != ZigTypeIdStruct) {
22407 ir_add_error(ira, type_value,
23318 ir_add_error(ira, &type_value->base,
2240823319 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
22409 return ira->codegen->invalid_instruction;
23320 return ira->codegen->invalid_inst_gen;
2241023321 }
2241123322
2241223323 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
22413 return ira->codegen->invalid_instruction;
23324 return ira->codegen->invalid_inst_gen;
2241423325
2241523326 TypeStructField *field = find_struct_type_field(container_type, field_name);
2241623327 if (field == nullptr) {
22417 ir_add_error(ira, field_name_value,
23328 ir_add_error(ira, &field_name_value->base,
2241823329 buf_sprintf("struct '%s' has no field '%s'",
2241923330 buf_ptr(&container_type->name), buf_ptr(field_name)));
22420 return ira->codegen->invalid_instruction;
23331 return ira->codegen->invalid_inst_gen;
2242123332 }
2242223333
2242323334 if (field_ptr->value->type->id != ZigTypeIdPointer) {
22424 ir_add_error(ira, field_ptr,
23335 ir_add_error(ira, &field_ptr->base,
2242523336 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));
22426 return ira->codegen->invalid_instruction;
23337 return ira->codegen->invalid_inst_gen;
2242723338 }
2242823339
2242923340 bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked);
......@@ -22435,9 +23346,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2243523346 field_ptr->value->type->data.pointer.is_volatile,
2243623347 PtrLenSingle,
2243723348 field_ptr_align, 0, 0, false);
22438 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
23349 IrInstGen *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
2243923350 if (type_is_invalid(casted_field_ptr->value->type))
22440 return ira->codegen->invalid_instruction;
23351 return ira->codegen->invalid_inst_gen;
2244123352
2244223353 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
2244323354 casted_field_ptr->value->type->data.pointer.is_const,
......@@ -22448,23 +23359,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2244823359 if (instr_is_comptime(casted_field_ptr)) {
2244923360 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);
2245023361 if (!field_ptr_val)
22451 return ira->codegen->invalid_instruction;
23362 return ira->codegen->invalid_inst_gen;
2245223363
2245323364 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {
22454 ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct"));
22455 return ira->codegen->invalid_instruction;
23365 ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct"));
23366 return ira->codegen->invalid_inst_gen;
2245623367 }
2245723368
2245823369 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;
2245923370 if (ptr_field_index != field->src_index) {
22460 ir_add_error(ira, &instruction->base,
23371 ir_add_error(ira, &instruction->base.base,
2246123372 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",
2246223373 buf_ptr(field->name), field->src_index,
2246323374 ptr_field_index, buf_ptr(&container_type->name)));
22464 return ira->codegen->invalid_instruction;
23375 return ira->codegen->invalid_inst_gen;
2246523376 }
2246623377
22467 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
23378 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2246823379 ZigValue *out_val = result->value;
2246923380 out_val->data.x_ptr.special = ConstPtrSpecialRef;
2247023381 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
......@@ -22472,15 +23383,12 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2247223383 return result;
2247323384 }
2247423385
22475 IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope,
22476 instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field);
22477 result->value->type = result_type;
22478 return result;
23386 return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type);
2247923387}
2248023388
2248123389static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22482 IrInstruction *type_value,
22483 IrInstruction *field_name_value,
23390 IrInstGen *type_value,
23391 IrInstGen *field_name_value,
2248423392 size_t *byte_offset)
2248523393{
2248623394 ZigType *container_type = ir_resolve_type(ira, type_value);
......@@ -22496,21 +23404,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
2249623404 return nullptr;
2249723405
2249823406 if (container_type->id != ZigTypeIdStruct) {
22499 ir_add_error(ira, type_value,
23407 ir_add_error(ira, &type_value->base,
2250023408 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
2250123409 return nullptr;
2250223410 }
2250323411
2250423412 TypeStructField *field = find_struct_type_field(container_type, field_name);
2250523413 if (field == nullptr) {
22506 ir_add_error(ira, field_name_value,
23414 ir_add_error(ira, &field_name_value->base,
2250723415 buf_sprintf("struct '%s' has no field '%s'",
2250823416 buf_ptr(&container_type->name), buf_ptr(field_name)));
2250923417 return nullptr;
2251023418 }
2251123419
2251223420 if (!type_has_bits(field->type_entry)) {
22513 ir_add_error(ira, field_name_value,
23421 ir_add_error(ira, &field_name_value->base,
2251423422 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
2251523423 buf_ptr(field_name), buf_ptr(&container_type->name)));
2251623424 return nullptr;
......@@ -22520,36 +23428,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
2252023428 return field;
2252123429}
2252223430
22523static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira,
22524 IrInstructionByteOffsetOf *instruction)
22525{
22526 IrInstruction *type_value = instruction->type_value->child;
23431static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSrcByteOffsetOf *instruction) {
23432 IrInstGen *type_value = instruction->type_value->child;
2252723433 if (type_is_invalid(type_value->value->type))
22528 return ira->codegen->invalid_instruction;
23434 return ira->codegen->invalid_inst_gen;
2252923435
22530 IrInstruction *field_name_value = instruction->field_name->child;
23436 IrInstGen *field_name_value = instruction->field_name->child;
2253123437 size_t byte_offset = 0;
2253223438 if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset))
22533 return ira->codegen->invalid_instruction;
23439 return ira->codegen->invalid_inst_gen;
2253423440
2253523441
22536 return ir_const_unsigned(ira, &instruction->base, byte_offset);
23442 return ir_const_unsigned(ira, &instruction->base.base, byte_offset);
2253723443}
2253823444
22539static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,
22540 IrInstructionBitOffsetOf *instruction)
22541{
22542 IrInstruction *type_value = instruction->type_value->child;
23445static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) {
23446 IrInstGen *type_value = instruction->type_value->child;
2254323447 if (type_is_invalid(type_value->value->type))
22544 return ira->codegen->invalid_instruction;
22545 IrInstruction *field_name_value = instruction->field_name->child;
23448 return ira->codegen->invalid_inst_gen;
23449 IrInstGen *field_name_value = instruction->field_name->child;
2254623450 size_t byte_offset = 0;
2254723451 TypeStructField *field = nullptr;
2254823452 if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset)))
22549 return ira->codegen->invalid_instruction;
23453 return ira->codegen->invalid_inst_gen;
2255023454
2255123455 size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host;
22552 return ir_const_unsigned(ira, &instruction->base, bit_offset);
23456 return ir_const_unsigned(ira, &instruction->base.base, bit_offset);
2255323457}
2255423458
2255523459static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
......@@ -22597,7 +23501,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
2259723501 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
2259823502}
2259923503
22600static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val,
23504static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,
2260123505 ScopeDecls *decls_scope)
2260223506{
2260323507 Error err;
......@@ -22955,7 +23859,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
2295523859 enum_field_val->data.x_struct.fields = inner_fields;
2295623860}
2295723861
22958static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
23862static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
2295923863 ZigValue **out)
2296023864{
2296123865 Error err;
......@@ -23543,22 +24447,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2354324447 return ErrorNone;
2354424448}
2354524449
23546static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
23547 IrInstructionTypeInfo *instruction)
23548{
24450static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcTypeInfo *instruction) {
2354924451 Error err;
23550 IrInstruction *type_value = instruction->type_value->child;
24452 IrInstGen *type_value = instruction->type_value->child;
2355124453 ZigType *type_entry = ir_resolve_type(ira, type_value);
2355224454 if (type_is_invalid(type_entry))
23553 return ira->codegen->invalid_instruction;
24455 return ira->codegen->invalid_inst_gen;
2355424456
2355524457 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
2355624458
2355724459 ZigValue *payload;
23558 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))
23559 return ira->codegen->invalid_instruction;
24460 if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload)))
24461 return ira->codegen->invalid_inst_gen;
2356024462
23561 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
24463 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2356224464 ZigValue *out_val = result->value;
2356324465 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
2356424466 out_val->data.x_union.payload = payload;
......@@ -23582,15 +24484,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
2358224484 return val;
2358324485}
2358424486
23585static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
24487static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value,
2358624488 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
2358724489{
2358824490 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
2358924491 if (field_val == nullptr)
2359024492 return ErrorSemanticAnalyzeFail;
2359124493
23592 IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val);
23593 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
24494 IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val);
24495 IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst,
2359424496 get_optional_type(ira->codegen, elem_type));
2359524497 if (type_is_invalid(casted_field_inst->value->type))
2359624498 return ErrorSemanticAnalyzeFail;
......@@ -23629,12 +24531,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node,
2362924531{
2363024532 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
2363124533 if (value == nullptr)
23632 return ira->codegen->invalid_instruction->value->type;
24534 return ira->codegen->invalid_inst_gen->value->type;
2363324535 assert(value->type == ira->codegen->builtin_types.entry_type);
2363424536 return value->data.x_type;
2363524537}
2363624538
23637static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) {
24539static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) {
2363824540 Error err;
2363924541 switch (tagTypeId) {
2364024542 case ZigTypeIdInvalid:
......@@ -23650,21 +24552,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2365024552 case ZigTypeIdInt: {
2365124553 assert(payload->special == ConstValSpecialStatic);
2365224554 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
23653 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);
24555 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);
2365424556 if (bi == nullptr)
23655 return ira->codegen->invalid_instruction->value->type;
24557 return ira->codegen->invalid_inst_gen->value->type;
2365624558 bool is_signed;
23657 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed)))
23658 return ira->codegen->invalid_instruction->value->type;
24559 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed)))
24560 return ira->codegen->invalid_inst_gen->value->type;
2365924561 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
2366024562 }
2366124563 case ZigTypeIdFloat:
2366224564 {
2366324565 assert(payload->special == ConstValSpecialStatic);
2366424566 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
23665 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0);
24567 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0);
2366624568 if (bi == nullptr)
23667 return ira->codegen->invalid_instruction->value->type;
24569 return ira->codegen->invalid_inst_gen->value->type;
2366824570 uint32_t bits = bigint_as_u32(bi);
2366924571 switch (bits) {
2367024572 case 16: return ira->codegen->builtin_types.entry_f16;
......@@ -23672,48 +24574,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2367224574 case 64: return ira->codegen->builtin_types.entry_f64;
2367324575 case 128: return ira->codegen->builtin_types.entry_f128;
2367424576 }
23675 ir_add_error(ira, instruction,
23676 buf_sprintf("%d-bit float unsupported", bits));
23677 return ira->codegen->invalid_instruction->value->type;
24577 ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits));
24578 return ira->codegen->invalid_inst_gen->value->type;
2367824579 }
2367924580 case ZigTypeIdPointer:
2368024581 {
2368124582 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2368224583 assert(payload->special == ConstValSpecialStatic);
2368324584 assert(payload->type == type_info_pointer_type);
23684 ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0);
24585 ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0);
2368524586 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
2368624587 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
2368724588 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
23688 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4);
24589 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4);
2368924590 if (type_is_invalid(elem_type))
23690 return ira->codegen->invalid_instruction->value->type;
24591 return ira->codegen->invalid_inst_gen->value->type;
2369124592 ZigValue *sentinel;
23692 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
24593 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6,
2369324594 elem_type, &sentinel)))
2369424595 {
23695 return ira->codegen->invalid_instruction->value->type;
24596 return ira->codegen->invalid_inst_gen->value->type;
2369624597 }
23697 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3);
24598 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3);
2369824599 if (bi == nullptr)
23699 return ira->codegen->invalid_instruction->value->type;
24600 return ira->codegen->invalid_inst_gen->value->type;
2370024601
2370124602 bool is_const;
23702 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const)))
23703 return ira->codegen->invalid_instruction->value->type;
24603 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const)))
24604 return ira->codegen->invalid_inst_gen->value->type;
2370424605
2370524606 bool is_volatile;
23706 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2,
24607 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2,
2370724608 &is_volatile)))
2370824609 {
23709 return ira->codegen->invalid_instruction->value->type;
24610 return ira->codegen->invalid_inst_gen->value->type;
2371024611 }
2371124612
2371224613 bool is_allowzero;
23713 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5,
24614 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5,
2371424615 &is_allowzero)))
2371524616 {
23716 return ira->codegen->invalid_instruction->value->type;
24617 return ira->codegen->invalid_inst_gen->value->type;
2371724618 }
2371824619
2371924620
......@@ -23734,18 +24635,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2373424635 case ZigTypeIdArray: {
2373524636 assert(payload->special == ConstValSpecialStatic);
2373624637 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
23737 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1);
24638 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1);
2373824639 if (type_is_invalid(elem_type))
23739 return ira->codegen->invalid_instruction->value->type;
24640 return ira->codegen->invalid_inst_gen->value->type;
2374024641 ZigValue *sentinel;
23741 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
24642 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2,
2374224643 elem_type, &sentinel)))
2374324644 {
23744 return ira->codegen->invalid_instruction->value->type;
24645 return ira->codegen->invalid_inst_gen->value->type;
2374524646 }
23746 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);
24647 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0);
2374724648 if (bi == nullptr)
23748 return ira->codegen->invalid_instruction->value->type;
24649 return ira->codegen->invalid_inst_gen->value->type;
2374924650 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
2375024651 }
2375124652 case ZigTypeIdComptimeFloat:
......@@ -23765,78 +24666,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2376524666 case ZigTypeIdAnyFrame:
2376624667 case ZigTypeIdVector:
2376724668 case ZigTypeIdEnumLiteral:
23768 ir_add_error(ira, instruction, buf_sprintf(
24669 ir_add_error(ira, source_instr, buf_sprintf(
2376924670 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
23770 return ira->codegen->invalid_instruction->value->type;
24671 return ira->codegen->invalid_inst_gen->value->type;
2377124672 case ZigTypeIdUnion:
2377224673 case ZigTypeIdFn:
2377324674 case ZigTypeIdBoundFn:
2377424675 case ZigTypeIdStruct:
23775 ir_add_error(ira, instruction, buf_sprintf(
24676 ir_add_error(ira, source_instr, buf_sprintf(
2377624677 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
23777 return ira->codegen->invalid_instruction->value->type;
24678 return ira->codegen->invalid_inst_gen->value->type;
2377824679 }
2377924680 zig_unreachable();
2378024681}
2378124682
23782static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {
23783 IrInstruction *type_info_ir = instruction->type_info->child;
23784 if (type_is_invalid(type_info_ir->value->type))
23785 return ira->codegen->invalid_instruction;
24683static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *instruction) {
24684 IrInstGen *uncasted_type_info = instruction->type_info->child;
24685 if (type_is_invalid(uncasted_type_info->value->type))
24686 return ira->codegen->invalid_inst_gen;
2378624687
23787 IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));
23788 if (type_is_invalid(casted_ir->value->type))
23789 return ira->codegen->invalid_instruction;
24688 IrInstGen *type_info = ir_implicit_cast(ira, uncasted_type_info, ir_type_info_get_type(ira, nullptr, nullptr));
24689 if (type_is_invalid(type_info->value->type))
24690 return ira->codegen->invalid_inst_gen;
2379024691
23791 ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);
23792 if (!type_info_value)
23793 return ira->codegen->invalid_instruction;
23794 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
23795 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);
24692 ZigValue *type_info_val = ir_resolve_const(ira, type_info, UndefBad);
24693 if (type_info_val == nullptr)
24694 return ira->codegen->invalid_inst_gen;
24695 ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag));
24696 ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag,
24697 type_info_val->data.x_union.payload);
2379624698 if (type_is_invalid(type))
23797 return ira->codegen->invalid_instruction;
23798 return ir_const_type(ira, &instruction->base, type);
24699 return ira->codegen->invalid_inst_gen;
24700 return ir_const_type(ira, &instruction->base.base, type);
2379924701}
2380024702
23801static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,
23802 IrInstructionTypeId *instruction)
23803{
23804 IrInstruction *type_value = instruction->type_value->child;
24703static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
24704 IrInstGen *type_value = instruction->type_value->child;
2380524705 ZigType *type_entry = ir_resolve_type(ira, type_value);
2380624706 if (type_is_invalid(type_entry))
23807 return ira->codegen->invalid_instruction;
24707 return ira->codegen->invalid_inst_gen;
2380824708
2380924709 ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");
2381024710
23811 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
24711 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2381224712 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
2381324713 return result;
2381424714}
2381524715
23816static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
23817 IrInstructionSetEvalBranchQuota *instruction)
24716static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
24717 IrInstSrcSetEvalBranchQuota *instruction)
2381824718{
2381924719 uint64_t new_quota;
2382024720 if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota))
23821 return ira->codegen->invalid_instruction;
24721 return ira->codegen->invalid_inst_gen;
2382224722
2382324723 if (new_quota > *ira->new_irb.exec->backward_branch_quota) {
2382424724 *ira->new_irb.exec->backward_branch_quota = new_quota;
2382524725 }
2382624726
23827 return ir_const_void(ira, &instruction->base);
24727 return ir_const_void(ira, &instruction->base.base);
2382824728}
2382924729
23830static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
23831 IrInstruction *type_value = instruction->type_value->child;
24730static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) {
24731 IrInstGen *type_value = instruction->type_value->child;
2383224732 ZigType *type_entry = ir_resolve_type(ira, type_value);
2383324733 if (type_is_invalid(type_entry))
23834 return ira->codegen->invalid_instruction;
24734 return ira->codegen->invalid_inst_gen;
2383524735
2383624736 if (!type_entry->cached_const_name_val) {
2383724737 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
2383824738 }
23839 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
24739 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2384024740 copy_const_val(result->value, type_entry->cached_const_name_val);
2384124741 return result;
2384224742}
......@@ -23848,13 +24748,13 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf *
2384824748 buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest));
2384924749 buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir));
2385024750}
23851static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {
24751static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {
2385224752 Error err;
23853 AstNode *node = instruction->base.source_node;
24753 AstNode *node = instruction->base.base.source_node;
2385424754 assert(node->type == NodeTypeFnCallExpr);
2385524755 AstNode *block_node = node->data.fn_call_expr.params.at(0);
2385624756
23857 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope);
24757 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope);
2385824758
2385924759 // Execute the C import block like an inline function
2386024760 ZigType *void_type = ira->codegen->builtin_types.entry_void;
......@@ -23862,9 +24762,9 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2386224762 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
2386324763 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);
2386424764 if (type_is_invalid(cimport_result->type))
23865 return ira->codegen->invalid_instruction;
24765 return ira->codegen->invalid_inst_gen;
2386624766
23867 ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope);
24767 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);
2386824768 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,
2386924769 buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1);
2387024770
......@@ -23876,7 +24776,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2387624776 CacheHash *cache_hash;
2387724777 if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) {
2387824778 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err)));
23879 return ira->codegen->invalid_instruction;
24779 return ira->codegen->invalid_inst_gen;
2388024780 }
2388124781 cache_buf(cache_hash, &cimport_scope->buf);
2388224782
......@@ -23888,7 +24788,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2388824788 if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) {
2388924789 if (err != ErrorInvalidFormat) {
2389024790 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err)));
23891 return ira->codegen->invalid_instruction;
24791 return ira->codegen->invalid_inst_gen;
2389224792 }
2389324793 }
2389424794 ira->codegen->caches_to_release.append(cache_hash);
......@@ -23907,12 +24807,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2390724807
2390824808 if ((err = os_make_path(tmp_c_file_dir))) {
2390924809 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));
23910 return ira->codegen->invalid_instruction;
24810 return ira->codegen->invalid_inst_gen;
2391124811 }
2391224812
2391324813 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {
2391424814 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));
23915 return ira->codegen->invalid_instruction;
24815 return ira->codegen->invalid_inst_gen;
2391624816 }
2391724817 if (ira->codegen->verbose_cimport) {
2391824818 fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path));
......@@ -23947,7 +24847,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2394724847 {
2394824848 if (err != ErrorCCompileErrors) {
2394924849 ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));
23950 return ira->codegen->invalid_instruction;
24850 return ira->codegen->invalid_inst_gen;
2395124851 }
2395224852
2395324853 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
......@@ -23968,7 +24868,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2396824868 }
2396924869 }
2397024870
23971 return ira->codegen->invalid_instruction;
24871 return ira->codegen->invalid_inst_gen;
2397224872 }
2397324873 if (ira->codegen->verbose_cimport) {
2397424874 fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file));
......@@ -23976,29 +24876,29 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2397624876
2397724877 if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) {
2397824878 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err)));
23979 return ira->codegen->invalid_instruction;
24879 return ira->codegen->invalid_inst_gen;
2398024880 }
2398124881 if ((err = cache_final(cache_hash, &tmp_c_file_digest))) {
2398224882 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err)));
23983 return ira->codegen->invalid_instruction;
24883 return ira->codegen->invalid_inst_gen;
2398424884 }
2398524885
2398624886 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);
2398724887 if ((err = os_make_path(out_zig_dir))) {
2398824888 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err)));
23989 return ira->codegen->invalid_instruction;
24889 return ira->codegen->invalid_inst_gen;
2399024890 }
2399124891 FILE *out_file = fopen(buf_ptr(out_zig_path), "wb");
2399224892 if (out_file == nullptr) {
2399324893 ir_add_error_node(ira, node,
2399424894 buf_sprintf("C import failed: unable to open output file: %s", strerror(errno)));
23995 return ira->codegen->invalid_instruction;
24895 return ira->codegen->invalid_inst_gen;
2399624896 }
2399724897 stage2_render_ast(ast, out_file);
2399824898 if (fclose(out_file) != 0) {
2399924899 ir_add_error_node(ira, node,
2400024900 buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno)));
24001 return ira->codegen->invalid_instruction;
24901 return ira->codegen->invalid_inst_gen;
2400224902 }
2400324903
2400424904 if (ira->codegen->verbose_cimport) {
......@@ -24017,90 +24917,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2401724917 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {
2401824918 ir_add_error_node(ira, node,
2401924919 buf_sprintf("unable to open '%s': %s", buf_ptr(out_zig_path), err_str(err)));
24020 return ira->codegen->invalid_instruction;
24920 return ira->codegen->invalid_inst_gen;
2402124921 }
2402224922 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,
2402324923 import_code, SourceKindCImport);
24024 return ir_const_type(ira, &instruction->base, child_import);
24924 return ir_const_type(ira, &instruction->base.base, child_import);
2402524925}
2402624926
24027static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
24028 IrInstruction *name_value = instruction->name->child;
24927static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) {
24928 IrInstGen *name_value = instruction->name->child;
2402924929 if (type_is_invalid(name_value->value->type))
24030 return ira->codegen->invalid_instruction;
24930 return ira->codegen->invalid_inst_gen;
2403124931
2403224932 Buf *include_name = ir_resolve_str(ira, name_value);
2403324933 if (!include_name)
24034 return ira->codegen->invalid_instruction;
24934 return ira->codegen->invalid_inst_gen;
2403524935
24036 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);
24936 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
2403724937 // We check for this error in pass1
2403824938 assert(c_import_buf);
2403924939
2404024940 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));
2404124941
24042 return ir_const_void(ira, &instruction->base);
24942 return ir_const_void(ira, &instruction->base.base);
2404324943}
2404424944
24045static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
24046 IrInstruction *name = instruction->name->child;
24945static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) {
24946 IrInstGen *name = instruction->name->child;
2404724947 if (type_is_invalid(name->value->type))
24048 return ira->codegen->invalid_instruction;
24948 return ira->codegen->invalid_inst_gen;
2404924949
2405024950 Buf *define_name = ir_resolve_str(ira, name);
2405124951 if (!define_name)
24052 return ira->codegen->invalid_instruction;
24952 return ira->codegen->invalid_inst_gen;
2405324953
24054 IrInstruction *value = instruction->value->child;
24954 IrInstGen *value = instruction->value->child;
2405524955 if (type_is_invalid(value->value->type))
24056 return ira->codegen->invalid_instruction;
24956 return ira->codegen->invalid_inst_gen;
2405724957
2405824958 Buf *define_value = nullptr;
2405924959 // The second parameter is either a string or void (equivalent to "")
2406024960 if (value->value->type->id != ZigTypeIdVoid) {
2406124961 define_value = ir_resolve_str(ira, value);
2406224962 if (!define_value)
24063 return ira->codegen->invalid_instruction;
24963 return ira->codegen->invalid_inst_gen;
2406424964 }
2406524965
24066 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);
24966 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
2406724967 // We check for this error in pass1
2406824968 assert(c_import_buf);
2406924969
2407024970 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),
2407124971 define_value ? buf_ptr(define_value) : "");
2407224972
24073 return ir_const_void(ira, &instruction->base);
24973 return ir_const_void(ira, &instruction->base.base);
2407424974}
2407524975
24076static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
24077 IrInstruction *name = instruction->name->child;
24976static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) {
24977 IrInstGen *name = instruction->name->child;
2407824978 if (type_is_invalid(name->value->type))
24079 return ira->codegen->invalid_instruction;
24979 return ira->codegen->invalid_inst_gen;
2408024980
2408124981 Buf *undef_name = ir_resolve_str(ira, name);
2408224982 if (!undef_name)
24083 return ira->codegen->invalid_instruction;
24983 return ira->codegen->invalid_inst_gen;
2408424984
24085 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);
24985 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
2408624986 // We check for this error in pass1
2408724987 assert(c_import_buf);
2408824988
2408924989 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));
2409024990
24091 return ir_const_void(ira, &instruction->base);
24991 return ir_const_void(ira, &instruction->base.base);
2409224992}
2409324993
24094static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
24095 IrInstruction *name = instruction->name->child;
24994static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) {
24995 IrInstGen *name = instruction->name->child;
2409624996 if (type_is_invalid(name->value->type))
24097 return ira->codegen->invalid_instruction;
24997 return ira->codegen->invalid_inst_gen;
2409824998
2409924999 Buf *rel_file_path = ir_resolve_str(ira, name);
2410025000 if (!rel_file_path)
24101 return ira->codegen->invalid_instruction;
25001 return ira->codegen->invalid_inst_gen;
2410225002
24103 ZigType *import = get_scope_import(instruction->base.scope);
25003 ZigType *import = get_scope_import(instruction->base.base.scope);
2410425004 // figure out absolute path to resource
2410525005 Buf source_dir_path = BUF_INIT;
2410625006 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);
......@@ -24117,93 +25017,95 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
2411725017 Error err;
2411825018 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {
2411925019 if (err == ErrorFileNotFound) {
24120 ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
24121 return ira->codegen->invalid_instruction;
25020 ir_add_error(ira, &instruction->name->base,
25021 buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
25022 return ira->codegen->invalid_inst_gen;
2412225023 } else {
24123 ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
24124 return ira->codegen->invalid_instruction;
25024 ir_add_error(ira, &instruction->name->base,
25025 buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
25026 return ira->codegen->invalid_inst_gen;
2412525027 }
2412625028 }
2412725029
2412825030 ZigType *result_type = get_array_type(ira->codegen,
2412925031 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);
24130 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
25032 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2413125033 init_const_str_lit(ira->codegen, result->value, file_contents);
2413225034 return result;
2413325035}
2413425036
24135static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchgSrc *instruction) {
25037static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) {
2413625038 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child);
2413725039 if (type_is_invalid(operand_type))
24138 return ira->codegen->invalid_instruction;
25040 return ira->codegen->invalid_inst_gen;
2413925041
2414025042 if (operand_type->id == ZigTypeIdFloat) {
24141 ir_add_error(ira, instruction->type_value->child,
25043 ir_add_error(ira, &instruction->type_value->child->base,
2414225044 buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
24143 return ira->codegen->invalid_instruction;
25045 return ira->codegen->invalid_inst_gen;
2414425046 }
2414525047
24146 IrInstruction *ptr = instruction->ptr->child;
25048 IrInstGen *ptr = instruction->ptr->child;
2414725049 if (type_is_invalid(ptr->value->type))
24148 return ira->codegen->invalid_instruction;
25050 return ira->codegen->invalid_inst_gen;
2414925051
2415025052 // TODO let this be volatile
2415125053 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
24152 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
25054 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
2415325055 if (type_is_invalid(casted_ptr->value->type))
24154 return ira->codegen->invalid_instruction;
25056 return ira->codegen->invalid_inst_gen;
2415525057
24156 IrInstruction *cmp_value = instruction->cmp_value->child;
25058 IrInstGen *cmp_value = instruction->cmp_value->child;
2415725059 if (type_is_invalid(cmp_value->value->type))
24158 return ira->codegen->invalid_instruction;
25060 return ira->codegen->invalid_inst_gen;
2415925061
24160 IrInstruction *new_value = instruction->new_value->child;
25062 IrInstGen *new_value = instruction->new_value->child;
2416125063 if (type_is_invalid(new_value->value->type))
24162 return ira->codegen->invalid_instruction;
25064 return ira->codegen->invalid_inst_gen;
2416325065
24164 IrInstruction *success_order_value = instruction->success_order_value->child;
25066 IrInstGen *success_order_value = instruction->success_order_value->child;
2416525067 if (type_is_invalid(success_order_value->value->type))
24166 return ira->codegen->invalid_instruction;
25068 return ira->codegen->invalid_inst_gen;
2416725069
2416825070 AtomicOrder success_order;
2416925071 if (!ir_resolve_atomic_order(ira, success_order_value, &success_order))
24170 return ira->codegen->invalid_instruction;
25072 return ira->codegen->invalid_inst_gen;
2417125073
24172 IrInstruction *failure_order_value = instruction->failure_order_value->child;
25074 IrInstGen *failure_order_value = instruction->failure_order_value->child;
2417325075 if (type_is_invalid(failure_order_value->value->type))
24174 return ira->codegen->invalid_instruction;
25076 return ira->codegen->invalid_inst_gen;
2417525077
2417625078 AtomicOrder failure_order;
2417725079 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
24178 return ira->codegen->invalid_instruction;
25080 return ira->codegen->invalid_inst_gen;
2417925081
24180 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);
25082 IrInstGen *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);
2418125083 if (type_is_invalid(casted_cmp_value->value->type))
24182 return ira->codegen->invalid_instruction;
25084 return ira->codegen->invalid_inst_gen;
2418325085
24184 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);
25086 IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);
2418525087 if (type_is_invalid(casted_new_value->value->type))
24186 return ira->codegen->invalid_instruction;
25088 return ira->codegen->invalid_inst_gen;
2418725089
2418825090 if (success_order < AtomicOrderMonotonic) {
24189 ir_add_error(ira, success_order_value,
25091 ir_add_error(ira, &success_order_value->base,
2419025092 buf_sprintf("success atomic ordering must be Monotonic or stricter"));
24191 return ira->codegen->invalid_instruction;
25093 return ira->codegen->invalid_inst_gen;
2419225094 }
2419325095 if (failure_order < AtomicOrderMonotonic) {
24194 ir_add_error(ira, failure_order_value,
25096 ir_add_error(ira, &failure_order_value->base,
2419525097 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));
24196 return ira->codegen->invalid_instruction;
25098 return ira->codegen->invalid_inst_gen;
2419725099 }
2419825100 if (failure_order > success_order) {
24199 ir_add_error(ira, failure_order_value,
25101 ir_add_error(ira, &failure_order_value->base,
2420025102 buf_sprintf("failure atomic ordering must be no stricter than success"));
24201 return ira->codegen->invalid_instruction;
25103 return ira->codegen->invalid_inst_gen;
2420225104 }
2420325105 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {
24204 ir_add_error(ira, failure_order_value,
25106 ir_add_error(ira, &failure_order_value->base,
2420525107 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));
24206 return ira->codegen->invalid_instruction;
25108 return ira->codegen->invalid_inst_gen;
2420725109 }
2420825110
2420925111 if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
......@@ -24212,66 +25114,63 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2421225114 }
2421325115
2421425116 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
24215 IrInstruction *result_loc;
25117 IrInstGen *result_loc;
2421625118 if (handle_is_ptr(result_type)) {
24217 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
25119 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2421825120 result_type, nullptr, true, false, true);
24219 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
25121 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2422025122 return result_loc;
2422125123 }
2422225124 } else {
2422325125 result_loc = nullptr;
2422425126 }
2422525127
24226 return ir_build_cmpxchg_gen(ira, &instruction->base, result_type,
25128 return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type,
2422725129 casted_ptr, casted_cmp_value, casted_new_value,
2422825130 success_order, failure_order, instruction->is_weak, result_loc);
2422925131}
2423025132
24231static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
24232 IrInstruction *order_value = instruction->order_value->child;
24233 if (type_is_invalid(order_value->value->type))
24234 return ira->codegen->invalid_instruction;
25133static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) {
25134 IrInstGen *order_inst = instruction->order->child;
25135 if (type_is_invalid(order_inst->value->type))
25136 return ira->codegen->invalid_inst_gen;
2423525137
2423625138 AtomicOrder order;
24237 if (!ir_resolve_atomic_order(ira, order_value, &order))
24238 return ira->codegen->invalid_instruction;
25139 if (!ir_resolve_atomic_order(ira, order_inst, &order))
25140 return ira->codegen->invalid_inst_gen;
2423925141
2424025142 if (order < AtomicOrderAcquire) {
24241 ir_add_error(ira, order_value,
25143 ir_add_error(ira, &order_inst->base,
2424225144 buf_sprintf("atomic ordering must be Acquire or stricter"));
24243 return ira->codegen->invalid_instruction;
25145 return ira->codegen->invalid_inst_gen;
2424425146 }
2424525147
24246 IrInstruction *result = ir_build_fence(&ira->new_irb,
24247 instruction->base.scope, instruction->base.source_node, order_value, order);
24248 result->value->type = ira->codegen->builtin_types.entry_void;
24249 return result;
25148 return ir_build_fence_gen(ira, &instruction->base.base, order);
2425025149}
2425125150
24252static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
24253 IrInstruction *dest_type_value = instruction->dest_type->child;
25151static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) {
25152 IrInstGen *dest_type_value = instruction->dest_type->child;
2425425153 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2425525154 if (type_is_invalid(dest_type))
24256 return ira->codegen->invalid_instruction;
25155 return ira->codegen->invalid_inst_gen;
2425725156
2425825157 if (dest_type->id != ZigTypeIdInt &&
2425925158 dest_type->id != ZigTypeIdComptimeInt)
2426025159 {
24261 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24262 return ira->codegen->invalid_instruction;
25160 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
25161 return ira->codegen->invalid_inst_gen;
2426325162 }
2426425163
24265 IrInstruction *target = instruction->target->child;
25164 IrInstGen *target = instruction->target->child;
2426625165 ZigType *src_type = target->value->type;
2426725166 if (type_is_invalid(src_type))
24268 return ira->codegen->invalid_instruction;
25167 return ira->codegen->invalid_inst_gen;
2426925168
2427025169 if (src_type->id != ZigTypeIdInt &&
2427125170 src_type->id != ZigTypeIdComptimeInt)
2427225171 {
24273 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
24274 return ira->codegen->invalid_instruction;
25172 ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
25173 return ira->codegen->invalid_inst_gen;
2427525174 }
2427625175
2427725176 if (dest_type->id == ZigTypeIdComptimeInt) {
......@@ -24281,54 +25180,51 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
2428125180 if (instr_is_comptime(target)) {
2428225181 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2428325182 if (val == nullptr)
24284 return ira->codegen->invalid_instruction;
25183 return ira->codegen->invalid_inst_gen;
2428525184
24286 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
25185 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
2428725186 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,
2428825187 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
2428925188 return result;
2429025189 }
2429125190
2429225191 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {
24293 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
25192 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
2429425193 bigint_init_unsigned(&result->value->data.x_bigint, 0);
2429525194 return result;
2429625195 }
2429725196
2429825197 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
2429925198 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
24300 ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
24301 return ira->codegen->invalid_instruction;
25199 ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
25200 return ira->codegen->invalid_inst_gen;
2430225201 } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {
24303 ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
25202 ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
2430425203 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
24305 return ira->codegen->invalid_instruction;
25204 return ira->codegen->invalid_inst_gen;
2430625205 }
2430725206
24308 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,
24309 instruction->base.source_node, dest_type_value, target);
24310 new_instruction->value->type = dest_type;
24311 return new_instruction;
25207 return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target);
2431225208}
2431325209
24314static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
25210static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) {
2431525211 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2431625212 if (type_is_invalid(dest_type))
24317 return ira->codegen->invalid_instruction;
25213 return ira->codegen->invalid_inst_gen;
2431825214
2431925215 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {
24320 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24321 return ira->codegen->invalid_instruction;
25216 ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
25217 return ira->codegen->invalid_inst_gen;
2432225218 }
2432325219
24324 IrInstruction *target = instruction->target->child;
25220 IrInstGen *target = instruction->target->child;
2432525221 if (type_is_invalid(target->value->type))
24326 return ira->codegen->invalid_instruction;
25222 return ira->codegen->invalid_inst_gen;
2432725223
2432825224 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
24329 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
25225 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'",
2433025226 buf_ptr(&target->value->type->name)));
24331 return ira->codegen->invalid_instruction;
25227 return ira->codegen->invalid_inst_gen;
2433225228 }
2433325229
2433425230 if (instr_is_comptime(target)) {
......@@ -24336,28 +25232,28 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
2433625232 }
2433725233
2433825234 if (dest_type->id == ZigTypeIdComptimeInt) {
24339 ir_add_error(ira, instruction->target, buf_sprintf("attempt to cast runtime value to '%s'",
25235 ir_add_error(ira, &instruction->target->base, buf_sprintf("attempt to cast runtime value to '%s'",
2434025236 buf_ptr(&dest_type->name)));
24341 return ira->codegen->invalid_instruction;
25237 return ira->codegen->invalid_inst_gen;
2434225238 }
2434325239
24344 return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);
25240 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
2434525241}
2434625242
24347static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
25243static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) {
2434825244 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2434925245 if (type_is_invalid(dest_type))
24350 return ira->codegen->invalid_instruction;
25246 return ira->codegen->invalid_inst_gen;
2435125247
2435225248 if (dest_type->id != ZigTypeIdFloat) {
24353 ir_add_error(ira, instruction->dest_type,
25249 ir_add_error(ira, &instruction->dest_type->base,
2435425250 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
24355 return ira->codegen->invalid_instruction;
25251 return ira->codegen->invalid_inst_gen;
2435625252 }
2435725253
24358 IrInstruction *target = instruction->target->child;
25254 IrInstGen *target = instruction->target->child;
2435925255 if (type_is_invalid(target->value->type))
24360 return ira->codegen->invalid_instruction;
25256 return ira->codegen->invalid_inst_gen;
2436125257
2436225258 if (target->value->type->id == ZigTypeIdComptimeInt ||
2436325259 target->value->type->id == ZigTypeIdComptimeFloat)
......@@ -24369,55 +25265,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
2436925265 } else {
2437025266 op = CastOpNumLitToConcrete;
2437125267 }
24372 return ir_resolve_cast(ira, &instruction->base, target, dest_type, op);
25268 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op);
2437325269 } else {
24374 return ira->codegen->invalid_instruction;
25270 return ira->codegen->invalid_inst_gen;
2437525271 }
2437625272 }
2437725273
2437825274 if (target->value->type->id != ZigTypeIdFloat) {
24379 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
25275 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'",
2438025276 buf_ptr(&target->value->type->name)));
24381 return ira->codegen->invalid_instruction;
25277 return ira->codegen->invalid_inst_gen;
2438225278 }
2438325279
24384 return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);
25280 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
2438525281}
2438625282
24387static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
25283static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) {
2438825284 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2438925285 if (type_is_invalid(dest_type))
24390 return ira->codegen->invalid_instruction;
25286 return ira->codegen->invalid_inst_gen;
2439125287
2439225288 if (dest_type->id != ZigTypeIdErrorSet) {
24393 ir_add_error(ira, instruction->dest_type,
25289 ir_add_error(ira, &instruction->dest_type->base,
2439425290 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
24395 return ira->codegen->invalid_instruction;
25291 return ira->codegen->invalid_inst_gen;
2439625292 }
2439725293
24398 IrInstruction *target = instruction->target->child;
25294 IrInstGen *target = instruction->target->child;
2439925295 if (type_is_invalid(target->value->type))
24400 return ira->codegen->invalid_instruction;
25296 return ira->codegen->invalid_inst_gen;
2440125297
2440225298 if (target->value->type->id != ZigTypeIdErrorSet) {
24403 ir_add_error(ira, instruction->target,
25299 ir_add_error(ira, &instruction->target->base,
2440425300 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));
24405 return ira->codegen->invalid_instruction;
25301 return ira->codegen->invalid_inst_gen;
2440625302 }
2440725303
24408 return ir_analyze_err_set_cast(ira, &instruction->base, target, dest_type);
25304 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);
2440925305}
2441025306
24411static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
25307static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) {
2441225308 Error err;
2441325309
2441425310 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);
2441525311 if (type_is_invalid(dest_child_type))
24416 return ira->codegen->invalid_instruction;
25312 return ira->codegen->invalid_inst_gen;
2441725313
24418 IrInstruction *target = instruction->target->child;
25314 IrInstGen *target = instruction->target->child;
2441925315 if (type_is_invalid(target->value->type))
24420 return ira->codegen->invalid_instruction;
25316 return ira->codegen->invalid_inst_gen;
2442125317
2442225318 bool src_ptr_const;
2442325319 bool src_ptr_volatile;
......@@ -24427,27 +25323,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2442725323 src_ptr_volatile = target->value->type->data.pointer.is_volatile;
2442825324
2442925325 if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))
24430 return ira->codegen->invalid_instruction;
25326 return ira->codegen->invalid_inst_gen;
2443125327 } else if (is_slice(target->value->type)) {
2443225328 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2443325329 src_ptr_const = src_ptr_type->data.pointer.is_const;
2443425330 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
2443525331
2443625332 if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align)))
24437 return ira->codegen->invalid_instruction;
25333 return ira->codegen->invalid_inst_gen;
2443825334 } else {
2443925335 src_ptr_const = true;
2444025336 src_ptr_volatile = false;
2444125337
2444225338 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))
24443 return ira->codegen->invalid_instruction;
25339 return ira->codegen->invalid_inst_gen;
2444425340
2444525341 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);
2444625342 }
2444725343
2444825344 if (src_ptr_align != 0) {
2444925345 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))
24450 return ira->codegen->invalid_instruction;
25346 return ira->codegen->invalid_inst_gen;
2445125347 }
2445225348
2445325349 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
......@@ -24460,9 +25356,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2446025356 src_ptr_align, 0, 0, false);
2446125357 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
2446225358
24463 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);
25359 IrInstGen *casted_value = ir_implicit_cast(ira, target, u8_slice);
2446425360 if (type_is_invalid(casted_value->value->type))
24465 return ira->codegen->invalid_instruction;
25361 return ira->codegen->invalid_inst_gen;
2446625362
2446725363 bool have_known_len = false;
2446825364 uint64_t known_len;
......@@ -24470,7 +25366,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2447025366 if (instr_is_comptime(casted_value)) {
2447125367 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
2447225368 if (!val)
24473 return ira->codegen->invalid_instruction;
25369 return ira->codegen->invalid_inst_gen;
2447425370
2447525371 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
2447625372 if (value_is_comptime(len_val)) {
......@@ -24479,9 +25375,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2447925375 }
2448025376 }
2448125377
24482 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
25378 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2448325379 dest_slice_type, nullptr, true, false, true);
24484 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) {
25380 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) {
2448525381 return result_loc;
2448625382 }
2448725383
......@@ -24498,41 +25394,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2449825394
2449925395 if (have_known_len) {
2450025396 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))
24501 return ira->codegen->invalid_instruction;
25397 return ira->codegen->invalid_inst_gen;
2450225398 uint64_t child_type_size = type_size(ira->codegen, dest_child_type);
2450325399 uint64_t remainder = known_len % child_type_size;
2450425400 if (remainder != 0) {
24505 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
25401 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2450625402 buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",
2450725403 known_len, buf_ptr(&dest_slice_type->name)));
24508 add_error_note(ira->codegen, msg, instruction->dest_child_type->source_node,
25404 add_error_note(ira->codegen, msg, instruction->dest_child_type->base.source_node,
2450925405 buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,
2451025406 buf_ptr(&dest_child_type->name), child_type_size, remainder));
24511 return ira->codegen->invalid_instruction;
25407 return ira->codegen->invalid_inst_gen;
2451225408 }
2451325409 }
2451425410
24515 return ir_build_resize_slice(ira, &instruction->base, casted_value, dest_slice_type, result_loc);
25411 return ir_build_resize_slice(ira, &instruction->base.base, casted_value, dest_slice_type, result_loc);
2451625412}
2451725413
24518static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {
25414static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) {
2451925415 Error err;
2452025416
24521 IrInstruction *target = instruction->target->child;
25417 IrInstGen *target = instruction->target->child;
2452225418 if (type_is_invalid(target->value->type))
24523 return ira->codegen->invalid_instruction;
25419 return ira->codegen->invalid_inst_gen;
2452425420
2452525421 if (!is_slice(target->value->type)) {
24526 ir_add_error(ira, instruction->target,
25422 ir_add_error(ira, &instruction->target->base,
2452725423 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));
24528 return ira->codegen->invalid_instruction;
25424 return ira->codegen->invalid_inst_gen;
2452925425 }
2453025426
2453125427 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2453225428
2453325429 uint32_t alignment;
2453425430 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
24535 return ira->codegen->invalid_instruction;
25431 return ira->codegen->invalid_inst_gen;
2453625432
2453725433 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
2453825434 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,
......@@ -24542,9 +25438,9 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2454225438 if (instr_is_comptime(target)) {
2454325439 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
2454425440 if (target_val == nullptr)
24545 return ira->codegen->invalid_instruction;
25441 return ira->codegen->invalid_inst_gen;
2454625442
24547 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);
25443 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);
2454825444 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);
2454925445
2455025446 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
......@@ -24564,13 +25460,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2456425460 return result;
2456525461 }
2456625462
24567 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
25463 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2456825464 dest_slice_type, nullptr, true, false, true);
24569 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
25465 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2457025466 return result_loc;
2457125467 }
2457225468
24573 return ir_build_resize_slice(ira, &instruction->base, target, dest_slice_type, result_loc);
25469 return ir_build_resize_slice(ira, &instruction->base.base, target, dest_slice_type, result_loc);
2457425470}
2457525471
2457625472static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
......@@ -24587,26 +25483,26 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali
2458725483 return ErrorNone;
2458825484}
2458925485
24590static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
25486static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcIntToFloat *instruction) {
2459125487 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2459225488 if (type_is_invalid(dest_type))
24593 return ira->codegen->invalid_instruction;
25489 return ira->codegen->invalid_inst_gen;
2459425490
24595 IrInstruction *target = instruction->target->child;
25491 IrInstGen *target = instruction->target->child;
2459625492 if (type_is_invalid(target->value->type))
24597 return ira->codegen->invalid_instruction;
25493 return ira->codegen->invalid_inst_gen;
2459825494
2459925495 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
24600 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",
25496 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'",
2460125497 buf_ptr(&target->value->type->name)));
24602 return ira->codegen->invalid_instruction;
25498 return ira->codegen->invalid_inst_gen;
2460325499 }
2460425500
24605 return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat);
25501 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat);
2460625502}
2460725503
24608static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *source_instr,
24609 ZigType *dest_type, IrInstruction *operand, AstNode *operand_source_node)
25504static IrInstGen *ir_analyze_float_to_int(IrAnalyze *ira, IrInst* source_instr,
25505 ZigType *dest_type, IrInstGen *operand, AstNode *operand_source_node)
2461025506{
2461125507 if (operand->value->type->id == ZigTypeIdComptimeInt) {
2461225508 return ir_implicit_cast(ira, operand, dest_type);
......@@ -24615,106 +25511,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou
2461525511 if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) {
2461625512 ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'",
2461725513 buf_ptr(&operand->value->type->name)));
24618 return ira->codegen->invalid_instruction;
25514 return ira->codegen->invalid_inst_gen;
2461925515 }
2462025516
2462125517 return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt);
2462225518}
2462325519
24624static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
25520static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) {
2462525521 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2462625522 if (type_is_invalid(dest_type))
24627 return ira->codegen->invalid_instruction;
25523 return ira->codegen->invalid_inst_gen;
2462825524
24629 IrInstruction *operand = instruction->target->child;
25525 IrInstGen *operand = instruction->target->child;
2463025526 if (type_is_invalid(operand->value->type))
24631 return ira->codegen->invalid_instruction;
25527 return ira->codegen->invalid_inst_gen;
2463225528
24633 return ir_analyze_float_to_int(ira, &instruction->base, dest_type, operand, instruction->target->source_node);
25529 return ir_analyze_float_to_int(ira, &instruction->base.base, dest_type, operand,
25530 instruction->target->base.source_node);
2463425531}
2463525532
24636static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
24637 IrInstruction *target = instruction->target->child;
25533static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) {
25534 IrInstGen *target = instruction->target->child;
2463825535 if (type_is_invalid(target->value->type))
24639 return ira->codegen->invalid_instruction;
25536 return ira->codegen->invalid_inst_gen;
2464025537
24641 IrInstruction *casted_target;
25538 IrInstGen *casted_target;
2464225539 if (target->value->type->id == ZigTypeIdErrorSet) {
2464325540 casted_target = target;
2464425541 } else {
2464525542 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
2464625543 if (type_is_invalid(casted_target->value->type))
24647 return ira->codegen->invalid_instruction;
25544 return ira->codegen->invalid_inst_gen;
2464825545 }
2464925546
24650 return ir_analyze_err_to_int(ira, &instruction->base, casted_target, ira->codegen->err_tag_type);
25547 return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type);
2465125548}
2465225549
24653static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
24654 IrInstruction *target = instruction->target->child;
25550static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) {
25551 IrInstGen *target = instruction->target->child;
2465525552 if (type_is_invalid(target->value->type))
24656 return ira->codegen->invalid_instruction;
25553 return ira->codegen->invalid_inst_gen;
2465725554
24658 IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);
25555 IrInstGen *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);
2465925556 if (type_is_invalid(casted_target->value->type))
24660 return ira->codegen->invalid_instruction;
25557 return ira->codegen->invalid_inst_gen;
2466125558
24662 return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set);
25559 return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set);
2466325560}
2466425561
24665static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
24666 IrInstruction *target = instruction->target->child;
25562static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) {
25563 IrInstGen *target = instruction->target->child;
2466725564 if (type_is_invalid(target->value->type))
24668 return ira->codegen->invalid_instruction;
25565 return ira->codegen->invalid_inst_gen;
2466925566
2467025567 if (target->value->type->id != ZigTypeIdBool) {
24671 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
25568 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'",
2467225569 buf_ptr(&target->value->type->name)));
24673 return ira->codegen->invalid_instruction;
25570 return ira->codegen->invalid_inst_gen;
2467425571 }
2467525572
2467625573 if (instr_is_comptime(target)) {
2467725574 bool is_true;
2467825575 if (!ir_resolve_bool(ira, target, &is_true))
24679 return ira->codegen->invalid_instruction;
25576 return ira->codegen->invalid_inst_gen;
2468025577
24681 return ir_const_unsigned(ira, &instruction->base, is_true ? 1 : 0);
25578 return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0);
2468225579 }
2468325580
2468425581 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
24685 return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt);
25582 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
2468625583}
2468725584
24688static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
24689 IrInstruction *is_signed_value = instruction->is_signed->child;
25585static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) {
25586 IrInstGen *is_signed_value = instruction->is_signed->child;
2469025587 bool is_signed;
2469125588 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
24692 return ira->codegen->invalid_instruction;
25589 return ira->codegen->invalid_inst_gen;
2469325590
24694 IrInstruction *bit_count_value = instruction->bit_count->child;
25591 IrInstGen *bit_count_value = instruction->bit_count->child;
2469525592 uint64_t bit_count;
2469625593 if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))
24697 return ira->codegen->invalid_instruction;
25594 return ira->codegen->invalid_inst_gen;
2469825595
24699 return ir_const_type(ira, &instruction->base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
25596 return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
2470025597}
2470125598
24702static IrInstruction *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstructionVectorType *instruction) {
25599static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
2470325600 uint64_t len;
2470425601 if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))
24705 return ira->codegen->invalid_instruction;
25602 return ira->codegen->invalid_inst_gen;
2470625603
2470725604 ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child);
2470825605 if (type_is_invalid(elem_type))
24709 return ira->codegen->invalid_instruction;
25606 return ira->codegen->invalid_inst_gen;
2471025607
2471125608 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);
2471225609
24713 return ir_const_type(ira, &instruction->base, vector_type);
25610 return ir_const_type(ira, &instruction->base.base, vector_type);
2471425611}
2471525612
24716static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *source_instr,
24717 ZigType *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)
25613static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,
25614 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
2471825615{
2471925616 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);
2472025617 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);
......@@ -24725,15 +25622,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2472525622 } else if (mask->value->type->id == ZigTypeIdArray) {
2472625623 len_mask = mask->value->type->data.array.len;
2472725624 } else {
24728 ir_add_error(ira, mask,
25625 ir_add_error(ira, &mask->base,
2472925626 buf_sprintf("expected vector or array, found '%s'",
2473025627 buf_ptr(&mask->value->type->name)));
24731 return ira->codegen->invalid_instruction;
25628 return ira->codegen->invalid_inst_gen;
2473225629 }
2473325630 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,
2473425631 ira->codegen->builtin_types.entry_i32));
2473525632 if (type_is_invalid(mask->value->type))
24736 return ira->codegen->invalid_instruction;
25633 return ira->codegen->invalid_inst_gen;
2473725634
2473825635 uint32_t len_a;
2473925636 if (a->value->type->id == ZigTypeIdVector) {
......@@ -24743,11 +25640,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2474325640 } else if (a->value->type->id == ZigTypeIdUndefined) {
2474425641 len_a = UINT32_MAX;
2474525642 } else {
24746 ir_add_error(ira, a,
25643 ir_add_error(ira, &a->base,
2474725644 buf_sprintf("expected vector or array with element type '%s', found '%s'",
2474825645 buf_ptr(&scalar_type->name),
2474925646 buf_ptr(&a->value->type->name)));
24750 return ira->codegen->invalid_instruction;
25647 return ira->codegen->invalid_inst_gen;
2475125648 }
2475225649
2475325650 uint32_t len_b;
......@@ -24758,38 +25655,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2475825655 } else if (b->value->type->id == ZigTypeIdUndefined) {
2475925656 len_b = UINT32_MAX;
2476025657 } else {
24761 ir_add_error(ira, b,
25658 ir_add_error(ira, &b->base,
2476225659 buf_sprintf("expected vector or array with element type '%s', found '%s'",
2476325660 buf_ptr(&scalar_type->name),
2476425661 buf_ptr(&b->value->type->name)));
24765 return ira->codegen->invalid_instruction;
25662 return ira->codegen->invalid_inst_gen;
2476625663 }
2476725664
2476825665 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {
24769 return ir_const_undef(ira, a, get_vector_type(ira->codegen, len_mask, scalar_type));
25666 return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type));
2477025667 }
2477125668
2477225669 if (len_a == UINT32_MAX) {
2477325670 len_a = len_b;
24774 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
25671 a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type));
2477525672 } else {
2477625673 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
2477725674 if (type_is_invalid(a->value->type))
24778 return ira->codegen->invalid_instruction;
25675 return ira->codegen->invalid_inst_gen;
2477925676 }
2478025677
2478125678 if (len_b == UINT32_MAX) {
2478225679 len_b = len_a;
24783 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
25680 b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type));
2478425681 } else {
2478525682 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
2478625683 if (type_is_invalid(b->value->type))
24787 return ira->codegen->invalid_instruction;
25684 return ira->codegen->invalid_inst_gen;
2478825685 }
2478925686
2479025687 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
2479125688 if (mask_val == nullptr)
24792 return ira->codegen->invalid_instruction;
25689 return ira->codegen->invalid_inst_gen;
2479325690
2479425691 expand_undef_array(ira->codegen, mask_val);
2479525692
......@@ -24799,7 +25696,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2479925696 continue;
2480025697 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);
2480125698 uint32_t v;
24802 IrInstruction *chosen_operand;
25699 IrInstGen *chosen_operand;
2480325700 if (v_i32 >= 0) {
2480425701 v = (uint32_t)v_i32;
2480525702 chosen_operand = a;
......@@ -24808,16 +25705,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2480825705 chosen_operand = b;
2480925706 }
2481025707 if (v >= chosen_operand->value->type->data.vector.len) {
24811 ErrorMsg *msg = ir_add_error(ira, mask,
25708 ErrorMsg *msg = ir_add_error(ira, &mask->base,
2481225709 buf_sprintf("mask index '%u' has out-of-bounds selection", i));
24813 add_error_note(ira->codegen, msg, chosen_operand->source_node,
25710 add_error_note(ira->codegen, msg, chosen_operand->base.source_node,
2481425711 buf_sprintf("selected index '%u' out of bounds of %s", v,
2481525712 buf_ptr(&chosen_operand->value->type->name)));
2481625713 if (chosen_operand == a && v < len_a + len_b) {
24817 add_error_note(ira->codegen, msg, b->source_node,
25714 add_error_note(ira->codegen, msg, b->base.source_node,
2481825715 buf_create_from_str("selections from the second vector are specified with negative numbers"));
2481925716 }
24820 return ira->codegen->invalid_instruction;
25717 return ira->codegen->invalid_inst_gen;
2482125718 }
2482225719 }
2482325720
......@@ -24825,16 +25722,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2482525722 if (instr_is_comptime(a) && instr_is_comptime(b)) {
2482625723 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);
2482725724 if (a_val == nullptr)
24828 return ira->codegen->invalid_instruction;
25725 return ira->codegen->invalid_inst_gen;
2482925726
2483025727 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);
2483125728 if (b_val == nullptr)
24832 return ira->codegen->invalid_instruction;
25729 return ira->codegen->invalid_inst_gen;
2483325730
2483425731 expand_undef_array(ira->codegen, a_val);
2483525732 expand_undef_array(ira->codegen, b_val);
2483625733
24837 IrInstruction *result = ir_const(ira, source_instr, result_type);
25734 IrInstGen *result = ir_const(ira, source_instr, result_type);
2483825735 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);
2483925736 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
2484025737 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
......@@ -24866,7 +25763,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2486625763 uint32_t len_min = min(len_a, len_b);
2486725764 uint32_t len_max = max(len_a, len_b);
2486825765
24869 IrInstruction *expand_mask = ir_const(ira, mask,
25766 IrInstGen *expand_mask = ir_const(ira, &mask->base,
2487025767 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
2487125768 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);
2487225769 uint32_t i = 0;
......@@ -24875,7 +25772,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2487525772 for (; i < len_max; i += 1)
2487625773 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);
2487725774
24878 IrInstruction *undef = ir_const_undef(ira, source_instr,
25775 IrInstGen *undef = ir_const_undef(ira, source_instr,
2487925776 get_vector_type(ira->codegen, len_min, scalar_type));
2488025777
2488125778 if (len_b < len_a) {
......@@ -24885,62 +25782,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2488525782 }
2488625783 }
2488725784
24888 IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb,
24889 source_instr->scope, source_instr->source_node,
24890 nullptr, a, b, mask);
24891 result->value->type = result_type;
24892 return result;
25785 return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node,
25786 result_type, a, b, mask);
2489325787}
2489425788
24895static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstructionShuffleVector *instruction) {
24896 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type);
25789static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSrcShuffleVector *instruction) {
25790 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type->child);
2489725791 if (type_is_invalid(scalar_type))
24898 return ira->codegen->invalid_instruction;
25792 return ira->codegen->invalid_inst_gen;
2489925793
24900 IrInstruction *a = instruction->a->child;
25794 IrInstGen *a = instruction->a->child;
2490125795 if (type_is_invalid(a->value->type))
24902 return ira->codegen->invalid_instruction;
25796 return ira->codegen->invalid_inst_gen;
2490325797
24904 IrInstruction *b = instruction->b->child;
25798 IrInstGen *b = instruction->b->child;
2490525799 if (type_is_invalid(b->value->type))
24906 return ira->codegen->invalid_instruction;
25800 return ira->codegen->invalid_inst_gen;
2490725801
24908 IrInstruction *mask = instruction->mask->child;
25802 IrInstGen *mask = instruction->mask->child;
2490925803 if (type_is_invalid(mask->value->type))
24910 return ira->codegen->invalid_instruction;
25804 return ira->codegen->invalid_inst_gen;
2491125805
24912 return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask);
25806 return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask);
2491325807}
2491425808
24915static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstructionSplatSrc *instruction) {
25809static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) {
2491625810 Error err;
2491725811
24918 IrInstruction *len = instruction->len->child;
25812 IrInstGen *len = instruction->len->child;
2491925813 if (type_is_invalid(len->value->type))
24920 return ira->codegen->invalid_instruction;
25814 return ira->codegen->invalid_inst_gen;
2492125815
24922 IrInstruction *scalar = instruction->scalar->child;
25816 IrInstGen *scalar = instruction->scalar->child;
2492325817 if (type_is_invalid(scalar->value->type))
24924 return ira->codegen->invalid_instruction;
25818 return ira->codegen->invalid_inst_gen;
2492525819
2492625820 uint64_t len_u64;
2492725821 if (!ir_resolve_unsigned(ira, len, ira->codegen->builtin_types.entry_u32, &len_u64))
24928 return ira->codegen->invalid_instruction;
25822 return ira->codegen->invalid_inst_gen;
2492925823 uint32_t len_int = len_u64;
2493025824
24931 if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type)))
24932 return ira->codegen->invalid_instruction;
25825 if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type)))
25826 return ira->codegen->invalid_inst_gen;
2493325827
2493425828 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);
2493525829
2493625830 if (instr_is_comptime(scalar)) {
2493725831 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);
2493825832 if (scalar_val == nullptr)
24939 return ira->codegen->invalid_instruction;
25833 return ira->codegen->invalid_inst_gen;
2494025834 if (scalar_val->special == ConstValSpecialUndef)
24941 return ir_const_undef(ira, &instruction->base, return_type);
25835 return ir_const_undef(ira, &instruction->base.base, return_type);
2494225836
24943 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
25837 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
2494425838 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
2494525839 for (uint32_t i = 0; i < len_int; i += 1) {
2494625840 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);
......@@ -24948,48 +25842,45 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
2494825842 return result;
2494925843 }
2495025844
24951 return ir_build_splat_gen(ira, &instruction->base, return_type, scalar);
25845 return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar);
2495225846}
2495325847
24954static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
24955 IrInstruction *value = instruction->value->child;
25848static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) {
25849 IrInstGen *value = instruction->value->child;
2495625850 if (type_is_invalid(value->value->type))
24957 return ira->codegen->invalid_instruction;
25851 return ira->codegen->invalid_inst_gen;
2495825852
2495925853 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
2496025854
24961 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
25855 IrInstGen *casted_value = ir_implicit_cast(ira, value, bool_type);
2496225856 if (type_is_invalid(casted_value->value->type))
24963 return ira->codegen->invalid_instruction;
25857 return ira->codegen->invalid_inst_gen;
2496425858
2496525859 if (instr_is_comptime(casted_value)) {
2496625860 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);
2496725861 if (value == nullptr)
24968 return ira->codegen->invalid_instruction;
25862 return ira->codegen->invalid_inst_gen;
2496925863
24970 return ir_const_bool(ira, &instruction->base, !value->data.x_bool);
25864 return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool);
2497125865 }
2497225866
24973 IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope,
24974 instruction->base.source_node, casted_value);
24975 result->value->type = bool_type;
24976 return result;
25867 return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value);
2497725868}
2497825869
24979static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
25870static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) {
2498025871 Error err;
2498125872
24982 IrInstruction *dest_ptr = instruction->dest_ptr->child;
25873 IrInstGen *dest_ptr = instruction->dest_ptr->child;
2498325874 if (type_is_invalid(dest_ptr->value->type))
24984 return ira->codegen->invalid_instruction;
25875 return ira->codegen->invalid_inst_gen;
2498525876
24986 IrInstruction *byte_value = instruction->byte->child;
25877 IrInstGen *byte_value = instruction->byte->child;
2498725878 if (type_is_invalid(byte_value->value->type))
24988 return ira->codegen->invalid_instruction;
25879 return ira->codegen->invalid_inst_gen;
2498925880
24990 IrInstruction *count_value = instruction->count->child;
25881 IrInstGen *count_value = instruction->count->child;
2499125882 if (type_is_invalid(count_value->value->type))
24992 return ira->codegen->invalid_instruction;
25883 return ira->codegen->invalid_inst_gen;
2499325884
2499425885 ZigType *dest_uncasted_type = dest_ptr->value->type;
2499525886 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
......@@ -25000,24 +25891,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2500025891 uint32_t dest_align;
2500125892 if (dest_uncasted_type->id == ZigTypeIdPointer) {
2500225893 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25003 return ira->codegen->invalid_instruction;
25894 return ira->codegen->invalid_inst_gen;
2500425895 } else {
2500525896 dest_align = get_abi_alignment(ira->codegen, u8);
2500625897 }
2500725898 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
2500825899 PtrLenUnknown, dest_align, 0, 0, false);
2500925900
25010 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
25901 IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
2501125902 if (type_is_invalid(casted_dest_ptr->value->type))
25012 return ira->codegen->invalid_instruction;
25903 return ira->codegen->invalid_inst_gen;
2501325904
25014 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);
25905 IrInstGen *casted_byte = ir_implicit_cast(ira, byte_value, u8);
2501525906 if (type_is_invalid(casted_byte->value->type))
25016 return ira->codegen->invalid_instruction;
25907 return ira->codegen->invalid_inst_gen;
2501725908
25018 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
25909 IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize);
2501925910 if (type_is_invalid(casted_count->value->type))
25020 return ira->codegen->invalid_instruction;
25911 return ira->codegen->invalid_inst_gen;
2502125912
2502225913 // TODO test this at comptime with u8 and non-u8 types
2502325914 if (instr_is_comptime(casted_dest_ptr) &&
......@@ -25026,15 +25917,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2502625917 {
2502725918 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
2502825919 if (dest_ptr_val == nullptr)
25029 return ira->codegen->invalid_instruction;
25920 return ira->codegen->invalid_inst_gen;
2503025921
2503125922 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);
2503225923 if (byte_val == nullptr)
25033 return ira->codegen->invalid_instruction;
25924 return ira->codegen->invalid_inst_gen;
2503425925
2503525926 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
2503625927 if (count_val == nullptr)
25037 return ira->codegen->invalid_instruction;
25928 return ira->codegen->invalid_inst_gen;
2503825929
2503925930 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
2504025931 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
......@@ -25079,38 +25970,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2507925970 size_t count = bigint_as_usize(&count_val->data.x_bigint);
2508025971 size_t end = start + count;
2508125972 if (end > bound_end) {
25082 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));
25083 return ira->codegen->invalid_instruction;
25973 ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access"));
25974 return ira->codegen->invalid_inst_gen;
2508425975 }
2508525976
2508625977 for (size_t i = start; i < end; i += 1) {
2508725978 copy_const_val(&dest_elements[i], byte_val);
2508825979 }
2508925980
25090 return ir_const_void(ira, &instruction->base);
25981 return ir_const_void(ira, &instruction->base.base);
2509125982 }
2509225983 }
2509325984
25094 IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
25095 casted_dest_ptr, casted_byte, casted_count);
25096 result->value->type = ira->codegen->builtin_types.entry_void;
25097 return result;
25985 return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count);
2509825986}
2509925987
25100static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
25988static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) {
2510125989 Error err;
2510225990
25103 IrInstruction *dest_ptr = instruction->dest_ptr->child;
25991 IrInstGen *dest_ptr = instruction->dest_ptr->child;
2510425992 if (type_is_invalid(dest_ptr->value->type))
25105 return ira->codegen->invalid_instruction;
25993 return ira->codegen->invalid_inst_gen;
2510625994
25107 IrInstruction *src_ptr = instruction->src_ptr->child;
25995 IrInstGen *src_ptr = instruction->src_ptr->child;
2510825996 if (type_is_invalid(src_ptr->value->type))
25109 return ira->codegen->invalid_instruction;
25997 return ira->codegen->invalid_inst_gen;
2511025998
25111 IrInstruction *count_value = instruction->count->child;
25999 IrInstGen *count_value = instruction->count->child;
2511226000 if (type_is_invalid(count_value->value->type))
25113 return ira->codegen->invalid_instruction;
26001 return ira->codegen->invalid_inst_gen;
2511426002
2511526003 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
2511626004 ZigType *dest_uncasted_type = dest_ptr->value->type;
......@@ -25123,7 +26011,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2512326011 uint32_t dest_align;
2512426012 if (dest_uncasted_type->id == ZigTypeIdPointer) {
2512526013 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25126 return ira->codegen->invalid_instruction;
26014 return ira->codegen->invalid_inst_gen;
2512726015 } else {
2512826016 dest_align = get_abi_alignment(ira->codegen, u8);
2512926017 }
......@@ -25131,7 +26019,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2513126019 uint32_t src_align;
2513226020 if (src_uncasted_type->id == ZigTypeIdPointer) {
2513326021 if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align)))
25134 return ira->codegen->invalid_instruction;
26022 return ira->codegen->invalid_inst_gen;
2513526023 } else {
2513626024 src_align = get_abi_alignment(ira->codegen, u8);
2513726025 }
......@@ -25142,17 +26030,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2514226030 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
2514326031 PtrLenUnknown, src_align, 0, 0, false);
2514426032
25145 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
26033 IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
2514626034 if (type_is_invalid(casted_dest_ptr->value->type))
25147 return ira->codegen->invalid_instruction;
26035 return ira->codegen->invalid_inst_gen;
2514826036
25149 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
26037 IrInstGen *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
2515026038 if (type_is_invalid(casted_src_ptr->value->type))
25151 return ira->codegen->invalid_instruction;
26039 return ira->codegen->invalid_inst_gen;
2515226040
25153 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
26041 IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize);
2515426042 if (type_is_invalid(casted_count->value->type))
25155 return ira->codegen->invalid_instruction;
26043 return ira->codegen->invalid_inst_gen;
2515626044
2515726045 // TODO test this at comptime with u8 and non-u8 types
2515826046 // TODO test with dest ptr being a global runtime variable
......@@ -25162,15 +26050,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2516226050 {
2516326051 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
2516426052 if (dest_ptr_val == nullptr)
25165 return ira->codegen->invalid_instruction;
26053 return ira->codegen->invalid_inst_gen;
2516626054
2516726055 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);
2516826056 if (src_ptr_val == nullptr)
25169 return ira->codegen->invalid_instruction;
26057 return ira->codegen->invalid_inst_gen;
2517026058
2517126059 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
2517226060 if (count_val == nullptr)
25173 return ira->codegen->invalid_instruction;
26061 return ira->codegen->invalid_inst_gen;
2517426062
2517526063 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
2517626064 size_t count = bigint_as_usize(&count_val->data.x_bigint);
......@@ -25213,8 +26101,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2521326101 }
2521426102
2521526103 if (dest_start + count > dest_end) {
25216 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));
25217 return ira->codegen->invalid_instruction;
26104 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
26105 return ira->codegen->invalid_inst_gen;
2521826106 }
2521926107
2522026108 ZigValue *src_elements;
......@@ -25256,8 +26144,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2525626144 }
2525726145
2525826146 if (src_start + count > src_end) {
25259 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));
25260 return ira->codegen->invalid_instruction;
26147 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
26148 return ira->codegen->invalid_inst_gen;
2526126149 }
2526226150
2526326151 // TODO check for noalias violations - this should be generalized to work for any function
......@@ -25266,42 +26154,39 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2526626154 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
2526726155 }
2526826156
25269 return ir_const_void(ira, &instruction->base);
26157 return ir_const_void(ira, &instruction->base.base);
2527026158 }
2527126159 }
2527226160
25273 IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
25274 casted_dest_ptr, casted_src_ptr, casted_count);
25275 result->value->type = ira->codegen->builtin_types.entry_void;
25276 return result;
26161 return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count);
2527726162}
2527826163
25279static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) {
25280 IrInstruction *ptr_ptr = instruction->ptr->child;
26164static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) {
26165 IrInstGen *ptr_ptr = instruction->ptr->child;
2528126166 if (type_is_invalid(ptr_ptr->value->type))
25282 return ira->codegen->invalid_instruction;
26167 return ira->codegen->invalid_inst_gen;
2528326168
2528426169 ZigType *ptr_ptr_type = ptr_ptr->value->type;
2528526170 assert(ptr_ptr_type->id == ZigTypeIdPointer);
2528626171 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;
2528726172
25288 IrInstruction *start = instruction->start->child;
26173 IrInstGen *start = instruction->start->child;
2528926174 if (type_is_invalid(start->value->type))
25290 return ira->codegen->invalid_instruction;
26175 return ira->codegen->invalid_inst_gen;
2529126176
2529226177 ZigType *usize = ira->codegen->builtin_types.entry_usize;
25293 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
26178 IrInstGen *casted_start = ir_implicit_cast(ira, start, usize);
2529426179 if (type_is_invalid(casted_start->value->type))
25295 return ira->codegen->invalid_instruction;
26180 return ira->codegen->invalid_inst_gen;
2529626181
25297 IrInstruction *end;
26182 IrInstGen *end;
2529826183 if (instruction->end) {
2529926184 end = instruction->end->child;
2530026185 if (type_is_invalid(end->value->type))
25301 return ira->codegen->invalid_instruction;
26186 return ira->codegen->invalid_inst_gen;
2530226187 end = ir_implicit_cast(ira, end, usize);
2530326188 if (type_is_invalid(end->value->type))
25304 return ira->codegen->invalid_instruction;
26189 return ira->codegen->invalid_inst_gen;
2530526190 } else {
2530626191 end = nullptr;
2530726192 }
......@@ -25329,8 +26214,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2532926214 PtrLenUnknown,
2533026215 array_type->data.pointer.explicit_alignment, 0, 0, false);
2533126216 } else {
25332 ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer"));
25333 return ira->codegen->invalid_instruction;
26217 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer"));
26218 return ira->codegen->invalid_inst_gen;
2533426219 }
2533526220 } else {
2533626221 elem_type = array_type->data.pointer.child_type;
......@@ -25340,8 +26225,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2534026225 ZigType *maybe_sentineled_slice_ptr_type = array_type;
2534126226 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
2534226227 if (!end) {
25343 ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value"));
25344 return ira->codegen->invalid_instruction;
26228 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value"));
26229 return ira->codegen->invalid_inst_gen;
2534526230 }
2534626231 }
2534726232 } else if (is_slice(array_type)) {
......@@ -25349,23 +26234,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2534926234 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
2535026235 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;
2535126236 } else {
25352 ir_add_error(ira, &instruction->base,
26237 ir_add_error(ira, &instruction->base.base,
2535326238 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));
25354 return ira->codegen->invalid_instruction;
26239 return ira->codegen->invalid_inst_gen;
2535526240 }
2535626241
2535726242 ZigType *return_type;
2535826243 ZigValue *sentinel_val = nullptr;
2535926244 if (instruction->sentinel) {
25360 IrInstruction *uncasted_sentinel = instruction->sentinel->child;
26245 IrInstGen *uncasted_sentinel = instruction->sentinel->child;
2536126246 if (type_is_invalid(uncasted_sentinel->value->type))
25362 return ira->codegen->invalid_instruction;
25363 IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);
26247 return ira->codegen->invalid_inst_gen;
26248 IrInstGen *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);
2536426249 if (type_is_invalid(sentinel->value->type))
25365 return ira->codegen->invalid_instruction;
26250 return ira->codegen->invalid_inst_gen;
2536626251 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
2536726252 if (sentinel_val == nullptr)
25368 return ira->codegen->invalid_instruction;
26253 return ira->codegen->invalid_inst_gen;
2536926254 ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val);
2537026255 return_type = get_slice_type(ira->codegen, slice_ptr_type);
2537126256 } else {
......@@ -25387,9 +26272,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2538726272 if (array_type->id == ZigTypeIdPointer) {
2538826273 ZigType *child_array_type = array_type->data.pointer.child_type;
2538926274 assert(child_array_type->id == ZigTypeIdArray);
25390 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26275 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2539126276 if (parent_ptr == nullptr)
25392 return ira->codegen->invalid_instruction;
26277 return ira->codegen->invalid_inst_gen;
2539326278
2539426279
2539526280 if (parent_ptr->special == ConstValSpecialUndef) {
......@@ -25398,26 +26283,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2539826283 rel_end = SIZE_MAX;
2539926284 ptr_is_undef = true;
2540026285 } else {
25401 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
26286 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node);
2540226287 if (array_val == nullptr)
25403 return ira->codegen->invalid_instruction;
26288 return ira->codegen->invalid_inst_gen;
2540426289
2540526290 rel_end = child_array_type->data.array.len;
2540626291 abs_offset = 0;
2540726292 }
2540826293 } else {
25409 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26294 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2541026295 if (array_val == nullptr)
25411 return ira->codegen->invalid_instruction;
26296 return ira->codegen->invalid_inst_gen;
2541226297 rel_end = array_type->data.array.len;
2541326298 parent_ptr = nullptr;
2541426299 abs_offset = 0;
2541526300 }
2541626301 } else if (array_type->id == ZigTypeIdPointer) {
2541726302 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
25418 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26303 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2541926304 if (parent_ptr == nullptr)
25420 return ira->codegen->invalid_instruction;
26305 return ira->codegen->invalid_inst_gen;
2542126306
2542226307 if (parent_ptr->special == ConstValSpecialUndef) {
2542326308 array_val = nullptr;
......@@ -25463,19 +26348,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2546326348 zig_panic("TODO slice of null ptr");
2546426349 }
2546526350 } else if (is_slice(array_type)) {
25466 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26351 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2546726352 if (slice_ptr == nullptr)
25468 return ira->codegen->invalid_instruction;
26353 return ira->codegen->invalid_inst_gen;
2546926354
2547026355 if (slice_ptr->special == ConstValSpecialUndef) {
25471 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
25472 return ira->codegen->invalid_instruction;
26356 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
26357 return ira->codegen->invalid_inst_gen;
2547326358 }
2547426359
2547526360 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
2547626361 if (parent_ptr->special == ConstValSpecialUndef) {
25477 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
25478 return ira->codegen->invalid_instruction;
26362 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
26363 return ira->codegen->invalid_inst_gen;
2547926364 }
2548026365
2548126366 ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];
......@@ -25518,37 +26403,37 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2551826403
2551926404 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
2552026405 if (!start_val)
25521 return ira->codegen->invalid_instruction;
26406 return ira->codegen->invalid_inst_gen;
2552226407
2552326408 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
2552426409 if (!ptr_is_undef && start_scalar > rel_end) {
25525 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));
25526 return ira->codegen->invalid_instruction;
26410 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
26411 return ira->codegen->invalid_inst_gen;
2552726412 }
2552826413
2552926414 uint64_t end_scalar = rel_end;
2553026415 if (end) {
2553126416 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);
2553226417 if (!end_val)
25533 return ira->codegen->invalid_instruction;
26418 return ira->codegen->invalid_inst_gen;
2553426419 end_scalar = bigint_as_u64(&end_val->data.x_bigint);
2553526420 }
2553626421 if (!ptr_is_undef) {
2553726422 if (end_scalar > rel_end) {
25538 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));
25539 return ira->codegen->invalid_instruction;
26423 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
26424 return ira->codegen->invalid_inst_gen;
2554026425 }
2554126426 if (start_scalar > end_scalar) {
25542 ir_add_error(ira, &instruction->base, buf_sprintf("slice start is greater than end"));
25543 return ira->codegen->invalid_instruction;
26427 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end"));
26428 return ira->codegen->invalid_inst_gen;
2554426429 }
2554526430 }
2554626431 if (ptr_is_undef && start_scalar != end_scalar) {
25547 ir_add_error(ira, &instruction->base, buf_sprintf("non-zero length slice of undefined pointer"));
25548 return ira->codegen->invalid_instruction;
26432 ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer"));
26433 return ira->codegen->invalid_inst_gen;
2554926434 }
2555026435
25551 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
26436 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
2555226437 ZigValue *out_val = result->value;
2555326438 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
2555426439
......@@ -25605,28 +26490,28 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2560526490 return result;
2560626491 }
2560726492
25608 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
26493 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2560926494 return_type, nullptr, true, false, true);
25610 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
26495 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2561126496 return result_loc;
2561226497 }
25613 return ir_build_slice_gen(ira, &instruction->base, return_type,
26498 return ir_build_slice_gen(ira, &instruction->base.base, return_type,
2561426499 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
2561526500}
2561626501
25617static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
26502static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
2561826503 Error err;
25619 IrInstruction *container = instruction->container->child;
26504 IrInstGen *container = instruction->container->child;
2562026505 if (type_is_invalid(container->value->type))
25621 return ira->codegen->invalid_instruction;
26506 return ira->codegen->invalid_inst_gen;
2562226507 ZigType *container_type = ir_resolve_type(ira, container);
2562326508
2562426509 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25625 return ira->codegen->invalid_instruction;
26510 return ira->codegen->invalid_inst_gen;
2562626511
2562726512 uint64_t result;
2562826513 if (type_is_invalid(container_type)) {
25629 return ira->codegen->invalid_instruction;
26514 return ira->codegen->invalid_inst_gen;
2563026515 } else if (container_type->id == ZigTypeIdEnum) {
2563126516 result = container_type->data.enumeration.src_field_count;
2563226517 } else if (container_type->id == ZigTypeIdStruct) {
......@@ -25634,135 +26519,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
2563426519 } else if (container_type->id == ZigTypeIdUnion) {
2563526520 result = container_type->data.unionation.src_field_count;
2563626521 } else if (container_type->id == ZigTypeIdErrorSet) {
25637 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {
25638 return ira->codegen->invalid_instruction;
26522 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
26523 return ira->codegen->invalid_inst_gen;
2563926524 }
2564026525 if (type_is_global_error_set(container_type)) {
25641 ir_add_error(ira, &instruction->base, buf_sprintf("global error set member count not available at comptime"));
25642 return ira->codegen->invalid_instruction;
26526 ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
26527 return ira->codegen->invalid_inst_gen;
2564326528 }
2564426529 result = container_type->data.error_set.err_count;
2564526530 } else {
25646 ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
25647 return ira->codegen->invalid_instruction;
26531 ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
26532 return ira->codegen->invalid_inst_gen;
2564826533 }
2564926534
25650 return ir_const_unsigned(ira, &instruction->base, result);
26535 return ir_const_unsigned(ira, &instruction->base.base, result);
2565126536}
2565226537
25653static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
26538static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
2565426539 Error err;
25655 IrInstruction *container_type_value = instruction->container_type->child;
26540 IrInstGen *container_type_value = instruction->container_type->child;
2565626541 ZigType *container_type = ir_resolve_type(ira, container_type_value);
2565726542 if (type_is_invalid(container_type))
25658 return ira->codegen->invalid_instruction;
26543 return ira->codegen->invalid_inst_gen;
2565926544
2566026545 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25661 return ira->codegen->invalid_instruction;
26546 return ira->codegen->invalid_inst_gen;
2566226547
2566326548
2566426549 uint64_t member_index;
25665 IrInstruction *index_value = instruction->member_index->child;
26550 IrInstGen *index_value = instruction->member_index->child;
2566626551 if (!ir_resolve_usize(ira, index_value, &member_index))
25667 return ira->codegen->invalid_instruction;
26552 return ira->codegen->invalid_inst_gen;
2566826553
2566926554 if (container_type->id == ZigTypeIdStruct) {
2567026555 if (member_index >= container_type->data.structure.src_field_count) {
25671 ir_add_error(ira, index_value,
26556 ir_add_error(ira, &index_value->base,
2567226557 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2567326558 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
25674 return ira->codegen->invalid_instruction;
26559 return ira->codegen->invalid_inst_gen;
2567526560 }
2567626561 TypeStructField *field = container_type->data.structure.fields[member_index];
2567726562
25678 return ir_const_type(ira, &instruction->base, field->type_entry);
26563 return ir_const_type(ira, &instruction->base.base, field->type_entry);
2567926564 } else if (container_type->id == ZigTypeIdUnion) {
2568026565 if (member_index >= container_type->data.unionation.src_field_count) {
25681 ir_add_error(ira, index_value,
26566 ir_add_error(ira, &index_value->base,
2568226567 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2568326568 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
25684 return ira->codegen->invalid_instruction;
26569 return ira->codegen->invalid_inst_gen;
2568526570 }
2568626571 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2568726572
25688 return ir_const_type(ira, &instruction->base, field->type_entry);
26573 return ir_const_type(ira, &instruction->base.base, field->type_entry);
2568926574 } else {
25690 ir_add_error(ira, container_type_value,
26575 ir_add_error(ira, &container_type_value->base,
2569126576 buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));
25692 return ira->codegen->invalid_instruction;
26577 return ira->codegen->invalid_inst_gen;
2569326578 }
2569426579}
2569526580
25696static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
26581static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
2569726582 Error err;
25698 IrInstruction *container_type_value = instruction->container_type->child;
26583 IrInstGen *container_type_value = instruction->container_type->child;
2569926584 ZigType *container_type = ir_resolve_type(ira, container_type_value);
2570026585 if (type_is_invalid(container_type))
25701 return ira->codegen->invalid_instruction;
26586 return ira->codegen->invalid_inst_gen;
2570226587
2570326588 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25704 return ira->codegen->invalid_instruction;
26589 return ira->codegen->invalid_inst_gen;
2570526590
2570626591 uint64_t member_index;
25707 IrInstruction *index_value = instruction->member_index->child;
26592 IrInstGen *index_value = instruction->member_index->child;
2570826593 if (!ir_resolve_usize(ira, index_value, &member_index))
25709 return ira->codegen->invalid_instruction;
26594 return ira->codegen->invalid_inst_gen;
2571026595
2571126596 if (container_type->id == ZigTypeIdStruct) {
2571226597 if (member_index >= container_type->data.structure.src_field_count) {
25713 ir_add_error(ira, index_value,
26598 ir_add_error(ira, &index_value->base,
2571426599 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2571526600 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
25716 return ira->codegen->invalid_instruction;
26601 return ira->codegen->invalid_inst_gen;
2571726602 }
2571826603 TypeStructField *field = container_type->data.structure.fields[member_index];
2571926604
25720 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
26605 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2572126606 init_const_str_lit(ira->codegen, result->value, field->name);
2572226607 return result;
2572326608 } else if (container_type->id == ZigTypeIdEnum) {
2572426609 if (member_index >= container_type->data.enumeration.src_field_count) {
25725 ir_add_error(ira, index_value,
26610 ir_add_error(ira, &index_value->base,
2572626611 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2572726612 member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));
25728 return ira->codegen->invalid_instruction;
26613 return ira->codegen->invalid_inst_gen;
2572926614 }
2573026615 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
2573126616
25732 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
26617 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2573326618 init_const_str_lit(ira->codegen, result->value, field->name);
2573426619 return result;
2573526620 } else if (container_type->id == ZigTypeIdUnion) {
2573626621 if (member_index >= container_type->data.unionation.src_field_count) {
25737 ir_add_error(ira, index_value,
26622 ir_add_error(ira, &index_value->base,
2573826623 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2573926624 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
25740 return ira->codegen->invalid_instruction;
26625 return ira->codegen->invalid_inst_gen;
2574126626 }
2574226627 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2574326628
25744 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
26629 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2574526630 init_const_str_lit(ira->codegen, result->value, field->name);
2574626631 return result;
2574726632 } else {
25748 ir_add_error(ira, container_type_value,
26633 ir_add_error(ira, &container_type_value->base,
2574926634 buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));
25750 return ira->codegen->invalid_instruction;
26635 return ira->codegen->invalid_inst_gen;
2575126636 }
2575226637}
2575326638
25754static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstructionHasField *instruction) {
26639static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
2575526640 Error err;
2575626641 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
2575726642 if (type_is_invalid(container_type))
25758 return ira->codegen->invalid_instruction;
26643 return ira->codegen->invalid_inst_gen;
2575926644
2576026645 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown)))
25761 return ira->codegen->invalid_instruction;
26646 return ira->codegen->invalid_inst_gen;
2576226647
2576326648 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
2576426649 if (field_name == nullptr)
25765 return ira->codegen->invalid_instruction;
26650 return ira->codegen->invalid_inst_gen;
2576626651
2576726652 bool result;
2576826653 if (container_type->id == ZigTypeIdStruct) {
......@@ -25772,91 +26657,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc
2577226657 } else if (container_type->id == ZigTypeIdUnion) {
2577326658 result = find_union_type_field(container_type, field_name) != nullptr;
2577426659 } else {
25775 ir_add_error(ira, instruction->container_type,
26660 ir_add_error(ira, &instruction->container_type->base,
2577626661 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));
25777 return ira->codegen->invalid_instruction;
26662 return ira->codegen->invalid_inst_gen;
2577826663 }
25779 return ir_const_bool(ira, &instruction->base, result);
26664 return ir_const_bool(ira, &instruction->base.base, result);
2578026665}
2578126666
25782static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
25783 IrInstruction *result = ir_build_breakpoint(&ira->new_irb,
25784 instruction->base.scope, instruction->base.source_node);
25785 result->value->type = ira->codegen->builtin_types.entry_void;
25786 return result;
26667static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) {
26668 return ir_build_breakpoint_gen(ira, &instruction->base.base);
2578726669}
2578826670
25789static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
25790 IrInstruction *result = ir_build_return_address(&ira->new_irb,
25791 instruction->base.scope, instruction->base.source_node);
25792 result->value->type = ira->codegen->builtin_types.entry_usize;
25793 return result;
26671static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) {
26672 return ir_build_return_address_gen(ira, &instruction->base.base);
2579426673}
2579526674
25796static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
25797 IrInstruction *result = ir_build_frame_address(&ira->new_irb,
25798 instruction->base.scope, instruction->base.source_node);
25799 result->value->type = ira->codegen->builtin_types.entry_usize;
25800 return result;
26675static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) {
26676 return ir_build_frame_address_gen(ira, &instruction->base.base);
2580126677}
2580226678
25803static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstructionFrameHandle *instruction) {
25804 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);
25805 ir_assert(fn != nullptr, &instruction->base);
26679static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) {
26680 ZigFn *fn = ira->new_irb.exec->fn_entry;
26681 ir_assert(fn != nullptr, &instruction->base.base);
2580626682
2580726683 if (fn->inferred_async_node == nullptr) {
25808 fn->inferred_async_node = instruction->base.source_node;
26684 fn->inferred_async_node = instruction->base.base.source_node;
2580926685 }
2581026686
2581126687 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);
2581226688 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2581326689
25814 IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
25815 result->value->type = ptr_frame_type;
25816 return result;
26690 return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type);
2581726691}
2581826692
25819static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstructionFrameType *instruction) {
26693static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) {
2582026694 ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child);
2582126695 if (fn == nullptr)
25822 return ira->codegen->invalid_instruction;
26696 return ira->codegen->invalid_inst_gen;
2582326697
2582426698 if (fn->type_entry->data.fn.is_generic) {
25825 ir_add_error(ira, &instruction->base,
26699 ir_add_error(ira, &instruction->base.base,
2582626700 buf_sprintf("@Frame() of generic function"));
25827 return ira->codegen->invalid_instruction;
26701 return ira->codegen->invalid_inst_gen;
2582826702 }
2582926703
2583026704 ZigType *ty = get_fn_frame_type(ira->codegen, fn);
25831 return ir_const_type(ira, &instruction->base, ty);
26705 return ir_const_type(ira, &instruction->base.base, ty);
2583226706}
2583326707
25834static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) {
25835 IrInstruction *fn = instruction->fn->child;
26708static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) {
26709 IrInstGen *fn = instruction->fn->child;
2583626710 if (type_is_invalid(fn->value->type))
25837 return ira->codegen->invalid_instruction;
26711 return ira->codegen->invalid_inst_gen;
2583826712
2583926713 if (fn->value->type->id != ZigTypeIdFn) {
25840 ir_add_error(ira, fn,
26714 ir_add_error(ira, &fn->base,
2584126715 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));
25842 return ira->codegen->invalid_instruction;
26716 return ira->codegen->invalid_inst_gen;
2584326717 }
2584426718
2584526719 ira->codegen->need_frame_size_prefix_data = true;
2584626720
25847 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,
25848 instruction->base.source_node, fn);
25849 result->value->type = ira->codegen->builtin_types.entry_usize;
25850 return result;
26721 return ir_build_frame_size_gen(ira, &instruction->base.base, fn);
2585126722}
2585226723
25853static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
26724static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) {
2585426725 // Here we create a lazy value in order to avoid resolving the alignment of the type
2585526726 // immediately. This avoids false positive dependency loops such as:
2585626727 // const Node = struct {
2585726728 // field: []align(@alignOf(Node)) Node,
2585826729 // };
25859 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
26730 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2586026731 result->value->special = ConstValSpecialLazy;
2586126732
2586226733 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");
......@@ -25866,41 +26737,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
2586626737
2586726738 lazy_align_of->target_type = instruction->type_value->child;
2586826739 if (ir_resolve_type_lazy(ira, lazy_align_of->target_type) == nullptr)
25869 return ira->codegen->invalid_instruction;
26740 return ira->codegen->invalid_inst_gen;
2587026741
2587126742 return result;
2587226743}
2587326744
25874static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
26745static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOverflowOp *instruction) {
2587526746 Error err;
2587626747
25877 IrInstruction *type_value = instruction->type_value->child;
26748 IrInstGen *type_value = instruction->type_value->child;
2587826749 if (type_is_invalid(type_value->value->type))
25879 return ira->codegen->invalid_instruction;
26750 return ira->codegen->invalid_inst_gen;
2588026751
2588126752 ZigType *dest_type = ir_resolve_type(ira, type_value);
2588226753 if (type_is_invalid(dest_type))
25883 return ira->codegen->invalid_instruction;
26754 return ira->codegen->invalid_inst_gen;
2588426755
2588526756 if (dest_type->id != ZigTypeIdInt) {
25886 ir_add_error(ira, type_value,
26757 ir_add_error(ira, &type_value->base,
2588726758 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
25888 return ira->codegen->invalid_instruction;
26759 return ira->codegen->invalid_inst_gen;
2588926760 }
2589026761
25891 IrInstruction *op1 = instruction->op1->child;
26762 IrInstGen *op1 = instruction->op1->child;
2589226763 if (type_is_invalid(op1->value->type))
25893 return ira->codegen->invalid_instruction;
26764 return ira->codegen->invalid_inst_gen;
2589426765
25895 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
26766 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
2589626767 if (type_is_invalid(casted_op1->value->type))
25897 return ira->codegen->invalid_instruction;
26768 return ira->codegen->invalid_inst_gen;
2589826769
25899 IrInstruction *op2 = instruction->op2->child;
26770 IrInstGen *op2 = instruction->op2->child;
2590026771 if (type_is_invalid(op2->value->type))
25901 return ira->codegen->invalid_instruction;
26772 return ira->codegen->invalid_inst_gen;
2590226773
25903 IrInstruction *casted_op2;
26774 IrInstGen *casted_op2;
2590426775 if (instruction->op == IrOverflowOpShl) {
2590526776 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
2590626777 dest_type->data.integral.bit_count - 1);
......@@ -25909,17 +26780,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2590926780 casted_op2 = ir_implicit_cast(ira, op2, dest_type);
2591026781 }
2591126782 if (type_is_invalid(casted_op2->value->type))
25912 return ira->codegen->invalid_instruction;
26783 return ira->codegen->invalid_inst_gen;
2591326784
25914 IrInstruction *result_ptr = instruction->result_ptr->child;
26785 IrInstGen *result_ptr = instruction->result_ptr->child;
2591526786 if (type_is_invalid(result_ptr->value->type))
25916 return ira->codegen->invalid_instruction;
26787 return ira->codegen->invalid_inst_gen;
2591726788
2591826789 ZigType *expected_ptr_type;
2591926790 if (result_ptr->value->type->id == ZigTypeIdPointer) {
2592026791 uint32_t alignment;
2592126792 if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment)))
25922 return ira->codegen->invalid_instruction;
26793 return ira->codegen->invalid_inst_gen;
2592326794 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
2592426795 false, result_ptr->value->type->data.pointer.is_volatile,
2592526796 PtrLenSingle,
......@@ -25928,9 +26799,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2592826799 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
2592926800 }
2593026801
25931 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
26802 IrInstGen *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
2593226803 if (type_is_invalid(casted_result_ptr->value->type))
25933 return ira->codegen->invalid_instruction;
26804 return ira->codegen->invalid_inst_gen;
2593426805
2593526806 if (instr_is_comptime(casted_op1) &&
2593626807 instr_is_comptime(casted_op2) &&
......@@ -25938,22 +26809,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2593826809 {
2593926810 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
2594026811 if (op1_val == nullptr)
25941 return ira->codegen->invalid_instruction;
26812 return ira->codegen->invalid_inst_gen;
2594226813
2594326814 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
2594426815 if (op2_val == nullptr)
25945 return ira->codegen->invalid_instruction;
26816 return ira->codegen->invalid_inst_gen;
2594626817
2594726818 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);
2594826819 if (result_val == nullptr)
25949 return ira->codegen->invalid_instruction;
26820 return ira->codegen->invalid_inst_gen;
2595026821
2595126822 BigInt *op1_bigint = &op1_val->data.x_bigint;
2595226823 BigInt *op2_bigint = &op2_val->data.x_bigint;
2595326824 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
25954 casted_result_ptr->source_node);
26825 casted_result_ptr->base.source_node);
2595526826 if (pointee_val == nullptr)
25956 return ira->codegen->invalid_instruction;
26827 return ira->codegen->invalid_inst_gen;
2595726828 BigInt *dest_bigint = &pointee_val->data.x_bigint;
2595826829 switch (instruction->op) {
2595926830 case IrOverflowOpAdd:
......@@ -25980,17 +26851,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2598026851 dest_type->data.integral.is_signed);
2598126852 }
2598226853 pointee_val->special = ConstValSpecialStatic;
25983 return ir_const_bool(ira, &instruction->base, result_bool);
26854 return ir_const_bool(ira, &instruction->base.base, result_bool);
2598426855 }
2598526856
25986 IrInstruction *result = ir_build_overflow_op(&ira->new_irb,
25987 instruction->base.scope, instruction->base.source_node,
25988 instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type);
25989 result->value->type = ira->codegen->builtin_types.entry_bool;
25990 return result;
26857 return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op,
26858 casted_op1, casted_op2, casted_result_ptr, dest_type);
2599126859}
2599226860
25993static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type,
26861static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type,
2599426862 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
2599526863 if (float_type->id == ZigTypeIdComptimeFloat) {
2599626864 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
......@@ -26017,61 +26885,61 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z
2601726885 }
2601826886}
2601926887
26020static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) {
26021 IrInstruction *type_value = instruction->type_value->child;
26888static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *instruction) {
26889 IrInstGen *type_value = instruction->type_value->child;
2602226890 if (type_is_invalid(type_value->value->type))
26023 return ira->codegen->invalid_instruction;
26891 return ira->codegen->invalid_inst_gen;
2602426892
2602526893 ZigType *expr_type = ir_resolve_type(ira, type_value);
2602626894 if (type_is_invalid(expr_type))
26027 return ira->codegen->invalid_instruction;
26895 return ira->codegen->invalid_inst_gen;
2602826896
2602926897 // Only allow float types, and vectors of floats.
2603026898 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
2603126899 if (float_type->id != ZigTypeIdFloat) {
26032 ir_add_error(ira, type_value,
26900 ir_add_error(ira, &type_value->base,
2603326901 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));
26034 return ira->codegen->invalid_instruction;
26902 return ira->codegen->invalid_inst_gen;
2603526903 }
2603626904
26037 IrInstruction *op1 = instruction->op1->child;
26905 IrInstGen *op1 = instruction->op1->child;
2603826906 if (type_is_invalid(op1->value->type))
26039 return ira->codegen->invalid_instruction;
26907 return ira->codegen->invalid_inst_gen;
2604026908
26041 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type);
26909 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, expr_type);
2604226910 if (type_is_invalid(casted_op1->value->type))
26043 return ira->codegen->invalid_instruction;
26911 return ira->codegen->invalid_inst_gen;
2604426912
26045 IrInstruction *op2 = instruction->op2->child;
26913 IrInstGen *op2 = instruction->op2->child;
2604626914 if (type_is_invalid(op2->value->type))
26047 return ira->codegen->invalid_instruction;
26915 return ira->codegen->invalid_inst_gen;
2604826916
26049 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type);
26917 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, expr_type);
2605026918 if (type_is_invalid(casted_op2->value->type))
26051 return ira->codegen->invalid_instruction;
26919 return ira->codegen->invalid_inst_gen;
2605226920
26053 IrInstruction *op3 = instruction->op3->child;
26921 IrInstGen *op3 = instruction->op3->child;
2605426922 if (type_is_invalid(op3->value->type))
26055 return ira->codegen->invalid_instruction;
26923 return ira->codegen->invalid_inst_gen;
2605626924
26057 IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type);
26925 IrInstGen *casted_op3 = ir_implicit_cast(ira, op3, expr_type);
2605826926 if (type_is_invalid(casted_op3->value->type))
26059 return ira->codegen->invalid_instruction;
26927 return ira->codegen->invalid_inst_gen;
2606026928
2606126929 if (instr_is_comptime(casted_op1) &&
2606226930 instr_is_comptime(casted_op2) &&
2606326931 instr_is_comptime(casted_op3)) {
2606426932 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
2606526933 if (!op1_const)
26066 return ira->codegen->invalid_instruction;
26934 return ira->codegen->invalid_inst_gen;
2606726935 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);
2606826936 if (!op2_const)
26069 return ira->codegen->invalid_instruction;
26937 return ira->codegen->invalid_inst_gen;
2607026938 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);
2607126939 if (!op3_const)
26072 return ira->codegen->invalid_instruction;
26940 return ira->codegen->invalid_inst_gen;
2607326941
26074 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
26942 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
2607526943 ZigValue *out_val = result->value;
2607626944
2607726945 if (expr_type->id == ZigTypeIdVector) {
......@@ -26102,63 +26970,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
2610226970 return result;
2610326971 }
2610426972
26105 IrInstruction *result = ir_build_mul_add(&ira->new_irb,
26106 instruction->base.scope, instruction->base.source_node,
26107 type_value, casted_op1, casted_op2, casted_op3);
26108 result->value->type = expr_type;
26109 return result;
26973 return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type);
2611026974}
2611126975
26112static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {
26113 IrInstruction *base_ptr = instruction->base_ptr->child;
26976static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) {
26977 IrInstGen *base_ptr = instruction->base_ptr->child;
2611426978 if (type_is_invalid(base_ptr->value->type))
26115 return ira->codegen->invalid_instruction;
26979 return ira->codegen->invalid_inst_gen;
2611626980
26117 IrInstruction *value;
26981 IrInstGen *value;
2611826982 if (instruction->base_ptr_is_payload) {
2611926983 value = base_ptr;
2612026984 } else {
26121 value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);
26985 value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr);
2612226986 }
2612326987
2612426988 ZigType *type_entry = value->value->type;
2612526989 if (type_is_invalid(type_entry))
26126 return ira->codegen->invalid_instruction;
26990 return ira->codegen->invalid_inst_gen;
2612726991 if (type_entry->id == ZigTypeIdErrorUnion) {
2612826992 if (instr_is_comptime(value)) {
2612926993 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
2613026994 if (!err_union_val)
26131 return ira->codegen->invalid_instruction;
26995 return ira->codegen->invalid_inst_gen;
2613226996
2613326997 if (err_union_val->special != ConstValSpecialRuntime) {
2613426998 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;
26135 return ir_const_bool(ira, &instruction->base, (err != nullptr));
26999 return ir_const_bool(ira, &instruction->base.base, (err != nullptr));
2613627000 }
2613727001 }
2613827002
2613927003 if (instruction->resolve_err_set) {
2614027004 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
26141 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
26142 return ira->codegen->invalid_instruction;
27005 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) {
27006 return ira->codegen->invalid_inst_gen;
2614327007 }
2614427008 if (!type_is_global_error_set(err_set_type) &&
2614527009 err_set_type->data.error_set.err_count == 0)
2614627010 {
2614727011 assert(!err_set_type->data.error_set.incomplete);
26148 return ir_const_bool(ira, &instruction->base, false);
27012 return ir_const_bool(ira, &instruction->base.base, false);
2614927013 }
2615027014 }
2615127015
26152 return ir_build_test_err_gen(ira, &instruction->base, value);
27016 return ir_build_test_err_gen(ira, &instruction->base.base, value);
2615327017 } else if (type_entry->id == ZigTypeIdErrorSet) {
26154 return ir_const_bool(ira, &instruction->base, true);
27018 return ir_const_bool(ira, &instruction->base.base, true);
2615527019 } else {
26156 return ir_const_bool(ira, &instruction->base, false);
27020 return ir_const_bool(ira, &instruction->base.base, false);
2615727021 }
2615827022}
2615927023
26160static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,
26161 IrInstruction *base_ptr, bool initializing)
27024static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
27025 IrInstGen *base_ptr, bool initializing)
2616227026{
2616327027 ZigType *ptr_type = base_ptr->value->type;
2616427028
......@@ -26167,12 +27031,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2616727031
2616827032 ZigType *type_entry = ptr_type->data.pointer.child_type;
2616927033 if (type_is_invalid(type_entry))
26170 return ira->codegen->invalid_instruction;
27034 return ira->codegen->invalid_inst_gen;
2617127035
2617227036 if (type_entry->id != ZigTypeIdErrorUnion) {
26173 ir_add_error(ira, base_ptr,
27037 ir_add_error(ira, &base_ptr->base,
2617427038 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
26175 return ira->codegen->invalid_instruction;
27039 return ira->codegen->invalid_inst_gen;
2617627040 }
2617727041
2617827042 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
......@@ -26183,13 +27047,13 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2618327047 if (instr_is_comptime(base_ptr)) {
2618427048 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
2618527049 if (!ptr_val)
26186 return ira->codegen->invalid_instruction;
27050 return ira->codegen->invalid_inst_gen;
2618727051 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
2618827052 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
2618927053 {
2619027054 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2619127055 if (err_union_val == nullptr)
26192 return ira->codegen->invalid_instruction;
27056 return ira->codegen->invalid_inst_gen;
2619327057
2619427058 if (initializing && err_union_val->special == ConstValSpecialUndef) {
2619527059 ZigValue *vals = create_const_vals(2);
......@@ -26212,11 +27076,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2621227076 }
2621327077 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);
2621427078
26215 IrInstruction *result;
27079 IrInstGen *result;
2621627080 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26217 result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope,
26218 source_instr->source_node, base_ptr);
26219 result->value->type = result_type;
27081 result = ir_build_unwrap_err_code_gen(ira, source_instr->scope,
27082 source_instr->source_node, base_ptr, result_type);
2622027083 result->value->special = ConstValSpecialStatic;
2622127084 } else {
2622227085 result = ir_const(ira, source_instr, result_type);
......@@ -26229,23 +27092,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2622927092 }
2623027093 }
2623127094
26232 IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb,
26233 source_instr->scope, source_instr->source_node, base_ptr);
26234 result->value->type = result_type;
26235 return result;
27095 return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type);
2623627096}
2623727097
26238static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
26239 IrInstructionUnwrapErrCode *instruction)
26240{
26241 IrInstruction *base_ptr = instruction->err_union_ptr->child;
27098static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) {
27099 IrInstGen *base_ptr = instruction->err_union_ptr->child;
2624227100 if (type_is_invalid(base_ptr->value->type))
26243 return ira->codegen->invalid_instruction;
26244 return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false);
27101 return ira->codegen->invalid_inst_gen;
27102 return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false);
2624527103}
2624627104
26247static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
26248 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
27105static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
27106 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
2624927107{
2625027108 ZigType *ptr_type = base_ptr->value->type;
2625127109
......@@ -26254,17 +27112,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2625427112
2625527113 ZigType *type_entry = ptr_type->data.pointer.child_type;
2625627114 if (type_is_invalid(type_entry))
26257 return ira->codegen->invalid_instruction;
27115 return ira->codegen->invalid_inst_gen;
2625827116
2625927117 if (type_entry->id != ZigTypeIdErrorUnion) {
26260 ir_add_error(ira, base_ptr,
27118 ir_add_error(ira, &base_ptr->base,
2626127119 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
26262 return ira->codegen->invalid_instruction;
27120 return ira->codegen->invalid_inst_gen;
2626327121 }
2626427122
2626527123 ZigType *payload_type = type_entry->data.error_union.payload_type;
2626627124 if (type_is_invalid(payload_type))
26267 return ira->codegen->invalid_instruction;
27125 return ira->codegen->invalid_inst_gen;
2626827126
2626927127 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
2627027128 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
......@@ -26273,11 +27131,11 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2627327131 if (instr_is_comptime(base_ptr)) {
2627427132 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
2627527133 if (!ptr_val)
26276 return ira->codegen->invalid_instruction;
27134 return ira->codegen->invalid_inst_gen;
2627727135 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2627827136 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2627927137 if (err_union_val == nullptr)
26280 return ira->codegen->invalid_instruction;
27138 return ira->codegen->invalid_inst_gen;
2628127139 if (initializing && err_union_val->special == ConstValSpecialUndef) {
2628227140 ZigValue *vals = create_const_vals(2);
2628327141 ZigValue *err_set_val = &vals[0];
......@@ -26300,14 +27158,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2630027158 if (err != nullptr) {
2630127159 ir_add_error(ira, source_instr,
2630227160 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));
26303 return ira->codegen->invalid_instruction;
27161 return ira->codegen->invalid_inst_gen;
2630427162 }
2630527163
26306 IrInstruction *result;
27164 IrInstGen *result;
2630727165 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26308 result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
26309 source_instr->source_node, base_ptr, safety_check_on, initializing);
26310 result->value->type = result_type;
27166 result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope,
27167 source_instr->source_node, base_ptr, safety_check_on, initializing, result_type);
2631127168 result->value->special = ConstValSpecialStatic;
2631227169 } else {
2631327170 result = ir_const(ira, source_instr, result_type);
......@@ -26320,28 +27177,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2632027177 }
2632127178 }
2632227179
26323 IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
26324 source_instr->source_node, base_ptr, safety_check_on, initializing);
26325 result->value->type = result_type;
26326 return result;
27180 return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node,
27181 base_ptr, safety_check_on, initializing, result_type);
2632727182}
2632827183
26329static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
26330 IrInstructionUnwrapErrPayload *instruction)
27184static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
27185 IrInstSrcUnwrapErrPayload *instruction)
2633127186{
2633227187 assert(instruction->value->child);
26333 IrInstruction *value = instruction->value->child;
27188 IrInstGen *value = instruction->value->child;
2633427189 if (type_is_invalid(value->value->type))
26335 return ira->codegen->invalid_instruction;
27190 return ira->codegen->invalid_inst_gen;
2633627191
26337 return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false);
27192 return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false);
2633827193}
2633927194
26340static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {
26341 AstNode *proto_node = instruction->base.source_node;
27195static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) {
27196 AstNode *proto_node = instruction->base.base.source_node;
2634227197 assert(proto_node->type == NodeTypeFnProto);
2634327198
26344 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
27199 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2634527200 result->value->special = ConstValSpecialLazy;
2634627201
2634727202 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");
......@@ -26350,29 +27205,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2635027205 lazy_fn_type->base.id = LazyValueIdFnType;
2635127206
2635227207 if (proto_node->data.fn_proto.auto_err_set) {
26353 ir_add_error(ira, &instruction->base,
27208 ir_add_error(ira, &instruction->base.base,
2635427209 buf_sprintf("inferring error set of return type valid only for function definitions"));
26355 return ira->codegen->invalid_instruction;
27210 return ira->codegen->invalid_inst_gen;
2635627211 }
2635727212
2635827213 lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto);
2635927214 if (instruction->callconv_value != nullptr) {
2636027215 ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention");
2636127216
26362 IrInstruction *casted_value = ir_implicit_cast(ira, instruction->callconv_value, cc_enum_type);
27217 IrInstGen *casted_value = ir_implicit_cast(ira, instruction->callconv_value->child, cc_enum_type);
2636327218 if (type_is_invalid(casted_value->value->type))
26364 return ira->codegen->invalid_instruction;
27219 return ira->codegen->invalid_inst_gen;
2636527220
2636627221 ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad);
2636727222 if (const_value == nullptr)
26368 return ira->codegen->invalid_instruction;
27223 return ira->codegen->invalid_inst_gen;
2636927224
2637027225 lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag);
2637127226 }
2637227227
2637327228 size_t param_count = proto_node->data.fn_proto.params.length;
2637427229 lazy_fn_type->proto_node = proto_node;
26375 lazy_fn_type->param_types = allocate<IrInstruction *>(param_count);
27230 lazy_fn_type->param_types = allocate<IrInstGen *>(param_count);
2637627231
2637727232 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
2637827233 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);
......@@ -26397,63 +27252,63 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2639727252 return result;
2639827253 }
2639927254
26400 IrInstruction *param_type_value = instruction->param_types[param_index]->child;
27255 IrInstGen *param_type_value = instruction->param_types[param_index]->child;
2640127256 if (type_is_invalid(param_type_value->value->type))
26402 return ira->codegen->invalid_instruction;
27257 return ira->codegen->invalid_inst_gen;
2640327258 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)
26404 return ira->codegen->invalid_instruction;
27259 return ira->codegen->invalid_inst_gen;
2640527260 lazy_fn_type->param_types[param_index] = param_type_value;
2640627261 }
2640727262
2640827263 if (instruction->align_value != nullptr) {
2640927264 lazy_fn_type->align_inst = instruction->align_value->child;
2641027265 if (ir_resolve_const(ira, lazy_fn_type->align_inst, LazyOk) == nullptr)
26411 return ira->codegen->invalid_instruction;
27266 return ira->codegen->invalid_inst_gen;
2641227267 }
2641327268
2641427269 lazy_fn_type->return_type = instruction->return_type->child;
2641527270 if (ir_resolve_const(ira, lazy_fn_type->return_type, LazyOk) == nullptr)
26416 return ira->codegen->invalid_instruction;
27271 return ira->codegen->invalid_inst_gen;
2641727272
2641827273 return result;
2641927274}
2642027275
26421static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
26422 IrInstruction *value = instruction->value->child;
27276static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrcTestComptime *instruction) {
27277 IrInstGen *value = instruction->value->child;
2642327278 if (type_is_invalid(value->value->type))
26424 return ira->codegen->invalid_instruction;
27279 return ira->codegen->invalid_inst_gen;
2642527280
26426 return ir_const_bool(ira, &instruction->base, instr_is_comptime(value));
27281 return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value));
2642727282}
2642827283
26429static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26430 IrInstructionCheckSwitchProngs *instruction)
27284static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
27285 IrInstSrcCheckSwitchProngs *instruction)
2643127286{
26432 IrInstruction *target_value = instruction->target_value->child;
27287 IrInstGen *target_value = instruction->target_value->child;
2643327288 ZigType *switch_type = target_value->value->type;
2643427289 if (type_is_invalid(switch_type))
26435 return ira->codegen->invalid_instruction;
27290 return ira->codegen->invalid_inst_gen;
2643627291
2643727292 if (switch_type->id == ZigTypeIdEnum) {
2643827293 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
2643927294 field_prev_uses.init(switch_type->data.enumeration.src_field_count);
2644027295
2644127296 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26442 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27297 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2644327298
26444 IrInstruction *start_value_uncasted = range->start->child;
27299 IrInstGen *start_value_uncasted = range->start->child;
2644527300 if (type_is_invalid(start_value_uncasted->value->type))
26446 return ira->codegen->invalid_instruction;
26447 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
27301 return ira->codegen->invalid_inst_gen;
27302 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
2644827303 if (type_is_invalid(start_value->value->type))
26449 return ira->codegen->invalid_instruction;
27304 return ira->codegen->invalid_inst_gen;
2645027305
26451 IrInstruction *end_value_uncasted = range->end->child;
27306 IrInstGen *end_value_uncasted = range->end->child;
2645227307 if (type_is_invalid(end_value_uncasted->value->type))
26453 return ira->codegen->invalid_instruction;
26454 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
27308 return ira->codegen->invalid_inst_gen;
27309 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
2645527310 if (type_is_invalid(end_value->value->type))
26456 return ira->codegen->invalid_instruction;
27311 return ira->codegen->invalid_inst_gen;
2645727312
2645827313 assert(start_value->value->type->id == ZigTypeIdEnum);
2645927314 BigInt start_index;
......@@ -26464,7 +27319,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2646427319 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
2646527320
2646627321 if (bigint_cmp(&start_index, &end_index) == CmpGT) {
26467 ir_add_error(ira, start_value,
27322 ir_add_error(ira, &start_value->base,
2646827323 buf_sprintf("range start value is greater than the end value"));
2646927324 }
2647027325
......@@ -26475,12 +27330,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2647527330 if (cmp == CmpGT) {
2647627331 break;
2647727332 }
26478 auto entry = field_prev_uses.put_unique(field_index, start_value->source_node);
27333 auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node);
2647927334 if (entry) {
2648027335 AstNode *prev_node = entry->value;
2648127336 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);
2648227337 assert(enum_field != nullptr);
26483 ErrorMsg *msg = ir_add_error(ira, start_value,
27338 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
2648427339 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),
2648527340 buf_ptr(enum_field->name)));
2648627341 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
......@@ -26490,7 +27345,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2649027345 }
2649127346 if (instruction->have_underscore_prong) {
2649227347 if (!switch_type->data.enumeration.non_exhaustive){
26493 ir_add_error(ira, &instruction->base,
27348 ir_add_error(ira, &instruction->base.base,
2649427349 buf_sprintf("switch on non-exhaustive enum has `_` prong"));
2649527350 }
2649627351 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
......@@ -26500,14 +27355,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2650027355
2650127356 auto entry = field_prev_uses.maybe_get(enum_field->value);
2650227357 if (!entry) {
26503 ir_add_error(ira, &instruction->base,
27358 ir_add_error(ira, &instruction->base.base,
2650427359 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
2650527360 buf_ptr(enum_field->name)));
2650627361 }
2650727362 }
2650827363 } else if (!instruction->have_else_prong) {
2650927364 if (switch_type->data.enumeration.non_exhaustive) {
26510 ir_add_error(ira, &instruction->base,
27365 ir_add_error(ira, &instruction->base.base,
2651127366 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));
2651227367 }
2651327368 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
......@@ -26515,69 +27370,69 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2651527370
2651627371 auto entry = field_prev_uses.maybe_get(enum_field->value);
2651727372 if (!entry) {
26518 ir_add_error(ira, &instruction->base,
27373 ir_add_error(ira, &instruction->base.base,
2651927374 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
2652027375 buf_ptr(enum_field->name)));
2652127376 }
2652227377 }
2652327378 }
2652427379 } else if (switch_type->id == ZigTypeIdErrorSet) {
26525 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
26526 return ira->codegen->invalid_instruction;
27380 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) {
27381 return ira->codegen->invalid_inst_gen;
2652727382 }
2652827383
2652927384 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;
2653027385 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");
2653127386
2653227387 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26533 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27388 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2653427389
26535 IrInstruction *start_value_uncasted = range->start->child;
27390 IrInstGen *start_value_uncasted = range->start->child;
2653627391 if (type_is_invalid(start_value_uncasted->value->type))
26537 return ira->codegen->invalid_instruction;
26538 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
27392 return ira->codegen->invalid_inst_gen;
27393 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
2653927394 if (type_is_invalid(start_value->value->type))
26540 return ira->codegen->invalid_instruction;
27395 return ira->codegen->invalid_inst_gen;
2654127396
26542 IrInstruction *end_value_uncasted = range->end->child;
27397 IrInstGen *end_value_uncasted = range->end->child;
2654327398 if (type_is_invalid(end_value_uncasted->value->type))
26544 return ira->codegen->invalid_instruction;
26545 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
27399 return ira->codegen->invalid_inst_gen;
27400 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
2654627401 if (type_is_invalid(end_value->value->type))
26547 return ira->codegen->invalid_instruction;
27402 return ira->codegen->invalid_inst_gen;
2654827403
26549 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
27404 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
2655027405 uint32_t start_index = start_value->value->data.x_err_set->value;
2655127406
26552 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
27407 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
2655327408 uint32_t end_index = end_value->value->data.x_err_set->value;
2655427409
2655527410 if (start_index != end_index) {
26556 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));
26557 return ira->codegen->invalid_instruction;
27411 ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors"));
27412 return ira->codegen->invalid_inst_gen;
2655827413 }
2655927414
2656027415 AstNode *prev_node = field_prev_uses[start_index];
2656127416 if (prev_node != nullptr) {
2656227417 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;
26563 ErrorMsg *msg = ir_add_error(ira, start_value,
27418 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
2656427419 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));
2656527420 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
2656627421 }
26567 field_prev_uses[start_index] = start_value->source_node;
27422 field_prev_uses[start_index] = start_value->base.source_node;
2656827423 }
2656927424 if (!instruction->have_else_prong) {
2657027425 if (type_is_global_error_set(switch_type)) {
26571 ir_add_error(ira, &instruction->base,
27426 ir_add_error(ira, &instruction->base.base,
2657227427 buf_sprintf("else prong required when switching on type 'anyerror'"));
26573 return ira->codegen->invalid_instruction;
27428 return ira->codegen->invalid_inst_gen;
2657427429 } else {
2657527430 for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {
2657627431 ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i];
2657727432
2657827433 AstNode *prev_node = field_prev_uses[err_entry->value];
2657927434 if (prev_node == nullptr) {
26580 ir_add_error(ira, &instruction->base,
27435 ir_add_error(ira, &instruction->base.base,
2658127436 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));
2658227437 }
2658327438 }
......@@ -26588,44 +27443,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2658827443 } else if (switch_type->id == ZigTypeIdInt) {
2658927444 RangeSet rs = {0};
2659027445 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26591 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27446 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2659227447
26593 IrInstruction *start_value = range->start->child;
27448 IrInstGen *start_value = range->start->child;
2659427449 if (type_is_invalid(start_value->value->type))
26595 return ira->codegen->invalid_instruction;
26596 IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);
27450 return ira->codegen->invalid_inst_gen;
27451 IrInstGen *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);
2659727452 if (type_is_invalid(casted_start_value->value->type))
26598 return ira->codegen->invalid_instruction;
27453 return ira->codegen->invalid_inst_gen;
2659927454
26600 IrInstruction *end_value = range->end->child;
27455 IrInstGen *end_value = range->end->child;
2660127456 if (type_is_invalid(end_value->value->type))
26602 return ira->codegen->invalid_instruction;
26603 IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);
27457 return ira->codegen->invalid_inst_gen;
27458 IrInstGen *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);
2660427459 if (type_is_invalid(casted_end_value->value->type))
26605 return ira->codegen->invalid_instruction;
27460 return ira->codegen->invalid_inst_gen;
2660627461
2660727462 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);
2660827463 if (!start_val)
26609 return ira->codegen->invalid_instruction;
27464 return ira->codegen->invalid_inst_gen;
2661027465
2661127466 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);
2661227467 if (!end_val)
26613 return ira->codegen->invalid_instruction;
27468 return ira->codegen->invalid_inst_gen;
2661427469
2661527470 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
2661627471 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
2661727472
2661827473 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {
26619 ir_add_error(ira, start_value,
27474 ir_add_error(ira, &start_value->base,
2662027475 buf_sprintf("range start value is greater than the end value"));
2662127476 }
2662227477
2662327478 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
26624 start_value->source_node);
27479 start_value->base.source_node);
2662527480 if (prev_node != nullptr) {
26626 ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value"));
27481 ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value"));
2662727482 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here"));
26628 return ira->codegen->invalid_instruction;
27483 return ira->codegen->invalid_inst_gen;
2662927484 }
2663027485 }
2663127486 if (!instruction->have_else_prong) {
......@@ -26634,25 +27489,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2663427489 BigInt max_val;
2663527490 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);
2663627491 if (!rangeset_spans(&rs, &min_val, &max_val)) {
26637 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));
26638 return ira->codegen->invalid_instruction;
27492 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
27493 return ira->codegen->invalid_inst_gen;
2663927494 }
2664027495 }
2664127496 } else if (switch_type->id == ZigTypeIdBool) {
2664227497 int seenTrue = 0;
2664327498 int seenFalse = 0;
2664427499 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26645 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27500 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2664627501
26647 IrInstruction *value = range->start->child;
27502 IrInstGen *value = range->start->child;
2664827503
26649 IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type);
27504 IrInstGen *casted_value = ir_implicit_cast(ira, value, switch_type);
2665027505 if (type_is_invalid(casted_value->value->type))
26651 return ira->codegen->invalid_instruction;
27506 return ira->codegen->invalid_inst_gen;
2665227507
2665327508 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);
2665427509 if (!const_expr_val)
26655 return ira->codegen->invalid_instruction;
27510 return ira->codegen->invalid_inst_gen;
2665627511
2665727512 assert(const_expr_val->type->id == ZigTypeIdBool);
2665827513
......@@ -26663,60 +27518,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2666327518 }
2666427519
2666527520 if ((seenTrue > 1) || (seenFalse > 1)) {
26666 ir_add_error(ira, value, buf_sprintf("duplicate switch value"));
26667 return ira->codegen->invalid_instruction;
27521 ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));
27522 return ira->codegen->invalid_inst_gen;
2666827523 }
2666927524 }
2667027525 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {
26671 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));
26672 return ira->codegen->invalid_instruction;
27526 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
27527 return ira->codegen->invalid_inst_gen;
2667327528 }
2667427529 } else if (!instruction->have_else_prong) {
26675 ir_add_error(ira, &instruction->base,
27530 ir_add_error(ira, &instruction->base.base,
2667627531 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
26677 return ira->codegen->invalid_instruction;
27532 return ira->codegen->invalid_inst_gen;
2667827533 }
26679 return ir_const_void(ira, &instruction->base);
27534 return ir_const_void(ira, &instruction->base.base);
2668027535}
2668127536
26682static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
26683 IrInstructionCheckStatementIsVoid *instruction)
27537static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
27538 IrInstSrcCheckStatementIsVoid *instruction)
2668427539{
26685 IrInstruction *statement_value = instruction->statement_value->child;
27540 IrInstGen *statement_value = instruction->statement_value->child;
2668627541 ZigType *statement_type = statement_value->value->type;
2668727542 if (type_is_invalid(statement_type))
26688 return ira->codegen->invalid_instruction;
27543 return ira->codegen->invalid_inst_gen;
2668927544
2669027545 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {
26691 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));
27546 ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored"));
2669227547 }
2669327548
26694 return ir_const_void(ira, &instruction->base);
27549 return ir_const_void(ira, &instruction->base.base);
2669527550}
2669627551
26697static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
26698 IrInstruction *msg = instruction->msg->child;
27552static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) {
27553 IrInstGen *msg = instruction->msg->child;
2669927554 if (type_is_invalid(msg->value->type))
2670027555 return ir_unreach_error(ira);
2670127556
26702 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
26703 ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));
27557 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) {
27558 ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time"));
2670427559 return ir_unreach_error(ira);
2670527560 }
2670627561
2670727562 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
2670827563 true, false, PtrLenUnknown, 0, 0, 0, false);
2670927564 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
26710 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
27565 IrInstGen *casted_msg = ir_implicit_cast(ira, msg, str_type);
2671127566 if (type_is_invalid(casted_msg->value->type))
2671227567 return ir_unreach_error(ira);
2671327568
26714 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,
26715 instruction->base.source_node, casted_msg);
27569 IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg);
2671627570 return ir_finish_anal(ira, new_instruction);
2671727571}
2671827572
26719static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {
27573static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t align_bytes, bool safety_check_on) {
2672027574 Error err;
2672127575
2672227576 ZigType *target_type = target->value->type;
......@@ -26728,7 +27582,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2672827582 if (target_type->id == ZigTypeIdPointer) {
2672927583 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
2673027584 if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes)))
26731 return ira->codegen->invalid_instruction;
27585 return ira->codegen->invalid_inst_gen;
2673227586 } else if (target_type->id == ZigTypeIdFn) {
2673327587 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
2673427588 old_align_bytes = fn_type_id.alignment;
......@@ -26739,7 +27593,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2673927593 {
2674027594 ZigType *ptr_type = target_type->data.maybe.child_type;
2674127595 if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes)))
26742 return ira->codegen->invalid_instruction;
27596 return ira->codegen->invalid_inst_gen;
2674327597 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
2674427598
2674527599 result_type = get_optional_type(ira->codegen, better_ptr_type);
......@@ -26754,47 +27608,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2675427608 } else if (is_slice(target_type)) {
2675527609 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;
2675627610 if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes)))
26757 return ira->codegen->invalid_instruction;
27611 return ira->codegen->invalid_inst_gen;
2675827612 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
2675927613 result_type = get_slice_type(ira->codegen, result_ptr_type);
2676027614 } else {
26761 ir_add_error(ira, target,
27615 ir_add_error(ira, &target->base,
2676227616 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));
26763 return ira->codegen->invalid_instruction;
27617 return ira->codegen->invalid_inst_gen;
2676427618 }
2676527619
2676627620 if (instr_is_comptime(target)) {
2676727621 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2676827622 if (!val)
26769 return ira->codegen->invalid_instruction;
27623 return ira->codegen->invalid_inst_gen;
2677027624
2677127625 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
2677227626 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
2677327627 {
26774 ir_add_error(ira, target,
27628 ir_add_error(ira, &target->base,
2677527629 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",
2677627630 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
26777 return ira->codegen->invalid_instruction;
27631 return ira->codegen->invalid_inst_gen;
2677827632 }
2677927633
26780 IrInstruction *result = ir_const(ira, target, result_type);
27634 IrInstGen *result = ir_const(ira, &target->base, result_type);
2678127635 copy_const_val(result->value, val);
2678227636 result->value->type = result_type;
2678327637 return result;
2678427638 }
2678527639
26786 IrInstruction *result;
2678727640 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {
26788 result = ir_build_align_cast(&ira->new_irb, target->scope, target->source_node, nullptr, target);
27641 return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type);
2678927642 } else {
26790 result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop);
27643 return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop);
2679127644 }
26792 result->value->type = result_type;
26793 return result;
2679427645}
2679527646
26796static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
26797 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on)
27647static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
27648 ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on)
2679827649{
2679927650 Error err;
2680027651
......@@ -26810,44 +27661,44 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2681027661
2681127662 ZigType *src_ptr_type = get_src_ptr_type(src_type);
2681227663 if (src_ptr_type == nullptr) {
26813 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
26814 return ira->codegen->invalid_instruction;
27664 ir_add_error(ira, &ptr->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
27665 return ira->codegen->invalid_inst_gen;
2681527666 }
2681627667
2681727668 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);
2681827669 if (dest_ptr_type == nullptr) {
2681927670 ir_add_error(ira, dest_type_src,
2682027671 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
26821 return ira->codegen->invalid_instruction;
27672 return ira->codegen->invalid_inst_gen;
2682227673 }
2682327674
2682427675 if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) {
2682527676 ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier"));
26826 return ira->codegen->invalid_instruction;
27677 return ira->codegen->invalid_inst_gen;
2682727678 }
2682827679 uint32_t src_align_bytes;
2682927680 if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes)))
26830 return ira->codegen->invalid_instruction;
27681 return ira->codegen->invalid_inst_gen;
2683127682
2683227683 uint32_t dest_align_bytes;
2683327684 if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes)))
26834 return ira->codegen->invalid_instruction;
27685 return ira->codegen->invalid_inst_gen;
2683527686
2683627687 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26837 return ira->codegen->invalid_instruction;
27688 return ira->codegen->invalid_inst_gen;
2683827689
2683927690 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))
26840 return ira->codegen->invalid_instruction;
27691 return ira->codegen->invalid_inst_gen;
2684127692
2684227693 if (type_has_bits(dest_type) && !type_has_bits(src_type)) {
2684327694 ErrorMsg *msg = ir_add_error(ira, source_instr,
2684427695 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
2684527696 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
26846 add_error_note(ira->codegen, msg, ptr->source_node,
27697 add_error_note(ira->codegen, msg, ptr->base.source_node,
2684727698 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));
2684827699 add_error_note(ira->codegen, msg, dest_type_src->source_node,
2684927700 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));
26850 return ira->codegen->invalid_instruction;
27701 return ira->codegen->invalid_inst_gen;
2685127702 }
2685227703
2685327704 if (instr_is_comptime(ptr)) {
......@@ -26855,7 +27706,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2685527706 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;
2685627707 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);
2685727708 if (!val)
26858 return ira->codegen->invalid_instruction;
27709 return ira->codegen->invalid_inst_gen;
2685927710
2686027711 if (value_is_comptime(val) && val->special != ConstValSpecialUndef) {
2686127712 bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull ||
......@@ -26864,16 +27715,16 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2686427715 if (is_addr_zero && !dest_allows_addr_zero) {
2686527716 ir_add_error(ira, source_instr,
2686627717 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));
26867 return ira->codegen->invalid_instruction;
27718 return ira->codegen->invalid_inst_gen;
2686827719 }
2686927720 }
2687027721
26871 IrInstruction *result;
27722 IrInstGen *result;
2687227723 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
2687327724 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2687427725
2687527726 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26876 return ira->codegen->invalid_instruction;
27727 return ira->codegen->invalid_inst_gen;
2687727728 } else {
2687827729 result = ir_const(ira, source_instr, dest_type);
2687927730 }
......@@ -26891,40 +27742,40 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2689127742
2689227743 if (dest_align_bytes > src_align_bytes) {
2689327744 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));
26894 add_error_note(ira->codegen, msg, ptr->source_node,
27745 add_error_note(ira->codegen, msg, ptr->base.source_node,
2689527746 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));
2689627747 add_error_note(ira->codegen, msg, dest_type_src->source_node,
2689727748 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));
26898 return ira->codegen->invalid_instruction;
27749 return ira->codegen->invalid_inst_gen;
2689927750 }
2690027751
26901 IrInstruction *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
27752 IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2690227753
2690327754 // Keep the bigger alignment, it can only help-
2690427755 // unless the target is zero bits.
26905 IrInstruction *result;
27756 IrInstGen *result;
2690627757 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {
2690727758 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);
2690827759 if (type_is_invalid(result->value->type))
26909 return ira->codegen->invalid_instruction;
27760 return ira->codegen->invalid_inst_gen;
2691027761 } else {
2691127762 result = casted_ptr;
2691227763 }
2691327764 return result;
2691427765}
2691527766
26916static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCastSrc *instruction) {
26917 IrInstruction *dest_type_value = instruction->dest_type->child;
27767static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCast *instruction) {
27768 IrInstGen *dest_type_value = instruction->dest_type->child;
2691827769 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2691927770 if (type_is_invalid(dest_type))
26920 return ira->codegen->invalid_instruction;
27771 return ira->codegen->invalid_inst_gen;
2692127772
26922 IrInstruction *ptr = instruction->ptr->child;
27773 IrInstGen *ptr = instruction->ptr->child;
2692327774 ZigType *src_type = ptr->value->type;
2692427775 if (type_is_invalid(src_type))
26925 return ira->codegen->invalid_instruction;
27776 return ira->codegen->invalid_inst_gen;
2692627777
26927 return ir_analyze_ptr_cast(ira, &instruction->base, ptr, dest_type, dest_type_value,
27778 return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, dest_type, &dest_type_value->base,
2692827779 instruction->safety_check_on);
2692927780}
2693027781
......@@ -27255,7 +28106,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2725528106 zig_unreachable();
2725628107}
2725728108
27258static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
28109static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
2725928110 ZigType *dest_type)
2726028111{
2726128112 Error err;
......@@ -27271,14 +28122,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2727128122 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));
2727228123 add_error_note(ira->codegen, msg, source_instr->source_node,
2727328124 buf_sprintf("use @intToEnum for type coercion"));
27274 return ira->codegen->invalid_instruction;
28125 return ira->codegen->invalid_inst_gen;
2727528126 }
2727628127
2727728128 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))
27278 return ira->codegen->invalid_instruction;
28129 return ira->codegen->invalid_inst_gen;
2727928130
2728028131 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown)))
27281 return ira->codegen->invalid_instruction;
28132 return ira->codegen->invalid_inst_gen;
2728228133
2728328134 uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);
2728428135 uint64_t src_size_bytes = type_size(ira->codegen, src_type);
......@@ -27287,7 +28138,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2728728138 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,
2728828139 buf_ptr(&dest_type->name), dest_size_bytes,
2728928140 buf_ptr(&src_type->name), src_size_bytes));
27290 return ira->codegen->invalid_instruction;
28141 return ira->codegen->invalid_inst_gen;
2729128142 }
2729228143
2729328144 uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);
......@@ -27297,26 +28148,26 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2729728148 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",
2729828149 buf_ptr(&dest_type->name), dest_size_bits,
2729928150 buf_ptr(&src_type->name), src_size_bits));
27300 return ira->codegen->invalid_instruction;
28151 return ira->codegen->invalid_inst_gen;
2730128152 }
2730228153
2730328154 if (instr_is_comptime(value)) {
2730428155 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
2730528156 if (!val)
27306 return ira->codegen->invalid_instruction;
28157 return ira->codegen->invalid_inst_gen;
2730728158
27308 IrInstruction *result = ir_const(ira, source_instr, dest_type);
28159 IrInstGen *result = ir_const(ira, source_instr, dest_type);
2730928160 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
2731028161 buf_write_value_bytes(ira->codegen, buf, val);
2731128162 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
27312 return ira->codegen->invalid_instruction;
28163 return ira->codegen->invalid_inst_gen;
2731328164 return result;
2731428165 }
2731528166
2731628167 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
2731728168}
2731828169
27319static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
28170static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
2732028171 ZigType *ptr_type)
2732128172{
2732228173 Error err;
......@@ -27324,136 +28175,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
2732428175 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
2732528176 ir_assert(type_has_bits(ptr_type), source_instr);
2732628177
27327 IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
28178 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
2732828179 if (type_is_invalid(casted_int->value->type))
27329 return ira->codegen->invalid_instruction;
28180 return ira->codegen->invalid_inst_gen;
2733028181
2733128182 if (instr_is_comptime(casted_int)) {
2733228183 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);
2733328184 if (!val)
27334 return ira->codegen->invalid_instruction;
28185 return ira->codegen->invalid_inst_gen;
2733528186
2733628187 uint64_t addr = bigint_as_u64(&val->data.x_bigint);
2733728188 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
2733828189 ir_add_error(ira, source_instr,
2733928190 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));
27340 return ira->codegen->invalid_instruction;
28191 return ira->codegen->invalid_inst_gen;
2734128192 }
2734228193
2734328194 uint32_t align_bytes;
2734428195 if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes)))
27345 return ira->codegen->invalid_instruction;
28196 return ira->codegen->invalid_inst_gen;
2734628197
2734728198 if (addr != 0 && addr % align_bytes != 0) {
2734828199 ir_add_error(ira, source_instr,
2734928200 buf_sprintf("pointer type '%s' requires aligned address",
2735028201 buf_ptr(&ptr_type->name)));
27351 return ira->codegen->invalid_instruction;
28202 return ira->codegen->invalid_inst_gen;
2735228203 }
2735328204
27354 IrInstruction *result = ir_const(ira, source_instr, ptr_type);
28205 IrInstGen *result = ir_const(ira, source_instr, ptr_type);
2735528206 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
2735628207 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
2735728208 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;
2735828209 return result;
2735928210 }
2736028211
27361 IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope,
27362 source_instr->source_node, nullptr, casted_int);
27363 result->value->type = ptr_type;
27364 return result;
28212 return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type);
2736528213}
2736628214
27367static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
28215static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) {
2736828216 Error err;
27369 IrInstruction *dest_type_value = instruction->dest_type->child;
28217 IrInstGen *dest_type_value = instruction->dest_type->child;
2737028218 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2737128219 if (type_is_invalid(dest_type))
27372 return ira->codegen->invalid_instruction;
28220 return ira->codegen->invalid_inst_gen;
2737328221
2737428222 // We explicitly check for the size, so we can use get_src_ptr_type
2737528223 if (get_src_ptr_type(dest_type) == nullptr) {
27376 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
27377 return ira->codegen->invalid_instruction;
28224 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
28225 return ira->codegen->invalid_inst_gen;
2737828226 }
2737928227
2738028228 bool has_bits;
2738128229 if ((err = type_has_bits2(ira->codegen, dest_type, &has_bits)))
27382 return ira->codegen->invalid_instruction;
28230 return ira->codegen->invalid_inst_gen;
2738328231
2738428232 if (!has_bits) {
27385 ir_add_error(ira, dest_type_value,
28233 ir_add_error(ira, &dest_type_value->base,
2738628234 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));
27387 return ira->codegen->invalid_instruction;
28235 return ira->codegen->invalid_inst_gen;
2738828236 }
2738928237
27390 IrInstruction *target = instruction->target->child;
28238 IrInstGen *target = instruction->target->child;
2739128239 if (type_is_invalid(target->value->type))
27392 return ira->codegen->invalid_instruction;
28240 return ira->codegen->invalid_inst_gen;
2739328241
27394 return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type);
28242 return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type);
2739528243}
2739628244
27397static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
27398 IrInstructionDeclRef *instruction)
27399{
27400 IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld);
28245static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) {
28246 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld);
2740128247 if (type_is_invalid(ref_instruction->value->type)) {
27402 return ira->codegen->invalid_instruction;
28248 return ira->codegen->invalid_inst_gen;
2740328249 }
2740428250
2740528251 if (instruction->lval == LValPtr) {
2740628252 return ref_instruction;
2740728253 } else {
27408 return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr);
28254 return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr);
2740928255 }
2741028256}
2741128257
27412static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
28258static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtrToInt *instruction) {
2741328259 Error err;
27414 IrInstruction *target = instruction->target->child;
28260 IrInstGen *target = instruction->target->child;
2741528261 if (type_is_invalid(target->value->type))
27416 return ira->codegen->invalid_instruction;
28262 return ira->codegen->invalid_inst_gen;
2741728263
2741828264 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2741928265
2742028266 // We check size explicitly so we can use get_src_ptr_type here.
2742128267 if (get_src_ptr_type(target->value->type) == nullptr) {
27422 ir_add_error(ira, target,
28268 ir_add_error(ira, &target->base,
2742328269 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));
27424 return ira->codegen->invalid_instruction;
28270 return ira->codegen->invalid_inst_gen;
2742528271 }
2742628272
2742728273 bool has_bits;
2742828274 if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits)))
27429 return ira->codegen->invalid_instruction;
28275 return ira->codegen->invalid_inst_gen;
2743028276
2743128277 if (!has_bits) {
27432 ir_add_error(ira, target,
28278 ir_add_error(ira, &target->base,
2743328279 buf_sprintf("pointer to size 0 type has no address"));
27434 return ira->codegen->invalid_instruction;
28280 return ira->codegen->invalid_inst_gen;
2743528281 }
2743628282
2743728283 if (instr_is_comptime(target)) {
2743828284 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2743928285 if (!val)
27440 return ira->codegen->invalid_instruction;
28286 return ira->codegen->invalid_inst_gen;
2744128287 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
27442 IrInstruction *result = ir_const(ira, &instruction->base, usize);
28288 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);
2744328289 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
2744428290 result->value->type = usize;
2744528291 return result;
2744628292 }
2744728293 }
2744828294
27449 IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope,
27450 instruction->base.source_node, target);
27451 result->value->type = usize;
27452 return result;
28295 return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target);
2745328296}
2745428297
27455static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
27456 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
28298static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) {
28299 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2745728300 result->value->special = ConstValSpecialLazy;
2745828301
2745928302 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");
......@@ -27464,17 +28307,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
2746428307 if (instruction->sentinel != nullptr) {
2746528308 lazy_ptr_type->sentinel = instruction->sentinel->child;
2746628309 if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr)
27467 return ira->codegen->invalid_instruction;
28310 return ira->codegen->invalid_inst_gen;
2746828311 }
2746928312
2747028313 lazy_ptr_type->elem_type = instruction->child_type->child;
2747128314 if (ir_resolve_type_lazy(ira, lazy_ptr_type->elem_type) == nullptr)
27472 return ira->codegen->invalid_instruction;
28315 return ira->codegen->invalid_inst_gen;
2747328316
2747428317 if (instruction->align_value != nullptr) {
2747528318 lazy_ptr_type->align_inst = instruction->align_value->child;
2747628319 if (ir_resolve_const(ira, lazy_ptr_type->align_inst, LazyOk) == nullptr)
27477 return ira->codegen->invalid_instruction;
28320 return ira->codegen->invalid_inst_gen;
2747828321 }
2747928322
2748028323 lazy_ptr_type->ptr_len = instruction->ptr_len;
......@@ -27487,10 +28330,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
2748728330 return result;
2748828331}
2748928332
27490static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
27491 IrInstruction *target = instruction->target->child;
28333static IrInstGen *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstSrcAlignCast *instruction) {
28334 IrInstGen *target = instruction->target->child;
2749228335 if (type_is_invalid(target->value->type))
27493 return ira->codegen->invalid_instruction;
28336 return ira->codegen->invalid_inst_gen;
2749428337
2749528338 ZigType *elem_type = nullptr;
2749628339 if (is_slice(target->value->type)) {
......@@ -27501,192 +28344,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
2750128344 }
2750228345
2750328346 uint32_t align_bytes;
27504 IrInstruction *align_bytes_inst = instruction->align_bytes->child;
28347 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
2750528348 if (!ir_resolve_align(ira, align_bytes_inst, elem_type, &align_bytes))
27506 return ira->codegen->invalid_instruction;
28349 return ira->codegen->invalid_inst_gen;
2750728350
27508 IrInstruction *result = ir_align_cast(ira, target, align_bytes, true);
28351 IrInstGen *result = ir_align_cast(ira, target, align_bytes, true);
2750928352 if (type_is_invalid(result->value->type))
27510 return ira->codegen->invalid_instruction;
28353 return ira->codegen->invalid_inst_gen;
2751128354
2751228355 return result;
2751328356}
2751428357
27515static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
28358static IrInstGen *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstSrcOpaqueType *instruction) {
2751628359 Buf *bare_name = buf_alloc();
27517 Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque",
27518 instruction->base.scope, instruction->base.source_node, bare_name);
27519 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,
27520 buf_ptr(full_name), bare_name);
27521 return ir_const_type(ira, &instruction->base, result_type);
28360 Buf *full_name = get_anon_type_name(ira->codegen, ira->old_irb.exec, "opaque",
28361 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
28362 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.base.scope,
28363 instruction->base.base.source_node, buf_ptr(full_name), bare_name);
28364 return ir_const_type(ira, &instruction->base.base, result_type);
2752228365}
2752328366
27524static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) {
28367static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstSrcSetAlignStack *instruction) {
2752528368 uint32_t align_bytes;
27526 IrInstruction *align_bytes_inst = instruction->align_bytes->child;
28369 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
2752728370 if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes))
27528 return ira->codegen->invalid_instruction;
28371 return ira->codegen->invalid_inst_gen;
2752928372
2753028373 if (align_bytes > 256) {
27531 ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
27532 return ira->codegen->invalid_instruction;
28374 ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
28375 return ira->codegen->invalid_inst_gen;
2753328376 }
2753428377
27535 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
28378 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
2753628379 if (fn_entry == nullptr) {
27537 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));
27538 return ira->codegen->invalid_instruction;
28380 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function"));
28381 return ira->codegen->invalid_inst_gen;
2753928382 }
2754028383 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {
27541 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in naked function"));
27542 return ira->codegen->invalid_instruction;
28384 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function"));
28385 return ira->codegen->invalid_inst_gen;
2754328386 }
2754428387
2754528388 if (fn_entry->fn_inline == FnInlineAlways) {
27546 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in inline function"));
27547 return ira->codegen->invalid_instruction;
28389 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function"));
28390 return ira->codegen->invalid_inst_gen;
2754828391 }
2754928392
2755028393 if (fn_entry->set_alignstack_node != nullptr) {
27551 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
28394 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2755228395 buf_sprintf("alignstack set twice"));
2755328396 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));
27554 return ira->codegen->invalid_instruction;
28397 return ira->codegen->invalid_inst_gen;
2755528398 }
2755628399
27557 fn_entry->set_alignstack_node = instruction->base.source_node;
28400 fn_entry->set_alignstack_node = instruction->base.base.source_node;
2755828401 fn_entry->alignstack_value = align_bytes;
2755928402
27560 return ir_const_void(ira, &instruction->base);
28403 return ir_const_void(ira, &instruction->base.base);
2756128404}
2756228405
27563static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
27564 IrInstruction *fn_type_inst = instruction->fn_type->child;
28406static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) {
28407 IrInstGen *fn_type_inst = instruction->fn_type->child;
2756528408 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
2756628409 if (type_is_invalid(fn_type))
27567 return ira->codegen->invalid_instruction;
28410 return ira->codegen->invalid_inst_gen;
2756828411
27569 IrInstruction *arg_index_inst = instruction->arg_index->child;
28412 IrInstGen *arg_index_inst = instruction->arg_index->child;
2757028413 uint64_t arg_index;
2757128414 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
27572 return ira->codegen->invalid_instruction;
28415 return ira->codegen->invalid_inst_gen;
2757328416
2757428417 if (fn_type->id == ZigTypeIdBoundFn) {
2757528418 fn_type = fn_type->data.bound_fn.fn_type;
2757628419 arg_index += 1;
2757728420 }
2757828421 if (fn_type->id != ZigTypeIdFn) {
27579 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
27580 return ira->codegen->invalid_instruction;
28422 ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
28423 return ira->codegen->invalid_inst_gen;
2758128424 }
2758228425
2758328426 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
2758428427 if (arg_index >= fn_type_id->param_count) {
2758528428 if (instruction->allow_var) {
2758628429 // TODO remove this with var args
27587 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);
28430 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var);
2758828431 }
27589 ir_add_error(ira, arg_index_inst,
28432 ir_add_error(ira, &arg_index_inst->base,
2759028433 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",
2759128434 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
27592 return ira->codegen->invalid_instruction;
28435 return ira->codegen->invalid_inst_gen;
2759328436 }
2759428437
2759528438 ZigType *result_type = fn_type_id->param_info[arg_index].type;
2759628439 if (result_type == nullptr) {
2759728440 // Args are only unresolved if our function is generic.
27598 ir_assert(fn_type->data.fn.is_generic, &instruction->base);
28441 ir_assert(fn_type->data.fn.is_generic, &instruction->base.base);
2759928442
2760028443 if (instruction->allow_var) {
27601 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);
28444 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var);
2760228445 } else {
27603 ir_add_error(ira, arg_index_inst,
28446 ir_add_error(ira, &arg_index_inst->base,
2760428447 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
2760528448 arg_index, buf_ptr(&fn_type->name)));
27606 return ira->codegen->invalid_instruction;
28449 return ira->codegen->invalid_inst_gen;
2760728450 }
2760828451 }
27609 return ir_const_type(ira, &instruction->base, result_type);
28452 return ir_const_type(ira, &instruction->base.base, result_type);
2761028453}
2761128454
27612static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
28455static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) {
2761328456 Error err;
27614 IrInstruction *target_inst = instruction->target->child;
28457 IrInstGen *target_inst = instruction->target->child;
2761528458 ZigType *enum_type = ir_resolve_type(ira, target_inst);
2761628459 if (type_is_invalid(enum_type))
27617 return ira->codegen->invalid_instruction;
28460 return ira->codegen->invalid_inst_gen;
2761828461
2761928462 if (enum_type->id == ZigTypeIdEnum) {
2762028463 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
27621 return ira->codegen->invalid_instruction;
28464 return ira->codegen->invalid_inst_gen;
2762228465
27623 return ir_const_type(ira, &instruction->base, enum_type->data.enumeration.tag_int_type);
28466 return ir_const_type(ira, &instruction->base.base, enum_type->data.enumeration.tag_int_type);
2762428467 } else if (enum_type->id == ZigTypeIdUnion) {
27625 ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target, enum_type);
28468 ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target->base.source_node, enum_type);
2762628469 if (type_is_invalid(tag_type))
27627 return ira->codegen->invalid_instruction;
27628 return ir_const_type(ira, &instruction->base, tag_type);
28470 return ira->codegen->invalid_inst_gen;
28471 return ir_const_type(ira, &instruction->base.base, tag_type);
2762928472 } else {
27630 ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'",
28473 ir_add_error(ira, &target_inst->base, buf_sprintf("expected enum or union, found '%s'",
2763128474 buf_ptr(&enum_type->name)));
27632 return ira->codegen->invalid_instruction;
28475 return ira->codegen->invalid_inst_gen;
2763328476 }
2763428477}
2763528478
27636static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
28479static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
2763728480 ZigType *operand_type = ir_resolve_type(ira, op);
2763828481 if (type_is_invalid(operand_type))
2763928482 return ira->codegen->builtin_types.entry_invalid;
2764028483
2764128484 if (operand_type->id == ZigTypeIdInt) {
2764228485 if (operand_type->data.integral.bit_count < 8) {
27643 ir_add_error(ira, op,
28486 ir_add_error(ira, &op->base,
2764428487 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",
2764528488 operand_type->data.integral.bit_count));
2764628489 return ira->codegen->builtin_types.entry_invalid;
2764728490 }
2764828491 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2764928492 if (operand_type->data.integral.bit_count > max_atomic_bits) {
27650 ir_add_error(ira, op,
28493 ir_add_error(ira, &op->base,
2765128494 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",
2765228495 max_atomic_bits, operand_type->data.integral.bit_count));
2765328496 return ira->codegen->builtin_types.entry_invalid;
2765428497 }
2765528498 if (!is_power_of_2(operand_type->data.integral.bit_count)) {
27656 ir_add_error(ira, op,
28499 ir_add_error(ira, &op->base,
2765728500 buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count));
2765828501 return ira->codegen->builtin_types.entry_invalid;
2765928502 }
2766028503 } else if (operand_type->id == ZigTypeIdEnum) {
2766128504 ZigType *int_type = operand_type->data.enumeration.tag_int_type;
2766228505 if (int_type->data.integral.bit_count < 8) {
27663 ir_add_error(ira, op,
28506 ir_add_error(ira, &op->base,
2766428507 buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type",
2766528508 int_type->data.integral.bit_count));
2766628509 return ira->codegen->builtin_types.entry_invalid;
2766728510 }
2766828511 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2766928512 if (int_type->data.integral.bit_count > max_atomic_bits) {
27670 ir_add_error(ira, op,
28513 ir_add_error(ira, &op->base,
2767128514 buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type",
2767228515 max_atomic_bits, int_type->data.integral.bit_count));
2767328516 return ira->codegen->builtin_types.entry_invalid;
2767428517 }
2767528518 if (!is_power_of_2(int_type->data.integral.bit_count)) {
27676 ir_add_error(ira, op,
28519 ir_add_error(ira, &op->base,
2767728520 buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count));
2767828521 return ira->codegen->builtin_types.entry_invalid;
2767928522 }
2768028523 } else if (operand_type->id == ZigTypeIdFloat) {
2768128524 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2768228525 if (operand_type->data.floating.bit_count > max_atomic_bits) {
27683 ir_add_error(ira, op,
28526 ir_add_error(ira, &op->base,
2768428527 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",
2768528528 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
2768628529 return ira->codegen->builtin_types.entry_invalid;
2768728530 }
2768828531 } else if (get_codegen_ptr_type(operand_type) == nullptr) {
27689 ir_add_error(ira, op,
28532 ir_add_error(ira, &op->base,
2769028533 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
2769128534 return ira->codegen->builtin_types.entry_invalid;
2769228535 }
......@@ -27694,172 +28537,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op
2769428537 return operand_type;
2769528538}
2769628539
27697static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {
28540static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) {
2769828541 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
2769928542 if (type_is_invalid(operand_type))
27700 return ira->codegen->invalid_instruction;
28543 return ira->codegen->invalid_inst_gen;
2770128544
27702 IrInstruction *ptr_inst = instruction->ptr->child;
28545 IrInstGen *ptr_inst = instruction->ptr->child;
2770328546 if (type_is_invalid(ptr_inst->value->type))
27704 return ira->codegen->invalid_instruction;
28547 return ira->codegen->invalid_inst_gen;
2770528548
2770628549 // TODO let this be volatile
2770728550 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
27708 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
28551 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2770928552 if (type_is_invalid(casted_ptr->value->type))
27710 return ira->codegen->invalid_instruction;
28553 return ira->codegen->invalid_inst_gen;
2771128554
2771228555 AtomicRmwOp op;
27713 if (instruction->op == nullptr) {
27714 op = instruction->resolved_op;
27715 } else {
27716 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
27717 return ira->codegen->invalid_instruction;
27718 }
28556 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
28557 return ira->codegen->invalid_inst_gen;
2771928558 }
2772028559
2772128560 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
27722 ir_add_error(ira, instruction->op,
28561 ir_add_error(ira, &instruction->op->base,
2772328562 buf_sprintf("@atomicRmw on enum only works with .Xchg"));
27724 return ira->codegen->invalid_instruction;
28563 return ira->codegen->invalid_inst_gen;
2772528564 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {
27726 ir_add_error(ira, instruction->op,
28565 ir_add_error(ira, &instruction->op->base,
2772728566 buf_sprintf("@atomicRmw with float only works with .Xchg, .Add and .Sub"));
27728 return ira->codegen->invalid_instruction;
28567 return ira->codegen->invalid_inst_gen;
2772928568 }
2773028569
27731 IrInstruction *operand = instruction->operand->child;
28570 IrInstGen *operand = instruction->operand->child;
2773228571 if (type_is_invalid(operand->value->type))
27733 return ira->codegen->invalid_instruction;
28572 return ira->codegen->invalid_inst_gen;
2773428573
27735 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type);
28574 IrInstGen *casted_operand = ir_implicit_cast(ira, operand, operand_type);
2773628575 if (type_is_invalid(casted_operand->value->type))
27737 return ira->codegen->invalid_instruction;
28576 return ira->codegen->invalid_inst_gen;
2773828577
2773928578 AtomicOrder ordering;
27740 if (instruction->ordering == nullptr) {
27741 ordering = instruction->resolved_ordering;
27742 } else {
27743 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27744 return ira->codegen->invalid_instruction;
27745 if (ordering == AtomicOrderUnordered) {
27746 ir_add_error(ira, instruction->ordering,
27747 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
27748 return ira->codegen->invalid_instruction;
27749 }
28579 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
28580 return ira->codegen->invalid_inst_gen;
28581 if (ordering == AtomicOrderUnordered) {
28582 ir_add_error(ira, &instruction->ordering->base,
28583 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
28584 return ira->codegen->invalid_inst_gen;
2775028585 }
2775128586
2775228587 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar)
2775328588 {
27754 zig_panic("TODO compile-time execution of atomicRmw");
28589 ir_add_error(ira, &instruction->base.base,
28590 buf_sprintf("compiler bug: TODO compile-time execution of @atomicRmw"));
28591 return ira->codegen->invalid_inst_gen;
2775528592 }
2775628593
27757 IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope,
27758 instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr,
27759 op, ordering);
27760 result->value->type = operand_type;
27761 return result;
28594 return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op,
28595 ordering, operand_type);
2776228596}
2776328597
27764static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {
28598static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) {
2776528599 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
2776628600 if (type_is_invalid(operand_type))
27767 return ira->codegen->invalid_instruction;
28601 return ira->codegen->invalid_inst_gen;
2776828602
27769 IrInstruction *ptr_inst = instruction->ptr->child;
28603 IrInstGen *ptr_inst = instruction->ptr->child;
2777028604 if (type_is_invalid(ptr_inst->value->type))
27771 return ira->codegen->invalid_instruction;
28605 return ira->codegen->invalid_inst_gen;
2777228606
2777328607 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
27774 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
28608 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2777528609 if (type_is_invalid(casted_ptr->value->type))
27776 return ira->codegen->invalid_instruction;
28610 return ira->codegen->invalid_inst_gen;
2777728611
2777828612 AtomicOrder ordering;
27779 if (instruction->ordering == nullptr) {
27780 ordering = instruction->resolved_ordering;
27781 } else {
27782 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27783 return ira->codegen->invalid_instruction;
27784 }
28613 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
28614 return ira->codegen->invalid_inst_gen;
2778528615
2778628616 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {
27787 ir_assert(instruction->ordering != nullptr, &instruction->base);
27788 ir_add_error(ira, instruction->ordering,
28617 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
28618 ir_add_error(ira, &instruction->ordering->base,
2778928619 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));
27790 return ira->codegen->invalid_instruction;
28620 return ira->codegen->invalid_inst_gen;
2779128621 }
2779228622
2779328623 if (instr_is_comptime(casted_ptr)) {
27794 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);
27795 ir_assert(result->value->type != nullptr, &instruction->base);
28624 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr);
28625 ir_assert(result->value->type != nullptr, &instruction->base.base);
2779628626 return result;
2779728627 }
2779828628
27799 IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope,
27800 instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering);
27801 result->value->type = operand_type;
27802 return result;
28629 return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type);
2780328630}
2780428631
27805static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstructionAtomicStore *instruction) {
28632static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) {
2780628633 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
2780728634 if (type_is_invalid(operand_type))
27808 return ira->codegen->invalid_instruction;
28635 return ira->codegen->invalid_inst_gen;
2780928636
27810 IrInstruction *ptr_inst = instruction->ptr->child;
28637 IrInstGen *ptr_inst = instruction->ptr->child;
2781128638 if (type_is_invalid(ptr_inst->value->type))
27812 return ira->codegen->invalid_instruction;
28639 return ira->codegen->invalid_inst_gen;
2781328640
2781428641 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
27815 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
28642 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2781628643 if (type_is_invalid(casted_ptr->value->type))
27817 return ira->codegen->invalid_instruction;
28644 return ira->codegen->invalid_inst_gen;
2781828645
27819 IrInstruction *value = instruction->value->child;
28646 IrInstGen *value = instruction->value->child;
2782028647 if (type_is_invalid(value->value->type))
27821 return ira->codegen->invalid_instruction;
28648 return ira->codegen->invalid_inst_gen;
2782228649
27823 IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type);
28650 IrInstGen *casted_value = ir_implicit_cast(ira, value, operand_type);
2782428651 if (type_is_invalid(casted_value->value->type))
27825 return ira->codegen->invalid_instruction;
28652 return ira->codegen->invalid_inst_gen;
2782628653
2782728654
2782828655 AtomicOrder ordering;
27829 if (instruction->ordering == nullptr) {
27830 ordering = instruction->resolved_ordering;
27831 } else {
27832 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27833 return ira->codegen->invalid_instruction;
27834 }
28656 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
28657 return ira->codegen->invalid_inst_gen;
2783528658
2783628659 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {
27837 ir_assert(instruction->ordering != nullptr, &instruction->base);
27838 ir_add_error(ira, instruction->ordering,
28660 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
28661 ir_add_error(ira, &instruction->ordering->base,
2783928662 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));
27840 return ira->codegen->invalid_instruction;
28663 return ira->codegen->invalid_inst_gen;
2784128664 }
2784228665
2784328666 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
27844 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);
28667 IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false);
2784528668 result->value->type = ira->codegen->builtin_types.entry_void;
2784628669 return result;
2784728670 }
2784828671
27849 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,
27850 instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering);
27851 result->value->type = ira->codegen->builtin_types.entry_void;
27852 return result;
28672 return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering);
2785328673}
2785428674
27855static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
27856 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
27857 instruction->base.source_node);
27858 result->value->type = ira->codegen->builtin_types.entry_void;
27859 return result;
28675static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) {
28676 return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base);
2786028677}
2786128678
27862static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, BuiltinFnId fop, ZigType *float_type,
28679static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type,
2786328680 ZigValue *op, ZigValue *out_val)
2786428681{
2786528682 assert(ira && source_instr && float_type && out_val && op);
......@@ -28072,30 +28889,30 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, B
2807228889 return nullptr;
2807328890}
2807428891
28075static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) {
28076 IrInstruction *operand = instruction->operand->child;
28892static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloatOp *instruction) {
28893 IrInstGen *operand = instruction->operand->child;
2807728894 ZigType *operand_type = operand->value->type;
2807828895 if (type_is_invalid(operand_type))
28079 return ira->codegen->invalid_instruction;
28896 return ira->codegen->invalid_inst_gen;
2808028897
2808128898 // This instruction accepts floats and vectors of floats.
2808228899 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
2808328900 operand_type->data.vector.elem_type : operand_type;
2808428901
2808528902 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {
28086 ir_add_error(ira, operand,
28903 ir_add_error(ira, &operand->base,
2808728904 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));
28088 return ira->codegen->invalid_instruction;
28905 return ira->codegen->invalid_inst_gen;
2808928906 }
2809028907
2809128908 if (instr_is_comptime(operand)) {
2809228909 ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk);
2809328910 if (operand_val == nullptr)
28094 return ira->codegen->invalid_instruction;
28911 return ira->codegen->invalid_inst_gen;
2809528912 if (operand_val->special == ConstValSpecialUndef)
28096 return ir_const_undef(ira, &instruction->base, operand_type);
28913 return ir_const_undef(ira, &instruction->base.base, operand_type);
2809728914
28098 IrInstruction *result = ir_const(ira, &instruction->base, operand_type);
28915 IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type);
2809928916 ZigValue *out_val = result->value;
2810028917
2810128918 if (operand_type->id == ZigTypeIdVector) {
......@@ -28106,47 +28923,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
2810628923 for (size_t i = 0; i < len; i += 1) {
2810728924 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];
2810828925 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
28109 ir_assert(elem_operand->type == scalar_type, &instruction->base);
28110 ir_assert(float_out_val->type == scalar_type, &instruction->base);
28111 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type,
28926 ir_assert(elem_operand->type == scalar_type, &instruction->base.base);
28927 ir_assert(float_out_val->type == scalar_type, &instruction->base.base);
28928 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
2811228929 elem_operand, float_out_val);
2811328930 if (msg != nullptr) {
28114 add_error_note(ira->codegen, msg, instruction->base.source_node,
28931 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
2811528932 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
28116 return ira->codegen->invalid_instruction;
28933 return ira->codegen->invalid_inst_gen;
2811728934 }
2811828935 float_out_val->type = scalar_type;
2811928936 }
2812028937 out_val->type = operand_type;
2812128938 out_val->special = ConstValSpecialStatic;
2812228939 } else {
28123 if (ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type,
28940 if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
2812428941 operand_val, out_val) != nullptr)
2812528942 {
28126 return ira->codegen->invalid_instruction;
28943 return ira->codegen->invalid_inst_gen;
2812728944 }
2812828945 }
2812928946 return result;
2813028947 }
2813128948
28132 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base);
28949 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base);
2813328950
28134 IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope,
28135 instruction->base.source_node, operand, instruction->fn_id);
28136 result->value->type = operand_type;
28137 return result;
28951 return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type);
2813828952}
2813928953
28140static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) {
28954static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) {
2814128955 Error err;
2814228956
2814328957 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2814428958 if (type_is_invalid(int_type))
28145 return ira->codegen->invalid_instruction;
28959 return ira->codegen->invalid_inst_gen;
2814628960
28147 IrInstruction *uncasted_op = instruction->op->child;
28961 IrInstGen *uncasted_op = instruction->op->child;
2814828962 if (type_is_invalid(uncasted_op->value->type))
28149 return ira->codegen->invalid_instruction;
28963 return ira->codegen->invalid_inst_gen;
2815028964
2815128965 uint32_t vector_len; // UINT32_MAX means not a vector
2815228966 if (uncasted_op->value->type->id == ZigTypeIdArray &&
......@@ -28162,28 +28976,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2816228976 bool is_vector = (vector_len != UINT32_MAX);
2816328977 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;
2816428978
28165 IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type);
28979 IrInstGen *op = ir_implicit_cast(ira, uncasted_op, op_type);
2816628980 if (type_is_invalid(op->value->type))
28167 return ira->codegen->invalid_instruction;
28981 return ira->codegen->invalid_inst_gen;
2816828982
2816928983 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)
2817028984 return op;
2817128985
2817228986 if (int_type->data.integral.bit_count % 8 != 0) {
28173 ir_add_error(ira, instruction->op,
28987 ir_add_error(ira, &instruction->op->base,
2817428988 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",
2817528989 buf_ptr(&int_type->name), int_type->data.integral.bit_count));
28176 return ira->codegen->invalid_instruction;
28990 return ira->codegen->invalid_inst_gen;
2817728991 }
2817828992
2817928993 if (instr_is_comptime(op)) {
2818028994 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2818128995 if (val == nullptr)
28182 return ira->codegen->invalid_instruction;
28996 return ira->codegen->invalid_inst_gen;
2818328997 if (val->special == ConstValSpecialUndef)
28184 return ir_const_undef(ira, &instruction->base, op_type);
28998 return ir_const_undef(ira, &instruction->base.base, op_type);
2818528999
28186 IrInstruction *result = ir_const(ira, &instruction->base, op_type);
29000 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);
2818729001 size_t buf_size = int_type->data.integral.bit_count / 8;
2818829002 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
2818929003 if (is_vector) {
......@@ -28191,10 +29005,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2819129005 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
2819229006 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
2819329007 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
28194 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,
29008 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,
2819529009 op_elem_val, UndefOk)))
2819629010 {
28197 return ira->codegen->invalid_instruction;
29011 return ira->codegen->invalid_inst_gen;
2819829012 }
2819929013 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
2820029014 result_elem_val->type = int_type;
......@@ -28216,23 +29030,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2821629030 return result;
2821729031 }
2821829032
28219 IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope,
28220 instruction->base.source_node, nullptr, op);
28221 result->value->type = op_type;
28222 return result;
29033 return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op);
2822329034}
2822429035
28225static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) {
29036static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) {
2822629037 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2822729038 if (type_is_invalid(int_type))
28228 return ira->codegen->invalid_instruction;
29039 return ira->codegen->invalid_inst_gen;
2822929040
28230 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
29041 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2823129042 if (type_is_invalid(op->value->type))
28232 return ira->codegen->invalid_instruction;
29043 return ira->codegen->invalid_inst_gen;
2823329044
2823429045 if (int_type->data.integral.bit_count == 0) {
28235 IrInstruction *result = ir_const(ira, &instruction->base, int_type);
29046 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
2823629047 bigint_init_unsigned(&result->value->data.x_bigint, 0);
2823729048 return result;
2823829049 }
......@@ -28240,11 +29051,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2824029051 if (instr_is_comptime(op)) {
2824129052 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2824229053 if (val == nullptr)
28243 return ira->codegen->invalid_instruction;
29054 return ira->codegen->invalid_inst_gen;
2824429055 if (val->special == ConstValSpecialUndef)
28245 return ir_const_undef(ira, &instruction->base, int_type);
29056 return ir_const_undef(ira, &instruction->base.base, int_type);
2824629057
28247 IrInstruction *result = ir_const(ira, &instruction->base, int_type);
29058 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
2824829059 size_t num_bits = int_type->data.integral.bit_count;
2824929060 size_t buf_size = (num_bits + 7) / 8;
2825029061 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);
......@@ -28271,128 +29082,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2827129082 return result;
2827229083 }
2827329084
28274 IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope,
28275 instruction->base.source_node, nullptr, op);
28276 result->value->type = int_type;
28277 return result;
29085 return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op);
2827829086}
2827929087
2828029088
28281static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
28282 IrInstruction *target = instruction->target->child;
29089static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEnumToInt *instruction) {
29090 IrInstGen *target = instruction->target->child;
2828329091 if (type_is_invalid(target->value->type))
28284 return ira->codegen->invalid_instruction;
29092 return ira->codegen->invalid_inst_gen;
2828529093
28286 return ir_analyze_enum_to_int(ira, &instruction->base, target);
29094 return ir_analyze_enum_to_int(ira, &instruction->base.base, target);
2828729095}
2828829096
28289static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
29097static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) {
2829029098 Error err;
28291 IrInstruction *dest_type_value = instruction->dest_type->child;
29099 IrInstGen *dest_type_value = instruction->dest_type->child;
2829229100 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2829329101 if (type_is_invalid(dest_type))
28294 return ira->codegen->invalid_instruction;
29102 return ira->codegen->invalid_inst_gen;
2829529103
2829629104 if (dest_type->id != ZigTypeIdEnum) {
28297 ir_add_error(ira, instruction->dest_type,
29105 ir_add_error(ira, &instruction->dest_type->base,
2829829106 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
28299 return ira->codegen->invalid_instruction;
29107 return ira->codegen->invalid_inst_gen;
2830029108 }
2830129109
2830229110 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
28303 return ira->codegen->invalid_instruction;
29111 return ira->codegen->invalid_inst_gen;
2830429112
2830529113 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
2830629114
28307 IrInstruction *target = instruction->target->child;
29115 IrInstGen *target = instruction->target->child;
2830829116 if (type_is_invalid(target->value->type))
28309 return ira->codegen->invalid_instruction;
29117 return ira->codegen->invalid_inst_gen;
2831029118
28311 IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type);
29119 IrInstGen *casted_target = ir_implicit_cast(ira, target, tag_type);
2831229120 if (type_is_invalid(casted_target->value->type))
28313 return ira->codegen->invalid_instruction;
29121 return ira->codegen->invalid_inst_gen;
2831429122
28315 return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type);
29123 return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type);
2831629124}
2831729125
28318static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) {
28319 IrInstruction *block_comptime_inst = instruction->scope_is_comptime->child;
29126static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) {
29127 IrInstGen *block_comptime_inst = instruction->scope_is_comptime->child;
2832029128 bool scope_is_comptime;
2832129129 if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime))
28322 return ira->codegen->invalid_instruction;
29130 return ira->codegen->invalid_inst_gen;
2832329131
28324 IrInstruction *is_comptime_inst = instruction->is_comptime->child;
29132 IrInstGen *is_comptime_inst = instruction->is_comptime->child;
2832529133 bool is_comptime;
2832629134 if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))
28327 return ira->codegen->invalid_instruction;
29135 return ira->codegen->invalid_inst_gen;
2832829136
2832929137 if (!scope_is_comptime && is_comptime) {
28330 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
29138 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2833129139 buf_sprintf("comptime control flow inside runtime block"));
28332 add_error_note(ira->codegen, msg, block_comptime_inst->source_node,
29140 add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node,
2833329141 buf_sprintf("runtime block created here"));
28334 return ira->codegen->invalid_instruction;
29142 return ira->codegen->invalid_inst_gen;
2833529143 }
2833629144
28337 return ir_const_void(ira, &instruction->base);
29145 return ir_const_void(ira, &instruction->base.base);
2833829146}
2833929147
28340static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstructionHasDecl *instruction) {
29148static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) {
2834129149 ZigType *container_type = ir_resolve_type(ira, instruction->container->child);
2834229150 if (type_is_invalid(container_type))
28343 return ira->codegen->invalid_instruction;
29151 return ira->codegen->invalid_inst_gen;
2834429152
2834529153 Buf *name = ir_resolve_str(ira, instruction->name->child);
2834629154 if (name == nullptr)
28347 return ira->codegen->invalid_instruction;
29155 return ira->codegen->invalid_inst_gen;
2834829156
2834929157 if (!is_container(container_type)) {
28350 ir_add_error(ira, instruction->container,
29158 ir_add_error(ira, &instruction->container->base,
2835129159 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));
28352 return ira->codegen->invalid_instruction;
29160 return ira->codegen->invalid_inst_gen;
2835329161 }
2835429162
2835529163 ScopeDecls *container_scope = get_container_scope(container_type);
2835629164 Tld *tld = find_container_decl(ira->codegen, container_scope, name);
2835729165 if (tld == nullptr)
28358 return ir_const_bool(ira, &instruction->base, false);
29166 return ir_const_bool(ira, &instruction->base.base, false);
2835929167
28360 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) {
28361 return ir_const_bool(ira, &instruction->base, false);
29168 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) {
29169 return ir_const_bool(ira, &instruction->base.base, false);
2836229170 }
2836329171
28364 return ir_const_bool(ira, &instruction->base, true);
29172 return ir_const_bool(ira, &instruction->base.base, true);
2836529173}
2836629174
28367static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstructionUndeclaredIdent *instruction) {
29175static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) {
2836829176 // put a variable of same name with invalid type in global scope
2836929177 // so that future references to this same name will find a variable with an invalid type
28370 populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope, instruction->base.source_node,
28371 instruction->name);
28372 ir_add_error(ira, &instruction->base,
29178 populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope,
29179 instruction->base.base.source_node, instruction->name);
29180 ir_add_error(ira, &instruction->base.base,
2837329181 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));
28374 return ira->codegen->invalid_instruction;
29182 return ira->codegen->invalid_inst_gen;
2837529183}
2837629184
28377static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) {
28378 IrInstruction *value = instruction->value->child;
29185static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndExpr *instruction) {
29186 IrInstGen *value = instruction->value->child;
2837929187 if (type_is_invalid(value->value->type))
28380 return ira->codegen->invalid_instruction;
29188 return ira->codegen->invalid_inst_gen;
2838129189
2838229190 bool was_written = instruction->result_loc->written;
28383 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
29191 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2838429192 value->value->type, value, false, false, true);
2838529193 if (result_loc != nullptr) {
2838629194 if (type_is_invalid(result_loc->value->type))
28387 return ira->codegen->invalid_instruction;
29195 return ira->codegen->invalid_inst_gen;
2838829196 if (result_loc->value->type->id == ZigTypeIdUnreachable)
2838929197 return result_loc;
2839029198
2839129199 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
28392 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value,
29200 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value,
2839329201 instruction->result_loc->allow_write_through_const);
2839429202 if (type_is_invalid(store_ptr->value->type)) {
28395 return ira->codegen->invalid_instruction;
29203 return ira->codegen->invalid_inst_gen;
2839629204 }
2839729205 }
2839829206
......@@ -28407,33 +29215,33 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2840729215 }
2840829216 }
2840929217
28410 return ir_const_void(ira, &instruction->base);
29218 return ir_const_void(ira, &instruction->base.base);
2841129219}
2841229220
28413static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
28414 IrInstruction *operand = instruction->operand->child;
29221static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) {
29222 IrInstGen *operand = instruction->operand->child;
2841529223 if (type_is_invalid(operand->value->type))
2841629224 return operand;
2841729225
28418 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
29226 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
2841929227 &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true);
28420 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
29228 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
2842129229 return result_loc;
2842229230
2842329231 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
2842429232 if (type_is_invalid(dest_type))
28425 return ira->codegen->invalid_instruction;
28426 return ir_implicit_cast2(ira, &instruction->base, operand, dest_type);
29233 return ira->codegen->invalid_inst_gen;
29234 return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type);
2842729235}
2842829236
28429static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
28430 IrInstruction *operand = instruction->operand->child;
29237static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) {
29238 IrInstGen *operand = instruction->operand->child;
2843129239 if (type_is_invalid(operand->value->type))
2843229240 return operand;
2843329241
28434 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
29242 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
2843529243 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true);
28436 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
29244 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
2843729245 return result_loc;
2843829246
2843929247 if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) {
......@@ -28443,70 +29251,66 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst
2844329251 return result_loc;
2844429252}
2844529253
28446static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
28447 IrInstructionUnionInitNamedField *instruction)
29254static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
29255 IrInstSrcUnionInitNamedField *instruction)
2844829256{
2844929257 ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child);
2845029258 if (type_is_invalid(union_type))
28451 return ira->codegen->invalid_instruction;
29259 return ira->codegen->invalid_inst_gen;
2845229260
2845329261 if (union_type->id != ZigTypeIdUnion) {
28454 ir_add_error(ira, instruction->union_type,
29262 ir_add_error(ira, &instruction->union_type->base,
2845529263 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));
28456 return ira->codegen->invalid_instruction;
29264 return ira->codegen->invalid_inst_gen;
2845729265 }
2845829266
2845929267 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
2846029268 if (field_name == nullptr)
28461 return ira->codegen->invalid_instruction;
29269 return ira->codegen->invalid_inst_gen;
2846229270
28463 IrInstruction *field_result_loc = instruction->field_result_loc->child;
29271 IrInstGen *field_result_loc = instruction->field_result_loc->child;
2846429272 if (type_is_invalid(field_result_loc->value->type))
28465 return ira->codegen->invalid_instruction;
29273 return ira->codegen->invalid_inst_gen;
2846629274
28467 IrInstruction *result_loc = instruction->result_loc->child;
29275 IrInstGen *result_loc = instruction->result_loc->child;
2846829276 if (type_is_invalid(result_loc->value->type))
28469 return ira->codegen->invalid_instruction;
29277 return ira->codegen->invalid_inst_gen;
2847029278
28471 return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node,
29279 return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node,
2847229280 union_type, field_name, field_result_loc, result_loc);
2847329281}
2847429282
28475static IrInstruction *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstructionSuspendBegin *instruction) {
28476 IrInstructionSuspendBegin *result = ir_build_suspend_begin(&ira->new_irb, instruction->base.scope,
28477 instruction->base.source_node);
28478 return &result->base;
29283static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) {
29284 return ir_build_suspend_begin_gen(ira, &instruction->base.base);
2847929285}
2848029286
28481static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,
28482 IrInstructionSuspendFinish *instruction)
28483{
28484 IrInstruction *begin_base = instruction->begin->base.child;
29287static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) {
29288 IrInstGen *begin_base = instruction->begin->base.child;
2848529289 if (type_is_invalid(begin_base->value->type))
28486 return ira->codegen->invalid_instruction;
28487 ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base);
28488 IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base);
29290 return ira->codegen->invalid_inst_gen;
29291 ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base);
29292 IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base);
2848929293
28490 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
28491 ir_assert(fn_entry != nullptr, &instruction->base);
29294 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
29295 ir_assert(fn_entry != nullptr, &instruction->base.base);
2849229296
2849329297 if (fn_entry->inferred_async_node == nullptr) {
28494 fn_entry->inferred_async_node = instruction->base.source_node;
29298 fn_entry->inferred_async_node = instruction->base.base.source_node;
2849529299 }
2849629300
28497 return ir_build_suspend_finish(&ira->new_irb, instruction->base.scope, instruction->base.source_node, begin);
29301 return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin);
2849829302}
2849929303
28500static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr,
28501 IrInstruction *frame_ptr, ZigFn **target_fn)
29304static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr,
29305 IrInstGen *frame_ptr, ZigFn **target_fn)
2850229306{
2850329307 if (type_is_invalid(frame_ptr->value->type))
28504 return ira->codegen->invalid_instruction;
29308 return ira->codegen->invalid_inst_gen;
2850529309
2850629310 *target_fn = nullptr;
2850729311
2850829312 ZigType *result_type;
28509 IrInstruction *frame;
29313 IrInstGen *frame;
2851029314 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
2851129315 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
2851229316 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
......@@ -28529,38 +29333,38 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
2852929333 {
2853029334 ir_add_error(ira, source_instr,
2853129335 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));
28532 return ira->codegen->invalid_instruction;
29336 return ira->codegen->invalid_inst_gen;
2853329337 } else {
2853429338 result_type = frame->value->type->data.any_frame.result_type;
2853529339 }
2853629340 }
2853729341
2853829342 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);
28539 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
29343 IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
2854029344 if (type_is_invalid(casted_frame->value->type))
28541 return ira->codegen->invalid_instruction;
29345 return ira->codegen->invalid_inst_gen;
2854229346
2854329347 return casted_frame;
2854429348}
2854529349
28546static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) {
28547 IrInstruction *operand = instruction->frame->child;
29350static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *instruction) {
29351 IrInstGen *operand = instruction->frame->child;
2854829352 if (type_is_invalid(operand->value->type))
28549 return ira->codegen->invalid_instruction;
29353 return ira->codegen->invalid_inst_gen;
2855029354 ZigFn *target_fn;
28551 IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn);
29355 IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn);
2855229356 if (type_is_invalid(frame->value->type))
28553 return ira->codegen->invalid_instruction;
29357 return ira->codegen->invalid_inst_gen;
2855429358
2855529359 ZigType *result_type = frame->value->type->data.any_frame.result_type;
2855629360
28557 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
28558 ir_assert(fn_entry != nullptr, &instruction->base);
29361 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
29362 ir_assert(fn_entry != nullptr, &instruction->base.base);
2855929363
2856029364 // If it's not @Frame(func) then it's definitely a suspend point
2856129365 if (target_fn == nullptr) {
2856229366 if (fn_entry->inferred_async_node == nullptr) {
28563 fn_entry->inferred_async_node = instruction->base.source_node;
29367 fn_entry->inferred_async_node = instruction->base.base.source_node;
2856429368 }
2856529369 }
2856629370
......@@ -28568,401 +29372,364 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
2856829372 fn_entry->calls_or_awaits_errorable_fn = true;
2856929373 }
2857029374
28571 IrInstruction *result_loc;
29375 IrInstGen *result_loc;
2857229376 if (type_has_bits(result_type)) {
28573 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
29377 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2857429378 result_type, nullptr, true, true, true);
28575 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
29379 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
2857629380 return result_loc;
2857729381 } else {
2857829382 result_loc = nullptr;
2857929383 }
2858029384
28581 IrInstructionAwaitGen *result = ir_build_await_gen(ira, &instruction->base, frame, result_type, result_loc);
29385 IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc);
2858229386 result->target_fn = target_fn;
2858329387 fn_entry->await_list.append(result);
2858429388 return ir_finish_anal(ira, &result->base);
2858529389}
2858629390
28587static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {
28588 IrInstruction *frame_ptr = instruction->frame->child;
29391static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume *instruction) {
29392 IrInstGen *frame_ptr = instruction->frame->child;
2858929393 if (type_is_invalid(frame_ptr->value->type))
28590 return ira->codegen->invalid_instruction;
29394 return ira->codegen->invalid_inst_gen;
2859129395
28592 IrInstruction *frame;
29396 IrInstGen *frame;
2859329397 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
2859429398 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
2859529399 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2859629400 {
2859729401 frame = frame_ptr;
2859829402 } else {
28599 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);
29403 frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr);
2860029404 }
2860129405
2860229406 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
28603 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
29407 IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
2860429408 if (type_is_invalid(casted_frame->value->type))
28605 return ira->codegen->invalid_instruction;
29409 return ira->codegen->invalid_inst_gen;
2860629410
28607 return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame);
29411 return ir_build_resume_gen(ira, &instruction->base.base, casted_frame);
2860829412}
2860929413
28610static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstructionSpillBegin *instruction) {
28611 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope))
28612 return ir_const_void(ira, &instruction->base);
29414static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) {
29415 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope))
29416 return ir_const_void(ira, &instruction->base.base);
2861329417
28614 IrInstruction *operand = instruction->operand->child;
29418 IrInstGen *operand = instruction->operand->child;
2861529419 if (type_is_invalid(operand->value->type))
28616 return ira->codegen->invalid_instruction;
29420 return ira->codegen->invalid_inst_gen;
2861729421
2861829422 if (!type_has_bits(operand->value->type))
28619 return ir_const_void(ira, &instruction->base);
29423 return ir_const_void(ira, &instruction->base.base);
2862029424
28621 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base);
29425 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base.base);
2862229426 ira->new_irb.exec->need_err_code_spill = true;
2862329427
28624 IrInstructionSpillBegin *result = ir_build_spill_begin(&ira->new_irb, instruction->base.scope,
28625 instruction->base.source_node, operand, instruction->spill_id);
28626 return &result->base;
29428 return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id);
2862729429}
2862829430
28629static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) {
28630 IrInstruction *operand = instruction->begin->operand->child;
29431static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) {
29432 IrInstGen *operand = instruction->begin->operand->child;
2863129433 if (type_is_invalid(operand->value->type))
28632 return ira->codegen->invalid_instruction;
29434 return ira->codegen->invalid_inst_gen;
2863329435
28634 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type))
29436 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) || !type_has_bits(operand->value->type))
2863529437 return operand;
2863629438
28637 ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base);
28638 IrInstructionSpillBegin *begin = reinterpret_cast<IrInstructionSpillBegin *>(instruction->begin->base.child);
29439 ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base);
29440 IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child);
2863929441
28640 IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope,
28641 instruction->base.source_node, begin);
28642 result->value->type = operand->value->type;
28643 return result;
29442 return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type);
2864429443}
2864529444
28646static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) {
29445static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) {
2864729446 switch (instruction->id) {
28648 case IrInstructionIdInvalid:
28649 case IrInstructionIdWidenOrShorten:
28650 case IrInstructionIdStructFieldPtr:
28651 case IrInstructionIdUnionFieldPtr:
28652 case IrInstructionIdOptionalWrap:
28653 case IrInstructionIdErrWrapCode:
28654 case IrInstructionIdErrWrapPayload:
28655 case IrInstructionIdCast:
28656 case IrInstructionIdDeclVarGen:
28657 case IrInstructionIdPtrCastGen:
28658 case IrInstructionIdCmpxchgGen:
28659 case IrInstructionIdArrayToVector:
28660 case IrInstructionIdVectorToArray:
28661 case IrInstructionIdPtrOfArrayToSlice:
28662 case IrInstructionIdAssertZero:
28663 case IrInstructionIdAssertNonNull:
28664 case IrInstructionIdResizeSlice:
28665 case IrInstructionIdLoadPtrGen:
28666 case IrInstructionIdBitCastGen:
28667 case IrInstructionIdCallGen:
28668 case IrInstructionIdReturnPtr:
28669 case IrInstructionIdAllocaGen:
28670 case IrInstructionIdSliceGen:
28671 case IrInstructionIdRefGen:
28672 case IrInstructionIdTestErrGen:
28673 case IrInstructionIdFrameSizeGen:
28674 case IrInstructionIdAwaitGen:
28675 case IrInstructionIdSplatGen:
28676 case IrInstructionIdVectorExtractElem:
28677 case IrInstructionIdVectorStoreElem:
28678 case IrInstructionIdAsmGen:
29447 case IrInstSrcIdInvalid:
2867929448 zig_unreachable();
2868029449
28681 case IrInstructionIdReturn:
28682 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);
28683 case IrInstructionIdConst:
28684 return ir_analyze_instruction_const(ira, (IrInstructionConst *)instruction);
28685 case IrInstructionIdUnOp:
28686 return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction);
28687 case IrInstructionIdBinOp:
28688 return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction);
28689 case IrInstructionIdMergeErrSets:
28690 return ir_analyze_instruction_merge_err_sets(ira, (IrInstructionMergeErrSets *)instruction);
28691 case IrInstructionIdDeclVarSrc:
28692 return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction);
28693 case IrInstructionIdLoadPtr:
28694 return ir_analyze_instruction_load_ptr(ira, (IrInstructionLoadPtr *)instruction);
28695 case IrInstructionIdStorePtr:
28696 return ir_analyze_instruction_store_ptr(ira, (IrInstructionStorePtr *)instruction);
28697 case IrInstructionIdElemPtr:
28698 return ir_analyze_instruction_elem_ptr(ira, (IrInstructionElemPtr *)instruction);
28699 case IrInstructionIdVarPtr:
28700 return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction);
28701 case IrInstructionIdFieldPtr:
28702 return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction);
28703 case IrInstructionIdCallSrc:
28704 return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction);
28705 case IrInstructionIdCallSrcArgs:
28706 return ir_analyze_instruction_call_args(ira, (IrInstructionCallSrcArgs *)instruction);
28707 case IrInstructionIdCallExtra:
28708 return ir_analyze_instruction_call_extra(ira, (IrInstructionCallExtra *)instruction);
28709 case IrInstructionIdBr:
28710 return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction);
28711 case IrInstructionIdCondBr:
28712 return ir_analyze_instruction_cond_br(ira, (IrInstructionCondBr *)instruction);
28713 case IrInstructionIdUnreachable:
28714 return ir_analyze_instruction_unreachable(ira, (IrInstructionUnreachable *)instruction);
28715 case IrInstructionIdPhi:
28716 return ir_analyze_instruction_phi(ira, (IrInstructionPhi *)instruction);
28717 case IrInstructionIdTypeOf:
28718 return ir_analyze_instruction_typeof(ira, (IrInstructionTypeOf *)instruction);
28719 case IrInstructionIdSetCold:
28720 return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction);
28721 case IrInstructionIdSetRuntimeSafety:
28722 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction);
28723 case IrInstructionIdSetFloatMode:
28724 return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction);
28725 case IrInstructionIdAnyFrameType:
28726 return ir_analyze_instruction_any_frame_type(ira, (IrInstructionAnyFrameType *)instruction);
28727 case IrInstructionIdSliceType:
28728 return ir_analyze_instruction_slice_type(ira, (IrInstructionSliceType *)instruction);
28729 case IrInstructionIdAsmSrc:
28730 return ir_analyze_instruction_asm(ira, (IrInstructionAsmSrc *)instruction);
28731 case IrInstructionIdArrayType:
28732 return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction);
28733 case IrInstructionIdSizeOf:
28734 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);
28735 case IrInstructionIdTestNonNull:
28736 return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction);
28737 case IrInstructionIdOptionalUnwrapPtr:
28738 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstructionOptionalUnwrapPtr *)instruction);
28739 case IrInstructionIdClz:
28740 return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction);
28741 case IrInstructionIdCtz:
28742 return ir_analyze_instruction_ctz(ira, (IrInstructionCtz *)instruction);
28743 case IrInstructionIdPopCount:
28744 return ir_analyze_instruction_pop_count(ira, (IrInstructionPopCount *)instruction);
28745 case IrInstructionIdBswap:
28746 return ir_analyze_instruction_bswap(ira, (IrInstructionBswap *)instruction);
28747 case IrInstructionIdBitReverse:
28748 return ir_analyze_instruction_bit_reverse(ira, (IrInstructionBitReverse *)instruction);
28749 case IrInstructionIdSwitchBr:
28750 return ir_analyze_instruction_switch_br(ira, (IrInstructionSwitchBr *)instruction);
28751 case IrInstructionIdSwitchTarget:
28752 return ir_analyze_instruction_switch_target(ira, (IrInstructionSwitchTarget *)instruction);
28753 case IrInstructionIdSwitchVar:
28754 return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction);
28755 case IrInstructionIdSwitchElseVar:
28756 return ir_analyze_instruction_switch_else_var(ira, (IrInstructionSwitchElseVar *)instruction);
28757 case IrInstructionIdUnionTag:
28758 return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction);
28759 case IrInstructionIdImport:
28760 return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction);
28761 case IrInstructionIdRef:
28762 return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction);
28763 case IrInstructionIdContainerInitList:
28764 return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction);
28765 case IrInstructionIdContainerInitFields:
28766 return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction);
28767 case IrInstructionIdCompileErr:
28768 return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction);
28769 case IrInstructionIdCompileLog:
28770 return ir_analyze_instruction_compile_log(ira, (IrInstructionCompileLog *)instruction);
28771 case IrInstructionIdErrName:
28772 return ir_analyze_instruction_err_name(ira, (IrInstructionErrName *)instruction);
28773 case IrInstructionIdTypeName:
28774 return ir_analyze_instruction_type_name(ira, (IrInstructionTypeName *)instruction);
28775 case IrInstructionIdCImport:
28776 return ir_analyze_instruction_c_import(ira, (IrInstructionCImport *)instruction);
28777 case IrInstructionIdCInclude:
28778 return ir_analyze_instruction_c_include(ira, (IrInstructionCInclude *)instruction);
28779 case IrInstructionIdCDefine:
28780 return ir_analyze_instruction_c_define(ira, (IrInstructionCDefine *)instruction);
28781 case IrInstructionIdCUndef:
28782 return ir_analyze_instruction_c_undef(ira, (IrInstructionCUndef *)instruction);
28783 case IrInstructionIdEmbedFile:
28784 return ir_analyze_instruction_embed_file(ira, (IrInstructionEmbedFile *)instruction);
28785 case IrInstructionIdCmpxchgSrc:
28786 return ir_analyze_instruction_cmpxchg(ira, (IrInstructionCmpxchgSrc *)instruction);
28787 case IrInstructionIdFence:
28788 return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction);
28789 case IrInstructionIdTruncate:
28790 return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction);
28791 case IrInstructionIdIntCast:
28792 return ir_analyze_instruction_int_cast(ira, (IrInstructionIntCast *)instruction);
28793 case IrInstructionIdFloatCast:
28794 return ir_analyze_instruction_float_cast(ira, (IrInstructionFloatCast *)instruction);
28795 case IrInstructionIdErrSetCast:
28796 return ir_analyze_instruction_err_set_cast(ira, (IrInstructionErrSetCast *)instruction);
28797 case IrInstructionIdFromBytes:
28798 return ir_analyze_instruction_from_bytes(ira, (IrInstructionFromBytes *)instruction);
28799 case IrInstructionIdToBytes:
28800 return ir_analyze_instruction_to_bytes(ira, (IrInstructionToBytes *)instruction);
28801 case IrInstructionIdIntToFloat:
28802 return ir_analyze_instruction_int_to_float(ira, (IrInstructionIntToFloat *)instruction);
28803 case IrInstructionIdFloatToInt:
28804 return ir_analyze_instruction_float_to_int(ira, (IrInstructionFloatToInt *)instruction);
28805 case IrInstructionIdBoolToInt:
28806 return ir_analyze_instruction_bool_to_int(ira, (IrInstructionBoolToInt *)instruction);
28807 case IrInstructionIdIntType:
28808 return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction);
28809 case IrInstructionIdVectorType:
28810 return ir_analyze_instruction_vector_type(ira, (IrInstructionVectorType *)instruction);
28811 case IrInstructionIdShuffleVector:
28812 return ir_analyze_instruction_shuffle_vector(ira, (IrInstructionShuffleVector *)instruction);
28813 case IrInstructionIdSplatSrc:
28814 return ir_analyze_instruction_splat(ira, (IrInstructionSplatSrc *)instruction);
28815 case IrInstructionIdBoolNot:
28816 return ir_analyze_instruction_bool_not(ira, (IrInstructionBoolNot *)instruction);
28817 case IrInstructionIdMemset:
28818 return ir_analyze_instruction_memset(ira, (IrInstructionMemset *)instruction);
28819 case IrInstructionIdMemcpy:
28820 return ir_analyze_instruction_memcpy(ira, (IrInstructionMemcpy *)instruction);
28821 case IrInstructionIdSliceSrc:
28822 return ir_analyze_instruction_slice(ira, (IrInstructionSliceSrc *)instruction);
28823 case IrInstructionIdMemberCount:
28824 return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction);
28825 case IrInstructionIdMemberType:
28826 return ir_analyze_instruction_member_type(ira, (IrInstructionMemberType *)instruction);
28827 case IrInstructionIdMemberName:
28828 return ir_analyze_instruction_member_name(ira, (IrInstructionMemberName *)instruction);
28829 case IrInstructionIdBreakpoint:
28830 return ir_analyze_instruction_breakpoint(ira, (IrInstructionBreakpoint *)instruction);
28831 case IrInstructionIdReturnAddress:
28832 return ir_analyze_instruction_return_address(ira, (IrInstructionReturnAddress *)instruction);
28833 case IrInstructionIdFrameAddress:
28834 return ir_analyze_instruction_frame_address(ira, (IrInstructionFrameAddress *)instruction);
28835 case IrInstructionIdFrameHandle:
28836 return ir_analyze_instruction_frame_handle(ira, (IrInstructionFrameHandle *)instruction);
28837 case IrInstructionIdFrameType:
28838 return ir_analyze_instruction_frame_type(ira, (IrInstructionFrameType *)instruction);
28839 case IrInstructionIdFrameSizeSrc:
28840 return ir_analyze_instruction_frame_size(ira, (IrInstructionFrameSizeSrc *)instruction);
28841 case IrInstructionIdAlignOf:
28842 return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction);
28843 case IrInstructionIdOverflowOp:
28844 return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction);
28845 case IrInstructionIdTestErrSrc:
28846 return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction);
28847 case IrInstructionIdUnwrapErrCode:
28848 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);
28849 case IrInstructionIdUnwrapErrPayload:
28850 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction);
28851 case IrInstructionIdFnProto:
28852 return ir_analyze_instruction_fn_proto(ira, (IrInstructionFnProto *)instruction);
28853 case IrInstructionIdTestComptime:
28854 return ir_analyze_instruction_test_comptime(ira, (IrInstructionTestComptime *)instruction);
28855 case IrInstructionIdCheckSwitchProngs:
28856 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction);
28857 case IrInstructionIdCheckStatementIsVoid:
28858 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction);
28859 case IrInstructionIdDeclRef:
28860 return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction);
28861 case IrInstructionIdPanic:
28862 return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction);
28863 case IrInstructionIdPtrCastSrc:
28864 return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction);
28865 case IrInstructionIdIntToPtr:
28866 return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction);
28867 case IrInstructionIdPtrToInt:
28868 return ir_analyze_instruction_ptr_to_int(ira, (IrInstructionPtrToInt *)instruction);
28869 case IrInstructionIdTagName:
28870 return ir_analyze_instruction_enum_tag_name(ira, (IrInstructionTagName *)instruction);
28871 case IrInstructionIdFieldParentPtr:
28872 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstructionFieldParentPtr *)instruction);
28873 case IrInstructionIdByteOffsetOf:
28874 return ir_analyze_instruction_byte_offset_of(ira, (IrInstructionByteOffsetOf *)instruction);
28875 case IrInstructionIdBitOffsetOf:
28876 return ir_analyze_instruction_bit_offset_of(ira, (IrInstructionBitOffsetOf *)instruction);
28877 case IrInstructionIdTypeInfo:
28878 return ir_analyze_instruction_type_info(ira, (IrInstructionTypeInfo *) instruction);
28879 case IrInstructionIdType:
28880 return ir_analyze_instruction_type(ira, (IrInstructionType *)instruction);
28881 case IrInstructionIdHasField:
28882 return ir_analyze_instruction_has_field(ira, (IrInstructionHasField *) instruction);
28883 case IrInstructionIdTypeId:
28884 return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction);
28885 case IrInstructionIdSetEvalBranchQuota:
28886 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction);
28887 case IrInstructionIdPtrType:
28888 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);
28889 case IrInstructionIdAlignCast:
28890 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);
28891 case IrInstructionIdImplicitCast:
28892 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);
28893 case IrInstructionIdResolveResult:
28894 return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction);
28895 case IrInstructionIdResetResult:
28896 return ir_analyze_instruction_reset_result(ira, (IrInstructionResetResult *)instruction);
28897 case IrInstructionIdOpaqueType:
28898 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);
28899 case IrInstructionIdSetAlignStack:
28900 return ir_analyze_instruction_set_align_stack(ira, (IrInstructionSetAlignStack *)instruction);
28901 case IrInstructionIdArgType:
28902 return ir_analyze_instruction_arg_type(ira, (IrInstructionArgType *)instruction);
28903 case IrInstructionIdTagType:
28904 return ir_analyze_instruction_tag_type(ira, (IrInstructionTagType *)instruction);
28905 case IrInstructionIdExport:
28906 return ir_analyze_instruction_export(ira, (IrInstructionExport *)instruction);
28907 case IrInstructionIdErrorReturnTrace:
28908 return ir_analyze_instruction_error_return_trace(ira, (IrInstructionErrorReturnTrace *)instruction);
28909 case IrInstructionIdErrorUnion:
28910 return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction);
28911 case IrInstructionIdAtomicRmw:
28912 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);
28913 case IrInstructionIdAtomicLoad:
28914 return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction);
28915 case IrInstructionIdAtomicStore:
28916 return ir_analyze_instruction_atomic_store(ira, (IrInstructionAtomicStore *)instruction);
28917 case IrInstructionIdSaveErrRetAddr:
28918 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);
28919 case IrInstructionIdAddImplicitReturnType:
28920 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction);
28921 case IrInstructionIdFloatOp:
28922 return ir_analyze_instruction_float_op(ira, (IrInstructionFloatOp *)instruction);
28923 case IrInstructionIdMulAdd:
28924 return ir_analyze_instruction_mul_add(ira, (IrInstructionMulAdd *)instruction);
28925 case IrInstructionIdIntToErr:
28926 return ir_analyze_instruction_int_to_err(ira, (IrInstructionIntToErr *)instruction);
28927 case IrInstructionIdErrToInt:
28928 return ir_analyze_instruction_err_to_int(ira, (IrInstructionErrToInt *)instruction);
28929 case IrInstructionIdIntToEnum:
28930 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);
28931 case IrInstructionIdEnumToInt:
28932 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);
28933 case IrInstructionIdCheckRuntimeScope:
28934 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction);
28935 case IrInstructionIdHasDecl:
28936 return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction);
28937 case IrInstructionIdUndeclaredIdent:
28938 return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction);
28939 case IrInstructionIdAllocaSrc:
29450 case IrInstSrcIdReturn:
29451 return ir_analyze_instruction_return(ira, (IrInstSrcReturn *)instruction);
29452 case IrInstSrcIdConst:
29453 return ir_analyze_instruction_const(ira, (IrInstSrcConst *)instruction);
29454 case IrInstSrcIdUnOp:
29455 return ir_analyze_instruction_un_op(ira, (IrInstSrcUnOp *)instruction);
29456 case IrInstSrcIdBinOp:
29457 return ir_analyze_instruction_bin_op(ira, (IrInstSrcBinOp *)instruction);
29458 case IrInstSrcIdMergeErrSets:
29459 return ir_analyze_instruction_merge_err_sets(ira, (IrInstSrcMergeErrSets *)instruction);
29460 case IrInstSrcIdDeclVar:
29461 return ir_analyze_instruction_decl_var(ira, (IrInstSrcDeclVar *)instruction);
29462 case IrInstSrcIdLoadPtr:
29463 return ir_analyze_instruction_load_ptr(ira, (IrInstSrcLoadPtr *)instruction);
29464 case IrInstSrcIdStorePtr:
29465 return ir_analyze_instruction_store_ptr(ira, (IrInstSrcStorePtr *)instruction);
29466 case IrInstSrcIdElemPtr:
29467 return ir_analyze_instruction_elem_ptr(ira, (IrInstSrcElemPtr *)instruction);
29468 case IrInstSrcIdVarPtr:
29469 return ir_analyze_instruction_var_ptr(ira, (IrInstSrcVarPtr *)instruction);
29470 case IrInstSrcIdFieldPtr:
29471 return ir_analyze_instruction_field_ptr(ira, (IrInstSrcFieldPtr *)instruction);
29472 case IrInstSrcIdCall:
29473 return ir_analyze_instruction_call(ira, (IrInstSrcCall *)instruction);
29474 case IrInstSrcIdCallArgs:
29475 return ir_analyze_instruction_call_args(ira, (IrInstSrcCallArgs *)instruction);
29476 case IrInstSrcIdCallExtra:
29477 return ir_analyze_instruction_call_extra(ira, (IrInstSrcCallExtra *)instruction);
29478 case IrInstSrcIdBr:
29479 return ir_analyze_instruction_br(ira, (IrInstSrcBr *)instruction);
29480 case IrInstSrcIdCondBr:
29481 return ir_analyze_instruction_cond_br(ira, (IrInstSrcCondBr *)instruction);
29482 case IrInstSrcIdUnreachable:
29483 return ir_analyze_instruction_unreachable(ira, (IrInstSrcUnreachable *)instruction);
29484 case IrInstSrcIdPhi:
29485 return ir_analyze_instruction_phi(ira, (IrInstSrcPhi *)instruction);
29486 case IrInstSrcIdTypeOf:
29487 return ir_analyze_instruction_typeof(ira, (IrInstSrcTypeOf *)instruction);
29488 case IrInstSrcIdSetCold:
29489 return ir_analyze_instruction_set_cold(ira, (IrInstSrcSetCold *)instruction);
29490 case IrInstSrcIdSetRuntimeSafety:
29491 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstSrcSetRuntimeSafety *)instruction);
29492 case IrInstSrcIdSetFloatMode:
29493 return ir_analyze_instruction_set_float_mode(ira, (IrInstSrcSetFloatMode *)instruction);
29494 case IrInstSrcIdAnyFrameType:
29495 return ir_analyze_instruction_any_frame_type(ira, (IrInstSrcAnyFrameType *)instruction);
29496 case IrInstSrcIdSliceType:
29497 return ir_analyze_instruction_slice_type(ira, (IrInstSrcSliceType *)instruction);
29498 case IrInstSrcIdAsm:
29499 return ir_analyze_instruction_asm(ira, (IrInstSrcAsm *)instruction);
29500 case IrInstSrcIdArrayType:
29501 return ir_analyze_instruction_array_type(ira, (IrInstSrcArrayType *)instruction);
29502 case IrInstSrcIdSizeOf:
29503 return ir_analyze_instruction_size_of(ira, (IrInstSrcSizeOf *)instruction);
29504 case IrInstSrcIdTestNonNull:
29505 return ir_analyze_instruction_test_non_null(ira, (IrInstSrcTestNonNull *)instruction);
29506 case IrInstSrcIdOptionalUnwrapPtr:
29507 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstSrcOptionalUnwrapPtr *)instruction);
29508 case IrInstSrcIdClz:
29509 return ir_analyze_instruction_clz(ira, (IrInstSrcClz *)instruction);
29510 case IrInstSrcIdCtz:
29511 return ir_analyze_instruction_ctz(ira, (IrInstSrcCtz *)instruction);
29512 case IrInstSrcIdPopCount:
29513 return ir_analyze_instruction_pop_count(ira, (IrInstSrcPopCount *)instruction);
29514 case IrInstSrcIdBswap:
29515 return ir_analyze_instruction_bswap(ira, (IrInstSrcBswap *)instruction);
29516 case IrInstSrcIdBitReverse:
29517 return ir_analyze_instruction_bit_reverse(ira, (IrInstSrcBitReverse *)instruction);
29518 case IrInstSrcIdSwitchBr:
29519 return ir_analyze_instruction_switch_br(ira, (IrInstSrcSwitchBr *)instruction);
29520 case IrInstSrcIdSwitchTarget:
29521 return ir_analyze_instruction_switch_target(ira, (IrInstSrcSwitchTarget *)instruction);
29522 case IrInstSrcIdSwitchVar:
29523 return ir_analyze_instruction_switch_var(ira, (IrInstSrcSwitchVar *)instruction);
29524 case IrInstSrcIdSwitchElseVar:
29525 return ir_analyze_instruction_switch_else_var(ira, (IrInstSrcSwitchElseVar *)instruction);
29526 case IrInstSrcIdImport:
29527 return ir_analyze_instruction_import(ira, (IrInstSrcImport *)instruction);
29528 case IrInstSrcIdRef:
29529 return ir_analyze_instruction_ref(ira, (IrInstSrcRef *)instruction);
29530 case IrInstSrcIdContainerInitList:
29531 return ir_analyze_instruction_container_init_list(ira, (IrInstSrcContainerInitList *)instruction);
29532 case IrInstSrcIdContainerInitFields:
29533 return ir_analyze_instruction_container_init_fields(ira, (IrInstSrcContainerInitFields *)instruction);
29534 case IrInstSrcIdCompileErr:
29535 return ir_analyze_instruction_compile_err(ira, (IrInstSrcCompileErr *)instruction);
29536 case IrInstSrcIdCompileLog:
29537 return ir_analyze_instruction_compile_log(ira, (IrInstSrcCompileLog *)instruction);
29538 case IrInstSrcIdErrName:
29539 return ir_analyze_instruction_err_name(ira, (IrInstSrcErrName *)instruction);
29540 case IrInstSrcIdTypeName:
29541 return ir_analyze_instruction_type_name(ira, (IrInstSrcTypeName *)instruction);
29542 case IrInstSrcIdCImport:
29543 return ir_analyze_instruction_c_import(ira, (IrInstSrcCImport *)instruction);
29544 case IrInstSrcIdCInclude:
29545 return ir_analyze_instruction_c_include(ira, (IrInstSrcCInclude *)instruction);
29546 case IrInstSrcIdCDefine:
29547 return ir_analyze_instruction_c_define(ira, (IrInstSrcCDefine *)instruction);
29548 case IrInstSrcIdCUndef:
29549 return ir_analyze_instruction_c_undef(ira, (IrInstSrcCUndef *)instruction);
29550 case IrInstSrcIdEmbedFile:
29551 return ir_analyze_instruction_embed_file(ira, (IrInstSrcEmbedFile *)instruction);
29552 case IrInstSrcIdCmpxchg:
29553 return ir_analyze_instruction_cmpxchg(ira, (IrInstSrcCmpxchg *)instruction);
29554 case IrInstSrcIdFence:
29555 return ir_analyze_instruction_fence(ira, (IrInstSrcFence *)instruction);
29556 case IrInstSrcIdTruncate:
29557 return ir_analyze_instruction_truncate(ira, (IrInstSrcTruncate *)instruction);
29558 case IrInstSrcIdIntCast:
29559 return ir_analyze_instruction_int_cast(ira, (IrInstSrcIntCast *)instruction);
29560 case IrInstSrcIdFloatCast:
29561 return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);
29562 case IrInstSrcIdErrSetCast:
29563 return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction);
29564 case IrInstSrcIdFromBytes:
29565 return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction);
29566 case IrInstSrcIdToBytes:
29567 return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction);
29568 case IrInstSrcIdIntToFloat:
29569 return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
29570 case IrInstSrcIdFloatToInt:
29571 return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
29572 case IrInstSrcIdBoolToInt:
29573 return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
29574 case IrInstSrcIdIntType:
29575 return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
29576 case IrInstSrcIdVectorType:
29577 return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
29578 case IrInstSrcIdShuffleVector:
29579 return ir_analyze_instruction_shuffle_vector(ira, (IrInstSrcShuffleVector *)instruction);
29580 case IrInstSrcIdSplat:
29581 return ir_analyze_instruction_splat(ira, (IrInstSrcSplat *)instruction);
29582 case IrInstSrcIdBoolNot:
29583 return ir_analyze_instruction_bool_not(ira, (IrInstSrcBoolNot *)instruction);
29584 case IrInstSrcIdMemset:
29585 return ir_analyze_instruction_memset(ira, (IrInstSrcMemset *)instruction);
29586 case IrInstSrcIdMemcpy:
29587 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
29588 case IrInstSrcIdSlice:
29589 return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
29590 case IrInstSrcIdMemberCount:
29591 return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
29592 case IrInstSrcIdMemberType:
29593 return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
29594 case IrInstSrcIdMemberName:
29595 return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
29596 case IrInstSrcIdBreakpoint:
29597 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
29598 case IrInstSrcIdReturnAddress:
29599 return ir_analyze_instruction_return_address(ira, (IrInstSrcReturnAddress *)instruction);
29600 case IrInstSrcIdFrameAddress:
29601 return ir_analyze_instruction_frame_address(ira, (IrInstSrcFrameAddress *)instruction);
29602 case IrInstSrcIdFrameHandle:
29603 return ir_analyze_instruction_frame_handle(ira, (IrInstSrcFrameHandle *)instruction);
29604 case IrInstSrcIdFrameType:
29605 return ir_analyze_instruction_frame_type(ira, (IrInstSrcFrameType *)instruction);
29606 case IrInstSrcIdFrameSize:
29607 return ir_analyze_instruction_frame_size(ira, (IrInstSrcFrameSize *)instruction);
29608 case IrInstSrcIdAlignOf:
29609 return ir_analyze_instruction_align_of(ira, (IrInstSrcAlignOf *)instruction);
29610 case IrInstSrcIdOverflowOp:
29611 return ir_analyze_instruction_overflow_op(ira, (IrInstSrcOverflowOp *)instruction);
29612 case IrInstSrcIdTestErr:
29613 return ir_analyze_instruction_test_err(ira, (IrInstSrcTestErr *)instruction);
29614 case IrInstSrcIdUnwrapErrCode:
29615 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstSrcUnwrapErrCode *)instruction);
29616 case IrInstSrcIdUnwrapErrPayload:
29617 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstSrcUnwrapErrPayload *)instruction);
29618 case IrInstSrcIdFnProto:
29619 return ir_analyze_instruction_fn_proto(ira, (IrInstSrcFnProto *)instruction);
29620 case IrInstSrcIdTestComptime:
29621 return ir_analyze_instruction_test_comptime(ira, (IrInstSrcTestComptime *)instruction);
29622 case IrInstSrcIdCheckSwitchProngs:
29623 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstSrcCheckSwitchProngs *)instruction);
29624 case IrInstSrcIdCheckStatementIsVoid:
29625 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstSrcCheckStatementIsVoid *)instruction);
29626 case IrInstSrcIdDeclRef:
29627 return ir_analyze_instruction_decl_ref(ira, (IrInstSrcDeclRef *)instruction);
29628 case IrInstSrcIdPanic:
29629 return ir_analyze_instruction_panic(ira, (IrInstSrcPanic *)instruction);
29630 case IrInstSrcIdPtrCast:
29631 return ir_analyze_instruction_ptr_cast(ira, (IrInstSrcPtrCast *)instruction);
29632 case IrInstSrcIdIntToPtr:
29633 return ir_analyze_instruction_int_to_ptr(ira, (IrInstSrcIntToPtr *)instruction);
29634 case IrInstSrcIdPtrToInt:
29635 return ir_analyze_instruction_ptr_to_int(ira, (IrInstSrcPtrToInt *)instruction);
29636 case IrInstSrcIdTagName:
29637 return ir_analyze_instruction_enum_tag_name(ira, (IrInstSrcTagName *)instruction);
29638 case IrInstSrcIdFieldParentPtr:
29639 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstSrcFieldParentPtr *)instruction);
29640 case IrInstSrcIdByteOffsetOf:
29641 return ir_analyze_instruction_byte_offset_of(ira, (IrInstSrcByteOffsetOf *)instruction);
29642 case IrInstSrcIdBitOffsetOf:
29643 return ir_analyze_instruction_bit_offset_of(ira, (IrInstSrcBitOffsetOf *)instruction);
29644 case IrInstSrcIdTypeInfo:
29645 return ir_analyze_instruction_type_info(ira, (IrInstSrcTypeInfo *) instruction);
29646 case IrInstSrcIdType:
29647 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
29648 case IrInstSrcIdHasField:
29649 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
29650 case IrInstSrcIdTypeId:
29651 return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
29652 case IrInstSrcIdSetEvalBranchQuota:
29653 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
29654 case IrInstSrcIdPtrType:
29655 return ir_analyze_instruction_ptr_type(ira, (IrInstSrcPtrType *)instruction);
29656 case IrInstSrcIdAlignCast:
29657 return ir_analyze_instruction_align_cast(ira, (IrInstSrcAlignCast *)instruction);
29658 case IrInstSrcIdImplicitCast:
29659 return ir_analyze_instruction_implicit_cast(ira, (IrInstSrcImplicitCast *)instruction);
29660 case IrInstSrcIdResolveResult:
29661 return ir_analyze_instruction_resolve_result(ira, (IrInstSrcResolveResult *)instruction);
29662 case IrInstSrcIdResetResult:
29663 return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction);
29664 case IrInstSrcIdOpaqueType:
29665 return ir_analyze_instruction_opaque_type(ira, (IrInstSrcOpaqueType *)instruction);
29666 case IrInstSrcIdSetAlignStack:
29667 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);
29668 case IrInstSrcIdArgType:
29669 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);
29670 case IrInstSrcIdTagType:
29671 return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction);
29672 case IrInstSrcIdExport:
29673 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);
29674 case IrInstSrcIdErrorReturnTrace:
29675 return ir_analyze_instruction_error_return_trace(ira, (IrInstSrcErrorReturnTrace *)instruction);
29676 case IrInstSrcIdErrorUnion:
29677 return ir_analyze_instruction_error_union(ira, (IrInstSrcErrorUnion *)instruction);
29678 case IrInstSrcIdAtomicRmw:
29679 return ir_analyze_instruction_atomic_rmw(ira, (IrInstSrcAtomicRmw *)instruction);
29680 case IrInstSrcIdAtomicLoad:
29681 return ir_analyze_instruction_atomic_load(ira, (IrInstSrcAtomicLoad *)instruction);
29682 case IrInstSrcIdAtomicStore:
29683 return ir_analyze_instruction_atomic_store(ira, (IrInstSrcAtomicStore *)instruction);
29684 case IrInstSrcIdSaveErrRetAddr:
29685 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstSrcSaveErrRetAddr *)instruction);
29686 case IrInstSrcIdAddImplicitReturnType:
29687 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstSrcAddImplicitReturnType *)instruction);
29688 case IrInstSrcIdFloatOp:
29689 return ir_analyze_instruction_float_op(ira, (IrInstSrcFloatOp *)instruction);
29690 case IrInstSrcIdMulAdd:
29691 return ir_analyze_instruction_mul_add(ira, (IrInstSrcMulAdd *)instruction);
29692 case IrInstSrcIdIntToErr:
29693 return ir_analyze_instruction_int_to_err(ira, (IrInstSrcIntToErr *)instruction);
29694 case IrInstSrcIdErrToInt:
29695 return ir_analyze_instruction_err_to_int(ira, (IrInstSrcErrToInt *)instruction);
29696 case IrInstSrcIdIntToEnum:
29697 return ir_analyze_instruction_int_to_enum(ira, (IrInstSrcIntToEnum *)instruction);
29698 case IrInstSrcIdEnumToInt:
29699 return ir_analyze_instruction_enum_to_int(ira, (IrInstSrcEnumToInt *)instruction);
29700 case IrInstSrcIdCheckRuntimeScope:
29701 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstSrcCheckRuntimeScope *)instruction);
29702 case IrInstSrcIdHasDecl:
29703 return ir_analyze_instruction_has_decl(ira, (IrInstSrcHasDecl *)instruction);
29704 case IrInstSrcIdUndeclaredIdent:
29705 return ir_analyze_instruction_undeclared_ident(ira, (IrInstSrcUndeclaredIdent *)instruction);
29706 case IrInstSrcIdAlloca:
2894029707 return nullptr;
28941 case IrInstructionIdEndExpr:
28942 return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction);
28943 case IrInstructionIdBitCastSrc:
28944 return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction);
28945 case IrInstructionIdUnionInitNamedField:
28946 return ir_analyze_instruction_union_init_named_field(ira, (IrInstructionUnionInitNamedField *)instruction);
28947 case IrInstructionIdSuspendBegin:
28948 return ir_analyze_instruction_suspend_begin(ira, (IrInstructionSuspendBegin *)instruction);
28949 case IrInstructionIdSuspendFinish:
28950 return ir_analyze_instruction_suspend_finish(ira, (IrInstructionSuspendFinish *)instruction);
28951 case IrInstructionIdResume:
28952 return ir_analyze_instruction_resume(ira, (IrInstructionResume *)instruction);
28953 case IrInstructionIdAwaitSrc:
28954 return ir_analyze_instruction_await(ira, (IrInstructionAwaitSrc *)instruction);
28955 case IrInstructionIdSpillBegin:
28956 return ir_analyze_instruction_spill_begin(ira, (IrInstructionSpillBegin *)instruction);
28957 case IrInstructionIdSpillEnd:
28958 return ir_analyze_instruction_spill_end(ira, (IrInstructionSpillEnd *)instruction);
29708 case IrInstSrcIdEndExpr:
29709 return ir_analyze_instruction_end_expr(ira, (IrInstSrcEndExpr *)instruction);
29710 case IrInstSrcIdBitCast:
29711 return ir_analyze_instruction_bit_cast_src(ira, (IrInstSrcBitCast *)instruction);
29712 case IrInstSrcIdUnionInitNamedField:
29713 return ir_analyze_instruction_union_init_named_field(ira, (IrInstSrcUnionInitNamedField *)instruction);
29714 case IrInstSrcIdSuspendBegin:
29715 return ir_analyze_instruction_suspend_begin(ira, (IrInstSrcSuspendBegin *)instruction);
29716 case IrInstSrcIdSuspendFinish:
29717 return ir_analyze_instruction_suspend_finish(ira, (IrInstSrcSuspendFinish *)instruction);
29718 case IrInstSrcIdResume:
29719 return ir_analyze_instruction_resume(ira, (IrInstSrcResume *)instruction);
29720 case IrInstSrcIdAwait:
29721 return ir_analyze_instruction_await(ira, (IrInstSrcAwait *)instruction);
29722 case IrInstSrcIdSpillBegin:
29723 return ir_analyze_instruction_spill_begin(ira, (IrInstSrcSpillBegin *)instruction);
29724 case IrInstSrcIdSpillEnd:
29725 return ir_analyze_instruction_spill_end(ira, (IrInstSrcSpillEnd *)instruction);
2895929726 }
2896029727 zig_unreachable();
2896129728}
2896229729
2896329730// This function attempts to evaluate IR code while doing type checking and other analysis.
28964// It emits a new IrExecutable which is partially evaluated IR code.
28965ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
29731// It emits to a new IrExecutableGen which is partially evaluated IR code.
29732ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec,
2896629733 ZigType *expected_type, AstNode *expected_type_source_node)
2896729734{
2896829735 assert(old_exec->first_err_trace_msg == nullptr);
......@@ -28988,18 +29755,18 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2898829755 ira->exec_context.mem_slot_list.items[i] = &vals[i];
2898929756 }
2899029757
28991 IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0);
28992 IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
28993 ir_ref_bb(new_entry_bb);
29758 IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0);
29759 IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
29760 ir_ref_bb_gen(new_entry_bb);
2899429761 ira->new_irb.current_basic_block = new_entry_bb;
2899529762 ira->old_bb_index = 0;
2899629763
2899729764 ir_start_bb(ira, old_entry_bb, nullptr);
2899829765
2899929766 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {
29000 IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
29767 IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
2900129768
29002 if (old_instruction->ref_count == 0 && !ir_has_side_effects(old_instruction)) {
29769 if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) {
2900329770 ira->instruction_index += 1;
2900429771 continue;
2900529772 }
......@@ -29008,14 +29775,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2900829775 fprintf(stderr, "~ ");
2900929776 old_instruction->src();
2901029777 fprintf(stderr, "~ ");
29011 ir_print_instruction(codegen, stderr, old_instruction, 0, IrPassSrc);
29778 ir_print_inst_src(codegen, stderr, old_instruction, 0);
2901229779 bool want_break = false;
29013 if (ira->break_debug_id == old_instruction->debug_id) {
29780 if (ira->break_debug_id == old_instruction->base.debug_id) {
2901429781 want_break = true;
29015 } else if (old_instruction->source_node != nullptr) {
29782 } else if (old_instruction->base.source_node != nullptr) {
2901629783 for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) {
29017 if (dbg_ir_breakpoints_buf[i].line == old_instruction->source_node->line + 1 &&
29018 buf_ends_with_str(old_instruction->source_node->owner->data.structure.root_struct->path,
29784 if (dbg_ir_breakpoints_buf[i].line == old_instruction->base.source_node->line + 1 &&
29785 buf_ends_with_str(old_instruction->base.source_node->owner->data.structure.root_struct->path,
2901929786 dbg_ir_breakpoints_buf[i].src_file))
2902029787 {
2902129788 want_break = true;
......@@ -29024,9 +29791,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2902429791 }
2902529792 if (want_break) BREAKPOINT;
2902629793 }
29027 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
29794 IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
2902829795 if (new_instruction != nullptr) {
29029 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction);
29796 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base);
2903029797 old_instruction->child = new_instruction;
2903129798
2903229799 if (type_is_invalid(new_instruction->value->type)) {
......@@ -29040,19 +29807,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2904029807 new_exec->first_err_trace_msg = ira->codegen->trace_err;
2904129808 }
2904229809 if (new_exec->first_err_trace_msg != nullptr &&
29043 !old_instruction->source_node->already_traced_this_node)
29810 !old_instruction->base.source_node->already_traced_this_node)
2904429811 {
29045 old_instruction->source_node->already_traced_this_node = true;
29812 old_instruction->base.source_node->already_traced_this_node = true;
2904629813 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,
29047 old_instruction->source_node, buf_create_from_str("referenced here"));
29814 old_instruction->base.source_node, buf_create_from_str("referenced here"));
2904829815 }
2904929816 return ira->codegen->builtin_types.entry_invalid;
2905029817 } else if (ira->codegen->verbose_ir) {
2905129818 fprintf(stderr, "-> ");
29052 if (instr_is_unreachable(new_instruction)) {
29819 if (new_instruction->value->type->id == ZigTypeIdUnreachable) {
2905329820 fprintf(stderr, "(noreturn)\n");
2905429821 } else {
29055 ir_print_instruction(codegen, stderr, new_instruction, 0, IrPassGen);
29822 ir_print_inst_gen(codegen, stderr, new_instruction, 0);
2905629823 }
2905729824 }
2905829825
......@@ -29092,204 +29859,279 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2909229859 return res_type;
2909329860}
2909429861
29095bool ir_has_side_effects(IrInstruction *instruction) {
29862bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {
2909629863 switch (instruction->id) {
29097 case IrInstructionIdInvalid:
29864 case IrInstGenIdInvalid:
2909829865 zig_unreachable();
29099 case IrInstructionIdBr:
29100 case IrInstructionIdCondBr:
29101 case IrInstructionIdSwitchBr:
29102 case IrInstructionIdDeclVarSrc:
29103 case IrInstructionIdDeclVarGen:
29104 case IrInstructionIdStorePtr:
29105 case IrInstructionIdVectorStoreElem:
29106 case IrInstructionIdCallExtra:
29107 case IrInstructionIdCallSrc:
29108 case IrInstructionIdCallSrcArgs:
29109 case IrInstructionIdCallGen:
29110 case IrInstructionIdReturn:
29111 case IrInstructionIdUnreachable:
29112 case IrInstructionIdSetCold:
29113 case IrInstructionIdSetRuntimeSafety:
29114 case IrInstructionIdSetFloatMode:
29115 case IrInstructionIdImport:
29116 case IrInstructionIdCompileErr:
29117 case IrInstructionIdCompileLog:
29118 case IrInstructionIdCImport:
29119 case IrInstructionIdCInclude:
29120 case IrInstructionIdCDefine:
29121 case IrInstructionIdCUndef:
29122 case IrInstructionIdFence:
29123 case IrInstructionIdMemset:
29124 case IrInstructionIdMemcpy:
29125 case IrInstructionIdBreakpoint:
29126 case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free
29127 case IrInstructionIdCheckSwitchProngs:
29128 case IrInstructionIdCheckStatementIsVoid:
29129 case IrInstructionIdCheckRuntimeScope:
29130 case IrInstructionIdPanic:
29131 case IrInstructionIdSetEvalBranchQuota:
29132 case IrInstructionIdPtrType:
29133 case IrInstructionIdSetAlignStack:
29134 case IrInstructionIdExport:
29135 case IrInstructionIdSaveErrRetAddr:
29136 case IrInstructionIdAddImplicitReturnType:
29137 case IrInstructionIdAtomicRmw:
29138 case IrInstructionIdAtomicStore:
29139 case IrInstructionIdCmpxchgGen:
29140 case IrInstructionIdCmpxchgSrc:
29141 case IrInstructionIdAssertZero:
29142 case IrInstructionIdAssertNonNull:
29143 case IrInstructionIdResizeSlice:
29144 case IrInstructionIdUndeclaredIdent:
29145 case IrInstructionIdEndExpr:
29146 case IrInstructionIdPtrOfArrayToSlice:
29147 case IrInstructionIdSliceGen:
29148 case IrInstructionIdOptionalWrap:
29149 case IrInstructionIdVectorToArray:
29150 case IrInstructionIdResetResult:
29151 case IrInstructionIdSuspendBegin:
29152 case IrInstructionIdSuspendFinish:
29153 case IrInstructionIdResume:
29154 case IrInstructionIdAwaitSrc:
29155 case IrInstructionIdAwaitGen:
29156 case IrInstructionIdSpillBegin:
29866 case IrInstGenIdBr:
29867 case IrInstGenIdCondBr:
29868 case IrInstGenIdSwitchBr:
29869 case IrInstGenIdDeclVar:
29870 case IrInstGenIdStorePtr:
29871 case IrInstGenIdVectorStoreElem:
29872 case IrInstGenIdCall:
29873 case IrInstGenIdReturn:
29874 case IrInstGenIdUnreachable:
29875 case IrInstGenIdFence:
29876 case IrInstGenIdMemset:
29877 case IrInstGenIdMemcpy:
29878 case IrInstGenIdBreakpoint:
29879 case IrInstGenIdOverflowOp: // TODO when we support multiple returns this can be side effect free
29880 case IrInstGenIdPanic:
29881 case IrInstGenIdSaveErrRetAddr:
29882 case IrInstGenIdAtomicRmw:
29883 case IrInstGenIdAtomicStore:
29884 case IrInstGenIdCmpxchg:
29885 case IrInstGenIdAssertZero:
29886 case IrInstGenIdAssertNonNull:
29887 case IrInstGenIdResizeSlice:
29888 case IrInstGenIdPtrOfArrayToSlice:
29889 case IrInstGenIdSlice:
29890 case IrInstGenIdOptionalWrap:
29891 case IrInstGenIdVectorToArray:
29892 case IrInstGenIdSuspendBegin:
29893 case IrInstGenIdSuspendFinish:
29894 case IrInstGenIdResume:
29895 case IrInstGenIdAwait:
29896 case IrInstGenIdSpillBegin:
2915729897 return true;
2915829898
29159 case IrInstructionIdPhi:
29160 case IrInstructionIdUnOp:
29161 case IrInstructionIdBinOp:
29162 case IrInstructionIdMergeErrSets:
29163 case IrInstructionIdLoadPtr:
29164 case IrInstructionIdConst:
29165 case IrInstructionIdCast:
29166 case IrInstructionIdContainerInitList:
29167 case IrInstructionIdContainerInitFields:
29168 case IrInstructionIdUnionInitNamedField:
29169 case IrInstructionIdFieldPtr:
29170 case IrInstructionIdElemPtr:
29171 case IrInstructionIdVarPtr:
29172 case IrInstructionIdReturnPtr:
29173 case IrInstructionIdTypeOf:
29174 case IrInstructionIdStructFieldPtr:
29175 case IrInstructionIdArrayType:
29176 case IrInstructionIdSliceType:
29177 case IrInstructionIdAnyFrameType:
29178 case IrInstructionIdSizeOf:
29179 case IrInstructionIdTestNonNull:
29180 case IrInstructionIdOptionalUnwrapPtr:
29181 case IrInstructionIdClz:
29182 case IrInstructionIdCtz:
29183 case IrInstructionIdPopCount:
29184 case IrInstructionIdBswap:
29185 case IrInstructionIdBitReverse:
29186 case IrInstructionIdSwitchVar:
29187 case IrInstructionIdSwitchElseVar:
29188 case IrInstructionIdSwitchTarget:
29189 case IrInstructionIdUnionTag:
29190 case IrInstructionIdRef:
29191 case IrInstructionIdEmbedFile:
29192 case IrInstructionIdTruncate:
29193 case IrInstructionIdIntType:
29194 case IrInstructionIdVectorType:
29195 case IrInstructionIdShuffleVector:
29196 case IrInstructionIdSplatSrc:
29197 case IrInstructionIdSplatGen:
29198 case IrInstructionIdBoolNot:
29199 case IrInstructionIdSliceSrc:
29200 case IrInstructionIdMemberCount:
29201 case IrInstructionIdMemberType:
29202 case IrInstructionIdMemberName:
29203 case IrInstructionIdAlignOf:
29204 case IrInstructionIdReturnAddress:
29205 case IrInstructionIdFrameAddress:
29206 case IrInstructionIdFrameHandle:
29207 case IrInstructionIdFrameType:
29208 case IrInstructionIdFrameSizeSrc:
29209 case IrInstructionIdFrameSizeGen:
29210 case IrInstructionIdTestErrSrc:
29211 case IrInstructionIdTestErrGen:
29212 case IrInstructionIdFnProto:
29213 case IrInstructionIdTestComptime:
29214 case IrInstructionIdPtrCastSrc:
29215 case IrInstructionIdPtrCastGen:
29216 case IrInstructionIdBitCastSrc:
29217 case IrInstructionIdBitCastGen:
29218 case IrInstructionIdWidenOrShorten:
29219 case IrInstructionIdPtrToInt:
29220 case IrInstructionIdIntToPtr:
29221 case IrInstructionIdIntToEnum:
29222 case IrInstructionIdIntToErr:
29223 case IrInstructionIdErrToInt:
29224 case IrInstructionIdDeclRef:
29225 case IrInstructionIdErrName:
29226 case IrInstructionIdTypeName:
29227 case IrInstructionIdTagName:
29228 case IrInstructionIdFieldParentPtr:
29229 case IrInstructionIdByteOffsetOf:
29230 case IrInstructionIdBitOffsetOf:
29231 case IrInstructionIdTypeInfo:
29232 case IrInstructionIdType:
29233 case IrInstructionIdHasField:
29234 case IrInstructionIdTypeId:
29235 case IrInstructionIdAlignCast:
29236 case IrInstructionIdImplicitCast:
29237 case IrInstructionIdResolveResult:
29238 case IrInstructionIdOpaqueType:
29239 case IrInstructionIdArgType:
29240 case IrInstructionIdTagType:
29241 case IrInstructionIdErrorReturnTrace:
29242 case IrInstructionIdErrorUnion:
29243 case IrInstructionIdFloatOp:
29244 case IrInstructionIdMulAdd:
29245 case IrInstructionIdAtomicLoad:
29246 case IrInstructionIdIntCast:
29247 case IrInstructionIdFloatCast:
29248 case IrInstructionIdErrSetCast:
29249 case IrInstructionIdIntToFloat:
29250 case IrInstructionIdFloatToInt:
29251 case IrInstructionIdBoolToInt:
29252 case IrInstructionIdFromBytes:
29253 case IrInstructionIdToBytes:
29254 case IrInstructionIdEnumToInt:
29255 case IrInstructionIdArrayToVector:
29256 case IrInstructionIdHasDecl:
29257 case IrInstructionIdAllocaSrc:
29258 case IrInstructionIdAllocaGen:
29259 case IrInstructionIdSpillEnd:
29260 case IrInstructionIdVectorExtractElem:
29899 case IrInstGenIdPhi:
29900 case IrInstGenIdBinOp:
29901 case IrInstGenIdConst:
29902 case IrInstGenIdCast:
29903 case IrInstGenIdElemPtr:
29904 case IrInstGenIdVarPtr:
29905 case IrInstGenIdReturnPtr:
29906 case IrInstGenIdStructFieldPtr:
29907 case IrInstGenIdTestNonNull:
29908 case IrInstGenIdOptionalUnwrapPtr:
29909 case IrInstGenIdClz:
29910 case IrInstGenIdCtz:
29911 case IrInstGenIdPopCount:
29912 case IrInstGenIdBswap:
29913 case IrInstGenIdBitReverse:
29914 case IrInstGenIdUnionTag:
29915 case IrInstGenIdTruncate:
29916 case IrInstGenIdShuffleVector:
29917 case IrInstGenIdSplat:
29918 case IrInstGenIdBoolNot:
29919 case IrInstGenIdReturnAddress:
29920 case IrInstGenIdFrameAddress:
29921 case IrInstGenIdFrameHandle:
29922 case IrInstGenIdFrameSize:
29923 case IrInstGenIdTestErr:
29924 case IrInstGenIdPtrCast:
29925 case IrInstGenIdBitCast:
29926 case IrInstGenIdWidenOrShorten:
29927 case IrInstGenIdPtrToInt:
29928 case IrInstGenIdIntToPtr:
29929 case IrInstGenIdIntToEnum:
29930 case IrInstGenIdIntToErr:
29931 case IrInstGenIdErrToInt:
29932 case IrInstGenIdErrName:
29933 case IrInstGenIdTagName:
29934 case IrInstGenIdFieldParentPtr:
29935 case IrInstGenIdAlignCast:
29936 case IrInstGenIdErrorReturnTrace:
29937 case IrInstGenIdFloatOp:
29938 case IrInstGenIdMulAdd:
29939 case IrInstGenIdAtomicLoad:
29940 case IrInstGenIdArrayToVector:
29941 case IrInstGenIdAlloca:
29942 case IrInstGenIdSpillEnd:
29943 case IrInstGenIdVectorExtractElem:
29944 case IrInstGenIdBinaryNot:
29945 case IrInstGenIdNegation:
29946 case IrInstGenIdNegationWrapping:
2926129947 return false;
2926229948
29263 case IrInstructionIdAsmSrc:
29949 case IrInstGenIdAsm:
2926429950 {
29265 IrInstructionAsmSrc *asm_instruction = (IrInstructionAsmSrc *)instruction;
29951 IrInstGenAsm *asm_instruction = (IrInstGenAsm *)instruction;
2926629952 return asm_instruction->has_side_effects;
2926729953 }
29954 case IrInstGenIdUnwrapErrPayload:
29955 {
29956 IrInstGenUnwrapErrPayload *unwrap_err_payload_instruction =
29957 (IrInstGenUnwrapErrPayload *)instruction;
29958 return unwrap_err_payload_instruction->safety_check_on ||
29959 unwrap_err_payload_instruction->initializing;
29960 }
29961 case IrInstGenIdUnwrapErrCode:
29962 return reinterpret_cast<IrInstGenUnwrapErrCode *>(instruction)->initializing;
29963 case IrInstGenIdUnionFieldPtr:
29964 return reinterpret_cast<IrInstGenUnionFieldPtr *>(instruction)->initializing;
29965 case IrInstGenIdErrWrapPayload:
29966 return reinterpret_cast<IrInstGenErrWrapPayload *>(instruction)->result_loc != nullptr;
29967 case IrInstGenIdErrWrapCode:
29968 return reinterpret_cast<IrInstGenErrWrapCode *>(instruction)->result_loc != nullptr;
29969 case IrInstGenIdLoadPtr:
29970 return reinterpret_cast<IrInstGenLoadPtr *>(instruction)->result_loc != nullptr;
29971 case IrInstGenIdRef:
29972 return reinterpret_cast<IrInstGenRef *>(instruction)->result_loc != nullptr;
29973 }
29974 zig_unreachable();
29975}
29976
29977bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
29978 switch (instruction->id) {
29979 case IrInstSrcIdInvalid:
29980 zig_unreachable();
29981 case IrInstSrcIdBr:
29982 case IrInstSrcIdCondBr:
29983 case IrInstSrcIdSwitchBr:
29984 case IrInstSrcIdDeclVar:
29985 case IrInstSrcIdStorePtr:
29986 case IrInstSrcIdCallExtra:
29987 case IrInstSrcIdCall:
29988 case IrInstSrcIdCallArgs:
29989 case IrInstSrcIdReturn:
29990 case IrInstSrcIdUnreachable:
29991 case IrInstSrcIdSetCold:
29992 case IrInstSrcIdSetRuntimeSafety:
29993 case IrInstSrcIdSetFloatMode:
29994 case IrInstSrcIdImport:
29995 case IrInstSrcIdCompileErr:
29996 case IrInstSrcIdCompileLog:
29997 case IrInstSrcIdCImport:
29998 case IrInstSrcIdCInclude:
29999 case IrInstSrcIdCDefine:
30000 case IrInstSrcIdCUndef:
30001 case IrInstSrcIdFence:
30002 case IrInstSrcIdMemset:
30003 case IrInstSrcIdMemcpy:
30004 case IrInstSrcIdBreakpoint:
30005 case IrInstSrcIdOverflowOp: // TODO when we support multiple returns this can be side effect free
30006 case IrInstSrcIdCheckSwitchProngs:
30007 case IrInstSrcIdCheckStatementIsVoid:
30008 case IrInstSrcIdCheckRuntimeScope:
30009 case IrInstSrcIdPanic:
30010 case IrInstSrcIdSetEvalBranchQuota:
30011 case IrInstSrcIdPtrType:
30012 case IrInstSrcIdSetAlignStack:
30013 case IrInstSrcIdExport:
30014 case IrInstSrcIdSaveErrRetAddr:
30015 case IrInstSrcIdAddImplicitReturnType:
30016 case IrInstSrcIdAtomicRmw:
30017 case IrInstSrcIdAtomicStore:
30018 case IrInstSrcIdCmpxchg:
30019 case IrInstSrcIdUndeclaredIdent:
30020 case IrInstSrcIdEndExpr:
30021 case IrInstSrcIdResetResult:
30022 case IrInstSrcIdSuspendBegin:
30023 case IrInstSrcIdSuspendFinish:
30024 case IrInstSrcIdResume:
30025 case IrInstSrcIdAwait:
30026 case IrInstSrcIdSpillBegin:
30027 return true;
30028
30029 case IrInstSrcIdPhi:
30030 case IrInstSrcIdUnOp:
30031 case IrInstSrcIdBinOp:
30032 case IrInstSrcIdMergeErrSets:
30033 case IrInstSrcIdLoadPtr:
30034 case IrInstSrcIdConst:
30035 case IrInstSrcIdContainerInitList:
30036 case IrInstSrcIdContainerInitFields:
30037 case IrInstSrcIdUnionInitNamedField:
30038 case IrInstSrcIdFieldPtr:
30039 case IrInstSrcIdElemPtr:
30040 case IrInstSrcIdVarPtr:
30041 case IrInstSrcIdTypeOf:
30042 case IrInstSrcIdArrayType:
30043 case IrInstSrcIdSliceType:
30044 case IrInstSrcIdAnyFrameType:
30045 case IrInstSrcIdSizeOf:
30046 case IrInstSrcIdTestNonNull:
30047 case IrInstSrcIdOptionalUnwrapPtr:
30048 case IrInstSrcIdClz:
30049 case IrInstSrcIdCtz:
30050 case IrInstSrcIdPopCount:
30051 case IrInstSrcIdBswap:
30052 case IrInstSrcIdBitReverse:
30053 case IrInstSrcIdSwitchVar:
30054 case IrInstSrcIdSwitchElseVar:
30055 case IrInstSrcIdSwitchTarget:
30056 case IrInstSrcIdRef:
30057 case IrInstSrcIdEmbedFile:
30058 case IrInstSrcIdTruncate:
30059 case IrInstSrcIdIntType:
30060 case IrInstSrcIdVectorType:
30061 case IrInstSrcIdShuffleVector:
30062 case IrInstSrcIdSplat:
30063 case IrInstSrcIdBoolNot:
30064 case IrInstSrcIdSlice:
30065 case IrInstSrcIdMemberCount:
30066 case IrInstSrcIdMemberType:
30067 case IrInstSrcIdMemberName:
30068 case IrInstSrcIdAlignOf:
30069 case IrInstSrcIdReturnAddress:
30070 case IrInstSrcIdFrameAddress:
30071 case IrInstSrcIdFrameHandle:
30072 case IrInstSrcIdFrameType:
30073 case IrInstSrcIdFrameSize:
30074 case IrInstSrcIdTestErr:
30075 case IrInstSrcIdFnProto:
30076 case IrInstSrcIdTestComptime:
30077 case IrInstSrcIdPtrCast:
30078 case IrInstSrcIdBitCast:
30079 case IrInstSrcIdPtrToInt:
30080 case IrInstSrcIdIntToPtr:
30081 case IrInstSrcIdIntToEnum:
30082 case IrInstSrcIdIntToErr:
30083 case IrInstSrcIdErrToInt:
30084 case IrInstSrcIdDeclRef:
30085 case IrInstSrcIdErrName:
30086 case IrInstSrcIdTypeName:
30087 case IrInstSrcIdTagName:
30088 case IrInstSrcIdFieldParentPtr:
30089 case IrInstSrcIdByteOffsetOf:
30090 case IrInstSrcIdBitOffsetOf:
30091 case IrInstSrcIdTypeInfo:
30092 case IrInstSrcIdType:
30093 case IrInstSrcIdHasField:
30094 case IrInstSrcIdTypeId:
30095 case IrInstSrcIdAlignCast:
30096 case IrInstSrcIdImplicitCast:
30097 case IrInstSrcIdResolveResult:
30098 case IrInstSrcIdOpaqueType:
30099 case IrInstSrcIdArgType:
30100 case IrInstSrcIdTagType:
30101 case IrInstSrcIdErrorReturnTrace:
30102 case IrInstSrcIdErrorUnion:
30103 case IrInstSrcIdFloatOp:
30104 case IrInstSrcIdMulAdd:
30105 case IrInstSrcIdAtomicLoad:
30106 case IrInstSrcIdIntCast:
30107 case IrInstSrcIdFloatCast:
30108 case IrInstSrcIdErrSetCast:
30109 case IrInstSrcIdIntToFloat:
30110 case IrInstSrcIdFloatToInt:
30111 case IrInstSrcIdBoolToInt:
30112 case IrInstSrcIdFromBytes:
30113 case IrInstSrcIdToBytes:
30114 case IrInstSrcIdEnumToInt:
30115 case IrInstSrcIdHasDecl:
30116 case IrInstSrcIdAlloca:
30117 case IrInstSrcIdSpillEnd:
30118 return false;
2926830119
29269 case IrInstructionIdAsmGen:
30120 case IrInstSrcIdAsm:
2927030121 {
29271 IrInstructionAsmGen *asm_instruction = (IrInstructionAsmGen *)instruction;
30122 IrInstSrcAsm *asm_instruction = (IrInstSrcAsm *)instruction;
2927230123 return asm_instruction->has_side_effects;
2927330124 }
29274 case IrInstructionIdUnwrapErrPayload:
30125
30126 case IrInstSrcIdUnwrapErrPayload:
2927530127 {
29276 IrInstructionUnwrapErrPayload *unwrap_err_payload_instruction =
29277 (IrInstructionUnwrapErrPayload *)instruction;
30128 IrInstSrcUnwrapErrPayload *unwrap_err_payload_instruction =
30129 (IrInstSrcUnwrapErrPayload *)instruction;
2927830130 return unwrap_err_payload_instruction->safety_check_on ||
2927930131 unwrap_err_payload_instruction->initializing;
2928030132 }
29281 case IrInstructionIdUnwrapErrCode:
29282 return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing;
29283 case IrInstructionIdUnionFieldPtr:
29284 return reinterpret_cast<IrInstructionUnionFieldPtr *>(instruction)->initializing;
29285 case IrInstructionIdErrWrapPayload:
29286 return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr;
29287 case IrInstructionIdErrWrapCode:
29288 return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr;
29289 case IrInstructionIdLoadPtrGen:
29290 return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr;
29291 case IrInstructionIdRefGen:
29292 return reinterpret_cast<IrInstructionRefGen *>(instruction)->result_loc != nullptr;
30133 case IrInstSrcIdUnwrapErrCode:
30134 return reinterpret_cast<IrInstSrcUnwrapErrCode *>(instruction)->initializing;
2929330135 }
2929430136 zig_unreachable();
2929530137}
......@@ -29323,14 +30165,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2932330165 param_info->type = nullptr;
2932430166 return get_generic_fn_type(ira->codegen, &fn_type_id);
2932530167 } else {
29326 IrInstruction *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index];
30168 IrInstGen *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index];
2932730169 ZigType *param_type = ir_resolve_type(ira, param_type_inst);
2932830170 if (type_is_invalid(param_type))
2932930171 return nullptr;
2933030172 switch (type_requires_comptime(ira->codegen, param_type)) {
2933130173 case ReqCompTimeYes:
2933230174 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
29333 ir_add_error(ira, param_type_inst,
30175 ir_add_error(ira, &param_type_inst->base,
2933430176 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
2933530177 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
2933630178 return nullptr;
......@@ -29348,7 +30190,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2934830190 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))
2934930191 return nullptr;
2935030192 if (!has_bits) {
29351 ir_add_error(ira, param_type_inst,
30193 ir_add_error(ira, &param_type_inst->base,
2935230194 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
2935330195 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
2935430196 return nullptr;
......@@ -29367,7 +30209,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2936730209 if (type_is_invalid(fn_type_id.return_type))
2936830210 return nullptr;
2936930211 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
29370 ir_add_error(ira, lazy_fn_type->return_type, buf_create_from_str("return type cannot be opaque"));
30212 ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque"));
2937130213 return nullptr;
2937230214 }
2937330215
......@@ -29399,7 +30241,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2939930241 case ZigTypeIdBoundFn:
2940030242 case ZigTypeIdVoid:
2940130243 case ZigTypeIdOpaque:
29402 ir_add_error(ira, lazy_align_of->target_type,
30244 ir_add_error(ira, &lazy_align_of->target_type->base,
2940330245 buf_sprintf("no align available for type '%s'",
2940430246 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));
2940530247 return ErrorSemanticAnalyzeFail;
......@@ -29449,7 +30291,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2944930291 case ZigTypeIdNull:
2945030292 case ZigTypeIdBoundFn:
2945130293 case ZigTypeIdOpaque:
29452 ir_add_error(ira, lazy_size_of->target_type,
30294 ir_add_error(ira, &lazy_size_of->target_type->base,
2945330295 buf_sprintf("no size available for type '%s'",
2945430296 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));
2945530297 return ErrorSemanticAnalyzeFail;
......@@ -29507,7 +30349,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2950730349 if (lazy_slice_type->sentinel != nullptr) {
2950830350 if (type_is_invalid(lazy_slice_type->sentinel->value->type))
2950930351 return ErrorSemanticAnalyzeFail;
29510 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);
30352 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);
2951130353 if (type_is_invalid(sentinel->value->type))
2951230354 return ErrorSemanticAnalyzeFail;
2951330355 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
......@@ -29530,7 +30372,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2953030372 case ZigTypeIdUndefined:
2953130373 case ZigTypeIdNull:
2953230374 case ZigTypeIdOpaque:
29533 ir_add_error(ira, lazy_slice_type->elem_type,
30375 ir_add_error(ira, &lazy_slice_type->elem_type->base,
2953430376 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));
2953530377 return ErrorSemanticAnalyzeFail;
2953630378 case ZigTypeIdMetaType:
......@@ -29586,7 +30428,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2958630428 if (lazy_ptr_type->sentinel != nullptr) {
2958730429 if (type_is_invalid(lazy_ptr_type->sentinel->value->type))
2958830430 return ErrorSemanticAnalyzeFail;
29589 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);
30431 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);
2959030432 if (type_is_invalid(sentinel->value->type))
2959130433 return ErrorSemanticAnalyzeFail;
2959230434 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
......@@ -29603,11 +30445,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2960330445 }
2960430446
2960530447 if (elem_type->id == ZigTypeIdUnreachable) {
29606 ir_add_error(ira, lazy_ptr_type->elem_type,
30448 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2960730449 buf_create_from_str("pointer to noreturn not allowed"));
2960830450 return ErrorSemanticAnalyzeFail;
2960930451 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {
29610 ir_add_error(ira, lazy_ptr_type->elem_type,
30452 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2961130453 buf_create_from_str("unknown-length pointer to opaque"));
2961230454 return ErrorSemanticAnalyzeFail;
2961330455 } else if (lazy_ptr_type->ptr_len == PtrLenC) {
......@@ -29615,16 +30457,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2961530457 if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type)))
2961630458 return err;
2961730459 if (!ok_type) {
29618 ir_add_error(ira, lazy_ptr_type->elem_type,
30460 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2961930461 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",
2962030462 buf_ptr(&elem_type->name)));
2962130463 return ErrorSemanticAnalyzeFail;
2962230464 } else if (elem_type->id == ZigTypeIdOpaque) {
29623 ir_add_error(ira, lazy_ptr_type->elem_type,
30465 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2962430466 buf_sprintf("C pointers cannot point opaque types"));
2962530467 return ErrorSemanticAnalyzeFail;
2962630468 } else if (lazy_ptr_type->is_allowzero) {
29627 ir_add_error(ira, lazy_ptr_type->elem_type,
30469 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2962830470 buf_sprintf("C pointers always allow address zero"));
2962930471 return ErrorSemanticAnalyzeFail;
2963030472 }
......@@ -29662,7 +30504,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2966230504 case ZigTypeIdUndefined:
2966330505 case ZigTypeIdNull:
2966430506 case ZigTypeIdOpaque:
29665 ir_add_error(ira, lazy_array_type->elem_type,
30507 ir_add_error(ira, &lazy_array_type->elem_type->base,
2966630508 buf_sprintf("array of type '%s' not allowed",
2966730509 buf_ptr(&elem_type->name)));
2966830510 return ErrorSemanticAnalyzeFail;
......@@ -29697,7 +30539,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2969730539 if (lazy_array_type->sentinel != nullptr) {
2969830540 if (type_is_invalid(lazy_array_type->sentinel->value->type))
2969930541 return ErrorSemanticAnalyzeFail;
29700 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type);
30542 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type);
2970130543 if (type_is_invalid(sentinel->value->type))
2970230544 return ErrorSemanticAnalyzeFail;
2970330545 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
......@@ -29721,7 +30563,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2972130563 return ErrorSemanticAnalyzeFail;
2972230564
2972330565 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {
29724 ir_add_error(ira, lazy_opt_type->payload_type,
30566 ir_add_error(ira, &lazy_opt_type->payload_type->base,
2972530567 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));
2972630568 return ErrorSemanticAnalyzeFail;
2972730569 }
......@@ -29763,7 +30605,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2976330605 return ErrorSemanticAnalyzeFail;
2976430606
2976530607 if (err_set_type->id != ZigTypeIdErrorSet) {
29766 ir_add_error(ira, lazy_err_union_type->err_set_type,
30608 ir_add_error(ira, &lazy_err_union_type->err_set_type->base,
2976730609 buf_sprintf("expected error set type, found type '%s'",
2976830610 buf_ptr(&err_set_type->name)));
2976930611 return ErrorSemanticAnalyzeFail;
......@@ -29799,8 +30641,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
2979930641 return ErrorNone;
2980030642}
2980130643
29802void IrInstruction::src() {
29803 IrInstruction *inst = this;
30644void IrInst::src() {
30645 IrInst *inst = this;
2980430646 if (inst->source_node != nullptr) {
2980530647 inst->source_node->src();
2980630648 } else {
......@@ -29808,26 +30650,45 @@ void IrInstruction::src() {
2980830650 }
2980930651}
2981030652
29811void IrInstruction::dump() {
29812 IrInstruction *inst = this;
30653void IrInst::dump() {
30654 this->src();
30655 fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id);
30656}
30657
30658void IrInstSrc::src() {
30659 this->base.src();
30660}
30661
30662void IrInstGen::src() {
30663 this->base.src();
30664}
30665
30666void IrInstSrc::dump() {
30667 IrInstSrc *inst = this;
2981330668 inst->src();
29814 IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc;
29815 if (inst->scope == nullptr) {
30669 if (inst->base.scope == nullptr) {
2981630670 fprintf(stderr, "(null scope)\n");
2981730671 } else {
29818 ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass);
29819 if (pass == IrPassSrc) {
29820 fprintf(stderr, "-> ");
29821 ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen);
29822 }
30672 ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0);
30673 fprintf(stderr, "-> ");
30674 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0);
30675 }
30676}
30677void IrInstGen::dump() {
30678 IrInstGen *inst = this;
30679 inst->src();
30680 if (inst->base.scope == nullptr) {
30681 fprintf(stderr, "(null scope)\n");
30682 } else {
30683 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0);
2982330684 }
2982430685}
2982530686
2982630687void IrAnalyze::dump() {
29827 ir_print(this->codegen, stderr, this->new_irb.exec, 0, IrPassGen);
30688 ir_print_gen(this->codegen, stderr, this->new_irb.exec, 0);
2982830689 if (this->new_irb.current_basic_block != nullptr) {
2982930690 fprintf(stderr, "Current basic block:\n");
29830 ir_print_basic_block(this->codegen, stderr, this->new_irb.current_basic_block, 1, IrPassGen);
30691 ir_print_basic_block_gen(this->codegen, stderr, this->new_irb.current_basic_block, 1);
2983130692 }
2983230693}
2983330694
src/ir.hpp+10-10
......@@ -10,33 +10,33 @@
1010
1111#include "all_types.hpp"
1212
13enum IrPass {
14 IrPassSrc,
15 IrPassGen,
16};
17
18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
13bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable);
1914bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
2015
16IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
17 ZigType *var_type, const char *name_hint);
18
2119ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
2220 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
2321 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
24 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
22 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
2523
2624Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);
2725
28ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
26ZigType *ir_analyze(CodeGen *g, IrExecutableSrc *old_executable, IrExecutableGen *new_executable,
2927 ZigType *expected_type, AstNode *expected_type_source_node);
3028
31bool ir_has_side_effects(IrInstruction *instruction);
29bool ir_inst_gen_has_side_effects(IrInstGen *inst);
30bool ir_inst_src_has_side_effects(IrInstSrc *inst);
3231
3332struct IrAnalyze;
3433ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
3534 AstNode *source_node);
36const char *float_op_to_name(BuiltinFnId op);
3735
3836// for debugging purposes
3937void dbg_ir_break(const char *src_file, uint32_t line);
4038void dbg_ir_clear(void);
4139
40void destroy_instruction_gen(IrInstGen *inst);
41
4242#endif
src/ir_print.cpp+1998-1281
......@@ -10,19 +10,35 @@
1010#include "ir_print.hpp"
1111#include "os.hpp"
1212
13static uint32_t hash_instruction_ptr(IrInstruction* instruction) {
13static uint32_t hash_inst_src_ptr(IrInstSrc* instruction) {
1414 return (uint32_t)(uintptr_t)instruction;
1515}
1616
17static bool instruction_ptr_equal(IrInstruction* a, IrInstruction* b) {
17static uint32_t hash_inst_gen_ptr(IrInstGen* instruction) {
18 return (uint32_t)(uintptr_t)instruction;
19}
20
21static bool inst_src_ptr_eql(IrInstSrc* a, IrInstSrc* b) {
1822 return a == b;
1923}
2024
21using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, instruction_ptr_equal>;
22using InstructionList = ZigList<IrInstruction*>;
25static bool inst_gen_ptr_eql(IrInstGen* a, IrInstGen* b) {
26 return a == b;
27}
28
29using InstSetSrc = HashMap<IrInstSrc*, uint8_t, hash_inst_src_ptr, inst_src_ptr_eql>;
30using InstSetGen = HashMap<IrInstGen*, uint8_t, hash_inst_gen_ptr, inst_gen_ptr_eql>;
31using InstListSrc = ZigList<IrInstSrc*>;
32using InstListGen = ZigList<IrInstGen*>;
33
34struct IrPrintSrc {
35 CodeGen *codegen;
36 FILE *f;
37 int indent;
38 int indent_size;
39};
2340
24struct IrPrint {
25 IrPass pass;
41struct IrPrintGen {
2642 CodeGen *codegen;
2743 FILE *f;
2844 int indent;
......@@ -32,417 +48,590 @@ struct IrPrint {
3248 // present in the instruction list. Thus we track which instructions
3349 // are printed (per executable) and after each pass 2 instruction those
3450 // var instructions are rendered in a trailing fashion.
35 InstructionSet printed;
36 InstructionList pending;
51 InstSetGen printed;
52 InstListGen pending;
3753};
3854
39static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction);
55static void ir_print_other_inst_src(IrPrintSrc *irp, IrInstSrc *inst);
56static void ir_print_other_inst_gen(IrPrintGen *irp, IrInstGen *inst);
4057
41const char* ir_instruction_type_str(IrInstructionId id) {
58const char* ir_inst_src_type_str(IrInstSrcId id) {
4259 switch (id) {
43 case IrInstructionIdInvalid:
44 return "Invalid";
45 case IrInstructionIdShuffleVector:
46 return "Shuffle";
47 case IrInstructionIdSplatSrc:
48 return "SplatSrc";
49 case IrInstructionIdSplatGen:
50 return "SplatGen";
51 case IrInstructionIdDeclVarSrc:
52 return "DeclVarSrc";
53 case IrInstructionIdDeclVarGen:
54 return "DeclVarGen";
55 case IrInstructionIdBr:
56 return "Br";
57 case IrInstructionIdCondBr:
58 return "CondBr";
59 case IrInstructionIdSwitchBr:
60 return "SwitchBr";
61 case IrInstructionIdSwitchVar:
62 return "SwitchVar";
63 case IrInstructionIdSwitchElseVar:
64 return "SwitchElseVar";
65 case IrInstructionIdSwitchTarget:
66 return "SwitchTarget";
67 case IrInstructionIdPhi:
68 return "Phi";
69 case IrInstructionIdUnOp:
70 return "UnOp";
71 case IrInstructionIdBinOp:
72 return "BinOp";
73 case IrInstructionIdMergeErrSets:
74 return "MergeErrSets";
75 case IrInstructionIdLoadPtr:
76 return "LoadPtr";
77 case IrInstructionIdLoadPtrGen:
78 return "LoadPtrGen";
79 case IrInstructionIdStorePtr:
80 return "StorePtr";
81 case IrInstructionIdVectorStoreElem:
82 return "VectorStoreElem";
83 case IrInstructionIdFieldPtr:
84 return "FieldPtr";
85 case IrInstructionIdStructFieldPtr:
86 return "StructFieldPtr";
87 case IrInstructionIdUnionFieldPtr:
88 return "UnionFieldPtr";
89 case IrInstructionIdElemPtr:
90 return "ElemPtr";
91 case IrInstructionIdVarPtr:
92 return "VarPtr";
93 case IrInstructionIdReturnPtr:
94 return "ReturnPtr";
95 case IrInstructionIdCallExtra:
96 return "CallExtra";
97 case IrInstructionIdCallSrc:
98 return "CallSrc";
99 case IrInstructionIdCallSrcArgs:
100 return "CallSrcArgs";
101 case IrInstructionIdCallGen:
102 return "CallGen";
103 case IrInstructionIdConst:
104 return "Const";
105 case IrInstructionIdReturn:
106 return "Return";
107 case IrInstructionIdCast:
108 return "Cast";
109 case IrInstructionIdResizeSlice:
110 return "ResizeSlice";
111 case IrInstructionIdContainerInitList:
112 return "ContainerInitList";
113 case IrInstructionIdContainerInitFields:
114 return "ContainerInitFields";
115 case IrInstructionIdUnreachable:
116 return "Unreachable";
117 case IrInstructionIdTypeOf:
118 return "TypeOf";
119 case IrInstructionIdSetCold:
120 return "SetCold";
121 case IrInstructionIdSetRuntimeSafety:
122 return "SetRuntimeSafety";
123 case IrInstructionIdSetFloatMode:
124 return "SetFloatMode";
125 case IrInstructionIdArrayType:
126 return "ArrayType";
127 case IrInstructionIdAnyFrameType:
128 return "AnyFrameType";
129 case IrInstructionIdSliceType:
130 return "SliceType";
131 case IrInstructionIdAsmSrc:
132 return "AsmSrc";
133 case IrInstructionIdAsmGen:
134 return "AsmGen";
135 case IrInstructionIdSizeOf:
136 return "SizeOf";
137 case IrInstructionIdTestNonNull:
138 return "TestNonNull";
139 case IrInstructionIdOptionalUnwrapPtr:
140 return "OptionalUnwrapPtr";
141 case IrInstructionIdOptionalWrap:
142 return "OptionalWrap";
143 case IrInstructionIdUnionTag:
144 return "UnionTag";
145 case IrInstructionIdClz:
146 return "Clz";
147 case IrInstructionIdCtz:
148 return "Ctz";
149 case IrInstructionIdPopCount:
150 return "PopCount";
151 case IrInstructionIdBswap:
152 return "Bswap";
153 case IrInstructionIdBitReverse:
154 return "BitReverse";
155 case IrInstructionIdImport:
156 return "Import";
157 case IrInstructionIdCImport:
158 return "CImport";
159 case IrInstructionIdCInclude:
160 return "CInclude";
161 case IrInstructionIdCDefine:
162 return "CDefine";
163 case IrInstructionIdCUndef:
164 return "CUndef";
165 case IrInstructionIdRef:
166 return "Ref";
167 case IrInstructionIdRefGen:
168 return "RefGen";
169 case IrInstructionIdCompileErr:
170 return "CompileErr";
171 case IrInstructionIdCompileLog:
172 return "CompileLog";
173 case IrInstructionIdErrName:
174 return "ErrName";
175 case IrInstructionIdEmbedFile:
176 return "EmbedFile";
177 case IrInstructionIdCmpxchgSrc:
178 return "CmpxchgSrc";
179 case IrInstructionIdCmpxchgGen:
180 return "CmpxchgGen";
181 case IrInstructionIdFence:
182 return "Fence";
183 case IrInstructionIdTruncate:
184 return "Truncate";
185 case IrInstructionIdIntCast:
186 return "IntCast";
187 case IrInstructionIdFloatCast:
188 return "FloatCast";
189 case IrInstructionIdIntToFloat:
190 return "IntToFloat";
191 case IrInstructionIdFloatToInt:
192 return "FloatToInt";
193 case IrInstructionIdBoolToInt:
194 return "BoolToInt";
195 case IrInstructionIdIntType:
196 return "IntType";
197 case IrInstructionIdVectorType:
198 return "VectorType";
199 case IrInstructionIdBoolNot:
200 return "BoolNot";
201 case IrInstructionIdMemset:
202 return "Memset";
203 case IrInstructionIdMemcpy:
204 return "Memcpy";
205 case IrInstructionIdSliceSrc:
206 return "SliceSrc";
207 case IrInstructionIdSliceGen:
208 return "SliceGen";
209 case IrInstructionIdMemberCount:
210 return "MemberCount";
211 case IrInstructionIdMemberType:
212 return "MemberType";
213 case IrInstructionIdMemberName:
214 return "MemberName";
215 case IrInstructionIdBreakpoint:
216 return "Breakpoint";
217 case IrInstructionIdReturnAddress:
218 return "ReturnAddress";
219 case IrInstructionIdFrameAddress:
220 return "FrameAddress";
221 case IrInstructionIdFrameHandle:
222 return "FrameHandle";
223 case IrInstructionIdFrameType:
224 return "FrameType";
225 case IrInstructionIdFrameSizeSrc:
226 return "FrameSizeSrc";
227 case IrInstructionIdFrameSizeGen:
228 return "FrameSizeGen";
229 case IrInstructionIdAlignOf:
230 return "AlignOf";
231 case IrInstructionIdOverflowOp:
232 return "OverflowOp";
233 case IrInstructionIdTestErrSrc:
234 return "TestErrSrc";
235 case IrInstructionIdTestErrGen:
236 return "TestErrGen";
237 case IrInstructionIdMulAdd:
238 return "MulAdd";
239 case IrInstructionIdFloatOp:
240 return "FloatOp";
241 case IrInstructionIdUnwrapErrCode:
242 return "UnwrapErrCode";
243 case IrInstructionIdUnwrapErrPayload:
244 return "UnwrapErrPayload";
245 case IrInstructionIdErrWrapCode:
246 return "ErrWrapCode";
247 case IrInstructionIdErrWrapPayload:
248 return "ErrWrapPayload";
249 case IrInstructionIdFnProto:
250 return "FnProto";
251 case IrInstructionIdTestComptime:
252 return "TestComptime";
253 case IrInstructionIdPtrCastSrc:
254 return "PtrCastSrc";
255 case IrInstructionIdPtrCastGen:
256 return "PtrCastGen";
257 case IrInstructionIdBitCastSrc:
258 return "BitCastSrc";
259 case IrInstructionIdBitCastGen:
260 return "BitCastGen";
261 case IrInstructionIdWidenOrShorten:
262 return "WidenOrShorten";
263 case IrInstructionIdIntToPtr:
264 return "IntToPtr";
265 case IrInstructionIdPtrToInt:
266 return "PtrToInt";
267 case IrInstructionIdIntToEnum:
268 return "IntToEnum";
269 case IrInstructionIdEnumToInt:
270 return "EnumToInt";
271 case IrInstructionIdIntToErr:
272 return "IntToErr";
273 case IrInstructionIdErrToInt:
274 return "ErrToInt";
275 case IrInstructionIdCheckSwitchProngs:
276 return "CheckSwitchProngs";
277 case IrInstructionIdCheckStatementIsVoid:
278 return "CheckStatementIsVoid";
279 case IrInstructionIdTypeName:
280 return "TypeName";
281 case IrInstructionIdDeclRef:
282 return "DeclRef";
283 case IrInstructionIdPanic:
284 return "Panic";
285 case IrInstructionIdTagName:
286 return "TagName";
287 case IrInstructionIdTagType:
288 return "TagType";
289 case IrInstructionIdFieldParentPtr:
290 return "FieldParentPtr";
291 case IrInstructionIdByteOffsetOf:
292 return "ByteOffsetOf";
293 case IrInstructionIdBitOffsetOf:
294 return "BitOffsetOf";
295 case IrInstructionIdTypeInfo:
296 return "TypeInfo";
297 case IrInstructionIdType:
298 return "Type";
299 case IrInstructionIdHasField:
300 return "HasField";
301 case IrInstructionIdTypeId:
302 return "TypeId";
303 case IrInstructionIdSetEvalBranchQuota:
304 return "SetEvalBranchQuota";
305 case IrInstructionIdPtrType:
306 return "PtrType";
307 case IrInstructionIdAlignCast:
308 return "AlignCast";
309 case IrInstructionIdImplicitCast:
310 return "ImplicitCast";
311 case IrInstructionIdResolveResult:
312 return "ResolveResult";
313 case IrInstructionIdResetResult:
314 return "ResetResult";
315 case IrInstructionIdOpaqueType:
316 return "OpaqueType";
317 case IrInstructionIdSetAlignStack:
318 return "SetAlignStack";
319 case IrInstructionIdArgType:
320 return "ArgType";
321 case IrInstructionIdExport:
322 return "Export";
323 case IrInstructionIdErrorReturnTrace:
324 return "ErrorReturnTrace";
325 case IrInstructionIdErrorUnion:
326 return "ErrorUnion";
327 case IrInstructionIdAtomicRmw:
328 return "AtomicRmw";
329 case IrInstructionIdAtomicLoad:
330 return "AtomicLoad";
331 case IrInstructionIdAtomicStore:
332 return "AtomicStore";
333 case IrInstructionIdSaveErrRetAddr:
334 return "SaveErrRetAddr";
335 case IrInstructionIdAddImplicitReturnType:
336 return "AddImplicitReturnType";
337 case IrInstructionIdErrSetCast:
338 return "ErrSetCast";
339 case IrInstructionIdToBytes:
340 return "ToBytes";
341 case IrInstructionIdFromBytes:
342 return "FromBytes";
343 case IrInstructionIdCheckRuntimeScope:
344 return "CheckRuntimeScope";
345 case IrInstructionIdVectorToArray:
346 return "VectorToArray";
347 case IrInstructionIdArrayToVector:
348 return "ArrayToVector";
349 case IrInstructionIdAssertZero:
350 return "AssertZero";
351 case IrInstructionIdAssertNonNull:
352 return "AssertNonNull";
353 case IrInstructionIdHasDecl:
354 return "HasDecl";
355 case IrInstructionIdUndeclaredIdent:
356 return "UndeclaredIdent";
357 case IrInstructionIdAllocaSrc:
358 return "AllocaSrc";
359 case IrInstructionIdAllocaGen:
360 return "AllocaGen";
361 case IrInstructionIdEndExpr:
362 return "EndExpr";
363 case IrInstructionIdPtrOfArrayToSlice:
364 return "PtrOfArrayToSlice";
365 case IrInstructionIdUnionInitNamedField:
366 return "UnionInitNamedField";
367 case IrInstructionIdSuspendBegin:
368 return "SuspendBegin";
369 case IrInstructionIdSuspendFinish:
370 return "SuspendFinish";
371 case IrInstructionIdAwaitSrc:
372 return "AwaitSrc";
373 case IrInstructionIdAwaitGen:
374 return "AwaitGen";
375 case IrInstructionIdResume:
376 return "Resume";
377 case IrInstructionIdSpillBegin:
378 return "SpillBegin";
379 case IrInstructionIdSpillEnd:
380 return "SpillEnd";
381 case IrInstructionIdVectorExtractElem:
382 return "VectorExtractElem";
60 case IrInstSrcIdInvalid:
61 return "SrcInvalid";
62 case IrInstSrcIdShuffleVector:
63 return "SrcShuffle";
64 case IrInstSrcIdSplat:
65 return "SrcSplat";
66 case IrInstSrcIdDeclVar:
67 return "SrcDeclVar";
68 case IrInstSrcIdBr:
69 return "SrcBr";
70 case IrInstSrcIdCondBr:
71 return "SrcCondBr";
72 case IrInstSrcIdSwitchBr:
73 return "SrcSwitchBr";
74 case IrInstSrcIdSwitchVar:
75 return "SrcSwitchVar";
76 case IrInstSrcIdSwitchElseVar:
77 return "SrcSwitchElseVar";
78 case IrInstSrcIdSwitchTarget:
79 return "SrcSwitchTarget";
80 case IrInstSrcIdPhi:
81 return "SrcPhi";
82 case IrInstSrcIdUnOp:
83 return "SrcUnOp";
84 case IrInstSrcIdBinOp:
85 return "SrcBinOp";
86 case IrInstSrcIdMergeErrSets:
87 return "SrcMergeErrSets";
88 case IrInstSrcIdLoadPtr:
89 return "SrcLoadPtr";
90 case IrInstSrcIdStorePtr:
91 return "SrcStorePtr";
92 case IrInstSrcIdFieldPtr:
93 return "SrcFieldPtr";
94 case IrInstSrcIdElemPtr:
95 return "SrcElemPtr";
96 case IrInstSrcIdVarPtr:
97 return "SrcVarPtr";
98 case IrInstSrcIdCallExtra:
99 return "SrcCallExtra";
100 case IrInstSrcIdCall:
101 return "SrcCall";
102 case IrInstSrcIdCallArgs:
103 return "SrcCallArgs";
104 case IrInstSrcIdConst:
105 return "SrcConst";
106 case IrInstSrcIdReturn:
107 return "SrcReturn";
108 case IrInstSrcIdContainerInitList:
109 return "SrcContainerInitList";
110 case IrInstSrcIdContainerInitFields:
111 return "SrcContainerInitFields";
112 case IrInstSrcIdUnreachable:
113 return "SrcUnreachable";
114 case IrInstSrcIdTypeOf:
115 return "SrcTypeOf";
116 case IrInstSrcIdSetCold:
117 return "SrcSetCold";
118 case IrInstSrcIdSetRuntimeSafety:
119 return "SrcSetRuntimeSafety";
120 case IrInstSrcIdSetFloatMode:
121 return "SrcSetFloatMode";
122 case IrInstSrcIdArrayType:
123 return "SrcArrayType";
124 case IrInstSrcIdAnyFrameType:
125 return "SrcAnyFrameType";
126 case IrInstSrcIdSliceType:
127 return "SrcSliceType";
128 case IrInstSrcIdAsm:
129 return "SrcAsm";
130 case IrInstSrcIdSizeOf:
131 return "SrcSizeOf";
132 case IrInstSrcIdTestNonNull:
133 return "SrcTestNonNull";
134 case IrInstSrcIdOptionalUnwrapPtr:
135 return "SrcOptionalUnwrapPtr";
136 case IrInstSrcIdClz:
137 return "SrcClz";
138 case IrInstSrcIdCtz:
139 return "SrcCtz";
140 case IrInstSrcIdPopCount:
141 return "SrcPopCount";
142 case IrInstSrcIdBswap:
143 return "SrcBswap";
144 case IrInstSrcIdBitReverse:
145 return "SrcBitReverse";
146 case IrInstSrcIdImport:
147 return "SrcImport";
148 case IrInstSrcIdCImport:
149 return "SrcCImport";
150 case IrInstSrcIdCInclude:
151 return "SrcCInclude";
152 case IrInstSrcIdCDefine:
153 return "SrcCDefine";
154 case IrInstSrcIdCUndef:
155 return "SrcCUndef";
156 case IrInstSrcIdRef:
157 return "SrcRef";
158 case IrInstSrcIdCompileErr:
159 return "SrcCompileErr";
160 case IrInstSrcIdCompileLog:
161 return "SrcCompileLog";
162 case IrInstSrcIdErrName:
163 return "SrcErrName";
164 case IrInstSrcIdEmbedFile:
165 return "SrcEmbedFile";
166 case IrInstSrcIdCmpxchg:
167 return "SrcCmpxchg";
168 case IrInstSrcIdFence:
169 return "SrcFence";
170 case IrInstSrcIdTruncate:
171 return "SrcTruncate";
172 case IrInstSrcIdIntCast:
173 return "SrcIntCast";
174 case IrInstSrcIdFloatCast:
175 return "SrcFloatCast";
176 case IrInstSrcIdIntToFloat:
177 return "SrcIntToFloat";
178 case IrInstSrcIdFloatToInt:
179 return "SrcFloatToInt";
180 case IrInstSrcIdBoolToInt:
181 return "SrcBoolToInt";
182 case IrInstSrcIdIntType:
183 return "SrcIntType";
184 case IrInstSrcIdVectorType:
185 return "SrcVectorType";
186 case IrInstSrcIdBoolNot:
187 return "SrcBoolNot";
188 case IrInstSrcIdMemset:
189 return "SrcMemset";
190 case IrInstSrcIdMemcpy:
191 return "SrcMemcpy";
192 case IrInstSrcIdSlice:
193 return "SrcSlice";
194 case IrInstSrcIdMemberCount:
195 return "SrcMemberCount";
196 case IrInstSrcIdMemberType:
197 return "SrcMemberType";
198 case IrInstSrcIdMemberName:
199 return "SrcMemberName";
200 case IrInstSrcIdBreakpoint:
201 return "SrcBreakpoint";
202 case IrInstSrcIdReturnAddress:
203 return "SrcReturnAddress";
204 case IrInstSrcIdFrameAddress:
205 return "SrcFrameAddress";
206 case IrInstSrcIdFrameHandle:
207 return "SrcFrameHandle";
208 case IrInstSrcIdFrameType:
209 return "SrcFrameType";
210 case IrInstSrcIdFrameSize:
211 return "SrcFrameSize";
212 case IrInstSrcIdAlignOf:
213 return "SrcAlignOf";
214 case IrInstSrcIdOverflowOp:
215 return "SrcOverflowOp";
216 case IrInstSrcIdTestErr:
217 return "SrcTestErr";
218 case IrInstSrcIdMulAdd:
219 return "SrcMulAdd";
220 case IrInstSrcIdFloatOp:
221 return "SrcFloatOp";
222 case IrInstSrcIdUnwrapErrCode:
223 return "SrcUnwrapErrCode";
224 case IrInstSrcIdUnwrapErrPayload:
225 return "SrcUnwrapErrPayload";
226 case IrInstSrcIdFnProto:
227 return "SrcFnProto";
228 case IrInstSrcIdTestComptime:
229 return "SrcTestComptime";
230 case IrInstSrcIdPtrCast:
231 return "SrcPtrCast";
232 case IrInstSrcIdBitCast:
233 return "SrcBitCast";
234 case IrInstSrcIdIntToPtr:
235 return "SrcIntToPtr";
236 case IrInstSrcIdPtrToInt:
237 return "SrcPtrToInt";
238 case IrInstSrcIdIntToEnum:
239 return "SrcIntToEnum";
240 case IrInstSrcIdEnumToInt:
241 return "SrcEnumToInt";
242 case IrInstSrcIdIntToErr:
243 return "SrcIntToErr";
244 case IrInstSrcIdErrToInt:
245 return "SrcErrToInt";
246 case IrInstSrcIdCheckSwitchProngs:
247 return "SrcCheckSwitchProngs";
248 case IrInstSrcIdCheckStatementIsVoid:
249 return "SrcCheckStatementIsVoid";
250 case IrInstSrcIdTypeName:
251 return "SrcTypeName";
252 case IrInstSrcIdDeclRef:
253 return "SrcDeclRef";
254 case IrInstSrcIdPanic:
255 return "SrcPanic";
256 case IrInstSrcIdTagName:
257 return "SrcTagName";
258 case IrInstSrcIdTagType:
259 return "SrcTagType";
260 case IrInstSrcIdFieldParentPtr:
261 return "SrcFieldParentPtr";
262 case IrInstSrcIdByteOffsetOf:
263 return "SrcByteOffsetOf";
264 case IrInstSrcIdBitOffsetOf:
265 return "SrcBitOffsetOf";
266 case IrInstSrcIdTypeInfo:
267 return "SrcTypeInfo";
268 case IrInstSrcIdType:
269 return "SrcType";
270 case IrInstSrcIdHasField:
271 return "SrcHasField";
272 case IrInstSrcIdTypeId:
273 return "SrcTypeId";
274 case IrInstSrcIdSetEvalBranchQuota:
275 return "SrcSetEvalBranchQuota";
276 case IrInstSrcIdPtrType:
277 return "SrcPtrType";
278 case IrInstSrcIdAlignCast:
279 return "SrcAlignCast";
280 case IrInstSrcIdImplicitCast:
281 return "SrcImplicitCast";
282 case IrInstSrcIdResolveResult:
283 return "SrcResolveResult";
284 case IrInstSrcIdResetResult:
285 return "SrcResetResult";
286 case IrInstSrcIdOpaqueType:
287 return "SrcOpaqueType";
288 case IrInstSrcIdSetAlignStack:
289 return "SrcSetAlignStack";
290 case IrInstSrcIdArgType:
291 return "SrcArgType";
292 case IrInstSrcIdExport:
293 return "SrcExport";
294 case IrInstSrcIdErrorReturnTrace:
295 return "SrcErrorReturnTrace";
296 case IrInstSrcIdErrorUnion:
297 return "SrcErrorUnion";
298 case IrInstSrcIdAtomicRmw:
299 return "SrcAtomicRmw";
300 case IrInstSrcIdAtomicLoad:
301 return "SrcAtomicLoad";
302 case IrInstSrcIdAtomicStore:
303 return "SrcAtomicStore";
304 case IrInstSrcIdSaveErrRetAddr:
305 return "SrcSaveErrRetAddr";
306 case IrInstSrcIdAddImplicitReturnType:
307 return "SrcAddImplicitReturnType";
308 case IrInstSrcIdErrSetCast:
309 return "SrcErrSetCast";
310 case IrInstSrcIdToBytes:
311 return "SrcToBytes";
312 case IrInstSrcIdFromBytes:
313 return "SrcFromBytes";
314 case IrInstSrcIdCheckRuntimeScope:
315 return "SrcCheckRuntimeScope";
316 case IrInstSrcIdHasDecl:
317 return "SrcHasDecl";
318 case IrInstSrcIdUndeclaredIdent:
319 return "SrcUndeclaredIdent";
320 case IrInstSrcIdAlloca:
321 return "SrcAlloca";
322 case IrInstSrcIdEndExpr:
323 return "SrcEndExpr";
324 case IrInstSrcIdUnionInitNamedField:
325 return "SrcUnionInitNamedField";
326 case IrInstSrcIdSuspendBegin:
327 return "SrcSuspendBegin";
328 case IrInstSrcIdSuspendFinish:
329 return "SrcSuspendFinish";
330 case IrInstSrcIdAwait:
331 return "SrcAwaitSr";
332 case IrInstSrcIdResume:
333 return "SrcResume";
334 case IrInstSrcIdSpillBegin:
335 return "SrcSpillBegin";
336 case IrInstSrcIdSpillEnd:
337 return "SrcSpillEnd";
383338 }
384339 zig_unreachable();
385340}
386341
387static void ir_print_indent(IrPrint *irp) {
342const char* ir_inst_gen_type_str(IrInstGenId id) {
343 switch (id) {
344 case IrInstGenIdInvalid:
345 return "GenInvalid";
346 case IrInstGenIdShuffleVector:
347 return "GenShuffle";
348 case IrInstGenIdSplat:
349 return "GenSplat";
350 case IrInstGenIdDeclVar:
351 return "GenDeclVar";
352 case IrInstGenIdBr:
353 return "GenBr";
354 case IrInstGenIdCondBr:
355 return "GenCondBr";
356 case IrInstGenIdSwitchBr:
357 return "GenSwitchBr";
358 case IrInstGenIdPhi:
359 return "GenPhi";
360 case IrInstGenIdBinOp:
361 return "GenBinOp";
362 case IrInstGenIdLoadPtr:
363 return "GenLoadPtr";
364 case IrInstGenIdStorePtr:
365 return "GenStorePtr";
366 case IrInstGenIdVectorStoreElem:
367 return "GenVectorStoreElem";
368 case IrInstGenIdStructFieldPtr:
369 return "GenStructFieldPtr";
370 case IrInstGenIdUnionFieldPtr:
371 return "GenUnionFieldPtr";
372 case IrInstGenIdElemPtr:
373 return "GenElemPtr";
374 case IrInstGenIdVarPtr:
375 return "GenVarPtr";
376 case IrInstGenIdReturnPtr:
377 return "GenReturnPtr";
378 case IrInstGenIdCall:
379 return "GenCall";
380 case IrInstGenIdConst:
381 return "GenConst";
382 case IrInstGenIdReturn:
383 return "GenReturn";
384 case IrInstGenIdCast:
385 return "GenCast";
386 case IrInstGenIdResizeSlice:
387 return "GenResizeSlice";
388 case IrInstGenIdUnreachable:
389 return "GenUnreachable";
390 case IrInstGenIdAsm:
391 return "GenAsm";
392 case IrInstGenIdTestNonNull:
393 return "GenTestNonNull";
394 case IrInstGenIdOptionalUnwrapPtr:
395 return "GenOptionalUnwrapPtr";
396 case IrInstGenIdOptionalWrap:
397 return "GenOptionalWrap";
398 case IrInstGenIdUnionTag:
399 return "GenUnionTag";
400 case IrInstGenIdClz:
401 return "GenClz";
402 case IrInstGenIdCtz:
403 return "GenCtz";
404 case IrInstGenIdPopCount:
405 return "GenPopCount";
406 case IrInstGenIdBswap:
407 return "GenBswap";
408 case IrInstGenIdBitReverse:
409 return "GenBitReverse";
410 case IrInstGenIdRef:
411 return "GenRef";
412 case IrInstGenIdErrName:
413 return "GenErrName";
414 case IrInstGenIdCmpxchg:
415 return "GenCmpxchg";
416 case IrInstGenIdFence:
417 return "GenFence";
418 case IrInstGenIdTruncate:
419 return "GenTruncate";
420 case IrInstGenIdBoolNot:
421 return "GenBoolNot";
422 case IrInstGenIdMemset:
423 return "GenMemset";
424 case IrInstGenIdMemcpy:
425 return "GenMemcpy";
426 case IrInstGenIdSlice:
427 return "GenSlice";
428 case IrInstGenIdBreakpoint:
429 return "GenBreakpoint";
430 case IrInstGenIdReturnAddress:
431 return "GenReturnAddress";
432 case IrInstGenIdFrameAddress:
433 return "GenFrameAddress";
434 case IrInstGenIdFrameHandle:
435 return "GenFrameHandle";
436 case IrInstGenIdFrameSize:
437 return "GenFrameSize";
438 case IrInstGenIdOverflowOp:
439 return "GenOverflowOp";
440 case IrInstGenIdTestErr:
441 return "GenTestErr";
442 case IrInstGenIdMulAdd:
443 return "GenMulAdd";
444 case IrInstGenIdFloatOp:
445 return "GenFloatOp";
446 case IrInstGenIdUnwrapErrCode:
447 return "GenUnwrapErrCode";
448 case IrInstGenIdUnwrapErrPayload:
449 return "GenUnwrapErrPayload";
450 case IrInstGenIdErrWrapCode:
451 return "GenErrWrapCode";
452 case IrInstGenIdErrWrapPayload:
453 return "GenErrWrapPayload";
454 case IrInstGenIdPtrCast:
455 return "GenPtrCast";
456 case IrInstGenIdBitCast:
457 return "GenBitCast";
458 case IrInstGenIdWidenOrShorten:
459 return "GenWidenOrShorten";
460 case IrInstGenIdIntToPtr:
461 return "GenIntToPtr";
462 case IrInstGenIdPtrToInt:
463 return "GenPtrToInt";
464 case IrInstGenIdIntToEnum:
465 return "GenIntToEnum";
466 case IrInstGenIdIntToErr:
467 return "GenIntToErr";
468 case IrInstGenIdErrToInt:
469 return "GenErrToInt";
470 case IrInstGenIdPanic:
471 return "GenPanic";
472 case IrInstGenIdTagName:
473 return "GenTagName";
474 case IrInstGenIdFieldParentPtr:
475 return "GenFieldParentPtr";
476 case IrInstGenIdAlignCast:
477 return "GenAlignCast";
478 case IrInstGenIdErrorReturnTrace:
479 return "GenErrorReturnTrace";
480 case IrInstGenIdAtomicRmw:
481 return "GenAtomicRmw";
482 case IrInstGenIdAtomicLoad:
483 return "GenAtomicLoad";
484 case IrInstGenIdAtomicStore:
485 return "GenAtomicStore";
486 case IrInstGenIdSaveErrRetAddr:
487 return "GenSaveErrRetAddr";
488 case IrInstGenIdVectorToArray:
489 return "GenVectorToArray";
490 case IrInstGenIdArrayToVector:
491 return "GenArrayToVector";
492 case IrInstGenIdAssertZero:
493 return "GenAssertZero";
494 case IrInstGenIdAssertNonNull:
495 return "GenAssertNonNull";
496 case IrInstGenIdAlloca:
497 return "GenAlloca";
498 case IrInstGenIdPtrOfArrayToSlice:
499 return "GenPtrOfArrayToSlice";
500 case IrInstGenIdSuspendBegin:
501 return "GenSuspendBegin";
502 case IrInstGenIdSuspendFinish:
503 return "GenSuspendFinish";
504 case IrInstGenIdAwait:
505 return "GenAwait";
506 case IrInstGenIdResume:
507 return "GenResume";
508 case IrInstGenIdSpillBegin:
509 return "GenSpillBegin";
510 case IrInstGenIdSpillEnd:
511 return "GenSpillEnd";
512 case IrInstGenIdVectorExtractElem:
513 return "GenVectorExtractElem";
514 case IrInstGenIdBinaryNot:
515 return "GenBinaryNot";
516 case IrInstGenIdNegation:
517 return "GenNegation";
518 case IrInstGenIdNegationWrapping:
519 return "GenNegationWrapping";
520 }
521 zig_unreachable();
522}
523
524static void ir_print_indent_src(IrPrintSrc *irp) {
388525 for (int i = 0; i < irp->indent; i += 1) {
389526 fprintf(irp->f, " ");
390527 }
391528}
392529
393static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {
394 ir_print_indent(irp);
530static void ir_print_indent_gen(IrPrintGen *irp) {
531 for (int i = 0; i < irp->indent; i += 1) {
532 fprintf(irp->f, " ");
533 }
534}
535
536static void ir_print_prefix_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trailing) {
537 ir_print_indent_src(irp);
538 const char mark = trailing ? ':' : '#';
539 const char *type_name;
540 if (instruction->id == IrInstSrcIdConst) {
541 type_name = buf_ptr(&reinterpret_cast<IrInstSrcConst *>(instruction)->value->type->name);
542 } else if (instruction->is_noreturn) {
543 type_name = "noreturn";
544 } else {
545 type_name = "(unknown)";
546 }
547 const char *ref_count = ir_inst_src_has_side_effects(instruction) ?
548 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
549 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
550 ir_inst_src_type_str(instruction->id), type_name, ref_count);
551}
552
553static void ir_print_prefix_gen(IrPrintGen *irp, IrInstGen *instruction, bool trailing) {
554 ir_print_indent_gen(irp);
395555 const char mark = trailing ? ':' : '#';
396556 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";
397 const char *ref_count = ir_has_side_effects(instruction) ?
398 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
399 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
400 ir_instruction_type_str(instruction->id), type_name, ref_count);
557 const char *ref_count = ir_inst_gen_has_side_effects(instruction) ?
558 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
559 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
560 ir_inst_gen_type_str(instruction->id), type_name, ref_count);
401561}
402562
403static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) {
404 Buf buf = BUF_INIT;
405 buf_resize(&buf, 0);
406 render_const_value(irp->codegen, &buf, const_val);
407 fprintf(irp->f, "%s", buf_ptr(&buf));
563static void ir_print_var_src(IrPrintSrc *irp, IrInstSrc *inst) {
564 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
408565}
409566
410static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
411 fprintf(irp->f, "#%" PRIu32 "", instruction->debug_id);
412 if (irp->pass != IrPassSrc && irp->printed.maybe_get(instruction) == nullptr) {
413 irp->printed.put(instruction, 0);
414 irp->pending.append(instruction);
567static void ir_print_var_gen(IrPrintGen *irp, IrInstGen *inst) {
568 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
569 if (irp->printed.maybe_get(inst) == nullptr) {
570 irp->printed.put(inst, 0);
571 irp->pending.append(inst);
415572 }
416573}
417574
418static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {
419 if (instruction == nullptr) {
575static void ir_print_other_inst_src(IrPrintSrc *irp, IrInstSrc *inst) {
576 if (inst == nullptr) {
420577 fprintf(irp->f, "(null)");
421578 return;
422579 }
580 ir_print_var_src(irp, inst);
581}
582
583static void ir_print_const_value(CodeGen *g, FILE *f, ZigValue *const_val) {
584 Buf buf = BUF_INIT;
585 buf_resize(&buf, 0);
586 render_const_value(g, &buf, const_val);
587 fprintf(f, "%s", buf_ptr(&buf));
588}
589
590static void ir_print_other_inst_gen(IrPrintGen *irp, IrInstGen *inst) {
591 if (inst == nullptr) {
592 fprintf(irp->f, "(null)");
593 return;
594 }
595
596 if (inst->value->special != ConstValSpecialRuntime) {
597 ir_print_const_value(irp->codegen, irp->f, inst->value);
598 } else {
599 ir_print_var_gen(irp, inst);
600 }
601}
423602
424 if (instruction->value->special != ConstValSpecialRuntime) {
425 ir_print_const_value(irp, instruction->value);
603static void ir_print_other_block(IrPrintSrc *irp, IrBasicBlockSrc *bb) {
604 if (bb == nullptr) {
605 fprintf(irp->f, "(null block)");
426606 } else {
427 ir_print_var_instruction(irp, instruction);
607 fprintf(irp->f, "$%s_%" PRIu32 "", bb->name_hint, bb->debug_id);
428608 }
429609}
430610
431static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) {
611static void ir_print_other_block_gen(IrPrintGen *irp, IrBasicBlockGen *bb) {
432612 if (bb == nullptr) {
433613 fprintf(irp->f, "(null block)");
434614 } else {
435 fprintf(irp->f, "$%s_%" ZIG_PRI_usize "", bb->name_hint, bb->debug_id);
615 fprintf(irp->f, "$%s_%" PRIu32 "", bb->name_hint, bb->debug_id);
436616 }
437617}
438618
439static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {
619static void ir_print_return_src(IrPrintSrc *irp, IrInstSrcReturn *inst) {
440620 fprintf(irp->f, "return ");
441 ir_print_other_instruction(irp, instruction->operand);
621 ir_print_other_inst_src(irp, inst->operand);
442622}
443623
444static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {
445 ir_print_const_value(irp, const_instruction->base.value);
624static void ir_print_return_gen(IrPrintGen *irp, IrInstGenReturn *inst) {
625 fprintf(irp->f, "return ");
626 ir_print_other_inst_gen(irp, inst->operand);
627}
628
629static void ir_print_const(IrPrintSrc *irp, IrInstSrcConst *const_instruction) {
630 ir_print_const_value(irp->codegen, irp->f, const_instruction->value);
631}
632
633static void ir_print_const(IrPrintGen *irp, IrInstGenConst *const_instruction) {
634 ir_print_const_value(irp->codegen, irp->f, const_instruction->base.value);
446635}
447636
448637static const char *ir_bin_op_id_str(IrBinOp op_id) {
......@@ -531,89 +720,111 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
531720 zig_unreachable();
532721}
533722
534static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {
535 fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));
536 ir_print_other_instruction(irp, un_op_instruction->value);
723static void ir_print_un_op(IrPrintSrc *irp, IrInstSrcUnOp *inst) {
724 fprintf(irp->f, "%s ", ir_un_op_id_str(inst->op_id));
725 ir_print_other_inst_src(irp, inst->value);
726}
727
728static void ir_print_bin_op(IrPrintSrc *irp, IrInstSrcBinOp *bin_op_instruction) {
729 ir_print_other_inst_src(irp, bin_op_instruction->op1);
730 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
731 ir_print_other_inst_src(irp, bin_op_instruction->op2);
732 if (!bin_op_instruction->safety_check_on) {
733 fprintf(irp->f, " // no safety");
734 }
537735}
538736
539static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction) {
540 ir_print_other_instruction(irp, bin_op_instruction->op1);
737static void ir_print_bin_op(IrPrintGen *irp, IrInstGenBinOp *bin_op_instruction) {
738 ir_print_other_inst_gen(irp, bin_op_instruction->op1);
541739 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
542 ir_print_other_instruction(irp, bin_op_instruction->op2);
740 ir_print_other_inst_gen(irp, bin_op_instruction->op2);
543741 if (!bin_op_instruction->safety_check_on) {
544742 fprintf(irp->f, " // no safety");
545743 }
546744}
547745
548static void ir_print_merge_err_sets(IrPrint *irp, IrInstructionMergeErrSets *instruction) {
549 ir_print_other_instruction(irp, instruction->op1);
746static void ir_print_merge_err_sets(IrPrintSrc *irp, IrInstSrcMergeErrSets *instruction) {
747 ir_print_other_inst_src(irp, instruction->op1);
550748 fprintf(irp->f, " || ");
551 ir_print_other_instruction(irp, instruction->op2);
749 ir_print_other_inst_src(irp, instruction->op2);
552750 if (instruction->type_name != nullptr) {
553751 fprintf(irp->f, " // name=%s", buf_ptr(instruction->type_name));
554752 }
555753}
556754
557static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_var_instruction) {
755static void ir_print_decl_var_src(IrPrintSrc *irp, IrInstSrcDeclVar *decl_var_instruction) {
558756 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
559757 const char *name = decl_var_instruction->var->name;
560758 if (decl_var_instruction->var_type) {
561759 fprintf(irp->f, "%s %s: ", var_or_const, name);
562 ir_print_other_instruction(irp, decl_var_instruction->var_type);
760 ir_print_other_inst_src(irp, decl_var_instruction->var_type);
563761 fprintf(irp->f, " ");
564762 } else {
565763 fprintf(irp->f, "%s %s ", var_or_const, name);
566764 }
567765 if (decl_var_instruction->align_value) {
568766 fprintf(irp->f, "align ");
569 ir_print_other_instruction(irp, decl_var_instruction->align_value);
767 ir_print_other_inst_src(irp, decl_var_instruction->align_value);
570768 fprintf(irp->f, " ");
571769 }
572770 fprintf(irp->f, "= ");
573 ir_print_other_instruction(irp, decl_var_instruction->ptr);
771 ir_print_other_inst_src(irp, decl_var_instruction->ptr);
574772 if (decl_var_instruction->var->is_comptime != nullptr) {
575773 fprintf(irp->f, " // comptime = ");
576 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
774 ir_print_other_inst_src(irp, decl_var_instruction->var->is_comptime);
577775 }
578776}
579777
580static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {
581 fprintf(irp->f, "cast ");
582 ir_print_other_instruction(irp, cast_instruction->value);
583 fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));
778static const char *cast_op_str(CastOp op) {
779 switch (op) {
780 case CastOpNoCast: return "NoCast";
781 case CastOpNoop: return "NoOp";
782 case CastOpIntToFloat: return "IntToFloat";
783 case CastOpFloatToInt: return "FloatToInt";
784 case CastOpBoolToInt: return "BoolToInt";
785 case CastOpNumLitToConcrete: return "NumLitToConcrate";
786 case CastOpErrSet: return "ErrSet";
787 case CastOpBitCast: return "BitCast";
788 }
789 zig_unreachable();
790}
791
792static void ir_print_cast(IrPrintGen *irp, IrInstGenCast *cast_instruction) {
793 fprintf(irp->f, "%s cast ", cast_op_str(cast_instruction->cast_op));
794 ir_print_other_inst_gen(irp, cast_instruction->value);
584795}
585796
586static void ir_print_result_loc_var(IrPrint *irp, ResultLocVar *result_loc_var) {
797static void ir_print_result_loc_var(IrPrintSrc *irp, ResultLocVar *result_loc_var) {
587798 fprintf(irp->f, "var(");
588 ir_print_other_instruction(irp, result_loc_var->base.source_instruction);
799 ir_print_other_inst_src(irp, result_loc_var->base.source_instruction);
589800 fprintf(irp->f, ")");
590801}
591802
592static void ir_print_result_loc_instruction(IrPrint *irp, ResultLocInstruction *result_loc_inst) {
803static void ir_print_result_loc_instruction(IrPrintSrc *irp, ResultLocInstruction *result_loc_inst) {
593804 fprintf(irp->f, "inst(");
594 ir_print_other_instruction(irp, result_loc_inst->base.source_instruction);
805 ir_print_other_inst_src(irp, result_loc_inst->base.source_instruction);
595806 fprintf(irp->f, ")");
596807}
597808
598static void ir_print_result_loc_peer(IrPrint *irp, ResultLocPeer *result_loc_peer) {
809static void ir_print_result_loc_peer(IrPrintSrc *irp, ResultLocPeer *result_loc_peer) {
599810 fprintf(irp->f, "peer(next=");
600811 ir_print_other_block(irp, result_loc_peer->next_bb);
601812 fprintf(irp->f, ")");
602813}
603814
604static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_loc_bit_cast) {
815static void ir_print_result_loc_bit_cast(IrPrintSrc *irp, ResultLocBitCast *result_loc_bit_cast) {
605816 fprintf(irp->f, "bitcast(ty=");
606 ir_print_other_instruction(irp, result_loc_bit_cast->base.source_instruction);
817 ir_print_other_inst_src(irp, result_loc_bit_cast->base.source_instruction);
607818 fprintf(irp->f, ")");
608819}
609820
610static void ir_print_result_loc_cast(IrPrint *irp, ResultLocCast *result_loc_cast) {
821static void ir_print_result_loc_cast(IrPrintSrc *irp, ResultLocCast *result_loc_cast) {
611822 fprintf(irp->f, "cast(ty=");
612 ir_print_other_instruction(irp, result_loc_cast->base.source_instruction);
823 ir_print_other_inst_src(irp, result_loc_cast->base.source_instruction);
613824 fprintf(irp->f, ")");
614825}
615826
616static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
827static void ir_print_result_loc(IrPrintSrc *irp, ResultLoc *result_loc) {
617828 switch (result_loc->id) {
618829 case ResultLocIdInvalid:
619830 zig_unreachable();
......@@ -640,34 +851,34 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
640851 zig_unreachable();
641852}
642853
643static void ir_print_call_extra(IrPrint *irp, IrInstructionCallExtra *instruction) {
854static void ir_print_call_extra(IrPrintSrc *irp, IrInstSrcCallExtra *instruction) {
644855 fprintf(irp->f, "opts=");
645 ir_print_other_instruction(irp, instruction->options);
856 ir_print_other_inst_src(irp, instruction->options);
646857 fprintf(irp->f, ", fn=");
647 ir_print_other_instruction(irp, instruction->fn_ref);
858 ir_print_other_inst_src(irp, instruction->fn_ref);
648859 fprintf(irp->f, ", args=");
649 ir_print_other_instruction(irp, instruction->args);
860 ir_print_other_inst_src(irp, instruction->args);
650861 fprintf(irp->f, ", result=");
651862 ir_print_result_loc(irp, instruction->result_loc);
652863}
653864
654static void ir_print_call_src_args(IrPrint *irp, IrInstructionCallSrcArgs *instruction) {
865static void ir_print_call_args(IrPrintSrc *irp, IrInstSrcCallArgs *instruction) {
655866 fprintf(irp->f, "opts=");
656 ir_print_other_instruction(irp, instruction->options);
867 ir_print_other_inst_src(irp, instruction->options);
657868 fprintf(irp->f, ", fn=");
658 ir_print_other_instruction(irp, instruction->fn_ref);
869 ir_print_other_inst_src(irp, instruction->fn_ref);
659870 fprintf(irp->f, ", args=(");
660871 for (size_t i = 0; i < instruction->args_len; i += 1) {
661 IrInstruction *arg = instruction->args_ptr[i];
872 IrInstSrc *arg = instruction->args_ptr[i];
662873 if (i != 0)
663874 fprintf(irp->f, ", ");
664 ir_print_other_instruction(irp, arg);
875 ir_print_other_inst_src(irp, arg);
665876 }
666877 fprintf(irp->f, "), result=");
667878 ir_print_result_loc(irp, instruction->result_loc);
668879}
669880
670static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {
881static void ir_print_call_src(IrPrintSrc *irp, IrInstSrcCall *call_instruction) {
671882 switch (call_instruction->modifier) {
672883 case CallModifierNone:
673884 break;
......@@ -699,20 +910,20 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi
699910 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
700911 } else {
701912 assert(call_instruction->fn_ref);
702 ir_print_other_instruction(irp, call_instruction->fn_ref);
913 ir_print_other_inst_src(irp, call_instruction->fn_ref);
703914 }
704915 fprintf(irp->f, "(");
705916 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
706 IrInstruction *arg = call_instruction->args[i];
917 IrInstSrc *arg = call_instruction->args[i];
707918 if (i != 0)
708919 fprintf(irp->f, ", ");
709 ir_print_other_instruction(irp, arg);
920 ir_print_other_inst_src(irp, arg);
710921 }
711922 fprintf(irp->f, ")result=");
712923 ir_print_result_loc(irp, call_instruction->result_loc);
713924}
714925
715static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {
926static void ir_print_call_gen(IrPrintGen *irp, IrInstGenCall *call_instruction) {
716927 switch (call_instruction->modifier) {
717928 case CallModifierNone:
718929 break;
......@@ -744,221 +955,291 @@ static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instructi
744955 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
745956 } else {
746957 assert(call_instruction->fn_ref);
747 ir_print_other_instruction(irp, call_instruction->fn_ref);
958 ir_print_other_inst_gen(irp, call_instruction->fn_ref);
748959 }
749960 fprintf(irp->f, "(");
750961 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
751 IrInstruction *arg = call_instruction->args[i];
962 IrInstGen *arg = call_instruction->args[i];
752963 if (i != 0)
753964 fprintf(irp->f, ", ");
754 ir_print_other_instruction(irp, arg);
965 ir_print_other_inst_gen(irp, arg);
755966 }
756967 fprintf(irp->f, ")result=");
757 ir_print_other_instruction(irp, call_instruction->result_loc);
968 ir_print_other_inst_gen(irp, call_instruction->result_loc);
758969}
759970
760static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {
971static void ir_print_cond_br(IrPrintSrc *irp, IrInstSrcCondBr *inst) {
761972 fprintf(irp->f, "if (");
762 ir_print_other_instruction(irp, cond_br_instruction->condition);
973 ir_print_other_inst_src(irp, inst->condition);
763974 fprintf(irp->f, ") ");
764 ir_print_other_block(irp, cond_br_instruction->then_block);
975 ir_print_other_block(irp, inst->then_block);
765976 fprintf(irp->f, " else ");
766 ir_print_other_block(irp, cond_br_instruction->else_block);
767 if (cond_br_instruction->is_comptime != nullptr) {
977 ir_print_other_block(irp, inst->else_block);
978 if (inst->is_comptime != nullptr) {
768979 fprintf(irp->f, " // comptime = ");
769 ir_print_other_instruction(irp, cond_br_instruction->is_comptime);
980 ir_print_other_inst_src(irp, inst->is_comptime);
770981 }
771982}
772983
773static void ir_print_br(IrPrint *irp, IrInstructionBr *br_instruction) {
984static void ir_print_cond_br(IrPrintGen *irp, IrInstGenCondBr *inst) {
985 fprintf(irp->f, "if (");
986 ir_print_other_inst_gen(irp, inst->condition);
987 fprintf(irp->f, ") ");
988 ir_print_other_block_gen(irp, inst->then_block);
989 fprintf(irp->f, " else ");
990 ir_print_other_block_gen(irp, inst->else_block);
991}
992
993static void ir_print_br(IrPrintSrc *irp, IrInstSrcBr *br_instruction) {
774994 fprintf(irp->f, "goto ");
775995 ir_print_other_block(irp, br_instruction->dest_block);
776996 if (br_instruction->is_comptime != nullptr) {
777997 fprintf(irp->f, " // comptime = ");
778 ir_print_other_instruction(irp, br_instruction->is_comptime);
998 ir_print_other_inst_src(irp, br_instruction->is_comptime);
779999 }
7801000}
7811001
782static void ir_print_phi(IrPrint *irp, IrInstructionPhi *phi_instruction) {
1002static void ir_print_br(IrPrintGen *irp, IrInstGenBr *inst) {
1003 fprintf(irp->f, "goto ");
1004 ir_print_other_block_gen(irp, inst->dest_block);
1005}
1006
1007static void ir_print_phi(IrPrintSrc *irp, IrInstSrcPhi *phi_instruction) {
7831008 assert(phi_instruction->incoming_count != 0);
7841009 assert(phi_instruction->incoming_count != SIZE_MAX);
7851010 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
786 IrBasicBlock *incoming_block = phi_instruction->incoming_blocks[i];
787 IrInstruction *incoming_value = phi_instruction->incoming_values[i];
1011 IrBasicBlockSrc *incoming_block = phi_instruction->incoming_blocks[i];
1012 IrInstSrc *incoming_value = phi_instruction->incoming_values[i];
7881013 if (i != 0)
7891014 fprintf(irp->f, " ");
7901015 ir_print_other_block(irp, incoming_block);
7911016 fprintf(irp->f, ":");
792 ir_print_other_instruction(irp, incoming_value);
1017 ir_print_other_inst_src(irp, incoming_value);
7931018 }
7941019}
7951020
796static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerInitList *instruction) {
1021static void ir_print_phi(IrPrintGen *irp, IrInstGenPhi *phi_instruction) {
1022 assert(phi_instruction->incoming_count != 0);
1023 assert(phi_instruction->incoming_count != SIZE_MAX);
1024 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
1025 IrBasicBlockGen *incoming_block = phi_instruction->incoming_blocks[i];
1026 IrInstGen *incoming_value = phi_instruction->incoming_values[i];
1027 if (i != 0)
1028 fprintf(irp->f, " ");
1029 ir_print_other_block_gen(irp, incoming_block);
1030 fprintf(irp->f, ":");
1031 ir_print_other_inst_gen(irp, incoming_value);
1032 }
1033}
1034
1035static void ir_print_container_init_list(IrPrintSrc *irp, IrInstSrcContainerInitList *instruction) {
7971036 fprintf(irp->f, "{");
7981037 if (instruction->item_count > 50) {
7991038 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);
8001039 } else {
8011040 for (size_t i = 0; i < instruction->item_count; i += 1) {
802 IrInstruction *result_loc = instruction->elem_result_loc_list[i];
1041 IrInstSrc *result_loc = instruction->elem_result_loc_list[i];
8031042 if (i != 0)
8041043 fprintf(irp->f, ", ");
805 ir_print_other_instruction(irp, result_loc);
1044 ir_print_other_inst_src(irp, result_loc);
8061045 }
8071046 }
8081047 fprintf(irp->f, "}result=");
809 ir_print_other_instruction(irp, instruction->result_loc);
1048 ir_print_other_inst_src(irp, instruction->result_loc);
8101049}
8111050
812static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerInitFields *instruction) {
1051static void ir_print_container_init_fields(IrPrintSrc *irp, IrInstSrcContainerInitFields *instruction) {
8131052 fprintf(irp->f, "{");
8141053 for (size_t i = 0; i < instruction->field_count; i += 1) {
815 IrInstructionContainerInitFieldsField *field = &instruction->fields[i];
1054 IrInstSrcContainerInitFieldsField *field = &instruction->fields[i];
8161055 const char *comma = (i == 0) ? "" : ", ";
8171056 fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));
818 ir_print_other_instruction(irp, field->result_loc);
1057 ir_print_other_inst_src(irp, field->result_loc);
8191058 }
8201059 fprintf(irp->f, "}result=");
821 ir_print_other_instruction(irp, instruction->result_loc);
1060 ir_print_other_inst_src(irp, instruction->result_loc);
1061}
1062
1063static void ir_print_unreachable(IrPrintSrc *irp, IrInstSrcUnreachable *instruction) {
1064 fprintf(irp->f, "unreachable");
8221065}
8231066
824static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {
1067static void ir_print_unreachable(IrPrintGen *irp, IrInstGenUnreachable *instruction) {
8251068 fprintf(irp->f, "unreachable");
8261069}
8271070
828static void ir_print_elem_ptr(IrPrint *irp, IrInstructionElemPtr *instruction) {
1071static void ir_print_elem_ptr(IrPrintSrc *irp, IrInstSrcElemPtr *instruction) {
8291072 fprintf(irp->f, "&");
830 ir_print_other_instruction(irp, instruction->array_ptr);
1073 ir_print_other_inst_src(irp, instruction->array_ptr);
8311074 fprintf(irp->f, "[");
832 ir_print_other_instruction(irp, instruction->elem_index);
1075 ir_print_other_inst_src(irp, instruction->elem_index);
8331076 fprintf(irp->f, "]");
8341077 if (!instruction->safety_check_on) {
8351078 fprintf(irp->f, " // no safety");
8361079 }
8371080}
8381081
839static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {
1082static void ir_print_elem_ptr(IrPrintGen *irp, IrInstGenElemPtr *instruction) {
1083 fprintf(irp->f, "&");
1084 ir_print_other_inst_gen(irp, instruction->array_ptr);
1085 fprintf(irp->f, "[");
1086 ir_print_other_inst_gen(irp, instruction->elem_index);
1087 fprintf(irp->f, "]");
1088 if (!instruction->safety_check_on) {
1089 fprintf(irp->f, " // no safety");
1090 }
1091}
1092
1093static void ir_print_var_ptr(IrPrintSrc *irp, IrInstSrcVarPtr *instruction) {
1094 fprintf(irp->f, "&%s", instruction->var->name);
1095}
1096
1097static void ir_print_var_ptr(IrPrintGen *irp, IrInstGenVarPtr *instruction) {
8401098 fprintf(irp->f, "&%s", instruction->var->name);
8411099}
8421100
843static void ir_print_return_ptr(IrPrint *irp, IrInstructionReturnPtr *instruction) {
1101static void ir_print_return_ptr(IrPrintGen *irp, IrInstGenReturnPtr *instruction) {
8441102 fprintf(irp->f, "@ReturnPtr");
8451103}
8461104
847static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {
848 ir_print_other_instruction(irp, instruction->ptr);
1105static void ir_print_load_ptr(IrPrintSrc *irp, IrInstSrcLoadPtr *instruction) {
1106 ir_print_other_inst_src(irp, instruction->ptr);
8491107 fprintf(irp->f, ".*");
8501108}
8511109
852static void ir_print_load_ptr_gen(IrPrint *irp, IrInstructionLoadPtrGen *instruction) {
1110static void ir_print_load_ptr_gen(IrPrintGen *irp, IrInstGenLoadPtr *instruction) {
8531111 fprintf(irp->f, "loadptr(");
854 ir_print_other_instruction(irp, instruction->ptr);
1112 ir_print_other_inst_gen(irp, instruction->ptr);
8551113 fprintf(irp->f, ")result=");
856 ir_print_other_instruction(irp, instruction->result_loc);
1114 ir_print_other_inst_gen(irp, instruction->result_loc);
1115}
1116
1117static void ir_print_store_ptr(IrPrintSrc *irp, IrInstSrcStorePtr *instruction) {
1118 fprintf(irp->f, "*");
1119 ir_print_var_src(irp, instruction->ptr);
1120 fprintf(irp->f, " = ");
1121 ir_print_other_inst_src(irp, instruction->value);
8571122}
8581123
859static void ir_print_store_ptr(IrPrint *irp, IrInstructionStorePtr *instruction) {
1124static void ir_print_store_ptr(IrPrintGen *irp, IrInstGenStorePtr *instruction) {
8601125 fprintf(irp->f, "*");
861 ir_print_var_instruction(irp, instruction->ptr);
1126 ir_print_var_gen(irp, instruction->ptr);
8621127 fprintf(irp->f, " = ");
863 ir_print_other_instruction(irp, instruction->value);
1128 ir_print_other_inst_gen(irp, instruction->value);
8641129}
8651130
866static void ir_print_vector_store_elem(IrPrint *irp, IrInstructionVectorStoreElem *instruction) {
1131static void ir_print_vector_store_elem(IrPrintGen *irp, IrInstGenVectorStoreElem *instruction) {
8671132 fprintf(irp->f, "vector_ptr=");
868 ir_print_var_instruction(irp, instruction->vector_ptr);
1133 ir_print_var_gen(irp, instruction->vector_ptr);
8691134 fprintf(irp->f, ",index=");
870 ir_print_var_instruction(irp, instruction->index);
1135 ir_print_var_gen(irp, instruction->index);
8711136 fprintf(irp->f, ",value=");
872 ir_print_other_instruction(irp, instruction->value);
1137 ir_print_other_inst_gen(irp, instruction->value);
8731138}
8741139
875static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {
1140static void ir_print_typeof(IrPrintSrc *irp, IrInstSrcTypeOf *instruction) {
8761141 fprintf(irp->f, "@TypeOf(");
877 ir_print_other_instruction(irp, instruction->value);
1142 ir_print_other_inst_src(irp, instruction->value);
8781143 fprintf(irp->f, ")");
8791144}
8801145
881static void ir_print_field_ptr(IrPrint *irp, IrInstructionFieldPtr *instruction) {
1146static void ir_print_binary_not(IrPrintGen *irp, IrInstGenBinaryNot *instruction) {
1147 fprintf(irp->f, "~");
1148 ir_print_other_inst_gen(irp, instruction->operand);
1149}
1150
1151static void ir_print_negation(IrPrintGen *irp, IrInstGenNegation *instruction) {
1152 fprintf(irp->f, "-");
1153 ir_print_other_inst_gen(irp, instruction->operand);
1154}
1155
1156static void ir_print_negation_wrapping(IrPrintGen *irp, IrInstGenNegationWrapping *instruction) {
1157 fprintf(irp->f, "-%%");
1158 ir_print_other_inst_gen(irp, instruction->operand);
1159}
1160
1161
1162static void ir_print_field_ptr(IrPrintSrc *irp, IrInstSrcFieldPtr *instruction) {
8821163 if (instruction->field_name_buffer) {
8831164 fprintf(irp->f, "fieldptr ");
884 ir_print_other_instruction(irp, instruction->container_ptr);
1165 ir_print_other_inst_src(irp, instruction->container_ptr);
8851166 fprintf(irp->f, ".%s", buf_ptr(instruction->field_name_buffer));
8861167 } else {
8871168 assert(instruction->field_name_expr);
8881169 fprintf(irp->f, "@field(");
889 ir_print_other_instruction(irp, instruction->container_ptr);
1170 ir_print_other_inst_src(irp, instruction->container_ptr);
8901171 fprintf(irp->f, ", ");
891 ir_print_other_instruction(irp, instruction->field_name_expr);
1172 ir_print_other_inst_src(irp, instruction->field_name_expr);
8921173 fprintf(irp->f, ")");
8931174 }
8941175}
8951176
896static void ir_print_struct_field_ptr(IrPrint *irp, IrInstructionStructFieldPtr *instruction) {
1177static void ir_print_struct_field_ptr(IrPrintGen *irp, IrInstGenStructFieldPtr *instruction) {
8971178 fprintf(irp->f, "@StructFieldPtr(&");
898 ir_print_other_instruction(irp, instruction->struct_ptr);
1179 ir_print_other_inst_gen(irp, instruction->struct_ptr);
8991180 fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));
9001181 fprintf(irp->f, ")");
9011182}
9021183
903static void ir_print_union_field_ptr(IrPrint *irp, IrInstructionUnionFieldPtr *instruction) {
1184static void ir_print_union_field_ptr(IrPrintGen *irp, IrInstGenUnionFieldPtr *instruction) {
9041185 fprintf(irp->f, "@UnionFieldPtr(&");
905 ir_print_other_instruction(irp, instruction->union_ptr);
1186 ir_print_other_inst_gen(irp, instruction->union_ptr);
9061187 fprintf(irp->f, ".%s", buf_ptr(instruction->field->enum_field->name));
9071188 fprintf(irp->f, ")");
9081189}
9091190
910static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {
1191static void ir_print_set_cold(IrPrintSrc *irp, IrInstSrcSetCold *instruction) {
9111192 fprintf(irp->f, "@setCold(");
912 ir_print_other_instruction(irp, instruction->is_cold);
1193 ir_print_other_inst_src(irp, instruction->is_cold);
9131194 fprintf(irp->f, ")");
9141195}
9151196
916static void ir_print_set_runtime_safety(IrPrint *irp, IrInstructionSetRuntimeSafety *instruction) {
1197static void ir_print_set_runtime_safety(IrPrintSrc *irp, IrInstSrcSetRuntimeSafety *instruction) {
9171198 fprintf(irp->f, "@setRuntimeSafety(");
918 ir_print_other_instruction(irp, instruction->safety_on);
1199 ir_print_other_inst_src(irp, instruction->safety_on);
9191200 fprintf(irp->f, ")");
9201201}
9211202
922static void ir_print_set_float_mode(IrPrint *irp, IrInstructionSetFloatMode *instruction) {
1203static void ir_print_set_float_mode(IrPrintSrc *irp, IrInstSrcSetFloatMode *instruction) {
9231204 fprintf(irp->f, "@setFloatMode(");
924 ir_print_other_instruction(irp, instruction->scope_value);
1205 ir_print_other_inst_src(irp, instruction->scope_value);
9251206 fprintf(irp->f, ", ");
926 ir_print_other_instruction(irp, instruction->mode_value);
1207 ir_print_other_inst_src(irp, instruction->mode_value);
9271208 fprintf(irp->f, ")");
9281209}
9291210
930static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instruction) {
1211static void ir_print_array_type(IrPrintSrc *irp, IrInstSrcArrayType *instruction) {
9311212 fprintf(irp->f, "[");
932 ir_print_other_instruction(irp, instruction->size);
1213 ir_print_other_inst_src(irp, instruction->size);
9331214 if (instruction->sentinel != nullptr) {
9341215 fprintf(irp->f, ":");
935 ir_print_other_instruction(irp, instruction->sentinel);
1216 ir_print_other_inst_src(irp, instruction->sentinel);
9361217 }
9371218 fprintf(irp->f, "]");
938 ir_print_other_instruction(irp, instruction->child_type);
1219 ir_print_other_inst_src(irp, instruction->child_type);
9391220}
9401221
941static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {
1222static void ir_print_slice_type(IrPrintSrc *irp, IrInstSrcSliceType *instruction) {
9421223 const char *const_kw = instruction->is_const ? "const " : "";
9431224 fprintf(irp->f, "[]%s", const_kw);
944 ir_print_other_instruction(irp, instruction->child_type);
1225 ir_print_other_inst_src(irp, instruction->child_type);
9451226}
9461227
947static void ir_print_any_frame_type(IrPrint *irp, IrInstructionAnyFrameType *instruction) {
1228static void ir_print_any_frame_type(IrPrintSrc *irp, IrInstSrcAnyFrameType *instruction) {
9481229 if (instruction->payload_type == nullptr) {
9491230 fprintf(irp->f, "anyframe");
9501231 } else {
9511232 fprintf(irp->f, "anyframe->");
952 ir_print_other_instruction(irp, instruction->payload_type);
1233 ir_print_other_inst_src(irp, instruction->payload_type);
9531234 }
9541235}
9551236
956static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
957 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
958 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
1237static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
1238 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1239 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
9591240 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
9601241 fprintf(irp->f, "asm%s (", volatile_kw);
961 ir_print_other_instruction(irp, instruction->asm_template);
1242 ir_print_other_inst_src(irp, instruction->asm_template);
9621243
9631244 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
9641245 AsmOutput *asm_output = asm_expr->output_list.at(i);
......@@ -969,7 +1250,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
9691250 buf_ptr(asm_output->constraint));
9701251 if (asm_output->return_type) {
9711252 fprintf(irp->f, "-> ");
972 ir_print_other_instruction(irp, instruction->output_types[i]);
1253 ir_print_other_inst_src(irp, instruction->output_types[i]);
9731254 } else {
9741255 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
9751256 }
......@@ -984,7 +1265,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
9841265 fprintf(irp->f, "[%s] \"%s\" (",
9851266 buf_ptr(asm_input->asm_symbolic_name),
9861267 buf_ptr(asm_input->constraint));
987 ir_print_other_instruction(irp, instruction->input_list[i]);
1268 ir_print_other_inst_src(irp, instruction->input_list[i]);
9881269 fprintf(irp->f, ")");
9891270 }
9901271 fprintf(irp->f, " : ");
......@@ -996,9 +1277,9 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
9961277 fprintf(irp->f, ")");
9971278}
9981279
999static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1000 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
1001 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
1280static void ir_print_asm_gen(IrPrintGen *irp, IrInstGenAsm *instruction) {
1281 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1282 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
10021283 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
10031284 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));
10041285
......@@ -1011,7 +1292,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
10111292 buf_ptr(asm_output->constraint));
10121293 if (asm_output->return_type) {
10131294 fprintf(irp->f, "-> ");
1014 ir_print_other_instruction(irp, instruction->output_types[i]);
1295 ir_print_other_inst_gen(irp, instruction->output_types[i]);
10151296 } else {
10161297 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
10171298 }
......@@ -1026,7 +1307,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
10261307 fprintf(irp->f, "[%s] \"%s\" (",
10271308 buf_ptr(asm_input->asm_symbolic_name),
10281309 buf_ptr(asm_input->constraint));
1029 ir_print_other_instruction(irp, instruction->input_list[i]);
1310 ir_print_other_inst_gen(irp, instruction->input_list[i]);
10301311 fprintf(irp->f, ")");
10311312 }
10321313 fprintf(irp->f, " : ");
......@@ -1038,96 +1319,120 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
10381319 fprintf(irp->f, ")");
10391320}
10401321
1041static void ir_print_size_of(IrPrint *irp, IrInstructionSizeOf *instruction) {
1322static void ir_print_size_of(IrPrintSrc *irp, IrInstSrcSizeOf *instruction) {
10421323 if (instruction->bit_size)
10431324 fprintf(irp->f, "@bitSizeOf(");
10441325 else
10451326 fprintf(irp->f, "@sizeOf(");
1046 ir_print_other_instruction(irp, instruction->type_value);
1327 ir_print_other_inst_src(irp, instruction->type_value);
10471328 fprintf(irp->f, ")");
10481329}
10491330
1050static void ir_print_test_non_null(IrPrint *irp, IrInstructionTestNonNull *instruction) {
1051 ir_print_other_instruction(irp, instruction->value);
1331static void ir_print_test_non_null(IrPrintSrc *irp, IrInstSrcTestNonNull *instruction) {
1332 ir_print_other_inst_src(irp, instruction->value);
1333 fprintf(irp->f, " != null");
1334}
1335
1336static void ir_print_test_non_null(IrPrintGen *irp, IrInstGenTestNonNull *instruction) {
1337 ir_print_other_inst_gen(irp, instruction->value);
10521338 fprintf(irp->f, " != null");
10531339}
10541340
1055static void ir_print_optional_unwrap_ptr(IrPrint *irp, IrInstructionOptionalUnwrapPtr *instruction) {
1341static void ir_print_optional_unwrap_ptr(IrPrintSrc *irp, IrInstSrcOptionalUnwrapPtr *instruction) {
10561342 fprintf(irp->f, "&");
1057 ir_print_other_instruction(irp, instruction->base_ptr);
1343 ir_print_other_inst_src(irp, instruction->base_ptr);
10581344 fprintf(irp->f, ".*.?");
10591345 if (!instruction->safety_check_on) {
10601346 fprintf(irp->f, " // no safety");
10611347 }
10621348}
10631349
1064static void ir_print_clz(IrPrint *irp, IrInstructionClz *instruction) {
1065 fprintf(irp->f, "@clz(");
1066 if (instruction->type != nullptr) {
1067 ir_print_other_instruction(irp, instruction->type);
1068 } else {
1069 fprintf(irp->f, "null");
1350static void ir_print_optional_unwrap_ptr(IrPrintGen *irp, IrInstGenOptionalUnwrapPtr *instruction) {
1351 fprintf(irp->f, "&");
1352 ir_print_other_inst_gen(irp, instruction->base_ptr);
1353 fprintf(irp->f, ".*.?");
1354 if (!instruction->safety_check_on) {
1355 fprintf(irp->f, " // no safety");
10701356 }
1357}
1358
1359static void ir_print_clz(IrPrintSrc *irp, IrInstSrcClz *instruction) {
1360 fprintf(irp->f, "@clz(");
1361 ir_print_other_inst_src(irp, instruction->type);
10711362 fprintf(irp->f, ",");
1072 ir_print_other_instruction(irp, instruction->op);
1363 ir_print_other_inst_src(irp, instruction->op);
10731364 fprintf(irp->f, ")");
10741365}
10751366
1076static void ir_print_ctz(IrPrint *irp, IrInstructionCtz *instruction) {
1367static void ir_print_clz(IrPrintGen *irp, IrInstGenClz *instruction) {
1368 fprintf(irp->f, "@clz(");
1369 ir_print_other_inst_gen(irp, instruction->op);
1370 fprintf(irp->f, ")");
1371}
1372
1373static void ir_print_ctz(IrPrintSrc *irp, IrInstSrcCtz *instruction) {
10771374 fprintf(irp->f, "@ctz(");
1078 if (instruction->type != nullptr) {
1079 ir_print_other_instruction(irp, instruction->type);
1080 } else {
1081 fprintf(irp->f, "null");
1082 }
1375 ir_print_other_inst_src(irp, instruction->type);
10831376 fprintf(irp->f, ",");
1084 ir_print_other_instruction(irp, instruction->op);
1377 ir_print_other_inst_src(irp, instruction->op);
10851378 fprintf(irp->f, ")");
10861379}
10871380
1088static void ir_print_pop_count(IrPrint *irp, IrInstructionPopCount *instruction) {
1381static void ir_print_ctz(IrPrintGen *irp, IrInstGenCtz *instruction) {
1382 fprintf(irp->f, "@ctz(");
1383 ir_print_other_inst_gen(irp, instruction->op);
1384 fprintf(irp->f, ")");
1385}
1386
1387static void ir_print_pop_count(IrPrintSrc *irp, IrInstSrcPopCount *instruction) {
10891388 fprintf(irp->f, "@popCount(");
1090 if (instruction->type != nullptr) {
1091 ir_print_other_instruction(irp, instruction->type);
1092 } else {
1093 fprintf(irp->f, "null");
1094 }
1389 ir_print_other_inst_src(irp, instruction->type);
10951390 fprintf(irp->f, ",");
1096 ir_print_other_instruction(irp, instruction->op);
1391 ir_print_other_inst_src(irp, instruction->op);
10971392 fprintf(irp->f, ")");
10981393}
10991394
1100static void ir_print_bswap(IrPrint *irp, IrInstructionBswap *instruction) {
1395static void ir_print_pop_count(IrPrintGen *irp, IrInstGenPopCount *instruction) {
1396 fprintf(irp->f, "@popCount(");
1397 ir_print_other_inst_gen(irp, instruction->op);
1398 fprintf(irp->f, ")");
1399}
1400
1401static void ir_print_bswap(IrPrintSrc *irp, IrInstSrcBswap *instruction) {
11011402 fprintf(irp->f, "@byteSwap(");
1102 if (instruction->type != nullptr) {
1103 ir_print_other_instruction(irp, instruction->type);
1104 } else {
1105 fprintf(irp->f, "null");
1106 }
1403 ir_print_other_inst_src(irp, instruction->type);
11071404 fprintf(irp->f, ",");
1108 ir_print_other_instruction(irp, instruction->op);
1405 ir_print_other_inst_src(irp, instruction->op);
11091406 fprintf(irp->f, ")");
11101407}
11111408
1112static void ir_print_bit_reverse(IrPrint *irp, IrInstructionBitReverse *instruction) {
1409static void ir_print_bswap(IrPrintGen *irp, IrInstGenBswap *instruction) {
1410 fprintf(irp->f, "@byteSwap(");
1411 ir_print_other_inst_gen(irp, instruction->op);
1412 fprintf(irp->f, ")");
1413}
1414
1415static void ir_print_bit_reverse(IrPrintSrc *irp, IrInstSrcBitReverse *instruction) {
11131416 fprintf(irp->f, "@bitReverse(");
1114 if (instruction->type != nullptr) {
1115 ir_print_other_instruction(irp, instruction->type);
1116 } else {
1117 fprintf(irp->f, "null");
1118 }
1417 ir_print_other_inst_src(irp, instruction->type);
11191418 fprintf(irp->f, ",");
1120 ir_print_other_instruction(irp, instruction->op);
1419 ir_print_other_inst_src(irp, instruction->op);
11211420 fprintf(irp->f, ")");
11221421}
11231422
1124static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction) {
1423static void ir_print_bit_reverse(IrPrintGen *irp, IrInstGenBitReverse *instruction) {
1424 fprintf(irp->f, "@bitReverse(");
1425 ir_print_other_inst_gen(irp, instruction->op);
1426 fprintf(irp->f, ")");
1427}
1428
1429static void ir_print_switch_br(IrPrintSrc *irp, IrInstSrcSwitchBr *instruction) {
11251430 fprintf(irp->f, "switch (");
1126 ir_print_other_instruction(irp, instruction->target_value);
1431 ir_print_other_inst_src(irp, instruction->target_value);
11271432 fprintf(irp->f, ") ");
11281433 for (size_t i = 0; i < instruction->case_count; i += 1) {
1129 IrInstructionSwitchBrCase *this_case = &instruction->cases[i];
1130 ir_print_other_instruction(irp, this_case->value);
1434 IrInstSrcSwitchBrCase *this_case = &instruction->cases[i];
1435 ir_print_other_inst_src(irp, this_case->value);
11311436 fprintf(irp->f, " => ");
11321437 ir_print_other_block(irp, this_case->block);
11331438 fprintf(irp->f, ", ");
......@@ -1136,359 +1441,453 @@ static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction)
11361441 ir_print_other_block(irp, instruction->else_block);
11371442 if (instruction->is_comptime != nullptr) {
11381443 fprintf(irp->f, " // comptime = ");
1139 ir_print_other_instruction(irp, instruction->is_comptime);
1444 ir_print_other_inst_src(irp, instruction->is_comptime);
1445 }
1446}
1447
1448static void ir_print_switch_br(IrPrintGen *irp, IrInstGenSwitchBr *instruction) {
1449 fprintf(irp->f, "switch (");
1450 ir_print_other_inst_gen(irp, instruction->target_value);
1451 fprintf(irp->f, ") ");
1452 for (size_t i = 0; i < instruction->case_count; i += 1) {
1453 IrInstGenSwitchBrCase *this_case = &instruction->cases[i];
1454 ir_print_other_inst_gen(irp, this_case->value);
1455 fprintf(irp->f, " => ");
1456 ir_print_other_block_gen(irp, this_case->block);
1457 fprintf(irp->f, ", ");
11401458 }
1459 fprintf(irp->f, "else => ");
1460 ir_print_other_block_gen(irp, instruction->else_block);
11411461}
11421462
1143static void ir_print_switch_var(IrPrint *irp, IrInstructionSwitchVar *instruction) {
1463static void ir_print_switch_var(IrPrintSrc *irp, IrInstSrcSwitchVar *instruction) {
11441464 fprintf(irp->f, "switchvar ");
1145 ir_print_other_instruction(irp, instruction->target_value_ptr);
1465 ir_print_other_inst_src(irp, instruction->target_value_ptr);
11461466 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
11471467 fprintf(irp->f, ", ");
1148 ir_print_other_instruction(irp, instruction->prongs_ptr[i]);
1468 ir_print_other_inst_src(irp, instruction->prongs_ptr[i]);
11491469 }
11501470}
11511471
1152static void ir_print_switch_else_var(IrPrint *irp, IrInstructionSwitchElseVar *instruction) {
1472static void ir_print_switch_else_var(IrPrintSrc *irp, IrInstSrcSwitchElseVar *instruction) {
11531473 fprintf(irp->f, "switchelsevar ");
1154 ir_print_other_instruction(irp, &instruction->switch_br->base);
1474 ir_print_other_inst_src(irp, &instruction->switch_br->base);
11551475}
11561476
1157static void ir_print_switch_target(IrPrint *irp, IrInstructionSwitchTarget *instruction) {
1477static void ir_print_switch_target(IrPrintSrc *irp, IrInstSrcSwitchTarget *instruction) {
11581478 fprintf(irp->f, "switchtarget ");
1159 ir_print_other_instruction(irp, instruction->target_value_ptr);
1479 ir_print_other_inst_src(irp, instruction->target_value_ptr);
11601480}
11611481
1162static void ir_print_union_tag(IrPrint *irp, IrInstructionUnionTag *instruction) {
1482static void ir_print_union_tag(IrPrintGen *irp, IrInstGenUnionTag *instruction) {
11631483 fprintf(irp->f, "uniontag ");
1164 ir_print_other_instruction(irp, instruction->value);
1484 ir_print_other_inst_gen(irp, instruction->value);
11651485}
11661486
1167static void ir_print_import(IrPrint *irp, IrInstructionImport *instruction) {
1487static void ir_print_import(IrPrintSrc *irp, IrInstSrcImport *instruction) {
11681488 fprintf(irp->f, "@import(");
1169 ir_print_other_instruction(irp, instruction->name);
1489 ir_print_other_inst_src(irp, instruction->name);
11701490 fprintf(irp->f, ")");
11711491}
11721492
1173static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {
1493static void ir_print_ref(IrPrintSrc *irp, IrInstSrcRef *instruction) {
11741494 const char *const_str = instruction->is_const ? "const " : "";
11751495 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
11761496 fprintf(irp->f, "%s%sref ", const_str, volatile_str);
1177 ir_print_other_instruction(irp, instruction->value);
1497 ir_print_other_inst_src(irp, instruction->value);
11781498}
11791499
1180static void ir_print_ref_gen(IrPrint *irp, IrInstructionRefGen *instruction) {
1500static void ir_print_ref_gen(IrPrintGen *irp, IrInstGenRef *instruction) {
11811501 fprintf(irp->f, "@ref(");
1182 ir_print_other_instruction(irp, instruction->operand);
1502 ir_print_other_inst_gen(irp, instruction->operand);
11831503 fprintf(irp->f, ")result=");
1184 ir_print_other_instruction(irp, instruction->result_loc);
1504 ir_print_other_inst_gen(irp, instruction->result_loc);
11851505}
11861506
1187static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {
1507static void ir_print_compile_err(IrPrintSrc *irp, IrInstSrcCompileErr *instruction) {
11881508 fprintf(irp->f, "@compileError(");
1189 ir_print_other_instruction(irp, instruction->msg);
1509 ir_print_other_inst_src(irp, instruction->msg);
11901510 fprintf(irp->f, ")");
11911511}
11921512
1193static void ir_print_compile_log(IrPrint *irp, IrInstructionCompileLog *instruction) {
1513static void ir_print_compile_log(IrPrintSrc *irp, IrInstSrcCompileLog *instruction) {
11941514 fprintf(irp->f, "@compileLog(");
11951515 for (size_t i = 0; i < instruction->msg_count; i += 1) {
11961516 if (i != 0)
11971517 fprintf(irp->f, ",");
1198 IrInstruction *msg = instruction->msg_list[i];
1199 ir_print_other_instruction(irp, msg);
1518 IrInstSrc *msg = instruction->msg_list[i];
1519 ir_print_other_inst_src(irp, msg);
12001520 }
12011521 fprintf(irp->f, ")");
12021522}
12031523
1204static void ir_print_err_name(IrPrint *irp, IrInstructionErrName *instruction) {
1524static void ir_print_err_name(IrPrintSrc *irp, IrInstSrcErrName *instruction) {
12051525 fprintf(irp->f, "@errorName(");
1206 ir_print_other_instruction(irp, instruction->value);
1526 ir_print_other_inst_src(irp, instruction->value);
12071527 fprintf(irp->f, ")");
12081528}
12091529
1210static void ir_print_c_import(IrPrint *irp, IrInstructionCImport *instruction) {
1530static void ir_print_err_name(IrPrintGen *irp, IrInstGenErrName *instruction) {
1531 fprintf(irp->f, "@errorName(");
1532 ir_print_other_inst_gen(irp, instruction->value);
1533 fprintf(irp->f, ")");
1534}
1535
1536static void ir_print_c_import(IrPrintSrc *irp, IrInstSrcCImport *instruction) {
12111537 fprintf(irp->f, "@cImport(...)");
12121538}
12131539
1214static void ir_print_c_include(IrPrint *irp, IrInstructionCInclude *instruction) {
1540static void ir_print_c_include(IrPrintSrc *irp, IrInstSrcCInclude *instruction) {
12151541 fprintf(irp->f, "@cInclude(");
1216 ir_print_other_instruction(irp, instruction->name);
1542 ir_print_other_inst_src(irp, instruction->name);
12171543 fprintf(irp->f, ")");
12181544}
12191545
1220static void ir_print_c_define(IrPrint *irp, IrInstructionCDefine *instruction) {
1546static void ir_print_c_define(IrPrintSrc *irp, IrInstSrcCDefine *instruction) {
12211547 fprintf(irp->f, "@cDefine(");
1222 ir_print_other_instruction(irp, instruction->name);
1548 ir_print_other_inst_src(irp, instruction->name);
12231549 fprintf(irp->f, ", ");
1224 ir_print_other_instruction(irp, instruction->value);
1550 ir_print_other_inst_src(irp, instruction->value);
12251551 fprintf(irp->f, ")");
12261552}
12271553
1228static void ir_print_c_undef(IrPrint *irp, IrInstructionCUndef *instruction) {
1554static void ir_print_c_undef(IrPrintSrc *irp, IrInstSrcCUndef *instruction) {
12291555 fprintf(irp->f, "@cUndef(");
1230 ir_print_other_instruction(irp, instruction->name);
1556 ir_print_other_inst_src(irp, instruction->name);
12311557 fprintf(irp->f, ")");
12321558}
12331559
1234static void ir_print_embed_file(IrPrint *irp, IrInstructionEmbedFile *instruction) {
1560static void ir_print_embed_file(IrPrintSrc *irp, IrInstSrcEmbedFile *instruction) {
12351561 fprintf(irp->f, "@embedFile(");
1236 ir_print_other_instruction(irp, instruction->name);
1562 ir_print_other_inst_src(irp, instruction->name);
12371563 fprintf(irp->f, ")");
12381564}
12391565
1240static void ir_print_cmpxchg_src(IrPrint *irp, IrInstructionCmpxchgSrc *instruction) {
1566static void ir_print_cmpxchg_src(IrPrintSrc *irp, IrInstSrcCmpxchg *instruction) {
12411567 fprintf(irp->f, "@cmpxchg(");
1242 ir_print_other_instruction(irp, instruction->ptr);
1568 ir_print_other_inst_src(irp, instruction->ptr);
12431569 fprintf(irp->f, ", ");
1244 ir_print_other_instruction(irp, instruction->cmp_value);
1570 ir_print_other_inst_src(irp, instruction->cmp_value);
12451571 fprintf(irp->f, ", ");
1246 ir_print_other_instruction(irp, instruction->new_value);
1572 ir_print_other_inst_src(irp, instruction->new_value);
12471573 fprintf(irp->f, ", ");
1248 ir_print_other_instruction(irp, instruction->success_order_value);
1574 ir_print_other_inst_src(irp, instruction->success_order_value);
12491575 fprintf(irp->f, ", ");
1250 ir_print_other_instruction(irp, instruction->failure_order_value);
1576 ir_print_other_inst_src(irp, instruction->failure_order_value);
12511577 fprintf(irp->f, ")result=");
12521578 ir_print_result_loc(irp, instruction->result_loc);
12531579}
12541580
1255static void ir_print_cmpxchg_gen(IrPrint *irp, IrInstructionCmpxchgGen *instruction) {
1581static void ir_print_cmpxchg_gen(IrPrintGen *irp, IrInstGenCmpxchg *instruction) {
12561582 fprintf(irp->f, "@cmpxchg(");
1257 ir_print_other_instruction(irp, instruction->ptr);
1583 ir_print_other_inst_gen(irp, instruction->ptr);
12581584 fprintf(irp->f, ", ");
1259 ir_print_other_instruction(irp, instruction->cmp_value);
1585 ir_print_other_inst_gen(irp, instruction->cmp_value);
12601586 fprintf(irp->f, ", ");
1261 ir_print_other_instruction(irp, instruction->new_value);
1587 ir_print_other_inst_gen(irp, instruction->new_value);
12621588 fprintf(irp->f, ", TODO print atomic orders)result=");
1263 ir_print_other_instruction(irp, instruction->result_loc);
1589 ir_print_other_inst_gen(irp, instruction->result_loc);
12641590}
12651591
1266static void ir_print_fence(IrPrint *irp, IrInstructionFence *instruction) {
1592static void ir_print_fence(IrPrintSrc *irp, IrInstSrcFence *instruction) {
12671593 fprintf(irp->f, "@fence(");
1268 ir_print_other_instruction(irp, instruction->order_value);
1594 ir_print_other_inst_src(irp, instruction->order);
12691595 fprintf(irp->f, ")");
12701596}
12711597
1272static void ir_print_truncate(IrPrint *irp, IrInstructionTruncate *instruction) {
1598static const char *atomic_order_str(AtomicOrder order) {
1599 switch (order) {
1600 case AtomicOrderUnordered: return "Unordered";
1601 case AtomicOrderMonotonic: return "Monotonic";
1602 case AtomicOrderAcquire: return "Acquire";
1603 case AtomicOrderRelease: return "Release";
1604 case AtomicOrderAcqRel: return "AcqRel";
1605 case AtomicOrderSeqCst: return "SeqCst";
1606 }
1607 zig_unreachable();
1608}
1609
1610static void ir_print_fence(IrPrintGen *irp, IrInstGenFence *instruction) {
1611 fprintf(irp->f, "fence %s", atomic_order_str(instruction->order));
1612}
1613
1614static void ir_print_truncate(IrPrintSrc *irp, IrInstSrcTruncate *instruction) {
12731615 fprintf(irp->f, "@truncate(");
1274 ir_print_other_instruction(irp, instruction->dest_type);
1616 ir_print_other_inst_src(irp, instruction->dest_type);
12751617 fprintf(irp->f, ", ");
1276 ir_print_other_instruction(irp, instruction->target);
1618 ir_print_other_inst_src(irp, instruction->target);
12771619 fprintf(irp->f, ")");
12781620}
12791621
1280static void ir_print_int_cast(IrPrint *irp, IrInstructionIntCast *instruction) {
1622static void ir_print_truncate(IrPrintGen *irp, IrInstGenTruncate *instruction) {
1623 fprintf(irp->f, "@truncate(");
1624 ir_print_other_inst_gen(irp, instruction->target);
1625 fprintf(irp->f, ")");
1626}
1627
1628static void ir_print_int_cast(IrPrintSrc *irp, IrInstSrcIntCast *instruction) {
12811629 fprintf(irp->f, "@intCast(");
1282 ir_print_other_instruction(irp, instruction->dest_type);
1630 ir_print_other_inst_src(irp, instruction->dest_type);
12831631 fprintf(irp->f, ", ");
1284 ir_print_other_instruction(irp, instruction->target);
1632 ir_print_other_inst_src(irp, instruction->target);
12851633 fprintf(irp->f, ")");
12861634}
12871635
1288static void ir_print_float_cast(IrPrint *irp, IrInstructionFloatCast *instruction) {
1636static void ir_print_float_cast(IrPrintSrc *irp, IrInstSrcFloatCast *instruction) {
12891637 fprintf(irp->f, "@floatCast(");
1290 ir_print_other_instruction(irp, instruction->dest_type);
1638 ir_print_other_inst_src(irp, instruction->dest_type);
12911639 fprintf(irp->f, ", ");
1292 ir_print_other_instruction(irp, instruction->target);
1640 ir_print_other_inst_src(irp, instruction->target);
12931641 fprintf(irp->f, ")");
12941642}
12951643
1296static void ir_print_err_set_cast(IrPrint *irp, IrInstructionErrSetCast *instruction) {
1644static void ir_print_err_set_cast(IrPrintSrc *irp, IrInstSrcErrSetCast *instruction) {
12971645 fprintf(irp->f, "@errSetCast(");
1298 ir_print_other_instruction(irp, instruction->dest_type);
1646 ir_print_other_inst_src(irp, instruction->dest_type);
12991647 fprintf(irp->f, ", ");
1300 ir_print_other_instruction(irp, instruction->target);
1648 ir_print_other_inst_src(irp, instruction->target);
13011649 fprintf(irp->f, ")");
13021650}
13031651
1304static void ir_print_from_bytes(IrPrint *irp, IrInstructionFromBytes *instruction) {
1652static void ir_print_from_bytes(IrPrintSrc *irp, IrInstSrcFromBytes *instruction) {
13051653 fprintf(irp->f, "@bytesToSlice(");
1306 ir_print_other_instruction(irp, instruction->dest_child_type);
1654 ir_print_other_inst_src(irp, instruction->dest_child_type);
13071655 fprintf(irp->f, ", ");
1308 ir_print_other_instruction(irp, instruction->target);
1656 ir_print_other_inst_src(irp, instruction->target);
13091657 fprintf(irp->f, ")");
13101658}
13111659
1312static void ir_print_to_bytes(IrPrint *irp, IrInstructionToBytes *instruction) {
1660static void ir_print_to_bytes(IrPrintSrc *irp, IrInstSrcToBytes *instruction) {
13131661 fprintf(irp->f, "@sliceToBytes(");
1314 ir_print_other_instruction(irp, instruction->target);
1662 ir_print_other_inst_src(irp, instruction->target);
13151663 fprintf(irp->f, ")");
13161664}
13171665
1318static void ir_print_int_to_float(IrPrint *irp, IrInstructionIntToFloat *instruction) {
1666static void ir_print_int_to_float(IrPrintSrc *irp, IrInstSrcIntToFloat *instruction) {
13191667 fprintf(irp->f, "@intToFloat(");
1320 ir_print_other_instruction(irp, instruction->dest_type);
1668 ir_print_other_inst_src(irp, instruction->dest_type);
13211669 fprintf(irp->f, ", ");
1322 ir_print_other_instruction(irp, instruction->target);
1670 ir_print_other_inst_src(irp, instruction->target);
13231671 fprintf(irp->f, ")");
13241672}
13251673
1326static void ir_print_float_to_int(IrPrint *irp, IrInstructionFloatToInt *instruction) {
1674static void ir_print_float_to_int(IrPrintSrc *irp, IrInstSrcFloatToInt *instruction) {
13271675 fprintf(irp->f, "@floatToInt(");
1328 ir_print_other_instruction(irp, instruction->dest_type);
1676 ir_print_other_inst_src(irp, instruction->dest_type);
13291677 fprintf(irp->f, ", ");
1330 ir_print_other_instruction(irp, instruction->target);
1678 ir_print_other_inst_src(irp, instruction->target);
13311679 fprintf(irp->f, ")");
13321680}
13331681
1334static void ir_print_bool_to_int(IrPrint *irp, IrInstructionBoolToInt *instruction) {
1682static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instruction) {
13351683 fprintf(irp->f, "@boolToInt(");
1336 ir_print_other_instruction(irp, instruction->target);
1684 ir_print_other_inst_src(irp, instruction->target);
13371685 fprintf(irp->f, ")");
13381686}
13391687
1340static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {
1688static void ir_print_int_type(IrPrintSrc *irp, IrInstSrcIntType *instruction) {
13411689 fprintf(irp->f, "@IntType(");
1342 ir_print_other_instruction(irp, instruction->is_signed);
1690 ir_print_other_inst_src(irp, instruction->is_signed);
13431691 fprintf(irp->f, ", ");
1344 ir_print_other_instruction(irp, instruction->bit_count);
1692 ir_print_other_inst_src(irp, instruction->bit_count);
13451693 fprintf(irp->f, ")");
13461694}
13471695
1348static void ir_print_vector_type(IrPrint *irp, IrInstructionVectorType *instruction) {
1696static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {
13491697 fprintf(irp->f, "@Vector(");
1350 ir_print_other_instruction(irp, instruction->len);
1698 ir_print_other_inst_src(irp, instruction->len);
13511699 fprintf(irp->f, ", ");
1352 ir_print_other_instruction(irp, instruction->elem_type);
1700 ir_print_other_inst_src(irp, instruction->elem_type);
13531701 fprintf(irp->f, ")");
13541702}
13551703
1356static void ir_print_shuffle_vector(IrPrint *irp, IrInstructionShuffleVector *instruction) {
1704static void ir_print_shuffle_vector(IrPrintSrc *irp, IrInstSrcShuffleVector *instruction) {
13571705 fprintf(irp->f, "@shuffle(");
1358 ir_print_other_instruction(irp, instruction->scalar_type);
1706 ir_print_other_inst_src(irp, instruction->scalar_type);
13591707 fprintf(irp->f, ", ");
1360 ir_print_other_instruction(irp, instruction->a);
1708 ir_print_other_inst_src(irp, instruction->a);
13611709 fprintf(irp->f, ", ");
1362 ir_print_other_instruction(irp, instruction->b);
1710 ir_print_other_inst_src(irp, instruction->b);
13631711 fprintf(irp->f, ", ");
1364 ir_print_other_instruction(irp, instruction->mask);
1712 ir_print_other_inst_src(irp, instruction->mask);
13651713 fprintf(irp->f, ")");
13661714}
13671715
1368static void ir_print_splat_src(IrPrint *irp, IrInstructionSplatSrc *instruction) {
1716static void ir_print_shuffle_vector(IrPrintGen *irp, IrInstGenShuffleVector *instruction) {
1717 fprintf(irp->f, "@shuffle(");
1718 ir_print_other_inst_gen(irp, instruction->a);
1719 fprintf(irp->f, ", ");
1720 ir_print_other_inst_gen(irp, instruction->b);
1721 fprintf(irp->f, ", ");
1722 ir_print_other_inst_gen(irp, instruction->mask);
1723 fprintf(irp->f, ")");
1724}
1725
1726static void ir_print_splat_src(IrPrintSrc *irp, IrInstSrcSplat *instruction) {
13691727 fprintf(irp->f, "@splat(");
1370 ir_print_other_instruction(irp, instruction->len);
1728 ir_print_other_inst_src(irp, instruction->len);
13711729 fprintf(irp->f, ", ");
1372 ir_print_other_instruction(irp, instruction->scalar);
1730 ir_print_other_inst_src(irp, instruction->scalar);
13731731 fprintf(irp->f, ")");
13741732}
13751733
1376static void ir_print_splat_gen(IrPrint *irp, IrInstructionSplatGen *instruction) {
1734static void ir_print_splat_gen(IrPrintGen *irp, IrInstGenSplat *instruction) {
13771735 fprintf(irp->f, "@splat(");
1378 ir_print_other_instruction(irp, instruction->scalar);
1736 ir_print_other_inst_gen(irp, instruction->scalar);
13791737 fprintf(irp->f, ")");
13801738}
13811739
1382static void ir_print_bool_not(IrPrint *irp, IrInstructionBoolNot *instruction) {
1740static void ir_print_bool_not(IrPrintSrc *irp, IrInstSrcBoolNot *instruction) {
1741 fprintf(irp->f, "! ");
1742 ir_print_other_inst_src(irp, instruction->value);
1743}
1744
1745static void ir_print_bool_not(IrPrintGen *irp, IrInstGenBoolNot *instruction) {
13831746 fprintf(irp->f, "! ");
1384 ir_print_other_instruction(irp, instruction->value);
1747 ir_print_other_inst_gen(irp, instruction->value);
13851748}
13861749
1387static void ir_print_memset(IrPrint *irp, IrInstructionMemset *instruction) {
1750static void ir_print_memset(IrPrintSrc *irp, IrInstSrcMemset *instruction) {
13881751 fprintf(irp->f, "@memset(");
1389 ir_print_other_instruction(irp, instruction->dest_ptr);
1752 ir_print_other_inst_src(irp, instruction->dest_ptr);
1753 fprintf(irp->f, ", ");
1754 ir_print_other_inst_src(irp, instruction->byte);
1755 fprintf(irp->f, ", ");
1756 ir_print_other_inst_src(irp, instruction->count);
1757 fprintf(irp->f, ")");
1758}
1759
1760static void ir_print_memset(IrPrintGen *irp, IrInstGenMemset *instruction) {
1761 fprintf(irp->f, "@memset(");
1762 ir_print_other_inst_gen(irp, instruction->dest_ptr);
1763 fprintf(irp->f, ", ");
1764 ir_print_other_inst_gen(irp, instruction->byte);
1765 fprintf(irp->f, ", ");
1766 ir_print_other_inst_gen(irp, instruction->count);
1767 fprintf(irp->f, ")");
1768}
1769
1770static void ir_print_memcpy(IrPrintSrc *irp, IrInstSrcMemcpy *instruction) {
1771 fprintf(irp->f, "@memcpy(");
1772 ir_print_other_inst_src(irp, instruction->dest_ptr);
13901773 fprintf(irp->f, ", ");
1391 ir_print_other_instruction(irp, instruction->byte);
1774 ir_print_other_inst_src(irp, instruction->src_ptr);
13921775 fprintf(irp->f, ", ");
1393 ir_print_other_instruction(irp, instruction->count);
1776 ir_print_other_inst_src(irp, instruction->count);
13941777 fprintf(irp->f, ")");
13951778}
13961779
1397static void ir_print_memcpy(IrPrint *irp, IrInstructionMemcpy *instruction) {
1780static void ir_print_memcpy(IrPrintGen *irp, IrInstGenMemcpy *instruction) {
13981781 fprintf(irp->f, "@memcpy(");
1399 ir_print_other_instruction(irp, instruction->dest_ptr);
1782 ir_print_other_inst_gen(irp, instruction->dest_ptr);
14001783 fprintf(irp->f, ", ");
1401 ir_print_other_instruction(irp, instruction->src_ptr);
1784 ir_print_other_inst_gen(irp, instruction->src_ptr);
14021785 fprintf(irp->f, ", ");
1403 ir_print_other_instruction(irp, instruction->count);
1786 ir_print_other_inst_gen(irp, instruction->count);
14041787 fprintf(irp->f, ")");
14051788}
14061789
1407static void ir_print_slice_src(IrPrint *irp, IrInstructionSliceSrc *instruction) {
1408 ir_print_other_instruction(irp, instruction->ptr);
1790static void ir_print_slice_src(IrPrintSrc *irp, IrInstSrcSlice *instruction) {
1791 ir_print_other_inst_src(irp, instruction->ptr);
14091792 fprintf(irp->f, "[");
1410 ir_print_other_instruction(irp, instruction->start);
1793 ir_print_other_inst_src(irp, instruction->start);
14111794 fprintf(irp->f, "..");
14121795 if (instruction->end)
1413 ir_print_other_instruction(irp, instruction->end);
1796 ir_print_other_inst_src(irp, instruction->end);
14141797 fprintf(irp->f, "]result=");
14151798 ir_print_result_loc(irp, instruction->result_loc);
14161799}
14171800
1418static void ir_print_slice_gen(IrPrint *irp, IrInstructionSliceGen *instruction) {
1419 ir_print_other_instruction(irp, instruction->ptr);
1801static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
1802 ir_print_other_inst_gen(irp, instruction->ptr);
14201803 fprintf(irp->f, "[");
1421 ir_print_other_instruction(irp, instruction->start);
1804 ir_print_other_inst_gen(irp, instruction->start);
14221805 fprintf(irp->f, "..");
14231806 if (instruction->end)
1424 ir_print_other_instruction(irp, instruction->end);
1807 ir_print_other_inst_gen(irp, instruction->end);
14251808 fprintf(irp->f, "]result=");
1426 ir_print_other_instruction(irp, instruction->result_loc);
1809 ir_print_other_inst_gen(irp, instruction->result_loc);
14271810}
14281811
1429static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instruction) {
1812static void ir_print_member_count(IrPrintSrc *irp, IrInstSrcMemberCount *instruction) {
14301813 fprintf(irp->f, "@memberCount(");
1431 ir_print_other_instruction(irp, instruction->container);
1814 ir_print_other_inst_src(irp, instruction->container);
14321815 fprintf(irp->f, ")");
14331816}
14341817
1435static void ir_print_member_type(IrPrint *irp, IrInstructionMemberType *instruction) {
1818static void ir_print_member_type(IrPrintSrc *irp, IrInstSrcMemberType *instruction) {
14361819 fprintf(irp->f, "@memberType(");
1437 ir_print_other_instruction(irp, instruction->container_type);
1820 ir_print_other_inst_src(irp, instruction->container_type);
14381821 fprintf(irp->f, ", ");
1439 ir_print_other_instruction(irp, instruction->member_index);
1822 ir_print_other_inst_src(irp, instruction->member_index);
14401823 fprintf(irp->f, ")");
14411824}
14421825
1443static void ir_print_member_name(IrPrint *irp, IrInstructionMemberName *instruction) {
1826static void ir_print_member_name(IrPrintSrc *irp, IrInstSrcMemberName *instruction) {
14441827 fprintf(irp->f, "@memberName(");
1445 ir_print_other_instruction(irp, instruction->container_type);
1828 ir_print_other_inst_src(irp, instruction->container_type);
14461829 fprintf(irp->f, ", ");
1447 ir_print_other_instruction(irp, instruction->member_index);
1830 ir_print_other_inst_src(irp, instruction->member_index);
14481831 fprintf(irp->f, ")");
14491832}
14501833
1451static void ir_print_breakpoint(IrPrint *irp, IrInstructionBreakpoint *instruction) {
1834static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {
1835 fprintf(irp->f, "@breakpoint()");
1836}
1837
1838static void ir_print_breakpoint(IrPrintGen *irp, IrInstGenBreakpoint *instruction) {
14521839 fprintf(irp->f, "@breakpoint()");
14531840}
14541841
1455static void ir_print_frame_address(IrPrint *irp, IrInstructionFrameAddress *instruction) {
1842static void ir_print_frame_address(IrPrintSrc *irp, IrInstSrcFrameAddress *instruction) {
1843 fprintf(irp->f, "@frameAddress()");
1844}
1845
1846static void ir_print_frame_address(IrPrintGen *irp, IrInstGenFrameAddress *instruction) {
14561847 fprintf(irp->f, "@frameAddress()");
14571848}
14581849
1459static void ir_print_handle(IrPrint *irp, IrInstructionFrameHandle *instruction) {
1850static void ir_print_handle(IrPrintSrc *irp, IrInstSrcFrameHandle *instruction) {
14601851 fprintf(irp->f, "@frame()");
14611852}
14621853
1463static void ir_print_frame_type(IrPrint *irp, IrInstructionFrameType *instruction) {
1854static void ir_print_handle(IrPrintGen *irp, IrInstGenFrameHandle *instruction) {
1855 fprintf(irp->f, "@frame()");
1856}
1857
1858static void ir_print_frame_type(IrPrintSrc *irp, IrInstSrcFrameType *instruction) {
14641859 fprintf(irp->f, "@Frame(");
1465 ir_print_other_instruction(irp, instruction->fn);
1860 ir_print_other_inst_src(irp, instruction->fn);
14661861 fprintf(irp->f, ")");
14671862}
14681863
1469static void ir_print_frame_size_src(IrPrint *irp, IrInstructionFrameSizeSrc *instruction) {
1864static void ir_print_frame_size_src(IrPrintSrc *irp, IrInstSrcFrameSize *instruction) {
14701865 fprintf(irp->f, "@frameSize(");
1471 ir_print_other_instruction(irp, instruction->fn);
1866 ir_print_other_inst_src(irp, instruction->fn);
14721867 fprintf(irp->f, ")");
14731868}
14741869
1475static void ir_print_frame_size_gen(IrPrint *irp, IrInstructionFrameSizeGen *instruction) {
1870static void ir_print_frame_size_gen(IrPrintGen *irp, IrInstGenFrameSize *instruction) {
14761871 fprintf(irp->f, "@frameSize(");
1477 ir_print_other_instruction(irp, instruction->fn);
1872 ir_print_other_inst_gen(irp, instruction->fn);
14781873 fprintf(irp->f, ")");
14791874}
14801875
1481static void ir_print_return_address(IrPrint *irp, IrInstructionReturnAddress *instruction) {
1876static void ir_print_return_address(IrPrintSrc *irp, IrInstSrcReturnAddress *instruction) {
1877 fprintf(irp->f, "@returnAddress()");
1878}
1879
1880static void ir_print_return_address(IrPrintGen *irp, IrInstGenReturnAddress *instruction) {
14821881 fprintf(irp->f, "@returnAddress()");
14831882}
14841883
1485static void ir_print_align_of(IrPrint *irp, IrInstructionAlignOf *instruction) {
1884static void ir_print_align_of(IrPrintSrc *irp, IrInstSrcAlignOf *instruction) {
14861885 fprintf(irp->f, "@alignOf(");
1487 ir_print_other_instruction(irp, instruction->type_value);
1886 ir_print_other_inst_src(irp, instruction->type_value);
14881887 fprintf(irp->f, ")");
14891888}
14901889
1491static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruction) {
1890static void ir_print_overflow_op(IrPrintSrc *irp, IrInstSrcOverflowOp *instruction) {
14921891 switch (instruction->op) {
14931892 case IrOverflowOpAdd:
14941893 fprintf(irp->f, "@addWithOverflow(");
......@@ -1503,1146 +1902,1457 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct
15031902 fprintf(irp->f, "@shlWithOverflow(");
15041903 break;
15051904 }
1506 ir_print_other_instruction(irp, instruction->type_value);
1905 ir_print_other_inst_src(irp, instruction->type_value);
15071906 fprintf(irp->f, ", ");
1508 ir_print_other_instruction(irp, instruction->op1);
1907 ir_print_other_inst_src(irp, instruction->op1);
1908 fprintf(irp->f, ", ");
1909 ir_print_other_inst_src(irp, instruction->op2);
1910 fprintf(irp->f, ", ");
1911 ir_print_other_inst_src(irp, instruction->result_ptr);
1912 fprintf(irp->f, ")");
1913}
1914
1915static void ir_print_overflow_op(IrPrintGen *irp, IrInstGenOverflowOp *instruction) {
1916 switch (instruction->op) {
1917 case IrOverflowOpAdd:
1918 fprintf(irp->f, "@addWithOverflow(");
1919 break;
1920 case IrOverflowOpSub:
1921 fprintf(irp->f, "@subWithOverflow(");
1922 break;
1923 case IrOverflowOpMul:
1924 fprintf(irp->f, "@mulWithOverflow(");
1925 break;
1926 case IrOverflowOpShl:
1927 fprintf(irp->f, "@shlWithOverflow(");
1928 break;
1929 }
1930 ir_print_other_inst_gen(irp, instruction->op1);
15091931 fprintf(irp->f, ", ");
1510 ir_print_other_instruction(irp, instruction->op2);
1932 ir_print_other_inst_gen(irp, instruction->op2);
15111933 fprintf(irp->f, ", ");
1512 ir_print_other_instruction(irp, instruction->result_ptr);
1934 ir_print_other_inst_gen(irp, instruction->result_ptr);
15131935 fprintf(irp->f, ")");
15141936}
15151937
1516static void ir_print_test_err_src(IrPrint *irp, IrInstructionTestErrSrc *instruction) {
1938static void ir_print_test_err_src(IrPrintSrc *irp, IrInstSrcTestErr *instruction) {
15171939 fprintf(irp->f, "@testError(");
1518 ir_print_other_instruction(irp, instruction->base_ptr);
1940 ir_print_other_inst_src(irp, instruction->base_ptr);
15191941 fprintf(irp->f, ")");
15201942}
15211943
1522static void ir_print_test_err_gen(IrPrint *irp, IrInstructionTestErrGen *instruction) {
1944static void ir_print_test_err_gen(IrPrintGen *irp, IrInstGenTestErr *instruction) {
15231945 fprintf(irp->f, "@testError(");
1524 ir_print_other_instruction(irp, instruction->err_union);
1946 ir_print_other_inst_gen(irp, instruction->err_union);
1947 fprintf(irp->f, ")");
1948}
1949
1950static void ir_print_unwrap_err_code(IrPrintSrc *irp, IrInstSrcUnwrapErrCode *instruction) {
1951 fprintf(irp->f, "UnwrapErrorCode(");
1952 ir_print_other_inst_src(irp, instruction->err_union_ptr);
15251953 fprintf(irp->f, ")");
15261954}
15271955
1528static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {
1956static void ir_print_unwrap_err_code(IrPrintGen *irp, IrInstGenUnwrapErrCode *instruction) {
15291957 fprintf(irp->f, "UnwrapErrorCode(");
1530 ir_print_other_instruction(irp, instruction->err_union_ptr);
1958 ir_print_other_inst_gen(irp, instruction->err_union_ptr);
15311959 fprintf(irp->f, ")");
15321960}
15331961
1534static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) {
1962static void ir_print_unwrap_err_payload(IrPrintSrc *irp, IrInstSrcUnwrapErrPayload *instruction) {
1963 fprintf(irp->f, "ErrorUnionFieldPayload(");
1964 ir_print_other_inst_src(irp, instruction->value);
1965 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
1966}
1967
1968static void ir_print_unwrap_err_payload(IrPrintGen *irp, IrInstGenUnwrapErrPayload *instruction) {
15351969 fprintf(irp->f, "ErrorUnionFieldPayload(");
1536 ir_print_other_instruction(irp, instruction->value);
1970 ir_print_other_inst_gen(irp, instruction->value);
15371971 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
15381972}
15391973
1540static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {
1974static void ir_print_optional_wrap(IrPrintGen *irp, IrInstGenOptionalWrap *instruction) {
15411975 fprintf(irp->f, "@optionalWrap(");
1542 ir_print_other_instruction(irp, instruction->operand);
1976 ir_print_other_inst_gen(irp, instruction->operand);
15431977 fprintf(irp->f, ")result=");
1544 ir_print_other_instruction(irp, instruction->result_loc);
1978 ir_print_other_inst_gen(irp, instruction->result_loc);
15451979}
15461980
1547static void ir_print_err_wrap_code(IrPrint *irp, IrInstructionErrWrapCode *instruction) {
1981static void ir_print_err_wrap_code(IrPrintGen *irp, IrInstGenErrWrapCode *instruction) {
15481982 fprintf(irp->f, "@errWrapCode(");
1549 ir_print_other_instruction(irp, instruction->operand);
1983 ir_print_other_inst_gen(irp, instruction->operand);
15501984 fprintf(irp->f, ")result=");
1551 ir_print_other_instruction(irp, instruction->result_loc);
1985 ir_print_other_inst_gen(irp, instruction->result_loc);
15521986}
15531987
1554static void ir_print_err_wrap_payload(IrPrint *irp, IrInstructionErrWrapPayload *instruction) {
1988static void ir_print_err_wrap_payload(IrPrintGen *irp, IrInstGenErrWrapPayload *instruction) {
15551989 fprintf(irp->f, "@errWrapPayload(");
1556 ir_print_other_instruction(irp, instruction->operand);
1990 ir_print_other_inst_gen(irp, instruction->operand);
15571991 fprintf(irp->f, ")result=");
1558 ir_print_other_instruction(irp, instruction->result_loc);
1992 ir_print_other_inst_gen(irp, instruction->result_loc);
15591993}
15601994
1561static void ir_print_fn_proto(IrPrint *irp, IrInstructionFnProto *instruction) {
1995static void ir_print_fn_proto(IrPrintSrc *irp, IrInstSrcFnProto *instruction) {
15621996 fprintf(irp->f, "fn(");
1563 for (size_t i = 0; i < instruction->base.source_node->data.fn_proto.params.length; i += 1) {
1997 for (size_t i = 0; i < instruction->base.base.source_node->data.fn_proto.params.length; i += 1) {
15641998 if (i != 0)
15651999 fprintf(irp->f, ",");
1566 if (instruction->is_var_args && i == instruction->base.source_node->data.fn_proto.params.length - 1) {
2000 if (instruction->is_var_args && i == instruction->base.base.source_node->data.fn_proto.params.length - 1) {
15672001 fprintf(irp->f, "...");
15682002 } else {
1569 ir_print_other_instruction(irp, instruction->param_types[i]);
2003 ir_print_other_inst_src(irp, instruction->param_types[i]);
15702004 }
15712005 }
15722006 fprintf(irp->f, ")");
15732007 if (instruction->align_value != nullptr) {
15742008 fprintf(irp->f, " align ");
1575 ir_print_other_instruction(irp, instruction->align_value);
2009 ir_print_other_inst_src(irp, instruction->align_value);
15762010 fprintf(irp->f, " ");
15772011 }
15782012 fprintf(irp->f, "->");
1579 ir_print_other_instruction(irp, instruction->return_type);
2013 ir_print_other_inst_src(irp, instruction->return_type);
15802014}
15812015
1582static void ir_print_test_comptime(IrPrint *irp, IrInstructionTestComptime *instruction) {
2016static void ir_print_test_comptime(IrPrintSrc *irp, IrInstSrcTestComptime *instruction) {
15832017 fprintf(irp->f, "@testComptime(");
1584 ir_print_other_instruction(irp, instruction->value);
2018 ir_print_other_inst_src(irp, instruction->value);
15852019 fprintf(irp->f, ")");
15862020}
15872021
1588static void ir_print_ptr_cast_src(IrPrint *irp, IrInstructionPtrCastSrc *instruction) {
2022static void ir_print_ptr_cast_src(IrPrintSrc *irp, IrInstSrcPtrCast *instruction) {
15892023 fprintf(irp->f, "@ptrCast(");
15902024 if (instruction->dest_type) {
1591 ir_print_other_instruction(irp, instruction->dest_type);
2025 ir_print_other_inst_src(irp, instruction->dest_type);
15922026 }
15932027 fprintf(irp->f, ",");
1594 ir_print_other_instruction(irp, instruction->ptr);
2028 ir_print_other_inst_src(irp, instruction->ptr);
15952029 fprintf(irp->f, ")");
15962030}
15972031
1598static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruction) {
2032static void ir_print_ptr_cast_gen(IrPrintGen *irp, IrInstGenPtrCast *instruction) {
15992033 fprintf(irp->f, "@ptrCast(");
1600 ir_print_other_instruction(irp, instruction->ptr);
2034 ir_print_other_inst_gen(irp, instruction->ptr);
16012035 fprintf(irp->f, ")");
16022036}
16032037
1604static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
2038static void ir_print_implicit_cast(IrPrintSrc *irp, IrInstSrcImplicitCast *instruction) {
16052039 fprintf(irp->f, "@implicitCast(");
1606 ir_print_other_instruction(irp, instruction->operand);
2040 ir_print_other_inst_src(irp, instruction->operand);
16072041 fprintf(irp->f, ")result=");
16082042 ir_print_result_loc(irp, &instruction->result_loc_cast->base);
16092043}
16102044
1611static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {
2045static void ir_print_bit_cast_src(IrPrintSrc *irp, IrInstSrcBitCast *instruction) {
16122046 fprintf(irp->f, "@bitCast(");
1613 ir_print_other_instruction(irp, instruction->operand);
2047 ir_print_other_inst_src(irp, instruction->operand);
16142048 fprintf(irp->f, ")result=");
16152049 ir_print_result_loc(irp, &instruction->result_loc_bit_cast->base);
16162050}
16172051
1618static void ir_print_bit_cast_gen(IrPrint *irp, IrInstructionBitCastGen *instruction) {
2052static void ir_print_bit_cast_gen(IrPrintGen *irp, IrInstGenBitCast *instruction) {
16192053 fprintf(irp->f, "@bitCast(");
1620 ir_print_other_instruction(irp, instruction->operand);
2054 ir_print_other_inst_gen(irp, instruction->operand);
16212055 fprintf(irp->f, ")");
16222056}
16232057
1624static void ir_print_widen_or_shorten(IrPrint *irp, IrInstructionWidenOrShorten *instruction) {
2058static void ir_print_widen_or_shorten(IrPrintGen *irp, IrInstGenWidenOrShorten *instruction) {
16252059 fprintf(irp->f, "WidenOrShorten(");
1626 ir_print_other_instruction(irp, instruction->target);
2060 ir_print_other_inst_gen(irp, instruction->target);
16272061 fprintf(irp->f, ")");
16282062}
16292063
1630static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction) {
2064static void ir_print_ptr_to_int(IrPrintSrc *irp, IrInstSrcPtrToInt *instruction) {
16312065 fprintf(irp->f, "@ptrToInt(");
1632 ir_print_other_instruction(irp, instruction->target);
2066 ir_print_other_inst_src(irp, instruction->target);
16332067 fprintf(irp->f, ")");
16342068}
16352069
1636static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {
2070static void ir_print_ptr_to_int(IrPrintGen *irp, IrInstGenPtrToInt *instruction) {
2071 fprintf(irp->f, "@ptrToInt(");
2072 ir_print_other_inst_gen(irp, instruction->target);
2073 fprintf(irp->f, ")");
2074}
2075
2076static void ir_print_int_to_ptr(IrPrintSrc *irp, IrInstSrcIntToPtr *instruction) {
16372077 fprintf(irp->f, "@intToPtr(");
1638 if (instruction->dest_type == nullptr) {
1639 fprintf(irp->f, "(null)");
1640 } else {
1641 ir_print_other_instruction(irp, instruction->dest_type);
1642 }
2078 ir_print_other_inst_src(irp, instruction->dest_type);
16432079 fprintf(irp->f, ",");
1644 ir_print_other_instruction(irp, instruction->target);
2080 ir_print_other_inst_src(irp, instruction->target);
16452081 fprintf(irp->f, ")");
16462082}
16472083
1648static void ir_print_int_to_enum(IrPrint *irp, IrInstructionIntToEnum *instruction) {
2084static void ir_print_int_to_ptr(IrPrintGen *irp, IrInstGenIntToPtr *instruction) {
2085 fprintf(irp->f, "@intToPtr(");
2086 ir_print_other_inst_gen(irp, instruction->target);
2087 fprintf(irp->f, ")");
2088}
2089
2090static void ir_print_int_to_enum(IrPrintSrc *irp, IrInstSrcIntToEnum *instruction) {
16492091 fprintf(irp->f, "@intToEnum(");
1650 if (instruction->dest_type == nullptr) {
1651 fprintf(irp->f, "(null)");
1652 } else {
1653 ir_print_other_instruction(irp, instruction->dest_type);
1654 }
1655 ir_print_other_instruction(irp, instruction->target);
2092 ir_print_other_inst_src(irp, instruction->dest_type);
2093 fprintf(irp->f, ",");
2094 ir_print_other_inst_src(irp, instruction->target);
16562095 fprintf(irp->f, ")");
16572096}
16582097
1659static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instruction) {
2098static void ir_print_int_to_enum(IrPrintGen *irp, IrInstGenIntToEnum *instruction) {
2099 fprintf(irp->f, "@intToEnum(");
2100 ir_print_other_inst_gen(irp, instruction->target);
2101 fprintf(irp->f, ")");
2102}
2103
2104static void ir_print_enum_to_int(IrPrintSrc *irp, IrInstSrcEnumToInt *instruction) {
16602105 fprintf(irp->f, "@enumToInt(");
1661 ir_print_other_instruction(irp, instruction->target);
2106 ir_print_other_inst_src(irp, instruction->target);
16622107 fprintf(irp->f, ")");
16632108}
16642109
1665static void ir_print_check_runtime_scope(IrPrint *irp, IrInstructionCheckRuntimeScope *instruction) {
2110static void ir_print_check_runtime_scope(IrPrintSrc *irp, IrInstSrcCheckRuntimeScope *instruction) {
16662111 fprintf(irp->f, "@checkRuntimeScope(");
1667 ir_print_other_instruction(irp, instruction->scope_is_comptime);
2112 ir_print_other_inst_src(irp, instruction->scope_is_comptime);
16682113 fprintf(irp->f, ",");
1669 ir_print_other_instruction(irp, instruction->is_comptime);
2114 ir_print_other_inst_src(irp, instruction->is_comptime);
16702115 fprintf(irp->f, ")");
16712116}
16722117
1673static void ir_print_array_to_vector(IrPrint *irp, IrInstructionArrayToVector *instruction) {
2118static void ir_print_array_to_vector(IrPrintGen *irp, IrInstGenArrayToVector *instruction) {
16742119 fprintf(irp->f, "ArrayToVector(");
1675 ir_print_other_instruction(irp, instruction->array);
2120 ir_print_other_inst_gen(irp, instruction->array);
16762121 fprintf(irp->f, ")");
16772122}
16782123
1679static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *instruction) {
2124static void ir_print_vector_to_array(IrPrintGen *irp, IrInstGenVectorToArray *instruction) {
16802125 fprintf(irp->f, "VectorToArray(");
1681 ir_print_other_instruction(irp, instruction->vector);
2126 ir_print_other_inst_gen(irp, instruction->vector);
16822127 fprintf(irp->f, ")result=");
1683 ir_print_other_instruction(irp, instruction->result_loc);
2128 ir_print_other_inst_gen(irp, instruction->result_loc);
16842129}
16852130
1686static void ir_print_ptr_of_array_to_slice(IrPrint *irp, IrInstructionPtrOfArrayToSlice *instruction) {
2131static void ir_print_ptr_of_array_to_slice(IrPrintGen *irp, IrInstGenPtrOfArrayToSlice *instruction) {
16872132 fprintf(irp->f, "PtrOfArrayToSlice(");
1688 ir_print_other_instruction(irp, instruction->operand);
2133 ir_print_other_inst_gen(irp, instruction->operand);
16892134 fprintf(irp->f, ")result=");
1690 ir_print_other_instruction(irp, instruction->result_loc);
2135 ir_print_other_inst_gen(irp, instruction->result_loc);
16912136}
16922137
1693static void ir_print_assert_zero(IrPrint *irp, IrInstructionAssertZero *instruction) {
2138static void ir_print_assert_zero(IrPrintGen *irp, IrInstGenAssertZero *instruction) {
16942139 fprintf(irp->f, "AssertZero(");
1695 ir_print_other_instruction(irp, instruction->target);
2140 ir_print_other_inst_gen(irp, instruction->target);
16962141 fprintf(irp->f, ")");
16972142}
16982143
1699static void ir_print_assert_non_null(IrPrint *irp, IrInstructionAssertNonNull *instruction) {
2144static void ir_print_assert_non_null(IrPrintGen *irp, IrInstGenAssertNonNull *instruction) {
17002145 fprintf(irp->f, "AssertNonNull(");
1701 ir_print_other_instruction(irp, instruction->target);
2146 ir_print_other_inst_gen(irp, instruction->target);
17022147 fprintf(irp->f, ")");
17032148}
17042149
1705static void ir_print_resize_slice(IrPrint *irp, IrInstructionResizeSlice *instruction) {
2150static void ir_print_resize_slice(IrPrintGen *irp, IrInstGenResizeSlice *instruction) {
17062151 fprintf(irp->f, "@resizeSlice(");
1707 ir_print_other_instruction(irp, instruction->operand);
2152 ir_print_other_inst_gen(irp, instruction->operand);
17082153 fprintf(irp->f, ")result=");
1709 ir_print_other_instruction(irp, instruction->result_loc);
2154 ir_print_other_inst_gen(irp, instruction->result_loc);
17102155}
17112156
1712static void ir_print_alloca_src(IrPrint *irp, IrInstructionAllocaSrc *instruction) {
2157static void ir_print_alloca_src(IrPrintSrc *irp, IrInstSrcAlloca *instruction) {
17132158 fprintf(irp->f, "Alloca(align=");
1714 ir_print_other_instruction(irp, instruction->align);
2159 ir_print_other_inst_src(irp, instruction->align);
17152160 fprintf(irp->f, ",name=%s)", instruction->name_hint);
17162161}
17172162
1718static void ir_print_alloca_gen(IrPrint *irp, IrInstructionAllocaGen *instruction) {
2163static void ir_print_alloca_gen(IrPrintGen *irp, IrInstGenAlloca *instruction) {
17192164 fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);
17202165}
17212166
1722static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {
2167static void ir_print_end_expr(IrPrintSrc *irp, IrInstSrcEndExpr *instruction) {
17232168 fprintf(irp->f, "EndExpr(result=");
17242169 ir_print_result_loc(irp, instruction->result_loc);
17252170 fprintf(irp->f, ",value=");
1726 ir_print_other_instruction(irp, instruction->value);
2171 ir_print_other_inst_src(irp, instruction->value);
17272172 fprintf(irp->f, ")");
17282173}
17292174
1730static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
2175static void ir_print_int_to_err(IrPrintSrc *irp, IrInstSrcIntToErr *instruction) {
17312176 fprintf(irp->f, "inttoerr ");
1732 ir_print_other_instruction(irp, instruction->target);
2177 ir_print_other_inst_src(irp, instruction->target);
17332178}
17342179
1735static void ir_print_err_to_int(IrPrint *irp, IrInstructionErrToInt *instruction) {
2180static void ir_print_int_to_err(IrPrintGen *irp, IrInstGenIntToErr *instruction) {
2181 fprintf(irp->f, "inttoerr ");
2182 ir_print_other_inst_gen(irp, instruction->target);
2183}
2184
2185static void ir_print_err_to_int(IrPrintSrc *irp, IrInstSrcErrToInt *instruction) {
2186 fprintf(irp->f, "errtoint ");
2187 ir_print_other_inst_src(irp, instruction->target);
2188}
2189
2190static void ir_print_err_to_int(IrPrintGen *irp, IrInstGenErrToInt *instruction) {
17362191 fprintf(irp->f, "errtoint ");
1737 ir_print_other_instruction(irp, instruction->target);
2192 ir_print_other_inst_gen(irp, instruction->target);
17382193}
17392194
1740static void ir_print_check_switch_prongs(IrPrint *irp, IrInstructionCheckSwitchProngs *instruction) {
2195static void ir_print_check_switch_prongs(IrPrintSrc *irp, IrInstSrcCheckSwitchProngs *instruction) {
17412196 fprintf(irp->f, "@checkSwitchProngs(");
1742 ir_print_other_instruction(irp, instruction->target_value);
2197 ir_print_other_inst_src(irp, instruction->target_value);
17432198 fprintf(irp->f, ",");
17442199 for (size_t i = 0; i < instruction->range_count; i += 1) {
17452200 if (i != 0)
17462201 fprintf(irp->f, ",");
1747 ir_print_other_instruction(irp, instruction->ranges[i].start);
2202 ir_print_other_inst_src(irp, instruction->ranges[i].start);
17482203 fprintf(irp->f, "...");
1749 ir_print_other_instruction(irp, instruction->ranges[i].end);
2204 ir_print_other_inst_src(irp, instruction->ranges[i].end);
17502205 }
17512206 const char *have_else_str = instruction->have_else_prong ? "yes" : "no";
17522207 fprintf(irp->f, ")else:%s", have_else_str);
17532208}
17542209
1755static void ir_print_check_statement_is_void(IrPrint *irp, IrInstructionCheckStatementIsVoid *instruction) {
2210static void ir_print_check_statement_is_void(IrPrintSrc *irp, IrInstSrcCheckStatementIsVoid *instruction) {
17562211 fprintf(irp->f, "@checkStatementIsVoid(");
1757 ir_print_other_instruction(irp, instruction->statement_value);
2212 ir_print_other_inst_src(irp, instruction->statement_value);
17582213 fprintf(irp->f, ")");
17592214}
17602215
1761static void ir_print_type_name(IrPrint *irp, IrInstructionTypeName *instruction) {
2216static void ir_print_type_name(IrPrintSrc *irp, IrInstSrcTypeName *instruction) {
17622217 fprintf(irp->f, "typename ");
1763 ir_print_other_instruction(irp, instruction->type_value);
2218 ir_print_other_inst_src(irp, instruction->type_value);
2219}
2220
2221static void ir_print_tag_name(IrPrintSrc *irp, IrInstSrcTagName *instruction) {
2222 fprintf(irp->f, "tagname ");
2223 ir_print_other_inst_src(irp, instruction->target);
17642224}
17652225
1766static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {
2226static void ir_print_tag_name(IrPrintGen *irp, IrInstGenTagName *instruction) {
17672227 fprintf(irp->f, "tagname ");
1768 ir_print_other_instruction(irp, instruction->target);
2228 ir_print_other_inst_gen(irp, instruction->target);
17692229}
17702230
1771static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
2231static void ir_print_ptr_type(IrPrintSrc *irp, IrInstSrcPtrType *instruction) {
17722232 fprintf(irp->f, "&");
17732233 if (instruction->align_value != nullptr) {
17742234 fprintf(irp->f, "align(");
1775 ir_print_other_instruction(irp, instruction->align_value);
2235 ir_print_other_inst_src(irp, instruction->align_value);
17762236 fprintf(irp->f, ")");
17772237 }
17782238 const char *const_str = instruction->is_const ? "const " : "";
17792239 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
17802240 fprintf(irp->f, ":%" PRIu32 ":%" PRIu32 " %s%s", instruction->bit_offset_start, instruction->host_int_bytes,
17812241 const_str, volatile_str);
1782 ir_print_other_instruction(irp, instruction->child_type);
2242 ir_print_other_inst_src(irp, instruction->child_type);
17832243}
17842244
1785static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {
2245static void ir_print_decl_ref(IrPrintSrc *irp, IrInstSrcDeclRef *instruction) {
17862246 const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";
17872247 fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));
17882248}
17892249
1790static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {
2250static void ir_print_panic(IrPrintSrc *irp, IrInstSrcPanic *instruction) {
17912251 fprintf(irp->f, "@panic(");
1792 ir_print_other_instruction(irp, instruction->msg);
2252 ir_print_other_inst_src(irp, instruction->msg);
17932253 fprintf(irp->f, ")");
17942254}
17952255
1796static void ir_print_field_parent_ptr(IrPrint *irp, IrInstructionFieldParentPtr *instruction) {
2256static void ir_print_panic(IrPrintGen *irp, IrInstGenPanic *instruction) {
2257 fprintf(irp->f, "@panic(");
2258 ir_print_other_inst_gen(irp, instruction->msg);
2259 fprintf(irp->f, ")");
2260}
2261
2262static void ir_print_field_parent_ptr(IrPrintSrc *irp, IrInstSrcFieldParentPtr *instruction) {
17972263 fprintf(irp->f, "@fieldParentPtr(");
1798 ir_print_other_instruction(irp, instruction->type_value);
2264 ir_print_other_inst_src(irp, instruction->type_value);
17992265 fprintf(irp->f, ",");
1800 ir_print_other_instruction(irp, instruction->field_name);
2266 ir_print_other_inst_src(irp, instruction->field_name);
18012267 fprintf(irp->f, ",");
1802 ir_print_other_instruction(irp, instruction->field_ptr);
2268 ir_print_other_inst_src(irp, instruction->field_ptr);
18032269 fprintf(irp->f, ")");
18042270}
18052271
1806static void ir_print_byte_offset_of(IrPrint *irp, IrInstructionByteOffsetOf *instruction) {
2272static void ir_print_field_parent_ptr(IrPrintGen *irp, IrInstGenFieldParentPtr *instruction) {
2273 fprintf(irp->f, "@fieldParentPtr(%s,", buf_ptr(instruction->field->name));
2274 ir_print_other_inst_gen(irp, instruction->field_ptr);
2275 fprintf(irp->f, ")");
2276}
2277
2278static void ir_print_byte_offset_of(IrPrintSrc *irp, IrInstSrcByteOffsetOf *instruction) {
18072279 fprintf(irp->f, "@byte_offset_of(");
1808 ir_print_other_instruction(irp, instruction->type_value);
2280 ir_print_other_inst_src(irp, instruction->type_value);
18092281 fprintf(irp->f, ",");
1810 ir_print_other_instruction(irp, instruction->field_name);
2282 ir_print_other_inst_src(irp, instruction->field_name);
18112283 fprintf(irp->f, ")");
18122284}
18132285
1814static void ir_print_bit_offset_of(IrPrint *irp, IrInstructionBitOffsetOf *instruction) {
2286static void ir_print_bit_offset_of(IrPrintSrc *irp, IrInstSrcBitOffsetOf *instruction) {
18152287 fprintf(irp->f, "@bit_offset_of(");
1816 ir_print_other_instruction(irp, instruction->type_value);
2288 ir_print_other_inst_src(irp, instruction->type_value);
18172289 fprintf(irp->f, ",");
1818 ir_print_other_instruction(irp, instruction->field_name);
2290 ir_print_other_inst_src(irp, instruction->field_name);
18192291 fprintf(irp->f, ")");
18202292}
18212293
1822static void ir_print_type_info(IrPrint *irp, IrInstructionTypeInfo *instruction) {
2294static void ir_print_type_info(IrPrintSrc *irp, IrInstSrcTypeInfo *instruction) {
18232295 fprintf(irp->f, "@typeInfo(");
1824 ir_print_other_instruction(irp, instruction->type_value);
2296 ir_print_other_inst_src(irp, instruction->type_value);
18252297 fprintf(irp->f, ")");
18262298}
18272299
1828static void ir_print_type(IrPrint *irp, IrInstructionType *instruction) {
2300static void ir_print_type(IrPrintSrc *irp, IrInstSrcType *instruction) {
18292301 fprintf(irp->f, "@Type(");
1830 ir_print_other_instruction(irp, instruction->type_info);
2302 ir_print_other_inst_src(irp, instruction->type_info);
18312303 fprintf(irp->f, ")");
18322304}
18332305
1834static void ir_print_has_field(IrPrint *irp, IrInstructionHasField *instruction) {
2306static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction) {
18352307 fprintf(irp->f, "@hasField(");
1836 ir_print_other_instruction(irp, instruction->container_type);
2308 ir_print_other_inst_src(irp, instruction->container_type);
18372309 fprintf(irp->f, ",");
1838 ir_print_other_instruction(irp, instruction->field_name);
2310 ir_print_other_inst_src(irp, instruction->field_name);
18392311 fprintf(irp->f, ")");
18402312}
18412313
1842static void ir_print_type_id(IrPrint *irp, IrInstructionTypeId *instruction) {
2314static void ir_print_type_id(IrPrintSrc *irp, IrInstSrcTypeId *instruction) {
18432315 fprintf(irp->f, "@typeId(");
1844 ir_print_other_instruction(irp, instruction->type_value);
2316 ir_print_other_inst_src(irp, instruction->type_value);
18452317 fprintf(irp->f, ")");
18462318}
18472319
1848static void ir_print_set_eval_branch_quota(IrPrint *irp, IrInstructionSetEvalBranchQuota *instruction) {
2320static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {
18492321 fprintf(irp->f, "@setEvalBranchQuota(");
1850 ir_print_other_instruction(irp, instruction->new_quota);
2322 ir_print_other_inst_src(irp, instruction->new_quota);
18512323 fprintf(irp->f, ")");
18522324}
18532325
1854static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instruction) {
2326static void ir_print_align_cast(IrPrintSrc *irp, IrInstSrcAlignCast *instruction) {
18552327 fprintf(irp->f, "@alignCast(");
1856 if (instruction->align_bytes == nullptr) {
1857 fprintf(irp->f, "null");
1858 } else {
1859 ir_print_other_instruction(irp, instruction->align_bytes);
1860 }
2328 ir_print_other_inst_src(irp, instruction->align_bytes);
18612329 fprintf(irp->f, ",");
1862 ir_print_other_instruction(irp, instruction->target);
2330 ir_print_other_inst_src(irp, instruction->target);
2331 fprintf(irp->f, ")");
2332}
2333
2334static void ir_print_align_cast(IrPrintGen *irp, IrInstGenAlignCast *instruction) {
2335 fprintf(irp->f, "@alignCast(");
2336 ir_print_other_inst_gen(irp, instruction->target);
18632337 fprintf(irp->f, ")");
18642338}
18652339
1866static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {
2340static void ir_print_resolve_result(IrPrintSrc *irp, IrInstSrcResolveResult *instruction) {
18672341 fprintf(irp->f, "ResolveResult(");
18682342 ir_print_result_loc(irp, instruction->result_loc);
18692343 fprintf(irp->f, ")");
18702344}
18712345
1872static void ir_print_reset_result(IrPrint *irp, IrInstructionResetResult *instruction) {
2346static void ir_print_reset_result(IrPrintSrc *irp, IrInstSrcResetResult *instruction) {
18732347 fprintf(irp->f, "ResetResult(");
18742348 ir_print_result_loc(irp, instruction->result_loc);
18752349 fprintf(irp->f, ")");
18762350}
18772351
1878static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {
2352static void ir_print_opaque_type(IrPrintSrc *irp, IrInstSrcOpaqueType *instruction) {
18792353 fprintf(irp->f, "@OpaqueType()");
18802354}
18812355
1882static void ir_print_set_align_stack(IrPrint *irp, IrInstructionSetAlignStack *instruction) {
2356static void ir_print_set_align_stack(IrPrintSrc *irp, IrInstSrcSetAlignStack *instruction) {
18832357 fprintf(irp->f, "@setAlignStack(");
1884 ir_print_other_instruction(irp, instruction->align_bytes);
2358 ir_print_other_inst_src(irp, instruction->align_bytes);
18852359 fprintf(irp->f, ")");
18862360}
18872361
1888static void ir_print_arg_type(IrPrint *irp, IrInstructionArgType *instruction) {
2362static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {
18892363 fprintf(irp->f, "@ArgType(");
1890 ir_print_other_instruction(irp, instruction->fn_type);
2364 ir_print_other_inst_src(irp, instruction->fn_type);
18912365 fprintf(irp->f, ",");
1892 ir_print_other_instruction(irp, instruction->arg_index);
2366 ir_print_other_inst_src(irp, instruction->arg_index);
18932367 fprintf(irp->f, ")");
18942368}
18952369
1896static void ir_print_enum_tag_type(IrPrint *irp, IrInstructionTagType *instruction) {
2370static void ir_print_enum_tag_type(IrPrintSrc *irp, IrInstSrcTagType *instruction) {
18972371 fprintf(irp->f, "@TagType(");
1898 ir_print_other_instruction(irp, instruction->target);
2372 ir_print_other_inst_src(irp, instruction->target);
18992373 fprintf(irp->f, ")");
19002374}
19012375
1902static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {
2376static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) {
19032377 fprintf(irp->f, "@export(");
1904 ir_print_other_instruction(irp, instruction->target);
2378 ir_print_other_inst_src(irp, instruction->target);
19052379 fprintf(irp->f, ",");
1906 ir_print_other_instruction(irp, instruction->options);
2380 ir_print_other_inst_src(irp, instruction->options);
2381 fprintf(irp->f, ")");
2382}
2383
2384static void ir_print_error_return_trace(IrPrintSrc *irp, IrInstSrcErrorReturnTrace *instruction) {
2385 fprintf(irp->f, "@errorReturnTrace(");
2386 switch (instruction->optional) {
2387 case IrInstErrorReturnTraceNull:
2388 fprintf(irp->f, "Null");
2389 break;
2390 case IrInstErrorReturnTraceNonNull:
2391 fprintf(irp->f, "NonNull");
2392 break;
2393 }
19072394 fprintf(irp->f, ")");
19082395}
19092396
1910static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {
2397static void ir_print_error_return_trace(IrPrintGen *irp, IrInstGenErrorReturnTrace *instruction) {
19112398 fprintf(irp->f, "@errorReturnTrace(");
19122399 switch (instruction->optional) {
1913 case IrInstructionErrorReturnTrace::Null:
2400 case IrInstErrorReturnTraceNull:
19142401 fprintf(irp->f, "Null");
19152402 break;
1916 case IrInstructionErrorReturnTrace::NonNull:
2403 case IrInstErrorReturnTraceNonNull:
19172404 fprintf(irp->f, "NonNull");
19182405 break;
19192406 }
19202407 fprintf(irp->f, ")");
19212408}
19222409
1923static void ir_print_error_union(IrPrint *irp, IrInstructionErrorUnion *instruction) {
1924 ir_print_other_instruction(irp, instruction->err_set);
2410static void ir_print_error_union(IrPrintSrc *irp, IrInstSrcErrorUnion *instruction) {
2411 ir_print_other_inst_src(irp, instruction->err_set);
19252412 fprintf(irp->f, "!");
1926 ir_print_other_instruction(irp, instruction->payload);
2413 ir_print_other_inst_src(irp, instruction->payload);
19272414}
19282415
1929static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {
2416static void ir_print_atomic_rmw(IrPrintSrc *irp, IrInstSrcAtomicRmw *instruction) {
19302417 fprintf(irp->f, "@atomicRmw(");
1931 if (instruction->operand_type != nullptr) {
1932 ir_print_other_instruction(irp, instruction->operand_type);
1933 } else {
1934 fprintf(irp->f, "[TODO print]");
1935 }
2418 ir_print_other_inst_src(irp, instruction->operand_type);
19362419 fprintf(irp->f, ",");
1937 ir_print_other_instruction(irp, instruction->ptr);
2420 ir_print_other_inst_src(irp, instruction->ptr);
19382421 fprintf(irp->f, ",");
1939 if (instruction->op != nullptr) {
1940 ir_print_other_instruction(irp, instruction->op);
1941 } else {
1942 fprintf(irp->f, "[TODO print]");
1943 }
2422 ir_print_other_inst_src(irp, instruction->op);
19442423 fprintf(irp->f, ",");
1945 ir_print_other_instruction(irp, instruction->operand);
2424 ir_print_other_inst_src(irp, instruction->operand);
19462425 fprintf(irp->f, ",");
1947 if (instruction->ordering != nullptr) {
1948 ir_print_other_instruction(irp, instruction->ordering);
1949 } else {
1950 fprintf(irp->f, "[TODO print]");
1951 }
2426 ir_print_other_inst_src(irp, instruction->ordering);
19522427 fprintf(irp->f, ")");
19532428}
19542429
1955static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruction) {
2430static void ir_print_atomic_rmw(IrPrintGen *irp, IrInstGenAtomicRmw *instruction) {
2431 fprintf(irp->f, "@atomicRmw(");
2432 ir_print_other_inst_gen(irp, instruction->ptr);
2433 fprintf(irp->f, ",[TODO print op],");
2434 ir_print_other_inst_gen(irp, instruction->operand);
2435 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2436}
2437
2438static void ir_print_atomic_load(IrPrintSrc *irp, IrInstSrcAtomicLoad *instruction) {
19562439 fprintf(irp->f, "@atomicLoad(");
1957 if (instruction->operand_type != nullptr) {
1958 ir_print_other_instruction(irp, instruction->operand_type);
1959 } else {
1960 fprintf(irp->f, "[TODO print]");
1961 }
2440 ir_print_other_inst_src(irp, instruction->operand_type);
19622441 fprintf(irp->f, ",");
1963 ir_print_other_instruction(irp, instruction->ptr);
2442 ir_print_other_inst_src(irp, instruction->ptr);
19642443 fprintf(irp->f, ",");
1965 if (instruction->ordering != nullptr) {
1966 ir_print_other_instruction(irp, instruction->ordering);
1967 } else {
1968 fprintf(irp->f, "[TODO print]");
1969 }
2444 ir_print_other_inst_src(irp, instruction->ordering);
19702445 fprintf(irp->f, ")");
19712446}
19722447
1973static void ir_print_atomic_store(IrPrint *irp, IrInstructionAtomicStore *instruction) {
2448static void ir_print_atomic_load(IrPrintGen *irp, IrInstGenAtomicLoad *instruction) {
2449 fprintf(irp->f, "@atomicLoad(");
2450 ir_print_other_inst_gen(irp, instruction->ptr);
2451 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2452}
2453
2454static void ir_print_atomic_store(IrPrintSrc *irp, IrInstSrcAtomicStore *instruction) {
19742455 fprintf(irp->f, "@atomicStore(");
1975 if (instruction->operand_type != nullptr) {
1976 ir_print_other_instruction(irp, instruction->operand_type);
1977 } else {
1978 fprintf(irp->f, "[TODO print]");
1979 }
2456 ir_print_other_inst_src(irp, instruction->operand_type);
19802457 fprintf(irp->f, ",");
1981 ir_print_other_instruction(irp, instruction->ptr);
2458 ir_print_other_inst_src(irp, instruction->ptr);
19822459 fprintf(irp->f, ",");
1983 ir_print_other_instruction(irp, instruction->value);
2460 ir_print_other_inst_src(irp, instruction->value);
19842461 fprintf(irp->f, ",");
1985 if (instruction->ordering != nullptr) {
1986 ir_print_other_instruction(irp, instruction->ordering);
1987 } else {
1988 fprintf(irp->f, "[TODO print]");
1989 }
2462 ir_print_other_inst_src(irp, instruction->ordering);
19902463 fprintf(irp->f, ")");
19912464}
19922465
2466static void ir_print_atomic_store(IrPrintGen *irp, IrInstGenAtomicStore *instruction) {
2467 fprintf(irp->f, "@atomicStore(");
2468 ir_print_other_inst_gen(irp, instruction->ptr);
2469 fprintf(irp->f, ",");
2470 ir_print_other_inst_gen(irp, instruction->value);
2471 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2472}
2473
2474
2475static void ir_print_save_err_ret_addr(IrPrintSrc *irp, IrInstSrcSaveErrRetAddr *instruction) {
2476 fprintf(irp->f, "@saveErrRetAddr()");
2477}
19932478
1994static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {
2479static void ir_print_save_err_ret_addr(IrPrintGen *irp, IrInstGenSaveErrRetAddr *instruction) {
19952480 fprintf(irp->f, "@saveErrRetAddr()");
19962481}
19972482
1998static void ir_print_add_implicit_return_type(IrPrint *irp, IrInstructionAddImplicitReturnType *instruction) {
2483static void ir_print_add_implicit_return_type(IrPrintSrc *irp, IrInstSrcAddImplicitReturnType *instruction) {
19992484 fprintf(irp->f, "@addImplicitReturnType(");
2000 ir_print_other_instruction(irp, instruction->value);
2485 ir_print_other_inst_src(irp, instruction->value);
2486 fprintf(irp->f, ")");
2487}
2488
2489static void ir_print_float_op(IrPrintSrc *irp, IrInstSrcFloatOp *instruction) {
2490 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));
2491 ir_print_other_inst_src(irp, instruction->operand);
20012492 fprintf(irp->f, ")");
20022493}
20032494
2004static void ir_print_float_op(IrPrint *irp, IrInstructionFloatOp *instruction) {
2495static void ir_print_float_op(IrPrintGen *irp, IrInstGenFloatOp *instruction) {
20052496 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));
2006 ir_print_other_instruction(irp, instruction->operand);
2497 ir_print_other_inst_gen(irp, instruction->operand);
20072498 fprintf(irp->f, ")");
20082499}
20092500
2010static void ir_print_mul_add(IrPrint *irp, IrInstructionMulAdd *instruction) {
2501static void ir_print_mul_add(IrPrintSrc *irp, IrInstSrcMulAdd *instruction) {
20112502 fprintf(irp->f, "@mulAdd(");
2012 if (instruction->type_value != nullptr) {
2013 ir_print_other_instruction(irp, instruction->type_value);
2014 } else {
2015 fprintf(irp->f, "null");
2016 }
2503 ir_print_other_inst_src(irp, instruction->type_value);
20172504 fprintf(irp->f, ",");
2018 ir_print_other_instruction(irp, instruction->op1);
2505 ir_print_other_inst_src(irp, instruction->op1);
20192506 fprintf(irp->f, ",");
2020 ir_print_other_instruction(irp, instruction->op2);
2507 ir_print_other_inst_src(irp, instruction->op2);
20212508 fprintf(irp->f, ",");
2022 ir_print_other_instruction(irp, instruction->op3);
2509 ir_print_other_inst_src(irp, instruction->op3);
20232510 fprintf(irp->f, ")");
20242511}
20252512
2026static void ir_print_decl_var_gen(IrPrint *irp, IrInstructionDeclVarGen *decl_var_instruction) {
2513static void ir_print_mul_add(IrPrintGen *irp, IrInstGenMulAdd *instruction) {
2514 fprintf(irp->f, "@mulAdd(");
2515 ir_print_other_inst_gen(irp, instruction->op1);
2516 fprintf(irp->f, ",");
2517 ir_print_other_inst_gen(irp, instruction->op2);
2518 fprintf(irp->f, ",");
2519 ir_print_other_inst_gen(irp, instruction->op3);
2520 fprintf(irp->f, ")");
2521}
2522
2523static void ir_print_decl_var_gen(IrPrintGen *irp, IrInstGenDeclVar *decl_var_instruction) {
20272524 ZigVar *var = decl_var_instruction->var;
20282525 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
20292526 const char *name = decl_var_instruction->var->name;
20302527 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),
20312528 var->align_bytes);
20322529
2033 ir_print_other_instruction(irp, decl_var_instruction->var_ptr);
2034 if (decl_var_instruction->var->is_comptime != nullptr) {
2035 fprintf(irp->f, " // comptime = ");
2036 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
2037 }
2530 ir_print_other_inst_gen(irp, decl_var_instruction->var_ptr);
20382531}
20392532
2040static void ir_print_has_decl(IrPrint *irp, IrInstructionHasDecl *instruction) {
2533static void ir_print_has_decl(IrPrintSrc *irp, IrInstSrcHasDecl *instruction) {
20412534 fprintf(irp->f, "@hasDecl(");
2042 ir_print_other_instruction(irp, instruction->container);
2535 ir_print_other_inst_src(irp, instruction->container);
20432536 fprintf(irp->f, ",");
2044 ir_print_other_instruction(irp, instruction->name);
2537 ir_print_other_inst_src(irp, instruction->name);
20452538 fprintf(irp->f, ")");
20462539}
20472540
2048static void ir_print_undeclared_ident(IrPrint *irp, IrInstructionUndeclaredIdent *instruction) {
2541static void ir_print_undeclared_ident(IrPrintSrc *irp, IrInstSrcUndeclaredIdent *instruction) {
20492542 fprintf(irp->f, "@undeclaredIdent(%s)", buf_ptr(instruction->name));
20502543}
20512544
2052static void ir_print_union_init_named_field(IrPrint *irp, IrInstructionUnionInitNamedField *instruction) {
2545static void ir_print_union_init_named_field(IrPrintSrc *irp, IrInstSrcUnionInitNamedField *instruction) {
20532546 fprintf(irp->f, "@unionInit(");
2054 ir_print_other_instruction(irp, instruction->union_type);
2547 ir_print_other_inst_src(irp, instruction->union_type);
20552548 fprintf(irp->f, ", ");
2056 ir_print_other_instruction(irp, instruction->field_name);
2549 ir_print_other_inst_src(irp, instruction->field_name);
20572550 fprintf(irp->f, ", ");
2058 ir_print_other_instruction(irp, instruction->field_result_loc);
2551 ir_print_other_inst_src(irp, instruction->field_result_loc);
20592552 fprintf(irp->f, ", ");
2060 ir_print_other_instruction(irp, instruction->result_loc);
2553 ir_print_other_inst_src(irp, instruction->result_loc);
20612554 fprintf(irp->f, ")");
20622555}
20632556
2064static void ir_print_suspend_begin(IrPrint *irp, IrInstructionSuspendBegin *instruction) {
2557static void ir_print_suspend_begin(IrPrintSrc *irp, IrInstSrcSuspendBegin *instruction) {
2558 fprintf(irp->f, "@suspendBegin()");
2559}
2560
2561static void ir_print_suspend_begin(IrPrintGen *irp, IrInstGenSuspendBegin *instruction) {
20652562 fprintf(irp->f, "@suspendBegin()");
20662563}
20672564
2068static void ir_print_suspend_finish(IrPrint *irp, IrInstructionSuspendFinish *instruction) {
2565static void ir_print_suspend_finish(IrPrintSrc *irp, IrInstSrcSuspendFinish *instruction) {
2566 fprintf(irp->f, "@suspendFinish()");
2567}
2568
2569static void ir_print_suspend_finish(IrPrintGen *irp, IrInstGenSuspendFinish *instruction) {
20692570 fprintf(irp->f, "@suspendFinish()");
20702571}
20712572
2072static void ir_print_resume(IrPrint *irp, IrInstructionResume *instruction) {
2573static void ir_print_resume(IrPrintSrc *irp, IrInstSrcResume *instruction) {
20732574 fprintf(irp->f, "resume ");
2074 ir_print_other_instruction(irp, instruction->frame);
2575 ir_print_other_inst_src(irp, instruction->frame);
20752576}
20762577
2077static void ir_print_await_src(IrPrint *irp, IrInstructionAwaitSrc *instruction) {
2578static void ir_print_resume(IrPrintGen *irp, IrInstGenResume *instruction) {
2579 fprintf(irp->f, "resume ");
2580 ir_print_other_inst_gen(irp, instruction->frame);
2581}
2582
2583static void ir_print_await_src(IrPrintSrc *irp, IrInstSrcAwait *instruction) {
20782584 fprintf(irp->f, "@await(");
2079 ir_print_other_instruction(irp, instruction->frame);
2585 ir_print_other_inst_src(irp, instruction->frame);
20802586 fprintf(irp->f, ",");
20812587 ir_print_result_loc(irp, instruction->result_loc);
20822588 fprintf(irp->f, ")");
20832589}
20842590
2085static void ir_print_await_gen(IrPrint *irp, IrInstructionAwaitGen *instruction) {
2591static void ir_print_await_gen(IrPrintGen *irp, IrInstGenAwait *instruction) {
20862592 fprintf(irp->f, "@await(");
2087 ir_print_other_instruction(irp, instruction->frame);
2593 ir_print_other_inst_gen(irp, instruction->frame);
20882594 fprintf(irp->f, ",");
2089 ir_print_other_instruction(irp, instruction->result_loc);
2595 ir_print_other_inst_gen(irp, instruction->result_loc);
2596 fprintf(irp->f, ")");
2597}
2598
2599static void ir_print_spill_begin(IrPrintSrc *irp, IrInstSrcSpillBegin *instruction) {
2600 fprintf(irp->f, "@spillBegin(");
2601 ir_print_other_inst_src(irp, instruction->operand);
20902602 fprintf(irp->f, ")");
20912603}
20922604
2093static void ir_print_spill_begin(IrPrint *irp, IrInstructionSpillBegin *instruction) {
2605static void ir_print_spill_begin(IrPrintGen *irp, IrInstGenSpillBegin *instruction) {
20942606 fprintf(irp->f, "@spillBegin(");
2095 ir_print_other_instruction(irp, instruction->operand);
2607 ir_print_other_inst_gen(irp, instruction->operand);
20962608 fprintf(irp->f, ")");
20972609}
20982610
2099static void ir_print_spill_end(IrPrint *irp, IrInstructionSpillEnd *instruction) {
2611static void ir_print_spill_end(IrPrintSrc *irp, IrInstSrcSpillEnd *instruction) {
21002612 fprintf(irp->f, "@spillEnd(");
2101 ir_print_other_instruction(irp, &instruction->begin->base);
2613 ir_print_other_inst_src(irp, &instruction->begin->base);
21022614 fprintf(irp->f, ")");
21032615}
21042616
2105static void ir_print_vector_extract_elem(IrPrint *irp, IrInstructionVectorExtractElem *instruction) {
2617static void ir_print_spill_end(IrPrintGen *irp, IrInstGenSpillEnd *instruction) {
2618 fprintf(irp->f, "@spillEnd(");
2619 ir_print_other_inst_gen(irp, &instruction->begin->base);
2620 fprintf(irp->f, ")");
2621}
2622
2623static void ir_print_vector_extract_elem(IrPrintGen *irp, IrInstGenVectorExtractElem *instruction) {
21062624 fprintf(irp->f, "@vectorExtractElem(");
2107 ir_print_other_instruction(irp, instruction->vector);
2625 ir_print_other_inst_gen(irp, instruction->vector);
21082626 fprintf(irp->f, ",");
2109 ir_print_other_instruction(irp, instruction->index);
2627 ir_print_other_inst_gen(irp, instruction->index);
21102628 fprintf(irp->f, ")");
21112629}
21122630
2113static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool trailing) {
2114 ir_print_prefix(irp, instruction, trailing);
2631static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trailing) {
2632 ir_print_prefix_src(irp, instruction, trailing);
21152633 switch (instruction->id) {
2116 case IrInstructionIdInvalid:
2634 case IrInstSrcIdInvalid:
21172635 zig_unreachable();
2118 case IrInstructionIdReturn:
2119 ir_print_return(irp, (IrInstructionReturn *)instruction);
2636 case IrInstSrcIdReturn:
2637 ir_print_return_src(irp, (IrInstSrcReturn *)instruction);
2638 break;
2639 case IrInstSrcIdConst:
2640 ir_print_const(irp, (IrInstSrcConst *)instruction);
2641 break;
2642 case IrInstSrcIdBinOp:
2643 ir_print_bin_op(irp, (IrInstSrcBinOp *)instruction);
2644 break;
2645 case IrInstSrcIdMergeErrSets:
2646 ir_print_merge_err_sets(irp, (IrInstSrcMergeErrSets *)instruction);
2647 break;
2648 case IrInstSrcIdDeclVar:
2649 ir_print_decl_var_src(irp, (IrInstSrcDeclVar *)instruction);
2650 break;
2651 case IrInstSrcIdCallExtra:
2652 ir_print_call_extra(irp, (IrInstSrcCallExtra *)instruction);
2653 break;
2654 case IrInstSrcIdCall:
2655 ir_print_call_src(irp, (IrInstSrcCall *)instruction);
2656 break;
2657 case IrInstSrcIdCallArgs:
2658 ir_print_call_args(irp, (IrInstSrcCallArgs *)instruction);
2659 break;
2660 case IrInstSrcIdUnOp:
2661 ir_print_un_op(irp, (IrInstSrcUnOp *)instruction);
2662 break;
2663 case IrInstSrcIdCondBr:
2664 ir_print_cond_br(irp, (IrInstSrcCondBr *)instruction);
21202665 break;
2121 case IrInstructionIdConst:
2122 ir_print_const(irp, (IrInstructionConst *)instruction);
2666 case IrInstSrcIdBr:
2667 ir_print_br(irp, (IrInstSrcBr *)instruction);
21232668 break;
2124 case IrInstructionIdBinOp:
2125 ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);
2669 case IrInstSrcIdPhi:
2670 ir_print_phi(irp, (IrInstSrcPhi *)instruction);
21262671 break;
2127 case IrInstructionIdMergeErrSets:
2128 ir_print_merge_err_sets(irp, (IrInstructionMergeErrSets *)instruction);
2672 case IrInstSrcIdContainerInitList:
2673 ir_print_container_init_list(irp, (IrInstSrcContainerInitList *)instruction);
21292674 break;
2130 case IrInstructionIdDeclVarSrc:
2131 ir_print_decl_var_src(irp, (IrInstructionDeclVarSrc *)instruction);
2675 case IrInstSrcIdContainerInitFields:
2676 ir_print_container_init_fields(irp, (IrInstSrcContainerInitFields *)instruction);
21322677 break;
2133 case IrInstructionIdCast:
2134 ir_print_cast(irp, (IrInstructionCast *)instruction);
2678 case IrInstSrcIdUnreachable:
2679 ir_print_unreachable(irp, (IrInstSrcUnreachable *)instruction);
21352680 break;
2136 case IrInstructionIdCallExtra:
2137 ir_print_call_extra(irp, (IrInstructionCallExtra *)instruction);
2681 case IrInstSrcIdElemPtr:
2682 ir_print_elem_ptr(irp, (IrInstSrcElemPtr *)instruction);
21382683 break;
2139 case IrInstructionIdCallSrc:
2140 ir_print_call_src(irp, (IrInstructionCallSrc *)instruction);
2684 case IrInstSrcIdVarPtr:
2685 ir_print_var_ptr(irp, (IrInstSrcVarPtr *)instruction);
21412686 break;
2142 case IrInstructionIdCallSrcArgs:
2143 ir_print_call_src_args(irp, (IrInstructionCallSrcArgs *)instruction);
2687 case IrInstSrcIdLoadPtr:
2688 ir_print_load_ptr(irp, (IrInstSrcLoadPtr *)instruction);
21442689 break;
2145 case IrInstructionIdCallGen:
2146 ir_print_call_gen(irp, (IrInstructionCallGen *)instruction);
2690 case IrInstSrcIdStorePtr:
2691 ir_print_store_ptr(irp, (IrInstSrcStorePtr *)instruction);
21472692 break;
2148 case IrInstructionIdUnOp:
2149 ir_print_un_op(irp, (IrInstructionUnOp *)instruction);
2693 case IrInstSrcIdTypeOf:
2694 ir_print_typeof(irp, (IrInstSrcTypeOf *)instruction);
21502695 break;
2151 case IrInstructionIdCondBr:
2152 ir_print_cond_br(irp, (IrInstructionCondBr *)instruction);
2696 case IrInstSrcIdFieldPtr:
2697 ir_print_field_ptr(irp, (IrInstSrcFieldPtr *)instruction);
21532698 break;
2154 case IrInstructionIdBr:
2155 ir_print_br(irp, (IrInstructionBr *)instruction);
2699 case IrInstSrcIdSetCold:
2700 ir_print_set_cold(irp, (IrInstSrcSetCold *)instruction);
21562701 break;
2157 case IrInstructionIdPhi:
2158 ir_print_phi(irp, (IrInstructionPhi *)instruction);
2702 case IrInstSrcIdSetRuntimeSafety:
2703 ir_print_set_runtime_safety(irp, (IrInstSrcSetRuntimeSafety *)instruction);
21592704 break;
2160 case IrInstructionIdContainerInitList:
2161 ir_print_container_init_list(irp, (IrInstructionContainerInitList *)instruction);
2705 case IrInstSrcIdSetFloatMode:
2706 ir_print_set_float_mode(irp, (IrInstSrcSetFloatMode *)instruction);
21622707 break;
2163 case IrInstructionIdContainerInitFields:
2164 ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);
2708 case IrInstSrcIdArrayType:
2709 ir_print_array_type(irp, (IrInstSrcArrayType *)instruction);
21652710 break;
2166 case IrInstructionIdUnreachable:
2167 ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);
2711 case IrInstSrcIdSliceType:
2712 ir_print_slice_type(irp, (IrInstSrcSliceType *)instruction);
21682713 break;
2169 case IrInstructionIdElemPtr:
2170 ir_print_elem_ptr(irp, (IrInstructionElemPtr *)instruction);
2714 case IrInstSrcIdAnyFrameType:
2715 ir_print_any_frame_type(irp, (IrInstSrcAnyFrameType *)instruction);
21712716 break;
2172 case IrInstructionIdVarPtr:
2173 ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);
2717 case IrInstSrcIdAsm:
2718 ir_print_asm_src(irp, (IrInstSrcAsm *)instruction);
21742719 break;
2175 case IrInstructionIdReturnPtr:
2176 ir_print_return_ptr(irp, (IrInstructionReturnPtr *)instruction);
2720 case IrInstSrcIdSizeOf:
2721 ir_print_size_of(irp, (IrInstSrcSizeOf *)instruction);
21772722 break;
2178 case IrInstructionIdLoadPtr:
2179 ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);
2723 case IrInstSrcIdTestNonNull:
2724 ir_print_test_non_null(irp, (IrInstSrcTestNonNull *)instruction);
21802725 break;
2181 case IrInstructionIdLoadPtrGen:
2182 ir_print_load_ptr_gen(irp, (IrInstructionLoadPtrGen *)instruction);
2726 case IrInstSrcIdOptionalUnwrapPtr:
2727 ir_print_optional_unwrap_ptr(irp, (IrInstSrcOptionalUnwrapPtr *)instruction);
21832728 break;
2184 case IrInstructionIdStorePtr:
2185 ir_print_store_ptr(irp, (IrInstructionStorePtr *)instruction);
2729 case IrInstSrcIdPopCount:
2730 ir_print_pop_count(irp, (IrInstSrcPopCount *)instruction);
21862731 break;
2187 case IrInstructionIdVectorStoreElem:
2188 ir_print_vector_store_elem(irp, (IrInstructionVectorStoreElem *)instruction);
2732 case IrInstSrcIdCtz:
2733 ir_print_ctz(irp, (IrInstSrcCtz *)instruction);
21892734 break;
2190 case IrInstructionIdTypeOf:
2191 ir_print_typeof(irp, (IrInstructionTypeOf *)instruction);
2735 case IrInstSrcIdBswap:
2736 ir_print_bswap(irp, (IrInstSrcBswap *)instruction);
21922737 break;
2193 case IrInstructionIdFieldPtr:
2194 ir_print_field_ptr(irp, (IrInstructionFieldPtr *)instruction);
2738 case IrInstSrcIdBitReverse:
2739 ir_print_bit_reverse(irp, (IrInstSrcBitReverse *)instruction);
21952740 break;
2196 case IrInstructionIdStructFieldPtr:
2197 ir_print_struct_field_ptr(irp, (IrInstructionStructFieldPtr *)instruction);
2741 case IrInstSrcIdSwitchBr:
2742 ir_print_switch_br(irp, (IrInstSrcSwitchBr *)instruction);
21982743 break;
2199 case IrInstructionIdUnionFieldPtr:
2200 ir_print_union_field_ptr(irp, (IrInstructionUnionFieldPtr *)instruction);
2744 case IrInstSrcIdSwitchVar:
2745 ir_print_switch_var(irp, (IrInstSrcSwitchVar *)instruction);
22012746 break;
2202 case IrInstructionIdSetCold:
2203 ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);
2747 case IrInstSrcIdSwitchElseVar:
2748 ir_print_switch_else_var(irp, (IrInstSrcSwitchElseVar *)instruction);
22042749 break;
2205 case IrInstructionIdSetRuntimeSafety:
2206 ir_print_set_runtime_safety(irp, (IrInstructionSetRuntimeSafety *)instruction);
2750 case IrInstSrcIdSwitchTarget:
2751 ir_print_switch_target(irp, (IrInstSrcSwitchTarget *)instruction);
22072752 break;
2208 case IrInstructionIdSetFloatMode:
2209 ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);
2753 case IrInstSrcIdImport:
2754 ir_print_import(irp, (IrInstSrcImport *)instruction);
22102755 break;
2211 case IrInstructionIdArrayType:
2212 ir_print_array_type(irp, (IrInstructionArrayType *)instruction);
2756 case IrInstSrcIdRef:
2757 ir_print_ref(irp, (IrInstSrcRef *)instruction);
22132758 break;
2214 case IrInstructionIdSliceType:
2215 ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);
2759 case IrInstSrcIdCompileErr:
2760 ir_print_compile_err(irp, (IrInstSrcCompileErr *)instruction);
22162761 break;
2217 case IrInstructionIdAnyFrameType:
2218 ir_print_any_frame_type(irp, (IrInstructionAnyFrameType *)instruction);
2762 case IrInstSrcIdCompileLog:
2763 ir_print_compile_log(irp, (IrInstSrcCompileLog *)instruction);
22192764 break;
2220 case IrInstructionIdAsmSrc:
2221 ir_print_asm_src(irp, (IrInstructionAsmSrc *)instruction);
2765 case IrInstSrcIdErrName:
2766 ir_print_err_name(irp, (IrInstSrcErrName *)instruction);
22222767 break;
2223 case IrInstructionIdAsmGen:
2224 ir_print_asm_gen(irp, (IrInstructionAsmGen *)instruction);
2768 case IrInstSrcIdCImport:
2769 ir_print_c_import(irp, (IrInstSrcCImport *)instruction);
22252770 break;
2226 case IrInstructionIdSizeOf:
2227 ir_print_size_of(irp, (IrInstructionSizeOf *)instruction);
2771 case IrInstSrcIdCInclude:
2772 ir_print_c_include(irp, (IrInstSrcCInclude *)instruction);
22282773 break;
2229 case IrInstructionIdTestNonNull:
2230 ir_print_test_non_null(irp, (IrInstructionTestNonNull *)instruction);
2774 case IrInstSrcIdCDefine:
2775 ir_print_c_define(irp, (IrInstSrcCDefine *)instruction);
22312776 break;
2232 case IrInstructionIdOptionalUnwrapPtr:
2233 ir_print_optional_unwrap_ptr(irp, (IrInstructionOptionalUnwrapPtr *)instruction);
2777 case IrInstSrcIdCUndef:
2778 ir_print_c_undef(irp, (IrInstSrcCUndef *)instruction);
22342779 break;
2235 case IrInstructionIdPopCount:
2236 ir_print_pop_count(irp, (IrInstructionPopCount *)instruction);
2780 case IrInstSrcIdEmbedFile:
2781 ir_print_embed_file(irp, (IrInstSrcEmbedFile *)instruction);
22372782 break;
2238 case IrInstructionIdClz:
2239 ir_print_clz(irp, (IrInstructionClz *)instruction);
2783 case IrInstSrcIdCmpxchg:
2784 ir_print_cmpxchg_src(irp, (IrInstSrcCmpxchg *)instruction);
22402785 break;
2241 case IrInstructionIdCtz:
2242 ir_print_ctz(irp, (IrInstructionCtz *)instruction);
2786 case IrInstSrcIdFence:
2787 ir_print_fence(irp, (IrInstSrcFence *)instruction);
22432788 break;
2244 case IrInstructionIdBswap:
2245 ir_print_bswap(irp, (IrInstructionBswap *)instruction);
2789 case IrInstSrcIdTruncate:
2790 ir_print_truncate(irp, (IrInstSrcTruncate *)instruction);
22462791 break;
2247 case IrInstructionIdBitReverse:
2248 ir_print_bit_reverse(irp, (IrInstructionBitReverse *)instruction);
2792 case IrInstSrcIdIntCast:
2793 ir_print_int_cast(irp, (IrInstSrcIntCast *)instruction);
22492794 break;
2250 case IrInstructionIdSwitchBr:
2251 ir_print_switch_br(irp, (IrInstructionSwitchBr *)instruction);
2795 case IrInstSrcIdFloatCast:
2796 ir_print_float_cast(irp, (IrInstSrcFloatCast *)instruction);
22522797 break;
2253 case IrInstructionIdSwitchVar:
2254 ir_print_switch_var(irp, (IrInstructionSwitchVar *)instruction);
2798 case IrInstSrcIdErrSetCast:
2799 ir_print_err_set_cast(irp, (IrInstSrcErrSetCast *)instruction);
22552800 break;
2256 case IrInstructionIdSwitchElseVar:
2257 ir_print_switch_else_var(irp, (IrInstructionSwitchElseVar *)instruction);
2801 case IrInstSrcIdFromBytes:
2802 ir_print_from_bytes(irp, (IrInstSrcFromBytes *)instruction);
22582803 break;
2259 case IrInstructionIdSwitchTarget:
2260 ir_print_switch_target(irp, (IrInstructionSwitchTarget *)instruction);
2804 case IrInstSrcIdToBytes:
2805 ir_print_to_bytes(irp, (IrInstSrcToBytes *)instruction);
22612806 break;
2262 case IrInstructionIdUnionTag:
2263 ir_print_union_tag(irp, (IrInstructionUnionTag *)instruction);
2807 case IrInstSrcIdIntToFloat:
2808 ir_print_int_to_float(irp, (IrInstSrcIntToFloat *)instruction);
22642809 break;
2265 case IrInstructionIdImport:
2266 ir_print_import(irp, (IrInstructionImport *)instruction);
2810 case IrInstSrcIdFloatToInt:
2811 ir_print_float_to_int(irp, (IrInstSrcFloatToInt *)instruction);
22672812 break;
2268 case IrInstructionIdRef:
2269 ir_print_ref(irp, (IrInstructionRef *)instruction);
2813 case IrInstSrcIdBoolToInt:
2814 ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);
22702815 break;
2271 case IrInstructionIdRefGen:
2272 ir_print_ref_gen(irp, (IrInstructionRefGen *)instruction);
2816 case IrInstSrcIdIntType:
2817 ir_print_int_type(irp, (IrInstSrcIntType *)instruction);
22732818 break;
2274 case IrInstructionIdCompileErr:
2275 ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);
2819 case IrInstSrcIdVectorType:
2820 ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);
22762821 break;
2277 case IrInstructionIdCompileLog:
2278 ir_print_compile_log(irp, (IrInstructionCompileLog *)instruction);
2822 case IrInstSrcIdShuffleVector:
2823 ir_print_shuffle_vector(irp, (IrInstSrcShuffleVector *)instruction);
22792824 break;
2280 case IrInstructionIdErrName:
2281 ir_print_err_name(irp, (IrInstructionErrName *)instruction);
2825 case IrInstSrcIdSplat:
2826 ir_print_splat_src(irp, (IrInstSrcSplat *)instruction);
22822827 break;
2283 case IrInstructionIdCImport:
2284 ir_print_c_import(irp, (IrInstructionCImport *)instruction);
2828 case IrInstSrcIdBoolNot:
2829 ir_print_bool_not(irp, (IrInstSrcBoolNot *)instruction);
22852830 break;
2286 case IrInstructionIdCInclude:
2287 ir_print_c_include(irp, (IrInstructionCInclude *)instruction);
2831 case IrInstSrcIdMemset:
2832 ir_print_memset(irp, (IrInstSrcMemset *)instruction);
22882833 break;
2289 case IrInstructionIdCDefine:
2290 ir_print_c_define(irp, (IrInstructionCDefine *)instruction);
2834 case IrInstSrcIdMemcpy:
2835 ir_print_memcpy(irp, (IrInstSrcMemcpy *)instruction);
22912836 break;
2292 case IrInstructionIdCUndef:
2293 ir_print_c_undef(irp, (IrInstructionCUndef *)instruction);
2837 case IrInstSrcIdSlice:
2838 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
22942839 break;
2295 case IrInstructionIdEmbedFile:
2296 ir_print_embed_file(irp, (IrInstructionEmbedFile *)instruction);
2840 case IrInstSrcIdMemberCount:
2841 ir_print_member_count(irp, (IrInstSrcMemberCount *)instruction);
22972842 break;
2298 case IrInstructionIdCmpxchgSrc:
2299 ir_print_cmpxchg_src(irp, (IrInstructionCmpxchgSrc *)instruction);
2843 case IrInstSrcIdMemberType:
2844 ir_print_member_type(irp, (IrInstSrcMemberType *)instruction);
23002845 break;
2301 case IrInstructionIdCmpxchgGen:
2302 ir_print_cmpxchg_gen(irp, (IrInstructionCmpxchgGen *)instruction);
2846 case IrInstSrcIdMemberName:
2847 ir_print_member_name(irp, (IrInstSrcMemberName *)instruction);
23032848 break;
2304 case IrInstructionIdFence:
2305 ir_print_fence(irp, (IrInstructionFence *)instruction);
2849 case IrInstSrcIdBreakpoint:
2850 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
23062851 break;
2307 case IrInstructionIdTruncate:
2308 ir_print_truncate(irp, (IrInstructionTruncate *)instruction);
2852 case IrInstSrcIdReturnAddress:
2853 ir_print_return_address(irp, (IrInstSrcReturnAddress *)instruction);
23092854 break;
2310 case IrInstructionIdIntCast:
2311 ir_print_int_cast(irp, (IrInstructionIntCast *)instruction);
2855 case IrInstSrcIdFrameAddress:
2856 ir_print_frame_address(irp, (IrInstSrcFrameAddress *)instruction);
23122857 break;
2313 case IrInstructionIdFloatCast:
2314 ir_print_float_cast(irp, (IrInstructionFloatCast *)instruction);
2858 case IrInstSrcIdFrameHandle:
2859 ir_print_handle(irp, (IrInstSrcFrameHandle *)instruction);
23152860 break;
2316 case IrInstructionIdErrSetCast:
2317 ir_print_err_set_cast(irp, (IrInstructionErrSetCast *)instruction);
2861 case IrInstSrcIdFrameType:
2862 ir_print_frame_type(irp, (IrInstSrcFrameType *)instruction);
23182863 break;
2319 case IrInstructionIdFromBytes:
2320 ir_print_from_bytes(irp, (IrInstructionFromBytes *)instruction);
2864 case IrInstSrcIdFrameSize:
2865 ir_print_frame_size_src(irp, (IrInstSrcFrameSize *)instruction);
23212866 break;
2322 case IrInstructionIdToBytes:
2323 ir_print_to_bytes(irp, (IrInstructionToBytes *)instruction);
2867 case IrInstSrcIdAlignOf:
2868 ir_print_align_of(irp, (IrInstSrcAlignOf *)instruction);
23242869 break;
2325 case IrInstructionIdIntToFloat:
2326 ir_print_int_to_float(irp, (IrInstructionIntToFloat *)instruction);
2870 case IrInstSrcIdOverflowOp:
2871 ir_print_overflow_op(irp, (IrInstSrcOverflowOp *)instruction);
23272872 break;
2328 case IrInstructionIdFloatToInt:
2329 ir_print_float_to_int(irp, (IrInstructionFloatToInt *)instruction);
2873 case IrInstSrcIdTestErr:
2874 ir_print_test_err_src(irp, (IrInstSrcTestErr *)instruction);
23302875 break;
2331 case IrInstructionIdBoolToInt:
2332 ir_print_bool_to_int(irp, (IrInstructionBoolToInt *)instruction);
2876 case IrInstSrcIdUnwrapErrCode:
2877 ir_print_unwrap_err_code(irp, (IrInstSrcUnwrapErrCode *)instruction);
23332878 break;
2334 case IrInstructionIdIntType:
2335 ir_print_int_type(irp, (IrInstructionIntType *)instruction);
2879 case IrInstSrcIdUnwrapErrPayload:
2880 ir_print_unwrap_err_payload(irp, (IrInstSrcUnwrapErrPayload *)instruction);
23362881 break;
2337 case IrInstructionIdVectorType:
2338 ir_print_vector_type(irp, (IrInstructionVectorType *)instruction);
2882 case IrInstSrcIdFnProto:
2883 ir_print_fn_proto(irp, (IrInstSrcFnProto *)instruction);
23392884 break;
2340 case IrInstructionIdShuffleVector:
2341 ir_print_shuffle_vector(irp, (IrInstructionShuffleVector *)instruction);
2885 case IrInstSrcIdTestComptime:
2886 ir_print_test_comptime(irp, (IrInstSrcTestComptime *)instruction);
23422887 break;
2343 case IrInstructionIdSplatSrc:
2344 ir_print_splat_src(irp, (IrInstructionSplatSrc *)instruction);
2888 case IrInstSrcIdPtrCast:
2889 ir_print_ptr_cast_src(irp, (IrInstSrcPtrCast *)instruction);
23452890 break;
2346 case IrInstructionIdSplatGen:
2347 ir_print_splat_gen(irp, (IrInstructionSplatGen *)instruction);
2891 case IrInstSrcIdBitCast:
2892 ir_print_bit_cast_src(irp, (IrInstSrcBitCast *)instruction);
23482893 break;
2349 case IrInstructionIdBoolNot:
2350 ir_print_bool_not(irp, (IrInstructionBoolNot *)instruction);
2894 case IrInstSrcIdPtrToInt:
2895 ir_print_ptr_to_int(irp, (IrInstSrcPtrToInt *)instruction);
23512896 break;
2352 case IrInstructionIdMemset:
2353 ir_print_memset(irp, (IrInstructionMemset *)instruction);
2897 case IrInstSrcIdIntToPtr:
2898 ir_print_int_to_ptr(irp, (IrInstSrcIntToPtr *)instruction);
23542899 break;
2355 case IrInstructionIdMemcpy:
2356 ir_print_memcpy(irp, (IrInstructionMemcpy *)instruction);
2900 case IrInstSrcIdIntToEnum:
2901 ir_print_int_to_enum(irp, (IrInstSrcIntToEnum *)instruction);
23572902 break;
2358 case IrInstructionIdSliceSrc:
2359 ir_print_slice_src(irp, (IrInstructionSliceSrc *)instruction);
2903 case IrInstSrcIdIntToErr:
2904 ir_print_int_to_err(irp, (IrInstSrcIntToErr *)instruction);
23602905 break;
2361 case IrInstructionIdSliceGen:
2362 ir_print_slice_gen(irp, (IrInstructionSliceGen *)instruction);
2906 case IrInstSrcIdErrToInt:
2907 ir_print_err_to_int(irp, (IrInstSrcErrToInt *)instruction);
23632908 break;
2364 case IrInstructionIdMemberCount:
2365 ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);
2909 case IrInstSrcIdCheckSwitchProngs:
2910 ir_print_check_switch_prongs(irp, (IrInstSrcCheckSwitchProngs *)instruction);
23662911 break;
2367 case IrInstructionIdMemberType:
2368 ir_print_member_type(irp, (IrInstructionMemberType *)instruction);
2912 case IrInstSrcIdCheckStatementIsVoid:
2913 ir_print_check_statement_is_void(irp, (IrInstSrcCheckStatementIsVoid *)instruction);
23692914 break;
2370 case IrInstructionIdMemberName:
2371 ir_print_member_name(irp, (IrInstructionMemberName *)instruction);
2915 case IrInstSrcIdTypeName:
2916 ir_print_type_name(irp, (IrInstSrcTypeName *)instruction);
23722917 break;
2373 case IrInstructionIdBreakpoint:
2374 ir_print_breakpoint(irp, (IrInstructionBreakpoint *)instruction);
2918 case IrInstSrcIdTagName:
2919 ir_print_tag_name(irp, (IrInstSrcTagName *)instruction);
23752920 break;
2376 case IrInstructionIdReturnAddress:
2377 ir_print_return_address(irp, (IrInstructionReturnAddress *)instruction);
2921 case IrInstSrcIdPtrType:
2922 ir_print_ptr_type(irp, (IrInstSrcPtrType *)instruction);
23782923 break;
2379 case IrInstructionIdFrameAddress:
2380 ir_print_frame_address(irp, (IrInstructionFrameAddress *)instruction);
2924 case IrInstSrcIdDeclRef:
2925 ir_print_decl_ref(irp, (IrInstSrcDeclRef *)instruction);
23812926 break;
2382 case IrInstructionIdFrameHandle:
2383 ir_print_handle(irp, (IrInstructionFrameHandle *)instruction);
2927 case IrInstSrcIdPanic:
2928 ir_print_panic(irp, (IrInstSrcPanic *)instruction);
23842929 break;
2385 case IrInstructionIdFrameType:
2386 ir_print_frame_type(irp, (IrInstructionFrameType *)instruction);
2930 case IrInstSrcIdFieldParentPtr:
2931 ir_print_field_parent_ptr(irp, (IrInstSrcFieldParentPtr *)instruction);
23872932 break;
2388 case IrInstructionIdFrameSizeSrc:
2389 ir_print_frame_size_src(irp, (IrInstructionFrameSizeSrc *)instruction);
2933 case IrInstSrcIdByteOffsetOf:
2934 ir_print_byte_offset_of(irp, (IrInstSrcByteOffsetOf *)instruction);
23902935 break;
2391 case IrInstructionIdFrameSizeGen:
2392 ir_print_frame_size_gen(irp, (IrInstructionFrameSizeGen *)instruction);
2936 case IrInstSrcIdBitOffsetOf:
2937 ir_print_bit_offset_of(irp, (IrInstSrcBitOffsetOf *)instruction);
23932938 break;
2394 case IrInstructionIdAlignOf:
2395 ir_print_align_of(irp, (IrInstructionAlignOf *)instruction);
2939 case IrInstSrcIdTypeInfo:
2940 ir_print_type_info(irp, (IrInstSrcTypeInfo *)instruction);
23962941 break;
2397 case IrInstructionIdOverflowOp:
2398 ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);
2942 case IrInstSrcIdType:
2943 ir_print_type(irp, (IrInstSrcType *)instruction);
23992944 break;
2400 case IrInstructionIdTestErrSrc:
2401 ir_print_test_err_src(irp, (IrInstructionTestErrSrc *)instruction);
2945 case IrInstSrcIdHasField:
2946 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
24022947 break;
2403 case IrInstructionIdTestErrGen:
2404 ir_print_test_err_gen(irp, (IrInstructionTestErrGen *)instruction);
2948 case IrInstSrcIdTypeId:
2949 ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
24052950 break;
2406 case IrInstructionIdUnwrapErrCode:
2407 ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);
2951 case IrInstSrcIdSetEvalBranchQuota:
2952 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
24082953 break;
2409 case IrInstructionIdUnwrapErrPayload:
2410 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
2954 case IrInstSrcIdAlignCast:
2955 ir_print_align_cast(irp, (IrInstSrcAlignCast *)instruction);
24112956 break;
2412 case IrInstructionIdOptionalWrap:
2413 ir_print_optional_wrap(irp, (IrInstructionOptionalWrap *)instruction);
2957 case IrInstSrcIdImplicitCast:
2958 ir_print_implicit_cast(irp, (IrInstSrcImplicitCast *)instruction);
24142959 break;
2415 case IrInstructionIdErrWrapCode:
2416 ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);
2960 case IrInstSrcIdResolveResult:
2961 ir_print_resolve_result(irp, (IrInstSrcResolveResult *)instruction);
24172962 break;
2418 case IrInstructionIdErrWrapPayload:
2419 ir_print_err_wrap_payload(irp, (IrInstructionErrWrapPayload *)instruction);
2963 case IrInstSrcIdResetResult:
2964 ir_print_reset_result(irp, (IrInstSrcResetResult *)instruction);
24202965 break;
2421 case IrInstructionIdFnProto:
2422 ir_print_fn_proto(irp, (IrInstructionFnProto *)instruction);
2966 case IrInstSrcIdOpaqueType:
2967 ir_print_opaque_type(irp, (IrInstSrcOpaqueType *)instruction);
24232968 break;
2424 case IrInstructionIdTestComptime:
2425 ir_print_test_comptime(irp, (IrInstructionTestComptime *)instruction);
2969 case IrInstSrcIdSetAlignStack:
2970 ir_print_set_align_stack(irp, (IrInstSrcSetAlignStack *)instruction);
24262971 break;
2427 case IrInstructionIdPtrCastSrc:
2428 ir_print_ptr_cast_src(irp, (IrInstructionPtrCastSrc *)instruction);
2972 case IrInstSrcIdArgType:
2973 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);
24292974 break;
2430 case IrInstructionIdPtrCastGen:
2431 ir_print_ptr_cast_gen(irp, (IrInstructionPtrCastGen *)instruction);
2975 case IrInstSrcIdTagType:
2976 ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction);
24322977 break;
2433 case IrInstructionIdBitCastSrc:
2434 ir_print_bit_cast_src(irp, (IrInstructionBitCastSrc *)instruction);
2978 case IrInstSrcIdExport:
2979 ir_print_export(irp, (IrInstSrcExport *)instruction);
24352980 break;
2436 case IrInstructionIdBitCastGen:
2437 ir_print_bit_cast_gen(irp, (IrInstructionBitCastGen *)instruction);
2981 case IrInstSrcIdErrorReturnTrace:
2982 ir_print_error_return_trace(irp, (IrInstSrcErrorReturnTrace *)instruction);
24382983 break;
2439 case IrInstructionIdWidenOrShorten:
2440 ir_print_widen_or_shorten(irp, (IrInstructionWidenOrShorten *)instruction);
2984 case IrInstSrcIdErrorUnion:
2985 ir_print_error_union(irp, (IrInstSrcErrorUnion *)instruction);
24412986 break;
2442 case IrInstructionIdPtrToInt:
2443 ir_print_ptr_to_int(irp, (IrInstructionPtrToInt *)instruction);
2987 case IrInstSrcIdAtomicRmw:
2988 ir_print_atomic_rmw(irp, (IrInstSrcAtomicRmw *)instruction);
24442989 break;
2445 case IrInstructionIdIntToPtr:
2446 ir_print_int_to_ptr(irp, (IrInstructionIntToPtr *)instruction);
2990 case IrInstSrcIdSaveErrRetAddr:
2991 ir_print_save_err_ret_addr(irp, (IrInstSrcSaveErrRetAddr *)instruction);
2992 break;
2993 case IrInstSrcIdAddImplicitReturnType:
2994 ir_print_add_implicit_return_type(irp, (IrInstSrcAddImplicitReturnType *)instruction);
2995 break;
2996 case IrInstSrcIdFloatOp:
2997 ir_print_float_op(irp, (IrInstSrcFloatOp *)instruction);
2998 break;
2999 case IrInstSrcIdMulAdd:
3000 ir_print_mul_add(irp, (IrInstSrcMulAdd *)instruction);
3001 break;
3002 case IrInstSrcIdAtomicLoad:
3003 ir_print_atomic_load(irp, (IrInstSrcAtomicLoad *)instruction);
3004 break;
3005 case IrInstSrcIdAtomicStore:
3006 ir_print_atomic_store(irp, (IrInstSrcAtomicStore *)instruction);
3007 break;
3008 case IrInstSrcIdEnumToInt:
3009 ir_print_enum_to_int(irp, (IrInstSrcEnumToInt *)instruction);
3010 break;
3011 case IrInstSrcIdCheckRuntimeScope:
3012 ir_print_check_runtime_scope(irp, (IrInstSrcCheckRuntimeScope *)instruction);
3013 break;
3014 case IrInstSrcIdHasDecl:
3015 ir_print_has_decl(irp, (IrInstSrcHasDecl *)instruction);
3016 break;
3017 case IrInstSrcIdUndeclaredIdent:
3018 ir_print_undeclared_ident(irp, (IrInstSrcUndeclaredIdent *)instruction);
3019 break;
3020 case IrInstSrcIdAlloca:
3021 ir_print_alloca_src(irp, (IrInstSrcAlloca *)instruction);
3022 break;
3023 case IrInstSrcIdEndExpr:
3024 ir_print_end_expr(irp, (IrInstSrcEndExpr *)instruction);
3025 break;
3026 case IrInstSrcIdUnionInitNamedField:
3027 ir_print_union_init_named_field(irp, (IrInstSrcUnionInitNamedField *)instruction);
3028 break;
3029 case IrInstSrcIdSuspendBegin:
3030 ir_print_suspend_begin(irp, (IrInstSrcSuspendBegin *)instruction);
3031 break;
3032 case IrInstSrcIdSuspendFinish:
3033 ir_print_suspend_finish(irp, (IrInstSrcSuspendFinish *)instruction);
3034 break;
3035 case IrInstSrcIdResume:
3036 ir_print_resume(irp, (IrInstSrcResume *)instruction);
3037 break;
3038 case IrInstSrcIdAwait:
3039 ir_print_await_src(irp, (IrInstSrcAwait *)instruction);
3040 break;
3041 case IrInstSrcIdSpillBegin:
3042 ir_print_spill_begin(irp, (IrInstSrcSpillBegin *)instruction);
3043 break;
3044 case IrInstSrcIdSpillEnd:
3045 ir_print_spill_end(irp, (IrInstSrcSpillEnd *)instruction);
3046 break;
3047 case IrInstSrcIdClz:
3048 ir_print_clz(irp, (IrInstSrcClz *)instruction);
3049 break;
3050 }
3051 fprintf(irp->f, "\n");
3052}
3053
3054static void ir_print_inst_gen(IrPrintGen *irp, IrInstGen *instruction, bool trailing) {
3055 ir_print_prefix_gen(irp, instruction, trailing);
3056 switch (instruction->id) {
3057 case IrInstGenIdInvalid:
3058 zig_unreachable();
3059 case IrInstGenIdReturn:
3060 ir_print_return_gen(irp, (IrInstGenReturn *)instruction);
24473061 break;
2448 case IrInstructionIdIntToEnum:
2449 ir_print_int_to_enum(irp, (IrInstructionIntToEnum *)instruction);
3062 case IrInstGenIdConst:
3063 ir_print_const(irp, (IrInstGenConst *)instruction);
24503064 break;
2451 case IrInstructionIdIntToErr:
2452 ir_print_int_to_err(irp, (IrInstructionIntToErr *)instruction);
3065 case IrInstGenIdBinOp:
3066 ir_print_bin_op(irp, (IrInstGenBinOp *)instruction);
24533067 break;
2454 case IrInstructionIdErrToInt:
2455 ir_print_err_to_int(irp, (IrInstructionErrToInt *)instruction);
3068 case IrInstGenIdDeclVar:
3069 ir_print_decl_var_gen(irp, (IrInstGenDeclVar *)instruction);
24563070 break;
2457 case IrInstructionIdCheckSwitchProngs:
2458 ir_print_check_switch_prongs(irp, (IrInstructionCheckSwitchProngs *)instruction);
3071 case IrInstGenIdCast:
3072 ir_print_cast(irp, (IrInstGenCast *)instruction);
24593073 break;
2460 case IrInstructionIdCheckStatementIsVoid:
2461 ir_print_check_statement_is_void(irp, (IrInstructionCheckStatementIsVoid *)instruction);
3074 case IrInstGenIdCall:
3075 ir_print_call_gen(irp, (IrInstGenCall *)instruction);
24623076 break;
2463 case IrInstructionIdTypeName:
2464 ir_print_type_name(irp, (IrInstructionTypeName *)instruction);
3077 case IrInstGenIdCondBr:
3078 ir_print_cond_br(irp, (IrInstGenCondBr *)instruction);
24653079 break;
2466 case IrInstructionIdTagName:
2467 ir_print_tag_name(irp, (IrInstructionTagName *)instruction);
3080 case IrInstGenIdBr:
3081 ir_print_br(irp, (IrInstGenBr *)instruction);
24683082 break;
2469 case IrInstructionIdPtrType:
2470 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);
3083 case IrInstGenIdPhi:
3084 ir_print_phi(irp, (IrInstGenPhi *)instruction);
24713085 break;
2472 case IrInstructionIdDeclRef:
2473 ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);
3086 case IrInstGenIdUnreachable:
3087 ir_print_unreachable(irp, (IrInstGenUnreachable *)instruction);
24743088 break;
2475 case IrInstructionIdPanic:
2476 ir_print_panic(irp, (IrInstructionPanic *)instruction);
3089 case IrInstGenIdElemPtr:
3090 ir_print_elem_ptr(irp, (IrInstGenElemPtr *)instruction);
24773091 break;
2478 case IrInstructionIdFieldParentPtr:
2479 ir_print_field_parent_ptr(irp, (IrInstructionFieldParentPtr *)instruction);
3092 case IrInstGenIdVarPtr:
3093 ir_print_var_ptr(irp, (IrInstGenVarPtr *)instruction);
24803094 break;
2481 case IrInstructionIdByteOffsetOf:
2482 ir_print_byte_offset_of(irp, (IrInstructionByteOffsetOf *)instruction);
3095 case IrInstGenIdReturnPtr:
3096 ir_print_return_ptr(irp, (IrInstGenReturnPtr *)instruction);
24833097 break;
2484 case IrInstructionIdBitOffsetOf:
2485 ir_print_bit_offset_of(irp, (IrInstructionBitOffsetOf *)instruction);
3098 case IrInstGenIdLoadPtr:
3099 ir_print_load_ptr_gen(irp, (IrInstGenLoadPtr *)instruction);
24863100 break;
2487 case IrInstructionIdTypeInfo:
2488 ir_print_type_info(irp, (IrInstructionTypeInfo *)instruction);
3101 case IrInstGenIdStorePtr:
3102 ir_print_store_ptr(irp, (IrInstGenStorePtr *)instruction);
24893103 break;
2490 case IrInstructionIdType:
2491 ir_print_type(irp, (IrInstructionType *)instruction);
3104 case IrInstGenIdStructFieldPtr:
3105 ir_print_struct_field_ptr(irp, (IrInstGenStructFieldPtr *)instruction);
24923106 break;
2493 case IrInstructionIdHasField:
2494 ir_print_has_field(irp, (IrInstructionHasField *)instruction);
3107 case IrInstGenIdUnionFieldPtr:
3108 ir_print_union_field_ptr(irp, (IrInstGenUnionFieldPtr *)instruction);
24953109 break;
2496 case IrInstructionIdTypeId:
2497 ir_print_type_id(irp, (IrInstructionTypeId *)instruction);
3110 case IrInstGenIdAsm:
3111 ir_print_asm_gen(irp, (IrInstGenAsm *)instruction);
24983112 break;
2499 case IrInstructionIdSetEvalBranchQuota:
2500 ir_print_set_eval_branch_quota(irp, (IrInstructionSetEvalBranchQuota *)instruction);
3113 case IrInstGenIdTestNonNull:
3114 ir_print_test_non_null(irp, (IrInstGenTestNonNull *)instruction);
25013115 break;
2502 case IrInstructionIdAlignCast:
2503 ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);
3116 case IrInstGenIdOptionalUnwrapPtr:
3117 ir_print_optional_unwrap_ptr(irp, (IrInstGenOptionalUnwrapPtr *)instruction);
25043118 break;
2505 case IrInstructionIdImplicitCast:
2506 ir_print_implicit_cast(irp, (IrInstructionImplicitCast *)instruction);
3119 case IrInstGenIdPopCount:
3120 ir_print_pop_count(irp, (IrInstGenPopCount *)instruction);
25073121 break;
2508 case IrInstructionIdResolveResult:
2509 ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction);
3122 case IrInstGenIdClz:
3123 ir_print_clz(irp, (IrInstGenClz *)instruction);
25103124 break;
2511 case IrInstructionIdResetResult:
2512 ir_print_reset_result(irp, (IrInstructionResetResult *)instruction);
3125 case IrInstGenIdCtz:
3126 ir_print_ctz(irp, (IrInstGenCtz *)instruction);
25133127 break;
2514 case IrInstructionIdOpaqueType:
2515 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);
3128 case IrInstGenIdBswap:
3129 ir_print_bswap(irp, (IrInstGenBswap *)instruction);
25163130 break;
2517 case IrInstructionIdSetAlignStack:
2518 ir_print_set_align_stack(irp, (IrInstructionSetAlignStack *)instruction);
3131 case IrInstGenIdBitReverse:
3132 ir_print_bit_reverse(irp, (IrInstGenBitReverse *)instruction);
25193133 break;
2520 case IrInstructionIdArgType:
2521 ir_print_arg_type(irp, (IrInstructionArgType *)instruction);
3134 case IrInstGenIdSwitchBr:
3135 ir_print_switch_br(irp, (IrInstGenSwitchBr *)instruction);
25223136 break;
2523 case IrInstructionIdTagType:
2524 ir_print_enum_tag_type(irp, (IrInstructionTagType *)instruction);
3137 case IrInstGenIdUnionTag:
3138 ir_print_union_tag(irp, (IrInstGenUnionTag *)instruction);
25253139 break;
2526 case IrInstructionIdExport:
2527 ir_print_export(irp, (IrInstructionExport *)instruction);
3140 case IrInstGenIdRef:
3141 ir_print_ref_gen(irp, (IrInstGenRef *)instruction);
25283142 break;
2529 case IrInstructionIdErrorReturnTrace:
2530 ir_print_error_return_trace(irp, (IrInstructionErrorReturnTrace *)instruction);
3143 case IrInstGenIdErrName:
3144 ir_print_err_name(irp, (IrInstGenErrName *)instruction);
25313145 break;
2532 case IrInstructionIdErrorUnion:
2533 ir_print_error_union(irp, (IrInstructionErrorUnion *)instruction);
3146 case IrInstGenIdCmpxchg:
3147 ir_print_cmpxchg_gen(irp, (IrInstGenCmpxchg *)instruction);
25343148 break;
2535 case IrInstructionIdAtomicRmw:
2536 ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);
3149 case IrInstGenIdFence:
3150 ir_print_fence(irp, (IrInstGenFence *)instruction);
25373151 break;
2538 case IrInstructionIdSaveErrRetAddr:
2539 ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);
3152 case IrInstGenIdTruncate:
3153 ir_print_truncate(irp, (IrInstGenTruncate *)instruction);
25403154 break;
2541 case IrInstructionIdAddImplicitReturnType:
2542 ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);
3155 case IrInstGenIdShuffleVector:
3156 ir_print_shuffle_vector(irp, (IrInstGenShuffleVector *)instruction);
25433157 break;
2544 case IrInstructionIdFloatOp:
2545 ir_print_float_op(irp, (IrInstructionFloatOp *)instruction);
3158 case IrInstGenIdSplat:
3159 ir_print_splat_gen(irp, (IrInstGenSplat *)instruction);
25463160 break;
2547 case IrInstructionIdMulAdd:
2548 ir_print_mul_add(irp, (IrInstructionMulAdd *)instruction);
3161 case IrInstGenIdBoolNot:
3162 ir_print_bool_not(irp, (IrInstGenBoolNot *)instruction);
25493163 break;
2550 case IrInstructionIdAtomicLoad:
2551 ir_print_atomic_load(irp, (IrInstructionAtomicLoad *)instruction);
3164 case IrInstGenIdMemset:
3165 ir_print_memset(irp, (IrInstGenMemset *)instruction);
25523166 break;
2553 case IrInstructionIdAtomicStore:
2554 ir_print_atomic_store(irp, (IrInstructionAtomicStore *)instruction);
3167 case IrInstGenIdMemcpy:
3168 ir_print_memcpy(irp, (IrInstGenMemcpy *)instruction);
25553169 break;
2556 case IrInstructionIdEnumToInt:
2557 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
3170 case IrInstGenIdSlice:
3171 ir_print_slice_gen(irp, (IrInstGenSlice *)instruction);
25583172 break;
2559 case IrInstructionIdCheckRuntimeScope:
2560 ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);
3173 case IrInstGenIdBreakpoint:
3174 ir_print_breakpoint(irp, (IrInstGenBreakpoint *)instruction);
25613175 break;
2562 case IrInstructionIdDeclVarGen:
2563 ir_print_decl_var_gen(irp, (IrInstructionDeclVarGen *)instruction);
3176 case IrInstGenIdReturnAddress:
3177 ir_print_return_address(irp, (IrInstGenReturnAddress *)instruction);
25643178 break;
2565 case IrInstructionIdArrayToVector:
2566 ir_print_array_to_vector(irp, (IrInstructionArrayToVector *)instruction);
3179 case IrInstGenIdFrameAddress:
3180 ir_print_frame_address(irp, (IrInstGenFrameAddress *)instruction);
25673181 break;
2568 case IrInstructionIdVectorToArray:
2569 ir_print_vector_to_array(irp, (IrInstructionVectorToArray *)instruction);
3182 case IrInstGenIdFrameHandle:
3183 ir_print_handle(irp, (IrInstGenFrameHandle *)instruction);
25703184 break;
2571 case IrInstructionIdPtrOfArrayToSlice:
2572 ir_print_ptr_of_array_to_slice(irp, (IrInstructionPtrOfArrayToSlice *)instruction);
3185 case IrInstGenIdFrameSize:
3186 ir_print_frame_size_gen(irp, (IrInstGenFrameSize *)instruction);
25733187 break;
2574 case IrInstructionIdAssertZero:
2575 ir_print_assert_zero(irp, (IrInstructionAssertZero *)instruction);
3188 case IrInstGenIdOverflowOp:
3189 ir_print_overflow_op(irp, (IrInstGenOverflowOp *)instruction);
25763190 break;
2577 case IrInstructionIdAssertNonNull:
2578 ir_print_assert_non_null(irp, (IrInstructionAssertNonNull *)instruction);
3191 case IrInstGenIdTestErr:
3192 ir_print_test_err_gen(irp, (IrInstGenTestErr *)instruction);
25793193 break;
2580 case IrInstructionIdResizeSlice:
2581 ir_print_resize_slice(irp, (IrInstructionResizeSlice *)instruction);
3194 case IrInstGenIdUnwrapErrCode:
3195 ir_print_unwrap_err_code(irp, (IrInstGenUnwrapErrCode *)instruction);
25823196 break;
2583 case IrInstructionIdHasDecl:
2584 ir_print_has_decl(irp, (IrInstructionHasDecl *)instruction);
3197 case IrInstGenIdUnwrapErrPayload:
3198 ir_print_unwrap_err_payload(irp, (IrInstGenUnwrapErrPayload *)instruction);
25853199 break;
2586 case IrInstructionIdUndeclaredIdent:
2587 ir_print_undeclared_ident(irp, (IrInstructionUndeclaredIdent *)instruction);
3200 case IrInstGenIdOptionalWrap:
3201 ir_print_optional_wrap(irp, (IrInstGenOptionalWrap *)instruction);
25883202 break;
2589 case IrInstructionIdAllocaSrc:
2590 ir_print_alloca_src(irp, (IrInstructionAllocaSrc *)instruction);
3203 case IrInstGenIdErrWrapCode:
3204 ir_print_err_wrap_code(irp, (IrInstGenErrWrapCode *)instruction);
25913205 break;
2592 case IrInstructionIdAllocaGen:
2593 ir_print_alloca_gen(irp, (IrInstructionAllocaGen *)instruction);
3206 case IrInstGenIdErrWrapPayload:
3207 ir_print_err_wrap_payload(irp, (IrInstGenErrWrapPayload *)instruction);
25943208 break;
2595 case IrInstructionIdEndExpr:
2596 ir_print_end_expr(irp, (IrInstructionEndExpr *)instruction);
3209 case IrInstGenIdPtrCast:
3210 ir_print_ptr_cast_gen(irp, (IrInstGenPtrCast *)instruction);
25973211 break;
2598 case IrInstructionIdUnionInitNamedField:
2599 ir_print_union_init_named_field(irp, (IrInstructionUnionInitNamedField *)instruction);
3212 case IrInstGenIdBitCast:
3213 ir_print_bit_cast_gen(irp, (IrInstGenBitCast *)instruction);
26003214 break;
2601 case IrInstructionIdSuspendBegin:
2602 ir_print_suspend_begin(irp, (IrInstructionSuspendBegin *)instruction);
3215 case IrInstGenIdWidenOrShorten:
3216 ir_print_widen_or_shorten(irp, (IrInstGenWidenOrShorten *)instruction);
26033217 break;
2604 case IrInstructionIdSuspendFinish:
2605 ir_print_suspend_finish(irp, (IrInstructionSuspendFinish *)instruction);
3218 case IrInstGenIdPtrToInt:
3219 ir_print_ptr_to_int(irp, (IrInstGenPtrToInt *)instruction);
26063220 break;
2607 case IrInstructionIdResume:
2608 ir_print_resume(irp, (IrInstructionResume *)instruction);
3221 case IrInstGenIdIntToPtr:
3222 ir_print_int_to_ptr(irp, (IrInstGenIntToPtr *)instruction);
26093223 break;
2610 case IrInstructionIdAwaitSrc:
2611 ir_print_await_src(irp, (IrInstructionAwaitSrc *)instruction);
3224 case IrInstGenIdIntToEnum:
3225 ir_print_int_to_enum(irp, (IrInstGenIntToEnum *)instruction);
26123226 break;
2613 case IrInstructionIdAwaitGen:
2614 ir_print_await_gen(irp, (IrInstructionAwaitGen *)instruction);
3227 case IrInstGenIdIntToErr:
3228 ir_print_int_to_err(irp, (IrInstGenIntToErr *)instruction);
26153229 break;
2616 case IrInstructionIdSpillBegin:
2617 ir_print_spill_begin(irp, (IrInstructionSpillBegin *)instruction);
3230 case IrInstGenIdErrToInt:
3231 ir_print_err_to_int(irp, (IrInstGenErrToInt *)instruction);
26183232 break;
2619 case IrInstructionIdSpillEnd:
2620 ir_print_spill_end(irp, (IrInstructionSpillEnd *)instruction);
3233 case IrInstGenIdTagName:
3234 ir_print_tag_name(irp, (IrInstGenTagName *)instruction);
26213235 break;
2622 case IrInstructionIdVectorExtractElem:
2623 ir_print_vector_extract_elem(irp, (IrInstructionVectorExtractElem *)instruction);
3236 case IrInstGenIdPanic:
3237 ir_print_panic(irp, (IrInstGenPanic *)instruction);
3238 break;
3239 case IrInstGenIdFieldParentPtr:
3240 ir_print_field_parent_ptr(irp, (IrInstGenFieldParentPtr *)instruction);
3241 break;
3242 case IrInstGenIdAlignCast:
3243 ir_print_align_cast(irp, (IrInstGenAlignCast *)instruction);
3244 break;
3245 case IrInstGenIdErrorReturnTrace:
3246 ir_print_error_return_trace(irp, (IrInstGenErrorReturnTrace *)instruction);
3247 break;
3248 case IrInstGenIdAtomicRmw:
3249 ir_print_atomic_rmw(irp, (IrInstGenAtomicRmw *)instruction);
3250 break;
3251 case IrInstGenIdSaveErrRetAddr:
3252 ir_print_save_err_ret_addr(irp, (IrInstGenSaveErrRetAddr *)instruction);
3253 break;
3254 case IrInstGenIdFloatOp:
3255 ir_print_float_op(irp, (IrInstGenFloatOp *)instruction);
3256 break;
3257 case IrInstGenIdMulAdd:
3258 ir_print_mul_add(irp, (IrInstGenMulAdd *)instruction);
3259 break;
3260 case IrInstGenIdAtomicLoad:
3261 ir_print_atomic_load(irp, (IrInstGenAtomicLoad *)instruction);
3262 break;
3263 case IrInstGenIdAtomicStore:
3264 ir_print_atomic_store(irp, (IrInstGenAtomicStore *)instruction);
3265 break;
3266 case IrInstGenIdArrayToVector:
3267 ir_print_array_to_vector(irp, (IrInstGenArrayToVector *)instruction);
3268 break;
3269 case IrInstGenIdVectorToArray:
3270 ir_print_vector_to_array(irp, (IrInstGenVectorToArray *)instruction);
3271 break;
3272 case IrInstGenIdPtrOfArrayToSlice:
3273 ir_print_ptr_of_array_to_slice(irp, (IrInstGenPtrOfArrayToSlice *)instruction);
3274 break;
3275 case IrInstGenIdAssertZero:
3276 ir_print_assert_zero(irp, (IrInstGenAssertZero *)instruction);
3277 break;
3278 case IrInstGenIdAssertNonNull:
3279 ir_print_assert_non_null(irp, (IrInstGenAssertNonNull *)instruction);
3280 break;
3281 case IrInstGenIdResizeSlice:
3282 ir_print_resize_slice(irp, (IrInstGenResizeSlice *)instruction);
3283 break;
3284 case IrInstGenIdAlloca:
3285 ir_print_alloca_gen(irp, (IrInstGenAlloca *)instruction);
3286 break;
3287 case IrInstGenIdSuspendBegin:
3288 ir_print_suspend_begin(irp, (IrInstGenSuspendBegin *)instruction);
3289 break;
3290 case IrInstGenIdSuspendFinish:
3291 ir_print_suspend_finish(irp, (IrInstGenSuspendFinish *)instruction);
3292 break;
3293 case IrInstGenIdResume:
3294 ir_print_resume(irp, (IrInstGenResume *)instruction);
3295 break;
3296 case IrInstGenIdAwait:
3297 ir_print_await_gen(irp, (IrInstGenAwait *)instruction);
3298 break;
3299 case IrInstGenIdSpillBegin:
3300 ir_print_spill_begin(irp, (IrInstGenSpillBegin *)instruction);
3301 break;
3302 case IrInstGenIdSpillEnd:
3303 ir_print_spill_end(irp, (IrInstGenSpillEnd *)instruction);
3304 break;
3305 case IrInstGenIdVectorExtractElem:
3306 ir_print_vector_extract_elem(irp, (IrInstGenVectorExtractElem *)instruction);
3307 break;
3308 case IrInstGenIdVectorStoreElem:
3309 ir_print_vector_store_elem(irp, (IrInstGenVectorStoreElem *)instruction);
3310 break;
3311 case IrInstGenIdBinaryNot:
3312 ir_print_binary_not(irp, (IrInstGenBinaryNot *)instruction);
3313 break;
3314 case IrInstGenIdNegation:
3315 ir_print_negation(irp, (IrInstGenNegation *)instruction);
3316 break;
3317 case IrInstGenIdNegationWrapping:
3318 ir_print_negation_wrapping(irp, (IrInstGenNegationWrapping *)instruction);
26243319 break;
26253320 }
26263321 fprintf(irp->f, "\n");
26273322}
26283323
2629static void irp_print_basic_block(IrPrint *irp, IrBasicBlock *current_block) {
2630 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
3324static void irp_print_basic_block_src(IrPrintSrc *irp, IrBasicBlockSrc *current_block) {
3325 fprintf(irp->f, "%s_%" PRIu32 ":\n", current_block->name_hint, current_block->debug_id);
26313326 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
2632 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
2633 if (irp->pass != IrPassSrc) {
2634 irp->printed.put(instruction, 0);
2635 irp->pending.clear();
2636 }
2637 ir_print_instruction(irp, instruction, false);
3327 IrInstSrc *instruction = current_block->instruction_list.at(instr_i);
3328 ir_print_inst_src(irp, instruction, false);
3329 }
3330}
3331
3332static void irp_print_basic_block_gen(IrPrintGen *irp, IrBasicBlockGen *current_block) {
3333 fprintf(irp->f, "%s_%" PRIu32 ":\n", current_block->name_hint, current_block->debug_id);
3334 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
3335 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
3336 irp->printed.put(instruction, 0);
3337 irp->pending.clear();
3338 ir_print_inst_gen(irp, instruction, false);
26383339 for (size_t j = 0; j < irp->pending.length; ++j)
2639 ir_print_instruction(irp, irp->pending.at(j), true);
3340 ir_print_inst_gen(irp, irp->pending.at(j), true);
26403341 }
26413342}
26423343
2643void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass) {
2644 IrPrint ir_print = {};
2645 ir_print.pass = pass;
3344void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size) {
3345 IrPrintSrc ir_print = {};
3346 ir_print.codegen = codegen;
3347 ir_print.f = f;
3348 ir_print.indent = indent_size;
3349 ir_print.indent_size = indent_size;
3350
3351 irp_print_basic_block_src(&ir_print, bb);
3352}
3353
3354void ir_print_basic_block_gen(CodeGen *codegen, FILE *f, IrBasicBlockGen *bb, int indent_size) {
3355 IrPrintGen ir_print = {};
26463356 ir_print.codegen = codegen;
26473357 ir_print.f = f;
26483358 ir_print.indent = indent_size;
......@@ -2651,16 +3361,28 @@ void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int inden
26513361 ir_print.printed.init(64);
26523362 ir_print.pending = {};
26533363
2654 irp_print_basic_block(&ir_print, bb);
3364 irp_print_basic_block_gen(&ir_print, bb);
26553365
26563366 ir_print.pending.deinit();
26573367 ir_print.printed.deinit();
26583368}
26593369
2660void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {
2661 IrPrint ir_print = {};
2662 IrPrint *irp = &ir_print;
2663 irp->pass = pass;
3370void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size) {
3371 IrPrintSrc ir_print = {};
3372 IrPrintSrc *irp = &ir_print;
3373 irp->codegen = codegen;
3374 irp->f = f;
3375 irp->indent = indent_size;
3376 irp->indent_size = indent_size;
3377
3378 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
3379 irp_print_basic_block_src(irp, executable->basic_block_list.at(bb_i));
3380 }
3381}
3382
3383void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size) {
3384 IrPrintGen ir_print = {};
3385 IrPrintGen *irp = &ir_print;
26643386 irp->codegen = codegen;
26653387 irp->f = f;
26663388 irp->indent = indent_size;
......@@ -2670,32 +3392,27 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
26703392 irp->pending = {};
26713393
26723394 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
2673 irp_print_basic_block(irp, executable->basic_block_list.at(bb_i));
3395 irp_print_basic_block_gen(irp, executable->basic_block_list.at(bb_i));
26743396 }
26753397
26763398 irp->pending.deinit();
26773399 irp->printed.deinit();
26783400}
26793401
2680void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass) {
2681 IrPrint ir_print = {};
2682 IrPrint *irp = &ir_print;
2683 irp->pass = pass;
3402void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *instruction, int indent_size) {
3403 IrPrintSrc ir_print = {};
3404 IrPrintSrc *irp = &ir_print;
26843405 irp->codegen = codegen;
26853406 irp->f = f;
26863407 irp->indent = indent_size;
26873408 irp->indent_size = indent_size;
2688 irp->printed = {};
2689 irp->printed.init(4);
2690 irp->pending = {};
26913409
2692 ir_print_instruction(irp, instruction, false);
3410 ir_print_inst_src(irp, instruction, false);
26933411}
26943412
2695void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass) {
2696 IrPrint ir_print = {};
2697 IrPrint *irp = &ir_print;
2698 irp->pass = pass;
3413void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *instruction, int indent_size) {
3414 IrPrintGen ir_print = {};
3415 IrPrintGen *irp = &ir_print;
26993416 irp->codegen = codegen;
27003417 irp->f = f;
27013418 irp->indent = indent_size;
......@@ -2704,5 +3421,5 @@ void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_
27043421 irp->printed.init(4);
27053422 irp->pending = {};
27063423
2707 ir_print_const_value(irp, value);
3424 ir_print_inst_gen(irp, instruction, false);
27083425}
src/ir_print.hpp+8-5
......@@ -12,11 +12,14 @@
1212
1313#include <stdio.h>
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);
18void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass);
15void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size);
16void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size);
17void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *inst, int indent_size);
18void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *inst, int indent_size);
19void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size);
20void ir_print_basic_block_gen(CodeGen *codegen, FILE *f, IrBasicBlockGen *bb, int indent_size);
1921
20const char* ir_instruction_type_str(IrInstructionId id);
22const char* ir_inst_src_type_str(IrInstSrcId id);
23const char* ir_inst_gen_type_str(IrInstGenId id);
2124
2225#endif
src/parser.cpp+1-1
......@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
147147}
148148
149149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
150 AstNode *node = allocate<AstNode>(1);
150 AstNode *node = allocate<AstNode>(1, "AstNode");
151151 node->type = type;
152152 node->owner = pc->owner;
153153 return node;