MIPS: Allow specifying base offset when constructing Keyed hydrogen instructions.

Port r21426 (17e6338)

This is preparation for pending hydrogen stub work that needs to access memory using KeyedLoad/KeyedStore operations where the base offset used for the accesses are is the the default (e.g. the size of an FixedArray header for FixedArrays or zero for external arrays).

BUG=
R=plind44@gmail.com

Review URL: https://codereview.chromium.org/296983003

Patch from Balazs Kilvady <kilvadyb@homejinni.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21443 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
plind44@gmail.com 2014-05-22 17:00:50 +00:00
parent 00b8e6128f
commit 9fb4abb94b
4 changed files with 32 additions and 72 deletions

View File

@ -3110,16 +3110,13 @@ void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
int element_size_shift = ElementsKindToShiftSize(elements_kind); int element_size_shift = ElementsKindToShiftSize(elements_kind);
int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
? (element_size_shift - kSmiTagSize) : element_size_shift; ? (element_size_shift - kSmiTagSize) : element_size_shift;
int additional_offset = IsFixedTypedArrayElementsKind(elements_kind) int base_offset = instr->base_offset();
? FixedTypedArrayBase::kDataOffset - kHeapObjectTag
: 0;
if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT32_ELEMENTS ||
elements_kind == EXTERNAL_FLOAT64_ELEMENTS || elements_kind == EXTERNAL_FLOAT64_ELEMENTS ||
elements_kind == FLOAT64_ELEMENTS) { elements_kind == FLOAT64_ELEMENTS) {
int base_offset = int base_offset = instr->base_offset();
(instr->additional_index() << element_size_shift) + additional_offset;
FPURegister result = ToDoubleRegister(instr->result()); FPURegister result = ToDoubleRegister(instr->result());
if (key_is_constant) { if (key_is_constant) {
__ Addu(scratch0(), external_pointer, constant_key << element_size_shift); __ Addu(scratch0(), external_pointer, constant_key << element_size_shift);
@ -3131,15 +3128,14 @@ void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
elements_kind == FLOAT32_ELEMENTS) { elements_kind == FLOAT32_ELEMENTS) {
__ lwc1(result, MemOperand(scratch0(), base_offset)); __ lwc1(result, MemOperand(scratch0(), base_offset));
__ cvt_d_s(result, result); __ cvt_d_s(result, result);
} else { // loading doubles, not floats. } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS
__ ldc1(result, MemOperand(scratch0(), base_offset)); __ ldc1(result, MemOperand(scratch0(), base_offset));
} }
} else { } else {
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
MemOperand mem_operand = PrepareKeyedOperand( MemOperand mem_operand = PrepareKeyedOperand(
key, external_pointer, key_is_constant, constant_key, key, external_pointer, key_is_constant, constant_key,
element_size_shift, shift_size, element_size_shift, shift_size, base_offset);
instr->additional_index(), additional_offset);
switch (elements_kind) { switch (elements_kind) {
case EXTERNAL_INT8_ELEMENTS: case EXTERNAL_INT8_ELEMENTS:
case INT8_ELEMENTS: case INT8_ELEMENTS:
@ -3199,15 +3195,13 @@ void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) {
int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS);
int base_offset = int base_offset = instr->base_offset();
FixedDoubleArray::kHeaderSize - kHeapObjectTag +
(instr->additional_index() << element_size_shift);
if (key_is_constant) { if (key_is_constant) {
int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); int constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
if (constant_key & 0xF0000000) { if (constant_key & 0xF0000000) {
Abort(kArrayIndexConstantValueTooBig); Abort(kArrayIndexConstantValueTooBig);
} }
base_offset += constant_key << element_size_shift; base_offset += constant_key * kDoubleSize;
} }
__ Addu(scratch, elements, Operand(base_offset)); __ Addu(scratch, elements, Operand(base_offset));
@ -3233,12 +3227,11 @@ void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) {
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
Register scratch = scratch0(); Register scratch = scratch0();
Register store_base = scratch; Register store_base = scratch;
int offset = 0; int offset = instr->base_offset();
if (instr->key()->IsConstantOperand()) { if (instr->key()->IsConstantOperand()) {
LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + offset += ToInteger32(const_operand) * kPointerSize;
instr->additional_index());
store_base = elements; store_base = elements;
} else { } else {
Register key = ToRegister(instr->key()); Register key = ToRegister(instr->key());
@ -3253,9 +3246,8 @@ void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) {
__ sll(scratch, key, kPointerSizeLog2); __ sll(scratch, key, kPointerSizeLog2);
__ addu(scratch, elements, scratch); __ addu(scratch, elements, scratch);
} }
offset = FixedArray::OffsetOfElementAt(instr->additional_index());
} }
__ lw(result, FieldMemOperand(store_base, offset)); __ lw(result, MemOperand(store_base, offset));
// Check for the hole value. // Check for the hole value.
if (instr->hydrogen()->RequiresHoleCheck()) { if (instr->hydrogen()->RequiresHoleCheck()) {
@ -3287,34 +3279,12 @@ MemOperand LCodeGen::PrepareKeyedOperand(Register key,
int constant_key, int constant_key,
int element_size, int element_size,
int shift_size, int shift_size,
int additional_index, int base_offset) {
int additional_offset) {
int base_offset = (additional_index << element_size) + additional_offset;
if (key_is_constant) { if (key_is_constant) {
return MemOperand(base, return MemOperand(base, (constant_key << element_size) + base_offset);
base_offset + (constant_key << element_size));
} }
if (additional_offset != 0) { if (base_offset == 0) {
if (shift_size >= 0) {
__ sll(scratch0(), key, shift_size);
__ Addu(scratch0(), scratch0(), Operand(base_offset));
} else {
ASSERT_EQ(-1, shift_size);
// Key can be negative, so using sra here.
__ sra(scratch0(), key, 1);
__ Addu(scratch0(), scratch0(), Operand(base_offset));
}
__ Addu(scratch0(), base, scratch0());
return MemOperand(scratch0());
}
if (additional_index != 0) {
additional_index *= 1 << (element_size - shift_size);
__ Addu(scratch0(), key, Operand(additional_index));
}
if (additional_index == 0) {
if (shift_size >= 0) { if (shift_size >= 0) {
__ sll(scratch0(), key, shift_size); __ sll(scratch0(), key, shift_size);
__ Addu(scratch0(), base, scratch0()); __ Addu(scratch0(), base, scratch0());
@ -3328,14 +3298,14 @@ MemOperand LCodeGen::PrepareKeyedOperand(Register key,
} }
if (shift_size >= 0) { if (shift_size >= 0) {
__ sll(scratch0(), scratch0(), shift_size); __ sll(scratch0(), key, shift_size);
__ Addu(scratch0(), base, scratch0()); __ Addu(scratch0(), base, scratch0());
return MemOperand(scratch0()); return MemOperand(scratch0(), base_offset);
} else { } else {
ASSERT_EQ(-1, shift_size); ASSERT_EQ(-1, shift_size);
__ srl(scratch0(), scratch0(), 1); __ sra(scratch0(), key, 1);
__ Addu(scratch0(), base, scratch0()); __ Addu(scratch0(), base, scratch0());
return MemOperand(scratch0()); return MemOperand(scratch0(), base_offset);
} }
} }
@ -4208,16 +4178,12 @@ void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
int element_size_shift = ElementsKindToShiftSize(elements_kind); int element_size_shift = ElementsKindToShiftSize(elements_kind);
int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
? (element_size_shift - kSmiTagSize) : element_size_shift; ? (element_size_shift - kSmiTagSize) : element_size_shift;
int additional_offset = IsFixedTypedArrayElementsKind(elements_kind) int base_offset = instr->base_offset();
? FixedTypedArrayBase::kDataOffset - kHeapObjectTag
: 0;
if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS ||
elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT32_ELEMENTS ||
elements_kind == EXTERNAL_FLOAT64_ELEMENTS || elements_kind == EXTERNAL_FLOAT64_ELEMENTS ||
elements_kind == FLOAT64_ELEMENTS) { elements_kind == FLOAT64_ELEMENTS) {
int base_offset =
(instr->additional_index() << element_size_shift) + additional_offset;
Register address = scratch0(); Register address = scratch0();
FPURegister value(ToDoubleRegister(instr->value())); FPURegister value(ToDoubleRegister(instr->value()));
if (key_is_constant) { if (key_is_constant) {
@ -4244,7 +4210,7 @@ void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
MemOperand mem_operand = PrepareKeyedOperand( MemOperand mem_operand = PrepareKeyedOperand(
key, external_pointer, key_is_constant, constant_key, key, external_pointer, key_is_constant, constant_key,
element_size_shift, shift_size, element_size_shift, shift_size,
instr->additional_index(), additional_offset); base_offset);
switch (elements_kind) { switch (elements_kind) {
case EXTERNAL_UINT8_CLAMPED_ELEMENTS: case EXTERNAL_UINT8_CLAMPED_ELEMENTS:
case EXTERNAL_INT8_ELEMENTS: case EXTERNAL_INT8_ELEMENTS:
@ -4291,6 +4257,7 @@ void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
Register scratch = scratch0(); Register scratch = scratch0();
DoubleRegister double_scratch = double_scratch0(); DoubleRegister double_scratch = double_scratch0();
bool key_is_constant = instr->key()->IsConstantOperand(); bool key_is_constant = instr->key()->IsConstantOperand();
int base_offset = instr->base_offset();
Label not_nan, done; Label not_nan, done;
// Calculate the effective address of the slot in the array to store the // Calculate the effective address of the slot in the array to store the
@ -4302,13 +4269,11 @@ void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
Abort(kArrayIndexConstantValueTooBig); Abort(kArrayIndexConstantValueTooBig);
} }
__ Addu(scratch, elements, __ Addu(scratch, elements,
Operand((constant_key << element_size_shift) + Operand((constant_key << element_size_shift) + base_offset));
FixedDoubleArray::kHeaderSize - kHeapObjectTag));
} else { } else {
int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
? (element_size_shift - kSmiTagSize) : element_size_shift; ? (element_size_shift - kSmiTagSize) : element_size_shift;
__ Addu(scratch, elements, __ Addu(scratch, elements, Operand(base_offset));
Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag));
__ sll(at, ToRegister(instr->key()), shift_size); __ sll(at, ToRegister(instr->key()), shift_size);
__ Addu(scratch, scratch, at); __ Addu(scratch, scratch, at);
} }
@ -4323,14 +4288,12 @@ void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
__ bind(&is_nan); __ bind(&is_nan);
__ LoadRoot(at, Heap::kNanValueRootIndex); __ LoadRoot(at, Heap::kNanValueRootIndex);
__ ldc1(double_scratch, FieldMemOperand(at, HeapNumber::kValueOffset)); __ ldc1(double_scratch, FieldMemOperand(at, HeapNumber::kValueOffset));
__ sdc1(double_scratch, MemOperand(scratch, instr->additional_index() << __ sdc1(double_scratch, MemOperand(scratch, 0));
element_size_shift));
__ Branch(&done); __ Branch(&done);
} }
__ bind(&not_nan); __ bind(&not_nan);
__ sdc1(value, MemOperand(scratch, instr->additional_index() << __ sdc1(value, MemOperand(scratch, 0));
element_size_shift));
__ bind(&done); __ bind(&done);
} }
@ -4342,14 +4305,13 @@ void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) {
: no_reg; : no_reg;
Register scratch = scratch0(); Register scratch = scratch0();
Register store_base = scratch; Register store_base = scratch;
int offset = 0; int offset = instr->base_offset();
// Do the store. // Do the store.
if (instr->key()->IsConstantOperand()) { if (instr->key()->IsConstantOperand()) {
ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); ASSERT(!instr->hydrogen()->NeedsWriteBarrier());
LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + offset += ToInteger32(const_operand) * kPointerSize;
instr->additional_index());
store_base = elements; store_base = elements;
} else { } else {
// Even though the HLoadKeyed instruction forces the input // Even though the HLoadKeyed instruction forces the input
@ -4363,16 +4325,15 @@ void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) {
__ sll(scratch, key, kPointerSizeLog2); __ sll(scratch, key, kPointerSizeLog2);
__ addu(scratch, elements, scratch); __ addu(scratch, elements, scratch);
} }
offset = FixedArray::OffsetOfElementAt(instr->additional_index());
} }
__ sw(value, FieldMemOperand(store_base, offset)); __ sw(value, MemOperand(store_base, offset));
if (instr->hydrogen()->NeedsWriteBarrier()) { if (instr->hydrogen()->NeedsWriteBarrier()) {
SmiCheck check_needed = SmiCheck check_needed =
instr->hydrogen()->value()->IsHeapObject() instr->hydrogen()->value()->IsHeapObject()
? OMIT_SMI_CHECK : INLINE_SMI_CHECK; ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
// Compute address of modified element and store it into key register. // Compute address of modified element and store it into key register.
__ Addu(key, store_base, Operand(offset - kHeapObjectTag)); __ Addu(key, store_base, Operand(offset));
__ RecordWrite(elements, __ RecordWrite(elements,
key, key,
value, value,

View File

@ -132,8 +132,7 @@ class LCodeGen: public LCodeGenBase {
int constant_key, int constant_key,
int element_size, int element_size,
int shift_size, int shift_size,
int additional_index, int base_offset);
int additional_offset);
// Emit frame translation commands for an environment. // Emit frame translation commands for an environment.
void WriteTranslation(LEnvironment* environment, Translation* translation); void WriteTranslation(LEnvironment* environment, Translation* translation);

View File

@ -342,7 +342,7 @@ void LLoadKeyed::PrintDataTo(StringStream* stream) {
stream->Add("["); stream->Add("[");
key()->PrintTo(stream); key()->PrintTo(stream);
if (hydrogen()->IsDehoisted()) { if (hydrogen()->IsDehoisted()) {
stream->Add(" + %d]", additional_index()); stream->Add(" + %d]", base_offset());
} else { } else {
stream->Add("]"); stream->Add("]");
} }
@ -354,7 +354,7 @@ void LStoreKeyed::PrintDataTo(StringStream* stream) {
stream->Add("["); stream->Add("[");
key()->PrintTo(stream); key()->PrintTo(stream);
if (hydrogen()->IsDehoisted()) { if (hydrogen()->IsDehoisted()) {
stream->Add(" + %d] <-", additional_index()); stream->Add(" + %d] <-", base_offset());
} else { } else {
stream->Add("] <- "); stream->Add("] <- ");
} }

View File

@ -1609,7 +1609,7 @@ class LLoadKeyed V8_FINAL : public LTemplateInstruction<1, 2, 0> {
DECLARE_HYDROGEN_ACCESSOR(LoadKeyed) DECLARE_HYDROGEN_ACCESSOR(LoadKeyed)
virtual void PrintDataTo(StringStream* stream); virtual void PrintDataTo(StringStream* stream);
uint32_t additional_index() const { return hydrogen()->index_offset(); } uint32_t base_offset() const { return hydrogen()->base_offset(); }
}; };
@ -2178,7 +2178,7 @@ class LStoreKeyed V8_FINAL : public LTemplateInstruction<0, 3, 0> {
virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE;
bool NeedsCanonicalization() { return hydrogen()->NeedsCanonicalization(); } bool NeedsCanonicalization() { return hydrogen()->NeedsCanonicalization(); }
uint32_t additional_index() const { return hydrogen()->index_offset(); } uint32_t base_offset() const { return hydrogen()->base_offset(); }
}; };