| 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 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_JUMP_TARGET_H_ | 28 #ifndef V8_JUMP_TARGET_H_ |
| 29 #define V8_JUMP_TARGET_H_ | 29 #define V8_JUMP_TARGET_H_ |
| 30 | 30 |
| 31 #include "macro-assembler.h" | 31 #if V8_TARGET_ARCH_IA32 |
| 32 #include "zone-inl.h" | 32 #include "jump-target-heavy.h" |
| 33 #elif V8_TARGET_ARCH_X64 |
| 34 #include "jump-target-heavy.h" |
| 35 #elif V8_TARGET_ARCH_ARM |
| 36 #include "jump-target-light.h" |
| 37 #elif V8_TARGET_ARCH_MIPS |
| 38 #include "jump-target-light.h" |
| 39 #else |
| 40 #error Unsupported target architecture. |
| 41 #endif |
| 33 | 42 |
| 34 namespace v8 { | 43 namespace v8 { |
| 35 namespace internal { | 44 namespace internal { |
| 36 | 45 |
| 37 // Forward declarations. | |
| 38 class FrameElement; | |
| 39 class Result; | |
| 40 class VirtualFrame; | |
| 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 used to generate code and to provide | |
| 64 // access to a current frame. | |
| 65 explicit JumpTarget(Directionality direction) | |
| 66 : direction_(direction), | |
| 67 reaching_frames_(0), | |
| 68 merge_labels_(0), | |
| 69 entry_frame_(NULL) { | |
| 70 } | |
| 71 | |
| 72 // Construct a jump target. | |
| 73 JumpTarget() | |
| 74 : direction_(FORWARD_ONLY), | |
| 75 reaching_frames_(0), | |
| 76 merge_labels_(0), | |
| 77 entry_frame_(NULL) { | |
| 78 } | |
| 79 | |
| 80 virtual ~JumpTarget() {} | |
| 81 | |
| 82 // Set the direction of the jump target. | |
| 83 virtual void set_direction(Directionality direction) { | |
| 84 direction_ = direction; | |
| 85 } | |
| 86 | |
| 87 // Treat the jump target as a fresh one. The state is reset. | |
| 88 void Unuse(); | |
| 89 | |
| 90 inline CodeGenerator* cgen(); | |
| 91 | |
| 92 Label* entry_label() { return &entry_label_; } | |
| 93 | |
| 94 VirtualFrame* entry_frame() const { return entry_frame_; } | |
| 95 void set_entry_frame(VirtualFrame* frame) { | |
| 96 entry_frame_ = frame; | |
| 97 } | |
| 98 | |
| 99 // Predicates testing the state of the encapsulated label. | |
| 100 bool is_bound() const { return entry_label_.is_bound(); } | |
| 101 bool is_linked() const { | |
| 102 return !is_bound() && !reaching_frames_.is_empty(); | |
| 103 } | |
| 104 bool is_unused() const { | |
| 105 // This is !is_bound() && !is_linked(). | |
| 106 return !is_bound() && reaching_frames_.is_empty(); | |
| 107 } | |
| 108 | |
| 109 // Emit a jump to the target. There must be a current frame at the | |
| 110 // jump and there will be no current frame after the jump. | |
| 111 virtual void Jump(); | |
| 112 virtual void Jump(Result* arg); | |
| 113 | |
| 114 // Emit a conditional branch to the target. There must be a current | |
| 115 // frame at the branch. The current frame will fall through to the | |
| 116 // code after the branch. The arg is a result that is live both at | |
| 117 // the target and the fall-through. | |
| 118 virtual void Branch(Condition cc, Hint hint = no_hint); | |
| 119 virtual void Branch(Condition cc, Result* arg, Hint hint = no_hint); | |
| 120 virtual void Branch(Condition cc, | |
| 121 Result* arg0, | |
| 122 Result* arg1, | |
| 123 Hint hint = no_hint); | |
| 124 | |
| 125 // Bind a jump target. If there is no current frame at the binding | |
| 126 // site, there must be at least one frame reaching via a forward | |
| 127 // jump. | |
| 128 virtual void Bind(); | |
| 129 virtual void Bind(Result* arg); | |
| 130 virtual void Bind(Result* arg0, Result* arg1); | |
| 131 | |
| 132 // Emit a call to a jump target. There must be a current frame at | |
| 133 // the call. The frame at the target is the same as the current | |
| 134 // frame except for an extra return address on top of it. The frame | |
| 135 // after the call is the same as the frame before the call. | |
| 136 void Call(); | |
| 137 | |
| 138 static void set_compiling_deferred_code(bool flag) { | |
| 139 compiling_deferred_code_ = flag; | |
| 140 } | |
| 141 | |
| 142 protected: | |
| 143 // Directionality flag set at initialization time. | |
| 144 Directionality direction_; | |
| 145 | |
| 146 // A list of frames reaching this block via forward jumps. | |
| 147 ZoneList<VirtualFrame*> reaching_frames_; | |
| 148 | |
| 149 // A parallel list of labels for merge code. | |
| 150 ZoneList<Label> merge_labels_; | |
| 151 | |
| 152 // The frame used on entry to the block and expected at backward | |
| 153 // jumps to the block. Set when the jump target is bound, but may | |
| 154 // or may not be set for forward-only blocks. | |
| 155 VirtualFrame* entry_frame_; | |
| 156 | |
| 157 // The actual entry label of the block. | |
| 158 Label entry_label_; | |
| 159 | |
| 160 // Implementations of Jump, Branch, and Bind with all arguments and | |
| 161 // return values using the virtual frame. | |
| 162 void DoJump(); | |
| 163 void DoBranch(Condition cc, Hint hint); | |
| 164 void DoBind(); | |
| 165 | |
| 166 private: | |
| 167 static bool compiling_deferred_code_; | |
| 168 | |
| 169 // Add a virtual frame reaching this labeled block via a forward jump, | |
| 170 // and a corresponding merge code label. | |
| 171 void AddReachingFrame(VirtualFrame* frame); | |
| 172 | |
| 173 // Perform initialization required during entry frame computation | |
| 174 // after setting the virtual frame element at index in frame to be | |
| 175 // target. | |
| 176 inline void InitializeEntryElement(int index, FrameElement* target); | |
| 177 | |
| 178 // Compute a frame to use for entry to this block. | |
| 179 void ComputeEntryFrame(); | |
| 180 | |
| 181 DISALLOW_COPY_AND_ASSIGN(JumpTarget); | |
| 182 }; | |
| 183 | |
| 184 | |
| 185 // ------------------------------------------------------------------------- | |
| 186 // Break targets | |
| 187 // | |
| 188 // A break target is a jump target that can be used to break out of a | |
| 189 // statement that keeps extra state on the stack (eg, for/in or | |
| 190 // try/finally). They know the expected stack height at the target | |
| 191 // and will drop state from nested statements as part of merging. | |
| 192 // | |
| 193 // Break targets are used for return, break, and continue targets. | |
| 194 | |
| 195 class BreakTarget : public JumpTarget { | |
| 196 public: | |
| 197 // Construct a break target. | |
| 198 BreakTarget() {} | |
| 199 | |
| 200 virtual ~BreakTarget() {} | |
| 201 | |
| 202 // Set the direction of the break target. | |
| 203 virtual void set_direction(Directionality direction); | |
| 204 | |
| 205 // Copy the state of this break target to the destination. The | |
| 206 // lists of forward-reaching frames and merge-point labels are | |
| 207 // copied. All virtual frame pointers are copied, not the | |
| 208 // pointed-to frames. The previous state of the destination is | |
| 209 // overwritten, without deallocating pointed-to virtual frames. | |
| 210 void CopyTo(BreakTarget* destination); | |
| 211 | |
| 212 // Emit a jump to the target. There must be a current frame at the | |
| 213 // jump and there will be no current frame after the jump. | |
| 214 virtual void Jump(); | |
| 215 virtual void Jump(Result* arg); | |
| 216 | |
| 217 // Emit a conditional branch to the target. There must be a current | |
| 218 // frame at the branch. The current frame will fall through to the | |
| 219 // code after the branch. | |
| 220 virtual void Branch(Condition cc, Hint hint = no_hint); | |
| 221 virtual void Branch(Condition cc, Result* arg, Hint hint = no_hint); | |
| 222 | |
| 223 // Bind a break target. If there is no current frame at the binding | |
| 224 // site, there must be at least one frame reaching via a forward | |
| 225 // jump. | |
| 226 virtual void Bind(); | |
| 227 virtual void Bind(Result* arg); | |
| 228 | |
| 229 // Setter for expected height. | |
| 230 void set_expected_height(int expected) { expected_height_ = expected; } | |
| 231 | |
| 232 private: | |
| 233 // The expected height of the expression stack where the target will | |
| 234 // be bound, statically known at initialization time. | |
| 235 int expected_height_; | |
| 236 | |
| 237 DISALLOW_COPY_AND_ASSIGN(BreakTarget); | |
| 238 }; | |
| 239 | |
| 240 | |
| 241 // ------------------------------------------------------------------------- | 46 // ------------------------------------------------------------------------- |
| 242 // Shadow break targets | 47 // Shadow break targets |
| 243 // | 48 // |
| 244 // A shadow break target represents a break target that is temporarily | 49 // A shadow break target represents a break target that is temporarily |
| 245 // shadowed by another one (represented by the original during | 50 // shadowed by another one (represented by the original during |
| 246 // shadowing). They are used to catch jumps to labels in certain | 51 // shadowing). They are used to catch jumps to labels in certain |
| 247 // contexts, e.g. try blocks. After shadowing ends, the formerly | 52 // contexts, e.g. try blocks. After shadowing ends, the formerly |
| 248 // shadowed target is again represented by the original and the | 53 // shadowed target is again represented by the original and the |
| 249 // ShadowTarget can be used as a jump target in its own right, | 54 // ShadowTarget can be used as a jump target in its own right, |
| 250 // representing the formerly shadowing target. | 55 // representing the formerly shadowing target. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 273 // shadowing, the target that was shadowed. | 78 // shadowing, the target that was shadowed. |
| 274 BreakTarget* other_target_; | 79 BreakTarget* other_target_; |
| 275 | 80 |
| 276 #ifdef DEBUG | 81 #ifdef DEBUG |
| 277 bool is_shadowing_; | 82 bool is_shadowing_; |
| 278 #endif | 83 #endif |
| 279 | 84 |
| 280 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); | 85 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); |
| 281 }; | 86 }; |
| 282 | 87 |
| 283 | |
| 284 } } // namespace v8::internal | 88 } } // namespace v8::internal |
| 285 | 89 |
| 286 #endif // V8_JUMP_TARGET_H_ | 90 #endif // V8_JUMP_TARGET_H_ |
| OLD | NEW |