Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Cache.h: Implements a cache for various commonly created objects. |
| 8 | |
| 9 | #ifndef COMPILER_TRANSLATOR_CACHE_H_ |
| 10 | #define COMPILER_TRANSLATOR_CACHE_H_ |
| 11 | |
| 12 | #include <stdint.h> |
| 13 | #include <string.h> |
| 14 | #include <map> |
| 15 | |
| 16 | #include "compiler/translator/Types.h" |
| 17 | #include "compiler/translator/PoolAlloc.h" |
| 18 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 19 | namespace sh |
| 20 | { |
| 21 | |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 22 | class TCache |
| 23 | { |
| 24 | public: |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 25 | static void initialize(); |
| 26 | static void destroy(); |
| 27 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 28 | static const TType *getType(TBasicType basicType, TPrecision precision) |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 29 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 30 | return getType(basicType, precision, EvqTemporary, 1, 1); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 31 | } |
| 32 | static const TType *getType(TBasicType basicType, |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 33 | unsigned char primarySize = 1, |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 34 | unsigned char secondarySize = 1) |
| 35 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 36 | return getType(basicType, EbpUndefined, EvqGlobal, primarySize, secondarySize); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 37 | } |
| 38 | static const TType *getType(TBasicType basicType, |
| 39 | TQualifier qualifier, |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 40 | unsigned char primarySize = 1, |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 41 | unsigned char secondarySize = 1) |
| 42 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 43 | return getType(basicType, EbpUndefined, qualifier, primarySize, secondarySize); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 44 | } |
| 45 | static const TType *getType(TBasicType basicType, |
| 46 | TPrecision precision, |
| 47 | TQualifier qualifier, |
| 48 | unsigned char primarySize, |
| 49 | unsigned char secondarySize); |
| 50 | |
| 51 | private: |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 52 | TCache() {} |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 53 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 54 | union TypeKey { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 55 | TypeKey(TBasicType basicType, |
| 56 | TPrecision precision, |
| 57 | TQualifier qualifier, |
| 58 | unsigned char primarySize, |
| 59 | unsigned char secondarySize); |
| 60 | |
| 61 | typedef uint8_t EnumComponentType; |
| 62 | struct |
| 63 | { |
| 64 | EnumComponentType basicType; |
| 65 | EnumComponentType precision; |
| 66 | EnumComponentType qualifier; |
| 67 | unsigned char primarySize; |
| 68 | unsigned char secondarySize; |
| 69 | } components; |
| 70 | uint64_t value; |
| 71 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 72 | bool operator<(const TypeKey &other) const { return value < other.value; } |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 73 | }; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 74 | typedef std::map<TypeKey, const TType *> TypeMap; |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 75 | |
| 76 | TypeMap mTypes; |
| 77 | TPoolAllocator mAllocator; |
| 78 | |
| 79 | static TCache *sCache; |
| 80 | }; |
| 81 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 82 | } // namespace sh |
| 83 | |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 84 | #endif // COMPILER_TRANSLATOR_CACHE_H_ |