From cc9ada16b3dbbbd85f03faec74afc7bae4b8014c Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Sat, 2 Mar 2024 05:19:19 +0800 Subject: Small cleanups for bitfield accessor synthesis (#3651) * Remove duplicate function * neaten --------- Co-authored-by: Yong He --- source/slang/slang-ir-bit-field-accessors.cpp | 20 +++----------------- source/slang/slang-lower-to-ir.cpp | 6 +++--- 2 files changed, 6 insertions(+), 20 deletions(-) (limited to 'source') 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(inst)) - return findInnerMostGenericReturnVal(g); - return inst; -} - -static IRInst* maybeUnwrapSpecialize(IRInst* inst) -{ - if(const auto g = as(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(maybeUnwrapSpecialize(structParamType)); + const auto structType = as(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(func->getParamType(0)); SLANG_ASSERT(ptrType); const auto structParamType = ptrType->getValueType(); - const auto structType = as(maybeUnwrapSpecialize(structParamType)); + const auto structType = as(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(maybeUnwrapGeneric(inst)); + const auto func = as(getResolvedInstForDecorations(inst)); if(!func) continue; const auto bfd = func->findDecoration(); 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 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(decl) && as(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(decl)) { if(const auto bfm = decl->parentDecl->findModifier()) { -- cgit v1.2.3