Revision: 12912
Author: [email protected]
Date: Fri Nov 9 02:21:07 2012
Log: Some improvements in register usage in lithium compilation of
LoadKeyed/StoreKeyed operations.
BUG=
Review URL: https://codereview.chromium.org/11365084
http://code.google.com/p/v8/source/detail?r=12912
Modified:
/branches/bleeding_edge/src/arm/lithium-arm.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-ia32.h
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.h
/branches/bleeding_edge/src/x64/lithium-x64.cc
/branches/bleeding_edge/src/x64/lithium-x64.h
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.cc Mon Nov 5 05:28:10 2012
+++ /branches/bleeding_edge/src/arm/lithium-arm.cc Fri Nov 9 02:21:07 2012
@@ -1881,6 +1881,7 @@
(instr->representation().IsDouble() &&
((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
(elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
+
LOperand* external_pointer = UseRegister(instr->elements());
result = new(zone()) LLoadKeyed(external_pointer, key);
}
@@ -1905,32 +1906,22 @@
LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
- ElementsKind elements_kind = instr->elements_kind();
- bool needs_write_barrier = instr->NeedsWriteBarrier();
- LOperand* key = needs_write_barrier
- ? UseTempRegister(instr->key())
- : UseRegisterOrConstantAtStart(instr->key());
- bool val_is_temp_register =
- elements_kind == EXTERNAL_PIXEL_ELEMENTS ||
- elements_kind == EXTERNAL_FLOAT_ELEMENTS;
- LOperand* val = val_is_temp_register || needs_write_barrier
- ? UseTempRegister(instr->value())
- : UseRegister(instr->value());
+ LOperand* elements = UseRegisterAtStart(instr->elements());
+ LOperand* key;
+ LOperand* val;
+ if (instr->NeedsWriteBarrier()) {
+ key = UseTempRegister(instr->key());
+ val = UseTempRegister(instr->value());
+ } else {
+ key = UseRegisterOrConstantAtStart(instr->key());
+ val = UseRegisterAtStart(instr->value());
+ }
- LStoreKeyed* result = NULL;
+#ifdef DEBUG
if (!instr->is_external()) {
ASSERT(instr->elements()->representation().IsTagged());
-
- LOperand* object = NULL;
- if (instr->value()->representation().IsDouble()) {
- object = UseRegisterAtStart(instr->elements());
- } else {
- ASSERT(instr->value()->representation().IsTagged());
- object = UseTempRegister(instr->elements());
- }
-
- result = new(zone()) LStoreKeyed(object, key, val);
} else {
+ ElementsKind elements_kind = instr->elements_kind();
ASSERT(
(instr->value()->representation().IsInteger32() &&
(elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
@@ -1939,11 +1930,10 @@
((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
(elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
ASSERT(instr->elements()->representation().IsExternal());
-
- LOperand* external_pointer = UseRegister(instr->elements());
- result = new(zone()) LStoreKeyed(external_pointer, key, val);
}
+#endif
+ LStoreKeyed* result = new(zone()) LStoreKeyed(elements, key, val);
ASSERT(result != NULL);
return result;
}
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Nov 8
04:18:11 2012
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Fri Nov 9
02:21:07 2012
@@ -2773,15 +2773,12 @@
void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
ElementsKind elements_kind = instr->elements_kind();
- LOperand* key = instr->key();
- if (!key->IsConstantOperand() &&
-
ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(),
- elements_kind)) {
- __ SmiUntag(ToRegister(key));
+ if (ExternalArrayOpRequiresTemp<HLoadKeyed>(instr->hydrogen())) {
+ __ SmiUntag(ToRegister(instr->key()));
}
Operand operand(BuildFastArrayOperand(
instr->elements(),
- key,
+ instr->key(),
instr->hydrogen()->key()->representation(),
elements_kind,
0,
@@ -3851,15 +3848,12 @@
void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
ElementsKind elements_kind = instr->elements_kind();
- LOperand* key = instr->key();
- if (!key->IsConstantOperand() &&
-
ExternalArrayOpRequiresTemp(instr->hydrogen()->key()->representation(),
- elements_kind)) {
- __ SmiUntag(ToRegister(key));
+ if (ExternalArrayOpRequiresTemp<HStoreKeyed>(instr->hydrogen())) {
+ __ SmiUntag(ToRegister(instr->key()));
}
Operand operand(BuildFastArrayOperand(
instr->elements(),
- key,
+ instr->key(),
instr->hydrogen()->key()->representation(),
elements_kind,
0,
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.cc Mon Nov 5 05:28:10
2012
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.cc Fri Nov 9 02:21:07
2012
@@ -1933,17 +1933,14 @@
ASSERT(instr->key()->representation().IsInteger32() ||
instr->key()->representation().IsTagged());
ElementsKind elements_kind = instr->elements_kind();
- bool clobbers_key = ExternalArrayOpRequiresTemp(
- instr->key()->representation(), elements_kind);
- LOperand* key = clobbers_key
+ LOperand* elements = UseRegisterAtStart(instr->elements());
+ LOperand* key = instr->is_external() &&
+ ExternalArrayOpRequiresTemp<HLoadKeyed>(instr)
? UseTempRegister(instr->key())
: UseRegisterOrConstantAtStart(instr->key());
- LLoadKeyed* result = NULL;
- if (!instr->is_external()) {
- LOperand* obj = UseRegisterAtStart(instr->elements());
- result = new(zone()) LLoadKeyed(obj, key);
- } else {
+#ifdef DEBUG
+ if (instr->is_external()) {
ASSERT(
(instr->representation().IsInteger32() &&
(elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
@@ -1951,10 +1948,10 @@
(instr->representation().IsDouble() &&
((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
(elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
- LOperand* external_pointer = UseRegister(instr->elements());
- result = new(zone()) LLoadKeyed(external_pointer, key);
}
+#endif
+ LLoadKeyed* result = new(zone()) LLoadKeyed(elements, key);
DefineAsRegister(result);
bool can_deoptimize = instr->RequiresHoleCheck() ||
(elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS);
@@ -1976,34 +1973,27 @@
LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
- LStoreKeyed* result = NULL;
+ ElementsKind elements_kind = instr->elements_kind();
+ LOperand* elements;
+ LOperand* val;
+ LOperand* key;
if (!instr->is_external()) {
ASSERT(instr->elements()->representation().IsTagged());
ASSERT(instr->key()->representation().IsInteger32() ||
instr->key()->representation().IsTagged());
- if (instr->value()->representation().IsDouble()) {
- LOperand* object = UseRegisterAtStart(instr->elements());
- LOperand* val = UseTempRegister(instr->value());
- LOperand* key = UseRegisterOrConstantAtStart(instr->key());
-
- result = new(zone()) LStoreKeyed(object, key, val);
+ if (instr->NeedsWriteBarrier() &&
+ !IsFastDoubleElementsKind(elements_kind)) {
+ val = UseTempRegister(instr->value());
+ key = UseTempRegister(instr->key());
+ elements = UseRegister(instr->elements());
} else {
- ASSERT(instr->value()->representation().IsTagged());
- bool needs_write_barrier = instr->NeedsWriteBarrier();
-
- LOperand* obj = UseRegister(instr->elements());
- LOperand* val = needs_write_barrier
- ? UseTempRegister(instr->value())
- : UseRegisterAtStart(instr->value());
- LOperand* key = needs_write_barrier
- ? UseTempRegister(instr->key())
- : UseRegisterOrConstantAtStart(instr->key());
- result = new(zone()) LStoreKeyed(obj, key, val);
+ val = UseRegisterAtStart(instr->value());
+ key = UseRegisterOrConstantAtStart(instr->key());
+ elements = UseRegisterAtStart(instr->elements());
}
} else {
- ElementsKind elements_kind = instr->elements_kind();
ASSERT(
(instr->value()->representation().IsInteger32() &&
(elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
@@ -2013,26 +2003,25 @@
(elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
ASSERT(instr->elements()->representation().IsExternal());
- LOperand* external_pointer = UseRegister(instr->elements());
+ if (ExternalArrayOpRequiresTemp<HStoreKeyed>(instr)) {
+ key = UseTempRegister(instr->key());
+ elements = UseRegister(instr->elements());
+ } else {
+ key = UseRegisterOrConstantAtStart(instr->key());
+ elements = UseRegisterAtStart(instr->elements());
+ }
+
// Determine if we need a byte register in this case for the value.
bool val_is_fixed_register =
elements_kind == EXTERNAL_BYTE_ELEMENTS ||
elements_kind == EXTERNAL_UNSIGNED_BYTE_ELEMENTS ||
elements_kind == EXTERNAL_PIXEL_ELEMENTS;
-
- LOperand* val = val_is_fixed_register
+ val = val_is_fixed_register
? UseFixed(instr->value(), eax)
: UseRegister(instr->value());
- bool clobbers_key = ExternalArrayOpRequiresTemp(
- instr->key()->representation(), elements_kind);
- LOperand* key = clobbers_key
- ? UseTempRegister(instr->key())
- : UseRegisterOrConstantAtStart(instr->key());
- result = new(zone()) LStoreKeyed(external_pointer,
- key,
- val);
}
+ LStoreKeyed* result = new(zone()) LStoreKeyed(elements, key, val);
ASSERT(result != NULL);
return result;
}
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.h Mon Nov 5 00:53:54 2012
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.h Fri Nov 9 02:21:07 2012
@@ -1408,13 +1408,16 @@
};
-inline static bool ExternalArrayOpRequiresTemp(
- Representation key_representation,
- ElementsKind elements_kind) {
+template <class T>
+inline static bool ExternalArrayOpRequiresTemp(T* value) {
+ CHECK(value->IsLoadKeyed() || value->IsStoreKeyed());
+ Representation key_representation = value->key()->representation();
+ ElementsKind elements_kind = value->elements_kind();
+
// Operations that require the key to be divided by two to be converted
into
// an index cannot fold the scale operation into a load and need an extra
// temp register to do the work.
- return key_representation.IsTagged() &&
+ return !value->IsConstant() && key_representation.IsTagged() &&
(elements_kind == EXTERNAL_BYTE_ELEMENTS ||
elements_kind == EXTERNAL_UNSIGNED_BYTE_ELEMENTS ||
elements_kind == EXTERNAL_PIXEL_ELEMENTS);
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Nov 8
04:18:11 2012
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Fri Nov 9
02:21:07 2012
@@ -2623,24 +2623,30 @@
}
-void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
- ElementsKind elements_kind = instr->elements_kind();
- LOperand* key = instr->key();
- if (!key->IsConstantOperand()) {
- Register key_reg = ToRegister(key);
+template <class T>
+inline void LCodeGen::PrepareKeyForKeyedOp(T* hydrogen_instr, LOperand*
key) {
+ if (ArrayOpClobbersKey<T>(hydrogen_instr)) {
// Even though the HLoad/StoreKeyed (in this case) instructions force
// the input representation for the key to be an integer, the input
// gets replaced during bound check elimination with the index argument
// to the bounds check, which can be tagged, so that case must be
// handled here, too.
- if (instr->hydrogen()->key()->representation().IsTagged()) {
+ Register key_reg = ToRegister(key);
+ if (hydrogen_instr->key()->representation().IsTagged()) {
__ SmiToInteger64(key_reg, key_reg);
- } else if (instr->hydrogen()->IsDehoisted()) {
+ } else if (hydrogen_instr->IsDehoisted()) {
// Sign extend key because it could be a 32 bit negative value
// and the dehoisted address computation happens in 64 bits
__ movsxlq(key_reg, key_reg);
}
}
+}
+
+
+void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
+ ElementsKind elements_kind = instr->elements_kind();
+ LOperand* key = instr->key();
+ PrepareKeyForKeyedOp(instr->hydrogen(), key);
Operand operand(BuildFastArrayOperand(
instr->elements(),
key,
@@ -2700,21 +2706,7 @@
void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) {
XMMRegister result(ToDoubleRegister(instr->result()));
LOperand* key = instr->key();
- if (!key->IsConstantOperand()) {
- Register key_reg = ToRegister(key);
- // Even though the HLoad/StoreKeyed instructions force the input
- // representation for the key to be an integer, the input gets replaced
- // during bound check elimination with the index argument to the bounds
- // check, which can be tagged, so that case must be handled here, too.
- if (instr->hydrogen()->key()->representation().IsTagged()) {
- __ SmiToInteger64(key_reg, key_reg);
- } else if (instr->hydrogen()->IsDehoisted()) {
- // Sign extend key because it could be a 32 bit negative value
- // and the dehoisted address computation happens in 64 bits
- __ movsxlq(key_reg, key_reg);
- }
- }
-
+ PrepareKeyForKeyedOp<HLoadKeyed>(instr->hydrogen(), key);
if (instr->hydrogen()->RequiresHoleCheck()) {
int offset = FixedDoubleArray::kHeaderSize - kHeapObjectTag +
sizeof(kHoleNanLower32);
@@ -2741,21 +2733,7 @@
void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) {
Register result = ToRegister(instr->result());
LOperand* key = instr->key();
- if (!key->IsConstantOperand()) {
- Register key_reg = ToRegister(key);
- // Even though the HLoad/StoreKeyedFastElement instructions force
- // the input representation for the key to be an integer, the input
- // gets replaced during bound check elimination with the index
- // argument to the bounds check, which can be tagged, so that
- // case must be handled here, too.
- if (instr->hydrogen()->key()->representation().IsTagged()) {
- __ SmiToInteger64(key_reg, key_reg);
- } else if (instr->hydrogen()->IsDehoisted()) {
- // Sign extend key because it could be a 32 bit negative value
- // and the dehoisted address computation happens in 64 bits
- __ movsxlq(key_reg, key_reg);
- }
- }
+ PrepareKeyForKeyedOp<HLoadKeyed>(instr->hydrogen(), key);
// Load the result.
__ movq(result,
@@ -3750,21 +3728,7 @@
void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
ElementsKind elements_kind = instr->elements_kind();
LOperand* key = instr->key();
- if (!key->IsConstantOperand()) {
- Register key_reg = ToRegister(key);
- // Even though the HLoad/StoreKeyedFastElement instructions force
- // the input representation for the key to be an integer, the input
- // gets replaced during bound check elimination with the index
- // argument to the bounds check, which can be tagged, so that case
- // must be handled here, too.
- if (instr->hydrogen()->key()->representation().IsTagged()) {
- __ SmiToInteger64(key_reg, key_reg);
- } else if (instr->hydrogen()->IsDehoisted()) {
- // Sign extend key because it could be a 32 bit negative value
- // and the dehoisted address computation happens in 64 bits
- __ movsxlq(key_reg, key_reg);
- }
- }
+ PrepareKeyForKeyedOp<HStoreKeyed>(instr->hydrogen(), key);
Operand operand(BuildFastArrayOperand(
instr->elements(),
key,
@@ -3814,22 +3778,7 @@
void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
XMMRegister value = ToDoubleRegister(instr->value());
LOperand* key = instr->key();
- if (!key->IsConstantOperand()) {
- Register key_reg = ToRegister(key);
- // Even though the HLoad/StoreKeyedFastElement instructions force
- // the input representation for the key to be an integer, the
- // input gets replaced during bound check elimination with the index
- // argument to the bounds check, which can be tagged, so that case
- // must be handled here, too.
- if (instr->hydrogen()->key()->representation().IsTagged()) {
- __ SmiToInteger64(key_reg, key_reg);
- } else if (instr->hydrogen()->IsDehoisted()) {
- // Sign extend key because it could be a 32 bit negative value
- // and the dehoisted address computation happens in 64 bits
- __ movsxlq(key_reg, key_reg);
- }
- }
-
+ PrepareKeyForKeyedOp<HStoreKeyed>(instr->hydrogen(), key);
if (instr->NeedsCanonicalization()) {
Label have_value;
@@ -3858,21 +3807,7 @@
Register value = ToRegister(instr->value());
Register elements = ToRegister(instr->elements());
LOperand* key = instr->key();
- if (!key->IsConstantOperand()) {
- Register key_reg = ToRegister(key);
- // Even though the HLoad/StoreKeyedFastElement instructions force
- // the input representation for the key to be an integer, the
- // input gets replaced during bound check elimination with the index
- // argument to the bounds check, which can be tagged, so that case
- // must be handled here, too.
- if (instr->hydrogen()->key()->representation().IsTagged()) {
- __ SmiToInteger64(key_reg, key_reg);
- } else if (instr->hydrogen()->IsDehoisted()) {
- // Sign extend key because it could be a 32 bit negative value
- // and the dehoisted address computation happens in 64 bits
- __ movsxlq(key_reg, key_reg);
- }
- }
+ PrepareKeyForKeyedOp<HStoreKeyed>(instr->hydrogen(), key);
Operand operand =
BuildFastArrayOperand(instr->elements(),
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Fri Nov 2
02:18:53 2012
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Fri Nov 9
02:21:07 2012
@@ -341,6 +341,8 @@
void DoStoreKeyedExternalArray(LStoreKeyed* instr);
void DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr);
void DoStoreKeyedFixedArray(LStoreKeyed* instr);
+ template <class T>
+ void PrepareKeyForKeyedOp(T* hydrogen_instr, LOperand* key);
Zone* zone_;
LPlatformChunk* const chunk_;
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.cc Mon Nov 5 05:28:10 2012
+++ /branches/bleeding_edge/src/x64/lithium-x64.cc Fri Nov 9 02:21:07 2012
@@ -1844,16 +1844,15 @@
ASSERT(instr->key()->representation().IsInteger32() ||
instr->key()->representation().IsTagged());
ElementsKind elements_kind = instr->elements_kind();
- bool clobbers_key = instr->key()->representation().IsTagged();
+ bool clobbers_key = ArrayOpClobbersKey<HLoadKeyed>(instr);
LOperand* key = clobbers_key
? UseTempRegister(instr->key())
: UseRegisterOrConstantAtStart(instr->key());
- LLoadKeyed* result = NULL;
+ LOperand* elements = UseRegisterAtStart(instr->elements());
+ LLoadKeyed* result = new(zone()) LLoadKeyed(elements, key);
- if (!instr->is_external()) {
- LOperand* obj = UseRegisterAtStart(instr->elements());
- result = new(zone()) LLoadKeyed(obj, key);
- } else {
+#ifdef DEBUG
+ if (instr->is_external()) {
ASSERT(
(instr->representation().IsInteger32() &&
(elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
@@ -1861,9 +1860,8 @@
(instr->representation().IsDouble() &&
((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
(elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
- LOperand* external_pointer = UseRegister(instr->elements());
- result = new(zone()) LLoadKeyed(external_pointer, key);
}
+#endif
DefineAsRegister(result);
bool can_deoptimize = instr->RequiresHoleCheck() ||
@@ -1884,33 +1882,21 @@
LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
- ElementsKind elements_kind = instr->elements_kind();
bool needs_write_barrier = instr->NeedsWriteBarrier();
- bool clobbers_key = instr->key()->representation().IsTagged();
+ bool clobbers_key = ArrayOpClobbersKey<HStoreKeyed>(instr);
LOperand* key = (clobbers_key || needs_write_barrier)
? UseTempRegister(instr->key())
: UseRegisterOrConstantAtStart(instr->key());
- bool val_is_temp_register =
- elements_kind == EXTERNAL_PIXEL_ELEMENTS ||
- elements_kind == EXTERNAL_FLOAT_ELEMENTS;
- LOperand* val = (needs_write_barrier || val_is_temp_register)
+ LOperand* val = needs_write_barrier
? UseTempRegister(instr->value())
: UseRegisterAtStart(instr->value());
- LStoreKeyed* result = NULL;
+ LOperand* elements = UseRegisterAtStart(instr->elements());
+#ifdef DEBUG
if (!instr->is_external()) {
ASSERT(instr->elements()->representation().IsTagged());
-
- LOperand* object = NULL;
- if (instr->value()->representation().IsDouble()) {
- object = UseRegisterAtStart(instr->elements());
- } else {
- ASSERT(instr->value()->representation().IsTagged());
- object = UseTempRegister(instr->elements());
- }
-
- result = new(zone()) LStoreKeyed(object, key, val);
} else {
+ ElementsKind elements_kind = instr->elements_kind();
ASSERT(
(instr->value()->representation().IsInteger32() &&
(elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
@@ -1919,11 +1905,10 @@
((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
(elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
ASSERT(instr->elements()->representation().IsExternal());
-
- LOperand* external_pointer = UseRegister(instr->elements());
- result = new(zone()) LStoreKeyed(external_pointer, key, val);
}
+#endif
+ LStoreKeyed* result = new(zone()) LStoreKeyed(elements, key, val);
ASSERT(result != NULL);
return result;
}
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.h Mon Nov 5 00:53:54 2012
+++ /branches/bleeding_edge/src/x64/lithium-x64.h Fri Nov 9 02:21:07 2012
@@ -1369,6 +1369,14 @@
return hydrogen()->elements_kind();
}
};
+
+
+template <class T>
+inline static bool ArrayOpClobbersKey(T *value) {
+ CHECK(value->IsLoadKeyed() || value->IsStoreKeyed());
+ return !value->IsConstant() && (value->key()->representation().IsTagged()
+ || value->IsDehoisted());
+}
class LLoadKeyedGeneric: public LTemplateInstruction<1, 2, 0> {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev