| 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 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 class CSEInstructionMap; | 13 class CSEInstructionMap; |
| 14 template <typename T> class GrowableArray; | 14 template <typename T> class GrowableArray; |
| 15 class ParsedFunction; | 15 class ParsedFunction; |
| 16 | 16 |
| 17 class FlowGraphOptimizer : public FlowGraphVisitor { | 17 class FlowGraphOptimizer : public FlowGraphVisitor { |
| 18 public: | 18 public: |
| 19 explicit FlowGraphOptimizer(FlowGraph* flow_graph) | 19 explicit FlowGraphOptimizer(FlowGraph* flow_graph) |
| 20 : FlowGraphVisitor(flow_graph->reverse_postorder()), | 20 : FlowGraphVisitor(flow_graph->reverse_postorder()), |
| 21 flow_graph_(flow_graph) { } | 21 flow_graph_(flow_graph) { } |
| 22 virtual ~FlowGraphOptimizer() {} | 22 virtual ~FlowGraphOptimizer() {} |
| 23 | 23 |
| 24 FlowGraph* flow_graph() const { return flow_graph_; } | 24 FlowGraph* flow_graph() const { return flow_graph_; } |
| 25 | 25 |
| 26 // Add ICData to InstanceCalls, so that optimizations can be run on them. |
| 27 // TODO(srdjan): StaticCals as well? |
| 28 void PopulateWithICData(); |
| 29 |
| 26 // Use ICData to optimize, replace or eliminate instructions. | 30 // Use ICData to optimize, replace or eliminate instructions. |
| 27 void ApplyICData(); | 31 void ApplyICData(); |
| 28 | 32 |
| 29 // Use propagated class ids to optimize, replace or eliminate instructions. | 33 // Use propagated class ids to optimize, replace or eliminate instructions. |
| 30 void ApplyClassIds(); | 34 void ApplyClassIds(); |
| 31 | 35 |
| 32 // Optimize (a << b) & c pattern: if c is a positive Smi or zero, then the | 36 // Optimize (a << b) & c pattern: if c is a positive Smi or zero, then the |
| 33 // shift can be a truncating Smi shift-left and result is always Smi. | 37 // shift can be a truncating Smi shift-left and result is always Smi. |
| 34 // Merge instructions (only per basic-block). | 38 // Merge instructions (only per basic-block). |
| 35 void TryOptimizePatterns(); | 39 void TryOptimizePatterns(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 Definition* index, | 105 Definition* index, |
| 102 Instruction** cursor); | 106 Instruction** cursor); |
| 103 | 107 |
| 104 | 108 |
| 105 bool TryReplaceWithBinaryOp(InstanceCallInstr* call, Token::Kind op_kind); | 109 bool TryReplaceWithBinaryOp(InstanceCallInstr* call, Token::Kind op_kind); |
| 106 bool TryReplaceWithUnaryOp(InstanceCallInstr* call, Token::Kind op_kind); | 110 bool TryReplaceWithUnaryOp(InstanceCallInstr* call, Token::Kind op_kind); |
| 107 | 111 |
| 108 bool TryReplaceWithEqualityOp(InstanceCallInstr* call, Token::Kind op_kind); | 112 bool TryReplaceWithEqualityOp(InstanceCallInstr* call, Token::Kind op_kind); |
| 109 bool TryReplaceWithRelationalOp(InstanceCallInstr* call, Token::Kind op_kind); | 113 bool TryReplaceWithRelationalOp(InstanceCallInstr* call, Token::Kind op_kind); |
| 110 | 114 |
| 111 bool TryInlineInstanceGetter(InstanceCallInstr* call); | 115 bool TryInlineInstanceGetter(InstanceCallInstr* call, |
| 116 bool allow_check = true); |
| 112 bool TryInlineInstanceSetter(InstanceCallInstr* call, | 117 bool TryInlineInstanceSetter(InstanceCallInstr* call, |
| 113 const ICData& unary_ic_data); | 118 const ICData& unary_ic_data); |
| 114 | 119 |
| 115 bool TryInlineInstanceMethod(InstanceCallInstr* call); | 120 bool TryInlineInstanceMethod(InstanceCallInstr* call); |
| 116 bool TryInlineFloat32x4Constructor(StaticCallInstr* call, | 121 bool TryInlineFloat32x4Constructor(StaticCallInstr* call, |
| 117 MethodRecognizer::Kind recognized_kind); | 122 MethodRecognizer::Kind recognized_kind); |
| 118 bool TryInlineFloat64x2Constructor(StaticCallInstr* call, | 123 bool TryInlineFloat64x2Constructor(StaticCallInstr* call, |
| 119 MethodRecognizer::Kind recognized_kind); | 124 MethodRecognizer::Kind recognized_kind); |
| 120 bool TryInlineInt32x4Constructor(StaticCallInstr* call, | 125 bool TryInlineInt32x4Constructor(StaticCallInstr* call, |
| 121 MethodRecognizer::Kind recognized_kind); | 126 MethodRecognizer::Kind recognized_kind); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 bool InlineFloat64x2Getter(InstanceCallInstr* call, | 231 bool InlineFloat64x2Getter(InstanceCallInstr* call, |
| 227 MethodRecognizer::Kind getter); | 232 MethodRecognizer::Kind getter); |
| 228 bool InlineInt32x4Getter(InstanceCallInstr* call, | 233 bool InlineInt32x4Getter(InstanceCallInstr* call, |
| 229 MethodRecognizer::Kind getter); | 234 MethodRecognizer::Kind getter); |
| 230 bool InlineFloat32x4BinaryOp(InstanceCallInstr* call, | 235 bool InlineFloat32x4BinaryOp(InstanceCallInstr* call, |
| 231 Token::Kind op_kind); | 236 Token::Kind op_kind); |
| 232 bool InlineInt32x4BinaryOp(InstanceCallInstr* call, | 237 bool InlineInt32x4BinaryOp(InstanceCallInstr* call, |
| 233 Token::Kind op_kind); | 238 Token::Kind op_kind); |
| 234 bool InlineFloat64x2BinaryOp(InstanceCallInstr* call, | 239 bool InlineFloat64x2BinaryOp(InstanceCallInstr* call, |
| 235 Token::Kind op_kind); | 240 Token::Kind op_kind); |
| 236 void InlineImplicitInstanceGetter(InstanceCallInstr* call); | 241 bool InlineImplicitInstanceGetter(InstanceCallInstr* call, bool allow_check); |
| 237 | 242 |
| 238 RawBool* InstanceOfAsBool(const ICData& ic_data, | 243 RawBool* InstanceOfAsBool(const ICData& ic_data, |
| 239 const AbstractType& type, | 244 const AbstractType& type, |
| 240 ZoneGrowableArray<intptr_t>* results) const; | 245 ZoneGrowableArray<intptr_t>* results) const; |
| 241 | 246 |
| 242 void ReplaceWithMathCFunction(InstanceCallInstr* call, | 247 void ReplaceWithMathCFunction(InstanceCallInstr* call, |
| 243 MethodRecognizer::Kind recognized_kind); | 248 MethodRecognizer::Kind recognized_kind); |
| 244 | 249 |
| 245 void OptimizeLeftShiftBitAndSmiOp(Definition* bit_and_instr, | 250 void OptimizeLeftShiftBitAndSmiOp(Definition* bit_and_instr, |
| 246 Definition* left_instr, | 251 Definition* left_instr, |
| 247 Definition* right_instr); | 252 Definition* right_instr); |
| 248 void TryMergeTruncDivMod(GrowableArray<BinarySmiOpInstr*>* merge_candidates); | 253 void TryMergeTruncDivMod(GrowableArray<BinarySmiOpInstr*>* merge_candidates); |
| 249 void TryMergeMathUnary(GrowableArray<MathUnaryInstr*>* merge_candidates); | 254 void TryMergeMathUnary(GrowableArray<MathUnaryInstr*>* merge_candidates); |
| 250 | 255 |
| 251 void AppendLoadIndexedForMerged(Definition* instr, intptr_t ix, intptr_t cid); | 256 void AppendLoadIndexedForMerged(Definition* instr, intptr_t ix, intptr_t cid); |
| 252 void AppendExtractNthOutputForMerged(Definition* instr, intptr_t ix, | 257 void AppendExtractNthOutputForMerged(Definition* instr, intptr_t ix, |
| 253 Representation rep, intptr_t cid); | 258 Representation rep, intptr_t cid); |
| 254 bool TryStringLengthOneEquality(InstanceCallInstr* call, Token::Kind op_kind); | 259 bool TryStringLengthOneEquality(InstanceCallInstr* call, Token::Kind op_kind); |
| 255 | 260 |
| 256 Thread* thread() const { return flow_graph_->thread(); } | 261 Thread* thread() const { return flow_graph_->thread(); } |
| 257 Isolate* isolate() const { return flow_graph_->isolate(); } | 262 Isolate* isolate() const { return flow_graph_->isolate(); } |
| 258 Zone* zone() const { return flow_graph_->zone(); } | 263 Zone* zone() const { return flow_graph_->zone(); } |
| 259 | 264 |
| 265 const Function& function() const { return flow_graph_->function(); } |
| 266 |
| 260 FlowGraph* flow_graph_; | 267 FlowGraph* flow_graph_; |
| 261 | 268 |
| 262 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); | 269 DISALLOW_COPY_AND_ASSIGN(FlowGraphOptimizer); |
| 263 }; | 270 }; |
| 264 | 271 |
| 265 | 272 |
| 266 // Loop invariant code motion. | 273 // Loop invariant code motion. |
| 267 class LICM : public ValueObject { | 274 class LICM : public ValueObject { |
| 268 public: | 275 public: |
| 269 explicit LICM(FlowGraph* flow_graph); | 276 explicit LICM(FlowGraph* flow_graph); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // Optimize spill stores inside try-blocks by identifying values that always | 434 // Optimize spill stores inside try-blocks by identifying values that always |
| 428 // contain a single known constant at catch block entry. | 435 // contain a single known constant at catch block entry. |
| 429 class TryCatchAnalyzer : public AllStatic { | 436 class TryCatchAnalyzer : public AllStatic { |
| 430 public: | 437 public: |
| 431 static void Optimize(FlowGraph* flow_graph); | 438 static void Optimize(FlowGraph* flow_graph); |
| 432 }; | 439 }; |
| 433 | 440 |
| 434 } // namespace dart | 441 } // namespace dart |
| 435 | 442 |
| 436 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ | 443 #endif // VM_FLOW_GRAPH_OPTIMIZER_H_ |
| OLD | NEW |