diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-12-11 15:17:55 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-11 15:17:55 -0800 |
| commit | 62d3e387774255be4d507cca045ac97dabac9970 (patch) | |
| tree | be43084855adaad3a843eaf9b46c845b17465a63 /source/slang/ir-serialize.cpp | |
| parent | 565200f0a9200cdc9a345c51096e50a745aabc1d (diff) | |
Decorations are instructions (#748)
* Make a test case use IR serialization
* Make all IR instructions usable as parents
This makes it so that every `IRInst` has the list of children that used to be on `IRParentInst` and eliminates `IRParentInst`.
Most places in the code were only checking against `IRParentInst` so that they could know whether there were child instructions to iterate over.
This change bloats the size of every instruction by two pointers, but we hope to be able to eliminate that overhead with a better encoding later.
* Change IR decorations to be instructions.
The main change here is that `IRDecoration` now inherits from `IRInst`, and `IRInst` now has a single linked list that holds both decorations *and* children.
At each point where code used to loop over `getChildren()` on an `IRInst`, I checked whether it made sense to leave the operation as processing just the children, or if it should process both decorations and children.
The thorniest bit was making sure the logic for inserting an instruction into a parent is correct. For the most part, once IR code is built all insertions are explicitly before/after another instruction, so the ordering can't get messed up. The sticking point is any code that does an explicit `insertAtStart` or `insertAtEnd`, but I surveyed those to make sure they are correct in context, and I also made all insertions bottleneck through one routine that does a better job of asserting the preconditions than what was there before. We may still want a "smart" insertion function at some point so that if somebody does `someDecoration->insertAtEnd(someInst)` the decoration intelligently goes to the end of the decoration list, and not the entire decorations-and-children list.
All of the existing decoration types were refactored to provide accessors for their operands, rather than directly exposing fields. In most cases the operands are required to be `IRConstant` nodes of fixed types. Not all of these types need to be kept around in the new approach, but they were left in so that as much existing code as possible can be kept working.
The `IRBuilder` was extended with factory functions to make the various decoration types and attach them.
All the fields in concrete decorations that were using `StringRepresentation` or `Name` pointers are now using IR-level string operands which provide their value as an `UnownedStringSlice`, so logic that was working with those decoration values needed to be updated here and there. I also needed to add the logic to clone string-literal values to the IR cloning pass, since they are now being used in almost every piece of code.
A new type of constant IR instruction for literal pointers was added, to handle the cases where an IR decoration needs an operand that is a raw AST-level pointer. These are even being serialized, although we obviously should not rely on them to round-trip through serialization in the future. Ideally, a follow-on change should add a cleanup pass where we remove any decorations from a module that shouldn't be allowed in the serialized code.
The biggest overall cleanup is in the serialization logic, where a lot of code just disappears because it can process the raw "decorations and children" list as the logical children of an IR instruction. The only special cases left are literals (which seem like they will always need special-casing) and global values (because they have a mangled name, which we plan to move into a decoration).
One other example of a simplification made possible by this change: the `IRNotePatchConstantFunc` instruction was implemented as an instruction only because it couldn't be encoded as a decoration at the time (it needed to have an operand that referenced an IR function).
The IR dumping logic was also updated (which meant a change to the `ir/string-literal` test) to try to make it print out all decorations a bit more systematically now that they are encoded like other instructions. The formatting isn't quite perfect, but it is good enough to be able to read what is going on.
I didn't include updates to the validation logic to ensure that decorations are being added in ways that follow the invariants, but that would be a nice thing to add next.
* fixup: 64-bit issues
* fixup: forward declaration issues
Diffstat (limited to 'source/slang/ir-serialize.cpp')
| -rw-r--r-- | source/slang/ir-serialize.cpp | 438 |
1 files changed, 32 insertions, 406 deletions
diff --git a/source/slang/ir-serialize.cpp b/source/slang/ir-serialize.cpp index 03e10c8e2..0fc8a0806 100644 --- a/source/slang/ir-serialize.cpp +++ b/source/slang/ir-serialize.cpp @@ -16,12 +16,9 @@ namespace Slang { /* Note that an IRInst can be derived from, but when it derived from it's new members are IRUse variables, and they in effect alias over the operands - and reflected in the operand count. There _could_ be other members after these IRUse -variables, but in practice there do not appear to be. - -The only difference to this is IRParentInst derived types, as it contains IRInstListBase children. Thus IRParentInst derived classes can -have no operands - because it would write over the top of IRInstListBase. BUT they can contain members after the list -types which do this are +variables, but only a few types include extra data, and these do not have any operands: +* IRConstant - Needs special-case handling * IRModuleInst - Presumably we can just set to the module pointer on reconstruction * IRGlobalValue - There are types derived from this type, but they don't add a parameter @@ -44,12 +41,6 @@ bother to check if it's correct, and just casts it. { 0, 0 } // Int64, }; -static bool isParentDerived(IROp opIn) -{ - const int op = (kIROpMeta_PseudoOpMask & opIn); - return op >= kIROp_FirstParentInst && op <= kIROp_LastParentInst; -} - static bool isGlobalValueDerived(IROp opIn) { const int op = (kIROpMeta_PseudoOpMask & opIn); @@ -273,7 +264,6 @@ size_t IRSerialData::calcSizeInBytes() const return _calcArraySize(m_insts) + _calcArraySize(m_childRuns) + - _calcArraySize(m_decorationRuns) + _calcArraySize(m_externalOperands) + _calcArraySize(m_stringTable) + /* Raw source locs */ @@ -293,7 +283,6 @@ void IRSerialData::clear() memset(&m_insts[0], 0, sizeof(Inst)); m_childRuns.Clear(); - m_decorationRuns.Clear(); m_externalOperands.Clear(); m_rawSourceLocs.Clear(); @@ -307,8 +296,6 @@ void IRSerialData::clear() m_stringTable.SetSize(2); m_stringTable[int(kNullStringIndex)] = 0; m_stringTable[int(kEmptyStringIndex)] = 0; - - m_decorationBaseIndex = 0; } template <typename T> @@ -344,10 +331,8 @@ static bool _isEqual(const List<T>& aIn, const List<T>& bIn) bool IRSerialData::operator==(const ThisType& rhs) const { return (this == &rhs) || - (m_decorationBaseIndex == rhs.m_decorationBaseIndex && - _isEqual(m_insts, rhs.m_insts) && + (_isEqual(m_insts, rhs.m_insts) && _isEqual(m_childRuns, rhs.m_childRuns) && - _isEqual(m_decorationRuns, rhs.m_decorationRuns) && _isEqual(m_externalOperands, rhs.m_externalOperands) && _isEqual(m_rawSourceLocs, rhs.m_rawSourceLocs) && _isEqual(m_stringTable, rhs.m_stringTable)); @@ -363,33 +348,6 @@ void IRSerialWriter::_addInstruction(IRInst* inst) // Add to the map m_instMap.Add(inst, Ser::InstIndex(m_insts.Count())); m_insts.Add(inst); - - // Add all the decorations, to the list. - // We don't add to the decoration map, as we only want to do this once all the instructions have been hit - if (inst->firstDecoration) - { - m_instWithFirstDecoration.Add(inst); - - IRDecoration* decor = inst->firstDecoration; - - const int initialNumDecor = int(m_decorations.Count()); - while (decor) - { - m_decorations.Add(decor); - decor = decor->next; - } - - const Ser::SizeType numDecor = Ser::SizeType(int(m_decorations.Count()) - initialNumDecor); - - Ser::InstRun run; - run.m_parentIndex = m_instMap[inst]; - - // NOTE! This isn't quite correct, as we need to correct for when all the instructions are added, this is done at the end - run.m_startInstIndex = Ser::InstIndex(initialNumDecor); - run.m_numChildren = numDecor; - - m_serialData->m_decorationRuns.Add(run); - } } // Find a view index that matches the view by file (and perhaps other characteristics in the future) @@ -433,7 +391,7 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt m_decorations.Clear(); // Stack for parentInst - List<IRParentInst*> parentInstStack; + List<IRInst*> parentInstStack; IRModuleInst* moduleInst = module->getModuleInst(); parentInstStack.Add(moduleInst); @@ -445,7 +403,7 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt while (parentInstStack.Count()) { // If it's in the stack it is assumed it is already in the inst map - IRParentInst* parentInst = parentInstStack.Last(); + IRInst* parentInst = parentInstStack.Last(); parentInstStack.RemoveLast(); SLANG_ASSERT(m_instMap.ContainsKey(parentInst)); @@ -453,7 +411,7 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt // cos we want breadth first so the order of children is the same as their index order, meaning we don't need to store explicit indices const Ser::InstIndex startChildInstIndex = Ser::InstIndex(m_insts.Count()); - IRInstListBase childrenList = parentInst->getChildren(); + IRInstListBase childrenList = parentInst->getDecorationsAndChildren(); for (IRInst* child : childrenList) { // This instruction can't be in the map... @@ -461,11 +419,7 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt _addInstruction(child); - IRParentInst* childAsParent = as<IRParentInst>(child); - if (childAsParent) - { - parentInstStack.Add(childAsParent); - } + parentInstStack.Add(child); } // If it had any children, then store the information about it @@ -480,32 +434,10 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt } } - // Now fix the decorations - { - const int decorationBaseIndex = int(m_insts.Count()); - m_serialData->m_decorationBaseIndex = decorationBaseIndex; - const int numDecorRuns = int(m_serialData->m_decorationRuns.Count()); - - // Work out the total num of decoration - int totalNumDecorations = 0; - if (numDecorRuns) - { - const auto& lastDecorInfo = m_serialData->m_decorationRuns.Last(); - totalNumDecorations = int(lastDecorInfo.m_startInstIndex) + lastDecorInfo.m_numChildren; - } - - // Fix the indices - for (int i = 0; i < numDecorRuns; ++i) - { - Ser::InstRun& info = m_serialData->m_decorationRuns[i]; - info.m_startInstIndex = Ser::InstIndex(decorationBaseIndex + int(info.m_startInstIndex)); - } - - // Set to the right size - m_serialData->m_insts.SetSize(decorationBaseIndex + totalNumDecorations); - // Clear all instructions - memset(m_serialData->m_insts.begin(), 0, sizeof(Ser::Inst) * m_serialData->m_insts.Count()); - } + // Set to the right size + m_serialData->m_insts.SetSize(m_insts.Count()); + // Clear all instructions + memset(m_serialData->m_insts.begin(), 0, sizeof(Ser::Inst) * m_serialData->m_insts.Count()); // Need to set up the actual instructions { @@ -543,6 +475,12 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt dstInst.m_payload.m_int64 = irConst->value.intVal; break; } + case kIROp_PtrLit: + { + dstInst.m_payloadType = PayloadType::Int64; + dstInst.m_payload.m_int64 = (intptr_t) irConst->value.ptrVal; + break; + } case kIROp_FloatLit: { dstInst.m_payloadType = PayloadType::Float64; @@ -616,128 +554,6 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt } } - // Now need to do the decorations - - { - const int decorationBaseIndex = m_serialData->m_decorationBaseIndex; - const int numDecor = int(m_decorations.Count()); - SLANG_ASSERT(decorationBaseIndex + numDecor == int(m_serialData->m_insts.Count())); - - // Have to be able to store in a byte! - SLANG_COMPILE_TIME_ASSERT(kIROpCount + kIRDecorationOp_CountOf < 0x100); - - for (int i = 0; i < numDecor; ++i) - { - IRDecoration* srcDecor = m_decorations[i]; - Ser::Inst& dstInst = m_serialData->m_insts[decorationBaseIndex + i]; - - dstInst.m_op = uint8_t(kIROpCount + srcDecor->op); - - switch (srcDecor->op) - { - case kIRDecorationOp_HighLevelDecl: - { - // TODO! - // Decl* decl; - break; - } - case kIRDecorationOp_Layout: - { - // TODO! - // Layout* layout; - break; - } - case kIRDecorationOp_LoopControl: - { - auto loopDecor = static_cast<IRLoopControlDecoration*>(srcDecor); - - dstInst.m_payloadType = PayloadType::UInt32; - dstInst.m_payload.m_uint32 = uint32_t(loopDecor->mode); - break; - } - case kIRDecorationOp_Target: - { - auto targetDecor = static_cast<IRTargetDecoration*>(srcDecor); - - dstInst.m_payloadType = PayloadType::String_1; - dstInst.m_payload.m_stringIndices[0] = getStringIndex(targetDecor->targetName); - break; - } - case kIRDecorationOp_TargetIntrinsic: - { - auto targetDecor = static_cast<IRTargetIntrinsicDecoration*>(srcDecor); - dstInst.m_payloadType = PayloadType::String_2; - - dstInst.m_payload.m_stringIndices[0] = getStringIndex(targetDecor->targetName); - dstInst.m_payload.m_stringIndices[1] = getStringIndex(targetDecor->definition); - break; - } - case kIRDecorationOp_GLSLOuterArray: - { - auto arrayDecor = static_cast<IRGLSLOuterArrayDecoration*>(srcDecor); - dstInst.m_payloadType = PayloadType::String_1; - - dstInst.m_payload.m_stringIndices[0] = getStringIndex(arrayDecor->outerArrayName); - break; - } - case kIRDecorationOp_Semantic: - { - auto semanticDecor = static_cast<IRSemanticDecoration*>(srcDecor); - - dstInst.m_payloadType = PayloadType::String_1; - dstInst.m_payload.m_stringIndices[0] = getStringIndex(semanticDecor->semanticName); - break; - } - case kIRDecorationOp_InterpolationMode: - { - auto semanticDecor = static_cast<IRInterpolationModeDecoration*>(srcDecor); - dstInst.m_payloadType = PayloadType::UInt32; - dstInst.m_payload.m_uint32 = uint32_t(semanticDecor->mode); - break; - } - case kIRDecorationOp_NameHint: - { - auto nameDecor = static_cast<IRNameHintDecoration*>(srcDecor); - - dstInst.m_payloadType = PayloadType::String_1; - dstInst.m_payload.m_stringIndices[0] = getStringIndex(nameDecor->name); - break; - } - case kIRDecorationOp_VulkanRayPayload: - case kIRDecorationOp_VulkanCallablePayload: - case kIRDecorationOp_VulkanHitAttributes: - case kIRDecorationOp_EarlyDepthStencil: - case kIRDecorationOp_ReadNone: - case kIRDecorationOp_GloballyCoherent: - { - dstInst.m_payloadType = PayloadType::Empty; - break; - } - case kIRDecorationOp_RequireGLSLExtension: - { - auto extDecor = static_cast<IRRequireGLSLExtensionDecoration*>(srcDecor); - - dstInst.m_payloadType = PayloadType::String_1; - dstInst.m_payload.m_stringIndices[0] = getStringIndex(extDecor->extensionName); - break; - } - case kIRDecorationOp_RequireGLSLVersion: - { - auto verDecor = static_cast<IRRequireGLSLVersionDecoration*>(srcDecor); - - dstInst.m_payloadType = PayloadType::UInt32; - dstInst.m_payload.m_uint32 = uint32_t(verDecor->languageVersion); - break; - } - default: - { - SLANG_ASSERT(!"Unhandled decoration type"); - return SLANG_FAIL; - } - } - } - } - // Convert strings into a string table { SerialStringTableUtil::encodeStringTable(m_stringSlicePool, serialData->m_stringTable); @@ -1083,7 +899,6 @@ static size_t _calcInstChunkSize(IRSerialBinary::CompressionType compressionType totalSize += sizeof(Bin::SlangHeader) + _calcInstChunkSize(compressionType, data.m_insts) + _calcChunkSize(compressionType, data.m_childRuns) + - _calcChunkSize(compressionType, data.m_decorationRuns) + _calcChunkSize(compressionType, data.m_externalOperands) + _calcChunkSize(Bin::CompressionType::None, data.m_stringTable) + _calcChunkSize(Bin::CompressionType::None, data.m_rawSourceLocs); @@ -1099,7 +914,6 @@ static size_t _calcInstChunkSize(IRSerialBinary::CompressionType compressionType Bin::SlangHeader slangHeader; slangHeader.m_chunk.m_type = Bin::kSlangFourCc; slangHeader.m_chunk.m_size = uint32_t(sizeof(slangHeader) - sizeof(Bin::Chunk)); - slangHeader.m_decorationBase = uint32_t(data.m_decorationBaseIndex); slangHeader.m_compressionType = uint32_t(Bin::CompressionType::VariableByteLite); stream->Write(&slangHeader, sizeof(slangHeader)); @@ -1107,7 +921,6 @@ static size_t _calcInstChunkSize(IRSerialBinary::CompressionType compressionType SLANG_RETURN_ON_FAIL(_writeInstArrayChunk(compressionType, Bin::kInstFourCc, data.m_insts, stream)); SLANG_RETURN_ON_FAIL(_writeArrayChunk(compressionType, Bin::kChildRunFourCc, data.m_childRuns, stream)); - SLANG_RETURN_ON_FAIL(_writeArrayChunk(compressionType, Bin::kDecoratorRunFourCc, data.m_decorationRuns, stream)); SLANG_RETURN_ON_FAIL(_writeArrayChunk(compressionType, Bin::kExternalOperandsFourCc, data.m_externalOperands, stream)); SLANG_RETURN_ON_FAIL(_writeArrayChunk(Bin::CompressionType::None, Bin::kStringFourCc, data.m_stringTable, stream)); @@ -1430,7 +1243,6 @@ int64_t _calcChunkTotalSize(const IRSerialBinary::Chunk& chunk) stream->Read(&slangHeader.m_chunk + 1, sizeof(slangHeader) - sizeof(chunk)); - dataOut->m_decorationBaseIndex = slangHeader.m_decorationBase; remainingBytes -= _calcChunkTotalSize(chunk); break; } @@ -1441,13 +1253,6 @@ int64_t _calcChunkTotalSize(const IRSerialBinary::Chunk& chunk) remainingBytes -= _calcChunkTotalSize(chunk); break; } - case SLANG_MAKE_COMPRESSED_FOUR_CC(Bin::kDecoratorRunFourCc): - case Bin::kDecoratorRunFourCc: - { - SLANG_RETURN_ON_FAIL(_readArrayChunk(slangHeader, chunk, stream, &bytesRead, dataOut->m_decorationRuns)); - remainingBytes -= _calcChunkTotalSize(chunk); - break; - } case SLANG_MAKE_COMPRESSED_FOUR_CC(Bin::kChildRunFourCc): case Bin::kChildRunFourCc: { @@ -1486,135 +1291,6 @@ int64_t _calcChunkTotalSize(const IRSerialBinary::Chunk& chunk) return SLANG_OK; } -IRDecoration* IRSerialReader::_createDecoration(const Ser::Inst& srcInst) -{ - typedef Ser::Inst::PayloadType PayloadType; - - IRDecorationOp decorOp = IRDecorationOp(srcInst.m_op - kIROpCount); - SLANG_ASSERT(decorOp < kIRDecorationOp_CountOf); - - switch (decorOp) - { - case kIRDecorationOp_HighLevelDecl: - { - // TODO! - // Decl* decl; - return createEmptyDecoration<IRHighLevelDeclDecoration>(m_module); - } - case kIRDecorationOp_Layout: - { - // TODO! - // Layout* layout; - return createEmptyDecoration<IRLayoutDecoration>(m_module); - } - case kIRDecorationOp_LoopControl: - { - auto decor = createEmptyDecoration<IRLoopControlDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::UInt32); - decor->mode = IRLoopControl(srcInst.m_payload.m_uint32); - return decor; - } - case kIRDecorationOp_Target: - { - auto decor = createEmptyDecoration<IRTargetDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_1); - decor->targetName = m_stringRepresentationCache.getStringRepresentation(StringHandle(srcInst.m_payload.m_stringIndices[0])); - return decor; - } - case kIRDecorationOp_TargetIntrinsic: - { - auto decor = createEmptyDecoration<IRTargetIntrinsicDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_2); - decor->targetName = m_stringRepresentationCache.getStringRepresentation(StringHandle(srcInst.m_payload.m_stringIndices[0])); - decor->definition = m_stringRepresentationCache.getStringRepresentation(StringHandle(srcInst.m_payload.m_stringIndices[1])); - return decor; - } - case kIRDecorationOp_GLSLOuterArray: - { - auto decor = createEmptyDecoration<IRGLSLOuterArrayDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_1); - decor->outerArrayName = m_stringRepresentationCache.getCStr(StringHandle(srcInst.m_payload.m_stringIndices[0])); - return decor; - } - case kIRDecorationOp_Semantic: - { - auto decor = createEmptyDecoration<IRSemanticDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_1); - decor->semanticName = m_stringRepresentationCache.getName(StringHandle(srcInst.m_payload.m_stringIndices[0])); - return decor; - } - case kIRDecorationOp_InterpolationMode: - { - auto decor = createEmptyDecoration<IRInterpolationModeDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == Ser::Inst::PayloadType::UInt32); - decor->mode = IRInterpolationMode(srcInst.m_payload.m_uint32); - return decor; - } - case kIRDecorationOp_NameHint: - { - auto decor = createEmptyDecoration<IRNameHintDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_1); - decor->name = m_stringRepresentationCache.getName(StringHandle(srcInst.m_payload.m_stringIndices[0])); - return decor; - } - case kIRDecorationOp_VulkanRayPayload: - { - auto decor = createEmptyDecoration<IRVulkanRayPayloadDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); - return decor; - } - case kIRDecorationOp_VulkanCallablePayload: - { - auto decor = createEmptyDecoration<IRVulkanCallablePayloadDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); - return decor; - } - case kIRDecorationOp_EarlyDepthStencil: - { - auto decor = createEmptyDecoration<IREarlyDepthStencilDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); - return decor; - } - case kIRDecorationOp_GloballyCoherent: - { - auto decor = createEmptyDecoration<IRGloballyCoherentDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); - return decor; - } - case kIRDecorationOp_VulkanHitAttributes: - { - auto decor = createEmptyDecoration<IRVulkanHitAttributesDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); - return decor; - } - case kIRDecorationOp_RequireGLSLExtension: - { - auto decor = createEmptyDecoration<IRRequireGLSLExtensionDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_1); - decor->extensionName = m_stringRepresentationCache.getStringRepresentation(StringHandle(srcInst.m_payload.m_stringIndices[0])); - return decor; - } - case kIRDecorationOp_RequireGLSLVersion: - { - auto decor = createEmptyDecoration<IRRequireGLSLVersionDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == Ser::Inst::PayloadType::UInt32); - decor->languageVersion = Int(srcInst.m_payload.m_uint32); - return decor; - } - case kIRDecorationOp_ReadNone: - { - auto decor = createEmptyDecoration<IRReadNoneDecoration>(m_module); - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); - return decor; - } - default: - { - SLANG_ASSERT(!"Unhandled decoration type"); - return nullptr; - } - } -} - /* static */Result IRSerialReader::read(const IRSerialData& data, Session* session, RefPtr<IRModule>& moduleOut) { typedef Ser::Inst::PayloadType PayloadType; @@ -1633,18 +1309,14 @@ IRDecoration* IRSerialReader::_createDecoration(const Ser::Inst& srcInst) // Add all the instructions List<IRInst*> insts; - List<IRDecoration*> decorations; - const int numInsts = data.m_decorationBaseIndex; - const int numDecorations = int(data.m_insts.Count() - numInsts); + const int numInsts = int(data.m_insts.Count()); SLANG_ASSERT(numInsts > 0); insts.SetSize(numInsts); insts[0] = nullptr; - decorations.SetSize(numDecorations); - // 0 holds null // 1 holds the IRModuleInst { @@ -1668,25 +1340,16 @@ IRDecoration* IRSerialReader::_createDecoration(const Ser::Inst& srcInst) const IROp op((IROp)srcInst.m_op); - if (isParentDerived(op)) + if (isGlobalValueDerived(op)) { // Cannot have operands SLANG_ASSERT(srcInst.getNumOperands() == 0); - if (isGlobalValueDerived(op)) - { - IRGlobalValue* globalValueInst = static_cast<IRGlobalValue*>(createEmptyInstWithSize(module, op, sizeof(IRGlobalValue))); - insts[i] = globalValueInst; - // Set the global value - SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_1); - globalValueInst->mangledName = m_stringRepresentationCache.getName(StringHandle(srcInst.m_payload.m_stringIndices[0])); - } - else - { - // Just needs to big enough to hold IRParentInst - IRParentInst* parentInst = static_cast<IRParentInst*>(createEmptyInstWithSize(module, op, sizeof(IRParentInst))); - insts[i] = parentInst; - } + IRGlobalValue* globalValueInst = static_cast<IRGlobalValue*>(createEmptyInstWithSize(module, op, sizeof(IRGlobalValue))); + insts[i] = globalValueInst; + // Set the global value + SLANG_ASSERT(srcInst.m_payloadType == PayloadType::String_1); + globalValueInst->mangledName = m_stringRepresentationCache.getName(StringHandle(srcInst.m_payload.m_stringIndices[0])); } else { @@ -1714,6 +1377,13 @@ IRDecoration* IRSerialReader::_createDecoration(const Ser::Inst& srcInst) irConst->value.intVal = srcInst.m_payload.m_int64; break; } + case kIROp_PtrLit: + { + SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Int64); + irConst = static_cast<IRConstant*>(createEmptyInstWithSize(module, op, prefixSize + sizeof(void*))); + irConst->value.ptrVal = (void*) (intptr_t) srcInst.m_payload.m_int64; + break; + } case kIROp_FloatLit: { SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Float64); @@ -1808,56 +1478,12 @@ IRDecoration* IRSerialReader::_createDecoration(const Ser::Inst& srcInst) const auto& run = data.m_childRuns[i]; IRInst* inst = insts[int(run.m_parentIndex)]; - IRParentInst* parentInst = as<IRParentInst>(inst); - SLANG_ASSERT(parentInst); for (int j = 0; j < int(run.m_numChildren); ++j) { IRInst* child = insts[j + int(run.m_startInstIndex)]; SLANG_ASSERT(child->parent == nullptr); - //child->parent = parentInst; - child->insertAtEnd(parentInst); - } - } - } - - // Create the decorations - for (int i = 0; i < numDecorations; ++i) - { - IRDecoration* decor = _createDecoration(data.m_insts[i + numInsts]); - if (!decor) - { - return SLANG_FAIL; - } - decorations[i] = decor; - } - - // Associate the decorations with the instructions - - { - const int decorationBaseIndex = m_serialData->m_decorationBaseIndex; - - const int numRuns = int(m_serialData->m_decorationRuns.Count()); - for (int i = 0; i < numRuns; ++i) - { - const Ser::InstRun& run = m_serialData->m_decorationRuns[i]; - - // Decorations must be associated with instructions - SLANG_ASSERT(int(run.m_parentIndex) < decorationBaseIndex); - - IRInst* inst = insts[int(run.m_parentIndex)]; - SLANG_ASSERT(int(run.m_startInstIndex) >= decorationBaseIndex && int(run.m_startInstIndex) + run.m_numChildren <= m_serialData->m_insts.Count()); - - // Calculate the offset in the decoration list, which index 0, is decorationBaseIndex in instruction indices - const int decorStartIndex = int(run.m_startInstIndex) - decorationBaseIndex; - - // Go in reverse order so that linked list is in same order as original - for (int j = int(run.m_numChildren) - 1; j >= 0; --j) - { - IRDecoration* decor = decorations[decorStartIndex + j]; - // And to the linked list on the - decor->next = inst->firstDecoration; - inst->firstDecoration = decor; + child->insertAtEnd(inst); } } } |
