From 4a94473eb34376dd8474f8ca3f2834b5c1daac14 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 1 Sep 2022 10:01:13 -0700 Subject: Deduplicate consts and IRSpecialize in IR, propagate type info for `IntVal`. (#2388) --- source/slang/slang-check-expr.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-check-expr.cpp') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index e33d26c0c..c7bfdd3a6 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -866,7 +866,7 @@ namespace Slang IntVal* SemanticsVisitor::getIntVal(IntegerLiteralExpr* expr) { // TODO(tfoley): don't keep allocating here! - return m_astBuilder->create(expr->value); + return m_astBuilder->create(expr->type.type, expr->value); } IntVal* SemanticsVisitor::tryConstantFoldExpr( @@ -982,7 +982,7 @@ namespace Slang || opName == getName("|") || opName == getName("&") || opName == getName("^") || opName == getName("~") || opName == getName("%") || opName == getName("?:") || opName == getName("<<") || opName == getName(">>")) { - auto result = m_astBuilder->create(); + auto result = m_astBuilder->create(invokeExpr.getExpr()->type.type); result->args.addRange(argVals, argCount); result->funcDeclRef = funcDeclRef; result->funcType = as(funcDeclRefExpr.getExpr()->type->substitute( @@ -1091,7 +1091,7 @@ namespace Slang } } - IntVal* result = m_astBuilder->create(resultValue); + IntVal* result = m_astBuilder->create(invokeExpr.getExpr()->type.type, resultValue); return result; } @@ -1176,7 +1176,7 @@ namespace Slang { // If it's a boolean, we allow promotion to int. const IntegerLiteralValue value = IntegerLiteralValue(boolLitExpr.getExpr()->value); - return m_astBuilder->create(value); + return m_astBuilder->create(m_astBuilder->getBoolType(), value); } // it is possible that we are referring to a generic value param @@ -1186,8 +1186,9 @@ namespace Slang if (auto genericValParamRef = declRef.as()) { - // TODO(tfoley): handle the case of non-`int` value parameters... - Val* valResult = m_astBuilder->create(genericValParamRef); + Val* valResult = m_astBuilder->create( + declRef.substitute(m_astBuilder, genericValParamRef.getDecl()->getType()), + genericValParamRef); valResult = valResult->substitute(m_astBuilder, expr.getSubsts()); return as(valResult); } @@ -2145,7 +2146,7 @@ namespace Slang // here if the input type had a sugared name... swizExpr->type = QualType(createVectorType( baseElementType, - m_astBuilder->create(elementCount))); + m_astBuilder->create(m_astBuilder->getIntType(), elementCount))); } // A swizzle can be used as an l-value as long as there @@ -2266,7 +2267,7 @@ namespace Slang // here if the input type had a sugared name... swizExpr->type = QualType(createVectorType( baseElementType, - m_astBuilder->create(elementCount))); + m_astBuilder->create(m_astBuilder->getIntType(), elementCount))); } // A swizzle can be used as an l-value as long as there -- cgit v1.2.3