Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 10536145: Fuse comparisons that are used by branches together. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_INTERMEDIATE_LANGUAGE_H_ 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_ 6 #define VM_INTERMEDIATE_LANGUAGE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 M(CheckStackOverflow, CheckStackOverflowComp) \ 72 M(CheckStackOverflow, CheckStackOverflowComp) \
73 M(ToDouble, ToDoubleComp) \ 73 M(ToDouble, ToDoubleComp) \
74 74
75 75
76 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; 76 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName;
77 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) 77 FOR_EACH_COMPUTATION(FORWARD_DECLARATION)
78 #undef FORWARD_DECLARATION 78 #undef FORWARD_DECLARATION
79 79
80 // Forward declarations. 80 // Forward declarations.
81 class BufferFormatter; 81 class BufferFormatter;
82 class BranchInstr;
82 class Instruction; 83 class Instruction;
83 class Value; 84 class Value;
84 85
85 86
86 class Computation : public ZoneAllocated { 87 class Computation : public ZoneAllocated {
87 public: 88 public:
88 static const int kNoCid = -1; 89 static const int kNoCid = -1;
89 90
90 Computation() : cid_(-1), ic_data_(NULL), instr_(NULL), locs_(NULL) { 91 Computation() : cid_(-1), ic_data_(NULL), instr_(NULL), locs_(NULL) {
91 Isolate* isolate = Isolate::Current(); 92 Isolate* isolate = Isolate::Current();
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 const intptr_t try_index_; 492 const intptr_t try_index_;
492 const String& function_name_; 493 const String& function_name_;
493 ZoneGrowableArray<Value*>* const arguments_; 494 ZoneGrowableArray<Value*>* const arguments_;
494 const Array& argument_names_; 495 const Array& argument_names_;
495 const intptr_t checked_argument_count_; 496 const intptr_t checked_argument_count_;
496 497
497 DISALLOW_COPY_AND_ASSIGN(InstanceCallComp); 498 DISALLOW_COPY_AND_ASSIGN(InstanceCallComp);
498 }; 499 };
499 500
500 501
501 class StrictCompareComp : public TemplateComputation<2> { 502 class ComparisonComp : public TemplateComputation<2> {
503 public:
504 ComparisonComp(Value* left, Value* right)
505 : fused_with_branch_(NULL) {
506 ASSERT(left != NULL);
507 ASSERT(right != NULL);
508 inputs_[0] = left;
509 inputs_[1] = right;
510 }
511
512 void MarkFusedWithBranch(BranchInstr* branch) {
513 fused_with_branch_ = branch;
514 }
515
516 BranchInstr* fused_with_branch() const {
517 return fused_with_branch_;
518 }
srdjan 2012/06/13 15:29:35 Maybe also is_fused_with_branch => fused_with_bran
Vyacheslav Egorov (Google) 2012/06/13 16:23:43 Done.
519
520 Value* left() const { return inputs_[0]; }
521 Value* right() const { return inputs_[1]; }
522
523 private:
524 BranchInstr* fused_with_branch_;
525 };
526
527
528 class StrictCompareComp : public ComparisonComp {
502 public: 529 public:
503 StrictCompareComp(Token::Kind kind, Value* left, Value* right) 530 StrictCompareComp(Token::Kind kind, Value* left, Value* right)
504 : kind_(kind) { 531 : ComparisonComp(left, right), kind_(kind) {
505 ASSERT((kind_ == Token::kEQ_STRICT) || (kind_ == Token::kNE_STRICT)); 532 ASSERT((kind_ == Token::kEQ_STRICT) || (kind_ == Token::kNE_STRICT));
506 inputs_[0] = left;
507 inputs_[1] = right;
508 } 533 }
509 534
510 DECLARE_COMPUTATION(StrictCompare) 535 DECLARE_COMPUTATION(StrictCompare)
511 536
512 Token::Kind kind() const { return kind_; } 537 Token::Kind kind() const { return kind_; }
513 Value* left() const { return inputs_[0]; }
514 Value* right() const { return inputs_[1]; }
515 538
516 virtual void PrintOperandsTo(BufferFormatter* f) const; 539 virtual void PrintOperandsTo(BufferFormatter* f) const;
517 540
518 private: 541 private:
519 const Token::Kind kind_; 542 const Token::Kind kind_;
520 543
521 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); 544 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp);
522 }; 545 };
523 546
524 547
525 class EqualityCompareComp : public TemplateComputation<2> { 548 class EqualityCompareComp : public ComparisonComp {
526 public: 549 public:
527 EqualityCompareComp(intptr_t token_index, 550 EqualityCompareComp(intptr_t token_index,
528 intptr_t try_index, 551 intptr_t try_index,
529 Value* left, 552 Value* left,
530 Value* right) 553 Value* right)
531 : token_index_(token_index), 554 : ComparisonComp(left, right),
555 token_index_(token_index),
532 try_index_(try_index) { 556 try_index_(try_index) {
533 ASSERT(left != NULL);
534 ASSERT(right != NULL);
535 inputs_[0] = left;
536 inputs_[1] = right;
537 } 557 }
538 558
539 DECLARE_COMPUTATION(EqualityCompare) 559 DECLARE_COMPUTATION(EqualityCompare)
540 560
541 intptr_t token_index() const { return token_index_; } 561 intptr_t token_index() const { return token_index_; }
542 intptr_t try_index() const { return try_index_; } 562 intptr_t try_index() const { return try_index_; }
543 Value* left() const { return inputs_[0]; }
544 Value* right() const { return inputs_[1]; }
545 563
546 virtual void PrintOperandsTo(BufferFormatter* f) const; 564 virtual void PrintOperandsTo(BufferFormatter* f) const;
547 565
548 private: 566 private:
549 const intptr_t token_index_; 567 const intptr_t token_index_;
550 const intptr_t try_index_; 568 const intptr_t try_index_;
551 569
552 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp); 570 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp);
553 }; 571 };
554 572
555 573
556 class RelationalOpComp : public TemplateComputation<2> { 574 class RelationalOpComp : public ComparisonComp {
557 public: 575 public:
558 RelationalOpComp(intptr_t token_index, 576 RelationalOpComp(intptr_t token_index,
559 intptr_t try_index, 577 intptr_t try_index,
560 Token::Kind kind, 578 Token::Kind kind,
561 Value* left, 579 Value* left,
562 Value* right) 580 Value* right)
563 : token_index_(token_index), 581 : ComparisonComp(left, right),
582 token_index_(token_index),
564 try_index_(try_index), 583 try_index_(try_index),
565 kind_(kind), 584 kind_(kind),
566 operands_class_id_(kObject) { 585 operands_class_id_(kObject) {
567 ASSERT(Token::IsRelationalOperator(kind)); 586 ASSERT(Token::IsRelationalOperator(kind));
568 ASSERT(left != NULL);
569 ASSERT(right != NULL);
570 inputs_[0] = left;
571 inputs_[1] = right;
572 } 587 }
573 588
574 DECLARE_COMPUTATION(RelationalOp) 589 DECLARE_COMPUTATION(RelationalOp)
575 590
576 intptr_t token_index() const { return token_index_; } 591 intptr_t token_index() const { return token_index_; }
577 intptr_t try_index() const { return try_index_; } 592 intptr_t try_index() const { return try_index_; }
578 Token::Kind kind() const { return kind_; } 593 Token::Kind kind() const { return kind_; }
579 Value* left() const { return inputs_[0]; }
580 Value* right() const { return inputs_[1]; }
581 594
582 // TODO(srdjan): instead of class-id pass an enum that can differentiate 595 // TODO(srdjan): instead of class-id pass an enum that can differentiate
583 // between boxed and unboxed doubles and integers. 596 // between boxed and unboxed doubles and integers.
584 void set_operands_class_id(intptr_t value) { 597 void set_operands_class_id(intptr_t value) {
585 operands_class_id_ = value; 598 operands_class_id_ = value;
586 } 599 }
600
587 intptr_t operands_class_id() const { return operands_class_id_; } 601 intptr_t operands_class_id() const { return operands_class_id_; }
588 602
589 virtual void PrintOperandsTo(BufferFormatter* f) const; 603 virtual void PrintOperandsTo(BufferFormatter* f) const;
590 604
591 private: 605 private:
592 const intptr_t token_index_; 606 const intptr_t token_index_;
593 const intptr_t try_index_; 607 const intptr_t try_index_;
594 const Token::Kind kind_; 608 const Token::Kind kind_;
595 intptr_t operands_class_id_; // class id of both operands. 609 intptr_t operands_class_id_; // class id of both operands.
596 610
(...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr); 2159 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr);
2146 }; 2160 };
2147 2161
2148 2162
2149 class BranchInstr : public InstructionWithInputs { 2163 class BranchInstr : public InstructionWithInputs {
2150 public: 2164 public:
2151 explicit BranchInstr(Value* value) 2165 explicit BranchInstr(Value* value)
2152 : InstructionWithInputs(), 2166 : InstructionWithInputs(),
2153 value_(value), 2167 value_(value),
2154 true_successor_(NULL), 2168 true_successor_(NULL),
2155 false_successor_(NULL) { } 2169 false_successor_(NULL),
2170 fused_with_comparison_(false) { }
2156 2171
2157 DECLARE_INSTRUCTION(Branch) 2172 DECLARE_INSTRUCTION(Branch)
2158 2173
2159 Value* value() const { return value_; } 2174 Value* value() const { return value_; }
2160 TargetEntryInstr* true_successor() const { return true_successor_; } 2175 TargetEntryInstr* true_successor() const { return true_successor_; }
2161 TargetEntryInstr* false_successor() const { return false_successor_; } 2176 TargetEntryInstr* false_successor() const { return false_successor_; }
2162 2177
2163 TargetEntryInstr** true_successor_address() { return &true_successor_; } 2178 TargetEntryInstr** true_successor_address() { return &true_successor_; }
2164 TargetEntryInstr** false_successor_address() { return &false_successor_; } 2179 TargetEntryInstr** false_successor_address() { return &false_successor_; }
2165 2180
2166 virtual Instruction* StraightLineSuccessor() const { return NULL; } 2181 virtual Instruction* StraightLineSuccessor() const { return NULL; }
2167 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } 2182 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); }
2168 2183
2169 virtual intptr_t SuccessorCount() const; 2184 virtual intptr_t SuccessorCount() const;
2170 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; 2185 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const;
2171 2186
2172 virtual void DiscoverBlocks( 2187 virtual void DiscoverBlocks(
2173 BlockEntryInstr* current_block, 2188 BlockEntryInstr* current_block,
2174 GrowableArray<BlockEntryInstr*>* preorder, 2189 GrowableArray<BlockEntryInstr*>* preorder,
2175 GrowableArray<BlockEntryInstr*>* postorder, 2190 GrowableArray<BlockEntryInstr*>* postorder,
2176 GrowableArray<intptr_t>* parent, 2191 GrowableArray<intptr_t>* parent,
2177 GrowableArray<BitVector*>* assigned_vars, 2192 GrowableArray<BitVector*>* assigned_vars,
2178 intptr_t variable_count); 2193 intptr_t variable_count);
2179 2194
2180 virtual LocationSummary* MakeLocationSummary() const; 2195 virtual LocationSummary* MakeLocationSummary() const;
2181 2196
2182 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 2197 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
2183 2198
2199 void EmitBranchOnCondition(FlowGraphCompiler* compiler,
2200 Condition true_condition);
2201
2202 void MarkFusedWithComparison() {
2203 fused_with_comparison_ = true;
2204 }
2205
2206 bool is_fused_with_comparison() const { return fused_with_comparison_; }
2207
2184 private: 2208 private:
2185 Value* value_; 2209 Value* value_;
2186 TargetEntryInstr* true_successor_; 2210 TargetEntryInstr* true_successor_;
2187 TargetEntryInstr* false_successor_; 2211 TargetEntryInstr* false_successor_;
2212 bool fused_with_comparison_;
srdjan 2012/06/13 15:29:35 rename to is_fused_with_comparison_
Vyacheslav Egorov (Google) 2012/06/13 16:23:43 Done.
2188 2213
2189 DISALLOW_COPY_AND_ASSIGN(BranchInstr); 2214 DISALLOW_COPY_AND_ASSIGN(BranchInstr);
2190 }; 2215 };
2191 2216
2192 #undef DECLARE_INSTRUCTION 2217 #undef DECLARE_INSTRUCTION
2193 2218
2194 2219
2195 // Visitor base class to visit each instruction and computation in a flow 2220 // Visitor base class to visit each instruction and computation in a flow
2196 // graph as defined by a reversed list of basic blocks. 2221 // graph as defined by a reversed list of basic blocks.
2197 class FlowGraphVisitor : public ValueObject { 2222 class FlowGraphVisitor : public ValueObject {
(...skipping 24 matching lines...) Expand all
2222 const GrowableArray<BlockEntryInstr*>& block_order_; 2247 const GrowableArray<BlockEntryInstr*>& block_order_;
2223 2248
2224 private: 2249 private:
2225 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2250 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2226 }; 2251 };
2227 2252
2228 2253
2229 } // namespace dart 2254 } // namespace dart
2230 2255
2231 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2256 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698