summaryrefslogtreecommitdiff
path: root/source/slang/ir.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-09-27 11:36:35 -0400
committerGitHub <noreply@github.com>2018-09-27 11:36:35 -0400
commitd06bd7d8ec8c132f5f63f2137c83506fc2e80617 (patch)
tree08bba293af9e10f074cfb7120886fd46cb29588f /source/slang/ir.h
parentee549942335add195df8e69a31f65a691d54aff9 (diff)
First pass implementation of IR serialization (#653)
* * Change the layout of IROp such that 'main' IROps are 0-x. * Removed MANUAL_RANGE instuction types, as no longer needed. * Work in prog on optimizing. * * Constant time lookup for IROpInfo * Refactor and document a little more the IROp layout * Mark ops that use 'other' bits * Fix typo in definition of kIROpFlag_UseOther * First pass at working out serialization structure. * Work in progress on ir-serialize * Storing strings in IRSerialInfo Split out IRSerialInfo from the IRSerializer - to make more explicit what is actually saved. * First pass at serializing out data. * First pass at serialize reading. * Fix riff fourcc mark order. * First pass at reconstructing IRInst / IRDecoration from serialized data. * Handling of TextureBaseType * Deserializing of constants. * Small changes around ir serialization. * Changed StringIndex indexing to not be an offset into the m_strings array, but an index into strings in order. Doing so makes cache lookup much faster, and makes the 'indicies' themselves smaller and therefore more compressible. * Removed the need for m_arena in IRSerialWriter. Previously it's purpose was to store the string contents that were being used to lookup UnownedStringSlice. Now we keep the StringRepresentation in scope and reference that, and so don't need the copy. * Don't need to construct the IRModuleInst as is created and set on createModule call. * Remove test code for testing serialization. * Fix problem with release build in ir-serialize causing warning. * Use SLANG_OFFSET_OF for offsets in non pod classes to avoid gcc/clang warning. Give storage to integral static variables to avoid linkage problems with gcc/clang. * Fix warnings under x86 win32 debug.
Diffstat (limited to 'source/slang/ir.h')
-rw-r--r--source/slang/ir.h39
1 files changed, 32 insertions, 7 deletions
diff --git a/source/slang/ir.h b/source/slang/ir.h
index 6627acd5d..4f36b6e7f 100644
--- a/source/slang/ir.h
+++ b/source/slang/ir.h
@@ -81,9 +81,10 @@ enum IROp : int32_t
/* IROpMeta describe values for layout of IROp, as well as values for accessing aspects of IROp bits. */
enum IROpMeta
{
- kIROpMeta_Shift = 9, ///< Number of bits for op/pseudo ops (shift right by this to get the other bits)
- kIROpMeta_OpMask = (int32_t(1) << kIROpMeta_Shift) - 1, ///< Mask for regular ops
- kIrOpMeta_OtherMask = ~kIROpMeta_OpMask, ///< Mask for bits that can be used for other purposes than 'op' ('other' bits)
+ kIROpMeta_OtherShift = 9, ///< Number of bits for op/pseudo ops (shift right by this to get the other bits)
+ kIROpMeta_PseudoOpMask = (int32_t(1) << kIROpMeta_OtherShift) - 1, ///< Mask for ops including pseudo ops
+ kIROpMeta_OpMask = 0xff, ///< Mask for just ops
+ kIrOpMeta_OtherMask = ~kIROpMeta_PseudoOpMask, ///< Mask for bits that can be used for other purposes than 'op' ('other' bits)
kIROpMeta_IsPseudoOp = kIROp_Invalid, ///< 'And' with op, if set, the op is a pseudo op
};
@@ -146,10 +147,13 @@ enum IRDecorationOp : uint16_t
kIRDecorationOp_Semantic,
kIRDecorationOp_InterpolationMode,
kIRDecorationOp_NameHint,
+
/** The _instruction_ is transitory. Such a decoration should NEVER be found on an output instruction a module.
Typically used mark an instruction so can be specially handled - say when creating a IRConstant literal, and the payload of
needs to be special cased for lookup. */
- kIRDecorationOp_Transitory,
+ kIRDecorationOp_Transitory,
+
+ kIRDecorationOp_CountOf
};
// represents an object allocated in an IR memory arena
@@ -423,8 +427,8 @@ struct IRInstList : IRInstListBase
// Types
-#define IR_LEAF_ISA(NAME) static bool isaImpl(IROp op) { return (kIROpMeta_OpMask & op) == kIROp_##NAME; }
-#define IR_PARENT_ISA(NAME) static bool isaImpl(IROp opIn) { const int op = (kIROpMeta_OpMask & opIn); return op >= kIROp_First##NAME && op <= kIROp_Last##NAME; }
+#define IR_LEAF_ISA(NAME) static bool isaImpl(IROp op) { return (kIROpMeta_PseudoOpMask & op) == kIROp_##NAME; }
+#define IR_PARENT_ISA(NAME) static bool isaImpl(IROp opIn) { const int op = (kIROpMeta_PseudoOpMask & opIn); return op >= kIROp_First##NAME && op <= kIROp_Last##NAME; }
#define SIMPLE_IR_TYPE(NAME, BASE) struct IR##NAME : IR##BASE { IR_LEAF_ISA(NAME) };
#define SIMPLE_IR_PARENT_TYPE(NAME, BASE) struct IR##NAME : IR##BASE { IR_PARENT_ISA(NAME) };
@@ -701,7 +705,7 @@ struct IRResourceTypeBase : IRType
{
TextureFlavor getFlavor() const
{
- return TextureFlavor((op >> kIROpMeta_Shift) & 0xFFFF);
+ return TextureFlavor((op >> kIROpMeta_OtherShift) & 0xFFFF);
}
TextureFlavor::Shape GetBaseShape() const
@@ -1098,6 +1102,27 @@ void dumpIR(IRGlobalValue* globalVal);
String dumpIRFunc(IRFunc* func);
+IRInst* createEmptyInst(
+ IRModule* module,
+ IROp op,
+ int totalArgCount);
+
+IRInst* createEmptyInstWithSize(
+ IRModule* module,
+ IROp op,
+ size_t totalSizeInBytes);
+
+IRDecoration* createEmptyDecoration(
+ IRModule* module,
+ IRDecorationOp op,
+ size_t sizeInBytes);
+
+template <typename T>
+T* createEmptyDecoration(IRModule* module)
+{
+ return static_cast<T*>(createEmptyDecoration(module, IRDecorationOp(T::kDecorationOp), sizeof(T)));
+}
+
}