authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-25 18:46:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-25 18:46:19-07:00
log66986dd248a6f8b551509131b7268d49beb772ab
tree676365f388e9e5808b80d56bd6ba53b3e36e2031
parentb87105c9217e41cb39c09d9a569ac8bc006c2eef

stage2 llvm backend: rename getLLVMType to llvmType


1 files changed, 21 insertions(+), 21 deletions(-)

src/codegen/llvm.zig+21-21
......@@ -486,11 +486,11 @@ pub const DeclGen = struct {
486486 defer self.gpa.free(llvm_param);
487487
488488 for (fn_param_types) |fn_param, i| {
489 llvm_param[i] = try self.getLLVMType(fn_param);
489 llvm_param[i] = try self.llvmType(fn_param);
490490 }
491491
492492 const fn_type = llvm.functionType(
493 try self.getLLVMType(return_type),
493 try self.llvmType(return_type),
494494 llvm_param.ptr,
495495 @intCast(c_uint, fn_param_len),
496496 .False,
......@@ -510,8 +510,8 @@ pub const DeclGen = struct {
510510
511511 assert(decl.has_tv);
512512
513 // TODO: remove this redundant `getLLVMType`, it is also called in `genTypedValue`.
514 const llvm_type = try self.getLLVMType(decl.ty);
513 // TODO: remove this redundant `llvmType`, it is also called in `genTypedValue`.
514 const llvm_type = try self.llvmType(decl.ty);
515515 const val = try self.genTypedValue(.{ .ty = decl.ty, .val = decl.val }, null);
516516 const global = self.llvmModule().addGlobal(llvm_type, decl.name);
517517 llvm.setInitializer(global, val);
......@@ -522,8 +522,8 @@ pub const DeclGen = struct {
522522 return global;
523523 }
524524
525 fn getLLVMType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type {
526 log.debug("getLLVMType for {}", .{t});
525 fn llvmType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type {
526 log.debug("llvmType for {}", .{t});
527527 switch (t.zigTypeTag()) {
528528 .Void => return self.context().voidType(),
529529 .NoReturn => return self.context().voidType(),
......@@ -536,12 +536,12 @@ pub const DeclGen = struct {
536536 if (t.isSlice()) {
537537 return self.todo("implement slices", .{});
538538 } else {
539 const elem_type = try self.getLLVMType(t.elemType());
539 const elem_type = try self.llvmType(t.elemType());
540540 return elem_type.pointerType(0);
541541 }
542542 },
543543 .Array => {
544 const elem_type = try self.getLLVMType(t.elemType());
544 const elem_type = try self.llvmType(t.elemType());
545545 return elem_type.arrayType(@intCast(c_uint, t.abiSize(self.module.getTarget())));
546546 },
547547 .Optional => {
......@@ -550,7 +550,7 @@ pub const DeclGen = struct {
550550 const child_type = t.optionalChild(&buf);
551551
552552 var optional_types: [2]*const llvm.Type = .{
553 try self.getLLVMType(child_type),
553 try self.llvmType(child_type),
554554 self.context().intType(1),
555555 };
556556 return self.context().structType(&optional_types, 2, .False);
......@@ -578,13 +578,13 @@ pub const DeclGen = struct {
578578 .Frame,
579579 .AnyFrame,
580580 .Vector,
581 => return self.todo("implement getLLVMType for type '{}'", .{t}),
581 => return self.todo("implement llvmType for type '{}'", .{t}),
582582 }
583583 }
584584
585585 // TODO: figure out a way to remove the FuncGen argument
586586 fn genTypedValue(self: *DeclGen, tv: TypedValue, fg: ?*FuncGen) error{ OutOfMemory, CodegenFail }!*const llvm.Value {
587 const llvm_type = try self.getLLVMType(tv.ty);
587 const llvm_type = try self.llvmType(tv.ty);
588588
589589 if (tv.val.isUndef())
590590 return llvm_type.getUndef();
......@@ -611,7 +611,7 @@ pub const DeclGen = struct {
611611 const decl = tv.val.castTag(.decl_ref).?.data;
612612 const val = try self.resolveGlobalDecl(decl);
613613
614 const usize_type = try self.getLLVMType(Type.initTag(.usize));
614 const usize_type = try self.llvmType(Type.initTag(.usize));
615615
616616 // TODO: second index should be the index into the memory!
617617 var indices: [2]*const llvm.Value = .{
......@@ -625,7 +625,7 @@ pub const DeclGen = struct {
625625 .ref_val => {
626626 const elem_value = tv.val.castTag(.ref_val).?.data;
627627 const elem_type = tv.ty.castPointer().?.data;
628 const alloca = fg.?.buildAlloca(try self.getLLVMType(elem_type));
628 const alloca = fg.?.buildAlloca(try self.llvmType(elem_type));
629629 _ = fg.?.builder.buildStore(try self.genTypedValue(.{ .ty = elem_type, .val = elem_value }, fg), alloca);
630630 return alloca;
631631 },
......@@ -647,7 +647,7 @@ pub const DeclGen = struct {
647647 if (!tv.ty.isPtrLikeOptional()) {
648648 var buf: Type.Payload.ElemType = undefined;
649649 const child_type = tv.ty.optionalChild(&buf);
650 const llvm_child_type = try self.getLLVMType(child_type);
650 const llvm_child_type = try self.llvmType(child_type);
651651
652652 if (tv.val.tag() == .null_value) {
653653 var optional_values: [2]*const llvm.Value = .{
......@@ -909,7 +909,7 @@ pub const FuncGen = struct {
909909 const inst_ty = self.air.typeOfIndex(inst);
910910 if (!inst_ty.hasCodeGenBits()) return null;
911911
912 const phi_node = self.builder.buildPhi(try self.dg.getLLVMType(inst_ty), "");
912 const phi_node = self.builder.buildPhi(try self.dg.llvmType(inst_ty), "");
913913 phi_node.addIncoming(
914914 break_vals.items.ptr,
915915 break_bbs.items.ptr,
......@@ -1086,7 +1086,7 @@ pub const FuncGen = struct {
10861086 }
10871087
10881088 const ret_ty = self.air.typeOfIndex(inst);
1089 const ret_llvm_ty = try self.dg.getLLVMType(ret_ty);
1089 const ret_llvm_ty = try self.dg.llvmType(ret_ty);
10901090 const llvm_fn_ty = llvm.functionType(
10911091 ret_llvm_ty,
10921092 llvm_param_types.ptr,
......@@ -1209,7 +1209,7 @@ pub const FuncGen = struct {
12091209 const signed = inst_ty.isSignedInt();
12101210 // TODO: Should we use intcast here or just a simple bitcast?
12111211 // LLVM does truncation vs bitcast (+signed extension) in the intcast depending on the sizes
1212 return self.builder.buildIntCast2(operand, try self.dg.getLLVMType(inst_ty), llvm.Bool.fromBool(signed), "");
1212 return self.builder.buildIntCast2(operand, try self.dg.llvmType(inst_ty), llvm.Bool.fromBool(signed), "");
12131213 }
12141214
12151215 fn airPtrToInt(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
......@@ -1218,7 +1218,7 @@ pub const FuncGen = struct {
12181218
12191219 const un_op = self.air.instructions.items(.data)[inst].un_op;
12201220 const operand = try self.resolveInst(un_op);
1221 const dest_llvm_ty = try self.dg.getLLVMType(self.air.typeOfIndex(inst));
1221 const dest_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst));
12221222 return self.builder.buildPtrToInt(operand, dest_llvm_ty, "");
12231223 }
12241224
......@@ -1229,7 +1229,7 @@ pub const FuncGen = struct {
12291229 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
12301230 const operand = try self.resolveInst(ty_op.operand);
12311231 const inst_ty = self.air.typeOfIndex(inst);
1232 const dest_type = try self.dg.getLLVMType(inst_ty);
1232 const dest_type = try self.dg.llvmType(inst_ty);
12331233
12341234 return self.builder.buildBitCast(operand, dest_type, "");
12351235 }
......@@ -1239,7 +1239,7 @@ pub const FuncGen = struct {
12391239 self.arg_index += 1;
12401240
12411241 const inst_ty = self.air.typeOfIndex(inst);
1242 const ptr_val = self.buildAlloca(try self.dg.getLLVMType(inst_ty));
1242 const ptr_val = self.buildAlloca(try self.dg.llvmType(inst_ty));
12431243 _ = self.builder.buildStore(arg_val, ptr_val);
12441244 return self.builder.buildLoad(ptr_val, "");
12451245 }
......@@ -1254,7 +1254,7 @@ pub const FuncGen = struct {
12541254
12551255 // TODO: figure out a way to get the name of the var decl.
12561256 // TODO: set alignment and volatile
1257 return self.buildAlloca(try self.dg.getLLVMType(pointee_type));
1257 return self.buildAlloca(try self.dg.llvmType(pointee_type));
12581258 }
12591259
12601260 /// Use this instead of builder.buildAlloca, because this function makes sure to