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

Side by Side Diff: src/hydrogen.cc

Issue 18562009: Turn array index dehoisting into a proper HPhase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | src/hydrogen-dehoist.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 18 matching lines...) Expand all
29 29
30 #include <algorithm> 30 #include <algorithm>
31 31
32 #include "v8.h" 32 #include "v8.h"
33 #include "codegen.h" 33 #include "codegen.h"
34 #include "full-codegen.h" 34 #include "full-codegen.h"
35 #include "hashmap.h" 35 #include "hashmap.h"
36 #include "hydrogen-bce.h" 36 #include "hydrogen-bce.h"
37 #include "hydrogen-canonicalize.h" 37 #include "hydrogen-canonicalize.h"
38 #include "hydrogen-dce.h" 38 #include "hydrogen-dce.h"
39 #include "hydrogen-dehoist.h"
39 #include "hydrogen-environment-liveness.h" 40 #include "hydrogen-environment-liveness.h"
40 #include "hydrogen-escape-analysis.h" 41 #include "hydrogen-escape-analysis.h"
41 #include "hydrogen-infer-representation.h" 42 #include "hydrogen-infer-representation.h"
42 #include "hydrogen-infer-types.h" 43 #include "hydrogen-infer-types.h"
43 #include "hydrogen-gvn.h" 44 #include "hydrogen-gvn.h"
44 #include "hydrogen-minus-zero.h" 45 #include "hydrogen-minus-zero.h"
45 #include "hydrogen-osr.h" 46 #include "hydrogen-osr.h"
46 #include "hydrogen-range-analysis.h" 47 #include "hydrogen-range-analysis.h"
47 #include "hydrogen-redundant-phi.h" 48 #include "hydrogen-redundant-phi.h"
48 #include "hydrogen-removable-simulates.h" 49 #include "hydrogen-removable-simulates.h"
(...skipping 3022 matching lines...) Expand 10 before | Expand all | Expand 10 after
3071 3072
3072 Run<HComputeMinusZeroChecksPhase>(); 3073 Run<HComputeMinusZeroChecksPhase>();
3073 3074
3074 // Eliminate redundant stack checks on backwards branches. 3075 // Eliminate redundant stack checks on backwards branches.
3075 Run<HStackCheckEliminationPhase>(); 3076 Run<HStackCheckEliminationPhase>();
3076 3077
3077 if (FLAG_idefs) SetupInformativeDefinitions(); 3078 if (FLAG_idefs) SetupInformativeDefinitions();
3078 if (FLAG_array_bounds_checks_elimination && !FLAG_idefs) { 3079 if (FLAG_array_bounds_checks_elimination && !FLAG_idefs) {
3079 Run<HBoundsCheckEliminationPhase>(); 3080 Run<HBoundsCheckEliminationPhase>();
3080 } 3081 }
3081 if (FLAG_array_index_dehoisting) DehoistSimpleArrayIndexComputations(); 3082 if (FLAG_array_index_dehoisting) Run<HDehoistIndexComputationsPhase>();
3082 if (FLAG_dead_code_elimination) Run<HDeadCodeEliminationPhase>(); 3083 if (FLAG_dead_code_elimination) Run<HDeadCodeEliminationPhase>();
3083 3084
3084 RestoreActualValues(); 3085 RestoreActualValues();
3085 3086
3086 return true; 3087 return true;
3087 } 3088 }
3088 3089
3089 3090
3090 void HGraph::SetupInformativeDefinitionsInBlock(HBasicBlock* block) { 3091 void HGraph::SetupInformativeDefinitionsInBlock(HBasicBlock* block) {
3091 for (int phi_index = 0; phi_index < block->phis()->length(); phi_index++) { 3092 for (int phi_index = 0; phi_index < block->phis()->length(); phi_index++) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3124 } 3125 }
3125 } 3126 }
3126 3127
3127 3128
3128 void HGraph::SetupInformativeDefinitions() { 3129 void HGraph::SetupInformativeDefinitions() {
3129 HPhase phase("H_Setup informative definitions", this); 3130 HPhase phase("H_Setup informative definitions", this);
3130 SetupInformativeDefinitionsRecursively(entry_block()); 3131 SetupInformativeDefinitionsRecursively(entry_block());
3131 } 3132 }
3132 3133
3133 3134
3134 static void DehoistArrayIndex(ArrayInstructionInterface* array_operation) {
3135 HValue* index = array_operation->GetKey()->ActualValue();
3136 if (!index->representation().IsSmiOrInteger32()) return;
3137
3138 HConstant* constant;
3139 HValue* subexpression;
3140 int32_t sign;
3141 if (index->IsAdd()) {
3142 sign = 1;
3143 HAdd* add = HAdd::cast(index);
3144 if (add->left()->IsConstant()) {
3145 subexpression = add->right();
3146 constant = HConstant::cast(add->left());
3147 } else if (add->right()->IsConstant()) {
3148 subexpression = add->left();
3149 constant = HConstant::cast(add->right());
3150 } else {
3151 return;
3152 }
3153 } else if (index->IsSub()) {
3154 sign = -1;
3155 HSub* sub = HSub::cast(index);
3156 if (sub->left()->IsConstant()) {
3157 subexpression = sub->right();
3158 constant = HConstant::cast(sub->left());
3159 } else if (sub->right()->IsConstant()) {
3160 subexpression = sub->left();
3161 constant = HConstant::cast(sub->right());
3162 } else {
3163 return;
3164 }
3165 } else {
3166 return;
3167 }
3168
3169 if (!constant->HasInteger32Value()) return;
3170 int32_t value = constant->Integer32Value() * sign;
3171 // We limit offset values to 30 bits because we want to avoid the risk of
3172 // overflows when the offset is added to the object header size.
3173 if (value >= 1 << 30 || value < 0) return;
3174 array_operation->SetKey(subexpression);
3175 if (index->HasNoUses()) {
3176 index->DeleteAndReplaceWith(NULL);
3177 }
3178 ASSERT(value >= 0);
3179 array_operation->SetIndexOffset(static_cast<uint32_t>(value));
3180 array_operation->SetDehoisted(true);
3181 }
3182
3183
3184 void HGraph::DehoistSimpleArrayIndexComputations() {
3185 HPhase phase("H_Dehoist index computations", this);
3186 for (int i = 0; i < blocks()->length(); ++i) {
3187 for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) {
3188 HInstruction* instr = it.Current();
3189 ArrayInstructionInterface* array_instruction = NULL;
3190 if (instr->IsLoadKeyed()) {
3191 HLoadKeyed* op = HLoadKeyed::cast(instr);
3192 array_instruction = static_cast<ArrayInstructionInterface*>(op);
3193 } else if (instr->IsStoreKeyed()) {
3194 HStoreKeyed* op = HStoreKeyed::cast(instr);
3195 array_instruction = static_cast<ArrayInstructionInterface*>(op);
3196 } else {
3197 continue;
3198 }
3199 DehoistArrayIndex(array_instruction);
3200 }
3201 }
3202 }
3203
3204
3205 void HGraph::RestoreActualValues() { 3135 void HGraph::RestoreActualValues() {
3206 HPhase phase("H_Restore actual values", this); 3136 HPhase phase("H_Restore actual values", this);
3207 3137
3208 for (int block_index = 0; block_index < blocks()->length(); block_index++) { 3138 for (int block_index = 0; block_index < blocks()->length(); block_index++) {
3209 HBasicBlock* block = blocks()->at(block_index); 3139 HBasicBlock* block = blocks()->at(block_index);
3210 3140
3211 #ifdef DEBUG 3141 #ifdef DEBUG
3212 for (int i = 0; i < block->phis()->length(); i++) { 3142 for (int i = 0; i < block->phis()->length(); i++) {
3213 HPhi* phi = block->phis()->at(i); 3143 HPhi* phi = block->phis()->at(i);
3214 ASSERT(phi->ActualValue() == phi); 3144 ASSERT(phi->ActualValue() == phi);
(...skipping 6879 matching lines...) Expand 10 before | Expand all | Expand 10 after
10094 if (ShouldProduceTraceOutput()) { 10024 if (ShouldProduceTraceOutput()) {
10095 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 10025 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
10096 } 10026 }
10097 10027
10098 #ifdef DEBUG 10028 #ifdef DEBUG
10099 graph_->Verify(false); // No full verify. 10029 graph_->Verify(false); // No full verify.
10100 #endif 10030 #endif
10101 } 10031 }
10102 10032
10103 } } // namespace v8::internal 10033 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/hydrogen-dehoist.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698