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 {...@@ -486,11 +486,11 @@ pub const DeclGen = struct {
486 defer self.gpa.free(llvm_param);486 defer self.gpa.free(llvm_param);
487487
488 for (fn_param_types) |fn_param, i| {488 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);
490 }490 }
491491
492 const fn_type = llvm.functionType(492 const fn_type = llvm.functionType(
493 try self.getLLVMType(return_type),493 try self.llvmType(return_type),
494 llvm_param.ptr,494 llvm_param.ptr,
495 @intCast(c_uint, fn_param_len),495 @intCast(c_uint, fn_param_len),
496 .False,496 .False,
...@@ -510,8 +510,8 @@ pub const DeclGen = struct {...@@ -510,8 +510,8 @@ pub const DeclGen = struct {
510510
511 assert(decl.has_tv);511 assert(decl.has_tv);
512512
513 // TODO: remove this redundant `getLLVMType`, it is also called in `genTypedValue`.513 // TODO: remove this redundant `llvmType`, it is also called in `genTypedValue`.
514 const llvm_type = try self.getLLVMType(decl.ty);514 const llvm_type = try self.llvmType(decl.ty);
515 const val = try self.genTypedValue(.{ .ty = decl.ty, .val = decl.val }, null);515 const val = try self.genTypedValue(.{ .ty = decl.ty, .val = decl.val }, null);
516 const global = self.llvmModule().addGlobal(llvm_type, decl.name);516 const global = self.llvmModule().addGlobal(llvm_type, decl.name);
517 llvm.setInitializer(global, val);517 llvm.setInitializer(global, val);
...@@ -522,8 +522,8 @@ pub const DeclGen = struct {...@@ -522,8 +522,8 @@ pub const DeclGen = struct {
522 return global;522 return global;
523 }523 }
524524
525 fn getLLVMType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type {525 fn llvmType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type {
526 log.debug("getLLVMType for {}", .{t});526 log.debug("llvmType for {}", .{t});
527 switch (t.zigTypeTag()) {527 switch (t.zigTypeTag()) {
528 .Void => return self.context().voidType(),528 .Void => return self.context().voidType(),
529 .NoReturn => return self.context().voidType(),529 .NoReturn => return self.context().voidType(),
...@@ -536,12 +536,12 @@ pub const DeclGen = struct {...@@ -536,12 +536,12 @@ pub const DeclGen = struct {
536 if (t.isSlice()) {536 if (t.isSlice()) {
537 return self.todo("implement slices", .{});537 return self.todo("implement slices", .{});
538 } else {538 } else {
539 const elem_type = try self.getLLVMType(t.elemType());539 const elem_type = try self.llvmType(t.elemType());
540 return elem_type.pointerType(0);540 return elem_type.pointerType(0);
541 }541 }
542 },542 },
543 .Array => {543 .Array => {
544 const elem_type = try self.getLLVMType(t.elemType());544 const elem_type = try self.llvmType(t.elemType());
545 return elem_type.arrayType(@intCast(c_uint, t.abiSize(self.module.getTarget())));545 return elem_type.arrayType(@intCast(c_uint, t.abiSize(self.module.getTarget())));
546 },546 },
547 .Optional => {547 .Optional => {
...@@ -550,7 +550,7 @@ pub const DeclGen = struct {...@@ -550,7 +550,7 @@ pub const DeclGen = struct {
550 const child_type = t.optionalChild(&buf);550 const child_type = t.optionalChild(&buf);
551551
552 var optional_types: [2]*const llvm.Type = .{552 var optional_types: [2]*const llvm.Type = .{
553 try self.getLLVMType(child_type),553 try self.llvmType(child_type),
554 self.context().intType(1),554 self.context().intType(1),
555 };555 };
556 return self.context().structType(&optional_types, 2, .False);556 return self.context().structType(&optional_types, 2, .False);
...@@ -578,13 +578,13 @@ pub const DeclGen = struct {...@@ -578,13 +578,13 @@ pub const DeclGen = struct {
578 .Frame,578 .Frame,
579 .AnyFrame,579 .AnyFrame,
580 .Vector,580 .Vector,
581 => return self.todo("implement getLLVMType for type '{}'", .{t}),581 => return self.todo("implement llvmType for type '{}'", .{t}),
582 }582 }
583 }583 }
584584
585 // TODO: figure out a way to remove the FuncGen argument585 // TODO: figure out a way to remove the FuncGen argument
586 fn genTypedValue(self: *DeclGen, tv: TypedValue, fg: ?*FuncGen) error{ OutOfMemory, CodegenFail }!*const llvm.Value {586 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
589 if (tv.val.isUndef())589 if (tv.val.isUndef())
590 return llvm_type.getUndef();590 return llvm_type.getUndef();
...@@ -611,7 +611,7 @@ pub const DeclGen = struct {...@@ -611,7 +611,7 @@ pub const DeclGen = struct {
611 const decl = tv.val.castTag(.decl_ref).?.data;611 const decl = tv.val.castTag(.decl_ref).?.data;
612 const val = try self.resolveGlobalDecl(decl);612 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
616 // TODO: second index should be the index into the memory!616 // TODO: second index should be the index into the memory!
617 var indices: [2]*const llvm.Value = .{617 var indices: [2]*const llvm.Value = .{
...@@ -625,7 +625,7 @@ pub const DeclGen = struct {...@@ -625,7 +625,7 @@ pub const DeclGen = struct {
625 .ref_val => {625 .ref_val => {
626 const elem_value = tv.val.castTag(.ref_val).?.data;626 const elem_value = tv.val.castTag(.ref_val).?.data;
627 const elem_type = tv.ty.castPointer().?.data;627 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));
629 _ = fg.?.builder.buildStore(try self.genTypedValue(.{ .ty = elem_type, .val = elem_value }, fg), alloca);629 _ = fg.?.builder.buildStore(try self.genTypedValue(.{ .ty = elem_type, .val = elem_value }, fg), alloca);
630 return alloca;630 return alloca;
631 },631 },
...@@ -647,7 +647,7 @@ pub const DeclGen = struct {...@@ -647,7 +647,7 @@ pub const DeclGen = struct {
647 if (!tv.ty.isPtrLikeOptional()) {647 if (!tv.ty.isPtrLikeOptional()) {
648 var buf: Type.Payload.ElemType = undefined;648 var buf: Type.Payload.ElemType = undefined;
649 const child_type = tv.ty.optionalChild(&buf);649 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
652 if (tv.val.tag() == .null_value) {652 if (tv.val.tag() == .null_value) {
653 var optional_values: [2]*const llvm.Value = .{653 var optional_values: [2]*const llvm.Value = .{
...@@ -909,7 +909,7 @@ pub const FuncGen = struct {...@@ -909,7 +909,7 @@ pub const FuncGen = struct {
909 const inst_ty = self.air.typeOfIndex(inst);909 const inst_ty = self.air.typeOfIndex(inst);
910 if (!inst_ty.hasCodeGenBits()) return null;910 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), "");
913 phi_node.addIncoming(913 phi_node.addIncoming(
914 break_vals.items.ptr,914 break_vals.items.ptr,
915 break_bbs.items.ptr,915 break_bbs.items.ptr,
...@@ -1086,7 +1086,7 @@ pub const FuncGen = struct {...@@ -1086,7 +1086,7 @@ pub const FuncGen = struct {
1086 }1086 }
10871087
1088 const ret_ty = self.air.typeOfIndex(inst);1088 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);
1090 const llvm_fn_ty = llvm.functionType(1090 const llvm_fn_ty = llvm.functionType(
1091 ret_llvm_ty,1091 ret_llvm_ty,
1092 llvm_param_types.ptr,1092 llvm_param_types.ptr,
...@@ -1209,7 +1209,7 @@ pub const FuncGen = struct {...@@ -1209,7 +1209,7 @@ pub const FuncGen = struct {
1209 const signed = inst_ty.isSignedInt();1209 const signed = inst_ty.isSignedInt();
1210 // TODO: Should we use intcast here or just a simple bitcast?1210 // TODO: Should we use intcast here or just a simple bitcast?
1211 // LLVM does truncation vs bitcast (+signed extension) in the intcast depending on the sizes1211 // 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), "");
1213 }1213 }
12141214
1215 fn airPtrToInt(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {1215 fn airPtrToInt(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
...@@ -1218,7 +1218,7 @@ pub const FuncGen = struct {...@@ -1218,7 +1218,7 @@ pub const FuncGen = struct {
12181218
1219 const un_op = self.air.instructions.items(.data)[inst].un_op;1219 const un_op = self.air.instructions.items(.data)[inst].un_op;
1220 const operand = try self.resolveInst(un_op);1220 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));
1222 return self.builder.buildPtrToInt(operand, dest_llvm_ty, "");1222 return self.builder.buildPtrToInt(operand, dest_llvm_ty, "");
1223 }1223 }
12241224
...@@ -1229,7 +1229,7 @@ pub const FuncGen = struct {...@@ -1229,7 +1229,7 @@ pub const FuncGen = struct {
1229 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1229 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1230 const operand = try self.resolveInst(ty_op.operand);1230 const operand = try self.resolveInst(ty_op.operand);
1231 const inst_ty = self.air.typeOfIndex(inst);1231 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
1234 return self.builder.buildBitCast(operand, dest_type, "");1234 return self.builder.buildBitCast(operand, dest_type, "");
1235 }1235 }
...@@ -1239,7 +1239,7 @@ pub const FuncGen = struct {...@@ -1239,7 +1239,7 @@ pub const FuncGen = struct {
1239 self.arg_index += 1;1239 self.arg_index += 1;
12401240
1241 const inst_ty = self.air.typeOfIndex(inst);1241 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));
1243 _ = self.builder.buildStore(arg_val, ptr_val);1243 _ = self.builder.buildStore(arg_val, ptr_val);
1244 return self.builder.buildLoad(ptr_val, "");1244 return self.builder.buildLoad(ptr_val, "");
1245 }1245 }
...@@ -1254,7 +1254,7 @@ pub const FuncGen = struct {...@@ -1254,7 +1254,7 @@ pub const FuncGen = struct {
12541254
1255 // TODO: figure out a way to get the name of the var decl.1255 // TODO: figure out a way to get the name of the var decl.
1256 // TODO: set alignment and volatile1256 // 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));
1258 }1258 }
12591259
1260 /// Use this instead of builder.buildAlloca, because this function makes sure to1260 /// Use this instead of builder.buildAlloca, because this function makes sure to