| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_FLOW_GRAPH_OPTIMIZER_H_ | 5 #ifndef VM_FLOW_GRAPH_OPTIMIZER_H_ |
| 6 #define VM_FLOW_GRAPH_OPTIMIZER_H_ | 6 #define VM_FLOW_GRAPH_OPTIMIZER_H_ |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 #include "vm/flow_graph.h" | 9 #include "vm/flow_graph.h" |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 void InsertBefore(Instruction* next, | 64 void InsertBefore(Instruction* next, |
| 65 Instruction* instr, | 65 Instruction* instr, |
| 66 Environment* env, | 66 Environment* env, |
| 67 FlowGraph::UseKind use_kind) { | 67 FlowGraph::UseKind use_kind) { |
| 68 flow_graph_->InsertBefore(next, instr, env, use_kind); | 68 flow_graph_->InsertBefore(next, instr, env, use_kind); |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 // Attempt to build ICData for call using propagated class-ids. | 72 // Attempt to build ICData for call using propagated class-ids. |
| 73 bool TryCreateICData(InstanceCallInstr* call); | 73 bool TryCreateICData(InstanceCallInstr* call); |
| 74 const ICData& TrySpecializeICData(const ICData& ic_data, intptr_t cid); |
| 74 | 75 |
| 75 void SpecializePolymorphicInstanceCall(PolymorphicInstanceCallInstr* call); | 76 void SpecializePolymorphicInstanceCall(PolymorphicInstanceCallInstr* call); |
| 76 | 77 |
| 77 bool TryReplaceWithStoreIndexed(InstanceCallInstr* call); | 78 bool TryReplaceWithStoreIndexed(InstanceCallInstr* call); |
| 78 bool InlineSetIndexed(MethodRecognizer::Kind kind, | 79 bool InlineSetIndexed(MethodRecognizer::Kind kind, |
| 79 const Function& target, | 80 const Function& target, |
| 80 Instruction* call, | 81 Instruction* call, |
| 81 Definition* receiver, | 82 Definition* receiver, |
| 82 intptr_t token_pos, | 83 intptr_t token_pos, |
| 83 const ICData* ic_data, | 84 const ICData* ic_data, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 MethodRecognizer::Kind recognized_kind); | 120 MethodRecognizer::Kind recognized_kind); |
| 120 bool TryInlineFloat64x2Method(InstanceCallInstr* call, | 121 bool TryInlineFloat64x2Method(InstanceCallInstr* call, |
| 121 MethodRecognizer::Kind recognized_kind); | 122 MethodRecognizer::Kind recognized_kind); |
| 122 bool TryInlineInt32x4Method(InstanceCallInstr* call, | 123 bool TryInlineInt32x4Method(InstanceCallInstr* call, |
| 123 MethodRecognizer::Kind recognized_kind); | 124 MethodRecognizer::Kind recognized_kind); |
| 124 void ReplaceWithInstanceOf(InstanceCallInstr* instr); | 125 void ReplaceWithInstanceOf(InstanceCallInstr* instr); |
| 125 void ReplaceWithTypeCast(InstanceCallInstr* instr); | 126 void ReplaceWithTypeCast(InstanceCallInstr* instr); |
| 126 | 127 |
| 127 bool TryReplaceInstanceCallWithInline(InstanceCallInstr* call); | 128 bool TryReplaceInstanceCallWithInline(InstanceCallInstr* call); |
| 128 | 129 |
| 130 LoadFieldInstr* BuildLoadStringLength(Definition* str); |
| 131 |
| 129 Definition* PrepareInlineStringIndexOp(Instruction* call, | 132 Definition* PrepareInlineStringIndexOp(Instruction* call, |
| 130 intptr_t cid, | 133 intptr_t cid, |
| 131 Definition* str, | 134 Definition* str, |
| 132 Definition* index, | 135 Definition* index, |
| 133 Instruction* cursor); | 136 Instruction* cursor); |
| 134 | 137 |
| 135 bool InlineStringCodeUnitAt(Instruction* call, | 138 bool InlineStringCodeUnitAt(Instruction* call, |
| 136 intptr_t cid, | 139 intptr_t cid, |
| 137 TargetEntryInstr** entry, | 140 TargetEntryInstr** entry, |
| 138 Definition** last); | 141 Definition** last); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 Definition* left_instr, | 239 Definition* left_instr, |
| 237 Definition* right_instr); | 240 Definition* right_instr); |
| 238 void TryMergeTruncDivMod(GrowableArray<BinarySmiOpInstr*>* merge_candidates); | 241 void TryMergeTruncDivMod(GrowableArray<BinarySmiOpInstr*>* merge_candidates); |
| 239 void TryMergeMathUnary(GrowableArray<MathUnaryInstr*>* merge_candidates); | 242 void TryMergeMathUnary(GrowableArray<MathUnaryInstr*>* merge_candidates); |
| 240 | 243 |
| 241 void AppendLoadIndexedForMerged(Definition* instr, intptr_t ix, intptr_t cid); | 244 void AppendLoadIndexedForMerged(Definition* instr, intptr_t ix, intptr_t cid); |
| 242 void AppendExtractNthOutputForMerged(Definition* instr, intptr_t ix, | 245 void AppendExtractNthOutputForMerged(Definition* instr, intptr_t ix, |
| 243 Representation rep, intptr_t cid); | 246 Representation rep, intptr_t cid); |
| 244 bool TryStringLengthOneEquality(InstanceCallInstr* call, Token::Kind op_kind); | 247 bool TryStringLengthOneEquality(InstanceCallInstr* call, Token::Kind op_kind); |
| 245 | 248 |
| 249 Isolate* isolate() const { return flow_graph_->isolate(); } |
| 250 |
| 246 FlowGraph* flow_graph_; | 251 FlowGraph* flow_graph_; |
| 247 | 252 |
| 248 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); | 253 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); |
| 249 }; | 254 }; |
| 250 | 255 |
| 251 | 256 |
| 252 // Loop invariant code motion. | 257 // Loop invariant code motion. |
| 253 class LICM : public ValueObject { | 258 class LICM : public ValueObject { |
| 254 public: | 259 public: |
| 255 explicit LICM(FlowGraph* flow_graph); | 260 explicit LICM(FlowGraph* flow_graph); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 Token::Kind op_kind, | 356 Token::Kind op_kind, |
| 352 const Value& left, | 357 const Value& left, |
| 353 const Value& right); | 358 const Value& right); |
| 354 | 359 |
| 355 virtual void VisitBlocks() { UNREACHABLE(); } | 360 virtual void VisitBlocks() { UNREACHABLE(); } |
| 356 | 361 |
| 357 #define DECLARE_VISIT(type) virtual void Visit##type(type##Instr* instr); | 362 #define DECLARE_VISIT(type) virtual void Visit##type(type##Instr* instr); |
| 358 FOR_EACH_INSTRUCTION(DECLARE_VISIT) | 363 FOR_EACH_INSTRUCTION(DECLARE_VISIT) |
| 359 #undef DECLARE_VISIT | 364 #undef DECLARE_VISIT |
| 360 | 365 |
| 366 Isolate* isolate() const { return graph_->isolate(); } |
| 367 |
| 361 FlowGraph* graph_; | 368 FlowGraph* graph_; |
| 362 | 369 |
| 363 // Sentinels for unknown constant and non-constant values. | 370 // Sentinels for unknown constant and non-constant values. |
| 364 const Object& unknown_; | 371 const Object& unknown_; |
| 365 const Object& non_constant_; | 372 const Object& non_constant_; |
| 366 | 373 |
| 367 // Analysis results. For each block, a reachability bit. Indexed by | 374 // Analysis results. For each block, a reachability bit. Indexed by |
| 368 // preorder number. | 375 // preorder number. |
| 369 BitVector* reachable_; | 376 BitVector* reachable_; |
| 370 | 377 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 382 // Rewrite branches to eliminate materialization of boolean values after | 389 // Rewrite branches to eliminate materialization of boolean values after |
| 383 // inlining, and to expose other optimizations (e.g., constant folding of | 390 // inlining, and to expose other optimizations (e.g., constant folding of |
| 384 // branches, unreachable code elimination). | 391 // branches, unreachable code elimination). |
| 385 class BranchSimplifier : public AllStatic { | 392 class BranchSimplifier : public AllStatic { |
| 386 public: | 393 public: |
| 387 static void Simplify(FlowGraph* flow_graph); | 394 static void Simplify(FlowGraph* flow_graph); |
| 388 | 395 |
| 389 // Replace a target entry instruction with a join entry instruction. Does | 396 // Replace a target entry instruction with a join entry instruction. Does |
| 390 // not update the original target's predecessors to point to the new block | 397 // not update the original target's predecessors to point to the new block |
| 391 // and does not replace the target in already computed block order lists. | 398 // and does not replace the target in already computed block order lists. |
| 392 static JoinEntryInstr* ToJoinEntry(TargetEntryInstr* target); | 399 static JoinEntryInstr* ToJoinEntry(Isolate* isolate, |
| 400 TargetEntryInstr* target); |
| 393 | 401 |
| 394 private: | 402 private: |
| 395 // Match an instance of the pattern to rewrite. See the implementation | 403 // Match an instance of the pattern to rewrite. See the implementation |
| 396 // for the patterns that are handled by this pass. | 404 // for the patterns that are handled by this pass. |
| 397 static bool Match(JoinEntryInstr* block); | 405 static bool Match(JoinEntryInstr* block); |
| 398 | 406 |
| 399 // Duplicate a branch while replacing its comparison's left and right | 407 // Duplicate a branch while replacing its comparison's left and right |
| 400 // inputs. | 408 // inputs. |
| 401 static BranchInstr* CloneBranch(BranchInstr* branch, | 409 static BranchInstr* CloneBranch(Isolate* isolate, |
| 410 BranchInstr* branch, |
| 402 Value* new_left, | 411 Value* new_left, |
| 403 Value* new_right); | 412 Value* new_right); |
| 404 }; | 413 }; |
| 405 | 414 |
| 406 | 415 |
| 407 // Rewrite diamond control flow patterns that materialize values to use more | 416 // Rewrite diamond control flow patterns that materialize values to use more |
| 408 // efficient branchless code patterns if such are supported on the current | 417 // efficient branchless code patterns if such are supported on the current |
| 409 // platform. | 418 // platform. |
| 410 class IfConverter : public AllStatic { | 419 class IfConverter : public AllStatic { |
| 411 public: | 420 public: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 425 | 434 |
| 426 private: | 435 private: |
| 427 void InsertMaterializations(AllocateObjectInstr* alloc); | 436 void InsertMaterializations(AllocateObjectInstr* alloc); |
| 428 | 437 |
| 429 void CreateMaterializationAt( | 438 void CreateMaterializationAt( |
| 430 Instruction* exit, | 439 Instruction* exit, |
| 431 AllocateObjectInstr* alloc, | 440 AllocateObjectInstr* alloc, |
| 432 const Class& cls, | 441 const Class& cls, |
| 433 const ZoneGrowableArray<const Object*>& fields); | 442 const ZoneGrowableArray<const Object*>& fields); |
| 434 | 443 |
| 444 Isolate* isolate() const { return flow_graph_->isolate(); } |
| 445 |
| 435 FlowGraph* flow_graph_; | 446 FlowGraph* flow_graph_; |
| 436 | 447 |
| 437 GrowableArray<MaterializeObjectInstr*> materializations_; | 448 GrowableArray<MaterializeObjectInstr*> materializations_; |
| 438 }; | 449 }; |
| 439 | 450 |
| 440 | 451 |
| 441 // Optimize spill stores inside try-blocks by identifying values that always | 452 // Optimize spill stores inside try-blocks by identifying values that always |
| 442 // contain a single known constant at catch block entry. | 453 // contain a single known constant at catch block entry. |
| 443 class TryCatchAnalyzer : public AllStatic { | 454 class TryCatchAnalyzer : public AllStatic { |
| 444 public: | 455 public: |
| 445 static void Optimize(FlowGraph* flow_graph); | 456 static void Optimize(FlowGraph* flow_graph); |
| 446 }; | 457 }; |
| 447 | 458 |
| 448 } // namespace dart | 459 } // namespace dart |
| 449 | 460 |
| 450 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ | 461 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ |
| OLD | NEW |