authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-30 23:54:15-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-01 01:13:21-05:00
log4b6740e19d57454f3c4eac0c2e9a92ce08e7ec04
treef41867e2e9fcae52ab38590a3067b0396d23aff6
parent5026b1aad550bd85d12480e0a356302e858f8eef
signaturelock-open Commit is signed but in an unrecognized format.

sometimes free stuff from Zig IR pass 1

Total bytes used in stage1 std lib tests: 3.418 -> 3.198 GiB (saving 225 MiB) There's still this from pass 1 not getting freed: Const: 6909049 items, 72 bytes each, total 474.407 MiB This is due to 2 things hanging on to references to IrAnalyze pointers: * ZigVar->owner_exec->analysis * LazyValue->ira The LazyValue one could be solved by memoizing the results after the lazy value is resolved, and then it could unref the IrAnalyze. ZigVars that are determined to be comptime const, could have their const_value set to that value, instead of using the mem_slot_index mechanism. This would prevent an IrAnalyze ref in some cases.

4 files changed, 400 insertions(+), 22 deletions(-)

src/all_types.hpp+3-1
......@@ -1565,7 +1565,7 @@ struct ZigFn {
15651565 // in the case of async functions this is the implicit return type according to the
15661566 // zig source code, not according to zig ir
15671567 ZigType *src_implicit_return_type;
1568 IrExecutable ir_executable;
1568 IrExecutable *ir_executable;
15691569 IrExecutable analyzed_executable;
15701570 size_t prealloc_bbc;
15711571 size_t prealloc_backward_branch_quota;
......@@ -2204,6 +2204,8 @@ struct ZigVar {
22042204 bool src_is_const;
22052205 bool gen_is_const;
22062206 bool is_thread_local;
2207 bool is_comptime_memoized;
2208 bool is_comptime_memoized_value;
22072209};
22082210
22092211struct ErrorTableEntry {
src/analyze.cpp+21-9
......@@ -3275,14 +3275,15 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
32753275}
32763276
32773277ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
3278 ZigFn *fn_entry = allocate<ZigFn>(1);
3278 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");
3279 fn_entry->ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");
32793280
32803281 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
32813282
32823283 fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc;
32833284 fn_entry->analyzed_executable.backward_branch_quota = &fn_entry->prealloc_backward_branch_quota;
32843285 fn_entry->analyzed_executable.fn_entry = fn_entry;
3285 fn_entry->ir_executable.fn_entry = fn_entry;
3286 fn_entry->ir_executable->fn_entry = fn_entry;
32863287 fn_entry->fn_inline = inline_value;
32873288
32883289 return fn_entry;
......@@ -4610,7 +4611,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
46104611 assert(!fn_type->data.fn.is_generic);
46114612 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
46124613
4613 ZigType *block_return_type = ir_analyze(g, &fn->ir_executable,
4614 ZigType *block_return_type = ir_analyze(g, fn->ir_executable,
46144615 &fn->analyzed_executable, fn_type_id->return_type, return_type_node);
46154616 fn->src_implicit_return_type = block_return_type;
46164617
......@@ -4706,7 +4707,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
47064707 assert(!fn_type->data.fn.is_generic);
47074708
47084709 ir_gen_fn(g, fn_table_entry);
4709 if (fn_table_entry->ir_executable.first_err_trace_msg != nullptr) {
4710 if (fn_table_entry->ir_executable->first_err_trace_msg != nullptr) {
47104711 fn_table_entry->anal_state = FnAnalStateInvalid;
47114712 return;
47124713 }
......@@ -4714,7 +4715,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
47144715 fprintf(stderr, "\n");
47154716 ast_render(stderr, fn_table_entry->body_node, 4);
47164717 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));
4717 ir_print(g, stderr, &fn_table_entry->ir_executable, 4, IrPassSrc);
4718 ir_print(g, stderr, fn_table_entry->ir_executable, 4, IrPassSrc);
47184719 fprintf(stderr, "}\n");
47194720 }
47204721
......@@ -6453,20 +6454,31 @@ Error type_resolve(CodeGen *g, ZigType *ty, ResolveStatus status) {
64536454}
64546455
64556456bool ir_get_var_is_comptime(ZigVar *var) {
6457 if (var->is_comptime_memoized)
6458 return var->is_comptime_memoized_value;
6459
6460 var->is_comptime_memoized = true;
6461
64566462 // The is_comptime field can be left null, which means not comptime.
6457 if (var->is_comptime == nullptr)
6458 return false;
6463 if (var->is_comptime == nullptr) {
6464 var->is_comptime_memoized_value = false;
6465 return var->is_comptime_memoized_value;
6466 }
64596467 // When the is_comptime field references an instruction that has to get analyzed, this
64606468 // is the value.
64616469 if (var->is_comptime->child != nullptr) {
64626470 assert(var->is_comptime->child->value->type->id == ZigTypeIdBool);
6463 return var->is_comptime->child->value->data.x_bool;
6471 var->is_comptime_memoized_value = var->is_comptime->child->value->data.x_bool;
6472 var->is_comptime = nullptr;
6473 return var->is_comptime_memoized_value;
64646474 }
64656475 // As an optimization, is_comptime values which are constant are allowed
64666476 // to be omitted from analysis. In this case, there is no child instruction
64676477 // and we simply look at the unanalyzed const parent instruction.
64686478 assert(var->is_comptime->value->type->id == ZigTypeIdBool);
6469 return var->is_comptime->value->data.x_bool;
6479 var->is_comptime_memoized_value = var->is_comptime->value->data.x_bool;
6480 var->is_comptime = nullptr;
6481 return var->is_comptime_memoized_value;
64706482}
64716483
64726484bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
src/ir.cpp+375-11
......@@ -253,6 +253,353 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
253253 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
254254static ResultLoc *no_result_loc(void);
255255
256static void destroy_instruction(IrInstruction *inst) {
257#ifdef ZIG_ENABLE_MEM_PROFILE
258 const char *name = ir_instruction_type_str(inst->id);
259#else
260 const char *name = nullptr;
261#endif
262 switch (inst->id) {
263 case IrInstructionIdInvalid:
264 zig_unreachable();
265 case IrInstructionIdReturn:
266 return destroy(reinterpret_cast<IrInstructionReturn *>(inst), name);
267 case IrInstructionIdConst:
268 return destroy(reinterpret_cast<IrInstructionConst *>(inst), name);
269 case IrInstructionIdBinOp:
270 return destroy(reinterpret_cast<IrInstructionBinOp *>(inst), name);
271 case IrInstructionIdMergeErrSets:
272 return destroy(reinterpret_cast<IrInstructionMergeErrSets *>(inst), name);
273 case IrInstructionIdDeclVarSrc:
274 return destroy(reinterpret_cast<IrInstructionDeclVarSrc *>(inst), name);
275 case IrInstructionIdCast:
276 return destroy(reinterpret_cast<IrInstructionCast *>(inst), name);
277 case IrInstructionIdCallSrc:
278 return destroy(reinterpret_cast<IrInstructionCallSrc *>(inst), name);
279 case IrInstructionIdCallGen:
280 return destroy(reinterpret_cast<IrInstructionCallGen *>(inst), name);
281 case IrInstructionIdUnOp:
282 return destroy(reinterpret_cast<IrInstructionUnOp *>(inst), name);
283 case IrInstructionIdCondBr:
284 return destroy(reinterpret_cast<IrInstructionCondBr *>(inst), name);
285 case IrInstructionIdBr:
286 return destroy(reinterpret_cast<IrInstructionBr *>(inst), name);
287 case IrInstructionIdPhi:
288 return destroy(reinterpret_cast<IrInstructionPhi *>(inst), name);
289 case IrInstructionIdContainerInitList:
290 return destroy(reinterpret_cast<IrInstructionContainerInitList *>(inst), name);
291 case IrInstructionIdContainerInitFields:
292 return destroy(reinterpret_cast<IrInstructionContainerInitFields *>(inst), name);
293 case IrInstructionIdUnreachable:
294 return destroy(reinterpret_cast<IrInstructionUnreachable *>(inst), name);
295 case IrInstructionIdElemPtr:
296 return destroy(reinterpret_cast<IrInstructionElemPtr *>(inst), name);
297 case IrInstructionIdVarPtr:
298 return destroy(reinterpret_cast<IrInstructionVarPtr *>(inst), name);
299 case IrInstructionIdReturnPtr:
300 return destroy(reinterpret_cast<IrInstructionReturnPtr *>(inst), name);
301 case IrInstructionIdLoadPtr:
302 return destroy(reinterpret_cast<IrInstructionLoadPtr *>(inst), name);
303 case IrInstructionIdLoadPtrGen:
304 return destroy(reinterpret_cast<IrInstructionLoadPtrGen *>(inst), name);
305 case IrInstructionIdStorePtr:
306 return destroy(reinterpret_cast<IrInstructionStorePtr *>(inst), name);
307 case IrInstructionIdVectorStoreElem:
308 return destroy(reinterpret_cast<IrInstructionVectorStoreElem *>(inst), name);
309 case IrInstructionIdTypeOf:
310 return destroy(reinterpret_cast<IrInstructionTypeOf *>(inst), name);
311 case IrInstructionIdFieldPtr:
312 return destroy(reinterpret_cast<IrInstructionFieldPtr *>(inst), name);
313 case IrInstructionIdStructFieldPtr:
314 return destroy(reinterpret_cast<IrInstructionStructFieldPtr *>(inst), name);
315 case IrInstructionIdUnionFieldPtr:
316 return destroy(reinterpret_cast<IrInstructionUnionFieldPtr *>(inst), name);
317 case IrInstructionIdSetCold:
318 return destroy(reinterpret_cast<IrInstructionSetCold *>(inst), name);
319 case IrInstructionIdSetRuntimeSafety:
320 return destroy(reinterpret_cast<IrInstructionSetRuntimeSafety *>(inst), name);
321 case IrInstructionIdSetFloatMode:
322 return destroy(reinterpret_cast<IrInstructionSetFloatMode *>(inst), name);
323 case IrInstructionIdArrayType:
324 return destroy(reinterpret_cast<IrInstructionArrayType *>(inst), name);
325 case IrInstructionIdSliceType:
326 return destroy(reinterpret_cast<IrInstructionSliceType *>(inst), name);
327 case IrInstructionIdAnyFrameType:
328 return destroy(reinterpret_cast<IrInstructionAnyFrameType *>(inst), name);
329 case IrInstructionIdGlobalAsm:
330 return destroy(reinterpret_cast<IrInstructionGlobalAsm *>(inst), name);
331 case IrInstructionIdAsm:
332 return destroy(reinterpret_cast<IrInstructionAsm *>(inst), name);
333 case IrInstructionIdSizeOf:
334 return destroy(reinterpret_cast<IrInstructionSizeOf *>(inst), name);
335 case IrInstructionIdTestNonNull:
336 return destroy(reinterpret_cast<IrInstructionTestNonNull *>(inst), name);
337 case IrInstructionIdOptionalUnwrapPtr:
338 return destroy(reinterpret_cast<IrInstructionOptionalUnwrapPtr *>(inst), name);
339 case IrInstructionIdPopCount:
340 return destroy(reinterpret_cast<IrInstructionPopCount *>(inst), name);
341 case IrInstructionIdClz:
342 return destroy(reinterpret_cast<IrInstructionClz *>(inst), name);
343 case IrInstructionIdCtz:
344 return destroy(reinterpret_cast<IrInstructionCtz *>(inst), name);
345 case IrInstructionIdBswap:
346 return destroy(reinterpret_cast<IrInstructionBswap *>(inst), name);
347 case IrInstructionIdBitReverse:
348 return destroy(reinterpret_cast<IrInstructionBitReverse *>(inst), name);
349 case IrInstructionIdSwitchBr:
350 return destroy(reinterpret_cast<IrInstructionSwitchBr *>(inst), name);
351 case IrInstructionIdSwitchVar:
352 return destroy(reinterpret_cast<IrInstructionSwitchVar *>(inst), name);
353 case IrInstructionIdSwitchElseVar:
354 return destroy(reinterpret_cast<IrInstructionSwitchElseVar *>(inst), name);
355 case IrInstructionIdSwitchTarget:
356 return destroy(reinterpret_cast<IrInstructionSwitchTarget *>(inst), name);
357 case IrInstructionIdUnionTag:
358 return destroy(reinterpret_cast<IrInstructionUnionTag *>(inst), name);
359 case IrInstructionIdImport:
360 return destroy(reinterpret_cast<IrInstructionImport *>(inst), name);
361 case IrInstructionIdRef:
362 return destroy(reinterpret_cast<IrInstructionRef *>(inst), name);
363 case IrInstructionIdRefGen:
364 return destroy(reinterpret_cast<IrInstructionRefGen *>(inst), name);
365 case IrInstructionIdCompileErr:
366 return destroy(reinterpret_cast<IrInstructionCompileErr *>(inst), name);
367 case IrInstructionIdCompileLog:
368 return destroy(reinterpret_cast<IrInstructionCompileLog *>(inst), name);
369 case IrInstructionIdErrName:
370 return destroy(reinterpret_cast<IrInstructionErrName *>(inst), name);
371 case IrInstructionIdCImport:
372 return destroy(reinterpret_cast<IrInstructionCImport *>(inst), name);
373 case IrInstructionIdCInclude:
374 return destroy(reinterpret_cast<IrInstructionCInclude *>(inst), name);
375 case IrInstructionIdCDefine:
376 return destroy(reinterpret_cast<IrInstructionCDefine *>(inst), name);
377 case IrInstructionIdCUndef:
378 return destroy(reinterpret_cast<IrInstructionCUndef *>(inst), name);
379 case IrInstructionIdEmbedFile:
380 return destroy(reinterpret_cast<IrInstructionEmbedFile *>(inst), name);
381 case IrInstructionIdCmpxchgSrc:
382 return destroy(reinterpret_cast<IrInstructionCmpxchgSrc *>(inst), name);
383 case IrInstructionIdCmpxchgGen:
384 return destroy(reinterpret_cast<IrInstructionCmpxchgGen *>(inst), name);
385 case IrInstructionIdFence:
386 return destroy(reinterpret_cast<IrInstructionFence *>(inst), name);
387 case IrInstructionIdTruncate:
388 return destroy(reinterpret_cast<IrInstructionTruncate *>(inst), name);
389 case IrInstructionIdIntCast:
390 return destroy(reinterpret_cast<IrInstructionIntCast *>(inst), name);
391 case IrInstructionIdFloatCast:
392 return destroy(reinterpret_cast<IrInstructionFloatCast *>(inst), name);
393 case IrInstructionIdErrSetCast:
394 return destroy(reinterpret_cast<IrInstructionErrSetCast *>(inst), name);
395 case IrInstructionIdFromBytes:
396 return destroy(reinterpret_cast<IrInstructionFromBytes *>(inst), name);
397 case IrInstructionIdToBytes:
398 return destroy(reinterpret_cast<IrInstructionToBytes *>(inst), name);
399 case IrInstructionIdIntToFloat:
400 return destroy(reinterpret_cast<IrInstructionIntToFloat *>(inst), name);
401 case IrInstructionIdFloatToInt:
402 return destroy(reinterpret_cast<IrInstructionFloatToInt *>(inst), name);
403 case IrInstructionIdBoolToInt:
404 return destroy(reinterpret_cast<IrInstructionBoolToInt *>(inst), name);
405 case IrInstructionIdIntType:
406 return destroy(reinterpret_cast<IrInstructionIntType *>(inst), name);
407 case IrInstructionIdVectorType:
408 return destroy(reinterpret_cast<IrInstructionVectorType *>(inst), name);
409 case IrInstructionIdShuffleVector:
410 return destroy(reinterpret_cast<IrInstructionShuffleVector *>(inst), name);
411 case IrInstructionIdSplatSrc:
412 return destroy(reinterpret_cast<IrInstructionSplatSrc *>(inst), name);
413 case IrInstructionIdSplatGen:
414 return destroy(reinterpret_cast<IrInstructionSplatGen *>(inst), name);
415 case IrInstructionIdBoolNot:
416 return destroy(reinterpret_cast<IrInstructionBoolNot *>(inst), name);
417 case IrInstructionIdMemset:
418 return destroy(reinterpret_cast<IrInstructionMemset *>(inst), name);
419 case IrInstructionIdMemcpy:
420 return destroy(reinterpret_cast<IrInstructionMemcpy *>(inst), name);
421 case IrInstructionIdSliceSrc:
422 return destroy(reinterpret_cast<IrInstructionSliceSrc *>(inst), name);
423 case IrInstructionIdSliceGen:
424 return destroy(reinterpret_cast<IrInstructionSliceGen *>(inst), name);
425 case IrInstructionIdMemberCount:
426 return destroy(reinterpret_cast<IrInstructionMemberCount *>(inst), name);
427 case IrInstructionIdMemberType:
428 return destroy(reinterpret_cast<IrInstructionMemberType *>(inst), name);
429 case IrInstructionIdMemberName:
430 return destroy(reinterpret_cast<IrInstructionMemberName *>(inst), name);
431 case IrInstructionIdBreakpoint:
432 return destroy(reinterpret_cast<IrInstructionBreakpoint *>(inst), name);
433 case IrInstructionIdReturnAddress:
434 return destroy(reinterpret_cast<IrInstructionReturnAddress *>(inst), name);
435 case IrInstructionIdFrameAddress:
436 return destroy(reinterpret_cast<IrInstructionFrameAddress *>(inst), name);
437 case IrInstructionIdFrameHandle:
438 return destroy(reinterpret_cast<IrInstructionFrameHandle *>(inst), name);
439 case IrInstructionIdFrameType:
440 return destroy(reinterpret_cast<IrInstructionFrameType *>(inst), name);
441 case IrInstructionIdFrameSizeSrc:
442 return destroy(reinterpret_cast<IrInstructionFrameSizeSrc *>(inst), name);
443 case IrInstructionIdFrameSizeGen:
444 return destroy(reinterpret_cast<IrInstructionFrameSizeGen *>(inst), name);
445 case IrInstructionIdAlignOf:
446 return destroy(reinterpret_cast<IrInstructionAlignOf *>(inst), name);
447 case IrInstructionIdOverflowOp:
448 return destroy(reinterpret_cast<IrInstructionOverflowOp *>(inst), name);
449 case IrInstructionIdTestErrSrc:
450 return destroy(reinterpret_cast<IrInstructionTestErrSrc *>(inst), name);
451 case IrInstructionIdTestErrGen:
452 return destroy(reinterpret_cast<IrInstructionTestErrGen *>(inst), name);
453 case IrInstructionIdUnwrapErrCode:
454 return destroy(reinterpret_cast<IrInstructionUnwrapErrCode *>(inst), name);
455 case IrInstructionIdUnwrapErrPayload:
456 return destroy(reinterpret_cast<IrInstructionUnwrapErrPayload *>(inst), name);
457 case IrInstructionIdOptionalWrap:
458 return destroy(reinterpret_cast<IrInstructionOptionalWrap *>(inst), name);
459 case IrInstructionIdErrWrapCode:
460 return destroy(reinterpret_cast<IrInstructionErrWrapCode *>(inst), name);
461 case IrInstructionIdErrWrapPayload:
462 return destroy(reinterpret_cast<IrInstructionErrWrapPayload *>(inst), name);
463 case IrInstructionIdFnProto:
464 return destroy(reinterpret_cast<IrInstructionFnProto *>(inst), name);
465 case IrInstructionIdTestComptime:
466 return destroy(reinterpret_cast<IrInstructionTestComptime *>(inst), name);
467 case IrInstructionIdPtrCastSrc:
468 return destroy(reinterpret_cast<IrInstructionPtrCastSrc *>(inst), name);
469 case IrInstructionIdPtrCastGen:
470 return destroy(reinterpret_cast<IrInstructionPtrCastGen *>(inst), name);
471 case IrInstructionIdBitCastSrc:
472 return destroy(reinterpret_cast<IrInstructionBitCastSrc *>(inst), name);
473 case IrInstructionIdBitCastGen:
474 return destroy(reinterpret_cast<IrInstructionBitCastGen *>(inst), name);
475 case IrInstructionIdWidenOrShorten:
476 return destroy(reinterpret_cast<IrInstructionWidenOrShorten *>(inst), name);
477 case IrInstructionIdPtrToInt:
478 return destroy(reinterpret_cast<IrInstructionPtrToInt *>(inst), name);
479 case IrInstructionIdIntToPtr:
480 return destroy(reinterpret_cast<IrInstructionIntToPtr *>(inst), name);
481 case IrInstructionIdIntToEnum:
482 return destroy(reinterpret_cast<IrInstructionIntToEnum *>(inst), name);
483 case IrInstructionIdIntToErr:
484 return destroy(reinterpret_cast<IrInstructionIntToErr *>(inst), name);
485 case IrInstructionIdErrToInt:
486 return destroy(reinterpret_cast<IrInstructionErrToInt *>(inst), name);
487 case IrInstructionIdCheckSwitchProngs:
488 return destroy(reinterpret_cast<IrInstructionCheckSwitchProngs *>(inst), name);
489 case IrInstructionIdCheckStatementIsVoid:
490 return destroy(reinterpret_cast<IrInstructionCheckStatementIsVoid *>(inst), name);
491 case IrInstructionIdTypeName:
492 return destroy(reinterpret_cast<IrInstructionTypeName *>(inst), name);
493 case IrInstructionIdTagName:
494 return destroy(reinterpret_cast<IrInstructionTagName *>(inst), name);
495 case IrInstructionIdPtrType:
496 return destroy(reinterpret_cast<IrInstructionPtrType *>(inst), name);
497 case IrInstructionIdDeclRef:
498 return destroy(reinterpret_cast<IrInstructionDeclRef *>(inst), name);
499 case IrInstructionIdPanic:
500 return destroy(reinterpret_cast<IrInstructionPanic *>(inst), name);
501 case IrInstructionIdFieldParentPtr:
502 return destroy(reinterpret_cast<IrInstructionFieldParentPtr *>(inst), name);
503 case IrInstructionIdByteOffsetOf:
504 return destroy(reinterpret_cast<IrInstructionByteOffsetOf *>(inst), name);
505 case IrInstructionIdBitOffsetOf:
506 return destroy(reinterpret_cast<IrInstructionBitOffsetOf *>(inst), name);
507 case IrInstructionIdTypeInfo:
508 return destroy(reinterpret_cast<IrInstructionTypeInfo *>(inst), name);
509 case IrInstructionIdType:
510 return destroy(reinterpret_cast<IrInstructionType *>(inst), name);
511 case IrInstructionIdHasField:
512 return destroy(reinterpret_cast<IrInstructionHasField *>(inst), name);
513 case IrInstructionIdTypeId:
514 return destroy(reinterpret_cast<IrInstructionTypeId *>(inst), name);
515 case IrInstructionIdSetEvalBranchQuota:
516 return destroy(reinterpret_cast<IrInstructionSetEvalBranchQuota *>(inst), name);
517 case IrInstructionIdAlignCast:
518 return destroy(reinterpret_cast<IrInstructionAlignCast *>(inst), name);
519 case IrInstructionIdImplicitCast:
520 return destroy(reinterpret_cast<IrInstructionImplicitCast *>(inst), name);
521 case IrInstructionIdResolveResult:
522 return destroy(reinterpret_cast<IrInstructionResolveResult *>(inst), name);
523 case IrInstructionIdResetResult:
524 return destroy(reinterpret_cast<IrInstructionResetResult *>(inst), name);
525 case IrInstructionIdOpaqueType:
526 return destroy(reinterpret_cast<IrInstructionOpaqueType *>(inst), name);
527 case IrInstructionIdSetAlignStack:
528 return destroy(reinterpret_cast<IrInstructionSetAlignStack *>(inst), name);
529 case IrInstructionIdArgType:
530 return destroy(reinterpret_cast<IrInstructionArgType *>(inst), name);
531 case IrInstructionIdTagType:
532 return destroy(reinterpret_cast<IrInstructionTagType *>(inst), name);
533 case IrInstructionIdExport:
534 return destroy(reinterpret_cast<IrInstructionExport *>(inst), name);
535 case IrInstructionIdErrorReturnTrace:
536 return destroy(reinterpret_cast<IrInstructionErrorReturnTrace *>(inst), name);
537 case IrInstructionIdErrorUnion:
538 return destroy(reinterpret_cast<IrInstructionErrorUnion *>(inst), name);
539 case IrInstructionIdAtomicRmw:
540 return destroy(reinterpret_cast<IrInstructionAtomicRmw *>(inst), name);
541 case IrInstructionIdSaveErrRetAddr:
542 return destroy(reinterpret_cast<IrInstructionSaveErrRetAddr *>(inst), name);
543 case IrInstructionIdAddImplicitReturnType:
544 return destroy(reinterpret_cast<IrInstructionAddImplicitReturnType *>(inst), name);
545 case IrInstructionIdFloatOp:
546 return destroy(reinterpret_cast<IrInstructionFloatOp *>(inst), name);
547 case IrInstructionIdMulAdd:
548 return destroy(reinterpret_cast<IrInstructionMulAdd *>(inst), name);
549 case IrInstructionIdAtomicLoad:
550 return destroy(reinterpret_cast<IrInstructionAtomicLoad *>(inst), name);
551 case IrInstructionIdAtomicStore:
552 return destroy(reinterpret_cast<IrInstructionAtomicStore *>(inst), name);
553 case IrInstructionIdEnumToInt:
554 return destroy(reinterpret_cast<IrInstructionEnumToInt *>(inst), name);
555 case IrInstructionIdCheckRuntimeScope:
556 return destroy(reinterpret_cast<IrInstructionCheckRuntimeScope *>(inst), name);
557 case IrInstructionIdDeclVarGen:
558 return destroy(reinterpret_cast<IrInstructionDeclVarGen *>(inst), name);
559 case IrInstructionIdArrayToVector:
560 return destroy(reinterpret_cast<IrInstructionArrayToVector *>(inst), name);
561 case IrInstructionIdVectorToArray:
562 return destroy(reinterpret_cast<IrInstructionVectorToArray *>(inst), name);
563 case IrInstructionIdPtrOfArrayToSlice:
564 return destroy(reinterpret_cast<IrInstructionPtrOfArrayToSlice *>(inst), name);
565 case IrInstructionIdAssertZero:
566 return destroy(reinterpret_cast<IrInstructionAssertZero *>(inst), name);
567 case IrInstructionIdAssertNonNull:
568 return destroy(reinterpret_cast<IrInstructionAssertNonNull *>(inst), name);
569 case IrInstructionIdResizeSlice:
570 return destroy(reinterpret_cast<IrInstructionResizeSlice *>(inst), name);
571 case IrInstructionIdHasDecl:
572 return destroy(reinterpret_cast<IrInstructionHasDecl *>(inst), name);
573 case IrInstructionIdUndeclaredIdent:
574 return destroy(reinterpret_cast<IrInstructionUndeclaredIdent *>(inst), name);
575 case IrInstructionIdAllocaSrc:
576 return destroy(reinterpret_cast<IrInstructionAllocaSrc *>(inst), name);
577 case IrInstructionIdAllocaGen:
578 return destroy(reinterpret_cast<IrInstructionAllocaGen *>(inst), name);
579 case IrInstructionIdEndExpr:
580 return destroy(reinterpret_cast<IrInstructionEndExpr *>(inst), name);
581 case IrInstructionIdUnionInitNamedField:
582 return destroy(reinterpret_cast<IrInstructionUnionInitNamedField *>(inst), name);
583 case IrInstructionIdSuspendBegin:
584 return destroy(reinterpret_cast<IrInstructionSuspendBegin *>(inst), name);
585 case IrInstructionIdSuspendFinish:
586 return destroy(reinterpret_cast<IrInstructionSuspendFinish *>(inst), name);
587 case IrInstructionIdResume:
588 return destroy(reinterpret_cast<IrInstructionResume *>(inst), name);
589 case IrInstructionIdAwaitSrc:
590 return destroy(reinterpret_cast<IrInstructionAwaitSrc *>(inst), name);
591 case IrInstructionIdAwaitGen:
592 return destroy(reinterpret_cast<IrInstructionAwaitGen *>(inst), name);
593 case IrInstructionIdSpillBegin:
594 return destroy(reinterpret_cast<IrInstructionSpillBegin *>(inst), name);
595 case IrInstructionIdSpillEnd:
596 return destroy(reinterpret_cast<IrInstructionSpillEnd *>(inst), name);
597 case IrInstructionIdVectorExtractElem:
598 return destroy(reinterpret_cast<IrInstructionVectorExtractElem *>(inst), name);
599 }
600 zig_unreachable();
601}
602
256603static void ira_ref(IrAnalyze *ira) {
257604 ira->ref_count += 1;
258605}
......@@ -262,6 +609,22 @@ static void ira_deref(IrAnalyze *ira) {
262609 return;
263610 }
264611 assert(ira->ref_count != 0);
612
613 for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) {
614 IrBasicBlock *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i];
615 for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) {
616 IrInstruction *pass1_inst = pass1_bb->instruction_list.items[inst_i];
617 destroy_instruction(pass1_inst);
618 }
619 destroy(pass1_bb, "IrBasicBlock");
620 }
621 ira->old_irb.exec->basic_block_list.deinit();
622 ira->old_irb.exec->tld_list.deinit();
623 // cannot destroy here because of var->owner_exec
624 //destroy(ira->old_irb.exec, "IrExecutablePass1");
625 ira->src_implicit_return_type_list.deinit();
626 ira->resume_stack.deinit();
627 ira->exec_context.mem_slot_list.deinit();
265628 destroy(ira, "IrAnalyze");
266629}
267630
......@@ -4202,7 +4565,7 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod
42024565 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
42034566 incoming_values[0] = val1;
42044567 incoming_values[1] = val2;
4205 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
4568 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
42064569 incoming_blocks[0] = post_val1_block;
42074570 incoming_blocks[1] = post_val2_block;
42084571
......@@ -4292,7 +4655,7 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode
42924655 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
42934656 incoming_values[0] = null_result;
42944657 incoming_values[1] = unwrapped_payload;
4295 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
4658 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
42964659 incoming_blocks[0] = after_null_block;
42974660 incoming_blocks[1] = after_ok_block;
42984661 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
......@@ -6057,7 +6420,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
60576420 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
60586421 incoming_values[0] = then_expr_result;
60596422 incoming_values[1] = else_expr_result;
6060 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
6423 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
60616424 incoming_blocks[0] = after_then_block;
60626425 incoming_blocks[1] = after_else_block;
60636426
......@@ -7409,7 +7772,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
74097772 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
74107773 incoming_values[0] = then_expr_result;
74117774 incoming_values[1] = else_expr_result;
7412 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
7775 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
74137776 incoming_blocks[0] = after_then_block;
74147777 incoming_blocks[1] = after_else_block;
74157778
......@@ -7506,7 +7869,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
75067869 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
75077870 incoming_values[0] = then_expr_result;
75087871 incoming_values[1] = else_expr_result;
7509 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
7872 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
75107873 incoming_blocks[0] = after_then_block;
75117874 incoming_blocks[1] = after_else_block;
75127875
......@@ -8102,7 +8465,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
81028465 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
81038466 incoming_values[0] = err_result;
81048467 incoming_values[1] = unwrapped_payload;
8105 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
8468 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
81068469 incoming_blocks[0] = after_err_block;
81078470 incoming_blocks[1] = after_ok_block;
81088471 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
......@@ -8690,7 +9053,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
86909053bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
86919054 assert(fn_entry);
86929055
8693 IrExecutable *ir_executable = &fn_entry->ir_executable;
9056 IrExecutable *ir_executable = fn_entry->ir_executable;
86949057 AstNode *body_node = fn_entry->body_node;
86959058
86969059 assert(fn_entry->child_scope);
......@@ -11565,7 +11928,7 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1156511928 if (expected_type != nullptr && type_is_invalid(expected_type))
1156611929 return codegen->invalid_instruction->value;
1156711930
11568 IrExecutable *ir_executable = allocate<IrExecutable>(1);
11931 IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");
1156911932 ir_executable->source_node = source_node;
1157011933 ir_executable->parent_exec = parent_exec;
1157111934 ir_executable->name = exec_name;
......@@ -11587,7 +11950,7 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1158711950 ir_print(codegen, stderr, ir_executable, 2, IrPassSrc);
1158811951 fprintf(stderr, "}\n");
1158911952 }
11590 IrExecutable *analyzed_executable = allocate<IrExecutable>(1);
11953 IrExecutable *analyzed_executable = allocate<IrExecutable>(1, "IrExecutablePass2");
1159111954 analyzed_executable->source_node = source_node;
1159211955 analyzed_executable->parent_exec = parent_exec;
1159311956 analyzed_executable->source_exec = ir_executable;
......@@ -15752,6 +16115,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1575216115 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);
1575316116 ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);
1575416117 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);
16118 ira_ref(var->owner_exec->analysis);
1575516119
1575616120 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
1575716121 return ir_const_void(ira, &decl_var_instruction->base);
......@@ -17522,8 +17886,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1752217886 if (type_is_invalid(impl_fn->type_entry))
1752317887 return ira->codegen->invalid_instruction;
1752417888
17525 impl_fn->ir_executable.source_node = call_instruction->base.source_node;
17526 impl_fn->ir_executable.parent_exec = ira->new_irb.exec;
17889 impl_fn->ir_executable->source_node = call_instruction->base.source_node;
17890 impl_fn->ir_executable->parent_exec = ira->new_irb.exec;
1752717891 impl_fn->analyzed_executable.source_node = call_instruction->base.source_node;
1752817892 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
1752917893 impl_fn->analyzed_executable.backward_branch_quota = ira->new_irb.exec->backward_branch_quota;
src/list.hpp+1-1
......@@ -13,7 +13,7 @@
1313template<typename T>
1414struct ZigList {
1515 void deinit() {
16 free(items);
16 deallocate(items, capacity);
1717 }
1818 void append(const T& item) {
1919 ensure_capacity(length + 1);