| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | // Defines the type "ValueNum". |
| 6 | |
| 7 | // This file exists only to break an include file cycle -- had been in ValueNum.h. But that |
| 8 | // file wanted to include gentree.h to get GT_COUNT, and gentree.h wanted ton include ValueNum.h to |
| 9 | // the ValueNum type. |
| 10 | |
| 11 | /*****************************************************************************/ |
| 12 | #ifndef _VALUENUMTYPE_H_ |
| 13 | #define _VALUENUMTYPE_H_ |
| 14 | /*****************************************************************************/ |
| 15 | |
| 16 | // We will represent ValueNum's as unsigned integers. |
| 17 | typedef UINT32 ValueNum; |
| 18 | |
| 19 | // There are two "kinds" of value numbers, which differ in their modeling of the actions of other threads. |
| 20 | // "Liberal" value numbers assume that the other threads change contents of memory locations only at |
| 21 | // synchronization points. Liberal VNs are appropriate, for example, in identifying CSE opportunities. |
| 22 | // "Conservative" value numbers assume that the contents of memory locations change arbitrarily between |
| 23 | // every two accesses. Conservative VNs are appropriate, for example, in assertion prop, where an observation |
| 24 | // of a property of the value in some storage location is used to perform an optimization downstream on |
| 25 | // an operation involving the contents of that storage location. If other threads may modify the storage |
| 26 | // location between the two accesses, the observed property may no longer hold -- and conservative VNs make |
| 27 | // it clear that the values need not be the same. |
| 28 | // |
| 29 | enum ValueNumKind |
| 30 | { |
| 31 | VNK_Liberal, |
| 32 | VNK_Conservative |
| 33 | }; |
| 34 | |
| 35 | struct ValueNumPair |
| 36 | { |
| 37 | private: |
| 38 | ValueNum m_liberal; |
| 39 | ValueNum m_conservative; |
| 40 | |
| 41 | public: |
| 42 | ValueNum GetLiberal() const |
| 43 | { |
| 44 | return m_liberal; |
| 45 | } |
| 46 | void SetLiberal(ValueNum vn) |
| 47 | { |
| 48 | m_liberal = vn; |
| 49 | } |
| 50 | ValueNum GetConservative() const |
| 51 | { |
| 52 | return m_conservative; |
| 53 | } |
| 54 | void SetConservative(ValueNum vn) |
| 55 | { |
| 56 | m_conservative = vn; |
| 57 | } |
| 58 | |
| 59 | ValueNum* GetLiberalAddr() |
| 60 | { |
| 61 | return &m_liberal; |
| 62 | } |
| 63 | ValueNum* GetConservativeAddr() |
| 64 | { |
| 65 | return &m_conservative; |
| 66 | } |
| 67 | |
| 68 | ValueNum Get(ValueNumKind vnk) |
| 69 | { |
| 70 | if (vnk == VNK_Liberal) |
| 71 | { |
| 72 | return m_liberal; |
| 73 | } |
| 74 | else |
| 75 | { |
| 76 | assert(vnk == VNK_Conservative); |
| 77 | return m_conservative; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void SetBoth(ValueNum vn) |
| 82 | { |
| 83 | m_liberal = vn; |
| 84 | m_conservative = vn; |
| 85 | } |
| 86 | |
| 87 | void operator=(const ValueNumPair& vn2) |
| 88 | { |
| 89 | m_liberal = vn2.m_liberal; |
| 90 | m_conservative = vn2.m_conservative; |
| 91 | } |
| 92 | |
| 93 | // Initializes both elements to "NoVN". Defined in ValueNum.cpp. |
| 94 | ValueNumPair(); |
| 95 | |
| 96 | ValueNumPair(ValueNum lib, ValueNum cons) : m_liberal(lib), m_conservative(cons) |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | // True iff neither element is "NoVN". Defined in ValueNum.cpp. |
| 101 | bool BothDefined() const; |
| 102 | |
| 103 | bool BothEqual() const |
| 104 | { |
| 105 | return m_liberal == m_conservative; |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | #endif // _VALUENUMTYPE_H_ |
| 110 | |