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(...@@ -4588,12 +4588,12 @@ fn finishThenElseBlock(
4588 } else {4588 } else {
4589 _ = try else_scope.addBreak(break_tag, main_block, .void_value);4589 _ = try else_scope.addBreak(break_tag, main_block, .void_value);
4590 }4590 }
4591 const block_ref = parent_gz.indexToRef(main_block);
4592 if (strat.elide_store_to_block_ptr_instructions) {4591 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);
4594 } else {4593 } else {
4595 try setCondBrPayload(condbr, cond, then_scope, else_scope);4594 try setCondBrPayload(condbr, cond, then_scope, else_scope);
4596 }4595 }
4596 const block_ref = parent_gz.indexToRef(main_block);
4597 switch (rl) {4597 switch (rl) {
4598 .ref => return block_ref,4598 .ref => return block_ref,
4599 else => return rvalue(parent_gz, parent_scope, rl, block_ref, node),4599 else => return rvalue(parent_gz, parent_scope, rl, block_ref, node),
...@@ -4909,7 +4909,7 @@ fn setCondBrPayloadElideBlockStorePtr(...@@ -4909,7 +4909,7 @@ fn setCondBrPayloadElideBlockStorePtr(
4909 cond: Zir.Inst.Ref,4909 cond: Zir.Inst.Ref,
4910 then_scope: *GenZir,4910 then_scope: *GenZir,
4911 else_scope: *GenZir,4911 else_scope: *GenZir,
4912 main_block: Zir.Inst.Ref,4912 block_ptr: Zir.Inst.Ref,
4913) !void {4913) !void {
4914 const astgen = then_scope.astgen;4914 const astgen = then_scope.astgen;
49154915
...@@ -4930,7 +4930,7 @@ fn setCondBrPayloadElideBlockStorePtr(...@@ -4930,7 +4930,7 @@ fn setCondBrPayloadElideBlockStorePtr(
49304930
4931 for (then_scope.instructions.items) |src_inst| {4931 for (then_scope.instructions.items) |src_inst| {
4932 if (zir_tags[src_inst] == .store_to_block_ptr) {4932 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) {
4934 astgen.extra.items[then_body_len_index] -= 1;4934 astgen.extra.items[then_body_len_index] -= 1;
4935 continue;4935 continue;
4936 }4936 }
...@@ -4939,7 +4939,7 @@ fn setCondBrPayloadElideBlockStorePtr(...@@ -4939,7 +4939,7 @@ fn setCondBrPayloadElideBlockStorePtr(
4939 }4939 }
4940 for (else_scope.instructions.items) |src_inst| {4940 for (else_scope.instructions.items) |src_inst| {
4941 if (zir_tags[src_inst] == .store_to_block_ptr) {4941 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) {
4943 astgen.extra.items[else_body_len_index] -= 1;4943 astgen.extra.items[else_body_len_index] -= 1;
4944 continue;4944 continue;
4945 }4945 }
src/codegen/llvm.zig+23-7
...@@ -193,14 +193,9 @@ pub const Object = struct {...@@ -193,14 +193,9 @@ pub const Object = struct {
193 try stderr.print(193 try stderr.print(
194 \\Zig is expecting LLVM to understand this target: '{s}'194 \\Zig is expecting LLVM to understand this target: '{s}'
195 \\However LLVM responded with: "{s}"195 \\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
198 \\196 \\
199 ,197 ,
200 .{198 .{ llvm_target_triple, error_message },
201 llvm_target_triple,
202 error_message,
203 },
204 );199 );
205 return error.InvalidLLVMTriple;200 return error.InvalidLLVMTriple;
206 }201 }
...@@ -431,6 +426,7 @@ pub const DeclGen = struct {...@@ -431,6 +426,7 @@ pub const DeclGen = struct {
431 }426 }
432427
433 fn getLLVMType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type {428 fn getLLVMType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type {
429 log.debug("getLLVMType for {}", .{t});
434 switch (t.zigTypeTag()) {430 switch (t.zigTypeTag()) {
435 .Void => return self.context().voidType(),431 .Void => return self.context().voidType(),
436 .NoReturn => return self.context().voidType(),432 .NoReturn => return self.context().voidType(),
...@@ -465,7 +461,27 @@ pub const DeclGen = struct {...@@ -465,7 +461,27 @@ pub const DeclGen = struct {
465 return self.todo("implement optional pointers as actual pointers", .{});461 return self.todo("implement optional pointers as actual pointers", .{});
466 }462 }
467 },463 },
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}),
469 }485 }
470 }486 }
471487