OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // all forward-reaching paths. When bound, an expected frame for the | 45 // all forward-reaching paths. When bound, an expected frame for the |
46 // block is determined and code is generated to merge to the expected | 46 // block is determined and code is generated to merge to the expected |
47 // frame. For backward jumps, the merge code is generated at the edge | 47 // frame. For backward jumps, the merge code is generated at the edge |
48 // leaving the predecessor block. | 48 // leaving the predecessor block. |
49 // | 49 // |
50 // A jump target must have been reached via control flow (either by | 50 // A jump target must have been reached via control flow (either by |
51 // jumping, branching, or falling through) at the time it is bound. | 51 // jumping, branching, or falling through) at the time it is bound. |
52 // In particular, this means that at least one of the control-flow | 52 // In particular, this means that at least one of the control-flow |
53 // graph edges reaching the target must be a forward edge. | 53 // graph edges reaching the target must be a forward edge. |
54 | 54 |
55 class JumpTarget : public Malloced { // Shadows are dynamically allocated. | 55 class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. |
56 public: | 56 public: |
57 // Forward-only jump targets can only be reached by forward CFG edges. | 57 // Forward-only jump targets can only be reached by forward CFG edges. |
58 enum Directionality { FORWARD_ONLY, BIDIRECTIONAL }; | 58 enum Directionality { FORWARD_ONLY, BIDIRECTIONAL }; |
59 | 59 |
60 // Construct a jump target with a given code generator used to generate | 60 // Construct a jump target with a given code generator used to generate |
61 // code and to provide access to a current frame. | 61 // code and to provide access to a current frame. |
62 explicit JumpTarget(CodeGenerator* cgen, | 62 explicit JumpTarget(CodeGenerator* cgen, |
63 Directionality direction = FORWARD_ONLY); | 63 Directionality direction = FORWARD_ONLY); |
64 | 64 |
65 // Construct a jump target without a code generator. A code | 65 // Construct a jump target without a code generator. A code |
66 // generator must be supplied before using the jump target as a | 66 // generator must be supplied before using the jump target as a |
67 // label. This is useful, eg, when break targets are embedded in | 67 // label. This is useful, eg, when break targets are embedded in |
68 // AST nodes. | 68 // AST nodes. |
69 JumpTarget(); | 69 JumpTarget(); |
70 | 70 |
71 // Supply a code generator and directionality to an already | 71 // Supply a code generator and directionality to an already |
72 // constructed jump target. This function expects to be given a | 72 // constructed jump target. This function expects to be given a |
73 // non-null code generator, and to be called only when the code | 73 // non-null code generator, and to be called only when the code |
74 // generator is not yet set. | 74 // generator is not yet set. |
75 virtual void Initialize(CodeGenerator* cgen, | 75 virtual void Initialize(CodeGenerator* cgen, |
76 Directionality direction = FORWARD_ONLY); | 76 Directionality direction = FORWARD_ONLY); |
77 | 77 |
78 virtual ~JumpTarget() { Unuse(); } | 78 // Treat the jump target as a fresh one. The state is reset. |
79 | |
80 // Treat the jump target as a fresh one. The state is reset and | |
81 // pointed-to virtual frames are deallocated. There should be no | |
82 // dangling jumps to the target. | |
83 void Unuse(); | 79 void Unuse(); |
84 | 80 |
85 // Reset the internal state of this jump target. Pointed-to virtual | |
86 // frames are not deallocated and dangling jumps to the target are | |
87 // left dangling. | |
88 void Reset(); | |
89 | |
90 // Accessors. | 81 // Accessors. |
91 CodeGenerator* code_generator() const { return cgen_; } | 82 CodeGenerator* code_generator() const { return cgen_; } |
92 | 83 |
93 Label* entry_label() { return &entry_label_; } | 84 Label* entry_label() { return &entry_label_; } |
94 | 85 |
95 VirtualFrame* entry_frame() const { return entry_frame_; } | 86 VirtualFrame* entry_frame() const { return entry_frame_; } |
96 void set_entry_frame(VirtualFrame* frame) { | 87 void set_entry_frame(VirtualFrame* frame) { |
97 entry_frame_ = frame; | 88 entry_frame_ = frame; |
98 } | 89 } |
99 | 90 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 protected: | 159 protected: |
169 // The code generator gives access to its current frame. | 160 // The code generator gives access to its current frame. |
170 CodeGenerator* cgen_; | 161 CodeGenerator* cgen_; |
171 | 162 |
172 // Used to emit code. | 163 // Used to emit code. |
173 MacroAssembler* masm_; | 164 MacroAssembler* masm_; |
174 | 165 |
175 // Directionality flag set at initialization time. | 166 // Directionality flag set at initialization time. |
176 Directionality direction_; | 167 Directionality direction_; |
177 | 168 |
| 169 // A target is bound if its Bind member function has been called. |
| 170 // It is linked if it is not bound but its Jump, Branch, or Call |
| 171 // member functions have been called. |
| 172 bool is_bound_; |
| 173 bool is_linked_; |
| 174 |
178 // A list of frames reaching this block via forward jumps. | 175 // A list of frames reaching this block via forward jumps. |
179 List<VirtualFrame*> reaching_frames_; | 176 ZoneList<VirtualFrame*> reaching_frames_; |
180 | 177 |
181 // A parallel list of labels for merge code. | 178 // A parallel list of labels for merge code. |
182 List<Label> merge_labels_; | 179 ZoneList<Label> merge_labels_; |
183 | 180 |
184 // The frame used on entry to the block and expected at backward | 181 // The frame used on entry to the block and expected at backward |
185 // jumps to the block. Set when the jump target is bound, but may | 182 // jumps to the block. Set when the jump target is bound, but may |
186 // or may not be set for forward-only blocks. | 183 // or may not be set for forward-only blocks. |
187 VirtualFrame* entry_frame_; | 184 VirtualFrame* entry_frame_; |
188 | 185 |
189 // The actual entry label of the block. | 186 // The actual entry label of the block. |
190 Label entry_label_; | 187 Label entry_label_; |
191 | 188 |
192 // A target is bound if its Bind member function has been called. | |
193 // It is linked if it is not bound but its Jump, Branch, or Call | |
194 // member functions have been called. | |
195 bool is_bound_; | |
196 bool is_linked_; | |
197 | |
198 // Implementations of Jump, Branch, and Bind with all arguments and | 189 // Implementations of Jump, Branch, and Bind with all arguments and |
199 // return values using the virtual frame. | 190 // return values using the virtual frame. |
200 void DoJump(); | 191 void DoJump(); |
201 void DoBranch(Condition cc, Hint hint); | 192 void DoBranch(Condition cc, Hint hint); |
202 void DoBind(int mergable_elements); | 193 void DoBind(int mergable_elements); |
203 | 194 |
204 private: | 195 private: |
205 static bool compiling_deferred_code_; | 196 static bool compiling_deferred_code_; |
206 | 197 |
207 // Add a virtual frame reaching this labeled block via a forward jump, | 198 // Add a virtual frame reaching this labeled block via a forward jump, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // representing the formerly shadowing target. | 280 // representing the formerly shadowing target. |
290 | 281 |
291 class ShadowTarget : public BreakTarget { | 282 class ShadowTarget : public BreakTarget { |
292 public: | 283 public: |
293 // Construct a shadow jump target. After construction the shadow | 284 // Construct a shadow jump target. After construction the shadow |
294 // target object holds the state of the original target, and the | 285 // target object holds the state of the original target, and the |
295 // original target is actually a fresh one that intercepts control | 286 // original target is actually a fresh one that intercepts control |
296 // flow intended for the shadowed one. | 287 // flow intended for the shadowed one. |
297 explicit ShadowTarget(BreakTarget* shadowed); | 288 explicit ShadowTarget(BreakTarget* shadowed); |
298 | 289 |
299 virtual ~ShadowTarget() { | |
300 ASSERT(!is_shadowing_); | |
301 } | |
302 | |
303 // End shadowing. After shadowing ends, the original jump target | 290 // End shadowing. After shadowing ends, the original jump target |
304 // again gives access to the formerly shadowed target and the shadow | 291 // again gives access to the formerly shadowed target and the shadow |
305 // target object gives access to the formerly shadowing target. | 292 // target object gives access to the formerly shadowing target. |
306 void StopShadowing(); | 293 void StopShadowing(); |
307 | 294 |
308 // During shadowing, the currently shadowing target. After | 295 // During shadowing, the currently shadowing target. After |
309 // shadowing, the target that was shadowed. | 296 // shadowing, the target that was shadowed. |
310 BreakTarget* other_target() const { return other_target_; } | 297 BreakTarget* other_target() const { return other_target_; } |
311 | 298 |
312 private: | 299 private: |
313 // During shadowing, the currently shadowing target. After | 300 // During shadowing, the currently shadowing target. After |
314 // shadowing, the target that was shadowed. | 301 // shadowing, the target that was shadowed. |
315 BreakTarget* other_target_; | 302 BreakTarget* other_target_; |
316 | 303 |
317 #ifdef DEBUG | 304 #ifdef DEBUG |
318 bool is_shadowing_; | 305 bool is_shadowing_; |
319 #endif | 306 #endif |
320 | 307 |
321 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); | 308 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); |
322 }; | 309 }; |
323 | 310 |
324 | 311 |
325 } } // namespace v8::internal | 312 } } // namespace v8::internal |
326 | 313 |
327 #endif // V8_JUMP_TARGET_H_ | 314 #endif // V8_JUMP_TARGET_H_ |
OLD | NEW |