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 const VirtualFrame* entry_frame() const { | |
78 return entry_frame_set_ ? &entry_frame_ : NULL; | |
79 } | |
80 | |
81 void set_entry_frame(VirtualFrame* frame) { | |
82 entry_frame_ = *frame; | |
83 } | |
84 | |
85 // Predicates testing the state of the encapsulated label. | |
86 bool is_bound() const { return entry_label_.is_bound(); } | |
87 bool is_linked() const { return entry_label_.is_linked(); } | |
88 bool is_unused() const { return entry_label_.is_unused(); } | |
89 | |
90 // Copy the state of this jump target to the destination. | |
91 inline void CopyTo(JumpTarget* destination) { | |
92 *destination = *this; | |
93 } | |
94 | |
95 // Emit a jump to the target. There must be a current frame at the | |
96 // jump and there will be no current frame after the jump. | |
97 virtual void Jump(); | |
98 | |
99 // Emit a conditional branch to the target. There must be a current | |
100 // frame at the branch. The current frame will fall through to the | |
101 // code after the branch. The arg is a result that is live both at | |
102 // the target and the fall-through. | |
103 virtual void Branch(Condition cc, Hint hint = no_hint); | |
104 | |
105 // Bind a jump target. If there is no current frame at the binding | |
106 // site, there must be at least one frame reaching via a forward | |
107 // jump. | |
108 virtual void Bind(); | |
109 | |
110 // Emit a call to a jump target. There must be a current frame at | |
111 // the call. The frame at the target is the same as the current | |
112 // frame except for an extra return address on top of it. The frame | |
113 // after the call is the same as the frame before the call. | |
114 void Call(); | |
115 | |
116 protected: | |
117 // Has an entry frame been found? | |
118 bool entry_frame_set_; | |
119 | |
120 // The frame used on entry to the block and expected at backward | |
121 // jumps to the block. Set the first time something branches to this | |
122 // jump target. | |
123 VirtualFrame entry_frame_; | |
124 | |
125 // The actual entry label of the block. | |
126 Label entry_label_; | |
127 | |
128 // Implementations of Jump, Branch, and Bind with all arguments and | |
129 // return values using the virtual frame. | |
130 void DoJump(); | |
131 void DoBranch(Condition cc, Hint hint); | |
132 void DoBind(); | |
Søren Thygesen Gjesse
2010/05/06 07:48:11
private:
DISALLOW_COPY_AND_ASSIGN?
Erik Corry
2010/05/10 10:34:10
We actually do copy and assign them and I don't se
| |
133 }; | |
134 | |
135 | |
136 // ------------------------------------------------------------------------- | |
137 // Break targets | |
138 // | |
139 // A break target is a jump target that can be used to break out of a | |
140 // statement that keeps extra state on the stack (eg, for/in or | |
141 // try/finally). They know the expected stack height at the target | |
142 // and will drop state from nested statements as part of merging. | |
143 // | |
144 // Break targets are used for return, break, and continue targets. | |
145 | |
146 class BreakTarget : public JumpTarget { | |
147 public: | |
148 // Construct a break target. | |
149 inline BreakTarget(); | |
150 | |
151 virtual ~BreakTarget() {} | |
152 | |
153 // Copy the state of this jump target to the destination. | |
154 inline void CopyTo(BreakTarget* destination) { | |
155 *destination = *this; | |
156 } | |
157 | |
158 // Emit a jump to the target. There must be a current frame at the | |
159 // jump and there will be no current frame after the jump. | |
160 virtual void Jump(); | |
161 | |
162 // Emit a conditional branch to the target. There must be a current | |
163 // frame at the branch. The current frame will fall through to the | |
164 // code after the branch. | |
165 virtual void Branch(Condition cc, Hint hint = no_hint); | |
166 | |
167 // Bind a break target. If there is no current frame at the binding | |
168 // site, there must be at least one frame reaching via a forward | |
169 // jump. | |
170 virtual void Bind(); | |
171 | |
172 // Setter for expected height. | |
173 void set_expected_height(int expected) { expected_height_ = expected; } | |
174 | |
175 // Uses the current frame to set the expected height. | |
176 void SetExpectedHeight(); | |
177 | |
178 private: | |
179 // The expected height of the expression stack where the target will | |
180 // be bound, statically known at initialization time. | |
181 int expected_height_; | |
Søren Thygesen Gjesse
2010/05/06 07:48:11
DISALLOW_COPY_AND_ASSIGN?
| |
182 }; | |
183 | |
184 } } // namespace v8::internal | |
185 | |
186 #endif // V8_JUMP_TARGET_LIGHT_H_ | |
OLD | NEW |