diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ir-lower-generic-type.cpp | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ir-lower-generic-type.cpp')
| -rw-r--r-- | source/slang/slang-ir-lower-generic-type.cpp | 116 |
1 files changed, 57 insertions, 59 deletions
diff --git a/source/slang/slang-ir-lower-generic-type.cpp b/source/slang/slang-ir-lower-generic-type.cpp index 28eed3582..5cc297536 100644 --- a/source/slang/slang-ir-lower-generic-type.cpp +++ b/source/slang/slang-ir-lower-generic-type.cpp @@ -1,86 +1,84 @@ // slang-ir-lower-generic-type.cpp #include "slang-ir-lower-generic-type.h" -#include "slang-ir-generics-lowering-context.h" -#include "slang-ir.h" #include "slang-ir-clone.h" +#include "slang-ir-generics-lowering-context.h" #include "slang-ir-insts.h" +#include "slang-ir.h" namespace Slang { - // This is a subpass of generics lowering IR transformation. - // This pass lowers all generic/polymorphic types into IRAnyValueType. - struct GenericTypeLoweringContext - { - SharedGenericsLoweringContext* sharedContext; +// This is a subpass of generics lowering IR transformation. +// This pass lowers all generic/polymorphic types into IRAnyValueType. +struct GenericTypeLoweringContext +{ + SharedGenericsLoweringContext* sharedContext; - IRInst* processInst(IRInst* inst) + IRInst* processInst(IRInst* inst) + { + // Ensure exported struct types has RTTI object defined. + if (as<IRStructType>(inst)) { - // Ensure exported struct types has RTTI object defined. - if (as<IRStructType>(inst)) + if (inst->findDecoration<IRHLSLExportDecoration>()) { - if (inst->findDecoration<IRHLSLExportDecoration>()) - { - sharedContext->maybeEmitRTTIObject(inst); - } + sharedContext->maybeEmitRTTIObject(inst); } + } + + // Don't modify type insts themselves. + if (as<IRType>(inst)) + return inst; - // Don't modify type insts themselves. - if (as<IRType>(inst)) - return inst; + IRBuilder builderStorage(sharedContext->module); + auto builder = &builderStorage; + builder->setInsertBefore(inst); - IRBuilder builderStorage(sharedContext->module); - auto builder = &builderStorage; - builder->setInsertBefore(inst); - - auto newType = sharedContext->lowerType(builder, inst->getFullType()); - if (newType != inst->getFullType()) - inst = builder->replaceOperand(&inst->typeUse, newType); + auto newType = sharedContext->lowerType(builder, inst->getFullType()); + if (newType != inst->getFullType()) + inst = builder->replaceOperand(&inst->typeUse, newType); - switch (inst->getOp()) + switch (inst->getOp()) + { + default: break; + case kIROp_StructField: { - default: - break; - case kIROp_StructField: - { - // Translate the struct field type. - auto structField = static_cast<IRStructField*>(inst); - auto loweredFieldType = - sharedContext->lowerType(builder, structField->getFieldType()); - structField->setOperand(1, loweredFieldType); - } - break; + // Translate the struct field type. + auto structField = static_cast<IRStructField*>(inst); + auto loweredFieldType = + sharedContext->lowerType(builder, structField->getFieldType()); + structField->setOperand(1, loweredFieldType); } - return inst; + break; } + return inst; + } - void processModule() - { - sharedContext->addToWorkList(sharedContext->module->getModuleInst()); + void processModule() + { + sharedContext->addToWorkList(sharedContext->module->getModuleInst()); - while (sharedContext->workList.getCount() != 0) - { - IRInst* inst = sharedContext->workList.getLast(); + while (sharedContext->workList.getCount() != 0) + { + IRInst* inst = sharedContext->workList.getLast(); - sharedContext->workList.removeLast(); - sharedContext->workListSet.remove(inst); + sharedContext->workList.removeLast(); + sharedContext->workListSet.remove(inst); - inst = processInst(inst); + inst = processInst(inst); - for (auto child = inst->getLastChild(); child; child = child->getPrevInst()) - { - sharedContext->addToWorkList(child); - } + for (auto child = inst->getLastChild(); child; child = child->getPrevInst()) + { + sharedContext->addToWorkList(child); } - sharedContext->mapInterfaceRequirementKeyValue.clear(); } - }; - - void lowerGenericType(SharedGenericsLoweringContext* sharedContext) - { - GenericTypeLoweringContext context; - context.sharedContext = sharedContext; - context.processModule(); + sharedContext->mapInterfaceRequirementKeyValue.clear(); } -} +}; +void lowerGenericType(SharedGenericsLoweringContext* sharedContext) +{ + GenericTypeLoweringContext context; + context.sharedContext = sharedContext; + context.processModule(); +} +} // namespace Slang |
