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

Side by Side Diff: src/hydrogen.cc

Issue 10382055: Array index computation dehoisting. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 7 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2740 matching lines...) Expand 10 before | Expand all | Expand 10 after
2751 HRangeAnalysis rangeAnalysis(graph()); 2751 HRangeAnalysis rangeAnalysis(graph());
2752 rangeAnalysis.Analyze(); 2752 rangeAnalysis.Analyze();
2753 } 2753 }
2754 graph()->ComputeMinusZeroChecks(); 2754 graph()->ComputeMinusZeroChecks();
2755 2755
2756 // Eliminate redundant stack checks on backwards branches. 2756 // Eliminate redundant stack checks on backwards branches.
2757 HStackCheckEliminator sce(graph()); 2757 HStackCheckEliminator sce(graph());
2758 sce.Process(); 2758 sce.Process();
2759 2759
2760 graph()->EliminateRedundantBoundsChecks(); 2760 graph()->EliminateRedundantBoundsChecks();
2761 graph()->DehoistSimpleArrayIndexComputations();
2761 2762
2762 return graph(); 2763 return graph();
2763 } 2764 }
2764 2765
2765 2766
2766 // We try to "factor up" HBoundsCheck instructions towards the root of the 2767 // We try to "factor up" HBoundsCheck instructions towards the root of the
2767 // dominator tree. 2768 // dominator tree.
2768 // For now we handle checks where the index is like "exp + int32value". 2769 // For now we handle checks where the index is like "exp + int32value".
2769 // If in the dominator tree we check "exp + v1" and later (dominated) 2770 // If in the dominator tree we check "exp + v1" and later (dominated)
2770 // "exp + v2", if v2 <= v1 we can safely remove the second check, and if 2771 // "exp + v2", if v2 <= v1 we can safely remove the second check, and if
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
3075 3076
3076 3077
3077 void HGraph::EliminateRedundantBoundsChecks() { 3078 void HGraph::EliminateRedundantBoundsChecks() {
3078 HPhase phase("H_Eliminate bounds checks", this); 3079 HPhase phase("H_Eliminate bounds checks", this);
3079 AssertNoAllocation no_gc; 3080 AssertNoAllocation no_gc;
3080 BoundsCheckTable checks_table; 3081 BoundsCheckTable checks_table;
3081 EliminateRedundantBoundsChecks(entry_block(), &checks_table); 3082 EliminateRedundantBoundsChecks(entry_block(), &checks_table);
3082 } 3083 }
3083 3084
3084 3085
3086 static bool DehoistArrayIndex(HInstruction* array_operation,
3087 HValue* index,
3088 int32_t index_position,
3089 int32_t* offset_value,
3090 Counters* counters) {
3091 HConstant* constant;
3092 HValue* subexpression;
3093 int32_t sign;
3094 if (index->IsAdd()) {
3095 sign = 1;
3096 HAdd* add = HAdd::cast(index);
3097 if (add->left()->IsConstant()) {
3098 subexpression = add->right();
3099 constant = HConstant::cast(add->left());
3100 } else if (add->right()->IsConstant()) {
3101 subexpression = add->left();
3102 constant = HConstant::cast(add->right());
3103 } else {
3104 return false;
3105 }
3106 } else if (index->IsSub()) {
3107 sign = -1;
3108 HSub* sub = HSub::cast(index);
3109 if (sub->left()->IsConstant()) {
3110 subexpression = sub->right();
3111 constant = HConstant::cast(sub->left());
3112 } else if (sub->right()->IsConstant()) {
3113 subexpression = sub->left();
3114 constant = HConstant::cast(sub->right());
3115 } return false;
3116 } else {
3117 return false;
3118 }
3119
3120 if (!constant->HasInteger32Value()) return false;
3121 (*offset_value) = constant->Integer32Value() * sign;
3122 // FIXME(mmassi): decide meaningful bound
Jakob Kummerow 2012/05/08 13:46:26 fix this before landing? :-)
Massi 2012/05/14 13:48:52 Done.
3123 if ((*offset_value) >= 1 << 8 || (*offset_value) < 0) return false;
3124 array_operation->SetOperandAt(index_position, subexpression);
3125 if (index->HasNoUses()) {
3126 index->DeleteAndReplaceWith(NULL);
3127 counters->array_indexes_removed()->Increment();
Jakob Kummerow 2012/05/08 13:46:26 Is it useful to keep those counters, or have they
Massi 2012/05/14 13:48:52 Done.
3128 }
3129 counters->array_indexes_dehoisted()->Increment();
3130 return true;
3131 }
3132
3133
3134 void HGraph::DehoistSimpleArrayIndexComputations() {
3135 if (!FLAG_array_index_dehoisting) return;
3136
3137 HPhase phase("H_Dehoist index computations", this);
3138 for (int i = 0; i < blocks()->length(); ++i) {
3139 for (HInstruction* instr = blocks()->at(i)->first();
3140 instr != NULL;
3141 instr = instr->next()) {
3142 int32_t index_offset = 0;
3143 if (instr->IsLoadKeyedFastElement()) {
Jakob Kummerow 2012/05/08 13:46:26 This is a lot of duplicate code... Suggestion: c
Massi 2012/05/14 13:48:52 Oddly enough, this was my original idea but Sven d
3144 HLoadKeyedFastElement* operation =
3145 HLoadKeyedFastElement::cast(instr);
3146 if (DehoistArrayIndex(operation,
3147 operation->key(),
3148 1,
3149 &index_offset,
3150 isolate()->counters())) {
3151 operation->SetIndexOffset(index_offset);
3152 }
3153 } else if (instr->IsLoadKeyedFastDoubleElement()) {
3154 HLoadKeyedFastDoubleElement* operation =
3155 HLoadKeyedFastDoubleElement::cast(instr);
3156 if (DehoistArrayIndex(operation,
3157 operation->key(),
3158 1,
3159 &index_offset,
3160 isolate()->counters())) {
3161 operation->SetIndexOffset(index_offset);
3162 }
3163 } else if (instr->IsLoadKeyedSpecializedArrayElement()) {
3164 HLoadKeyedSpecializedArrayElement* operation =
3165 HLoadKeyedSpecializedArrayElement::cast(instr);
3166 if (DehoistArrayIndex(operation,
3167 operation->key(),
3168 1,
3169 &index_offset,
3170 isolate()->counters())) {
3171 operation->SetIndexOffset(index_offset);
3172 }
3173 } else if (instr->IsStoreKeyedFastElement()) {
3174 HStoreKeyedFastElement* operation =
3175 HStoreKeyedFastElement::cast(instr);
3176 if (DehoistArrayIndex(operation,
3177 operation->key(),
3178 1,
3179 &index_offset,
3180 isolate()->counters())) {
3181 operation->SetIndexOffset(index_offset);
3182 }
3183 } else if (instr->IsStoreKeyedFastDoubleElement()) {
3184 HStoreKeyedFastDoubleElement* operation =
3185 HStoreKeyedFastDoubleElement::cast(instr);
3186 if (DehoistArrayIndex(operation,
3187 operation->key(),
3188 1,
3189 &index_offset,
3190 isolate()->counters())) {
3191 operation->SetIndexOffset(index_offset);
3192 }
3193 } else if (instr->IsStoreKeyedSpecializedArrayElement()) {
3194 HStoreKeyedSpecializedArrayElement* operation =
3195 HStoreKeyedSpecializedArrayElement::cast(instr);
3196 if (DehoistArrayIndex(operation,
3197 operation->key(),
3198 1,
3199 &index_offset,
3200 isolate()->counters())) {
3201 operation->SetIndexOffset(index_offset);
3202 }
3203 } else {
3204 continue;
3205 }
3206 }
3207 }
3208 }
3209
3210
3085 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { 3211 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) {
3086 ASSERT(current_block() != NULL); 3212 ASSERT(current_block() != NULL);
3087 current_block()->AddInstruction(instr); 3213 current_block()->AddInstruction(instr);
3088 return instr; 3214 return instr;
3089 } 3215 }
3090 3216
3091 3217
3092 void HGraphBuilder::AddSimulate(int ast_id) { 3218 void HGraphBuilder::AddSimulate(int ast_id) {
3093 ASSERT(current_block() != NULL); 3219 ASSERT(current_block() != NULL);
3094 current_block()->AddSimulate(ast_id); 3220 current_block()->AddSimulate(ast_id);
(...skipping 5765 matching lines...) Expand 10 before | Expand all | Expand 10 after
8860 } 8986 }
8861 } 8987 }
8862 8988
8863 #ifdef DEBUG 8989 #ifdef DEBUG
8864 if (graph_ != NULL) graph_->Verify(false); // No full verify. 8990 if (graph_ != NULL) graph_->Verify(false); // No full verify.
8865 if (allocator_ != NULL) allocator_->Verify(); 8991 if (allocator_ != NULL) allocator_->Verify();
8866 #endif 8992 #endif
8867 } 8993 }
8868 8994
8869 } } // namespace v8::internal 8995 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698