diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-11-06 18:37:25 -0500 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-11-06 15:37:25 -0800 |
| commit | 7a877c380c3c84d03326e6fb982f85547d0bd338 (patch) | |
| tree | b7cbd651e9e64743fccbb7aa35a23214caac0f3b /source | |
| parent | 13a2ca6135284a63a178918bd0c7c7becc56eaf2 (diff) | |
BasicTypeKey improvements/fix for gcc build issue (#1110)
* Added RiffReadHelper
* Move type to fourCC in Chunk simplifies some code.
* Make MemoryArena able to track external blocks.
Allow ownership of Data to vary.
Changed IR serialization to use moved allocations to avoid copies.
As it turns out all of the array writes could use unowned data, but doing so requires the IRData to stay in scope longer than IRSerialData, which it does at the moment - but perhaps needs better naming or a control for the feature.
* Write out slang-module container.
* WIP on -r option.
Loading modules - with -r.
* Making the serialized-module run (without using imported module).
* Split compiling module from the test.
* Separate module compilation with a function working.
* Remove serialization test as not used.
* Fix warning on gcc.
* Updated test to have types across module boundary.
* Allow entry point declaration.
A test that tries to build with just an entry point declaration and a module.
* Try to make link work with multiple modules.
* Multi module linking first pass working.
* Multi module test working with -module-name option
* Added feature to repro manifest of approximation of command line that was used.
* Use isDefinition - for determining to add decorations to entry point lowering.
* Added support for repo-file-system.h
More precise control of CacheFileSystem.
Allow RelativeFileSystem to strip paths optionally.
Use canonical paths in PathInfo cache.
Fix bug in -D options for command line output of StateSerailizeUtil
* Add missing slang-options.h
* Fix bug in bit slang-state-serialize.cpp with bit removal.
* Added documentation around -repro-file-system
Added spLoadReproAsFileSystem function.
* Fix warning.
* spAddLibraryReference
* * Add support for slang-lib extension
* Container output when using -no-codegen option
* Use the m_containerFormat to determine if the module container is constructed.
Store the result in a blob. This allows for potential access via the API.
Write the blob if a filename is set.
Use m_ prefix for container variables.
* Added spGetContainerCode.
Made spGetCompileRequestCode work.
* Use enum class for BasicTypeKey - removed type pun/bit field usage.
Specifed invalid BasicTypeKey value.
Fixed problem on gcc 7.4 not compiling claiming an uninitialized variable could be used.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-conversion.cpp | 13 | ||||
| -rw-r--r-- | source/slang/slang-check-impl.h | 96 |
2 files changed, 50 insertions, 59 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index 412bdca38..f313c7913 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -750,16 +750,17 @@ namespace Slang // As an optimization, we will maintain a cache of conversion results // for basic types such as scalars and vectors. // - BasicTypeKey key1, key2; - BasicTypeKeyPair cacheKey; + bool shouldAddToCache = false; ConversionCost cost; TypeCheckingCache* typeCheckingCache = getSession()->getTypeCheckingCache(); - if( key1.fromType(toType.Ptr()) && key2.fromType(fromType.Ptr()) ) - { - cacheKey.type1 = key1; - cacheKey.type2 = key2; + BasicTypeKeyPair cacheKey; + cacheKey.type1 = makeBasicTypeKey(toType.Ptr()); + cacheKey.type2 = makeBasicTypeKey(fromType.Ptr()); + + if( cacheKey.isValid()) + { if (typeCheckingCache->conversionCostCache.TryGetValue(cacheKey, cost)) { if (outCost) diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 78425b9ae..0cc9eb628 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -25,69 +25,56 @@ namespace Slang // A flat representation of basic types (scalars, vectors and matrices) // that can be used as lookup key in caches - struct BasicTypeKey + enum class BasicTypeKey : uint8_t { - union + Invalid = 0xff, ///< Value that can never be a valid type + }; + + SLANG_FORCE_INLINE BasicTypeKey makeBasicTypeKey(BaseType baseType, IntegerLiteralValue dim1 = 1, IntegerLiteralValue dim2 = 1) + { + SLANG_ASSERT(dim1 > 0 && dim2 > 0); + return BasicTypeKey((uint8_t(baseType) << 4) | ((uint8_t(dim1) - 1) << 2) | (uint8_t(dim2) - 1)); + } + + inline BasicTypeKey makeBasicTypeKey(Type* typeIn) + { + if (auto basicType = as<BasicExpressionType>(typeIn)) { - struct - { - unsigned char type : 4; - unsigned char dim1 : 2; - unsigned char dim2 : 2; - } data; - unsigned char aggVal; - }; - bool fromType(Type* typeIn) + return makeBasicTypeKey(basicType->baseType); + } + else if (auto vectorType = as<VectorExpressionType>(typeIn)) { - aggVal = 0; - if (auto basicType = as<BasicExpressionType>(typeIn)) + if (auto elemCount = as<ConstantIntVal>(vectorType->elementCount)) { - data.type = (unsigned char)basicType->baseType; - data.dim1 = data.dim2 = 0; + auto elemBasicType = as<BasicExpressionType>(vectorType->elementType); + return makeBasicTypeKey(elemBasicType->baseType, elemCount->value); } - else if (auto vectorType = as<VectorExpressionType>(typeIn)) - { - if (auto elemCount = as<ConstantIntVal>(vectorType->elementCount)) - { - data.dim1 = elemCount->value - 1; - auto elementBasicType = as<BasicExpressionType>(vectorType->elementType); - data.type = (unsigned char)elementBasicType->baseType; - data.dim2 = 0; - } - else - return false; - } - else if (auto matrixType = as<MatrixExpressionType>(typeIn)) + } + else if (auto matrixType = as<MatrixExpressionType>(typeIn)) + { + if (auto elemCount1 = as<ConstantIntVal>(matrixType->getRowCount())) { - if (auto elemCount1 = as<ConstantIntVal>(matrixType->getRowCount())) + if (auto elemCount2 = as<ConstantIntVal>(matrixType->getColumnCount())) { - if (auto elemCount2 = as<ConstantIntVal>(matrixType->getColumnCount())) - { - auto elemBasicType = as<BasicExpressionType>(matrixType->getElementType()); - data.type = (unsigned char)elemBasicType->baseType; - data.dim1 = elemCount1->value - 1; - data.dim2 = elemCount2->value - 1; - } + auto elemBasicType = as<BasicExpressionType>(matrixType->getElementType()); + return makeBasicTypeKey(elemBasicType->baseType, elemCount1->value, elemCount2->value); } - else - return false; } - else - return false; - return true; } - }; + return BasicTypeKey::Invalid; + } struct BasicTypeKeyPair { BasicTypeKey type1, type2; - bool operator == (BasicTypeKeyPair p) - { - return type1.aggVal == p.type1.aggVal && type2.aggVal == p.type2.aggVal; - } + bool operator==(const BasicTypeKeyPair& rhs) const { return type1 == rhs.type1 && type2 == rhs.type2; } + bool operator!=(const BasicTypeKeyPair& rhs) const { return !(*this == rhs); } + + bool isValid() const { return type1 != BasicTypeKey::Invalid && type2 != BasicTypeKey::Invalid; } + int GetHashCode() { - return combineHash(type1.aggVal, type2.aggVal); + return int(type1) << 16 | int(type2); } }; @@ -97,26 +84,29 @@ namespace Slang BasicTypeKey args[2]; bool operator == (OperatorOverloadCacheKey key) { - return operatorName == key.operatorName && args[0].aggVal == key.args[0].aggVal - && args[1].aggVal == key.args[1].aggVal; + return operatorName == key.operatorName && args[0] == key.args[0] && args[1] == key.args[1]; } int GetHashCode() { - return ((int)(UInt64)(void*)(operatorName) << 16) ^ (args[0].aggVal << 8) ^ (args[1].aggVal); + return ((int)(UInt64)(void*)(operatorName) << 16) ^ (int(args[0]) << 8) ^ (int(args[1])); } bool fromOperatorExpr(OperatorExpr* opExpr) { // First, lets see if the argument types are ones // that we can encode in our space of keys. - args[0].aggVal = 0; - args[1].aggVal = 0; + args[0] = BasicTypeKey::Invalid; + args[1] = BasicTypeKey::Invalid; if (opExpr->Arguments.getCount() > 2) return false; for (Index i = 0; i < opExpr->Arguments.getCount(); i++) { - if (!args[i].fromType(opExpr->Arguments[i]->type.Ptr())) + auto key = makeBasicTypeKey(opExpr->Arguments[i]->type.Ptr()); + if (key == BasicTypeKey::Invalid) + { return false; + } + args[i]= key; } // Next, lets see if we can find an intrinsic opcode |
