jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 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_HYDROGEN_H_ |
| 29 | #define V8_HYDROGEN_H_ |
| 30 | |
| 31 | #include "v8.h" |
| 32 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 33 | #include "allocation.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 34 | #include "ast.h" |
| 35 | #include "compiler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "hydrogen-instructions.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 37 | #include "type-info.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 38 | #include "zone.h" |
| 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
| 43 | // Forward declarations. |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 44 | class BitVector; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 45 | class FunctionState; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 46 | class HEnvironment; |
| 47 | class HGraph; |
| 48 | class HLoopInformation; |
| 49 | class HTracer; |
| 50 | class LAllocator; |
| 51 | class LChunk; |
| 52 | class LiveRange; |
| 53 | |
| 54 | |
| 55 | class HBasicBlock: public ZoneObject { |
| 56 | public: |
| 57 | explicit HBasicBlock(HGraph* graph); |
| 58 | virtual ~HBasicBlock() { } |
| 59 | |
| 60 | // Simple accessors. |
| 61 | int block_id() const { return block_id_; } |
| 62 | void set_block_id(int id) { block_id_ = id; } |
| 63 | HGraph* graph() const { return graph_; } |
| 64 | const ZoneList<HPhi*>* phis() const { return &phis_; } |
| 65 | HInstruction* first() const { return first_; } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 66 | HInstruction* last() const { return last_; } |
| 67 | void set_last(HInstruction* instr) { last_ = instr; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 68 | HInstruction* GetLastInstruction(); |
| 69 | HControlInstruction* end() const { return end_; } |
| 70 | HLoopInformation* loop_information() const { return loop_information_; } |
| 71 | const ZoneList<HBasicBlock*>* predecessors() const { return &predecessors_; } |
| 72 | bool HasPredecessor() const { return predecessors_.length() > 0; } |
| 73 | const ZoneList<HBasicBlock*>* dominated_blocks() const { |
| 74 | return &dominated_blocks_; |
| 75 | } |
| 76 | const ZoneList<int>* deleted_phis() const { |
| 77 | return &deleted_phis_; |
| 78 | } |
| 79 | void RecordDeletedPhi(int merge_index) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 80 | deleted_phis_.Add(merge_index, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 81 | } |
| 82 | HBasicBlock* dominator() const { return dominator_; } |
| 83 | HEnvironment* last_environment() const { return last_environment_; } |
| 84 | int argument_count() const { return argument_count_; } |
| 85 | void set_argument_count(int count) { argument_count_ = count; } |
| 86 | int first_instruction_index() const { return first_instruction_index_; } |
| 87 | void set_first_instruction_index(int index) { |
| 88 | first_instruction_index_ = index; |
| 89 | } |
| 90 | int last_instruction_index() const { return last_instruction_index_; } |
| 91 | void set_last_instruction_index(int index) { |
| 92 | last_instruction_index_ = index; |
| 93 | } |
| 94 | |
| 95 | void AttachLoopInformation(); |
| 96 | void DetachLoopInformation(); |
| 97 | bool IsLoopHeader() const { return loop_information() != NULL; } |
| 98 | bool IsStartBlock() const { return block_id() == 0; } |
| 99 | void PostProcessLoopHeader(IterationStatement* stmt); |
| 100 | |
| 101 | bool IsFinished() const { return end_ != NULL; } |
| 102 | void AddPhi(HPhi* phi); |
| 103 | void RemovePhi(HPhi* phi); |
| 104 | void AddInstruction(HInstruction* instr); |
| 105 | bool Dominates(HBasicBlock* other) const; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 106 | int LoopNestingDepth() const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 107 | |
| 108 | void SetInitialEnvironment(HEnvironment* env); |
| 109 | void ClearEnvironment() { last_environment_ = NULL; } |
| 110 | bool HasEnvironment() const { return last_environment_ != NULL; } |
| 111 | void UpdateEnvironment(HEnvironment* env) { last_environment_ = env; } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 112 | HBasicBlock* parent_loop_header() const { return parent_loop_header_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 113 | |
| 114 | void set_parent_loop_header(HBasicBlock* block) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 115 | ASSERT(parent_loop_header_ == NULL); |
| 116 | parent_loop_header_ = block; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 117 | } |
| 118 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 119 | bool HasParentLoopHeader() const { return parent_loop_header_ != NULL; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 120 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 121 | void SetJoinId(int ast_id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 122 | |
| 123 | void Finish(HControlInstruction* last); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 124 | void FinishExit(HControlInstruction* instruction); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 125 | void Goto(HBasicBlock* block, FunctionState* state = NULL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 126 | |
| 127 | int PredecessorIndexOf(HBasicBlock* predecessor) const; |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 128 | void AddSimulate(int ast_id) { AddInstruction(CreateSimulate(ast_id)); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 129 | void AssignCommonDominator(HBasicBlock* other); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 130 | void AssignLoopSuccessorDominators(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 131 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 132 | void FinishExitWithDeoptimization(HDeoptimize::UseEnvironment has_uses) { |
| 133 | FinishExit(CreateDeoptimize(has_uses)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 134 | } |
| 135 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 136 | // Add the inlined function exit sequence, adding an HLeaveInlined |
| 137 | // instruction and updating the bailout environment. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 138 | void AddLeaveInlined(HValue* return_value, |
| 139 | HBasicBlock* target, |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 140 | FunctionState* state = NULL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 141 | |
| 142 | // If a target block is tagged as an inline function return, all |
| 143 | // predecessors should contain the inlined exit sequence: |
| 144 | // |
| 145 | // LeaveInlined |
| 146 | // Simulate (caller's environment) |
| 147 | // Goto (target block) |
| 148 | bool IsInlineReturnTarget() const { return is_inline_return_target_; } |
| 149 | void MarkAsInlineReturnTarget() { is_inline_return_target_ = true; } |
| 150 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 151 | bool IsDeoptimizing() const { return is_deoptimizing_; } |
| 152 | void MarkAsDeoptimizing() { is_deoptimizing_ = true; } |
| 153 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 154 | bool IsLoopSuccessorDominator() const { |
| 155 | return dominates_loop_successors_; |
| 156 | } |
| 157 | void MarkAsLoopSuccessorDominator() { |
| 158 | dominates_loop_successors_ = true; |
| 159 | } |
| 160 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 161 | inline Zone* zone() const; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 162 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 163 | #ifdef DEBUG |
| 164 | void Verify(); |
| 165 | #endif |
| 166 | |
| 167 | private: |
| 168 | void RegisterPredecessor(HBasicBlock* pred); |
| 169 | void AddDominatedBlock(HBasicBlock* block); |
| 170 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 171 | HSimulate* CreateSimulate(int ast_id); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 172 | HDeoptimize* CreateDeoptimize(HDeoptimize::UseEnvironment has_uses); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 173 | |
| 174 | int block_id_; |
| 175 | HGraph* graph_; |
| 176 | ZoneList<HPhi*> phis_; |
| 177 | HInstruction* first_; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 178 | HInstruction* last_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 179 | HControlInstruction* end_; |
| 180 | HLoopInformation* loop_information_; |
| 181 | ZoneList<HBasicBlock*> predecessors_; |
| 182 | HBasicBlock* dominator_; |
| 183 | ZoneList<HBasicBlock*> dominated_blocks_; |
| 184 | HEnvironment* last_environment_; |
| 185 | // Outgoing parameter count at block exit, set during lithium translation. |
| 186 | int argument_count_; |
| 187 | // Instruction indices into the lithium code stream. |
| 188 | int first_instruction_index_; |
| 189 | int last_instruction_index_; |
| 190 | ZoneList<int> deleted_phis_; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 191 | HBasicBlock* parent_loop_header_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 192 | bool is_inline_return_target_; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 193 | bool is_deoptimizing_; |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 194 | bool dominates_loop_successors_; |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | class HPredecessorIterator BASE_EMBEDDED { |
| 199 | public: |
| 200 | explicit HPredecessorIterator(HBasicBlock* block) |
| 201 | : predecessor_list_(block->predecessors()), current_(0) { } |
| 202 | |
| 203 | bool Done() { return current_ >= predecessor_list_->length(); } |
| 204 | HBasicBlock* Current() { return predecessor_list_->at(current_); } |
| 205 | void Advance() { current_++; } |
| 206 | |
| 207 | private: |
| 208 | const ZoneList<HBasicBlock*>* predecessor_list_; |
| 209 | int current_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | |
| 213 | class HLoopInformation: public ZoneObject { |
| 214 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 215 | HLoopInformation(HBasicBlock* loop_header, Zone* zone) |
| 216 | : back_edges_(4, zone), |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 217 | loop_header_(loop_header), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 218 | blocks_(8, zone), |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 219 | stack_check_(NULL) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 220 | blocks_.Add(loop_header, zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 221 | } |
| 222 | virtual ~HLoopInformation() {} |
| 223 | |
| 224 | const ZoneList<HBasicBlock*>* back_edges() const { return &back_edges_; } |
| 225 | const ZoneList<HBasicBlock*>* blocks() const { return &blocks_; } |
| 226 | HBasicBlock* loop_header() const { return loop_header_; } |
| 227 | HBasicBlock* GetLastBackEdge() const; |
| 228 | void RegisterBackEdge(HBasicBlock* block); |
| 229 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 230 | HStackCheck* stack_check() const { return stack_check_; } |
| 231 | void set_stack_check(HStackCheck* stack_check) { |
| 232 | stack_check_ = stack_check; |
| 233 | } |
| 234 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 235 | private: |
| 236 | void AddBlock(HBasicBlock* block); |
| 237 | |
| 238 | ZoneList<HBasicBlock*> back_edges_; |
| 239 | HBasicBlock* loop_header_; |
| 240 | ZoneList<HBasicBlock*> blocks_; |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 241 | HStackCheck* stack_check_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 242 | }; |
| 243 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 244 | class BoundsCheckTable; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 245 | class HGraph: public ZoneObject { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 246 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 247 | HGraph(CompilationInfo* info, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 248 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 249 | Isolate* isolate() { return isolate_; } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 250 | Zone* zone() const { return zone_; } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 251 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 252 | const ZoneList<HBasicBlock*>* blocks() const { return &blocks_; } |
| 253 | const ZoneList<HPhi*>* phi_list() const { return phi_list_; } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 254 | HBasicBlock* entry_block() const { return entry_block_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 255 | HEnvironment* start_environment() const { return start_environment_; } |
| 256 | |
| 257 | void InitializeInferredTypes(); |
| 258 | void InsertTypeConversions(); |
| 259 | void InsertRepresentationChanges(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 260 | void MarkDeoptimizeOnUndefined(); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 261 | void ComputeMinusZeroChecks(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 262 | bool ProcessArgumentsObject(); |
| 263 | void EliminateRedundantPhis(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 264 | void EliminateUnreachablePhis(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 265 | void Canonicalize(); |
| 266 | void OrderBlocks(); |
| 267 | void AssignDominators(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 268 | void ReplaceCheckedValues(); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 269 | void EliminateRedundantBoundsChecks(); |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 270 | void DehoistSimpleArrayIndexComputations(); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 271 | void PropagateDeoptimizingMark(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 272 | |
| 273 | // Returns false if there are phi-uses of the arguments-object |
| 274 | // which are not supported by the optimizing compiler. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 275 | bool CheckArgumentsPhiUses(); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 276 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 277 | // Returns false if there are phi-uses of an uninitialized const |
| 278 | // which are not supported by the optimizing compiler. |
| 279 | bool CheckConstPhiUses(); |
| 280 | |
| 281 | void CollectPhis(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 282 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 283 | Handle<Code> Compile(CompilationInfo* info, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 284 | |
| 285 | void set_undefined_constant(HConstant* constant) { |
| 286 | undefined_constant_.set(constant); |
| 287 | } |
| 288 | HConstant* GetConstantUndefined() const { return undefined_constant_.get(); } |
| 289 | HConstant* GetConstant1(); |
| 290 | HConstant* GetConstantMinus1(); |
| 291 | HConstant* GetConstantTrue(); |
| 292 | HConstant* GetConstantFalse(); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 293 | HConstant* GetConstantHole(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 294 | |
| 295 | HBasicBlock* CreateBasicBlock(); |
| 296 | HArgumentsObject* GetArgumentsObject() const { |
| 297 | return arguments_object_.get(); |
| 298 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 299 | |
| 300 | void SetArgumentsObject(HArgumentsObject* object) { |
| 301 | arguments_object_.set(object); |
| 302 | } |
| 303 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 304 | int GetMaximumValueID() const { return values_.length(); } |
| 305 | int GetNextBlockID() { return next_block_id_++; } |
| 306 | int GetNextValueID(HValue* value) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 307 | values_.Add(value, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 308 | return values_.length() - 1; |
| 309 | } |
| 310 | HValue* LookupValue(int id) const { |
| 311 | if (id >= 0 && id < values_.length()) return values_[id]; |
| 312 | return NULL; |
| 313 | } |
| 314 | |
| 315 | #ifdef DEBUG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 316 | void Verify(bool do_full_verify) const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 317 | #endif |
| 318 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 319 | bool has_osr_loop_entry() { |
| 320 | return osr_loop_entry_.is_set(); |
| 321 | } |
| 322 | |
| 323 | HBasicBlock* osr_loop_entry() { |
| 324 | return osr_loop_entry_.get(); |
| 325 | } |
| 326 | |
| 327 | void set_osr_loop_entry(HBasicBlock* entry) { |
| 328 | osr_loop_entry_.set(entry); |
| 329 | } |
| 330 | |
| 331 | ZoneList<HUnknownOSRValue*>* osr_values() { |
| 332 | return osr_values_.get(); |
| 333 | } |
| 334 | |
| 335 | void set_osr_values(ZoneList<HUnknownOSRValue*>* values) { |
| 336 | osr_values_.set(values); |
| 337 | } |
| 338 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 339 | void MarkRecursive() { |
| 340 | is_recursive_ = true; |
| 341 | } |
| 342 | |
| 343 | bool is_recursive() const { |
| 344 | return is_recursive_; |
| 345 | } |
| 346 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 347 | private: |
| 348 | void Postorder(HBasicBlock* block, |
| 349 | BitVector* visited, |
| 350 | ZoneList<HBasicBlock*>* order, |
| 351 | HBasicBlock* loop_header); |
| 352 | void PostorderLoopBlocks(HLoopInformation* loop, |
| 353 | BitVector* visited, |
| 354 | ZoneList<HBasicBlock*>* order, |
| 355 | HBasicBlock* loop_header); |
| 356 | HConstant* GetConstant(SetOncePointer<HConstant>* pointer, |
| 357 | Object* value); |
| 358 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 359 | void MarkAsDeoptimizingRecursively(HBasicBlock* block); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 360 | void InsertTypeConversions(HInstruction* instr); |
| 361 | void PropagateMinusZeroChecks(HValue* value, BitVector* visited); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 362 | void RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi* phi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 363 | void InsertRepresentationChangeForUse(HValue* value, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 364 | HValue* use_value, |
| 365 | int use_index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 366 | Representation to); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 367 | void InsertRepresentationChangesForValue(HValue* value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 368 | void InferTypes(ZoneList<HValue*>* worklist); |
| 369 | void InitializeInferredTypes(int from_inclusive, int to_inclusive); |
| 370 | void CheckForBackEdge(HBasicBlock* block, HBasicBlock* successor); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 371 | void EliminateRedundantBoundsChecks(HBasicBlock* bb, BoundsCheckTable* table); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 372 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 373 | Isolate* isolate_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 374 | int next_block_id_; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 375 | HBasicBlock* entry_block_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 376 | HEnvironment* start_environment_; |
| 377 | ZoneList<HBasicBlock*> blocks_; |
| 378 | ZoneList<HValue*> values_; |
| 379 | ZoneList<HPhi*>* phi_list_; |
| 380 | SetOncePointer<HConstant> undefined_constant_; |
| 381 | SetOncePointer<HConstant> constant_1_; |
| 382 | SetOncePointer<HConstant> constant_minus1_; |
| 383 | SetOncePointer<HConstant> constant_true_; |
| 384 | SetOncePointer<HConstant> constant_false_; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 385 | SetOncePointer<HConstant> constant_hole_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 386 | SetOncePointer<HArgumentsObject> arguments_object_; |
| 387 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 388 | SetOncePointer<HBasicBlock> osr_loop_entry_; |
| 389 | SetOncePointer<ZoneList<HUnknownOSRValue*> > osr_values_; |
| 390 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 391 | Zone* zone_; |
| 392 | |
| 393 | bool is_recursive_; |
| 394 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 395 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 396 | }; |
| 397 | |
| 398 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 399 | Zone* HBasicBlock::zone() const { return graph_->zone(); } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 400 | |
| 401 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 402 | // Type of stack frame an environment might refer to. |
| 403 | enum FrameType { JS_FUNCTION, JS_CONSTRUCT, ARGUMENTS_ADAPTOR }; |
| 404 | |
| 405 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 406 | class HEnvironment: public ZoneObject { |
| 407 | public: |
| 408 | HEnvironment(HEnvironment* outer, |
| 409 | Scope* scope, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 410 | Handle<JSFunction> closure, |
| 411 | Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 412 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 413 | HEnvironment* DiscardInlined(bool drop_extra) { |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 414 | HEnvironment* outer = outer_; |
| 415 | while (outer->frame_type() != JS_FUNCTION) outer = outer->outer_; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 416 | if (drop_extra) outer->Drop(1); |
| 417 | return outer; |
| 418 | } |
| 419 | |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 420 | HEnvironment* arguments_environment() { |
| 421 | return outer()->frame_type() == ARGUMENTS_ADAPTOR ? outer() : this; |
| 422 | } |
| 423 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 424 | // Simple accessors. |
| 425 | Handle<JSFunction> closure() const { return closure_; } |
| 426 | const ZoneList<HValue*>* values() const { return &values_; } |
| 427 | const ZoneList<int>* assigned_variables() const { |
| 428 | return &assigned_variables_; |
| 429 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 430 | FrameType frame_type() const { return frame_type_; } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 431 | int parameter_count() const { return parameter_count_; } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 432 | int specials_count() const { return specials_count_; } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 433 | int local_count() const { return local_count_; } |
| 434 | HEnvironment* outer() const { return outer_; } |
| 435 | int pop_count() const { return pop_count_; } |
| 436 | int push_count() const { return push_count_; } |
| 437 | |
| 438 | int ast_id() const { return ast_id_; } |
| 439 | void set_ast_id(int id) { ast_id_ = id; } |
| 440 | |
| 441 | int length() const { return values_.length(); } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 442 | bool is_special_index(int i) const { |
| 443 | return i >= parameter_count() && i < parameter_count() + specials_count(); |
| 444 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 445 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 446 | int first_expression_index() const { |
| 447 | return parameter_count() + specials_count() + local_count(); |
| 448 | } |
| 449 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 450 | void Bind(Variable* variable, HValue* value) { |
| 451 | Bind(IndexFor(variable), value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 452 | } |
| 453 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 454 | void Bind(int index, HValue* value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 455 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 456 | void BindContext(HValue* value) { |
| 457 | Bind(parameter_count(), value); |
| 458 | } |
| 459 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 460 | HValue* Lookup(Variable* variable) const { |
| 461 | return Lookup(IndexFor(variable)); |
| 462 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 463 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 464 | HValue* Lookup(int index) const { |
| 465 | HValue* result = values_[index]; |
| 466 | ASSERT(result != NULL); |
| 467 | return result; |
| 468 | } |
| 469 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 470 | HValue* LookupContext() const { |
| 471 | // Return first special. |
| 472 | return Lookup(parameter_count()); |
| 473 | } |
| 474 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 475 | void Push(HValue* value) { |
| 476 | ASSERT(value != NULL); |
| 477 | ++push_count_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 478 | values_.Add(value, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 479 | } |
| 480 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 481 | HValue* Pop() { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 482 | ASSERT(!ExpressionStackIsEmpty()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 483 | if (push_count_ > 0) { |
| 484 | --push_count_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 485 | } else { |
| 486 | ++pop_count_; |
| 487 | } |
| 488 | return values_.RemoveLast(); |
| 489 | } |
| 490 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 491 | void Drop(int count); |
| 492 | |
| 493 | HValue* Top() const { return ExpressionStackAt(0); } |
| 494 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 495 | bool ExpressionStackIsEmpty() const; |
| 496 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 497 | HValue* ExpressionStackAt(int index_from_top) const { |
| 498 | int index = length() - index_from_top - 1; |
| 499 | ASSERT(HasExpressionAt(index)); |
| 500 | return values_[index]; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 501 | } |
| 502 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 503 | void SetExpressionStackAt(int index_from_top, HValue* value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 504 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 505 | HEnvironment* Copy() const; |
| 506 | HEnvironment* CopyWithoutHistory() const; |
| 507 | HEnvironment* CopyAsLoopHeader(HBasicBlock* block) const; |
| 508 | |
| 509 | // Create an "inlined version" of this environment, where the original |
| 510 | // environment is the outer environment but the top expression stack |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 511 | // elements are moved to an inner environment as parameters. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 512 | HEnvironment* CopyForInlining(Handle<JSFunction> target, |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 513 | int arguments, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 514 | FunctionLiteral* function, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 515 | HConstant* undefined, |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 516 | CallKind call_kind, |
| 517 | bool is_construct) const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 518 | |
| 519 | void AddIncomingEdge(HBasicBlock* block, HEnvironment* other); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 520 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 521 | void ClearHistory() { |
| 522 | pop_count_ = 0; |
| 523 | push_count_ = 0; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 524 | assigned_variables_.Rewind(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 525 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 526 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 527 | void SetValueAt(int index, HValue* value) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 528 | ASSERT(index < length()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 529 | values_[index] = value; |
| 530 | } |
| 531 | |
| 532 | void PrintTo(StringStream* stream); |
| 533 | void PrintToStd(); |
| 534 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 535 | Zone* zone() const { return zone_; } |
| 536 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 537 | private: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 538 | HEnvironment(const HEnvironment* other, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 539 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 540 | HEnvironment(HEnvironment* outer, |
| 541 | Handle<JSFunction> closure, |
| 542 | FrameType frame_type, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 543 | int arguments, |
| 544 | Zone* zone); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 545 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 546 | // Create an artificial stub environment (e.g. for argument adaptor or |
| 547 | // constructor stub). |
| 548 | HEnvironment* CreateStubEnvironment(HEnvironment* outer, |
| 549 | Handle<JSFunction> target, |
| 550 | FrameType frame_type, |
| 551 | int arguments) const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 552 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 553 | // True if index is included in the expression stack part of the environment. |
| 554 | bool HasExpressionAt(int index) const; |
| 555 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 556 | void Initialize(int parameter_count, int local_count, int stack_height); |
| 557 | void Initialize(const HEnvironment* other); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 558 | |
| 559 | // Map a variable to an environment index. Parameter indices are shifted |
| 560 | // by 1 (receiver is parameter index -1 but environment index 0). |
| 561 | // Stack-allocated local indices are shifted by the number of parameters. |
| 562 | int IndexFor(Variable* variable) const { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 563 | ASSERT(variable->IsStackAllocated()); |
| 564 | int shift = variable->IsParameter() |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 565 | ? 1 |
| 566 | : parameter_count_ + specials_count_; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 567 | return variable->index() + shift; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 568 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 569 | |
| 570 | Handle<JSFunction> closure_; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 571 | // Value array [parameters] [specials] [locals] [temporaries]. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 572 | ZoneList<HValue*> values_; |
| 573 | ZoneList<int> assigned_variables_; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 574 | FrameType frame_type_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 575 | int parameter_count_; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 576 | int specials_count_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 577 | int local_count_; |
| 578 | HEnvironment* outer_; |
| 579 | int pop_count_; |
| 580 | int push_count_; |
| 581 | int ast_id_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 582 | Zone* zone_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 583 | }; |
| 584 | |
| 585 | |
| 586 | class HGraphBuilder; |
| 587 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 588 | enum ArgumentsAllowedFlag { |
| 589 | ARGUMENTS_NOT_ALLOWED, |
| 590 | ARGUMENTS_ALLOWED |
| 591 | }; |
| 592 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 593 | // This class is not BASE_EMBEDDED because our inlining implementation uses |
| 594 | // new and delete. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 595 | class AstContext { |
| 596 | public: |
| 597 | bool IsEffect() const { return kind_ == Expression::kEffect; } |
| 598 | bool IsValue() const { return kind_ == Expression::kValue; } |
| 599 | bool IsTest() const { return kind_ == Expression::kTest; } |
| 600 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 601 | // 'Fill' this context with a hydrogen value. The value is assumed to |
| 602 | // have already been inserted in the instruction stream (or not need to |
| 603 | // be, e.g., HPhi). Call this function in tail position in the Visit |
| 604 | // functions for expressions. |
| 605 | virtual void ReturnValue(HValue* value) = 0; |
| 606 | |
| 607 | // Add a hydrogen instruction to the instruction stream (recording an |
| 608 | // environment simulation if necessary) and then fill this context with |
| 609 | // the instruction as value. |
| 610 | virtual void ReturnInstruction(HInstruction* instr, int ast_id) = 0; |
| 611 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 612 | // Finishes the current basic block and materialize a boolean for |
| 613 | // value context, nothing for effect, generate a branch for test context. |
| 614 | // Call this function in tail position in the Visit functions for |
| 615 | // expressions. |
| 616 | virtual void ReturnControl(HControlInstruction* instr, int ast_id) = 0; |
| 617 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 618 | void set_for_typeof(bool for_typeof) { for_typeof_ = for_typeof; } |
| 619 | bool is_for_typeof() { return for_typeof_; } |
| 620 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 621 | protected: |
| 622 | AstContext(HGraphBuilder* owner, Expression::Context kind); |
| 623 | virtual ~AstContext(); |
| 624 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 625 | HGraphBuilder* owner() const { return owner_; } |
| 626 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 627 | inline Zone* zone() const; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 628 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 629 | // We want to be able to assert, in a context-specific way, that the stack |
| 630 | // height makes sense when the context is filled. |
| 631 | #ifdef DEBUG |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 632 | int original_length_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 633 | #endif |
| 634 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 635 | private: |
| 636 | HGraphBuilder* owner_; |
| 637 | Expression::Context kind_; |
| 638 | AstContext* outer_; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 639 | bool for_typeof_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 640 | }; |
| 641 | |
| 642 | |
| 643 | class EffectContext: public AstContext { |
| 644 | public: |
| 645 | explicit EffectContext(HGraphBuilder* owner) |
| 646 | : AstContext(owner, Expression::kEffect) { |
| 647 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 648 | virtual ~EffectContext(); |
| 649 | |
| 650 | virtual void ReturnValue(HValue* value); |
| 651 | virtual void ReturnInstruction(HInstruction* instr, int ast_id); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 652 | virtual void ReturnControl(HControlInstruction* instr, int ast_id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 653 | }; |
| 654 | |
| 655 | |
| 656 | class ValueContext: public AstContext { |
| 657 | public: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 658 | explicit ValueContext(HGraphBuilder* owner, ArgumentsAllowedFlag flag) |
| 659 | : AstContext(owner, Expression::kValue), flag_(flag) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 660 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 661 | virtual ~ValueContext(); |
| 662 | |
| 663 | virtual void ReturnValue(HValue* value); |
| 664 | virtual void ReturnInstruction(HInstruction* instr, int ast_id); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 665 | virtual void ReturnControl(HControlInstruction* instr, int ast_id); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 666 | |
| 667 | bool arguments_allowed() { return flag_ == ARGUMENTS_ALLOWED; } |
| 668 | |
| 669 | private: |
| 670 | ArgumentsAllowedFlag flag_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 671 | }; |
| 672 | |
| 673 | |
| 674 | class TestContext: public AstContext { |
| 675 | public: |
| 676 | TestContext(HGraphBuilder* owner, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 677 | Expression* condition, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 678 | HBasicBlock* if_true, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 679 | HBasicBlock* if_false) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 680 | : AstContext(owner, Expression::kTest), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 681 | condition_(condition), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 682 | if_true_(if_true), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 683 | if_false_(if_false) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 684 | } |
| 685 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 686 | virtual void ReturnValue(HValue* value); |
| 687 | virtual void ReturnInstruction(HInstruction* instr, int ast_id); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 688 | virtual void ReturnControl(HControlInstruction* instr, int ast_id); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 689 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 690 | static TestContext* cast(AstContext* context) { |
| 691 | ASSERT(context->IsTest()); |
| 692 | return reinterpret_cast<TestContext*>(context); |
| 693 | } |
| 694 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 695 | Expression* condition() const { return condition_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 696 | HBasicBlock* if_true() const { return if_true_; } |
| 697 | HBasicBlock* if_false() const { return if_false_; } |
| 698 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 699 | private: |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 700 | // Build the shared core part of the translation unpacking a value into |
| 701 | // control flow. |
| 702 | void BuildBranch(HValue* value); |
| 703 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 704 | Expression* condition_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 705 | HBasicBlock* if_true_; |
| 706 | HBasicBlock* if_false_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 710 | enum ReturnHandlingFlag { |
| 711 | NORMAL_RETURN, |
| 712 | DROP_EXTRA_ON_RETURN, |
| 713 | CONSTRUCT_CALL_RETURN |
| 714 | }; |
| 715 | |
| 716 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 717 | class FunctionState { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 718 | public: |
| 719 | FunctionState(HGraphBuilder* owner, |
| 720 | CompilationInfo* info, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 721 | TypeFeedbackOracle* oracle, |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 722 | ReturnHandlingFlag return_handling); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 723 | ~FunctionState(); |
| 724 | |
| 725 | CompilationInfo* compilation_info() { return compilation_info_; } |
| 726 | TypeFeedbackOracle* oracle() { return oracle_; } |
| 727 | AstContext* call_context() { return call_context_; } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 728 | bool drop_extra() { return return_handling_ == DROP_EXTRA_ON_RETURN; } |
| 729 | bool is_construct() { return return_handling_ == CONSTRUCT_CALL_RETURN; } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 730 | HBasicBlock* function_return() { return function_return_; } |
| 731 | TestContext* test_context() { return test_context_; } |
| 732 | void ClearInlinedTestContext() { |
| 733 | delete test_context_; |
| 734 | test_context_ = NULL; |
| 735 | } |
| 736 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 737 | FunctionState* outer() { return outer_; } |
| 738 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 739 | HEnterInlined* entry() { return entry_; } |
| 740 | void set_entry(HEnterInlined* entry) { entry_ = entry; } |
| 741 | |
| 742 | HArgumentsElements* arguments_elements() { return arguments_elements_; } |
| 743 | void set_arguments_elements(HArgumentsElements* arguments_elements) { |
| 744 | arguments_elements_ = arguments_elements; |
| 745 | } |
| 746 | |
| 747 | bool arguments_pushed() { return arguments_elements() != NULL; } |
| 748 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 749 | private: |
| 750 | HGraphBuilder* owner_; |
| 751 | |
| 752 | CompilationInfo* compilation_info_; |
| 753 | TypeFeedbackOracle* oracle_; |
| 754 | |
| 755 | // During function inlining, expression context of the call being |
| 756 | // inlined. NULL when not inlining. |
| 757 | AstContext* call_context_; |
| 758 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 759 | // Indicate whether we have to perform special handling on return from |
| 760 | // inlined functions. |
| 761 | // - DROP_EXTRA_ON_RETURN: Drop an extra value from the environment. |
| 762 | // - CONSTRUCT_CALL_RETURN: Either use allocated receiver or return value. |
| 763 | ReturnHandlingFlag return_handling_; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 764 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 765 | // When inlining in an effect or value context, this is the return block. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 766 | // It is NULL otherwise. When inlining in a test context, there are a |
| 767 | // pair of return blocks in the context. When not inlining, there is no |
| 768 | // local return point. |
| 769 | HBasicBlock* function_return_; |
| 770 | |
| 771 | // When inlining a call in a test context, a context containing a pair of |
| 772 | // return blocks. NULL in all other cases. |
| 773 | TestContext* test_context_; |
| 774 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 775 | // When inlining HEnterInlined instruction corresponding to the function |
| 776 | // entry. |
| 777 | HEnterInlined* entry_; |
| 778 | |
| 779 | HArgumentsElements* arguments_elements_; |
| 780 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 781 | FunctionState* outer_; |
| 782 | }; |
| 783 | |
| 784 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 785 | class HGraphBuilder: public AstVisitor { |
| 786 | public: |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 787 | enum BreakType { BREAK, CONTINUE }; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 788 | enum SwitchType { UNKNOWN_SWITCH, SMI_SWITCH, STRING_SWITCH }; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 789 | |
| 790 | // A class encapsulating (lazily-allocated) break and continue blocks for |
| 791 | // a breakable statement. Separated from BreakAndContinueScope so that it |
| 792 | // can have a separate lifetime. |
| 793 | class BreakAndContinueInfo BASE_EMBEDDED { |
| 794 | public: |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 795 | explicit BreakAndContinueInfo(BreakableStatement* target, |
| 796 | int drop_extra = 0) |
| 797 | : target_(target), |
| 798 | break_block_(NULL), |
| 799 | continue_block_(NULL), |
| 800 | drop_extra_(drop_extra) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | BreakableStatement* target() { return target_; } |
| 804 | HBasicBlock* break_block() { return break_block_; } |
| 805 | void set_break_block(HBasicBlock* block) { break_block_ = block; } |
| 806 | HBasicBlock* continue_block() { return continue_block_; } |
| 807 | void set_continue_block(HBasicBlock* block) { continue_block_ = block; } |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 808 | int drop_extra() { return drop_extra_; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 809 | |
| 810 | private: |
| 811 | BreakableStatement* target_; |
| 812 | HBasicBlock* break_block_; |
| 813 | HBasicBlock* continue_block_; |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 814 | int drop_extra_; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 815 | }; |
| 816 | |
| 817 | // A helper class to maintain a stack of current BreakAndContinueInfo |
| 818 | // structures mirroring BreakableStatement nesting. |
| 819 | class BreakAndContinueScope BASE_EMBEDDED { |
| 820 | public: |
| 821 | BreakAndContinueScope(BreakAndContinueInfo* info, HGraphBuilder* owner) |
| 822 | : info_(info), owner_(owner), next_(owner->break_scope()) { |
| 823 | owner->set_break_scope(this); |
| 824 | } |
| 825 | |
| 826 | ~BreakAndContinueScope() { owner_->set_break_scope(next_); } |
| 827 | |
| 828 | BreakAndContinueInfo* info() { return info_; } |
| 829 | HGraphBuilder* owner() { return owner_; } |
| 830 | BreakAndContinueScope* next() { return next_; } |
| 831 | |
| 832 | // Search the break stack for a break or continue target. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 833 | HBasicBlock* Get(BreakableStatement* stmt, BreakType type, int* drop_extra); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 834 | |
| 835 | private: |
| 836 | BreakAndContinueInfo* info_; |
| 837 | HGraphBuilder* owner_; |
| 838 | BreakAndContinueScope* next_; |
| 839 | }; |
| 840 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 841 | HGraphBuilder(CompilationInfo* info, TypeFeedbackOracle* oracle, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 842 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 843 | HGraph* CreateGraph(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 844 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 845 | // Simple accessors. |
| 846 | HGraph* graph() const { return graph_; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 847 | BreakAndContinueScope* break_scope() const { return break_scope_; } |
| 848 | void set_break_scope(BreakAndContinueScope* head) { break_scope_ = head; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 849 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 850 | HBasicBlock* current_block() const { return current_block_; } |
| 851 | void set_current_block(HBasicBlock* block) { current_block_ = block; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 852 | HEnvironment* environment() const { |
| 853 | return current_block()->last_environment(); |
| 854 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 855 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 856 | bool inline_bailout() { return inline_bailout_; } |
| 857 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 858 | // Adding instructions. |
| 859 | HInstruction* AddInstruction(HInstruction* instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 860 | void AddSimulate(int ast_id); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 861 | |
| 862 | // Bailout environment manipulation. |
| 863 | void Push(HValue* value) { environment()->Push(value); } |
| 864 | HValue* Pop() { return environment()->Pop(); } |
| 865 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 866 | void Bailout(const char* reason); |
| 867 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 868 | HBasicBlock* CreateJoin(HBasicBlock* first, |
| 869 | HBasicBlock* second, |
| 870 | int join_id); |
| 871 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 872 | TypeFeedbackOracle* oracle() const { return function_state()->oracle(); } |
| 873 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 874 | FunctionState* function_state() const { return function_state_; } |
| 875 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 876 | void VisitDeclarations(ZoneList<Declaration*>* declarations); |
| 877 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 878 | private: |
| 879 | // Type of a member function that generates inline code for a native function. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 880 | typedef void (HGraphBuilder::*InlineFunctionGenerator)(CallRuntime* call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 881 | |
| 882 | // Forward declarations for inner scope classes. |
| 883 | class SubgraphScope; |
| 884 | |
| 885 | static const InlineFunctionGenerator kInlineFunctionGenerators[]; |
| 886 | |
| 887 | static const int kMaxCallPolymorphism = 4; |
| 888 | static const int kMaxLoadPolymorphism = 4; |
| 889 | static const int kMaxStorePolymorphism = 4; |
| 890 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 891 | // Even in the 'unlimited' case we have to have some limit in order not to |
| 892 | // overflow the stack. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 893 | static const int kUnlimitedMaxInlinedSourceSize = 100000; |
| 894 | static const int kUnlimitedMaxInlinedNodes = 10000; |
| 895 | static const int kUnlimitedMaxInlinedNodesCumulative = 10000; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 896 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 897 | // Simple accessors. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 898 | void set_function_state(FunctionState* state) { function_state_ = state; } |
| 899 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 900 | AstContext* ast_context() const { return ast_context_; } |
| 901 | void set_ast_context(AstContext* context) { ast_context_ = context; } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 902 | |
| 903 | // Accessors forwarded to the function state. |
| 904 | CompilationInfo* info() const { |
| 905 | return function_state()->compilation_info(); |
| 906 | } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 907 | AstContext* call_context() const { |
| 908 | return function_state()->call_context(); |
| 909 | } |
| 910 | HBasicBlock* function_return() const { |
| 911 | return function_state()->function_return(); |
| 912 | } |
| 913 | TestContext* inlined_test_context() const { |
| 914 | return function_state()->test_context(); |
| 915 | } |
| 916 | void ClearInlinedTestContext() { |
| 917 | function_state()->ClearInlinedTestContext(); |
| 918 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 919 | StrictModeFlag function_strict_mode_flag() { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 920 | return function_state()->compilation_info()->is_classic_mode() |
| 921 | ? kNonStrictMode : kStrictMode; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 922 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 923 | |
| 924 | // Generators for inline runtime functions. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 925 | #define INLINE_FUNCTION_GENERATOR_DECLARATION(Name, argc, ressize) \ |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 926 | void Generate##Name(CallRuntime* call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 927 | |
| 928 | INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_DECLARATION) |
| 929 | INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_DECLARATION) |
| 930 | #undef INLINE_FUNCTION_GENERATOR_DECLARATION |
| 931 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 932 | void VisitDelete(UnaryOperation* expr); |
| 933 | void VisitVoid(UnaryOperation* expr); |
| 934 | void VisitTypeof(UnaryOperation* expr); |
| 935 | void VisitAdd(UnaryOperation* expr); |
| 936 | void VisitSub(UnaryOperation* expr); |
| 937 | void VisitBitNot(UnaryOperation* expr); |
| 938 | void VisitNot(UnaryOperation* expr); |
| 939 | |
| 940 | void VisitComma(BinaryOperation* expr); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 941 | void VisitLogicalExpression(BinaryOperation* expr); |
| 942 | void VisitArithmeticExpression(BinaryOperation* expr); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 943 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 944 | bool PreProcessOsrEntry(IterationStatement* statement); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 945 | // True iff. we are compiling for OSR and the statement is the entry. |
| 946 | bool HasOsrEntryAt(IterationStatement* statement); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 947 | void VisitLoopBody(IterationStatement* stmt, |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 948 | HBasicBlock* loop_entry, |
| 949 | BreakAndContinueInfo* break_info); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 950 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 951 | // Create a back edge in the flow graph. body_exit is the predecessor |
| 952 | // block and loop_entry is the successor block. loop_successor is the |
| 953 | // block where control flow exits the loop normally (e.g., via failure of |
| 954 | // the condition) and break_block is the block where control flow breaks |
| 955 | // from the loop. All blocks except loop_entry can be NULL. The return |
| 956 | // value is the new successor block which is the join of loop_successor |
| 957 | // and break_block, or NULL. |
| 958 | HBasicBlock* CreateLoop(IterationStatement* statement, |
| 959 | HBasicBlock* loop_entry, |
| 960 | HBasicBlock* body_exit, |
| 961 | HBasicBlock* loop_successor, |
| 962 | HBasicBlock* break_block); |
| 963 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 964 | HBasicBlock* JoinContinue(IterationStatement* statement, |
| 965 | HBasicBlock* exit_block, |
| 966 | HBasicBlock* continue_block); |
| 967 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 968 | HValue* Top() const { return environment()->Top(); } |
| 969 | void Drop(int n) { environment()->Drop(n); } |
| 970 | void Bind(Variable* var, HValue* value) { environment()->Bind(var, value); } |
| 971 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 972 | // The value of the arguments object is allowed in some but not most value |
| 973 | // contexts. (It's allowed in all effect contexts and disallowed in all |
| 974 | // test contexts.) |
| 975 | void VisitForValue(Expression* expr, |
| 976 | ArgumentsAllowedFlag flag = ARGUMENTS_NOT_ALLOWED); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 977 | void VisitForTypeOf(Expression* expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 978 | void VisitForEffect(Expression* expr); |
| 979 | void VisitForControl(Expression* expr, |
| 980 | HBasicBlock* true_block, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 981 | HBasicBlock* false_block); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 982 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 983 | // Visit an argument subexpression and emit a push to the outgoing |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 984 | // arguments. Returns the hydrogen value that was pushed. |
| 985 | HValue* VisitArgument(Expression* expr); |
| 986 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 987 | void VisitArgumentList(ZoneList<Expression*>* arguments); |
| 988 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 989 | // Visit a list of expressions from left to right, each in a value context. |
| 990 | void VisitExpressions(ZoneList<Expression*>* exprs); |
| 991 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 992 | void AddPhi(HPhi* phi); |
| 993 | |
| 994 | void PushAndAdd(HInstruction* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 995 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 996 | // Remove the arguments from the bailout environment and emit instructions |
| 997 | // to push them as outgoing parameters. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 998 | template <class Instruction> HInstruction* PreProcessCall(Instruction* call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 999 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1000 | void TraceRepresentation(Token::Value op, |
| 1001 | TypeInfo info, |
| 1002 | HValue* value, |
| 1003 | Representation rep); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1004 | static Representation ToRepresentation(TypeInfo info); |
| 1005 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1006 | void SetUpScope(Scope* scope); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1007 | virtual void VisitStatements(ZoneList<Statement*>* statements); |
| 1008 | |
| 1009 | #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 1010 | AST_NODE_LIST(DECLARE_VISIT) |
| 1011 | #undef DECLARE_VISIT |
| 1012 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1013 | HBasicBlock* CreateBasicBlock(HEnvironment* env); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1014 | HBasicBlock* CreateLoopHeaderBlock(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1015 | |
| 1016 | // Helpers for flow graph construction. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1017 | enum GlobalPropertyAccess { |
| 1018 | kUseCell, |
| 1019 | kUseGeneric |
| 1020 | }; |
| 1021 | GlobalPropertyAccess LookupGlobalProperty(Variable* var, |
| 1022 | LookupResult* lookup, |
| 1023 | bool is_store); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1024 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1025 | void EnsureArgumentsArePushedForAccess(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1026 | bool TryArgumentsAccess(Property* expr); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1027 | |
| 1028 | // Try to optimize fun.apply(receiver, arguments) pattern. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1029 | bool TryCallApply(Call* expr); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1030 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1031 | int InliningAstSize(Handle<JSFunction> target); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1032 | bool TryInline(CallKind call_kind, |
| 1033 | Handle<JSFunction> target, |
| 1034 | ZoneList<Expression*>* arguments, |
| 1035 | HValue* receiver, |
| 1036 | int ast_id, |
| 1037 | int return_id, |
| 1038 | ReturnHandlingFlag return_handling); |
| 1039 | |
| 1040 | bool TryInlineCall(Call* expr, bool drop_extra = false); |
| 1041 | bool TryInlineConstruct(CallNew* expr, HValue* receiver); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1042 | bool TryInlineBuiltinMethodCall(Call* expr, |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1043 | HValue* receiver, |
| 1044 | Handle<Map> receiver_map, |
| 1045 | CheckType check_type); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1046 | bool TryInlineBuiltinFunctionCall(Call* expr, bool drop_extra); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1047 | |
| 1048 | // If --trace-inlining, print a line of the inlining trace. Inlining |
| 1049 | // succeeded if the reason string is NULL and failed if there is a |
| 1050 | // non-NULL reason string. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1051 | void TraceInline(Handle<JSFunction> target, |
| 1052 | Handle<JSFunction> caller, |
| 1053 | const char* failure_reason); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1054 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1055 | void HandleGlobalVariableAssignment(Variable* var, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1056 | HValue* value, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1057 | int position, |
| 1058 | int ast_id); |
| 1059 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1060 | void HandlePropertyAssignment(Assignment* expr); |
| 1061 | void HandleCompoundAssignment(Assignment* expr); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 1062 | void HandlePolymorphicLoadNamedField(Property* expr, |
| 1063 | HValue* object, |
| 1064 | SmallMapList* types, |
| 1065 | Handle<String> name); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1066 | void HandlePolymorphicStoreNamedField(Assignment* expr, |
| 1067 | HValue* object, |
| 1068 | HValue* value, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1069 | SmallMapList* types, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1070 | Handle<String> name); |
| 1071 | void HandlePolymorphicCallNamed(Call* expr, |
| 1072 | HValue* receiver, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1073 | SmallMapList* types, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1074 | Handle<String> name); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1075 | void HandleLiteralCompareTypeof(CompareOperation* expr, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1076 | HTypeof* typeof_expr, |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1077 | Handle<String> check); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1078 | void HandleLiteralCompareNil(CompareOperation* expr, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1079 | HValue* value, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1080 | NilValue nil); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1081 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1082 | HStringCharCodeAt* BuildStringCharCodeAt(HValue* context, |
| 1083 | HValue* string, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1084 | HValue* index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1085 | HInstruction* BuildBinaryOperation(BinaryOperation* expr, |
| 1086 | HValue* left, |
| 1087 | HValue* right); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1088 | HInstruction* BuildIncrement(bool returns_original_input, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1089 | CountOperation* expr); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1090 | HLoadNamedField* BuildLoadNamedField(HValue* object, |
| 1091 | Property* expr, |
| 1092 | Handle<Map> type, |
| 1093 | LookupResult* result, |
| 1094 | bool smi_and_map_check); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1095 | HInstruction* BuildLoadNamedGeneric(HValue* object, Property* expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1096 | HInstruction* BuildLoadKeyedGeneric(HValue* object, |
| 1097 | HValue* key); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1098 | HInstruction* BuildExternalArrayElementAccess( |
| 1099 | HValue* external_elements, |
| 1100 | HValue* checked_key, |
| 1101 | HValue* val, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1102 | ElementsKind elements_kind, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1103 | bool is_store); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1104 | HInstruction* BuildFastElementAccess(HValue* elements, |
| 1105 | HValue* checked_key, |
| 1106 | HValue* val, |
| 1107 | ElementsKind elements_kind, |
| 1108 | bool is_store); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1109 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1110 | HInstruction* BuildMonomorphicElementAccess(HValue* object, |
| 1111 | HValue* key, |
| 1112 | HValue* val, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1113 | HValue* dependency, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1114 | Handle<Map> map, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1115 | bool is_store); |
| 1116 | HValue* HandlePolymorphicElementAccess(HValue* object, |
| 1117 | HValue* key, |
| 1118 | HValue* val, |
| 1119 | Expression* prop, |
| 1120 | int ast_id, |
| 1121 | int position, |
| 1122 | bool is_store, |
| 1123 | bool* has_side_effects); |
| 1124 | |
| 1125 | HValue* HandleKeyedElementAccess(HValue* obj, |
| 1126 | HValue* key, |
| 1127 | HValue* val, |
| 1128 | Expression* expr, |
| 1129 | int ast_id, |
| 1130 | int position, |
| 1131 | bool is_store, |
| 1132 | bool* has_side_effects); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1133 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1134 | HInstruction* BuildLoadNamed(HValue* object, |
| 1135 | Property* prop, |
| 1136 | Handle<Map> map, |
| 1137 | Handle<String> name); |
| 1138 | HInstruction* BuildStoreNamed(HValue* object, |
| 1139 | HValue* value, |
| 1140 | Expression* expr); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1141 | HInstruction* BuildStoreNamed(HValue* object, |
| 1142 | HValue* value, |
| 1143 | ObjectLiteral::Property* prop); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1144 | HInstruction* BuildStoreNamedField(HValue* object, |
| 1145 | Handle<String> name, |
| 1146 | HValue* value, |
| 1147 | Handle<Map> type, |
| 1148 | LookupResult* lookup, |
| 1149 | bool smi_and_map_check); |
| 1150 | HInstruction* BuildStoreNamedGeneric(HValue* object, |
| 1151 | Handle<String> name, |
| 1152 | HValue* value); |
| 1153 | HInstruction* BuildStoreKeyedGeneric(HValue* object, |
| 1154 | HValue* key, |
| 1155 | HValue* value); |
| 1156 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1157 | HValue* BuildContextChainWalk(Variable* var); |
| 1158 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1159 | void AddCheckConstantFunction(Call* expr, |
| 1160 | HValue* receiver, |
| 1161 | Handle<Map> receiver_map, |
| 1162 | bool smi_and_map_check); |
| 1163 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1164 | Zone* zone() const { return zone_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1165 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1166 | // The translation state of the currently-being-translated function. |
| 1167 | FunctionState* function_state_; |
| 1168 | |
| 1169 | // The base of the function state stack. |
| 1170 | FunctionState initial_function_state_; |
| 1171 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1172 | // Expression context of the currently visited subexpression. NULL when |
| 1173 | // visiting statements. |
| 1174 | AstContext* ast_context_; |
| 1175 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1176 | // A stack of breakable statements entered. |
| 1177 | BreakAndContinueScope* break_scope_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1178 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1179 | HGraph* graph_; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1180 | HBasicBlock* current_block_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1181 | |
| 1182 | int inlined_count_; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1183 | ZoneList<Handle<Object> > globals_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1184 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1185 | Zone* zone_; |
| 1186 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1187 | bool inline_bailout_; |
| 1188 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1189 | friend class FunctionState; // Pushes and pops the state stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1190 | friend class AstContext; // Pushes and pops the AST context stack. |
| 1191 | |
| 1192 | DISALLOW_COPY_AND_ASSIGN(HGraphBuilder); |
| 1193 | }; |
| 1194 | |
| 1195 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1196 | Zone* AstContext::zone() const { return owner_->zone(); } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1197 | |
| 1198 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1199 | class HValueMap: public ZoneObject { |
| 1200 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1201 | explicit HValueMap(Zone* zone) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1202 | : array_size_(0), |
| 1203 | lists_size_(0), |
| 1204 | count_(0), |
| 1205 | present_flags_(0), |
| 1206 | array_(NULL), |
| 1207 | lists_(NULL), |
| 1208 | free_list_head_(kNil) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1209 | ResizeLists(kInitialSize, zone); |
| 1210 | Resize(kInitialSize, zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1213 | void Kill(GVNFlagSet flags); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1214 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1215 | void Add(HValue* value, Zone* zone) { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1216 | present_flags_.Add(value->gvn_flags()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1217 | Insert(value, zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | HValue* Lookup(HValue* value) const; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1221 | |
| 1222 | HValueMap* Copy(Zone* zone) const { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1223 | return new(zone) HValueMap(zone, this); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1224 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1225 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1226 | bool IsEmpty() const { return count_ == 0; } |
| 1227 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1228 | private: |
| 1229 | // A linked list of HValue* values. Stored in arrays. |
| 1230 | struct HValueMapListElement { |
| 1231 | HValue* value; |
| 1232 | int next; // Index in the array of the next list element. |
| 1233 | }; |
| 1234 | static const int kNil = -1; // The end of a linked list |
| 1235 | |
| 1236 | // Must be a power of 2. |
| 1237 | static const int kInitialSize = 16; |
| 1238 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1239 | HValueMap(Zone* zone, const HValueMap* other); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1240 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1241 | void Resize(int new_size, Zone* zone); |
| 1242 | void ResizeLists(int new_size, Zone* zone); |
| 1243 | void Insert(HValue* value, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1244 | uint32_t Bound(uint32_t value) const { return value & (array_size_ - 1); } |
| 1245 | |
| 1246 | int array_size_; |
| 1247 | int lists_size_; |
| 1248 | int count_; // The number of values stored in the HValueMap. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1249 | GVNFlagSet present_flags_; // All flags that are in any value in the |
| 1250 | // HValueMap. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1251 | HValueMapListElement* array_; // Primary store - contains the first value |
| 1252 | // with a given hash. Colliding elements are stored in linked lists. |
| 1253 | HValueMapListElement* lists_; // The linked lists containing hash collisions. |
| 1254 | int free_list_head_; // Unused elements in lists_ are on the free list. |
| 1255 | }; |
| 1256 | |
| 1257 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1258 | class HSideEffectMap BASE_EMBEDDED { |
| 1259 | public: |
| 1260 | HSideEffectMap(); |
| 1261 | explicit HSideEffectMap(HSideEffectMap* other); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 1262 | HSideEffectMap& operator= (const HSideEffectMap& other); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1263 | |
| 1264 | void Kill(GVNFlagSet flags); |
| 1265 | |
| 1266 | void Store(GVNFlagSet flags, HInstruction* instr); |
| 1267 | |
| 1268 | bool IsEmpty() const { return count_ == 0; } |
| 1269 | |
| 1270 | inline HInstruction* operator[](int i) const { |
| 1271 | ASSERT(0 <= i); |
| 1272 | ASSERT(i < kNumberOfTrackedSideEffects); |
| 1273 | return data_[i]; |
| 1274 | } |
| 1275 | inline HInstruction* at(int i) const { return operator[](i); } |
| 1276 | |
| 1277 | private: |
| 1278 | int count_; |
| 1279 | HInstruction* data_[kNumberOfTrackedSideEffects]; |
| 1280 | }; |
| 1281 | |
| 1282 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1283 | class HStatistics: public Malloced { |
| 1284 | public: |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1285 | void Initialize(CompilationInfo* info); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1286 | void Print(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1287 | void SaveTiming(const char* name, int64_t ticks, unsigned size); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1288 | static HStatistics* Instance() { |
| 1289 | static SetOncePointer<HStatistics> instance; |
| 1290 | if (!instance.is_set()) { |
| 1291 | instance.set(new HStatistics()); |
| 1292 | } |
| 1293 | return instance.get(); |
| 1294 | } |
| 1295 | |
| 1296 | private: |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1297 | HStatistics() |
| 1298 | : timing_(5), |
| 1299 | names_(5), |
| 1300 | sizes_(5), |
| 1301 | total_(0), |
| 1302 | total_size_(0), |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1303 | full_code_gen_(0), |
| 1304 | source_size_(0) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1305 | |
| 1306 | List<int64_t> timing_; |
| 1307 | List<const char*> names_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1308 | List<unsigned> sizes_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1309 | int64_t total_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1310 | unsigned total_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1311 | int64_t full_code_gen_; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1312 | double source_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1313 | }; |
| 1314 | |
| 1315 | |
| 1316 | class HPhase BASE_EMBEDDED { |
| 1317 | public: |
| 1318 | static const char* const kFullCodeGen; |
| 1319 | static const char* const kTotal; |
| 1320 | |
| 1321 | explicit HPhase(const char* name) { Begin(name, NULL, NULL, NULL); } |
| 1322 | HPhase(const char* name, HGraph* graph) { |
| 1323 | Begin(name, graph, NULL, NULL); |
| 1324 | } |
| 1325 | HPhase(const char* name, LChunk* chunk) { |
| 1326 | Begin(name, NULL, chunk, NULL); |
| 1327 | } |
| 1328 | HPhase(const char* name, LAllocator* allocator) { |
| 1329 | Begin(name, NULL, NULL, allocator); |
| 1330 | } |
| 1331 | |
| 1332 | ~HPhase() { |
| 1333 | End(); |
| 1334 | } |
| 1335 | |
| 1336 | private: |
| 1337 | void Begin(const char* name, |
| 1338 | HGraph* graph, |
| 1339 | LChunk* chunk, |
| 1340 | LAllocator* allocator); |
| 1341 | void End() const; |
| 1342 | |
| 1343 | int64_t start_; |
| 1344 | const char* name_; |
| 1345 | HGraph* graph_; |
| 1346 | LChunk* chunk_; |
| 1347 | LAllocator* allocator_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1348 | unsigned start_allocation_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1349 | }; |
| 1350 | |
| 1351 | |
| 1352 | class HTracer: public Malloced { |
| 1353 | public: |
| 1354 | void TraceCompilation(FunctionLiteral* function); |
| 1355 | void TraceHydrogen(const char* name, HGraph* graph); |
| 1356 | void TraceLithium(const char* name, LChunk* chunk); |
| 1357 | void TraceLiveRanges(const char* name, LAllocator* allocator); |
| 1358 | |
| 1359 | static HTracer* Instance() { |
| 1360 | static SetOncePointer<HTracer> instance; |
| 1361 | if (!instance.is_set()) { |
| 1362 | instance.set(new HTracer("hydrogen.cfg")); |
| 1363 | } |
| 1364 | return instance.get(); |
| 1365 | } |
| 1366 | |
| 1367 | private: |
| 1368 | class Tag BASE_EMBEDDED { |
| 1369 | public: |
| 1370 | Tag(HTracer* tracer, const char* name) { |
| 1371 | name_ = name; |
| 1372 | tracer_ = tracer; |
| 1373 | tracer->PrintIndent(); |
| 1374 | tracer->trace_.Add("begin_%s\n", name); |
| 1375 | tracer->indent_++; |
| 1376 | } |
| 1377 | |
| 1378 | ~Tag() { |
| 1379 | tracer_->indent_--; |
| 1380 | tracer_->PrintIndent(); |
| 1381 | tracer_->trace_.Add("end_%s\n", name_); |
| 1382 | ASSERT(tracer_->indent_ >= 0); |
| 1383 | tracer_->FlushToFile(); |
| 1384 | } |
| 1385 | |
| 1386 | private: |
| 1387 | HTracer* tracer_; |
| 1388 | const char* name_; |
| 1389 | }; |
| 1390 | |
| 1391 | explicit HTracer(const char* filename) |
| 1392 | : filename_(filename), trace_(&string_allocator_), indent_(0) { |
| 1393 | WriteChars(filename, "", 0, false); |
| 1394 | } |
| 1395 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame^] | 1396 | void TraceLiveRange(LiveRange* range, const char* type, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1397 | void Trace(const char* name, HGraph* graph, LChunk* chunk); |
| 1398 | void FlushToFile(); |
| 1399 | |
| 1400 | void PrintEmptyProperty(const char* name) { |
| 1401 | PrintIndent(); |
| 1402 | trace_.Add("%s\n", name); |
| 1403 | } |
| 1404 | |
| 1405 | void PrintStringProperty(const char* name, const char* value) { |
| 1406 | PrintIndent(); |
| 1407 | trace_.Add("%s \"%s\"\n", name, value); |
| 1408 | } |
| 1409 | |
| 1410 | void PrintLongProperty(const char* name, int64_t value) { |
| 1411 | PrintIndent(); |
| 1412 | trace_.Add("%s %d000\n", name, static_cast<int>(value / 1000)); |
| 1413 | } |
| 1414 | |
| 1415 | void PrintBlockProperty(const char* name, int block_id) { |
| 1416 | PrintIndent(); |
| 1417 | trace_.Add("%s \"B%d\"\n", name, block_id); |
| 1418 | } |
| 1419 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1420 | void PrintIntProperty(const char* name, int value) { |
| 1421 | PrintIndent(); |
| 1422 | trace_.Add("%s %d\n", name, value); |
| 1423 | } |
| 1424 | |
| 1425 | void PrintIndent() { |
| 1426 | for (int i = 0; i < indent_; i++) { |
| 1427 | trace_.Add(" "); |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | const char* filename_; |
| 1432 | HeapStringAllocator string_allocator_; |
| 1433 | StringStream trace_; |
| 1434 | int indent_; |
| 1435 | }; |
| 1436 | |
| 1437 | |
| 1438 | } } // namespace v8::internal |
| 1439 | |
| 1440 | #endif // V8_HYDROGEN_H_ |