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