authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-13 17:56:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-13 17:56:01-07:00
log78632894dabec3c20ee2ff4348e03cfa565477ef
tree6019fb67dc5b1a5d71df11522b37a6b2d99738df
parente83cf6a4542b34e7fd64028a3b1b89dacdc2e166

AstGen: fix elision of store_to_block_ptr for condbr


2 files changed, 28 insertions(+), 12 deletions(-)

src/AstGen.zig+5-5
......@@ -4588,12 +4588,12 @@ fn finishThenElseBlock(
45884588 } else {
45894589 _ = try else_scope.addBreak(break_tag, main_block, .void_value);
45904590 }
4591 const block_ref = parent_gz.indexToRef(main_block);
45924591 if (strat.elide_store_to_block_ptr_instructions) {
4593 try setCondBrPayloadElideBlockStorePtr(condbr, cond, then_scope, else_scope, block_ref);
4592 try setCondBrPayloadElideBlockStorePtr(condbr, cond, then_scope, else_scope, block_scope.rl_ptr);
45944593 } else {
45954594 try setCondBrPayload(condbr, cond, then_scope, else_scope);
45964595 }
4596 const block_ref = parent_gz.indexToRef(main_block);
45974597 switch (rl) {
45984598 .ref => return block_ref,
45994599 else => return rvalue(parent_gz, parent_scope, rl, block_ref, node),
......@@ -4909,7 +4909,7 @@ fn setCondBrPayloadElideBlockStorePtr(
49094909 cond: Zir.Inst.Ref,
49104910 then_scope: *GenZir,
49114911 else_scope: *GenZir,
4912 main_block: Zir.Inst.Ref,
4912 block_ptr: Zir.Inst.Ref,
49134913) !void {
49144914 const astgen = then_scope.astgen;
49154915
......@@ -4930,7 +4930,7 @@ fn setCondBrPayloadElideBlockStorePtr(
49304930
49314931 for (then_scope.instructions.items) |src_inst| {
49324932 if (zir_tags[src_inst] == .store_to_block_ptr) {
4933 if (zir_datas[src_inst].bin.lhs == main_block) {
4933 if (zir_datas[src_inst].bin.lhs == block_ptr) {
49344934 astgen.extra.items[then_body_len_index] -= 1;
49354935 continue;
49364936 }
......@@ -4939,7 +4939,7 @@ fn setCondBrPayloadElideBlockStorePtr(
49394939 }
49404940 for (else_scope.instructions.items) |src_inst| {
49414941 if (zir_tags[src_inst] == .store_to_block_ptr) {
4942 if (zir_datas[src_inst].bin.lhs == main_block) {
4942 if (zir_datas[src_inst].bin.lhs == block_ptr) {
49434943 astgen.extra.items[else_body_len_index] -= 1;
49444944 continue;
49454945 }
src/codegen/llvm.zig+23-7
......@@ -193,14 +193,9 @@ pub const Object = struct {
193193 try stderr.print(
194194 \\Zig is expecting LLVM to understand this target: '{s}'
195195 \\However LLVM responded with: "{s}"
196 \\Zig is unable to continue. This is a bug in Zig:
197 \\https://github.com/ziglang/zig/issues/438
198196 \\
199197 ,
200 .{
201 llvm_target_triple,
202 error_message,
203 },
198 .{ llvm_target_triple, error_message },
204199 );
205200 return error.InvalidLLVMTriple;
206201 }
......@@ -431,6 +426,7 @@ pub const DeclGen = struct {
431426 }
432427
433428 fn getLLVMType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type {
429 log.debug("getLLVMType for {}", .{t});
434430 switch (t.zigTypeTag()) {
435431 .Void => return self.context().voidType(),
436432 .NoReturn => return self.context().voidType(),
......@@ -465,7 +461,27 @@ pub const DeclGen = struct {
465461 return self.todo("implement optional pointers as actual pointers", .{});
466462 }
467463 },
468 else => return self.todo("implement getLLVMType for type '{}'", .{t}),
464 .ComptimeInt => unreachable,
465 .ComptimeFloat => unreachable,
466 .Type => unreachable,
467 .Undefined => unreachable,
468 .Null => unreachable,
469 .EnumLiteral => unreachable,
470
471 .BoundFn => @panic("TODO remove BoundFn from the language"),
472
473 .Float,
474 .Struct,
475 .ErrorUnion,
476 .ErrorSet,
477 .Enum,
478 .Union,
479 .Fn,
480 .Opaque,
481 .Frame,
482 .AnyFrame,
483 .Vector,
484 => return self.todo("implement getLLVMType for type '{}'", .{t}),
469485 }
470486 }
471487