@@ -33,7 +33,7 @@ struct TypeStructField;
33
33
struct CodeGen ;
34
34
struct ConstExprValue ;
35
35
struct IrInstruction ;
36
- struct IrInstructionCast ;
36
+ struct IrInstructionAlloca ;
37
37
struct IrBasicBlock ;
38
38
struct ScopeDecls ;
39
39
struct ZigWindowsSDK ;
@@ -68,6 +68,8 @@ struct IrExecutable {
68
68
Scope *begin_scope;
69
69
ZigList<Tld *> tld_list;
70
70
71
+ IrInstruction *return_result_loc;
72
+
71
73
IrInstruction *coro_handle;
72
74
IrInstruction *atomic_state_field_ptr; // this one is shared and in the promise
73
75
IrInstruction *coro_result_ptr_field_ptr;
@@ -1320,7 +1322,7 @@ struct ZigFn {
1320
1322
AstNode *fn_no_inline_set_node;
1321
1323
AstNode *fn_static_eval_set_node;
1322
1324
1323
- ZigList<IrInstruction *> alloca_list;
1325
+ ZigList<IrInstructionAlloca *> alloca_list;
1324
1326
ZigList<ZigVar *> variable_list;
1325
1327
1326
1328
Buf *section_name;
@@ -1885,6 +1887,7 @@ struct ScopeBlock {
1885
1887
Buf *name;
1886
1888
IrBasicBlock *end_block;
1887
1889
IrInstruction *is_comptime;
1890
+ IrInstruction *result_loc;
1888
1891
ZigList<IrInstruction *> *incoming_values;
1889
1892
ZigList<IrBasicBlock *> *incoming_blocks;
1890
1893
@@ -1937,6 +1940,7 @@ struct ScopeLoop {
1937
1940
IrBasicBlock *break_block;
1938
1941
IrBasicBlock *continue_block;
1939
1942
IrInstruction *is_comptime;
1943
+ IrInstruction *result_loc;
1940
1944
ZigList<IrInstruction *> *incoming_values;
1941
1945
ZigList<IrBasicBlock *> *incoming_blocks;
1942
1946
};
@@ -2029,6 +2033,8 @@ struct IrBasicBlock {
2029
2033
2030
2034
enum IrInstructionId {
2031
2035
IrInstructionIdInvalid,
2036
+ IrInstructionIdDeclVarSrc,
2037
+ IrInstructionIdDeclVarGen,
2032
2038
IrInstructionIdBr,
2033
2039
IrInstructionIdCondBr,
2034
2040
IrInstructionIdSwitchBr,
@@ -2037,7 +2043,6 @@ enum IrInstructionId {
2037
2043
IrInstructionIdPhi,
2038
2044
IrInstructionIdUnOp,
2039
2045
IrInstructionIdBinOp,
2040
- IrInstructionIdDeclVar,
2041
2046
IrInstructionIdLoadPtr,
2042
2047
IrInstructionIdStorePtr,
2043
2048
IrInstructionIdFieldPtr,
@@ -2166,9 +2171,16 @@ enum IrInstructionId {
2166
2171
IrInstructionIdMarkErrRetTracePtr,
2167
2172
IrInstructionIdSqrt,
2168
2173
IrInstructionIdErrSetCast,
2169
- IrInstructionIdToBytes,
2170
- IrInstructionIdFromBytes,
2171
2174
IrInstructionIdCheckRuntimeScope,
2175
+ IrInstructionIdResultErrorUnionPayload,
2176
+ IrInstructionIdResultReturn,
2177
+ IrInstructionIdResultBytesToSlice,
2178
+ IrInstructionIdResultSliceToBytes,
2179
+ IrInstructionIdResultParam,
2180
+ IrInstructionIdResultPtrCast,
2181
+ IrInstructionIdLoadResult,
2182
+ IrInstructionIdStoreResult,
2183
+ IrInstructionIdAlloca,
2172
2184
};
2173
2185
2174
2186
struct IrInstruction {
@@ -2190,6 +2202,21 @@ struct IrInstruction {
2190
2202
bool is_gen;
2191
2203
};
2192
2204
2205
+ struct IrInstructionDeclVarSrc {
2206
+ IrInstruction base;
2207
+
2208
+ ZigVar *var;
2209
+ IrInstruction *var_type;
2210
+ IrInstruction *align_value;
2211
+ IrInstruction *ptr;
2212
+ };
2213
+
2214
+ struct IrInstructionDeclVarGen {
2215
+ IrInstruction base;
2216
+
2217
+ ZigVar *var;
2218
+ };
2219
+
2193
2220
struct IrInstructionCondBr {
2194
2221
IrInstruction base;
2195
2222
@@ -2303,25 +2330,30 @@ struct IrInstructionBinOp {
2303
2330
bool safety_check_on;
2304
2331
};
2305
2332
2306
- struct IrInstructionDeclVar {
2333
+ struct IrInstructionLoadPtr {
2307
2334
IrInstruction base;
2308
2335
2309
- ZigVar *var;
2310
- IrInstruction *var_type;
2311
- IrInstruction *align_value;
2312
- IrInstruction *init_value;
2336
+ IrInstruction *ptr;
2313
2337
};
2314
2338
2315
- struct IrInstructionLoadPtr {
2339
+ struct IrInstructionStorePtr {
2316
2340
IrInstruction base;
2317
2341
2318
2342
IrInstruction *ptr;
2343
+ IrInstruction *value;
2319
2344
};
2320
2345
2321
- struct IrInstructionStorePtr {
2346
+ struct IrInstructionLoadResult {
2322
2347
IrInstruction base;
2323
2348
2324
2349
IrInstruction *ptr;
2350
+ IrInstruction *result_loc;
2351
+ };
2352
+
2353
+ struct IrInstructionStoreResult {
2354
+ IrInstruction base;
2355
+
2356
+ IrInstruction *result_loc;
2325
2357
IrInstruction *value;
2326
2358
};
2327
2359
@@ -2374,13 +2406,12 @@ struct IrInstructionCall {
2374
2406
ZigFn *fn_entry;
2375
2407
size_t arg_count;
2376
2408
IrInstruction **args;
2377
- bool is_comptime;
2378
- LLVMValueRef tmp_ptr;
2379
- FnInline fn_inline;
2380
- bool is_async;
2381
-
2382
2409
IrInstruction *async_allocator;
2383
2410
IrInstruction *new_stack;
2411
+ IrInstruction *result_loc;
2412
+ FnInline fn_inline;
2413
+ bool is_async;
2414
+ bool is_comptime;
2384
2415
};
2385
2416
2386
2417
struct IrInstructionConst {
@@ -2401,23 +2432,24 @@ struct IrInstructionCast {
2401
2432
IrInstruction base;
2402
2433
2403
2434
IrInstruction *value;
2435
+ IrInstruction *result_loc;
2404
2436
ZigType *dest_type;
2405
2437
CastOp cast_op;
2406
- LLVMValueRef tmp_ptr;
2407
2438
};
2408
2439
2409
2440
struct IrInstructionContainerInitList {
2410
2441
IrInstruction base;
2411
2442
2412
2443
IrInstruction *container_type;
2444
+ IrInstruction *result_loc;
2413
2445
size_t item_count;
2414
2446
IrInstruction **items;
2415
- LLVMValueRef tmp_ptr;
2416
2447
};
2417
2448
2418
2449
struct IrInstructionContainerInitFieldsField {
2419
2450
Buf *name;
2420
2451
IrInstruction *value;
2452
+ IrInstruction *result_loc;
2421
2453
AstNode *source_node;
2422
2454
TypeStructField *type_struct_field;
2423
2455
};
@@ -2439,9 +2471,9 @@ struct IrInstructionStructInit {
2439
2471
IrInstruction base;
2440
2472
2441
2473
ZigType *struct_type;
2474
+ IrInstruction *result_loc;
2442
2475
size_t field_count;
2443
2476
IrInstructionStructInitField *fields;
2444
- LLVMValueRef tmp_ptr;
2445
2477
};
2446
2478
2447
2479
struct IrInstructionUnionInit {
@@ -2450,7 +2482,7 @@ struct IrInstructionUnionInit {
2450
2482
ZigType *union_type;
2451
2483
TypeUnionField *field;
2452
2484
IrInstruction *init_value;
2453
- LLVMValueRef tmp_ptr ;
2485
+ IrInstruction *result_loc ;
2454
2486
};
2455
2487
2456
2488
struct IrInstructionUnreachable {
@@ -2523,9 +2555,9 @@ struct IrInstructionSliceType {
2523
2555
IrInstruction base;
2524
2556
2525
2557
IrInstruction *align_value;
2558
+ IrInstruction *child_type;
2526
2559
bool is_const;
2527
2560
bool is_volatile;
2528
- IrInstruction *child_type;
2529
2561
};
2530
2562
2531
2563
struct IrInstructionAsm {
@@ -2600,7 +2632,7 @@ struct IrInstructionRef {
2600
2632
IrInstruction base;
2601
2633
2602
2634
IrInstruction *value;
2603
- LLVMValueRef tmp_ptr ;
2635
+ IrInstruction *result_loc ;
2604
2636
bool is_const;
2605
2637
bool is_volatile;
2606
2638
};
@@ -2662,15 +2694,14 @@ struct IrInstructionCmpxchg {
2662
2694
IrInstruction *new_value;
2663
2695
IrInstruction *success_order_value;
2664
2696
IrInstruction *failure_order_value;
2697
+ IrInstruction *result_loc;
2665
2698
2666
2699
// if this instruction gets to runtime then we know these values:
2667
2700
ZigType *type;
2668
2701
AtomicOrder success_order;
2669
2702
AtomicOrder failure_order;
2670
2703
2671
2704
bool is_weak;
2672
-
2673
- LLVMValueRef tmp_ptr;
2674
2705
};
2675
2706
2676
2707
struct IrInstructionFence {
@@ -2710,19 +2741,6 @@ struct IrInstructionErrSetCast {
2710
2741
IrInstruction *target;
2711
2742
};
2712
2743
2713
- struct IrInstructionToBytes {
2714
- IrInstruction base;
2715
-
2716
- IrInstruction *target;
2717
- };
2718
-
2719
- struct IrInstructionFromBytes {
2720
- IrInstruction base;
2721
-
2722
- IrInstruction *dest_child_type;
2723
- IrInstruction *target;
2724
- };
2725
-
2726
2744
struct IrInstructionIntToFloat {
2727
2745
IrInstruction base;
2728
2746
@@ -2778,8 +2796,8 @@ struct IrInstructionSlice {
2778
2796
IrInstruction *ptr;
2779
2797
IrInstruction *start;
2780
2798
IrInstruction *end;
2799
+ IrInstruction *result_loc;
2781
2800
bool safety_check_on;
2782
- LLVMValueRef tmp_ptr;
2783
2801
};
2784
2802
2785
2803
struct IrInstructionMemberCount {
@@ -2867,21 +2885,21 @@ struct IrInstructionOptionalWrap {
2867
2885
IrInstruction base;
2868
2886
2869
2887
IrInstruction *value;
2870
- LLVMValueRef tmp_ptr ;
2888
+ IrInstruction *result_loc ;
2871
2889
};
2872
2890
2873
2891
struct IrInstructionErrWrapPayload {
2874
2892
IrInstruction base;
2875
2893
2876
2894
IrInstruction *value;
2877
- LLVMValueRef tmp_ptr ;
2895
+ IrInstruction *result_loc ;
2878
2896
};
2879
2897
2880
2898
struct IrInstructionErrWrapCode {
2881
2899
IrInstruction base;
2882
2900
2883
2901
IrInstruction *value;
2884
- LLVMValueRef tmp_ptr ;
2902
+ IrInstruction *result_loc ;
2885
2903
};
2886
2904
2887
2905
struct IrInstructionFnProto {
@@ -2983,6 +3001,7 @@ struct IrInstructionTypeName {
2983
3001
IrInstruction base;
2984
3002
2985
3003
IrInstruction *type_value;
3004
+ IrInstruction *result_loc;
2986
3005
};
2987
3006
2988
3007
enum LVal {
@@ -3007,6 +3026,7 @@ struct IrInstructionTagName {
3007
3026
IrInstruction base;
3008
3027
3009
3028
IrInstruction *target;
3029
+ IrInstruction *result_loc;
3010
3030
};
3011
3031
3012
3032
struct IrInstructionTagType {
@@ -3264,6 +3284,49 @@ struct IrInstructionCheckRuntimeScope {
3264
3284
IrInstruction *is_comptime;
3265
3285
};
3266
3286
3287
+ struct IrInstructionResultErrorUnionPayload {
3288
+ IrInstruction base;
3289
+
3290
+ IrInstruction *prev_result_loc;
3291
+ };
3292
+
3293
+ struct IrInstructionResultBytesToSlice {
3294
+ IrInstruction base;
3295
+
3296
+ IrInstruction *prev_result_loc;
3297
+ };
3298
+
3299
+ struct IrInstructionResultSliceToBytes {
3300
+ IrInstruction base;
3301
+
3302
+ IrInstruction *elem_type;
3303
+ IrInstruction *prev_result_loc;
3304
+ };
3305
+
3306
+ struct IrInstructionResultReturn {
3307
+ IrInstruction base;
3308
+ };
3309
+
3310
+ struct IrInstructionResultParam {
3311
+ IrInstruction base;
3312
+
3313
+ IrInstruction *fn_ref;
3314
+ size_t param_index;
3315
+ };
3316
+
3317
+ struct IrInstructionResultPtrCast {
3318
+ IrInstruction base;
3319
+
3320
+ IrInstruction *elem_type;
3321
+ IrInstruction *prev_result_loc;
3322
+ };
3323
+
3324
+ struct IrInstructionAlloca {
3325
+ IrInstruction base;
3326
+
3327
+ IrInstruction *ty;
3328
+ };
3329
+
3267
3330
static const size_t slice_ptr_index = 0 ;
3268
3331
static const size_t slice_len_index = 1 ;
3269
3332
0 commit comments