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

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 539153002: Port and integrate the irregexp engine from V8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated to current version Created 6 years, 2 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "vm/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/cpu.h" 9 #include "vm/cpu.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 if (!ShouldInlineSimd()) { 1624 if (!ShouldInlineSimd()) {
1625 return false; 1625 return false;
1626 } 1626 }
1627 return InlineByteArrayViewStore(target, call, receiver, receiver_cid, 1627 return InlineByteArrayViewStore(target, call, receiver, receiver_cid,
1628 kTypedDataInt32x4ArrayCid, 1628 kTypedDataInt32x4ArrayCid,
1629 ic_data, entry, last); 1629 ic_data, entry, last);
1630 case MethodRecognizer::kStringBaseCodeUnitAt: 1630 case MethodRecognizer::kStringBaseCodeUnitAt:
1631 return InlineStringCodeUnitAt(call, receiver_cid, entry, last); 1631 return InlineStringCodeUnitAt(call, receiver_cid, entry, last);
1632 case MethodRecognizer::kStringBaseCharAt: 1632 case MethodRecognizer::kStringBaseCharAt:
1633 return InlineStringBaseCharAt(call, receiver_cid, entry, last); 1633 return InlineStringBaseCharAt(call, receiver_cid, entry, last);
1634 case MethodRecognizer::kOneByteString_oneCodeUnitAt:
1635 case MethodRecognizer::kTwoByteString_oneCodeUnitAt:
1636 return InlineStringCodeUnitsAt(call, receiver_cid, 1, entry, last);
1637 case MethodRecognizer::kOneByteString_twoCodeUnitsAt:
1638 case MethodRecognizer::kTwoByteString_twoCodeUnitsAt:
1639 return InlineStringCodeUnitsAt(call, receiver_cid, 2, entry, last);
1640 case MethodRecognizer::kOneByteString_fourCodeUnitsAt:
1641 return InlineStringCodeUnitsAt(call, receiver_cid, 4, entry, last);
1634 case MethodRecognizer::kDoubleAdd: 1642 case MethodRecognizer::kDoubleAdd:
1635 return InlineDoubleOp(Token::kADD, call, entry, last); 1643 return InlineDoubleOp(Token::kADD, call, entry, last);
1636 case MethodRecognizer::kDoubleSub: 1644 case MethodRecognizer::kDoubleSub:
1637 return InlineDoubleOp(Token::kSUB, call, entry, last); 1645 return InlineDoubleOp(Token::kSUB, call, entry, last);
1638 case MethodRecognizer::kDoubleMul: 1646 case MethodRecognizer::kDoubleMul:
1639 return InlineDoubleOp(Token::kMUL, call, entry, last); 1647 return InlineDoubleOp(Token::kMUL, call, entry, last);
1640 case MethodRecognizer::kDoubleDiv: 1648 case MethodRecognizer::kDoubleDiv:
1641 return InlineDoubleOp(Token::kDIV, call, entry, last); 1649 return InlineDoubleOp(Token::kDIV, call, entry, last);
1642 default: 1650 default:
1643 return false; 1651 return false;
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2833 *entry = new(I) TargetEntryInstr(flow_graph()->allocate_block_id(), 2841 *entry = new(I) TargetEntryInstr(flow_graph()->allocate_block_id(),
2834 call->GetBlock()->try_index()); 2842 call->GetBlock()->try_index());
2835 (*entry)->InheritDeoptTarget(I, call); 2843 (*entry)->InheritDeoptTarget(I, call);
2836 2844
2837 *last = PrepareInlineStringIndexOp(call, cid, str, index, *entry); 2845 *last = PrepareInlineStringIndexOp(call, cid, str, index, *entry);
2838 2846
2839 return true; 2847 return true;
2840 } 2848 }
2841 2849
2842 2850
2851 Definition* FlowGraphOptimizer::PrepareInlineStringIndexOpUnchecked(
2852 Instruction* call,
2853 intptr_t cid,
2854 intptr_t count,
2855 Definition* str,
2856 Definition* index,
2857 Instruction* cursor) {
2858 LoadCodeUnitsInstr* load = new(I) LoadCodeUnitsInstr(
2859 new(I) Value(str),
2860 new(I) Value(index),
2861 Instance::ElementSizeFor(cid),
2862 count,
2863 cid,
2864 Isolate::kNoDeoptId,
2865 call->token_pos());
2866
2867 cursor = flow_graph()->AppendTo(cursor,
2868 load,
2869 NULL,
2870 FlowGraph::kValue);
2871 ASSERT(cursor == load);
2872 return load;
2873 }
2874
2875
2876 bool FlowGraphOptimizer::InlineStringCodeUnitsAt(
2877 Instruction* call,
2878 intptr_t cid,
2879 intptr_t count,
2880 TargetEntryInstr** entry,
2881 Definition** last) {
2882 // TODO(johnmccutchan): Handle external strings in PrepareInlineStringIndexOp.
2883 if (RawObject::IsExternalStringClassId(cid)) {
2884 return false;
2885 }
2886
2887 Definition* str = call->ArgumentAt(0);
2888 Definition* index = call->ArgumentAt(1);
2889
2890 *entry = new(I) TargetEntryInstr(flow_graph()->allocate_block_id(),
2891 call->GetBlock()->try_index());
2892 (*entry)->InheritDeoptTarget(I, call);
2893
2894 *last = PrepareInlineStringIndexOpUnchecked(
2895 call, cid, count, str, index, *entry);
2896
2897 return true;
2898 }
2899
2900
2843 bool FlowGraphOptimizer::InlineStringBaseCharAt( 2901 bool FlowGraphOptimizer::InlineStringBaseCharAt(
2844 Instruction* call, 2902 Instruction* call,
2845 intptr_t cid, 2903 intptr_t cid,
2846 TargetEntryInstr** entry, 2904 TargetEntryInstr** entry,
2847 Definition** last) { 2905 Definition** last) {
2848 // TODO(johnmccutchan): Handle external strings in PrepareInlineStringIndexOp. 2906 // TODO(johnmccutchan): Handle external strings in PrepareInlineStringIndexOp.
2849 if (RawObject::IsExternalStringClassId(cid) || cid != kOneByteStringCid) { 2907 if (RawObject::IsExternalStringClassId(cid) || cid != kOneByteStringCid) {
2850 return false; 2908 return false;
2851 } 2909 }
2852 Definition* str = call->ArgumentAt(0); 2910 Definition* str = call->ArgumentAt(0);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
3025 Bigint::neg_offset(), 3083 Bigint::neg_offset(),
3026 new(I) Value(bigint), 3084 new(I) Value(bigint),
3027 new(I) Value(value), 3085 new(I) Value(value),
3028 kEmitStoreBarrier, 3086 kEmitStoreBarrier,
3029 call->token_pos()); 3087 call->token_pos());
3030 ReplaceCall(call, store); 3088 ReplaceCall(call, store);
3031 return true; 3089 return true;
3032 } 3090 }
3033 3091
3034 if (((recognized_kind == MethodRecognizer::kStringBaseCodeUnitAt) || 3092 if (((recognized_kind == MethodRecognizer::kStringBaseCodeUnitAt) ||
3035 (recognized_kind == MethodRecognizer::kStringBaseCharAt)) && 3093 (recognized_kind == MethodRecognizer::kStringBaseCharAt) ||
3094 (recognized_kind == MethodRecognizer::kOneByteString_oneCodeUnitAt) ||
3095 (recognized_kind == MethodRecognizer::kOneByteString_twoCodeUnitsAt) ||
3096 (recognized_kind == MethodRecognizer::kOneByteString_fourCodeUnitsAt) ||
3097 (recognized_kind == MethodRecognizer::kTwoByteString_oneCodeUnitAt) ||
3098 (recognized_kind == MethodRecognizer::kTwoByteString_twoCodeUnitsAt)) &&
3036 (ic_data.NumberOfChecks() == 1) && 3099 (ic_data.NumberOfChecks() == 1) &&
3037 ((class_ids[0] == kOneByteStringCid) || 3100 ((class_ids[0] == kOneByteStringCid) ||
3038 (class_ids[0] == kTwoByteStringCid))) { 3101 (class_ids[0] == kTwoByteStringCid))) {
3039 return TryReplaceInstanceCallWithInline(call); 3102 return TryReplaceInstanceCallWithInline(call);
3040 } 3103 }
3041 3104
3042 if ((class_ids[0] == kOneByteStringCid) && (ic_data.NumberOfChecks() == 1)) { 3105 if ((class_ids[0] == kOneByteStringCid) && (ic_data.NumberOfChecks() == 1)) {
3043 if (recognized_kind == MethodRecognizer::kOneByteStringSetAt) { 3106 if (recognized_kind == MethodRecognizer::kOneByteStringSetAt) {
3044 // This is an internal method, no need to check argument types nor 3107 // This is an internal method, no need to check argument types nor
3045 // range. 3108 // range.
(...skipping 4634 matching lines...) Expand 10 before | Expand all | Expand 10 after
7680 } 7743 }
7681 7744
7682 7745
7683 void ConstantPropagator::VisitTargetEntry(TargetEntryInstr* block) { 7746 void ConstantPropagator::VisitTargetEntry(TargetEntryInstr* block) {
7684 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { 7747 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
7685 it.Current()->Accept(this); 7748 it.Current()->Accept(this);
7686 } 7749 }
7687 } 7750 }
7688 7751
7689 7752
7753 void ConstantPropagator::VisitIndirectEntry(IndirectEntryInstr* block) {
7754 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
7755 it.Current()->Accept(this);
7756 }
7757 }
7758
7759
7690 void ConstantPropagator::VisitCatchBlockEntry(CatchBlockEntryInstr* block) { 7760 void ConstantPropagator::VisitCatchBlockEntry(CatchBlockEntryInstr* block) {
7691 const GrowableArray<Definition*>& defs = *block->initial_definitions(); 7761 const GrowableArray<Definition*>& defs = *block->initial_definitions();
7692 for (intptr_t i = 0; i < defs.length(); ++i) { 7762 for (intptr_t i = 0; i < defs.length(); ++i) {
7693 defs[i]->Accept(this); 7763 defs[i]->Accept(this);
7694 } 7764 }
7695 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { 7765 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
7696 it.Current()->Accept(this); 7766 it.Current()->Accept(this);
7697 } 7767 }
7698 } 7768 }
7699 7769
(...skipping 27 matching lines...) Expand all
7727 SetReachable(instr->successor()); 7797 SetReachable(instr->successor());
7728 7798
7729 // Phi value depends on the reachability of a predecessor. We have 7799 // Phi value depends on the reachability of a predecessor. We have
7730 // to revisit phis every time a predecessor becomes reachable. 7800 // to revisit phis every time a predecessor becomes reachable.
7731 for (PhiIterator it(instr->successor()); !it.Done(); it.Advance()) { 7801 for (PhiIterator it(instr->successor()); !it.Done(); it.Advance()) {
7732 it.Current()->Accept(this); 7802 it.Current()->Accept(this);
7733 } 7803 }
7734 } 7804 }
7735 7805
7736 7806
7807 void ConstantPropagator::VisitIndirectGoto(IndirectGotoInstr* instr) {
7808 for (intptr_t i = 0; i < instr->SuccessorCount(); i++) {
7809 SetReachable(instr->SuccessorAt(i));
7810 }
7811 }
7812
7813
7737 void ConstantPropagator::VisitBranch(BranchInstr* instr) { 7814 void ConstantPropagator::VisitBranch(BranchInstr* instr) {
7738 instr->comparison()->Accept(this); 7815 instr->comparison()->Accept(this);
7739 7816
7740 // The successors may be reachable, but only if this instruction is. (We 7817 // The successors may be reachable, but only if this instruction is. (We
7741 // might be analyzing it because the constant value of one of its inputs 7818 // might be analyzing it because the constant value of one of its inputs
7742 // has changed.) 7819 // has changed.)
7743 if (reachable_->Contains(instr->GetBlock()->preorder_number())) { 7820 if (reachable_->Contains(instr->GetBlock()->preorder_number())) {
7744 if (instr->constant_target() != NULL) { 7821 if (instr->constant_target() != NULL) {
7745 ASSERT((instr->constant_target() == instr->true_successor()) || 7822 ASSERT((instr->constant_target() == instr->true_successor()) ||
7746 (instr->constant_target() == instr->false_successor())); 7823 (instr->constant_target() == instr->false_successor()));
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
8138 SetValue(instr, result); 8215 SetValue(instr, result);
8139 return; 8216 return;
8140 } 8217 }
8141 } 8218 }
8142 } 8219 }
8143 SetValue(instr, non_constant_); 8220 SetValue(instr, non_constant_);
8144 } 8221 }
8145 } 8222 }
8146 8223
8147 8224
8225 void ConstantPropagator::VisitLoadCodeUnits(LoadCodeUnitsInstr* instr) {
8226 // TODO(jgruber): Implement constant propagation.
8227 SetValue(instr, non_constant_);
8228 }
8229
8230
8148 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) { 8231 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) {
8149 SetValue(instr, instr->value()->definition()->constant_value()); 8232 SetValue(instr, instr->value()->definition()->constant_value());
8150 } 8233 }
8151 8234
8152 8235
8153 void ConstantPropagator::VisitStoreInstanceField( 8236 void ConstantPropagator::VisitStoreInstanceField(
8154 StoreInstanceFieldInstr* instr) { 8237 StoreInstanceFieldInstr* instr) {
8155 SetValue(instr, instr->value()->definition()->constant_value()); 8238 SetValue(instr, instr->value()->definition()->constant_value());
8156 } 8239 }
8157 8240
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
8780 const Object& right = instr->right()->definition()->constant_value(); 8863 const Object& right = instr->right()->definition()->constant_value();
8781 if (IsNonConstant(left) || IsNonConstant(right)) { 8864 if (IsNonConstant(left) || IsNonConstant(right)) {
8782 SetValue(instr, non_constant_); 8865 SetValue(instr, non_constant_);
8783 } else if (IsConstant(left) && IsConstant(right)) { 8866 } else if (IsConstant(left) && IsConstant(right)) {
8784 // TODO(srdjan): Handle min and max. 8867 // TODO(srdjan): Handle min and max.
8785 SetValue(instr, non_constant_); 8868 SetValue(instr, non_constant_);
8786 } 8869 }
8787 } 8870 }
8788 8871
8789 8872
8873 void ConstantPropagator::VisitCaseInsensitiveCompareUC16(
8874 CaseInsensitiveCompareUC16Instr *instr) {
8875 // TODO(jgruber): Handle constant propagation.
8876 SetValue(instr, non_constant_);
8877 }
8878
8879
8790 void ConstantPropagator::VisitUnboxDouble(UnboxDoubleInstr* instr) { 8880 void ConstantPropagator::VisitUnboxDouble(UnboxDoubleInstr* instr) {
8791 const Object& value = instr->value()->definition()->constant_value(); 8881 const Object& value = instr->value()->definition()->constant_value();
8792 if (IsNonConstant(value)) { 8882 if (IsNonConstant(value)) {
8793 SetValue(instr, non_constant_); 8883 SetValue(instr, non_constant_);
8794 } else if (IsConstant(value)) { 8884 } else if (IsConstant(value)) {
8795 // TODO(kmillikin): Handle conversion. 8885 // TODO(kmillikin): Handle conversion.
8796 SetValue(instr, non_constant_); 8886 SetValue(instr, non_constant_);
8797 } 8887 }
8798 } 8888 }
8799 8889
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
8929 } else { 9019 } else {
8930 BlockEntryInstr* block = block_worklist_.RemoveLast(); 9020 BlockEntryInstr* block = block_worklist_.RemoveLast();
8931 block->Accept(this); 9021 block->Accept(this);
8932 } 9022 }
8933 } 9023 }
8934 } 9024 }
8935 9025
8936 9026
8937 static bool IsEmptyBlock(BlockEntryInstr* block) { 9027 static bool IsEmptyBlock(BlockEntryInstr* block) {
8938 return block->next()->IsGoto() && 9028 return block->next()->IsGoto() &&
8939 (!block->IsJoinEntry() || (block->AsJoinEntry()->phis() == NULL)); 9029 (!block->IsJoinEntry() || (block->AsJoinEntry()->phis() == NULL)) &&
9030 !block->IsIndirectEntry();
8940 } 9031 }
8941 9032
8942 9033
8943 // Traverses a chain of empty blocks and returns the first reachable non-empty 9034 // Traverses a chain of empty blocks and returns the first reachable non-empty
8944 // block that is not dominated by the start block. The empty blocks are added 9035 // block that is not dominated by the start block. The empty blocks are added
8945 // to the supplied bit vector. 9036 // to the supplied bit vector.
8946 static BlockEntryInstr* FindFirstNonEmptySuccessor( 9037 static BlockEntryInstr* FindFirstNonEmptySuccessor(
8947 TargetEntryInstr* block, 9038 TargetEntryInstr* block,
8948 BitVector* empty_blocks) { 9039 BitVector* empty_blocks) {
8949 BlockEntryInstr* current = block; 9040 BlockEntryInstr* current = block;
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
10120 10211
10121 // Insert materializations at environment uses. 10212 // Insert materializations at environment uses.
10122 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) { 10213 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) {
10123 CreateMaterializationAt( 10214 CreateMaterializationAt(
10124 exits_collector_.exits()[i], alloc, alloc->cls(), *slots); 10215 exits_collector_.exits()[i], alloc, alloc->cls(), *slots);
10125 } 10216 }
10126 } 10217 }
10127 10218
10128 10219
10129 } // namespace dart 10220 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698