diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-03-02 05:19:19 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-01 13:19:19 -0800 |
| commit | cc9ada16b3dbbbd85f03faec74afc7bae4b8014c (patch) | |
| tree | af65901e5508c13df707c85fed214878e3705153 /source | |
| parent | a4ba7d63e3035895b8081387b49a52b0fda53424 (diff) | |
Small cleanups for bitfield accessor synthesis (#3651)
* Remove duplicate function
* neaten
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ir-bit-field-accessors.cpp | 20 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 6 |
2 files changed, 6 insertions, 20 deletions
diff --git a/source/slang/slang-ir-bit-field-accessors.cpp b/source/slang/slang-ir-bit-field-accessors.cpp index 3ca660a30..21b663bf8 100644 --- a/source/slang/slang-ir-bit-field-accessors.cpp +++ b/source/slang/slang-ir-bit-field-accessors.cpp @@ -5,20 +5,6 @@ namespace Slang { -static IRInst* maybeUnwrapGeneric(IRInst* inst) -{ - if(const auto g = as<IRGeneric>(inst)) - return findInnerMostGenericReturnVal(g); - return inst; -} - -static IRInst* maybeUnwrapSpecialize(IRInst* inst) -{ - if(const auto g = as<IRSpecialize>(inst)) - return maybeUnwrapGeneric(maybeUnwrapSpecialize(g->getBase())); - return inst; -} - static IRInst* shl(IRBuilder& builder, IRInst* inst, const IRIntegerValue value) { if(value == 0) @@ -55,7 +41,7 @@ static void synthesizeBitFieldGetter(IRFunc* func, IRBitFieldAccessorDecoration* SLANG_ASSERT(isIntegralType(bitFieldType)); SLANG_ASSERT(func->getParamCount() == 1); const auto structParamType = func->getParamType(0); - const auto structType = as<IRStructType>(maybeUnwrapSpecialize(structParamType)); + const auto structType = as<IRStructType>(getResolvedInstForDecorations(structParamType)); SLANG_ASSERT(structType); const auto backingMember = findStructField(structType, dec->getBackingMemberKey()); @@ -102,7 +88,7 @@ static void synthesizeBitFieldSetter(IRFunc* func, IRBitFieldAccessorDecoration* const auto ptrType = as<IRPtrTypeBase>(func->getParamType(0)); SLANG_ASSERT(ptrType); const auto structParamType = ptrType->getValueType(); - const auto structType = as<IRStructType>(maybeUnwrapSpecialize(structParamType)); + const auto structType = as<IRStructType>(getResolvedInstForDecorations(structParamType)); SLANG_ASSERT(structType); const auto bitFieldType = func->getParamType(1); SLANG_ASSERT(isIntegralType(bitFieldType)); @@ -145,7 +131,7 @@ void synthesizeBitFieldAccessors(IRModule* module) { for(const auto inst : module->getModuleInst()->getGlobalInsts()) { - const auto func = as<IRFunc>(maybeUnwrapGeneric(inst)); + const auto func = as<IRFunc>(getResolvedInstForDecorations(inst)); if(!func) continue; const auto bfd = func->findDecoration<IRBitFieldAccessorDecoration>(); diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 17ce04fec..89fc00087 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -8878,9 +8878,9 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> void addBitFieldAccessorDecorations(IRInst* irFunc, Decl* decl) { - // If this is an accessor under a property we can move the bitfield - // modifiers on the property to the accessor function. - if(as<AccessorDecl>(decl) && as<PropertyDecl>(decl->parentDecl)) + // If this is an accessor and the parent is describing some bitfield, + // we can move the bitfield modifiers to the accessor function. + if(as<AccessorDecl>(decl)) { if(const auto bfm = decl->parentDecl->findModifier<BitFieldModifier>()) { |
