diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2023-08-31 14:30:35 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-31 11:30:35 -0700 |
| commit | 1996785e1c5d76254a102c1ec0df5dd7e2e4d68a (patch) | |
| tree | 20a7aba6b1142ccb71cf6fa7752d5c7bbf839a0a /source | |
| parent | 0fee59a7f457d633463eaf7add4cdb9bdda9afff (diff) | |
Bottleneck `TypeCastIntVal` creation through ASTBuilder (#3171)
* Bottleneck type-cast-int-val creation through ASTBuilder
* Update slang-ast-builder.h
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ast-builder.h | 9 | ||||
| -rw-r--r-- | source/slang/slang-ast-val.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 4 |
3 files changed, 12 insertions, 3 deletions
diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h index 338993552..f75ab960f 100644 --- a/source/slang/slang-ast-builder.h +++ b/source/slang/slang-ast-builder.h @@ -372,6 +372,15 @@ public: return getOrCreate<ConstantIntVal>(type, value); } + TypeCastIntVal* getTypeCastIntVal(Type* type, Val* base) + { + // Unwrap any existing type casts. + while (auto baseTypeCast = as<TypeCastIntVal>(base)) + base = baseTypeCast->getBase(); + + return getOrCreate<TypeCastIntVal>(type, base); + } + DeclRef<Decl> getGenericAppDeclRef(DeclRef<GenericDecl> genericDeclRef, ConstArrayView<Val*> args, Decl* innerDecl = nullptr) { if (!innerDecl) diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index a0ea60625..8afc6e689 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -1062,7 +1062,7 @@ Val* TypeCastIntVal::_substituteImplOverride(ASTBuilder* astBuilder, Substitutio return newVal; else { - auto result = astBuilder->getOrCreate<TypeCastIntVal>(substType, substBase); + auto result = astBuilder->getTypeCastIntVal(substType, substBase); return result; } } diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index e6d1049a0..bf7950310 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1368,7 +1368,7 @@ namespace Slang TypeCastIntVal::tryFoldImpl(m_astBuilder, targetBasicType, argVals[0], getSink())); if (foldVal) return foldVal; - auto result = m_astBuilder->getOrCreate<TypeCastIntVal>(targetBasicType, argVals[0]); + auto result = m_astBuilder->getTypeCastIntVal(targetBasicType, argVals[0]); return result; } else @@ -1594,7 +1594,7 @@ namespace Slang TypeCastIntVal::tryFoldImpl(m_astBuilder, substType, val, getSink())); if (foldVal) return foldVal; - auto result = m_astBuilder->getOrCreate<TypeCastIntVal>(substType, val); + auto result = m_astBuilder->getTypeCastIntVal(substType, val); return result; } } |
