summaryrefslogtreecommitdiff
path: root/src/jit/valuenumtype.h
blob: 384d8e68694851e285b92cce9ded6b8d4f9e419a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//


// Defines the type "ValueNum".

// This file exists only to break an include file cycle -- had been in ValueNum.h.  But that
// file wanted to include gentree.h to get GT_COUNT, and gentree.h wanted ton include ValueNum.h to
// the ValueNum type.

/*****************************************************************************/
#ifndef _VALUENUMTYPE_H_
#define _VALUENUMTYPE_H_
/*****************************************************************************/

// We will represent ValueNum's as unsigned integers.
typedef UINT32 ValueNum;

// There are two "kinds" of value numbers, which differ in their modeling of the actions of other threads.
// "Liberal" value numbers assume that the other threads change contents of heap locations only at
// synchronization points.  Liberal VNs are appropriate, for example, in identifying CSE opportunities.
// "Conservative" value numbers assume that the contents of heap locations change arbitrarily between 
// every two accesses.  Conservative VNs are appropriate, for example, in assertion prop, where an observation
// of a property of the value in some storage location is used to perform an optimization downstream on
// an operation involving the contents of that storage location.  If other threads may modify the storage
// location between the two accesses, the observed property may no longer hold -- and conservative VNs make
// it clear that the values need not be the same.
//
enum ValueNumKind { VNK_Liberal, VNK_Conservative };

struct ValueNumPair
{
private:
    ValueNum m_liberal;
    ValueNum m_conservative;
public:
    ValueNum GetLiberal() const       { return m_liberal; }
    void SetLiberal(ValueNum vn)      { m_liberal = vn; }
    ValueNum GetConservative() const  { return m_conservative; }
    void SetConservative(ValueNum vn) { m_conservative = vn; }

    ValueNum* GetLiberalAddr()        { return &m_liberal; }
    ValueNum* GetConservativeAddr()   { return &m_conservative; }

    ValueNum Get(ValueNumKind vnk)    { return vnk == VNK_Liberal ? m_liberal : m_conservative; }

    void SetBoth(ValueNum vn)
    {
        m_liberal = vn;
        m_conservative = vn;
    }

    void operator=(const ValueNumPair& vn2)
    {
        m_liberal = vn2.m_liberal; 
        m_conservative = vn2.m_conservative;
    }

    // Initializes both elements to "NoVN".  Defined in ValueNum.cpp.
    ValueNumPair();

    ValueNumPair(ValueNum lib, ValueNum cons) : m_liberal(lib), m_conservative(cons) {}

    // True iff neither element is "NoVN".  Defined in ValueNum.cpp.
    bool BothDefined() const;

    bool BothEqual() const { return m_liberal == m_conservative; }
};

#endif // _VALUENUMTYPE_H_