From f8f4e6c9a13718113d76410f48c84047a66aae1a Mon Sep 17 00:00:00 2001 From: "mvstanton@chromium.org" Date: Tue, 15 Oct 2013 15:04:29 +0000 Subject: [PATCH] Make TestJSArrayForAllocationMemento less awkward. Generated code ended up having two conditional jump statements in a row. Also introduce JumpIfJSArrayHasAllocationMemento which handles most cases more simply. R=jkummerow@chromium.org Review URL: https://codereview.chromium.org/26841009 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17220 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/codegen-arm.cc | 9 +++------ src/arm/lithium-codegen-arm.cc | 4 +++- src/arm/macro-assembler-arm.cc | 9 ++++----- src/arm/macro-assembler-arm.h | 15 +++++++++++++-- src/ia32/codegen-ia32.cc | 9 +++------ src/ia32/lithium-codegen-ia32.cc | 4 +++- src/ia32/macro-assembler-ia32.cc | 10 ++++------ src/ia32/macro-assembler-ia32.h | 15 +++++++++++++-- src/x64/codegen-x64.cc | 9 +++------ src/x64/lithium-codegen-x64.cc | 4 +++- src/x64/macro-assembler-x64.cc | 9 ++++----- src/x64/macro-assembler-x64.h | 15 +++++++++++++-- 12 files changed, 69 insertions(+), 43 deletions(-) diff --git a/src/arm/codegen-arm.cc b/src/arm/codegen-arm.cc index e19c5abb00..717f286315 100644 --- a/src/arm/codegen-arm.cc +++ b/src/arm/codegen-arm.cc @@ -402,8 +402,7 @@ void ElementsTransitionGenerator::GenerateMapChangeElementsTransition( // ----------------------------------- if (mode == TRACK_ALLOCATION_SITE) { ASSERT(allocation_memento_found != NULL); - __ TestJSArrayForAllocationMemento(r2, r4); - __ b(eq, allocation_memento_found); + __ JumpIfJSArrayHasAllocationMemento(r2, r4, allocation_memento_found); } // Set transitioned map. @@ -432,8 +431,7 @@ void ElementsTransitionGenerator::GenerateSmiToDouble( Label loop, entry, convert_hole, gc_required, only_change_map, done; if (mode == TRACK_ALLOCATION_SITE) { - __ TestJSArrayForAllocationMemento(r2, r4); - __ b(eq, fail); + __ JumpIfJSArrayHasAllocationMemento(r2, r4, fail); } // Check for empty arrays, which only require a map transition and no changes @@ -559,8 +557,7 @@ void ElementsTransitionGenerator::GenerateDoubleToObject( Label entry, loop, convert_hole, gc_required, only_change_map; if (mode == TRACK_ALLOCATION_SITE) { - __ TestJSArrayForAllocationMemento(r2, r4); - __ b(eq, fail); + __ JumpIfJSArrayHasAllocationMemento(r2, r4, fail); } // Check for empty arrays, which only require a map transition and no changes diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 801c30bbdf..6979442ab5 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -4536,8 +4536,10 @@ void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { Register object = ToRegister(instr->object()); Register temp = ToRegister(instr->temp()); - __ TestJSArrayForAllocationMemento(object, temp); + Label no_memento_found; + __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); DeoptimizeIf(eq, instr->environment()); + __ bind(&no_memento_found); } diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc index 25060ea823..7ca61d254f 100644 --- a/src/arm/macro-assembler-arm.cc +++ b/src/arm/macro-assembler-arm.cc @@ -3858,8 +3858,8 @@ void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) { void MacroAssembler::TestJSArrayForAllocationMemento( Register receiver_reg, - Register scratch_reg) { - Label no_memento_available; + Register scratch_reg, + Label* no_memento_found) { ExternalReference new_space_start = ExternalReference::new_space_start(isolate()); ExternalReference new_space_allocation_top = @@ -3867,15 +3867,14 @@ void MacroAssembler::TestJSArrayForAllocationMemento( add(scratch_reg, receiver_reg, Operand(JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag)); cmp(scratch_reg, Operand(new_space_start)); - b(lt, &no_memento_available); + b(lt, no_memento_found); mov(ip, Operand(new_space_allocation_top)); ldr(ip, MemOperand(ip)); cmp(scratch_reg, ip); - b(gt, &no_memento_available); + b(gt, no_memento_found); ldr(scratch_reg, MemOperand(scratch_reg, -AllocationMemento::kSize)); cmp(scratch_reg, Operand(isolate()->factory()->allocation_memento_map())); - bind(&no_memento_available); } diff --git a/src/arm/macro-assembler-arm.h b/src/arm/macro-assembler-arm.h index 30a617b634..c709e5c57f 100644 --- a/src/arm/macro-assembler-arm.h +++ b/src/arm/macro-assembler-arm.h @@ -1388,9 +1388,20 @@ class MacroAssembler: public Assembler { // to another type. // On entry, receiver_reg should point to the array object. // scratch_reg gets clobbered. - // If allocation info is present, condition flags are set to eq + // If allocation info is present, condition flags are set to eq. void TestJSArrayForAllocationMemento(Register receiver_reg, - Register scratch_reg); + Register scratch_reg, + Label* no_memento_found); + + void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, + Register scratch_reg, + Label* memento_found) { + Label no_memento_found; + TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, + &no_memento_found); + b(eq, memento_found); + bind(&no_memento_found); + } private: void CallCFunctionHelper(Register function, diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc index 9385423578..b28161dd69 100644 --- a/src/ia32/codegen-ia32.cc +++ b/src/ia32/codegen-ia32.cc @@ -666,8 +666,7 @@ void ElementsTransitionGenerator::GenerateMapChangeElementsTransition( // ----------------------------------- if (mode == TRACK_ALLOCATION_SITE) { ASSERT(allocation_memento_found != NULL); - __ TestJSArrayForAllocationMemento(edx, edi); - __ j(equal, allocation_memento_found); + __ JumpIfJSArrayHasAllocationMemento(edx, edi, allocation_memento_found); } // Set transitioned map. @@ -694,8 +693,7 @@ void ElementsTransitionGenerator::GenerateSmiToDouble( Label loop, entry, convert_hole, gc_required, only_change_map; if (mode == TRACK_ALLOCATION_SITE) { - __ TestJSArrayForAllocationMemento(edx, edi); - __ j(equal, fail); + __ JumpIfJSArrayHasAllocationMemento(edx, edi, fail); } // Check for empty arrays, which only require a map transition and no changes @@ -833,8 +831,7 @@ void ElementsTransitionGenerator::GenerateDoubleToObject( Label loop, entry, convert_hole, gc_required, only_change_map, success; if (mode == TRACK_ALLOCATION_SITE) { - __ TestJSArrayForAllocationMemento(edx, edi); - __ j(equal, fail); + __ JumpIfJSArrayHasAllocationMemento(edx, edi, fail); } // Check for empty arrays, which only require a map transition and no changes diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 648bb73453..a9e1f5ae8c 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -4813,8 +4813,10 @@ void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { Register object = ToRegister(instr->object()); Register temp = ToRegister(instr->temp()); - __ TestJSArrayForAllocationMemento(object, temp); + Label no_memento_found; + __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); DeoptimizeIf(equal, instr->environment()); + __ bind(&no_memento_found); } diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc index 16b8bd79fb..9136ace8a8 100644 --- a/src/ia32/macro-assembler-ia32.cc +++ b/src/ia32/macro-assembler-ia32.cc @@ -3512,9 +3512,8 @@ void MacroAssembler::CheckEnumCache(Label* call_runtime) { void MacroAssembler::TestJSArrayForAllocationMemento( Register receiver_reg, - Register scratch_reg) { - Label no_memento_available; - + Register scratch_reg, + Label* no_memento_found) { ExternalReference new_space_start = ExternalReference::new_space_start(isolate()); ExternalReference new_space_allocation_top = @@ -3523,12 +3522,11 @@ void MacroAssembler::TestJSArrayForAllocationMemento( lea(scratch_reg, Operand(receiver_reg, JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag)); cmp(scratch_reg, Immediate(new_space_start)); - j(less, &no_memento_available); + j(less, no_memento_found); cmp(scratch_reg, Operand::StaticVariable(new_space_allocation_top)); - j(greater, &no_memento_available); + j(greater, no_memento_found); cmp(MemOperand(scratch_reg, -AllocationMemento::kSize), Immediate(isolate()->factory()->allocation_memento_map())); - bind(&no_memento_available); } diff --git a/src/ia32/macro-assembler-ia32.h b/src/ia32/macro-assembler-ia32.h index 33af5358b7..a6d782e44d 100644 --- a/src/ia32/macro-assembler-ia32.h +++ b/src/ia32/macro-assembler-ia32.h @@ -957,9 +957,20 @@ class MacroAssembler: public Assembler { // to another type. // On entry, receiver_reg should point to the array object. // scratch_reg gets clobbered. - // If allocation info is present, conditional code is set to equal + // If allocation info is present, conditional code is set to equal. void TestJSArrayForAllocationMemento(Register receiver_reg, - Register scratch_reg); + Register scratch_reg, + Label* no_memento_found); + + void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, + Register scratch_reg, + Label* memento_found) { + Label no_memento_found; + TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, + &no_memento_found); + j(equal, memento_found); + bind(&no_memento_found); + } private: bool generating_stub_; diff --git a/src/x64/codegen-x64.cc b/src/x64/codegen-x64.cc index 247c7a234a..5373827656 100644 --- a/src/x64/codegen-x64.cc +++ b/src/x64/codegen-x64.cc @@ -263,8 +263,7 @@ void ElementsTransitionGenerator::GenerateMapChangeElementsTransition( // ----------------------------------- if (mode == TRACK_ALLOCATION_SITE) { ASSERT(allocation_memento_found != NULL); - __ TestJSArrayForAllocationMemento(rdx, rdi); - __ j(equal, allocation_memento_found); + __ JumpIfJSArrayHasAllocationMemento(rdx, rdi, allocation_memento_found); } // Set transitioned map. @@ -292,8 +291,7 @@ void ElementsTransitionGenerator::GenerateSmiToDouble( Label allocated, new_backing_store, only_change_map, done; if (mode == TRACK_ALLOCATION_SITE) { - __ TestJSArrayForAllocationMemento(rdx, rdi); - __ j(equal, fail); + __ JumpIfJSArrayHasAllocationMemento(rdx, rdi, fail); } // Check for empty arrays, which only require a map transition and no changes @@ -418,8 +416,7 @@ void ElementsTransitionGenerator::GenerateDoubleToObject( Label loop, entry, convert_hole, gc_required, only_change_map; if (mode == TRACK_ALLOCATION_SITE) { - __ TestJSArrayForAllocationMemento(rdx, rdi); - __ j(equal, fail); + __ JumpIfJSArrayHasAllocationMemento(rdx, rdi, fail); } // Check for empty arrays, which only require a map transition and no changes diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 1c8bbbe28d..b95ac3a252 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -4257,8 +4257,10 @@ void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { Register object = ToRegister(instr->object()); Register temp = ToRegister(instr->temp()); - __ TestJSArrayForAllocationMemento(object, temp); + Label no_memento_found; + __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); DeoptimizeIf(equal, instr->environment()); + __ bind(&no_memento_found); } diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index b3336e6eab..9dcb9d1689 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -4921,8 +4921,8 @@ void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) { void MacroAssembler::TestJSArrayForAllocationMemento( Register receiver_reg, - Register scratch_reg) { - Label no_memento_available; + Register scratch_reg, + Label* no_memento_found) { ExternalReference new_space_start = ExternalReference::new_space_start(isolate()); ExternalReference new_space_allocation_top = @@ -4932,12 +4932,11 @@ void MacroAssembler::TestJSArrayForAllocationMemento( JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag)); movq(kScratchRegister, new_space_start); cmpq(scratch_reg, kScratchRegister); - j(less, &no_memento_available); + j(less, no_memento_found); cmpq(scratch_reg, ExternalOperand(new_space_allocation_top)); - j(greater, &no_memento_available); + j(greater, no_memento_found); CompareRoot(MemOperand(scratch_reg, -AllocationMemento::kSize), Heap::kAllocationMementoMapRootIndex); - bind(&no_memento_available); } diff --git a/src/x64/macro-assembler-x64.h b/src/x64/macro-assembler-x64.h index 931a4eb12f..d1c2434362 100644 --- a/src/x64/macro-assembler-x64.h +++ b/src/x64/macro-assembler-x64.h @@ -1412,9 +1412,20 @@ class MacroAssembler: public Assembler { // to another type. // On entry, receiver_reg should point to the array object. // scratch_reg gets clobbered. - // If allocation info is present, condition flags are set to equal + // If allocation info is present, condition flags are set to equal. void TestJSArrayForAllocationMemento(Register receiver_reg, - Register scratch_reg); + Register scratch_reg, + Label* no_memento_found); + + void JumpIfJSArrayHasAllocationMemento(Register receiver_reg, + Register scratch_reg, + Label* memento_found) { + Label no_memento_found; + TestJSArrayForAllocationMemento(receiver_reg, scratch_reg, + &no_memento_found); + j(equal, memento_found); + bind(&no_memento_found); + } private: // Order general registers are pushed by Pushad.