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