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_HEAVY_H_ |
| 29 #define V8_JUMP_TARGET_HEAVY_H_ |
| 30 |
| 31 #include "macro-assembler.h" |
| 32 #include "zone-inl.h" |
| 33 |
| 34 namespace v8 { |
| 35 namespace internal { |
| 36 |
| 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 } } // namespace v8::internal |
| 241 |
| 242 #endif // V8_JUMP_TARGET_HEAVY_H_ |
OLD | NEW |