| OLD | NEW |
| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 HValue* value = state->map_value(); | 154 HValue* value = state->map_value(); |
| 155 // TODO(mstarzinger): This will narrow a map check against a set of maps | 155 // TODO(mstarzinger): This will narrow a map check against a set of maps |
| 156 // down to the first element in the set. Revisit and fix this. | 156 // down to the first element in the set. Revisit and fix this. |
| 157 HCheckValue* check = HCheckValue::New( | 157 HCheckValue* check = HCheckValue::New( |
| 158 zone, NULL, value, mapcheck->first_map(), false); | 158 zone, NULL, value, mapcheck->first_map(), false); |
| 159 check->InsertBefore(mapcheck); | 159 check->InsertBefore(mapcheck); |
| 160 return check; | 160 return check; |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 // Replace a field load with a given value, forcing Smi representation if |
| 165 // necessary. |
| 166 HValue* HEscapeAnalysisPhase::NewLoadReplacement( |
| 167 HLoadNamedField* load, HValue* load_value) { |
| 168 HValue* replacement = load_value; |
| 169 Representation representation = load->representation(); |
| 170 if (representation.IsSmi()) { |
| 171 Zone* zone = graph()->zone(); |
| 172 HInstruction* new_instr = |
| 173 HForceRepresentation::New(zone, NULL, load_value, representation); |
| 174 new_instr->InsertAfter(load); |
| 175 replacement = new_instr; |
| 176 } |
| 177 return replacement; |
| 178 } |
| 179 |
| 180 |
| 164 // Performs a forward data-flow analysis of all loads and stores on the | 181 // Performs a forward data-flow analysis of all loads and stores on the |
| 165 // given captured allocation. This uses a reverse post-order iteration | 182 // given captured allocation. This uses a reverse post-order iteration |
| 166 // over affected basic blocks. All non-escaping instructions are handled | 183 // over affected basic blocks. All non-escaping instructions are handled |
| 167 // and replaced during the analysis. | 184 // and replaced during the analysis. |
| 168 void HEscapeAnalysisPhase::AnalyzeDataFlow(HInstruction* allocate) { | 185 void HEscapeAnalysisPhase::AnalyzeDataFlow(HInstruction* allocate) { |
| 169 HBasicBlock* allocate_block = allocate->block(); | 186 HBasicBlock* allocate_block = allocate->block(); |
| 170 block_states_.AddBlock(NULL, graph()->blocks()->length(), zone()); | 187 block_states_.AddBlock(NULL, graph()->blocks()->length(), zone()); |
| 171 | 188 |
| 172 // Iterate all blocks starting with the allocation block, since the | 189 // Iterate all blocks starting with the allocation block, since the |
| 173 // allocation cannot dominate blocks that come before. | 190 // allocation cannot dominate blocks that come before. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 189 case HValue::kAllocate: { | 206 case HValue::kAllocate: { |
| 190 if (instr != allocate) continue; | 207 if (instr != allocate) continue; |
| 191 state = NewStateForAllocation(allocate); | 208 state = NewStateForAllocation(allocate); |
| 192 break; | 209 break; |
| 193 } | 210 } |
| 194 case HValue::kLoadNamedField: { | 211 case HValue::kLoadNamedField: { |
| 195 HLoadNamedField* load = HLoadNamedField::cast(instr); | 212 HLoadNamedField* load = HLoadNamedField::cast(instr); |
| 196 int index = load->access().offset() / kPointerSize; | 213 int index = load->access().offset() / kPointerSize; |
| 197 if (load->object() != allocate) continue; | 214 if (load->object() != allocate) continue; |
| 198 ASSERT(load->access().IsInobject()); | 215 ASSERT(load->access().IsInobject()); |
| 199 HValue* replacement = state->OperandAt(index); | 216 HValue* replacement = |
| 217 NewLoadReplacement(load, state->OperandAt(index)); |
| 200 load->DeleteAndReplaceWith(replacement); | 218 load->DeleteAndReplaceWith(replacement); |
| 201 if (FLAG_trace_escape_analysis) { | 219 if (FLAG_trace_escape_analysis) { |
| 202 PrintF("Replacing load #%d with #%d (%s)\n", instr->id(), | 220 PrintF("Replacing load #%d with #%d (%s)\n", load->id(), |
| 203 replacement->id(), replacement->Mnemonic()); | 221 replacement->id(), replacement->Mnemonic()); |
| 204 } | 222 } |
| 205 break; | 223 break; |
| 206 } | 224 } |
| 207 case HValue::kStoreNamedField: { | 225 case HValue::kStoreNamedField: { |
| 208 HStoreNamedField* store = HStoreNamedField::cast(instr); | 226 HStoreNamedField* store = HStoreNamedField::cast(instr); |
| 209 int index = store->access().offset() / kPointerSize; | 227 int index = store->access().offset() / kPointerSize; |
| 210 if (store->object() != allocate) continue; | 228 if (store->object() != allocate) continue; |
| 211 ASSERT(store->access().IsInobject()); | 229 ASSERT(store->access().IsInobject()); |
| 212 state = NewStateCopy(store->previous(), state); | 230 state = NewStateCopy(store->previous(), state); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 for (int i = 0; i < max_fixpoint_iteration_count; i++) { | 342 for (int i = 0; i < max_fixpoint_iteration_count; i++) { |
| 325 CollectCapturedValues(); | 343 CollectCapturedValues(); |
| 326 if (captured_.is_empty()) break; | 344 if (captured_.is_empty()) break; |
| 327 PerformScalarReplacement(); | 345 PerformScalarReplacement(); |
| 328 captured_.Clear(); | 346 captured_.Clear(); |
| 329 } | 347 } |
| 330 } | 348 } |
| 331 | 349 |
| 332 | 350 |
| 333 } } // namespace v8::internal | 351 } } // namespace v8::internal |
| OLD | NEW |