From f875d3f5ba9c1ddc6aa9a0960efd5ab27ae4e4c9 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 9 Aug 2023 20:11:09 -0700 Subject: Support implciit casted swizzled lvalue. (#3077) * Support implciit casted swizzled lvalue. * Fix warnings. * Fix. * fix comment. * Prefer mangled linkage name for global params. * Update tests. --------- Co-authored-by: Yong He --- source/slang/slang-ir-lower-l-value-cast.cpp | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'source/slang/slang-ir-lower-l-value-cast.cpp') diff --git a/source/slang/slang-ir-lower-l-value-cast.cpp b/source/slang/slang-ir-lower-l-value-cast.cpp index cd03d2bd5..aca58cef3 100644 --- a/source/slang/slang-ir-lower-l-value-cast.cpp +++ b/source/slang/slang-ir-lower-l-value-cast.cpp @@ -166,15 +166,10 @@ struct LValueCastLoweringContext // convert in. // Okay we are going to replace the implicit casts with temporaries around call sites/uses. - List useSites; + List useSites; for (auto use = castInst->firstUse; use; use = use->nextUse) { - auto useSite = use->getUser(); - - if (useSites.indexOf(useSite) < 0) - { - useSites.add(useSite); - } + useSites.add(use); } // If there is a name hint on the source, we'll copy it over to the temporaries @@ -187,7 +182,8 @@ struct LValueCastLoweringContext for (auto useSite : useSites) { - builder.setInsertBefore(useSite); + auto user = useSite->getUser(); + builder.setInsertBefore(user); auto tmpVar = builder.emitVar(toValueType); if (nameHintDecoration) @@ -196,27 +192,17 @@ struct LValueCastLoweringContext } // If it's inout we convert via cast whats in the castOperand - if (castInst->getOp() == kIROp_InOutImplicitCast) + if (castInst->getOp() == kIROp_InOutImplicitCast && user->getOp() != kIROp_Store) { builder.emitStore(tmpVar, builder.emitCast(toValueType, builder.emitLoad(castOperand))); } // Convert the temporary back to the original location - builder.setInsertAfter(useSite); + builder.setInsertAfter(user); builder.emitStore(castOperand, builder.emitCast(fromValueType, builder.emitLoad(tmpVar))); // Go through all of the operands of the use inst relacing, with the temporary - const auto operandCount = Count(useSite->getOperandCount()); - auto operands = useSite->getOperands(); - - for (Index i = 0; i < operandCount; ++i) - { - auto& callSiteOperand = operands[i]; - if(callSiteOperand.get() == castInst) - { - callSiteOperand.set(tmpVar); - } - } + builder.replaceOperand(useSite, tmpVar); } // When we are done we can destroy the inst -- cgit v1.2.3