OLD | NEW |
---|---|
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 Loading... | |
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3009 void HGraph::EliminateRedundantBoundsChecks(HBasicBlock* bb, | 3010 void HGraph::EliminateRedundantBoundsChecks(HBasicBlock* bb, |
3010 BoundsCheckTable* table) { | 3011 BoundsCheckTable* table) { |
3011 BoundsCheckBbData* bb_data_list = NULL; | 3012 BoundsCheckBbData* bb_data_list = NULL; |
3012 | 3013 |
3013 for (HInstruction* i = bb->first(); i != NULL; i = i->next()) { | 3014 for (HInstruction* i = bb->first(); i != NULL; i = i->next()) { |
3014 if (!i->IsBoundsCheck()) continue; | 3015 if (!i->IsBoundsCheck()) continue; |
3015 | 3016 |
3016 HBoundsCheck* check = HBoundsCheck::cast(i); | 3017 HBoundsCheck* check = HBoundsCheck::cast(i); |
3017 check->ReplaceAllUsesWith(check->index()); | 3018 check->ReplaceAllUsesWith(check->index()); |
3018 | 3019 |
3019 isolate()->counters()->array_bounds_checks_seen()->Increment(); | |
3020 if (!FLAG_array_bounds_checks_elimination) continue; | 3020 if (!FLAG_array_bounds_checks_elimination) continue; |
3021 | 3021 |
3022 int32_t offset; | 3022 int32_t offset; |
3023 BoundsCheckKey* key = | 3023 BoundsCheckKey* key = |
3024 BoundsCheckKey::Create(bb->zone(), check, &offset); | 3024 BoundsCheckKey::Create(bb->zone(), check, &offset); |
3025 BoundsCheckBbData** data_p = table->LookupOrInsert(key); | 3025 BoundsCheckBbData** data_p = table->LookupOrInsert(key); |
3026 BoundsCheckBbData* data = *data_p; | 3026 BoundsCheckBbData* data = *data_p; |
3027 if (data == NULL) { | 3027 if (data == NULL) { |
3028 bb_data_list = new(zone()) BoundsCheckBbData(key, | 3028 bb_data_list = new(zone()) BoundsCheckBbData(key, |
3029 offset, | 3029 offset, |
3030 offset, | 3030 offset, |
3031 bb, | 3031 bb, |
3032 check, | 3032 check, |
3033 bb_data_list, | 3033 bb_data_list, |
3034 NULL); | 3034 NULL); |
3035 *data_p = bb_data_list; | 3035 *data_p = bb_data_list; |
3036 } else if (data->OffsetIsCovered(offset)) { | 3036 } else if (data->OffsetIsCovered(offset)) { |
3037 check->DeleteAndReplaceWith(NULL); | 3037 check->DeleteAndReplaceWith(NULL); |
3038 isolate()->counters()->array_bounds_checks_removed()->Increment(); | |
3039 } else if (data->BasicBlock() == bb) { | 3038 } else if (data->BasicBlock() == bb) { |
3040 data->CoverCheck(check, offset); | 3039 data->CoverCheck(check, offset); |
3041 isolate()->counters()->array_bounds_checks_removed()->Increment(); | |
3042 } else { | 3040 } else { |
3043 int32_t new_lower_offset = offset < data->LowerOffset() | 3041 int32_t new_lower_offset = offset < data->LowerOffset() |
3044 ? offset | 3042 ? offset |
3045 : data->LowerOffset(); | 3043 : data->LowerOffset(); |
3046 int32_t new_upper_offset = offset > data->UpperOffset() | 3044 int32_t new_upper_offset = offset > data->UpperOffset() |
3047 ? offset | 3045 ? offset |
3048 : data->UpperOffset(); | 3046 : data->UpperOffset(); |
3049 bb_data_list = new(bb->zone()) BoundsCheckBbData(key, | 3047 bb_data_list = new(bb->zone()) BoundsCheckBbData(key, |
3050 new_lower_offset, | 3048 new_lower_offset, |
3051 new_upper_offset, | 3049 new_upper_offset, |
(...skipping 23 matching lines...) Expand all Loading... | |
3075 | 3073 |
3076 | 3074 |
3077 void HGraph::EliminateRedundantBoundsChecks() { | 3075 void HGraph::EliminateRedundantBoundsChecks() { |
3078 HPhase phase("H_Eliminate bounds checks", this); | 3076 HPhase phase("H_Eliminate bounds checks", this); |
3079 AssertNoAllocation no_gc; | 3077 AssertNoAllocation no_gc; |
3080 BoundsCheckTable checks_table; | 3078 BoundsCheckTable checks_table; |
3081 EliminateRedundantBoundsChecks(entry_block(), &checks_table); | 3079 EliminateRedundantBoundsChecks(entry_block(), &checks_table); |
3082 } | 3080 } |
3083 | 3081 |
3084 | 3082 |
3083 static void DehoistArrayIndex(ArrayInstructionInterface* array_operation, | |
3084 Counters* counters) { | |
Jakob Kummerow
2012/05/15 15:53:23
No need to pass in |counters| any more, is there?
| |
3085 HValue* index = array_operation->GetKey(); | |
3086 array_operation->SetDehoisted(false); | |
Jakob Kummerow
2012/05/15 15:53:23
It's cleaner to do this in the instruction's c'tor
| |
3087 | |
3088 HConstant* constant; | |
3089 HValue* subexpression; | |
3090 int32_t sign; | |
3091 if (index->IsAdd()) { | |
3092 sign = 1; | |
3093 HAdd* add = HAdd::cast(index); | |
3094 if (add->left()->IsConstant()) { | |
3095 subexpression = add->right(); | |
3096 constant = HConstant::cast(add->left()); | |
3097 } else if (add->right()->IsConstant()) { | |
3098 subexpression = add->left(); | |
3099 constant = HConstant::cast(add->right()); | |
3100 } else { | |
3101 return; | |
3102 } | |
3103 } else if (index->IsSub()) { | |
3104 sign = -1; | |
3105 HSub* sub = HSub::cast(index); | |
3106 if (sub->left()->IsConstant()) { | |
3107 subexpression = sub->right(); | |
3108 constant = HConstant::cast(sub->left()); | |
3109 } else if (sub->right()->IsConstant()) { | |
3110 subexpression = sub->left(); | |
3111 constant = HConstant::cast(sub->right()); | |
3112 } return; | |
3113 } else { | |
3114 return; | |
3115 } | |
3116 | |
3117 if (!constant->HasInteger32Value()) return; | |
3118 int32_t value = constant->Integer32Value() * sign; | |
3119 // We limit offset values to 30 bits because we want to avoid the risk of | |
3120 // overflows when the offset is added to the object header size. | |
3121 if (value >= 1 << 30 || value < 0) return; | |
3122 array_operation->SetKey(subexpression); | |
3123 if (index->HasNoUses()) { | |
3124 index->DeleteAndReplaceWith(NULL); | |
3125 } | |
3126 ASSERT(value >= 0); | |
3127 array_operation->SetIndexOffset(static_cast<uint32_t>(value)); | |
3128 array_operation->SetDehoisted(true); | |
3129 } | |
3130 | |
3131 | |
3132 void HGraph::DehoistSimpleArrayIndexComputations() { | |
3133 if (!FLAG_array_index_dehoisting) return; | |
3134 | |
3135 HPhase phase("H_Dehoist index computations", this); | |
3136 for (int i = 0; i < blocks()->length(); ++i) { | |
3137 for (HInstruction* instr = blocks()->at(i)->first(); | |
3138 instr != NULL; | |
3139 instr = instr->next()) { | |
3140 ArrayInstructionInterface* array_instruction = NULL; | |
3141 if (instr->IsLoadKeyedFastElement()) { | |
3142 HLoadKeyedFastElement* op = HLoadKeyedFastElement::cast(instr); | |
3143 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3144 } else if (instr->IsLoadKeyedFastDoubleElement()) { | |
3145 HLoadKeyedFastDoubleElement* op = | |
3146 HLoadKeyedFastDoubleElement::cast(instr); | |
3147 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3148 } else if (instr->IsLoadKeyedSpecializedArrayElement()) { | |
3149 HLoadKeyedSpecializedArrayElement* op = | |
3150 HLoadKeyedSpecializedArrayElement::cast(instr); | |
3151 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3152 } else if (instr->IsStoreKeyedFastElement()) { | |
3153 HStoreKeyedFastElement* op = HStoreKeyedFastElement::cast(instr); | |
3154 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3155 } else if (instr->IsStoreKeyedFastDoubleElement()) { | |
3156 HStoreKeyedFastDoubleElement* op = | |
3157 HStoreKeyedFastDoubleElement::cast(instr); | |
3158 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3159 } else if (instr->IsStoreKeyedSpecializedArrayElement()) { | |
3160 HStoreKeyedSpecializedArrayElement* op = | |
3161 HStoreKeyedSpecializedArrayElement::cast(instr); | |
3162 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3163 } else { | |
3164 continue; | |
3165 } | |
3166 DehoistArrayIndex(array_instruction, isolate()->counters()); | |
3167 } | |
3168 } | |
3169 } | |
3170 | |
3171 | |
3085 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { | 3172 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { |
3086 ASSERT(current_block() != NULL); | 3173 ASSERT(current_block() != NULL); |
3087 current_block()->AddInstruction(instr); | 3174 current_block()->AddInstruction(instr); |
3088 return instr; | 3175 return instr; |
3089 } | 3176 } |
3090 | 3177 |
3091 | 3178 |
3092 void HGraphBuilder::AddSimulate(int ast_id) { | 3179 void HGraphBuilder::AddSimulate(int ast_id) { |
3093 ASSERT(current_block() != NULL); | 3180 ASSERT(current_block() != NULL); |
3094 current_block()->AddSimulate(ast_id); | 3181 current_block()->AddSimulate(ast_id); |
(...skipping 5765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8860 } | 8947 } |
8861 } | 8948 } |
8862 | 8949 |
8863 #ifdef DEBUG | 8950 #ifdef DEBUG |
8864 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 8951 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
8865 if (allocator_ != NULL) allocator_->Verify(); | 8952 if (allocator_ != NULL) allocator_->Verify(); |
8866 #endif | 8953 #endif |
8867 } | 8954 } |
8868 | 8955 |
8869 } } // namespace v8::internal | 8956 } } // namespace v8::internal |
OLD | NEW |