| 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 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 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 protected: | |
| 139 // Directionality flag set at initialization time. | |
| 140 Directionality direction_; | |
| 141 | |
| 142 // A list of frames reaching this block via forward jumps. | |
| 143 ZoneList<VirtualFrame*> reaching_frames_; | |
| 144 | |
| 145 // A parallel list of labels for merge code. | |
| 146 ZoneList<Label> merge_labels_; | |
| 147 | |
| 148 // The frame used on entry to the block and expected at backward | |
| 149 // jumps to the block. Set when the jump target is bound, but may | |
| 150 // or may not be set for forward-only blocks. | |
| 151 VirtualFrame* entry_frame_; | |
| 152 | |
| 153 // The actual entry label of the block. | |
| 154 Label entry_label_; | |
| 155 | |
| 156 // Implementations of Jump, Branch, and Bind with all arguments and | |
| 157 // return values using the virtual frame. | |
| 158 void DoJump(); | |
| 159 void DoBranch(Condition cc, Hint hint); | |
| 160 void DoBind(); | |
| 161 | |
| 162 private: | |
| 163 // Add a virtual frame reaching this labeled block via a forward jump, | |
| 164 // and a corresponding merge code label. | |
| 165 void AddReachingFrame(VirtualFrame* frame); | |
| 166 | |
| 167 // Perform initialization required during entry frame computation | |
| 168 // after setting the virtual frame element at index in frame to be | |
| 169 // target. | |
| 170 inline void InitializeEntryElement(int index, FrameElement* target); | |
| 171 | |
| 172 // Compute a frame to use for entry to this block. | |
| 173 void ComputeEntryFrame(); | |
| 174 | |
| 175 DISALLOW_COPY_AND_ASSIGN(JumpTarget); | |
| 176 }; | |
| 177 | |
| 178 | |
| 179 // ------------------------------------------------------------------------- | |
| 180 // Break targets | |
| 181 // | |
| 182 // A break target is a jump target that can be used to break out of a | |
| 183 // statement that keeps extra state on the stack (eg, for/in or | |
| 184 // try/finally). They know the expected stack height at the target | |
| 185 // and will drop state from nested statements as part of merging. | |
| 186 // | |
| 187 // Break targets are used for return, break, and continue targets. | |
| 188 | |
| 189 class BreakTarget : public JumpTarget { | |
| 190 public: | |
| 191 // Construct a break target. | |
| 192 BreakTarget() {} | |
| 193 explicit BreakTarget(JumpTarget::Directionality direction) | |
| 194 : JumpTarget(direction) { } | |
| 195 | |
| 196 virtual ~BreakTarget() {} | |
| 197 | |
| 198 // Set the direction of the break target. | |
| 199 virtual void set_direction(Directionality direction); | |
| 200 | |
| 201 // Copy the state of this break target to the destination. The | |
| 202 // lists of forward-reaching frames and merge-point labels are | |
| 203 // copied. All virtual frame pointers are copied, not the | |
| 204 // pointed-to frames. The previous state of the destination is | |
| 205 // overwritten, without deallocating pointed-to virtual frames. | |
| 206 void CopyTo(BreakTarget* destination); | |
| 207 | |
| 208 // Emit a jump to the target. There must be a current frame at the | |
| 209 // jump and there will be no current frame after the jump. | |
| 210 virtual void Jump(); | |
| 211 virtual void Jump(Result* arg); | |
| 212 | |
| 213 // Emit a conditional branch to the target. There must be a current | |
| 214 // frame at the branch. The current frame will fall through to the | |
| 215 // code after the branch. | |
| 216 virtual void Branch(Condition cc, Hint hint = no_hint); | |
| 217 virtual void Branch(Condition cc, Result* arg, Hint hint = no_hint); | |
| 218 | |
| 219 // Bind a break target. If there is no current frame at the binding | |
| 220 // site, there must be at least one frame reaching via a forward | |
| 221 // jump. | |
| 222 virtual void Bind(); | |
| 223 virtual void Bind(Result* arg); | |
| 224 | |
| 225 // Setter for expected height. | |
| 226 void set_expected_height(int expected) { expected_height_ = expected; } | |
| 227 | |
| 228 private: | |
| 229 // The expected height of the expression stack where the target will | |
| 230 // be bound, statically known at initialization time. | |
| 231 int expected_height_; | |
| 232 | |
| 233 DISALLOW_COPY_AND_ASSIGN(BreakTarget); | |
| 234 }; | |
| 235 | |
| 236 } } // namespace v8::internal | |
| 237 | |
| 238 #endif // V8_JUMP_TARGET_HEAVY_H_ | |
| OLD | NEW |