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

Side by Side Diff: src/lithium.cc

Issue 10701141: Remove duplicated LChunk code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nits. Created 8 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 | « src/lithium.h ('k') | src/mips/lithium-mips.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 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 #include "lithium.h" 29 #include "lithium.h"
30 #include "scopes.h"
31
32 #if V8_TARGET_ARCH_IA32
33 #include "ia32/lithium-ia32.h"
34 #elif V8_TARGET_ARCH_X64
35 #include "x64/lithium-x64.h"
36 #elif V8_TARGET_ARCH_ARM
37 #include "arm/lithium-arm.h"
38 #elif V8_TARGET_ARCH_MIPS
39 #include "mips/lithium-mips.h"
40 #else
41 #error "Unknown architecture."
42 #endif
30 43
31 namespace v8 { 44 namespace v8 {
32 namespace internal { 45 namespace internal {
33 46
34 47
35 void LOperand::PrintTo(StringStream* stream) { 48 void LOperand::PrintTo(StringStream* stream) {
36 LUnallocated* unalloc = NULL; 49 LUnallocated* unalloc = NULL;
37 switch (kind()) { 50 switch (kind()) {
38 case INVALID: 51 case INVALID:
39 stream->Add("(0)"); 52 stream->Add("(0)");
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 case FAST_HOLEY_ELEMENTS: 246 case FAST_HOLEY_ELEMENTS:
234 case DICTIONARY_ELEMENTS: 247 case DICTIONARY_ELEMENTS:
235 case NON_STRICT_ARGUMENTS_ELEMENTS: 248 case NON_STRICT_ARGUMENTS_ELEMENTS:
236 return kPointerSizeLog2; 249 return kPointerSizeLog2;
237 } 250 }
238 UNREACHABLE(); 251 UNREACHABLE();
239 return 0; 252 return 0;
240 } 253 }
241 254
242 255
256 LLabel* LChunkBase::GetLabel(int block_id) const {
257 HBasicBlock* block = graph_->blocks()->at(block_id);
258 int first_instruction = block->first_instruction_index();
259 return LLabel::cast(instructions_[first_instruction]);
260 }
261
262
263 int LChunkBase::LookupDestination(int block_id) const {
264 LLabel* cur = GetLabel(block_id);
265 while (cur->replacement() != NULL) {
266 cur = cur->replacement();
267 }
268 return cur->block_id();
269 }
270
271 Label* LChunkBase::GetAssemblyLabel(int block_id) const {
272 LLabel* label = GetLabel(block_id);
273 ASSERT(!label->HasReplacement());
274 return label->label();
275 }
276
277 void LChunkBase::MarkEmptyBlocks() {
278 HPhase phase("L_Mark empty blocks", this);
279 for (int i = 0; i < graph()->blocks()->length(); ++i) {
280 HBasicBlock* block = graph()->blocks()->at(i);
281 int first = block->first_instruction_index();
282 int last = block->last_instruction_index();
283 LInstruction* first_instr = instructions()->at(first);
284 LInstruction* last_instr = instructions()->at(last);
285
286 LLabel* label = LLabel::cast(first_instr);
287 if (last_instr->IsGoto()) {
288 LGoto* goto_instr = LGoto::cast(last_instr);
289 if (label->IsRedundant() &&
290 !label->is_loop_header()) {
291 bool can_eliminate = true;
292 for (int i = first + 1; i < last && can_eliminate; ++i) {
293 LInstruction* cur = instructions()->at(i);
294 if (cur->IsGap()) {
295 LGap* gap = LGap::cast(cur);
296 if (!gap->IsRedundant()) {
297 can_eliminate = false;
298 }
299 } else {
300 can_eliminate = false;
301 }
302 }
303
304 if (can_eliminate) {
305 label->set_replacement(GetLabel(goto_instr->block_id()));
306 }
307 }
308 }
309 }
310 }
311
312
313 void LChunkBase::AddInstruction(LInstruction* instr, HBasicBlock* block) {
314 LInstructionGap* gap = new(graph_->zone()) LInstructionGap(block);
315 int index = -1;
316 if (instr->IsControl()) {
317 instructions_.Add(gap, zone());
318 index = instructions_.length();
319 instructions_.Add(instr, zone());
320 } else {
321 index = instructions_.length();
322 instructions_.Add(instr, zone());
323 instructions_.Add(gap, zone());
324 }
325 if (instr->HasPointerMap()) {
326 pointer_maps_.Add(instr->pointer_map(), zone());
327 instr->pointer_map()->set_lithium_position(index);
328 }
329 }
330
331
332 LConstantOperand* LChunkBase::DefineConstantOperand(HConstant* constant) {
333 return LConstantOperand::Create(constant->id(), zone());
334 }
335
336
337 int LChunkBase::GetParameterStackSlot(int index) const {
338 // The receiver is at index 0, the first parameter at index 1, so we
339 // shift all parameter indexes down by the number of parameters, and
340 // make sure they end up negative so they are distinguishable from
341 // spill slots.
342 int result = index - info()->scope()->num_parameters() - 1;
343 ASSERT(result < 0);
344 return result;
345 }
346
347
348 // A parameter relative to ebp in the arguments stub.
349 int LChunkBase::ParameterAt(int index) {
350 ASSERT(-1 <= index); // -1 is the receiver.
351 return (1 + info()->scope()->num_parameters() - index) *
352 kPointerSize;
353 }
354
355
356 LGap* LChunkBase::GetGapAt(int index) const {
357 return LGap::cast(instructions_[index]);
358 }
359
360
361 bool LChunkBase::IsGapAt(int index) const {
362 return instructions_[index]->IsGap();
363 }
364
365
366 int LChunkBase::NearestGapPos(int index) const {
367 while (!IsGapAt(index)) index--;
368 return index;
369 }
370
371
372 void LChunkBase::AddGapMove(int index, LOperand* from, LOperand* to) {
373 GetGapAt(index)->GetOrCreateParallelMove(
374 LGap::START, zone())->AddMove(from, to, zone());
375 }
376
377
378 Handle<Object> LChunkBase::LookupLiteral(LConstantOperand* operand) const {
379 return HConstant::cast(graph_->LookupValue(operand->index()))->handle();
380 }
381
382
383 Representation LChunkBase::LookupLiteralRepresentation(
384 LConstantOperand* operand) const {
385 return graph_->LookupValue(operand->index())->representation();
386 }
387
388
243 } } // namespace v8::internal 389 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/lithium.h ('k') | src/mips/lithium-mips.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698