aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig7
-rw-r--r--src/codegen/llvm.zig25
-rw-r--r--src/codegen/spirv/spec.zig20
3 files changed, 42 insertions, 10 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 48ca64d176..2a0751a202 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -1734,6 +1734,8 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
.struct_field_ptr_index_2 => try airStructFieldPtrIndex(f, inst, 2),
.struct_field_ptr_index_3 => try airStructFieldPtrIndex(f, inst, 3),
+ .field_parent_ptr => try airFieldParentPtr(f, inst),
+
.struct_field_val => try airStructFieldVal(f, inst),
.slice_ptr => try airSliceField(f, inst, ".ptr;\n"),
.slice_len => try airSliceField(f, inst, ".len;\n"),
@@ -3026,6 +3028,11 @@ fn airStructFieldPtrIndex(f: *Function, inst: Air.Inst.Index, index: u8) !CValue
return structFieldPtr(f, inst, struct_ptr_ty, struct_ptr, index);
}
+fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
+ _ = inst;
+ return f.fail("TODO: C backend: implement airFieldParentPtr", .{});
+}
+
fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struct_ptr: CValue, index: u32) !CValue {
const writer = f.object.writer();
const struct_ty = struct_ptr_ty.elemType();
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 1679ee6d97..51bb713ed5 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -2191,6 +2191,8 @@ pub const FuncGen = struct {
.struct_field_ptr_index_2 => try self.airStructFieldPtrIndex(inst, 2),
.struct_field_ptr_index_3 => try self.airStructFieldPtrIndex(inst, 3),
+ .field_parent_ptr => try self.airFieldParentPtr(inst),
+
.array_elem_val => try self.airArrayElemVal(inst),
.slice_elem_val => try self.airSliceElemVal(inst),
.slice_elem_ptr => try self.airSliceElemPtr(inst),
@@ -2853,6 +2855,29 @@ pub const FuncGen = struct {
}
}
+ fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
+ if (self.liveness.isUnused(inst)) return null;
+
+ const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
+ const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
+
+ const field_ptr = try self.resolveInst(extra.field_ptr);
+
+ const target = self.dg.module.getTarget();
+ const struct_ty = self.air.getRefType(ty_pl.ty).childType();
+ const field_offset = struct_ty.structFieldOffset(extra.field_index, target);
+
+ const res_ty = try self.dg.llvmType(self.air.getRefType(ty_pl.ty));
+ if (field_offset == 0) {
+ return self.builder.buildBitCast(field_ptr, res_ty, "");
+ }
+ const llvm_usize_ty = self.context.intType(target.cpu.arch.ptrBitWidth());
+
+ const field_ptr_int = self.builder.buildPtrToInt(field_ptr, llvm_usize_ty, "");
+ const base_ptr_int = self.builder.buildNUWSub(field_ptr_int, llvm_usize_ty.constInt(field_offset, .False), "");
+ return self.builder.buildIntToPtr(base_ptr_int, res_ty, "");
+ }
+
fn airNot(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
if (self.liveness.isUnused(inst))
return null;
diff --git a/src/codegen/spirv/spec.zig b/src/codegen/spirv/spec.zig
index bb7453c006..5fbd371331 100644
--- a/src/codegen/spirv/spec.zig
+++ b/src/codegen/spirv/spec.zig
@@ -1206,7 +1206,7 @@ pub const Opcode = enum(u16) {
}
};
pub const ImageOperands = packed struct {
- Bias: bool align(@alignOf(u32)) = false,
+ Bias: bool = false,
Lod: bool = false,
Grad: bool = false,
ConstOffset: bool = false,
@@ -1280,7 +1280,7 @@ pub const ImageOperands = packed struct {
};
};
pub const FPFastMathMode = packed struct {
- NotNaN: bool align(@alignOf(u32)) = false,
+ NotNaN: bool = false,
NotInf: bool = false,
NSZ: bool = false,
AllowRecip: bool = false,
@@ -1314,7 +1314,7 @@ pub const FPFastMathMode = packed struct {
_reserved_bit_31: bool = false,
};
pub const SelectionControl = packed struct {
- Flatten: bool align(@alignOf(u32)) = false,
+ Flatten: bool = false,
DontFlatten: bool = false,
_reserved_bit_2: bool = false,
_reserved_bit_3: bool = false,
@@ -1348,7 +1348,7 @@ pub const SelectionControl = packed struct {
_reserved_bit_31: bool = false,
};
pub const LoopControl = packed struct {
- Unroll: bool align(@alignOf(u32)) = false,
+ Unroll: bool = false,
DontUnroll: bool = false,
DependencyInfinite: bool = false,
DependencyLength: bool = false,
@@ -1417,7 +1417,7 @@ pub const LoopControl = packed struct {
};
};
pub const FunctionControl = packed struct {
- Inline: bool align(@alignOf(u32)) = false,
+ Inline: bool = false,
DontInline: bool = false,
Pure: bool = false,
Const: bool = false,
@@ -1451,7 +1451,7 @@ pub const FunctionControl = packed struct {
_reserved_bit_31: bool = false,
};
pub const MemorySemantics = packed struct {
- _reserved_bit_0: bool align(@alignOf(u32)) = false,
+ _reserved_bit_0: bool = false,
Acquire: bool = false,
Release: bool = false,
AcquireRelease: bool = false,
@@ -1489,7 +1489,7 @@ pub const MemorySemantics = packed struct {
pub const MakeVisibleKHR: MemorySemantics = .{ .MakeVisible = true };
};
pub const MemoryAccess = packed struct {
- Volatile: bool align(@alignOf(u32)) = false,
+ Volatile: bool = false,
Aligned: bool = false,
Nontemporal: bool = false,
MakePointerAvailable: bool = false,
@@ -1562,7 +1562,7 @@ pub const MemoryAccess = packed struct {
};
};
pub const KernelProfilingInfo = packed struct {
- CmdExecTime: bool align(@alignOf(u32)) = false,
+ CmdExecTime: bool = false,
_reserved_bit_1: bool = false,
_reserved_bit_2: bool = false,
_reserved_bit_3: bool = false,
@@ -1596,7 +1596,7 @@ pub const KernelProfilingInfo = packed struct {
_reserved_bit_31: bool = false,
};
pub const RayFlags = packed struct {
- OpaqueKHR: bool align(@alignOf(u32)) = false,
+ OpaqueKHR: bool = false,
NoOpaqueKHR: bool = false,
TerminateOnFirstHitKHR: bool = false,
SkipClosestHitShaderKHR: bool = false,
@@ -1630,7 +1630,7 @@ pub const RayFlags = packed struct {
_reserved_bit_31: bool = false,
};
pub const FragmentShadingRate = packed struct {
- Vertical2Pixels: bool align(@alignOf(u32)) = false,
+ Vertical2Pixels: bool = false,
Vertical4Pixels: bool = false,
Horizontal2Pixels: bool = false,
Horizontal4Pixels: bool = false,