From 6c7120d684cc46caafbe348d658158c0060a7638 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 5 Jul 2023 14:37:48 -0700 Subject: Bottleneck DeclRef creation through ASTBuilder. (#2689) * Bottleneck DeclRef creation through ASTBuilder. * Fix clang error. * Fix. * Fix. * More fix. * Rebase on top of tree. --------- Co-authored-by: Yong He --- source/slang/slang-ast-builder.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source/slang/slang-ast-builder.cpp') diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp index 56861949f..d914b4568 100644 --- a/source/slang/slang-ast-builder.cpp +++ b/source/slang/slang-ast-builder.cpp @@ -167,7 +167,7 @@ SharedASTBuilder::~SharedASTBuilder() void SharedASTBuilder::registerBuiltinDecl(Decl* decl, BuiltinTypeModifier* modifier) { - auto type = DeclRefType::create(m_astBuilder, DeclRef(decl, nullptr)); + auto type = DeclRefType::create(m_astBuilder, DeclRef(decl)); m_builtinTypes[Index(modifier->tag)] = type; } @@ -299,7 +299,7 @@ ArrayExpressionType* ASTBuilder::getArrayType(Type* elementType, IntVal* element auto arrayGenericDecl = as(m_sharedASTBuilder->findMagicDecl("ArrayType")); auto arrayTypeDecl = arrayGenericDecl->inner; auto substitutions = getOrCreate(arrayGenericDecl, elementType, elementCount); - result->declRef = DeclRef(arrayTypeDecl, substitutions); + result->declRef = getSpecializedDeclRef(arrayTypeDecl, substitutions); } return result; } @@ -314,7 +314,7 @@ VectorExpressionType* ASTBuilder::getVectorType( auto vectorGenericDecl = as(m_sharedASTBuilder->findMagicDecl("Vector")); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = getOrCreate(vectorGenericDecl, elementType, elementCount); - result->declRef = DeclRef(vectorTypeDecl, substitutions); + result->declRef = getSpecializedDeclRef(vectorTypeDecl, substitutions); } return result; } @@ -332,7 +332,7 @@ DifferentialPairType* ASTBuilder::getDifferentialPairType( valueType, primalIsDifferentialWitness); - auto declRef = DeclRef(typeDecl, substitutions); + auto declRef = getSpecializedDeclRef(typeDecl, substitutions); auto rsType = DeclRefType::create(this, declRef); return as(rsType); @@ -373,7 +373,7 @@ MeshOutputType* ASTBuilder::getMeshOutputTypeFromModifier( elementType, maxElementCount); - auto declRef = DeclRef(typeDecl, substitutions); + auto declRef = getSpecializedDeclRef(typeDecl, substitutions); auto rsType = DeclRefType::create(this, declRef); return as(rsType); @@ -458,7 +458,8 @@ bool ASTBuilder::NodeDesc::operator==(NodeDesc const& that) const // via a `NodeDesc` *should* all be going through the // deduplication path anyway, as should their operands. // - if(operands[i].values.nodeOperand != that.operands[i].values.nodeOperand) return false; + if (operands[i].values.nodeOperand[0] != that.operands[i].values.nodeOperand[0]) return false; + if (operands[i].values.nodeOperand[1] != that.operands[i].values.nodeOperand[1]) return false; } return true; } @@ -473,9 +474,15 @@ HashCode ASTBuilder::NodeDesc::getHashCode() const // to match the semantics implemented for `==` on // `NodeDesc`. // - hasher.hashValue(operands[i].values.nodeOperand); + hasher.hashValue(operands[i].values.nodeOperand[0]); + hasher.hashValue(operands[i].values.nodeOperand[1]); } return hasher.getResult(); } +DeclRef _getSpecializedDeclRef(ASTBuilder* builder, Decl* decl, Substitutions* subst) +{ + return builder->getSpecializedDeclRef(decl, subst); +} + } // namespace Slang -- cgit v1.2.3