1 | /* |
2 | * Copyright (C) 2015-2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(B3_JIT) |
29 | |
30 | #include "AirStackSlotKind.h" |
31 | #include "B3SparseCollection.h" |
32 | #include <limits.h> |
33 | #include <wtf/FastMalloc.h> |
34 | #include <wtf/Noncopyable.h> |
35 | #include <wtf/PrintStream.h> |
36 | |
37 | namespace JSC { namespace B3 { |
38 | |
39 | class StackSlot; |
40 | |
41 | namespace Air { |
42 | |
43 | class StackSlot { |
44 | WTF_MAKE_NONCOPYABLE(StackSlot); |
45 | WTF_MAKE_FAST_ALLOCATED; |
46 | public: |
47 | unsigned byteSize() const { return m_byteSize; } |
48 | StackSlotKind kind() const { return m_kind; } |
49 | bool isLocked() const { return m_kind == StackSlotKind::Locked; } |
50 | bool isSpill() const { return m_kind == StackSlotKind::Spill; } |
51 | unsigned index() const { return m_index; } |
52 | |
53 | void ensureSize(unsigned requestedSize) |
54 | { |
55 | ASSERT(!m_offsetFromFP); |
56 | m_byteSize = std::max(m_byteSize, requestedSize); |
57 | } |
58 | |
59 | unsigned alignment() const |
60 | { |
61 | if (byteSize() <= 1) |
62 | return 1; |
63 | if (byteSize() <= 2) |
64 | return 2; |
65 | if (byteSize() <= 4) |
66 | return 4; |
67 | return 8; |
68 | } |
69 | |
70 | B3::StackSlot* b3Slot() const { return m_b3Slot; } |
71 | |
72 | // Zero means that it's not yet assigned. |
73 | intptr_t offsetFromFP() const { return m_offsetFromFP; } |
74 | |
75 | // This should usually just be called from phases that do stack allocation. But you can |
76 | // totally force a stack slot to land at some offset. |
77 | void setOffsetFromFP(intptr_t); |
78 | |
79 | // This computes a hash for comparing this to JSAir's StackSlot. |
80 | unsigned jsHash() const; |
81 | |
82 | void dump(PrintStream&) const; |
83 | void deepDump(PrintStream&) const; |
84 | |
85 | private: |
86 | friend class Code; |
87 | friend class SparseCollection<StackSlot>; |
88 | |
89 | StackSlot(unsigned byteSize, StackSlotKind, B3::StackSlot*); |
90 | |
91 | unsigned m_byteSize { 0 }; |
92 | unsigned m_index { UINT_MAX }; |
93 | intptr_t m_offsetFromFP { 0 }; |
94 | StackSlotKind m_kind { StackSlotKind::Locked }; |
95 | B3::StackSlot* m_b3Slot { nullptr }; |
96 | }; |
97 | |
98 | class DeepStackSlotDump { |
99 | public: |
100 | DeepStackSlotDump(const StackSlot* slot) |
101 | : m_slot(slot) |
102 | { |
103 | } |
104 | |
105 | void dump(PrintStream& out) const |
106 | { |
107 | if (m_slot) |
108 | m_slot->deepDump(out); |
109 | else |
110 | out.print("<null>" ); |
111 | } |
112 | |
113 | private: |
114 | const StackSlot* m_slot; |
115 | }; |
116 | |
117 | inline DeepStackSlotDump deepDump(const StackSlot* slot) |
118 | { |
119 | return DeepStackSlotDump(slot); |
120 | } |
121 | |
122 | } } } // namespace JSC::B3::Air |
123 | |
124 | namespace WTF { |
125 | |
126 | inline void printInternal(PrintStream& out, JSC::B3::Air::StackSlot* stackSlot) |
127 | { |
128 | out.print(pointerDump(stackSlot)); |
129 | } |
130 | |
131 | } // namespace WTF |
132 | |
133 | #endif // ENABLE(B3_JIT) |
134 | |