summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-03-29 18:00:34 -0700
committerGitHub <noreply@github.com>2023-03-29 18:00:34 -0700
commitaf062bff8f670de6a0c4fe7be797487ba124d811 (patch)
tree492f8ef0ed80842489d901de4f85573d712f6948 /source
parent082c48d96c5f8f6b4f560d705fe731da14409cb4 (diff)
Fix IRArrayType emit logic. (#2754)
* Fix IRArrayType emit logic. * Fix test. * Fix ast constant folding. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-expr.cpp12
-rw-r--r--source/slang/slang-ir.cpp53
2 files changed, 17 insertions, 48 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index a14ed38d8..0f744997d 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -1496,13 +1496,12 @@ namespace Slang
}
}
- auto initExpr = getInitExpr(m_astBuilder, declRef);
- if(!initExpr)
+ if (!getInitExpr(m_astBuilder, declRef))
return nullptr;
ensureDecl(declRef.decl, DeclCheckState::Checked);
ConstantFoldingCircularityInfo newCircularityInfo(decl, circularityInfo);
- return tryConstantFoldExpr(initExpr, &newCircularityInfo);
+ return tryConstantFoldExpr(getInitExpr(m_astBuilder, declRef), &newCircularityInfo);
}
IntVal* SemanticsVisitor::tryConstantFoldExpr(
@@ -1546,12 +1545,7 @@ namespace Slang
// it is possible that we are referring to a generic value param
if (auto declRefExpr = expr.as<DeclRefExpr>())
{
- auto checkedExpr = as<DeclRefExpr>(CheckTerm(expr.getExpr()));
- if (!checkedExpr)
- return nullptr;
-
- SubstExpr<DeclRefExpr> substExpr(checkedExpr, expr.getSubsts());
- auto declRef = getDeclRef(m_astBuilder, substExpr);
+ auto declRef = getDeclRef(m_astBuilder, declRefExpr);
if (auto genericValParamRef = declRef.as<GenericValueParamDecl>())
{
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 16926a742..d03096483 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -2389,20 +2389,22 @@ namespace Slang
capabilitySetType, kIROp_CapabilitySet, args.getCount(), args.getBuffer());
}
- static void canonicalizeInstOperands(IRBuilder& builder, IRInst* inst)
+ static void canonicalizeInstOperands(IRBuilder& builder, IROp op, ArrayView<IRInst*> operands)
{
// For Array types, we always want to make sure its element count
// has an int32_t type. We will convert all other int types to int32_t
// to avoid things like float[8] and float[8U] being distinct types.
- if (inst->getOp() == kIROp_ArrayType)
+ if (op == kIROp_ArrayType)
{
- IRInst* elementCount = inst->getOperand(1);
+ if (operands.getCount() < 2)
+ return;
+ IRInst* elementCount = operands[1];
if (auto intLit = as<IRIntLit>(elementCount))
{
if (intLit->getDataType()->getOp() != kIROp_IntType)
{
IRInst* newElementCount = builder.getIntValue(builder.getIntType(), intLit->getValue());
- inst->getOperands()[1].usedValue = newElementCount;
+ operands[1] = newElementCount;
}
}
}
@@ -2423,6 +2425,13 @@ namespace Slang
operandCount += listArgCounts[ii];
}
+ ShortList<IRInst*, 8> canonicalizedOperands;
+ canonicalizedOperands.setCount(fixedArgCount);
+ for (Index i = 0; i < fixedArgCount; i++)
+ canonicalizedOperands[i] = fixedArgs[i];
+
+ canonicalizeInstOperands(*this, op, canonicalizedOperands.getArrayView().arrayView);
+
auto& memoryArena = getModule()->getMemoryArena();
void* cursor = memoryArena.getCursor();
@@ -2449,7 +2458,7 @@ namespace Slang
IRUse* operand = inst->getOperands();
for (Int ii = 0; ii < fixedArgCount; ++ii)
{
- auto arg = fixedArgs[ii];
+ auto arg = canonicalizedOperands[ii];
m_dedupContext->getInstReplacementMap().TryGetValue(arg, arg);
operand->usedValue = arg;
operand++;
@@ -2467,8 +2476,6 @@ namespace Slang
}
}
- canonicalizeInstOperands(*this, inst);
-
// Find or add the key/inst
{
IRInstKey key = { inst };
@@ -2536,38 +2543,6 @@ namespace Slang
UInt operandCount,
IRInst* const* operands)
{
- switch (op)
- {
- case kIROp_ArrayType:
- {
- ShortList<IRInst*, 2> newOperands;
- newOperands.addRange(operands, operandCount);
-
- // If elementCount does not have int type, then we always cast
- // it to an int type, to avoid having to deal with the
- // possibility that an array<int, 2> and an array<int, 2U> are
- // treated as distinct types.
- if (operandCount < 2) break;
- auto elementCount = operands[1];
- if (elementCount->getFullType() && elementCount->getFullType()->getOp() != kIROp_IntType)
- {
- auto intLit = as<IRIntLit>(elementCount);
- if (intLit)
- elementCount = getIntValue(getIntType(), intLit->getValue());
- else
- elementCount = emitIntrinsicInst(getIntType(), kIROp_IntCast, 1, &elementCount);
- }
- newOperands[1] = elementCount;
- return (IRType*)createIntrinsicInst(
- nullptr,
- op,
- operandCount,
- newOperands.getArrayView().getBuffer());
- }
- default:
- break;
- }
-
return (IRType*)createIntrinsicInst(
nullptr,
op,