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" |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 39 | #include "scopes.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 40 | |
| 41 | namespace v8 { |
| 42 | namespace internal { |
| 43 | |
| 44 | // Forward declarations. |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 45 | class BitVector; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 46 | class FunctionState; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 47 | class HEnvironment; |
| 48 | class HGraph; |
| 49 | class HLoopInformation; |
| 50 | class HTracer; |
| 51 | class LAllocator; |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 52 | class LChunk; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 53 | class LiveRange; |
| 54 | |
| 55 | |
| 56 | class HBasicBlock: public ZoneObject { |
| 57 | public: |
| 58 | explicit HBasicBlock(HGraph* graph); |
| 59 | virtual ~HBasicBlock() { } |
| 60 | |
| 61 | // Simple accessors. |
| 62 | int block_id() const { return block_id_; } |
| 63 | void set_block_id(int id) { block_id_ = id; } |
| 64 | HGraph* graph() const { return graph_; } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 65 | Isolate* isolate() const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 66 | const ZoneList<HPhi*>* phis() const { return &phis_; } |
| 67 | HInstruction* first() const { return first_; } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 68 | HInstruction* last() const { return last_; } |
| 69 | void set_last(HInstruction* instr) { last_ = instr; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 70 | HInstruction* GetLastInstruction(); |
| 71 | HControlInstruction* end() const { return end_; } |
| 72 | HLoopInformation* loop_information() const { return loop_information_; } |
| 73 | const ZoneList<HBasicBlock*>* predecessors() const { return &predecessors_; } |
| 74 | bool HasPredecessor() const { return predecessors_.length() > 0; } |
| 75 | const ZoneList<HBasicBlock*>* dominated_blocks() const { |
| 76 | return &dominated_blocks_; |
| 77 | } |
| 78 | const ZoneList<int>* deleted_phis() const { |
| 79 | return &deleted_phis_; |
| 80 | } |
| 81 | void RecordDeletedPhi(int merge_index) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 82 | deleted_phis_.Add(merge_index, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 83 | } |
| 84 | HBasicBlock* dominator() const { return dominator_; } |
| 85 | HEnvironment* last_environment() const { return last_environment_; } |
| 86 | int argument_count() const { return argument_count_; } |
| 87 | void set_argument_count(int count) { argument_count_ = count; } |
| 88 | int first_instruction_index() const { return first_instruction_index_; } |
| 89 | void set_first_instruction_index(int index) { |
| 90 | first_instruction_index_ = index; |
| 91 | } |
| 92 | int last_instruction_index() const { return last_instruction_index_; } |
| 93 | void set_last_instruction_index(int index) { |
| 94 | last_instruction_index_ = index; |
| 95 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 96 | bool is_osr_entry() { return is_osr_entry_; } |
| 97 | void set_osr_entry() { is_osr_entry_ = true; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 98 | |
| 99 | void AttachLoopInformation(); |
| 100 | void DetachLoopInformation(); |
| 101 | bool IsLoopHeader() const { return loop_information() != NULL; } |
| 102 | bool IsStartBlock() const { return block_id() == 0; } |
| 103 | void PostProcessLoopHeader(IterationStatement* stmt); |
| 104 | |
| 105 | bool IsFinished() const { return end_ != NULL; } |
| 106 | void AddPhi(HPhi* phi); |
| 107 | void RemovePhi(HPhi* phi); |
| 108 | void AddInstruction(HInstruction* instr); |
| 109 | bool Dominates(HBasicBlock* other) const; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 110 | int LoopNestingDepth() const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 111 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 112 | void SetInitialEnvironment(HEnvironment* env); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 113 | void ClearEnvironment() { last_environment_ = NULL; } |
| 114 | bool HasEnvironment() const { return last_environment_ != NULL; } |
| 115 | void UpdateEnvironment(HEnvironment* env) { last_environment_ = env; } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 116 | HBasicBlock* parent_loop_header() const { return parent_loop_header_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 117 | |
| 118 | void set_parent_loop_header(HBasicBlock* block) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 119 | ASSERT(parent_loop_header_ == NULL); |
| 120 | parent_loop_header_ = block; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 121 | } |
| 122 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 123 | bool HasParentLoopHeader() const { return parent_loop_header_ != NULL; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 124 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 125 | void SetJoinId(BailoutId ast_id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 126 | |
| 127 | void Finish(HControlInstruction* last); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 128 | void FinishExit(HControlInstruction* instruction); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 129 | void Goto(HBasicBlock* block, |
| 130 | FunctionState* state = NULL, |
| 131 | bool add_simulate = true); |
| 132 | void GotoNoSimulate(HBasicBlock* block) { |
| 133 | Goto(block, NULL, false); |
| 134 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 135 | |
| 136 | int PredecessorIndexOf(HBasicBlock* predecessor) const; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 137 | void AddSimulate(BailoutId ast_id, |
| 138 | RemovableSimulate removable = FIXED_SIMULATE) { |
| 139 | AddInstruction(CreateSimulate(ast_id, removable)); |
| 140 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 141 | void AssignCommonDominator(HBasicBlock* other); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 142 | void AssignLoopSuccessorDominators(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 143 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 144 | void FinishExitWithDeoptimization(HDeoptimize::UseEnvironment has_uses) { |
| 145 | FinishExit(CreateDeoptimize(has_uses)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 146 | } |
| 147 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 148 | // Add the inlined function exit sequence, adding an HLeaveInlined |
| 149 | // instruction and updating the bailout environment. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 150 | void AddLeaveInlined(HValue* return_value, FunctionState* state); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 151 | |
| 152 | // If a target block is tagged as an inline function return, all |
| 153 | // predecessors should contain the inlined exit sequence: |
| 154 | // |
| 155 | // LeaveInlined |
| 156 | // Simulate (caller's environment) |
| 157 | // Goto (target block) |
| 158 | bool IsInlineReturnTarget() const { return is_inline_return_target_; } |
| 159 | void MarkAsInlineReturnTarget() { is_inline_return_target_ = true; } |
| 160 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 161 | bool IsDeoptimizing() const { return is_deoptimizing_; } |
| 162 | void MarkAsDeoptimizing() { is_deoptimizing_ = true; } |
| 163 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 164 | bool IsLoopSuccessorDominator() const { |
| 165 | return dominates_loop_successors_; |
| 166 | } |
| 167 | void MarkAsLoopSuccessorDominator() { |
| 168 | dominates_loop_successors_ = true; |
| 169 | } |
| 170 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 171 | inline Zone* zone() const; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 172 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 173 | #ifdef DEBUG |
| 174 | void Verify(); |
| 175 | #endif |
| 176 | |
| 177 | private: |
| 178 | void RegisterPredecessor(HBasicBlock* pred); |
| 179 | void AddDominatedBlock(HBasicBlock* block); |
| 180 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 181 | HSimulate* CreateSimulate(BailoutId ast_id, RemovableSimulate removable); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 182 | HDeoptimize* CreateDeoptimize(HDeoptimize::UseEnvironment has_uses); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 183 | |
| 184 | int block_id_; |
| 185 | HGraph* graph_; |
| 186 | ZoneList<HPhi*> phis_; |
| 187 | HInstruction* first_; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 188 | HInstruction* last_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 189 | HControlInstruction* end_; |
| 190 | HLoopInformation* loop_information_; |
| 191 | ZoneList<HBasicBlock*> predecessors_; |
| 192 | HBasicBlock* dominator_; |
| 193 | ZoneList<HBasicBlock*> dominated_blocks_; |
| 194 | HEnvironment* last_environment_; |
| 195 | // Outgoing parameter count at block exit, set during lithium translation. |
| 196 | int argument_count_; |
| 197 | // Instruction indices into the lithium code stream. |
| 198 | int first_instruction_index_; |
| 199 | int last_instruction_index_; |
| 200 | ZoneList<int> deleted_phis_; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 201 | HBasicBlock* parent_loop_header_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 202 | bool is_inline_return_target_; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 203 | bool is_deoptimizing_; |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 204 | bool dominates_loop_successors_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 205 | bool is_osr_entry_; |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | |
| 209 | class HPredecessorIterator BASE_EMBEDDED { |
| 210 | public: |
| 211 | explicit HPredecessorIterator(HBasicBlock* block) |
| 212 | : predecessor_list_(block->predecessors()), current_(0) { } |
| 213 | |
| 214 | bool Done() { return current_ >= predecessor_list_->length(); } |
| 215 | HBasicBlock* Current() { return predecessor_list_->at(current_); } |
| 216 | void Advance() { current_++; } |
| 217 | |
| 218 | private: |
| 219 | const ZoneList<HBasicBlock*>* predecessor_list_; |
| 220 | int current_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | |
| 224 | class HLoopInformation: public ZoneObject { |
| 225 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 226 | HLoopInformation(HBasicBlock* loop_header, Zone* zone) |
| 227 | : back_edges_(4, zone), |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 228 | loop_header_(loop_header), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 229 | blocks_(8, zone), |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 230 | stack_check_(NULL) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 231 | blocks_.Add(loop_header, zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 232 | } |
| 233 | virtual ~HLoopInformation() {} |
| 234 | |
| 235 | const ZoneList<HBasicBlock*>* back_edges() const { return &back_edges_; } |
| 236 | const ZoneList<HBasicBlock*>* blocks() const { return &blocks_; } |
| 237 | HBasicBlock* loop_header() const { return loop_header_; } |
| 238 | HBasicBlock* GetLastBackEdge() const; |
| 239 | void RegisterBackEdge(HBasicBlock* block); |
| 240 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 241 | HStackCheck* stack_check() const { return stack_check_; } |
| 242 | void set_stack_check(HStackCheck* stack_check) { |
| 243 | stack_check_ = stack_check; |
| 244 | } |
| 245 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 246 | private: |
| 247 | void AddBlock(HBasicBlock* block); |
| 248 | |
| 249 | ZoneList<HBasicBlock*> back_edges_; |
| 250 | HBasicBlock* loop_header_; |
| 251 | ZoneList<HBasicBlock*> blocks_; |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 252 | HStackCheck* stack_check_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 255 | class BoundsCheckTable; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 256 | class HGraph: public ZoneObject { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 257 | public: |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 258 | explicit HGraph(CompilationInfo* info); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 259 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 260 | Isolate* isolate() const { return isolate_; } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 261 | Zone* zone() const { return zone_; } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 262 | CompilationInfo* info() const { return info_; } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 263 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 264 | const ZoneList<HBasicBlock*>* blocks() const { return &blocks_; } |
| 265 | const ZoneList<HPhi*>* phi_list() const { return phi_list_; } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 266 | HBasicBlock* entry_block() const { return entry_block_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 267 | HEnvironment* start_environment() const { return start_environment_; } |
| 268 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 269 | void FinalizeUniqueValueIds(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 270 | void InitializeInferredTypes(); |
| 271 | void InsertTypeConversions(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 272 | void MergeRemovableSimulates(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 273 | void InsertRepresentationChanges(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 274 | void MarkDeoptimizeOnUndefined(); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 275 | void ComputeMinusZeroChecks(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 276 | void ComputeSafeUint32Operations(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 277 | void GlobalValueNumbering(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 278 | bool ProcessArgumentsObject(); |
| 279 | void EliminateRedundantPhis(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 280 | void EliminateUnreachablePhis(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 281 | void Canonicalize(); |
| 282 | void OrderBlocks(); |
| 283 | void AssignDominators(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 284 | void SetupInformativeDefinitions(); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 285 | void EliminateRedundantBoundsChecks(); |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 286 | void DehoistSimpleArrayIndexComputations(); |
jkummerow@chromium.org | c195667 | 2012-10-11 15:57:38 +0000 | [diff] [blame] | 287 | void DeadCodeElimination(); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 288 | void RestoreActualValues(); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 289 | void PropagateDeoptimizingMark(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 290 | void EliminateUnusedInstructions(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | |
| 292 | // Returns false if there are phi-uses of the arguments-object |
| 293 | // which are not supported by the optimizing compiler. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 294 | bool CheckArgumentsPhiUses(); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 295 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 296 | // Returns false if there are phi-uses of an uninitialized const |
| 297 | // which are not supported by the optimizing compiler. |
| 298 | bool CheckConstPhiUses(); |
| 299 | |
| 300 | void CollectPhis(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 301 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 302 | void set_undefined_constant(HConstant* constant) { |
| 303 | undefined_constant_.set(constant); |
| 304 | } |
| 305 | HConstant* GetConstantUndefined() const { return undefined_constant_.get(); } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 306 | HConstant* GetConstant0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 307 | HConstant* GetConstant1(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 308 | HConstant* GetConstantSmi0(); |
| 309 | HConstant* GetConstantSmi1(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 310 | HConstant* GetConstantMinus1(); |
| 311 | HConstant* GetConstantTrue(); |
| 312 | HConstant* GetConstantFalse(); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 313 | HConstant* GetConstantHole(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 314 | HConstant* GetConstantNull(); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 315 | HConstant* GetInvalidContext(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 316 | |
| 317 | HBasicBlock* CreateBasicBlock(); |
| 318 | HArgumentsObject* GetArgumentsObject() const { |
| 319 | return arguments_object_.get(); |
| 320 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 321 | |
| 322 | void SetArgumentsObject(HArgumentsObject* object) { |
| 323 | arguments_object_.set(object); |
| 324 | } |
| 325 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 326 | int GetMaximumValueID() const { return values_.length(); } |
| 327 | int GetNextBlockID() { return next_block_id_++; } |
| 328 | int GetNextValueID(HValue* value) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 329 | values_.Add(value, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 330 | return values_.length() - 1; |
| 331 | } |
| 332 | HValue* LookupValue(int id) const { |
| 333 | if (id >= 0 && id < values_.length()) return values_[id]; |
| 334 | return NULL; |
| 335 | } |
| 336 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 337 | bool Optimize(SmartArrayPointer<char>* bailout_reason); |
| 338 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 339 | #ifdef DEBUG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 340 | void Verify(bool do_full_verify) const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 341 | #endif |
| 342 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 343 | bool has_osr_loop_entry() { |
| 344 | return osr_loop_entry_.is_set(); |
| 345 | } |
| 346 | |
| 347 | HBasicBlock* osr_loop_entry() { |
| 348 | return osr_loop_entry_.get(); |
| 349 | } |
| 350 | |
| 351 | void set_osr_loop_entry(HBasicBlock* entry) { |
| 352 | osr_loop_entry_.set(entry); |
| 353 | } |
| 354 | |
| 355 | ZoneList<HUnknownOSRValue*>* osr_values() { |
| 356 | return osr_values_.get(); |
| 357 | } |
| 358 | |
| 359 | void set_osr_values(ZoneList<HUnknownOSRValue*>* values) { |
| 360 | osr_values_.set(values); |
| 361 | } |
| 362 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 363 | int update_type_change_checksum(int delta) { |
| 364 | type_change_checksum_ += delta; |
| 365 | return type_change_checksum_; |
| 366 | } |
| 367 | |
| 368 | bool use_optimistic_licm() { |
| 369 | return use_optimistic_licm_; |
| 370 | } |
| 371 | |
| 372 | void set_use_optimistic_licm(bool value) { |
| 373 | use_optimistic_licm_ = value; |
| 374 | } |
| 375 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 376 | bool has_soft_deoptimize() { |
| 377 | return has_soft_deoptimize_; |
| 378 | } |
| 379 | |
| 380 | void set_has_soft_deoptimize(bool value) { |
| 381 | has_soft_deoptimize_ = value; |
| 382 | } |
| 383 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 384 | void MarkRecursive() { |
| 385 | is_recursive_ = true; |
| 386 | } |
| 387 | |
| 388 | bool is_recursive() const { |
| 389 | return is_recursive_; |
| 390 | } |
| 391 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 392 | void RecordUint32Instruction(HInstruction* instr) { |
| 393 | if (uint32_instructions_ == NULL) { |
| 394 | uint32_instructions_ = new(zone()) ZoneList<HInstruction*>(4, zone()); |
| 395 | } |
| 396 | uint32_instructions_->Add(instr, zone()); |
| 397 | } |
| 398 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 399 | private: |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 400 | HConstant* GetConstantInt32(SetOncePointer<HConstant>* pointer, |
| 401 | int32_t integer_value); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 402 | HConstant* GetConstantSmi(SetOncePointer<HConstant>* pointer, |
| 403 | int32_t integer_value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 404 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 405 | void MarkAsDeoptimizingRecursively(HBasicBlock* block); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 406 | void NullifyUnreachableInstructions(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 407 | void InsertTypeConversions(HInstruction* instr); |
| 408 | void PropagateMinusZeroChecks(HValue* value, BitVector* visited); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 409 | void RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi* phi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 410 | void InsertRepresentationChangeForUse(HValue* value, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 411 | HValue* use_value, |
| 412 | int use_index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 413 | Representation to); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 414 | void InsertRepresentationChangesForValue(HValue* value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 415 | void InferTypes(ZoneList<HValue*>* worklist); |
| 416 | void InitializeInferredTypes(int from_inclusive, int to_inclusive); |
| 417 | void CheckForBackEdge(HBasicBlock* block, HBasicBlock* successor); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 418 | void SetupInformativeDefinitionsInBlock(HBasicBlock* block); |
| 419 | void SetupInformativeDefinitionsRecursively(HBasicBlock* block); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 420 | void EliminateRedundantBoundsChecks(HBasicBlock* bb, BoundsCheckTable* table); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 421 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 422 | Isolate* isolate_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 423 | int next_block_id_; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 424 | HBasicBlock* entry_block_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 425 | HEnvironment* start_environment_; |
| 426 | ZoneList<HBasicBlock*> blocks_; |
| 427 | ZoneList<HValue*> values_; |
| 428 | ZoneList<HPhi*>* phi_list_; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 429 | ZoneList<HInstruction*>* uint32_instructions_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 430 | SetOncePointer<HConstant> undefined_constant_; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 431 | SetOncePointer<HConstant> constant_0_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 432 | SetOncePointer<HConstant> constant_1_; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 433 | SetOncePointer<HConstant> constant_smi_0_; |
| 434 | SetOncePointer<HConstant> constant_smi_1_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 435 | SetOncePointer<HConstant> constant_minus1_; |
| 436 | SetOncePointer<HConstant> constant_true_; |
| 437 | SetOncePointer<HConstant> constant_false_; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 438 | SetOncePointer<HConstant> constant_the_hole_; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 439 | SetOncePointer<HConstant> constant_null_; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 440 | SetOncePointer<HConstant> constant_invalid_context_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 441 | SetOncePointer<HArgumentsObject> arguments_object_; |
| 442 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 443 | SetOncePointer<HBasicBlock> osr_loop_entry_; |
| 444 | SetOncePointer<ZoneList<HUnknownOSRValue*> > osr_values_; |
| 445 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 446 | CompilationInfo* info_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 447 | Zone* zone_; |
| 448 | |
| 449 | bool is_recursive_; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 450 | bool use_optimistic_licm_; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 451 | bool has_soft_deoptimize_; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 452 | int type_change_checksum_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 453 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 454 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 455 | }; |
| 456 | |
| 457 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 458 | Zone* HBasicBlock::zone() const { return graph_->zone(); } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 459 | |
| 460 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 461 | // Type of stack frame an environment might refer to. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 462 | enum FrameType { |
| 463 | JS_FUNCTION, |
| 464 | JS_CONSTRUCT, |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 465 | JS_GETTER, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 466 | JS_SETTER, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 467 | ARGUMENTS_ADAPTOR, |
| 468 | STUB |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 469 | }; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 470 | |
| 471 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 472 | class HEnvironment: public ZoneObject { |
| 473 | public: |
| 474 | HEnvironment(HEnvironment* outer, |
| 475 | Scope* scope, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 476 | Handle<JSFunction> closure, |
| 477 | Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 478 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 479 | HEnvironment(Zone* zone, int parameter_count); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 480 | |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 481 | HEnvironment* arguments_environment() { |
| 482 | return outer()->frame_type() == ARGUMENTS_ADAPTOR ? outer() : this; |
| 483 | } |
| 484 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 485 | // Simple accessors. |
| 486 | Handle<JSFunction> closure() const { return closure_; } |
| 487 | const ZoneList<HValue*>* values() const { return &values_; } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 488 | const GrowableBitVector* assigned_variables() const { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 489 | return &assigned_variables_; |
| 490 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 491 | FrameType frame_type() const { return frame_type_; } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 492 | int parameter_count() const { return parameter_count_; } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 493 | int specials_count() const { return specials_count_; } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 494 | int local_count() const { return local_count_; } |
| 495 | HEnvironment* outer() const { return outer_; } |
| 496 | int pop_count() const { return pop_count_; } |
| 497 | int push_count() const { return push_count_; } |
| 498 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 499 | BailoutId ast_id() const { return ast_id_; } |
| 500 | void set_ast_id(BailoutId id) { ast_id_ = id; } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 501 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 502 | HEnterInlined* entry() const { return entry_; } |
| 503 | void set_entry(HEnterInlined* entry) { entry_ = entry; } |
| 504 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 505 | int length() const { return values_.length(); } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 506 | bool is_special_index(int i) const { |
| 507 | return i >= parameter_count() && i < parameter_count() + specials_count(); |
| 508 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 509 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 510 | int first_expression_index() const { |
| 511 | return parameter_count() + specials_count() + local_count(); |
| 512 | } |
| 513 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 514 | void Bind(Variable* variable, HValue* value) { |
| 515 | Bind(IndexFor(variable), value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 516 | } |
| 517 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 518 | void Bind(int index, HValue* value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 519 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 520 | void BindContext(HValue* value) { |
| 521 | Bind(parameter_count(), value); |
| 522 | } |
| 523 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 524 | HValue* Lookup(Variable* variable) const { |
| 525 | return Lookup(IndexFor(variable)); |
| 526 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 527 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 528 | HValue* Lookup(int index) const { |
| 529 | HValue* result = values_[index]; |
| 530 | ASSERT(result != NULL); |
| 531 | return result; |
| 532 | } |
| 533 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 534 | HValue* LookupContext() const { |
| 535 | // Return first special. |
| 536 | return Lookup(parameter_count()); |
| 537 | } |
| 538 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 539 | void Push(HValue* value) { |
| 540 | ASSERT(value != NULL); |
| 541 | ++push_count_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 542 | values_.Add(value, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 543 | } |
| 544 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 545 | HValue* Pop() { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 546 | ASSERT(!ExpressionStackIsEmpty()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 547 | if (push_count_ > 0) { |
| 548 | --push_count_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 549 | } else { |
| 550 | ++pop_count_; |
| 551 | } |
| 552 | return values_.RemoveLast(); |
| 553 | } |
| 554 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 555 | void Drop(int count); |
| 556 | |
| 557 | HValue* Top() const { return ExpressionStackAt(0); } |
| 558 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 559 | bool ExpressionStackIsEmpty() const; |
| 560 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 561 | HValue* ExpressionStackAt(int index_from_top) const { |
| 562 | int index = length() - index_from_top - 1; |
| 563 | ASSERT(HasExpressionAt(index)); |
| 564 | return values_[index]; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 565 | } |
| 566 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 567 | void SetExpressionStackAt(int index_from_top, HValue* value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 568 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 569 | HEnvironment* Copy() const; |
| 570 | HEnvironment* CopyWithoutHistory() const; |
| 571 | HEnvironment* CopyAsLoopHeader(HBasicBlock* block) const; |
| 572 | |
| 573 | // Create an "inlined version" of this environment, where the original |
| 574 | // environment is the outer environment but the top expression stack |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 575 | // elements are moved to an inner environment as parameters. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 576 | HEnvironment* CopyForInlining(Handle<JSFunction> target, |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 577 | int arguments, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 578 | FunctionLiteral* function, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 579 | HConstant* undefined, |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 580 | InliningKind inlining_kind, |
| 581 | bool undefined_receiver) const; |
| 582 | |
| 583 | static bool UseUndefinedReceiver(Handle<JSFunction> closure, |
| 584 | FunctionLiteral* function, |
| 585 | CallKind call_kind, |
| 586 | InliningKind inlining_kind) { |
| 587 | return (closure->shared()->native() || !function->is_classic_mode()) && |
| 588 | call_kind == CALL_AS_FUNCTION && inlining_kind != CONSTRUCT_CALL_RETURN; |
| 589 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 590 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 591 | HEnvironment* DiscardInlined(bool drop_extra) { |
| 592 | HEnvironment* outer = outer_; |
| 593 | while (outer->frame_type() != JS_FUNCTION) outer = outer->outer_; |
| 594 | if (drop_extra) outer->Drop(1); |
| 595 | return outer; |
| 596 | } |
| 597 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 598 | void AddIncomingEdge(HBasicBlock* block, HEnvironment* other); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 599 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 600 | void ClearHistory() { |
| 601 | pop_count_ = 0; |
| 602 | push_count_ = 0; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 603 | assigned_variables_.Clear(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 604 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 605 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 606 | void SetValueAt(int index, HValue* value) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 607 | ASSERT(index < length()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 608 | values_[index] = value; |
| 609 | } |
| 610 | |
| 611 | void PrintTo(StringStream* stream); |
| 612 | void PrintToStd(); |
| 613 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 614 | Zone* zone() const { return zone_; } |
| 615 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 616 | private: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 617 | HEnvironment(const HEnvironment* other, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 618 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 619 | HEnvironment(HEnvironment* outer, |
| 620 | Handle<JSFunction> closure, |
| 621 | FrameType frame_type, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 622 | int arguments, |
| 623 | Zone* zone); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 624 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 625 | // Create an artificial stub environment (e.g. for argument adaptor or |
| 626 | // constructor stub). |
| 627 | HEnvironment* CreateStubEnvironment(HEnvironment* outer, |
| 628 | Handle<JSFunction> target, |
| 629 | FrameType frame_type, |
| 630 | int arguments) const; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 631 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 632 | // True if index is included in the expression stack part of the environment. |
| 633 | bool HasExpressionAt(int index) const; |
| 634 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 635 | void Initialize(int parameter_count, int local_count, int stack_height); |
| 636 | void Initialize(const HEnvironment* other); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 637 | |
| 638 | // Map a variable to an environment index. Parameter indices are shifted |
| 639 | // by 1 (receiver is parameter index -1 but environment index 0). |
| 640 | // Stack-allocated local indices are shifted by the number of parameters. |
| 641 | int IndexFor(Variable* variable) const { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 642 | ASSERT(variable->IsStackAllocated()); |
| 643 | int shift = variable->IsParameter() |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 644 | ? 1 |
| 645 | : parameter_count_ + specials_count_; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 646 | return variable->index() + shift; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 647 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 648 | |
| 649 | Handle<JSFunction> closure_; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 650 | // Value array [parameters] [specials] [locals] [temporaries]. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 651 | ZoneList<HValue*> values_; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 652 | GrowableBitVector assigned_variables_; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 653 | FrameType frame_type_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 654 | int parameter_count_; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 655 | int specials_count_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 656 | int local_count_; |
| 657 | HEnvironment* outer_; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 658 | HEnterInlined* entry_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 659 | int pop_count_; |
| 660 | int push_count_; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 661 | BailoutId ast_id_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 662 | Zone* zone_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 666 | class HInferRepresentation BASE_EMBEDDED { |
| 667 | public: |
| 668 | explicit HInferRepresentation(HGraph* graph) |
| 669 | : graph_(graph), |
| 670 | worklist_(8, graph->zone()), |
| 671 | in_worklist_(graph->GetMaximumValueID(), graph->zone()) { } |
| 672 | |
| 673 | void Analyze(); |
| 674 | void AddToWorklist(HValue* current); |
| 675 | |
| 676 | private: |
| 677 | Zone* zone() const { return graph_->zone(); } |
| 678 | |
| 679 | HGraph* graph_; |
| 680 | ZoneList<HValue*> worklist_; |
| 681 | BitVector in_worklist_; |
| 682 | }; |
| 683 | |
| 684 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 685 | class HOptimizedGraphBuilder; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 686 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 687 | enum ArgumentsAllowedFlag { |
| 688 | ARGUMENTS_NOT_ALLOWED, |
| 689 | ARGUMENTS_ALLOWED |
| 690 | }; |
| 691 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 692 | |
| 693 | class HIfContinuation; |
| 694 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 695 | // This class is not BASE_EMBEDDED because our inlining implementation uses |
| 696 | // new and delete. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 697 | class AstContext { |
| 698 | public: |
| 699 | bool IsEffect() const { return kind_ == Expression::kEffect; } |
| 700 | bool IsValue() const { return kind_ == Expression::kValue; } |
| 701 | bool IsTest() const { return kind_ == Expression::kTest; } |
| 702 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 703 | // 'Fill' this context with a hydrogen value. The value is assumed to |
| 704 | // have already been inserted in the instruction stream (or not need to |
| 705 | // be, e.g., HPhi). Call this function in tail position in the Visit |
| 706 | // functions for expressions. |
| 707 | virtual void ReturnValue(HValue* value) = 0; |
| 708 | |
| 709 | // Add a hydrogen instruction to the instruction stream (recording an |
| 710 | // environment simulation if necessary) and then fill this context with |
| 711 | // the instruction as value. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 712 | virtual void ReturnInstruction(HInstruction* instr, BailoutId ast_id) = 0; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 713 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 714 | // Finishes the current basic block and materialize a boolean for |
| 715 | // value context, nothing for effect, generate a branch for test context. |
| 716 | // Call this function in tail position in the Visit functions for |
| 717 | // expressions. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 718 | virtual void ReturnControl(HControlInstruction* instr, BailoutId ast_id) = 0; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 719 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 720 | // Finishes the current basic block and materialize a boolean for |
| 721 | // value context, nothing for effect, generate a branch for test context. |
| 722 | // Call this function in tail position in the Visit functions for |
| 723 | // expressions that use an IfBuilder. |
| 724 | virtual void ReturnContinuation(HIfContinuation* continuation, |
| 725 | BailoutId ast_id) = 0; |
| 726 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 727 | void set_for_typeof(bool for_typeof) { for_typeof_ = for_typeof; } |
| 728 | bool is_for_typeof() { return for_typeof_; } |
| 729 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 730 | protected: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 731 | AstContext(HOptimizedGraphBuilder* owner, Expression::Context kind); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | virtual ~AstContext(); |
| 733 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 734 | HOptimizedGraphBuilder* owner() const { return owner_; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 735 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 736 | inline Zone* zone() const; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 737 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 738 | // We want to be able to assert, in a context-specific way, that the stack |
| 739 | // height makes sense when the context is filled. |
| 740 | #ifdef DEBUG |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 741 | int original_length_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 742 | #endif |
| 743 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 744 | private: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 745 | HOptimizedGraphBuilder* owner_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 746 | Expression::Context kind_; |
| 747 | AstContext* outer_; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 748 | bool for_typeof_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 749 | }; |
| 750 | |
| 751 | |
| 752 | class EffectContext: public AstContext { |
| 753 | public: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 754 | explicit EffectContext(HOptimizedGraphBuilder* owner) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 755 | : AstContext(owner, Expression::kEffect) { |
| 756 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 757 | virtual ~EffectContext(); |
| 758 | |
| 759 | virtual void ReturnValue(HValue* value); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 760 | virtual void ReturnInstruction(HInstruction* instr, BailoutId ast_id); |
| 761 | virtual void ReturnControl(HControlInstruction* instr, BailoutId ast_id); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 762 | virtual void ReturnContinuation(HIfContinuation* continuation, |
| 763 | BailoutId ast_id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | |
| 767 | class ValueContext: public AstContext { |
| 768 | public: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 769 | ValueContext(HOptimizedGraphBuilder* owner, ArgumentsAllowedFlag flag) |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 770 | : AstContext(owner, Expression::kValue), flag_(flag) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 771 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 772 | virtual ~ValueContext(); |
| 773 | |
| 774 | virtual void ReturnValue(HValue* value); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 775 | virtual void ReturnInstruction(HInstruction* instr, BailoutId ast_id); |
| 776 | virtual void ReturnControl(HControlInstruction* instr, BailoutId ast_id); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 777 | virtual void ReturnContinuation(HIfContinuation* continuation, |
| 778 | BailoutId ast_id); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 779 | |
| 780 | bool arguments_allowed() { return flag_ == ARGUMENTS_ALLOWED; } |
| 781 | |
| 782 | private: |
| 783 | ArgumentsAllowedFlag flag_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 784 | }; |
| 785 | |
| 786 | |
| 787 | class TestContext: public AstContext { |
| 788 | public: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 789 | TestContext(HOptimizedGraphBuilder* owner, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 790 | Expression* condition, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 791 | TypeFeedbackOracle* oracle, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 792 | HBasicBlock* if_true, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 793 | HBasicBlock* if_false) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 794 | : AstContext(owner, Expression::kTest), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 795 | condition_(condition), |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 796 | oracle_(oracle), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 797 | if_true_(if_true), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 798 | if_false_(if_false) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 799 | } |
| 800 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 801 | virtual void ReturnValue(HValue* value); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 802 | virtual void ReturnInstruction(HInstruction* instr, BailoutId ast_id); |
| 803 | virtual void ReturnControl(HControlInstruction* instr, BailoutId ast_id); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 804 | virtual void ReturnContinuation(HIfContinuation* continuation, |
| 805 | BailoutId ast_id); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 806 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 807 | static TestContext* cast(AstContext* context) { |
| 808 | ASSERT(context->IsTest()); |
| 809 | return reinterpret_cast<TestContext*>(context); |
| 810 | } |
| 811 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 812 | Expression* condition() const { return condition_; } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 813 | TypeFeedbackOracle* oracle() const { return oracle_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 814 | HBasicBlock* if_true() const { return if_true_; } |
| 815 | HBasicBlock* if_false() const { return if_false_; } |
| 816 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 817 | private: |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 818 | // Build the shared core part of the translation unpacking a value into |
| 819 | // control flow. |
| 820 | void BuildBranch(HValue* value); |
| 821 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 822 | Expression* condition_; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 823 | TypeFeedbackOracle* oracle_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 824 | HBasicBlock* if_true_; |
| 825 | HBasicBlock* if_false_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 826 | }; |
| 827 | |
| 828 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 829 | class FunctionState { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 830 | public: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 831 | FunctionState(HOptimizedGraphBuilder* owner, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 832 | CompilationInfo* info, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 833 | TypeFeedbackOracle* oracle, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 834 | InliningKind inlining_kind); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 835 | ~FunctionState(); |
| 836 | |
| 837 | CompilationInfo* compilation_info() { return compilation_info_; } |
| 838 | TypeFeedbackOracle* oracle() { return oracle_; } |
| 839 | AstContext* call_context() { return call_context_; } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 840 | InliningKind inlining_kind() const { return inlining_kind_; } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 841 | HBasicBlock* function_return() { return function_return_; } |
| 842 | TestContext* test_context() { return test_context_; } |
| 843 | void ClearInlinedTestContext() { |
| 844 | delete test_context_; |
| 845 | test_context_ = NULL; |
| 846 | } |
| 847 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 848 | FunctionState* outer() { return outer_; } |
| 849 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 850 | HEnterInlined* entry() { return entry_; } |
| 851 | void set_entry(HEnterInlined* entry) { entry_ = entry; } |
| 852 | |
| 853 | HArgumentsElements* arguments_elements() { return arguments_elements_; } |
| 854 | void set_arguments_elements(HArgumentsElements* arguments_elements) { |
| 855 | arguments_elements_ = arguments_elements; |
| 856 | } |
| 857 | |
| 858 | bool arguments_pushed() { return arguments_elements() != NULL; } |
| 859 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 860 | private: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 861 | HOptimizedGraphBuilder* owner_; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 862 | |
| 863 | CompilationInfo* compilation_info_; |
| 864 | TypeFeedbackOracle* oracle_; |
| 865 | |
| 866 | // During function inlining, expression context of the call being |
| 867 | // inlined. NULL when not inlining. |
| 868 | AstContext* call_context_; |
| 869 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 870 | // The kind of call which is currently being inlined. |
| 871 | InliningKind inlining_kind_; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 872 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 873 | // 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] | 874 | // It is NULL otherwise. When inlining in a test context, there are a |
| 875 | // pair of return blocks in the context. When not inlining, there is no |
| 876 | // local return point. |
| 877 | HBasicBlock* function_return_; |
| 878 | |
| 879 | // When inlining a call in a test context, a context containing a pair of |
| 880 | // return blocks. NULL in all other cases. |
| 881 | TestContext* test_context_; |
| 882 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 883 | // When inlining HEnterInlined instruction corresponding to the function |
| 884 | // entry. |
| 885 | HEnterInlined* entry_; |
| 886 | |
| 887 | HArgumentsElements* arguments_elements_; |
| 888 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 889 | FunctionState* outer_; |
| 890 | }; |
| 891 | |
| 892 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 893 | class HIfContinuation { |
| 894 | public: |
| 895 | HIfContinuation() { continuation_captured_ = false; } |
| 896 | ~HIfContinuation() { ASSERT(!continuation_captured_); } |
| 897 | |
| 898 | void Capture(HBasicBlock* true_branch, |
| 899 | HBasicBlock* false_branch, |
| 900 | int position) { |
| 901 | ASSERT(!continuation_captured_); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 902 | true_branch_ = true_branch; |
| 903 | false_branch_ = false_branch; |
| 904 | position_ = position; |
| 905 | continuation_captured_ = true; |
| 906 | } |
| 907 | |
| 908 | void Continue(HBasicBlock** true_branch, |
| 909 | HBasicBlock** false_branch, |
| 910 | int* position) { |
| 911 | ASSERT(continuation_captured_); |
| 912 | *true_branch = true_branch_; |
| 913 | *false_branch = false_branch_; |
| 914 | if (position != NULL) *position = position_; |
| 915 | continuation_captured_ = false; |
| 916 | } |
| 917 | |
| 918 | bool IsTrueReachable() { return true_branch_ != NULL; } |
| 919 | bool IsFalseReachable() { return false_branch_ != NULL; } |
| 920 | bool TrueAndFalseReachable() { |
| 921 | return IsTrueReachable() || IsFalseReachable(); |
| 922 | } |
| 923 | |
| 924 | bool continuation_captured_; |
| 925 | HBasicBlock* true_branch_; |
| 926 | HBasicBlock* false_branch_; |
| 927 | int position_; |
| 928 | }; |
| 929 | |
| 930 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 931 | class HGraphBuilder { |
| 932 | public: |
| 933 | explicit HGraphBuilder(CompilationInfo* info) |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 934 | : info_(info), |
| 935 | graph_(NULL), |
| 936 | current_block_(NULL), |
| 937 | no_side_effects_scope_count_(0) {} |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 938 | virtual ~HGraphBuilder() {} |
| 939 | |
| 940 | HBasicBlock* current_block() const { return current_block_; } |
| 941 | void set_current_block(HBasicBlock* block) { current_block_ = block; } |
| 942 | HEnvironment* environment() const { |
| 943 | return current_block()->last_environment(); |
| 944 | } |
| 945 | Zone* zone() const { return info_->zone(); } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 946 | HGraph* graph() const { return graph_; } |
| 947 | Isolate* isolate() const { return graph_->isolate(); } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 948 | |
| 949 | HGraph* CreateGraph(); |
| 950 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 951 | // Bailout environment manipulation. |
| 952 | void Push(HValue* value) { environment()->Push(value); } |
| 953 | HValue* Pop() { return environment()->Pop(); } |
| 954 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 955 | // Adding instructions. |
| 956 | HInstruction* AddInstruction(HInstruction* instr); |
| 957 | void AddSimulate(BailoutId id, |
| 958 | RemovableSimulate removable = FIXED_SIMULATE); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 959 | HBoundsCheck* AddBoundsCheck( |
| 960 | HValue* index, |
| 961 | HValue* length, |
| 962 | BoundsCheckKeyMode key_mode = DONT_ALLOW_SMI_KEY, |
| 963 | Representation r = Representation::None()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 964 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 965 | HReturn* AddReturn(HValue* value); |
| 966 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 967 | void IncrementInNoSideEffectsScope() { |
| 968 | no_side_effects_scope_count_++; |
| 969 | } |
| 970 | |
| 971 | void DecrementInNoSideEffectsScope() { |
| 972 | no_side_effects_scope_count_--; |
| 973 | } |
| 974 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 975 | protected: |
| 976 | virtual bool BuildGraph() = 0; |
| 977 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 978 | HBasicBlock* CreateBasicBlock(HEnvironment* env); |
| 979 | HBasicBlock* CreateLoopHeaderBlock(); |
| 980 | |
| 981 | HValue* BuildCheckNonSmi(HValue* object); |
| 982 | HValue* BuildCheckMap(HValue* obj, Handle<Map> map); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 983 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 984 | // Building common constructs |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 985 | HLoadNamedField* DoBuildLoadNamedField(HValue* object, |
| 986 | bool inobject, |
| 987 | Representation representation, |
| 988 | int offset); |
| 989 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 990 | HInstruction* BuildExternalArrayElementAccess( |
| 991 | HValue* external_elements, |
| 992 | HValue* checked_key, |
| 993 | HValue* val, |
| 994 | HValue* dependency, |
| 995 | ElementsKind elements_kind, |
| 996 | bool is_store); |
| 997 | |
| 998 | HInstruction* BuildFastElementAccess( |
| 999 | HValue* elements, |
| 1000 | HValue* checked_key, |
| 1001 | HValue* val, |
| 1002 | HValue* dependency, |
| 1003 | ElementsKind elements_kind, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1004 | bool is_store, |
| 1005 | KeyedAccessStoreMode store_mode); |
| 1006 | |
| 1007 | HValue* BuildCheckForCapacityGrow(HValue* object, |
| 1008 | HValue* elements, |
| 1009 | ElementsKind kind, |
| 1010 | HValue* length, |
| 1011 | HValue* key, |
| 1012 | bool is_js_array); |
| 1013 | |
| 1014 | HValue* BuildCopyElementsOnWrite(HValue* object, |
| 1015 | HValue* elements, |
| 1016 | ElementsKind kind, |
| 1017 | HValue* length); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1018 | |
| 1019 | HInstruction* BuildUncheckedMonomorphicElementAccess( |
| 1020 | HValue* object, |
| 1021 | HValue* key, |
| 1022 | HValue* val, |
| 1023 | HCheckMaps* mapcheck, |
| 1024 | bool is_js_array, |
| 1025 | ElementsKind elements_kind, |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1026 | bool is_store, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1027 | KeyedAccessStoreMode store_mode, |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1028 | Representation checked_index_representation = Representation::None()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1029 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1030 | HInstruction* BuildStoreMap(HValue* object, HValue* map); |
| 1031 | HInstruction* BuildStoreMap(HValue* object, Handle<Map> map); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1032 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 1033 | HLoadNamedField* AddLoadElements(HValue *object, HValue *typecheck = NULL); |
| 1034 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1035 | class IfBuilder { |
| 1036 | public: |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1037 | explicit IfBuilder(HGraphBuilder* builder, |
| 1038 | int position = RelocInfo::kNoPosition); |
| 1039 | IfBuilder(HGraphBuilder* builder, |
| 1040 | HIfContinuation* continuation); |
| 1041 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1042 | ~IfBuilder() { |
| 1043 | if (!finished_) End(); |
| 1044 | } |
| 1045 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1046 | HInstruction* IfCompare( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1047 | HValue* left, |
| 1048 | HValue* right, |
| 1049 | Token::Value token, |
| 1050 | Representation input_representation = Representation::Integer32()); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1051 | |
| 1052 | HInstruction* IfCompareMap(HValue* left, Handle<Map> map); |
| 1053 | |
| 1054 | template<class Condition> |
| 1055 | HInstruction* If(HValue *p) { |
| 1056 | HControlInstruction* compare = new(zone()) Condition(p); |
| 1057 | AddCompare(compare); |
| 1058 | return compare; |
| 1059 | } |
| 1060 | |
| 1061 | template<class Condition, class P2> |
| 1062 | HInstruction* If(HValue* p1, P2 p2) { |
| 1063 | HControlInstruction* compare = new(zone()) Condition(p1, p2); |
| 1064 | AddCompare(compare); |
| 1065 | return compare; |
| 1066 | } |
| 1067 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1068 | template<class Condition, class P2> |
| 1069 | HInstruction* IfNot(HValue* p1, P2 p2) { |
| 1070 | HControlInstruction* compare = new(zone()) Condition(p1, p2); |
| 1071 | AddCompare(compare); |
| 1072 | HBasicBlock* block0 = compare->SuccessorAt(0); |
| 1073 | HBasicBlock* block1 = compare->SuccessorAt(1); |
| 1074 | compare->SetSuccessorAt(0, block1); |
| 1075 | compare->SetSuccessorAt(1, block0); |
| 1076 | return compare; |
| 1077 | } |
| 1078 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1079 | HInstruction* OrIfCompare( |
| 1080 | HValue* p1, |
| 1081 | HValue* p2, |
| 1082 | Token::Value token, |
| 1083 | Representation input_representation = Representation::Integer32()) { |
| 1084 | Or(); |
| 1085 | return IfCompare(p1, p2, token, input_representation); |
| 1086 | } |
| 1087 | |
| 1088 | HInstruction* OrIfCompareMap(HValue* left, Handle<Map> map) { |
| 1089 | Or(); |
| 1090 | return IfCompareMap(left, map); |
| 1091 | } |
| 1092 | |
| 1093 | template<class Condition> |
| 1094 | HInstruction* OrIf(HValue *p) { |
| 1095 | Or(); |
| 1096 | return If<Condition>(p); |
| 1097 | } |
| 1098 | |
| 1099 | template<class Condition, class P2> |
| 1100 | HInstruction* OrIf(HValue* p1, P2 p2) { |
| 1101 | Or(); |
| 1102 | return If<Condition>(p1, p2); |
| 1103 | } |
| 1104 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1105 | HInstruction* AndIfCompare( |
| 1106 | HValue* p1, |
| 1107 | HValue* p2, |
| 1108 | Token::Value token, |
| 1109 | Representation input_representation = Representation::Integer32()) { |
| 1110 | And(); |
| 1111 | return IfCompare(p1, p2, token, input_representation); |
| 1112 | } |
| 1113 | |
| 1114 | HInstruction* AndIfCompareMap(HValue* left, Handle<Map> map) { |
| 1115 | And(); |
| 1116 | return IfCompareMap(left, map); |
| 1117 | } |
| 1118 | |
| 1119 | template<class Condition> |
| 1120 | HInstruction* AndIf(HValue *p) { |
| 1121 | And(); |
| 1122 | return If<Condition>(p); |
| 1123 | } |
| 1124 | |
| 1125 | template<class Condition, class P2> |
| 1126 | HInstruction* AndIf(HValue* p1, P2 p2) { |
| 1127 | And(); |
| 1128 | return If<Condition>(p1, p2); |
| 1129 | } |
| 1130 | |
| 1131 | void Or(); |
| 1132 | void And(); |
| 1133 | |
| 1134 | void CaptureContinuation(HIfContinuation* continuation); |
| 1135 | |
| 1136 | void Then(); |
| 1137 | void Else(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1138 | void End(); |
| 1139 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1140 | void Deopt(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1141 | void ElseDeopt() { |
| 1142 | Else(); |
| 1143 | Deopt(); |
| 1144 | End(); |
| 1145 | } |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1146 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1147 | void Return(HValue* value); |
| 1148 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1149 | private: |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1150 | void AddCompare(HControlInstruction* compare); |
| 1151 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1152 | Zone* zone() { return builder_->zone(); } |
| 1153 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1154 | HGraphBuilder* builder_; |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1155 | int position_; |
| 1156 | bool finished_ : 1; |
| 1157 | bool did_then_ : 1; |
| 1158 | bool did_else_ : 1; |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1159 | bool did_and_ : 1; |
| 1160 | bool did_or_ : 1; |
| 1161 | bool captured_ : 1; |
| 1162 | bool needs_compare_ : 1; |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1163 | HBasicBlock* first_true_block_; |
| 1164 | HBasicBlock* last_true_block_; |
| 1165 | HBasicBlock* first_false_block_; |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1166 | HBasicBlock* split_edge_merge_block_; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1167 | HBasicBlock* merge_block_; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1168 | }; |
| 1169 | |
| 1170 | class LoopBuilder { |
| 1171 | public: |
| 1172 | enum Direction { |
| 1173 | kPreIncrement, |
| 1174 | kPostIncrement, |
| 1175 | kPreDecrement, |
| 1176 | kPostDecrement |
| 1177 | }; |
| 1178 | |
| 1179 | LoopBuilder(HGraphBuilder* builder, |
| 1180 | HValue* context, |
danno@chromium.org | 2d18b36 | 2013-03-22 17:19:26 +0000 | [diff] [blame] | 1181 | Direction direction); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1182 | ~LoopBuilder() { |
| 1183 | ASSERT(finished_); |
| 1184 | } |
| 1185 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1186 | HValue* BeginBody( |
| 1187 | HValue* initial, |
| 1188 | HValue* terminating, |
| 1189 | Token::Value token, |
| 1190 | Representation input_representation = Representation::Integer32()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1191 | void EndBody(); |
| 1192 | |
| 1193 | private: |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1194 | Zone* zone() { return builder_->zone(); } |
| 1195 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1196 | HGraphBuilder* builder_; |
| 1197 | HValue* context_; |
| 1198 | HInstruction* increment_; |
| 1199 | HPhi* phi_; |
| 1200 | HBasicBlock* header_block_; |
| 1201 | HBasicBlock* body_block_; |
| 1202 | HBasicBlock* exit_block_; |
| 1203 | Direction direction_; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1204 | bool finished_; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1205 | }; |
| 1206 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1207 | class NoObservableSideEffectsScope { |
| 1208 | public: |
| 1209 | explicit NoObservableSideEffectsScope(HGraphBuilder* builder) : |
| 1210 | builder_(builder) { |
| 1211 | builder_->IncrementInNoSideEffectsScope(); |
| 1212 | } |
| 1213 | ~NoObservableSideEffectsScope() { |
| 1214 | builder_->DecrementInNoSideEffectsScope(); |
| 1215 | } |
| 1216 | |
| 1217 | private: |
| 1218 | HGraphBuilder* builder_; |
| 1219 | }; |
| 1220 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1221 | HValue* BuildNewElementsCapacity(HValue* context, |
| 1222 | HValue* old_capacity); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1223 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1224 | void BuildNewSpaceArrayCheck(HValue* length, |
| 1225 | ElementsKind kind); |
| 1226 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1227 | class JSArrayBuilder { |
| 1228 | public: |
| 1229 | JSArrayBuilder(HGraphBuilder* builder, |
| 1230 | ElementsKind kind, |
| 1231 | HValue* allocation_site_payload, |
| 1232 | AllocationSiteMode mode); |
| 1233 | |
| 1234 | HValue* AllocateEmptyArray(); |
| 1235 | HValue* AllocateArray(HValue* capacity, HValue* length_field, |
| 1236 | bool fill_with_hole); |
| 1237 | HValue* GetElementsLocation() { return elements_location_; } |
| 1238 | |
| 1239 | private: |
| 1240 | Zone* zone() const { return builder_->zone(); } |
| 1241 | int elements_size() const { |
| 1242 | return IsFastDoubleElementsKind(kind_) ? kDoubleSize : kPointerSize; |
| 1243 | } |
| 1244 | HInstruction* AddInstruction(HInstruction* instr) { |
| 1245 | return builder_->AddInstruction(instr); |
| 1246 | } |
| 1247 | HGraphBuilder* builder() { return builder_; } |
| 1248 | HGraph* graph() { return builder_->graph(); } |
| 1249 | int initial_capacity() { |
| 1250 | STATIC_ASSERT(JSArray::kPreallocatedArrayElements > 0); |
| 1251 | return JSArray::kPreallocatedArrayElements; |
| 1252 | } |
| 1253 | |
| 1254 | HValue* EmitMapCode(HValue* context); |
| 1255 | HValue* EstablishEmptyArrayAllocationSize(); |
| 1256 | HValue* EstablishAllocationSize(HValue* length_node); |
| 1257 | HValue* AllocateArray(HValue* size_in_bytes, HValue* capacity, |
| 1258 | HValue* length_field, bool fill_with_hole); |
| 1259 | |
| 1260 | HGraphBuilder* builder_; |
| 1261 | ElementsKind kind_; |
| 1262 | AllocationSiteMode mode_; |
| 1263 | HValue* allocation_site_payload_; |
| 1264 | HInnerAllocatedObject* elements_location_; |
| 1265 | }; |
| 1266 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1267 | HValue* BuildAllocateElements(HValue* context, |
| 1268 | ElementsKind kind, |
danno@chromium.org | 2d18b36 | 2013-03-22 17:19:26 +0000 | [diff] [blame] | 1269 | HValue* capacity); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1270 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1271 | void BuildInitializeElements(HValue* elements, |
| 1272 | ElementsKind kind, |
| 1273 | HValue* capacity); |
| 1274 | |
| 1275 | HValue* BuildAllocateAndInitializeElements(HValue* context, |
| 1276 | ElementsKind kind, |
| 1277 | HValue* capacity); |
| 1278 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1279 | // array must have been allocated with enough room for |
| 1280 | // 1) the JSArray, 2) a AllocationSiteInfo if mode requires it, |
| 1281 | // 3) a FixedArray or FixedDoubleArray. |
| 1282 | // A pointer to the Fixed(Double)Array is returned. |
| 1283 | HInnerAllocatedObject* BuildJSArrayHeader(HValue* array, |
| 1284 | HValue* array_map, |
| 1285 | AllocationSiteMode mode, |
| 1286 | HValue* allocation_site_payload, |
| 1287 | HValue* length_field); |
| 1288 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1289 | HValue* BuildGrowElementsCapacity(HValue* object, |
| 1290 | HValue* elements, |
| 1291 | ElementsKind kind, |
| 1292 | HValue* length, |
danno@chromium.org | 2d18b36 | 2013-03-22 17:19:26 +0000 | [diff] [blame] | 1293 | HValue* new_capacity); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1294 | |
| 1295 | void BuildFillElementsWithHole(HValue* context, |
| 1296 | HValue* elements, |
| 1297 | ElementsKind elements_kind, |
| 1298 | HValue* from, |
danno@chromium.org | 2d18b36 | 2013-03-22 17:19:26 +0000 | [diff] [blame] | 1299 | HValue* to); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1300 | |
| 1301 | void BuildCopyElements(HValue* context, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1302 | HValue* from_elements, |
| 1303 | ElementsKind from_elements_kind, |
| 1304 | HValue* to_elements, |
| 1305 | ElementsKind to_elements_kind, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1306 | HValue* length, |
danno@chromium.org | 2d18b36 | 2013-03-22 17:19:26 +0000 | [diff] [blame] | 1307 | HValue* capacity); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1308 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1309 | HValue* BuildCloneShallowArray(HContext* context, |
| 1310 | HValue* boilerplate, |
| 1311 | AllocationSiteMode mode, |
| 1312 | ElementsKind kind, |
| 1313 | int length); |
| 1314 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1315 | void BuildCompareNil( |
| 1316 | HValue* value, |
| 1317 | EqualityKind kind, |
| 1318 | CompareNilICStub::Types types, |
| 1319 | Handle<Map> map, |
| 1320 | int position, |
| 1321 | HIfContinuation* continuation); |
| 1322 | |
| 1323 | HValue* BuildCreateAllocationSiteInfo(HValue* previous_object, |
| 1324 | int previous_object_size, |
| 1325 | HValue* payload); |
| 1326 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 1327 | HInstruction* BuildGetNativeContext(HValue* context); |
| 1328 | HInstruction* BuildGetArrayFunction(HValue* context); |
| 1329 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1330 | private: |
| 1331 | HGraphBuilder(); |
| 1332 | CompilationInfo* info_; |
| 1333 | HGraph* graph_; |
| 1334 | HBasicBlock* current_block_; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1335 | int no_side_effects_scope_count_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1336 | }; |
| 1337 | |
| 1338 | |
| 1339 | class HOptimizedGraphBuilder: public HGraphBuilder, public AstVisitor { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1340 | public: |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1341 | enum BreakType { BREAK, CONTINUE }; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1342 | enum SwitchType { UNKNOWN_SWITCH, SMI_SWITCH, STRING_SWITCH }; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1343 | |
| 1344 | // A class encapsulating (lazily-allocated) break and continue blocks for |
| 1345 | // a breakable statement. Separated from BreakAndContinueScope so that it |
| 1346 | // can have a separate lifetime. |
| 1347 | class BreakAndContinueInfo BASE_EMBEDDED { |
| 1348 | public: |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1349 | explicit BreakAndContinueInfo(BreakableStatement* target, |
| 1350 | int drop_extra = 0) |
| 1351 | : target_(target), |
| 1352 | break_block_(NULL), |
| 1353 | continue_block_(NULL), |
| 1354 | drop_extra_(drop_extra) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | BreakableStatement* target() { return target_; } |
| 1358 | HBasicBlock* break_block() { return break_block_; } |
| 1359 | void set_break_block(HBasicBlock* block) { break_block_ = block; } |
| 1360 | HBasicBlock* continue_block() { return continue_block_; } |
| 1361 | void set_continue_block(HBasicBlock* block) { continue_block_ = block; } |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1362 | int drop_extra() { return drop_extra_; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1363 | |
| 1364 | private: |
| 1365 | BreakableStatement* target_; |
| 1366 | HBasicBlock* break_block_; |
| 1367 | HBasicBlock* continue_block_; |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1368 | int drop_extra_; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1369 | }; |
| 1370 | |
| 1371 | // A helper class to maintain a stack of current BreakAndContinueInfo |
| 1372 | // structures mirroring BreakableStatement nesting. |
| 1373 | class BreakAndContinueScope BASE_EMBEDDED { |
| 1374 | public: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1375 | BreakAndContinueScope(BreakAndContinueInfo* info, |
| 1376 | HOptimizedGraphBuilder* owner) |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1377 | : info_(info), owner_(owner), next_(owner->break_scope()) { |
| 1378 | owner->set_break_scope(this); |
| 1379 | } |
| 1380 | |
| 1381 | ~BreakAndContinueScope() { owner_->set_break_scope(next_); } |
| 1382 | |
| 1383 | BreakAndContinueInfo* info() { return info_; } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1384 | HOptimizedGraphBuilder* owner() { return owner_; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1385 | BreakAndContinueScope* next() { return next_; } |
| 1386 | |
| 1387 | // Search the break stack for a break or continue target. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1388 | HBasicBlock* Get(BreakableStatement* stmt, BreakType type, int* drop_extra); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1389 | |
| 1390 | private: |
| 1391 | BreakAndContinueInfo* info_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1392 | HOptimizedGraphBuilder* owner_; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1393 | BreakAndContinueScope* next_; |
| 1394 | }; |
| 1395 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1396 | HOptimizedGraphBuilder(CompilationInfo* info, TypeFeedbackOracle* oracle); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1397 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1398 | virtual bool BuildGraph(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1399 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1400 | // Simple accessors. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1401 | BreakAndContinueScope* break_scope() const { return break_scope_; } |
| 1402 | void set_break_scope(BreakAndContinueScope* head) { break_scope_ = head; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1403 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1404 | bool inline_bailout() { return inline_bailout_; } |
| 1405 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1406 | void AddSoftDeoptimize(); |
| 1407 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1408 | void Bailout(const char* reason); |
| 1409 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1410 | HBasicBlock* CreateJoin(HBasicBlock* first, |
| 1411 | HBasicBlock* second, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1412 | BailoutId join_id); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1413 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1414 | TypeFeedbackOracle* oracle() const { return function_state()->oracle(); } |
| 1415 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1416 | FunctionState* function_state() const { return function_state_; } |
| 1417 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 1418 | void VisitDeclarations(ZoneList<Declaration*>* declarations); |
| 1419 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 1420 | void* operator new(size_t size, Zone* zone) { |
| 1421 | return zone->New(static_cast<int>(size)); |
| 1422 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1423 | void operator delete(void* pointer, Zone* zone) { } |
| 1424 | void operator delete(void* pointer) { } |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 1425 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1426 | DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 1427 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1428 | private: |
| 1429 | // Type of a member function that generates inline code for a native function. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1430 | typedef void (HOptimizedGraphBuilder::*InlineFunctionGenerator) |
| 1431 | (CallRuntime* call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1432 | |
| 1433 | // Forward declarations for inner scope classes. |
| 1434 | class SubgraphScope; |
| 1435 | |
| 1436 | static const InlineFunctionGenerator kInlineFunctionGenerators[]; |
| 1437 | |
| 1438 | static const int kMaxCallPolymorphism = 4; |
| 1439 | static const int kMaxLoadPolymorphism = 4; |
| 1440 | static const int kMaxStorePolymorphism = 4; |
| 1441 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1442 | // Even in the 'unlimited' case we have to have some limit in order not to |
| 1443 | // overflow the stack. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 1444 | static const int kUnlimitedMaxInlinedSourceSize = 100000; |
| 1445 | static const int kUnlimitedMaxInlinedNodes = 10000; |
| 1446 | static const int kUnlimitedMaxInlinedNodesCumulative = 10000; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1447 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1448 | // Maximum depth and total number of elements and properties for literal |
| 1449 | // graphs to be considered for fast deep-copying. |
| 1450 | static const int kMaxFastLiteralDepth = 3; |
| 1451 | static const int kMaxFastLiteralProperties = 8; |
| 1452 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1453 | // Simple accessors. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1454 | void set_function_state(FunctionState* state) { function_state_ = state; } |
| 1455 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1456 | AstContext* ast_context() const { return ast_context_; } |
| 1457 | void set_ast_context(AstContext* context) { ast_context_ = context; } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1458 | |
| 1459 | // Accessors forwarded to the function state. |
| 1460 | CompilationInfo* info() const { |
| 1461 | return function_state()->compilation_info(); |
| 1462 | } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1463 | AstContext* call_context() const { |
| 1464 | return function_state()->call_context(); |
| 1465 | } |
| 1466 | HBasicBlock* function_return() const { |
| 1467 | return function_state()->function_return(); |
| 1468 | } |
| 1469 | TestContext* inlined_test_context() const { |
| 1470 | return function_state()->test_context(); |
| 1471 | } |
| 1472 | void ClearInlinedTestContext() { |
| 1473 | function_state()->ClearInlinedTestContext(); |
| 1474 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1475 | StrictModeFlag function_strict_mode_flag() { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1476 | return function_state()->compilation_info()->is_classic_mode() |
| 1477 | ? kNonStrictMode : kStrictMode; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1478 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1479 | |
| 1480 | // Generators for inline runtime functions. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1481 | #define INLINE_FUNCTION_GENERATOR_DECLARATION(Name, argc, ressize) \ |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1482 | void Generate##Name(CallRuntime* call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1483 | |
| 1484 | INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_DECLARATION) |
| 1485 | INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_DECLARATION) |
| 1486 | #undef INLINE_FUNCTION_GENERATOR_DECLARATION |
| 1487 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1488 | void VisitDelete(UnaryOperation* expr); |
| 1489 | void VisitVoid(UnaryOperation* expr); |
| 1490 | void VisitTypeof(UnaryOperation* expr); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1491 | void VisitSub(UnaryOperation* expr); |
| 1492 | void VisitBitNot(UnaryOperation* expr); |
| 1493 | void VisitNot(UnaryOperation* expr); |
| 1494 | |
| 1495 | void VisitComma(BinaryOperation* expr); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1496 | void VisitLogicalExpression(BinaryOperation* expr); |
| 1497 | void VisitArithmeticExpression(BinaryOperation* expr); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1498 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1499 | bool PreProcessOsrEntry(IterationStatement* statement); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1500 | // True iff. we are compiling for OSR and the statement is the entry. |
| 1501 | bool HasOsrEntryAt(IterationStatement* statement); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1502 | void VisitLoopBody(IterationStatement* stmt, |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1503 | HBasicBlock* loop_entry, |
| 1504 | BreakAndContinueInfo* break_info); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1505 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1506 | // Create a back edge in the flow graph. body_exit is the predecessor |
| 1507 | // block and loop_entry is the successor block. loop_successor is the |
| 1508 | // block where control flow exits the loop normally (e.g., via failure of |
| 1509 | // the condition) and break_block is the block where control flow breaks |
| 1510 | // from the loop. All blocks except loop_entry can be NULL. The return |
| 1511 | // value is the new successor block which is the join of loop_successor |
| 1512 | // and break_block, or NULL. |
| 1513 | HBasicBlock* CreateLoop(IterationStatement* statement, |
| 1514 | HBasicBlock* loop_entry, |
| 1515 | HBasicBlock* body_exit, |
| 1516 | HBasicBlock* loop_successor, |
| 1517 | HBasicBlock* break_block); |
| 1518 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1519 | HBasicBlock* JoinContinue(IterationStatement* statement, |
| 1520 | HBasicBlock* exit_block, |
| 1521 | HBasicBlock* continue_block); |
| 1522 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1523 | HValue* Top() const { return environment()->Top(); } |
| 1524 | void Drop(int n) { environment()->Drop(n); } |
| 1525 | void Bind(Variable* var, HValue* value) { environment()->Bind(var, value); } |
| 1526 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1527 | // The value of the arguments object is allowed in some but not most value |
| 1528 | // contexts. (It's allowed in all effect contexts and disallowed in all |
| 1529 | // test contexts.) |
| 1530 | void VisitForValue(Expression* expr, |
| 1531 | ArgumentsAllowedFlag flag = ARGUMENTS_NOT_ALLOWED); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1532 | void VisitForTypeOf(Expression* expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1533 | void VisitForEffect(Expression* expr); |
| 1534 | void VisitForControl(Expression* expr, |
| 1535 | HBasicBlock* true_block, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1536 | HBasicBlock* false_block); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1537 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1538 | // Visit an argument subexpression and emit a push to the outgoing arguments. |
| 1539 | void VisitArgument(Expression* expr); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1540 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1541 | void VisitArgumentList(ZoneList<Expression*>* arguments); |
| 1542 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1543 | // Visit a list of expressions from left to right, each in a value context. |
| 1544 | void VisitExpressions(ZoneList<Expression*>* exprs); |
| 1545 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1546 | void AddPhi(HPhi* phi); |
| 1547 | |
| 1548 | void PushAndAdd(HInstruction* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1549 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1550 | // Remove the arguments from the bailout environment and emit instructions |
| 1551 | // to push them as outgoing parameters. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1552 | template <class Instruction> HInstruction* PreProcessCall(Instruction* call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1553 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1554 | static Representation ToRepresentation(TypeInfo info); |
| 1555 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1556 | void SetUpScope(Scope* scope); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1557 | virtual void VisitStatements(ZoneList<Statement*>* statements); |
| 1558 | |
| 1559 | #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 1560 | AST_NODE_LIST(DECLARE_VISIT) |
| 1561 | #undef DECLARE_VISIT |
| 1562 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1563 | // Helpers for flow graph construction. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1564 | enum GlobalPropertyAccess { |
| 1565 | kUseCell, |
| 1566 | kUseGeneric |
| 1567 | }; |
| 1568 | GlobalPropertyAccess LookupGlobalProperty(Variable* var, |
| 1569 | LookupResult* lookup, |
| 1570 | bool is_store); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1571 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1572 | void EnsureArgumentsArePushedForAccess(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1573 | bool TryArgumentsAccess(Property* expr); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1574 | |
| 1575 | // Try to optimize fun.apply(receiver, arguments) pattern. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1576 | bool TryCallApply(Call* expr); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1577 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1578 | int InliningAstSize(Handle<JSFunction> target); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1579 | bool TryInline(CallKind call_kind, |
| 1580 | Handle<JSFunction> target, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1581 | int arguments_count, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1582 | HValue* implicit_return_value, |
| 1583 | BailoutId ast_id, |
| 1584 | BailoutId return_id, |
| 1585 | InliningKind inlining_kind); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1586 | |
| 1587 | bool TryInlineCall(Call* expr, bool drop_extra = false); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1588 | bool TryInlineConstruct(CallNew* expr, HValue* implicit_return_value); |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 1589 | bool TryInlineGetter(Handle<JSFunction> getter, Property* prop); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1590 | bool TryInlineSetter(Handle<JSFunction> setter, |
| 1591 | Assignment* assignment, |
| 1592 | HValue* implicit_return_value); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 1593 | bool TryInlineApply(Handle<JSFunction> function, |
| 1594 | Call* expr, |
| 1595 | int arguments_count); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1596 | bool TryInlineBuiltinMethodCall(Call* expr, |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1597 | HValue* receiver, |
| 1598 | Handle<Map> receiver_map, |
| 1599 | CheckType check_type); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1600 | bool TryInlineBuiltinFunctionCall(Call* expr, bool drop_extra); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1601 | |
| 1602 | // If --trace-inlining, print a line of the inlining trace. Inlining |
| 1603 | // succeeded if the reason string is NULL and failed if there is a |
| 1604 | // non-NULL reason string. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1605 | void TraceInline(Handle<JSFunction> target, |
| 1606 | Handle<JSFunction> caller, |
| 1607 | const char* failure_reason); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1608 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1609 | void HandleGlobalVariableAssignment(Variable* var, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1610 | HValue* value, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1611 | int position, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1612 | BailoutId ast_id); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1613 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1614 | void HandlePropertyAssignment(Assignment* expr); |
| 1615 | void HandleCompoundAssignment(Assignment* expr); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 1616 | void HandlePolymorphicLoadNamedField(Property* expr, |
| 1617 | HValue* object, |
| 1618 | SmallMapList* types, |
| 1619 | Handle<String> name); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1620 | bool HandlePolymorphicArrayLengthLoad(Property* expr, |
| 1621 | HValue* object, |
| 1622 | SmallMapList* types, |
| 1623 | Handle<String> name); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1624 | void HandlePolymorphicStoreNamedField(Assignment* expr, |
| 1625 | HValue* object, |
| 1626 | HValue* value, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1627 | SmallMapList* types, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1628 | Handle<String> name); |
| 1629 | void HandlePolymorphicCallNamed(Call* expr, |
| 1630 | HValue* receiver, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1631 | SmallMapList* types, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1632 | Handle<String> name); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1633 | void HandleLiteralCompareTypeof(CompareOperation* expr, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1634 | HTypeof* typeof_expr, |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1635 | Handle<String> check); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1636 | void HandleLiteralCompareNil(CompareOperation* expr, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1637 | HValue* value, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1638 | NilValue nil); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1639 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 1640 | HInstruction* BuildStringCharCodeAt(HValue* context, |
| 1641 | HValue* string, |
| 1642 | HValue* index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1643 | HInstruction* BuildBinaryOperation(BinaryOperation* expr, |
| 1644 | HValue* left, |
| 1645 | HValue* right); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1646 | HInstruction* BuildIncrement(bool returns_original_input, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1647 | CountOperation* expr); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1648 | HInstruction* BuildLoadKeyedGeneric(HValue* object, |
| 1649 | HValue* key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1650 | |
mstarzinger@chromium.org | c6d9cee | 2012-07-03 10:03:19 +0000 | [diff] [blame] | 1651 | HInstruction* TryBuildConsolidatedElementLoad(HValue* object, |
| 1652 | HValue* key, |
| 1653 | HValue* val, |
| 1654 | SmallMapList* maps); |
| 1655 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1656 | HInstruction* BuildMonomorphicElementAccess(HValue* object, |
| 1657 | HValue* key, |
| 1658 | HValue* val, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1659 | HValue* dependency, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1660 | Handle<Map> map, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1661 | bool is_store, |
| 1662 | KeyedAccessStoreMode store_mode); |
mstarzinger@chromium.org | c6d9cee | 2012-07-03 10:03:19 +0000 | [diff] [blame] | 1663 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1664 | HValue* HandlePolymorphicElementAccess(HValue* object, |
| 1665 | HValue* key, |
| 1666 | HValue* val, |
| 1667 | Expression* prop, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1668 | BailoutId ast_id, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1669 | int position, |
| 1670 | bool is_store, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1671 | KeyedAccessStoreMode store_mode, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1672 | bool* has_side_effects); |
| 1673 | |
| 1674 | HValue* HandleKeyedElementAccess(HValue* obj, |
| 1675 | HValue* key, |
| 1676 | HValue* val, |
| 1677 | Expression* expr, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1678 | BailoutId ast_id, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1679 | int position, |
| 1680 | bool is_store, |
| 1681 | bool* has_side_effects); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1682 | |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 1683 | HLoadNamedField* BuildLoadNamedField(HValue* object, |
| 1684 | Handle<Map> map, |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1685 | LookupResult* result); |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 1686 | HInstruction* BuildLoadNamedGeneric(HValue* object, |
| 1687 | Handle<String> name, |
| 1688 | Property* expr); |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1689 | HInstruction* BuildCallGetter(HValue* object, |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1690 | Handle<Map> map, |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 1691 | Handle<JSFunction> getter, |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1692 | Handle<JSObject> holder); |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1693 | HInstruction* BuildLoadNamedMonomorphic(HValue* object, |
| 1694 | Handle<String> name, |
| 1695 | Property* expr, |
| 1696 | Handle<Map> map); |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 1697 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1698 | void AddCheckMap(HValue* object, Handle<Map> map); |
| 1699 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1700 | void AddCheckMapsWithTransitions(HValue* object, |
| 1701 | Handle<Map> map); |
| 1702 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1703 | HInstruction* BuildStoreNamedField(HValue* object, |
| 1704 | Handle<String> name, |
| 1705 | HValue* value, |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1706 | Handle<Map> map, |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1707 | LookupResult* lookup); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1708 | HInstruction* BuildStoreNamedGeneric(HValue* object, |
| 1709 | Handle<String> name, |
| 1710 | HValue* value); |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 1711 | HInstruction* BuildCallSetter(HValue* object, |
| 1712 | HValue* value, |
| 1713 | Handle<Map> map, |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 1714 | Handle<JSFunction> setter, |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 1715 | Handle<JSObject> holder); |
| 1716 | HInstruction* BuildStoreNamedMonomorphic(HValue* object, |
| 1717 | Handle<String> name, |
| 1718 | HValue* value, |
| 1719 | Handle<Map> map); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1720 | HInstruction* BuildStoreKeyedGeneric(HValue* object, |
| 1721 | HValue* key, |
| 1722 | HValue* value); |
| 1723 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1724 | HValue* BuildContextChainWalk(Variable* var); |
| 1725 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1726 | HInstruction* BuildThisFunction(); |
| 1727 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1728 | HInstruction* BuildFastLiteral(HValue* context, |
| 1729 | Handle<JSObject> boilerplate_object, |
| 1730 | Handle<JSObject> original_boilerplate_object, |
| 1731 | int data_size, |
| 1732 | int pointer_size, |
| 1733 | AllocationSiteMode mode); |
| 1734 | |
| 1735 | void BuildEmitDeepCopy(Handle<JSObject> boilerplat_object, |
| 1736 | Handle<JSObject> object, |
| 1737 | HInstruction* result, |
| 1738 | int* offset, |
| 1739 | AllocationSiteMode mode); |
| 1740 | |
| 1741 | MUST_USE_RESULT HValue* BuildCopyObjectHeader( |
| 1742 | Handle<JSObject> boilerplat_object, |
| 1743 | HInstruction* target, |
| 1744 | int object_offset, |
| 1745 | int elements_offset, |
| 1746 | int elements_size); |
| 1747 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1748 | void AddCheckPrototypeMaps(Handle<JSObject> holder, |
| 1749 | Handle<Map> receiver_map); |
| 1750 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1751 | void AddCheckConstantFunction(Handle<JSObject> holder, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1752 | HValue* receiver, |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1753 | Handle<Map> receiver_map); |
| 1754 | |
| 1755 | bool MatchRotateRight(HValue* left, |
| 1756 | HValue* right, |
| 1757 | HValue** operand, |
| 1758 | HValue** shift_amount); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1759 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1760 | // The translation state of the currently-being-translated function. |
| 1761 | FunctionState* function_state_; |
| 1762 | |
| 1763 | // The base of the function state stack. |
| 1764 | FunctionState initial_function_state_; |
| 1765 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1766 | // Expression context of the currently visited subexpression. NULL when |
| 1767 | // visiting statements. |
| 1768 | AstContext* ast_context_; |
| 1769 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1770 | // A stack of breakable statements entered. |
| 1771 | BreakAndContinueScope* break_scope_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1772 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1773 | int inlined_count_; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1774 | ZoneList<Handle<Object> > globals_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1776 | bool inline_bailout_; |
| 1777 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1778 | friend class FunctionState; // Pushes and pops the state stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1779 | friend class AstContext; // Pushes and pops the AST context stack. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1780 | friend class KeyedLoadFastElementStub; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1781 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1782 | DISALLOW_COPY_AND_ASSIGN(HOptimizedGraphBuilder); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1783 | }; |
| 1784 | |
| 1785 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1786 | Zone* AstContext::zone() const { return owner_->zone(); } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1787 | |
| 1788 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1789 | class HValueMap: public ZoneObject { |
| 1790 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1791 | explicit HValueMap(Zone* zone) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1792 | : array_size_(0), |
| 1793 | lists_size_(0), |
| 1794 | count_(0), |
| 1795 | present_flags_(0), |
| 1796 | array_(NULL), |
| 1797 | lists_(NULL), |
| 1798 | free_list_head_(kNil) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1799 | ResizeLists(kInitialSize, zone); |
| 1800 | Resize(kInitialSize, zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1803 | void Kill(GVNFlagSet flags); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1804 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1805 | void Add(HValue* value, Zone* zone) { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1806 | present_flags_.Add(value->gvn_flags()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1807 | Insert(value, zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | HValue* Lookup(HValue* value) const; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1811 | |
| 1812 | HValueMap* Copy(Zone* zone) const { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1813 | return new(zone) HValueMap(zone, this); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1814 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1815 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1816 | bool IsEmpty() const { return count_ == 0; } |
| 1817 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1818 | private: |
| 1819 | // A linked list of HValue* values. Stored in arrays. |
| 1820 | struct HValueMapListElement { |
| 1821 | HValue* value; |
| 1822 | int next; // Index in the array of the next list element. |
| 1823 | }; |
| 1824 | static const int kNil = -1; // The end of a linked list |
| 1825 | |
| 1826 | // Must be a power of 2. |
| 1827 | static const int kInitialSize = 16; |
| 1828 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1829 | HValueMap(Zone* zone, const HValueMap* other); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1830 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1831 | void Resize(int new_size, Zone* zone); |
| 1832 | void ResizeLists(int new_size, Zone* zone); |
| 1833 | void Insert(HValue* value, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1834 | uint32_t Bound(uint32_t value) const { return value & (array_size_ - 1); } |
| 1835 | |
| 1836 | int array_size_; |
| 1837 | int lists_size_; |
| 1838 | int count_; // The number of values stored in the HValueMap. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1839 | GVNFlagSet present_flags_; // All flags that are in any value in the |
| 1840 | // HValueMap. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1841 | HValueMapListElement* array_; // Primary store - contains the first value |
| 1842 | // with a given hash. Colliding elements are stored in linked lists. |
| 1843 | HValueMapListElement* lists_; // The linked lists containing hash collisions. |
| 1844 | int free_list_head_; // Unused elements in lists_ are on the free list. |
| 1845 | }; |
| 1846 | |
| 1847 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1848 | class HSideEffectMap BASE_EMBEDDED { |
| 1849 | public: |
| 1850 | HSideEffectMap(); |
| 1851 | explicit HSideEffectMap(HSideEffectMap* other); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 1852 | HSideEffectMap& operator= (const HSideEffectMap& other); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1853 | |
| 1854 | void Kill(GVNFlagSet flags); |
| 1855 | |
| 1856 | void Store(GVNFlagSet flags, HInstruction* instr); |
| 1857 | |
| 1858 | bool IsEmpty() const { return count_ == 0; } |
| 1859 | |
| 1860 | inline HInstruction* operator[](int i) const { |
| 1861 | ASSERT(0 <= i); |
| 1862 | ASSERT(i < kNumberOfTrackedSideEffects); |
| 1863 | return data_[i]; |
| 1864 | } |
| 1865 | inline HInstruction* at(int i) const { return operator[](i); } |
| 1866 | |
| 1867 | private: |
| 1868 | int count_; |
| 1869 | HInstruction* data_[kNumberOfTrackedSideEffects]; |
| 1870 | }; |
| 1871 | |
| 1872 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1873 | class HStatistics: public Malloced { |
| 1874 | public: |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1875 | HStatistics() |
| 1876 | : timing_(5), |
| 1877 | names_(5), |
| 1878 | sizes_(5), |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1879 | create_graph_(0), |
| 1880 | optimize_graph_(0), |
| 1881 | generate_code_(0), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1882 | total_size_(0), |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1883 | full_code_gen_(0), |
| 1884 | source_size_(0) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1885 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1886 | void Initialize(CompilationInfo* info); |
| 1887 | void Print(); |
| 1888 | void SaveTiming(const char* name, int64_t ticks, unsigned size); |
| 1889 | |
| 1890 | void IncrementSubtotals(int64_t create_graph, |
| 1891 | int64_t optimize_graph, |
| 1892 | int64_t generate_code) { |
| 1893 | create_graph_ += create_graph; |
| 1894 | optimize_graph_ += optimize_graph; |
| 1895 | generate_code_ += generate_code; |
| 1896 | } |
| 1897 | |
| 1898 | private: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1899 | List<int64_t> timing_; |
| 1900 | List<const char*> names_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1901 | List<unsigned> sizes_; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1902 | int64_t create_graph_; |
| 1903 | int64_t optimize_graph_; |
| 1904 | int64_t generate_code_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1905 | unsigned total_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1906 | int64_t full_code_gen_; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1907 | double source_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1908 | }; |
| 1909 | |
| 1910 | |
| 1911 | class HPhase BASE_EMBEDDED { |
| 1912 | public: |
| 1913 | static const char* const kFullCodeGen; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1914 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1915 | HPhase(const char* name, Isolate* isolate); |
| 1916 | HPhase(const char* name, HGraph* graph); |
| 1917 | HPhase(const char* name, LChunk* chunk); |
| 1918 | HPhase(const char* name, LAllocator* allocator); |
| 1919 | ~HPhase(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1920 | |
| 1921 | private: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1922 | void Init(Isolate* isolate, |
| 1923 | const char* name, |
| 1924 | HGraph* graph, |
| 1925 | LChunk* chunk, |
| 1926 | LAllocator* allocator); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1927 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1928 | Isolate* isolate_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1929 | const char* name_; |
| 1930 | HGraph* graph_; |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 1931 | LChunk* chunk_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1932 | LAllocator* allocator_; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1933 | int64_t start_ticks_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1934 | unsigned start_allocation_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1935 | }; |
| 1936 | |
| 1937 | |
| 1938 | class HTracer: public Malloced { |
| 1939 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1940 | explicit HTracer(int isolate_id) |
| 1941 | : trace_(&string_allocator_), indent_(0) { |
| 1942 | OS::SNPrintF(filename_, |
| 1943 | "hydrogen-%d-%d.cfg", |
| 1944 | OS::GetCurrentProcessId(), |
| 1945 | isolate_id); |
| 1946 | WriteChars(filename_.start(), "", 0, false); |
| 1947 | } |
| 1948 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1949 | void TraceCompilation(CompilationInfo* info); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1950 | void TraceHydrogen(const char* name, HGraph* graph); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 1951 | void TraceLithium(const char* name, LChunk* chunk); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1952 | void TraceLiveRanges(const char* name, LAllocator* allocator); |
| 1953 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1954 | private: |
| 1955 | class Tag BASE_EMBEDDED { |
| 1956 | public: |
| 1957 | Tag(HTracer* tracer, const char* name) { |
| 1958 | name_ = name; |
| 1959 | tracer_ = tracer; |
| 1960 | tracer->PrintIndent(); |
| 1961 | tracer->trace_.Add("begin_%s\n", name); |
| 1962 | tracer->indent_++; |
| 1963 | } |
| 1964 | |
| 1965 | ~Tag() { |
| 1966 | tracer_->indent_--; |
| 1967 | tracer_->PrintIndent(); |
| 1968 | tracer_->trace_.Add("end_%s\n", name_); |
| 1969 | ASSERT(tracer_->indent_ >= 0); |
| 1970 | tracer_->FlushToFile(); |
| 1971 | } |
| 1972 | |
| 1973 | private: |
| 1974 | HTracer* tracer_; |
| 1975 | const char* name_; |
| 1976 | }; |
| 1977 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1978 | void TraceLiveRange(LiveRange* range, const char* type, Zone* zone); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 1979 | void Trace(const char* name, HGraph* graph, LChunk* chunk); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1980 | void FlushToFile(); |
| 1981 | |
| 1982 | void PrintEmptyProperty(const char* name) { |
| 1983 | PrintIndent(); |
| 1984 | trace_.Add("%s\n", name); |
| 1985 | } |
| 1986 | |
| 1987 | void PrintStringProperty(const char* name, const char* value) { |
| 1988 | PrintIndent(); |
| 1989 | trace_.Add("%s \"%s\"\n", name, value); |
| 1990 | } |
| 1991 | |
| 1992 | void PrintLongProperty(const char* name, int64_t value) { |
| 1993 | PrintIndent(); |
| 1994 | trace_.Add("%s %d000\n", name, static_cast<int>(value / 1000)); |
| 1995 | } |
| 1996 | |
| 1997 | void PrintBlockProperty(const char* name, int block_id) { |
| 1998 | PrintIndent(); |
| 1999 | trace_.Add("%s \"B%d\"\n", name, block_id); |
| 2000 | } |
| 2001 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2002 | void PrintIntProperty(const char* name, int value) { |
| 2003 | PrintIndent(); |
| 2004 | trace_.Add("%s %d\n", name, value); |
| 2005 | } |
| 2006 | |
| 2007 | void PrintIndent() { |
| 2008 | for (int i = 0; i < indent_; i++) { |
| 2009 | trace_.Add(" "); |
| 2010 | } |
| 2011 | } |
| 2012 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2013 | EmbeddedVector<char, 64> filename_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2014 | HeapStringAllocator string_allocator_; |
| 2015 | StringStream trace_; |
| 2016 | int indent_; |
| 2017 | }; |
| 2018 | |
| 2019 | |
| 2020 | } } // namespace v8::internal |
| 2021 | |
| 2022 | #endif // V8_HYDROGEN_H_ |