Reviewers: ulan, jochen,

Description:
A64: ElementsKind TODOs

Replace LoadElementsKind with LoadElementsKindFromMap, remove unneeded TODO in DoStringCharFromCode, improve constraints for DoCheckValue and improve code for
ElementsKind checking in StoreArrayLiteralElementStub.

BUG=

Please review this at https://codereview.chromium.org/202853005/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+31, -54 lines):
  M src/a64/code-stubs-a64.cc
  M src/a64/lithium-a64.h
  M src/a64/lithium-a64.cc
  M src/a64/lithium-codegen-a64.cc
  M src/a64/macro-assembler-a64.h
  M src/a64/macro-assembler-a64.cc


Index: src/a64/code-stubs-a64.cc
diff --git a/src/a64/code-stubs-a64.cc b/src/a64/code-stubs-a64.cc
index 2996df9b82d6863bb54e67739a22c9ba7415f4c8..18b1f3eeb0c973376b4f753921638644435e88a4 100644
--- a/src/a64/code-stubs-a64.cc
+++ b/src/a64/code-stubs-a64.cc
@@ -4796,12 +4796,6 @@ void RecordWriteStub::Generate(MacroAssembler* masm) {


 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
-  // TODO(all): Possible optimisations in this function:
-  // 1. Merge CheckFastElements and CheckFastSmiElements, so that the map
-  //    bitfield is loaded only once.
-  // 2. Refactor the Ldr/Add sequence at the start of fast_elements and
-  //    smi_element.
-
   // x0     value            element value to store
   // x3     index_smi        element index as smi
   // sp[0]  array_index_smi  array literal index in function as smi
@@ -4817,9 +4811,23 @@ void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
   __ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));

   Label double_elements, smi_element, fast_elements, slow_elements;
-  __ CheckFastElements(array_map, x10, &double_elements);
+  Register bitfield2 = x10;
+  __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
+
+ // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
+  // FAST_HOLEY_ELEMENTS.
+  STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
+  STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
+  STATIC_ASSERT(FAST_ELEMENTS == 2);
+  STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
+  __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
+  __ B(hi, &double_elements);
+
   __ JumpIfSmi(value, &smi_element);
-  __ CheckFastSmiElements(array_map, x10, &fast_elements);
+
+ // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
+  __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::kElementsKindShift),
+          &fast_elements);

// Store into the array literal requires an elements transition. Call into
   // the runtime.
@@ -5545,12 +5553,8 @@ void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
   __ Ldr(x10, FieldMemOperand(constructor,
                               JSFunction::kPrototypeOrInitialMapOffset));

-  // TODO(jbramley): Add a helper function to read elements kind from an
-  // existing map.
-  // Load the map's "bit field 2" into result.
-  __ Ldr(kind, FieldMemOperand(x10, Map::kBitField2Offset));
-  // Retrieve elements_kind from bit field 2.
-  __ Ubfx(kind, kind, Map::kElementsKindShift, Map::kElementsKindBitCount);
+  // Retrieve elements_kind from map.
+  __ LoadElementsKindFromMap(kind, x10);

   if (FLAG_debug_code) {
     Label done;
Index: src/a64/lithium-a64.cc
diff --git a/src/a64/lithium-a64.cc b/src/a64/lithium-a64.cc
index cc785dde53212b25b4aa3f0bda4d1d0a849172d5..1c3b24eba81c6576f08ef3db005e81639bdb269d 100644
--- a/src/a64/lithium-a64.cc
+++ b/src/a64/lithium-a64.cc
@@ -1176,12 +1176,8 @@ LInstruction* LChunkBuilder::DoChange(HChange* instr) {


 LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
- // We only need a temp register if the target is in new space, but we can't
-  // dereference the handle to test that here.
- // TODO(all): Check these constraints. The temp register is not always used.
-  LOperand* value = UseRegister(instr->value());
-  LOperand* temp = TempRegister();
-  return AssignEnvironment(new(zone()) LCheckValue(value, temp));
+  LOperand* value = UseRegisterAtStart(instr->value());
+  return AssignEnvironment(new(zone()) LCheckValue(value));
 }


@@ -2292,7 +2288,6 @@ LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {


LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
-  // TODO(all) use at start and remove assert in codegen
   LOperand* char_code = UseRegister(instr->value());
   LOperand* context = UseAny(instr->context());
   LStringCharFromCode* result =
@@ -2320,7 +2315,7 @@ LInstruction* LChunkBuilder::DoSub(HSub* instr) {
ASSERT(instr->right()->representation().Equals(instr->representation()));
     LOperand *left;
     if (instr->left()->IsConstant() &&
-       (HConstant::cast(instr->left())->Integer32Value() == 0)) {
+        (HConstant::cast(instr->left())->Integer32Value() == 0)) {
       left = UseConstant(instr->left());
     } else {
       left = UseRegisterAtStart(instr->left());
Index: src/a64/lithium-a64.h
diff --git a/src/a64/lithium-a64.h b/src/a64/lithium-a64.h
index 7f96df18ae9b3b62f5fea1d3f9cb35d6512fd2c7..a100da84ed065adcdbe672bfa068273d10185860 100644
--- a/src/a64/lithium-a64.h
+++ b/src/a64/lithium-a64.h
@@ -965,15 +965,13 @@ class LCheckSmi V8_FINAL : public LTemplateInstruction<1, 1, 0> {
 };


-class LCheckValue V8_FINAL : public LTemplateInstruction<0, 1, 1> {
+class LCheckValue V8_FINAL : public LTemplateInstruction<0, 1, 0> {
  public:
-  LCheckValue(LOperand* value, LOperand* temp) {
+  explicit LCheckValue(LOperand* value) {
     inputs_[0] = value;
-    temps_[0] = temp;
   }

   LOperand* value() { return inputs_[0]; }
-  LOperand* temp() { return temps_[0]; }

   DECLARE_CONCRETE_INSTRUCTION(CheckValue, "check-value")
   DECLARE_HYDROGEN_ACCESSOR(CheckValue)
Index: src/a64/lithium-codegen-a64.cc
diff --git a/src/a64/lithium-codegen-a64.cc b/src/a64/lithium-codegen-a64.cc
index 6c29abdcff467eaf2cfa923d92ce7438ae20195d..ad5e7a254db4c9e61d77ef56a83238c9ead7abae 100644
--- a/src/a64/lithium-codegen-a64.cc
+++ b/src/a64/lithium-codegen-a64.cc
@@ -2535,7 +2535,8 @@ void LCodeGen::DoCheckValue(LCheckValue* instr) {
   Handle<HeapObject> object = instr->hydrogen()->object().handle();
   AllowDeferredHandleDereference smi_check;
   if (isolate()->heap()->InNewSpace(*object)) {
-    Register temp = ToRegister(instr->temp());
+    UseScratchRegisterScope temps(masm());
+    Register temp = temps.AcquireX();
     Handle<Cell> cell = isolate()->factory()->NewCell(object);
     __ Mov(temp, Operand(Handle<Object>(cell)));
     __ Ldr(temp, FieldMemOperand(temp, Cell::kValueOffset));
Index: src/a64/macro-assembler-a64.cc
diff --git a/src/a64/macro-assembler-a64.cc b/src/a64/macro-assembler-a64.cc
index ca61b491632fa523ee997f33c90e577d908bfe7f..d26c2d003dc12099a36f08e290c520199dd60cd3 100644
--- a/src/a64/macro-assembler-a64.cc
+++ b/src/a64/macro-assembler-a64.cc
@@ -3644,11 +3644,9 @@ void MacroAssembler::TestMapBitfield(Register object, uint64_t mask) {
 }


-void MacroAssembler::LoadElementsKind(Register result, Register object) {
-  // Load map.
-  __ Ldr(result, FieldMemOperand(object, HeapObject::kMapOffset));
+void MacroAssembler::LoadElementsKindFromMap(Register result, Register map) {
   // Load the map's "bit field 2".
-  __ Ldrb(result, FieldMemOperand(result, Map::kBitField2Offset));
+  __ Ldrb(result, FieldMemOperand(map, Map::kBitField2Offset));
   // Retrieve elements_kind from bit field 2.
__ Ubfx(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount);
 }
@@ -3806,17 +3804,6 @@ void MacroAssembler::CheckFastObjectElements(Register map,
 }


-void MacroAssembler::CheckFastSmiElements(Register map,
-                                          Register scratch,
-                                          Label* fail) {
-  STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
-  STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
-  Ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset));
-  Cmp(scratch, Map::kMaximumBitField2FastHoleySmiElementValue);
-  B(hi, fail);
-}
-
-
// Note: The ARM version of this clobbers elements_reg, but this version does // not. Some uses of this in A64 assume that elements_reg will be preserved.
 void MacroAssembler::StoreNumberToDoubleElements(Register value_reg,
Index: src/a64/macro-assembler-a64.h
diff --git a/src/a64/macro-assembler-a64.h b/src/a64/macro-assembler-a64.h
index bbc573aad866ed5c09b3e7cc7e598c600d35f066..346d5754903c4fbe76be951e0c41c22273f51a7b 100644
--- a/src/a64/macro-assembler-a64.h
+++ b/src/a64/macro-assembler-a64.h
@@ -1469,9 +1469,9 @@ class MacroAssembler : public Assembler {
   // flags. The object register is preserved.
   void TestMapBitfield(Register object, uint64_t mask);

-  // Load the elements kind field of an object, and return it in the result
+  // Load the elements kind field from a map, and return it in the result
   // register.
-  void LoadElementsKind(Register result, Register object);
+  void LoadElementsKindFromMap(Register result, Register map);

   // Compare the object in a register to a value from the root list.
   void CompareRoot(const Register& obj, Heap::RootListIndex index);
@@ -1535,19 +1535,11 @@ class MacroAssembler : public Assembler {

// Check if a map for a JSObject indicates that the object has fast elements.
   // Jump to the specified label if it does not.
-  void CheckFastElements(Register map,
-                         Register scratch,
-                         Label* fail);
+  void CheckFastElements(Register map, Register scratch, Label* fail);

// Check if a map for a JSObject indicates that the object can have both smi
   // and HeapObject elements.  Jump to the specified label if it does not.
-  void CheckFastObjectElements(Register map,
-                               Register scratch,
-                               Label* fail);
-
- // Check if a map for a JSObject indicates that the object has fast smi only
-  // elements. Jump to the specified label if it does not.
-  void CheckFastSmiElements(Register map, Register scratch, Label* fail);
+ void CheckFastObjectElements(Register map, Register scratch, Label* fail);

// Check to see if number can be stored as a double in FastDoubleElements.
   // If it can, store it at the index specified by key_reg in the array,


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to