OLD | NEW |
| (Empty) |
1 // Copyright 2008 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 #ifndef V8_JUMP_TARGET_LIGHT_H_ | |
29 #define V8_JUMP_TARGET_LIGHT_H_ | |
30 | |
31 #include "macro-assembler.h" | |
32 #include "zone-inl.h" | |
33 #include "virtual-frame.h" | |
34 | |
35 namespace v8 { | |
36 namespace internal { | |
37 | |
38 // Forward declarations. | |
39 class FrameElement; | |
40 class Result; | |
41 | |
42 // ------------------------------------------------------------------------- | |
43 // Jump targets | |
44 // | |
45 // A jump target is an abstraction of a basic-block entry in generated | |
46 // code. It collects all the virtual frames reaching the block by | |
47 // forward jumps and pairs them with labels for the merge code along | |
48 // all forward-reaching paths. When bound, an expected frame for the | |
49 // block is determined and code is generated to merge to the expected | |
50 // frame. For backward jumps, the merge code is generated at the edge | |
51 // leaving the predecessor block. | |
52 // | |
53 // A jump target must have been reached via control flow (either by | |
54 // jumping, branching, or falling through) at the time it is bound. | |
55 // In particular, this means that at least one of the control-flow | |
56 // graph edges reaching the target must be a forward edge. | |
57 | |
58 class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. | |
59 public: | |
60 // Forward-only jump targets can only be reached by forward CFG edges. | |
61 enum Directionality { FORWARD_ONLY, BIDIRECTIONAL }; | |
62 | |
63 // Construct a jump target. | |
64 explicit inline JumpTarget(Directionality direction); | |
65 | |
66 inline JumpTarget(); | |
67 | |
68 virtual ~JumpTarget() {} | |
69 | |
70 void Unuse() { | |
71 entry_frame_set_ = false; | |
72 entry_label_.Unuse(); | |
73 } | |
74 | |
75 inline CodeGenerator* cgen(); | |
76 | |
77 Label* entry_label() { return &entry_label_; } | |
78 | |
79 const VirtualFrame* entry_frame() const { | |
80 return entry_frame_set_ ? &entry_frame_ : NULL; | |
81 } | |
82 | |
83 void set_entry_frame(VirtualFrame* frame) { | |
84 entry_frame_ = *frame; | |
85 entry_frame_set_ = true; | |
86 } | |
87 | |
88 // Predicates testing the state of the encapsulated label. | |
89 bool is_bound() const { return entry_label_.is_bound(); } | |
90 bool is_linked() const { return entry_label_.is_linked(); } | |
91 bool is_unused() const { return entry_label_.is_unused(); } | |
92 | |
93 // Copy the state of this jump target to the destination. | |
94 inline void CopyTo(JumpTarget* destination) { | |
95 *destination = *this; | |
96 } | |
97 | |
98 // Emit a jump to the target. There must be a current frame at the | |
99 // jump and there will be no current frame after the jump. | |
100 virtual void Jump(); | |
101 | |
102 // Emit a conditional branch to the target. There must be a current | |
103 // frame at the branch. The current frame will fall through to the | |
104 // code after the branch. | |
105 virtual void Branch(Condition cc, Hint hint = no_hint); | |
106 | |
107 // Bind a jump target. If there is no current frame at the binding | |
108 // site, there must be at least one frame reaching via a forward | |
109 // jump. | |
110 virtual void Bind(); | |
111 | |
112 // Emit a call to a jump target. There must be a current frame at | |
113 // the call. The frame at the target is the same as the current | |
114 // frame except for an extra return address on top of it. The frame | |
115 // after the call is the same as the frame before the call. | |
116 void Call(); | |
117 | |
118 protected: | |
119 // Has an entry frame been found? | |
120 bool entry_frame_set_; | |
121 | |
122 // Can we branch backwards to this label? | |
123 Directionality direction_; | |
124 | |
125 // The frame used on entry to the block and expected at backward | |
126 // jumps to the block. Set the first time something branches to this | |
127 // jump target. | |
128 VirtualFrame entry_frame_; | |
129 | |
130 // The actual entry label of the block. | |
131 Label entry_label_; | |
132 | |
133 // Implementations of Jump, Branch, and Bind with all arguments and | |
134 // return values using the virtual frame. | |
135 void DoJump(); | |
136 void DoBranch(Condition cc, Hint hint); | |
137 void DoBind(); | |
138 }; | |
139 | |
140 | |
141 // ------------------------------------------------------------------------- | |
142 // Break targets | |
143 // | |
144 // A break target is a jump target that can be used to break out of a | |
145 // statement that keeps extra state on the stack (eg, for/in or | |
146 // try/finally). They know the expected stack height at the target | |
147 // and will drop state from nested statements as part of merging. | |
148 // | |
149 // Break targets are used for return, break, and continue targets. | |
150 | |
151 class BreakTarget : public JumpTarget { | |
152 public: | |
153 // Construct a break target. | |
154 inline BreakTarget(); | |
155 | |
156 inline BreakTarget(JumpTarget::Directionality direction); | |
157 | |
158 virtual ~BreakTarget() {} | |
159 | |
160 // Copy the state of this jump target to the destination. | |
161 inline void CopyTo(BreakTarget* destination) { | |
162 *destination = *this; | |
163 } | |
164 | |
165 // Emit a jump to the target. There must be a current frame at the | |
166 // jump and there will be no current frame after the jump. | |
167 virtual void Jump(); | |
168 | |
169 // Emit a conditional branch to the target. There must be a current | |
170 // frame at the branch. The current frame will fall through to the | |
171 // code after the branch. | |
172 virtual void Branch(Condition cc, Hint hint = no_hint); | |
173 | |
174 // Bind a break target. If there is no current frame at the binding | |
175 // site, there must be at least one frame reaching via a forward | |
176 // jump. | |
177 virtual void Bind(); | |
178 | |
179 // Setter for expected height. | |
180 void set_expected_height(int expected) { expected_height_ = expected; } | |
181 | |
182 // Uses the current frame to set the expected height. | |
183 void SetExpectedHeight(); | |
184 | |
185 private: | |
186 // The expected height of the expression stack where the target will | |
187 // be bound, statically known at initialization time. | |
188 int expected_height_; | |
189 }; | |
190 | |
191 } } // namespace v8::internal | |
192 | |
193 #endif // V8_JUMP_TARGET_LIGHT_H_ | |
OLD | NEW |