summaryrefslogtreecommitdiff
path: root/source/slang/ir-inst-defs.h
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-08-17 14:17:29 -0700
committerTim Foley <tfoley@nvidia.com>2017-08-17 14:17:29 -0700
commit95348fdb623509eb22c04d4c7c19af8228c5a533 (patch)
tree213fec5c06df3401fddd99d90c95f2ed7ccd2c9e /source/slang/ir-inst-defs.h
parentad19484792dcc5a1fb90720614830c66c4b9712d (diff)
[ir] Represent fields more direclty
Previously, a `StructType` was an ordinary instruction that took a variable number of types are operands, representing the types of fields. This ends up being inconvenient for a few reasons: - To add decorations to the fields, you'd end up having to decorate the struct type instead (SPIR-V has this problem) - You need to compute field indices during lowering, when you might prefer to defer that until later - The get/set field operations now need an index, which needs to be an explicit operand, which means a magic numeric literal floating around to represent the index The new approach fixes for the first two of these, and at least makes the last one a bit nicer. A `StructDecl` is now a parent instruction, and its sub-instructions represent the fields of the type - each field is an explicit instruction of type `StructField`. The operation to extract a field takes a direct reference the struct field, so everything is quite explicit.
Diffstat (limited to 'source/slang/ir-inst-defs.h')
-rw-r--r--source/slang/ir-inst-defs.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/source/slang/ir-inst-defs.h b/source/slang/ir-inst-defs.h
index 8445e5a1e..d594d2755 100644
--- a/source/slang/ir-inst-defs.h
+++ b/source/slang/ir-inst-defs.h
@@ -14,7 +14,7 @@ INST(BoolType, type.bool, 0, 0)
INST(Float32Type, type.f32, 0, 0)
INST(Int32Type, type.i32, 0, 0)
INST(UInt32Type, type.u32, 0, 0)
-INST(StructType, type.struct, 0, 0)
+INST(StructType, type.struct, 0, PARENT)
INST(FuncType, func_type, 0, 0)
INST(IntLit, integer_constant, 0, 0)
@@ -26,9 +26,10 @@ INST(Module, module, 0, PARENT)
INST(Func, func, 0, PARENT)
INST(Block, block, 0, PARENT)
-INST(Param, param, 0, 0)
+INST(Param, param, 0, 0)
+INST(StructField, field, 0, 0)
-INST(FieldExtract, get_field, 1, 0)
+INST(FieldExtract, get_field, 2, 0)
INST(ReturnVal, return_val, 1, 0)
INST(ReturnVoid, return_void, 1, 0)