Revision: 16002
Author:   [email protected]
Date:     Thu Aug  1 01:42:47 2013
Log:      Get rid of HStringLength.

Use HLoadNamedField to load the string length field instead.

Depends on: https://codereview.chromium.org/21488002

[email protected]

Review URL: https://codereview.chromium.org/21499002
http://code.google.com/p/v8/source/detail?r=16002

Modified:
 /branches/bleeding_edge/src/arm/lithium-arm.cc
 /branches/bleeding_edge/src/arm/lithium-arm.h
 /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
 /branches/bleeding_edge/src/hydrogen-instructions.cc
 /branches/bleeding_edge/src/hydrogen-instructions.h
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/hydrogen.h
 /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/mips/lithium-codegen-mips.cc
 /branches/bleeding_edge/src/mips/lithium-mips.cc
 /branches/bleeding_edge/src/mips/lithium-mips.h
 /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
 /branches/bleeding_edge/src/x64/lithium-x64.cc
 /branches/bleeding_edge/src/x64/lithium-x64.h

=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.cc      Wed Jul 31 03:47:44 2013
+++ /branches/bleeding_edge/src/arm/lithium-arm.cc      Thu Aug  1 01:42:47 2013
@@ -2391,12 +2391,6 @@
   LStringCharFromCode* result = new(zone()) LStringCharFromCode(char_code);
   return AssignPointerMap(DefineAsRegister(result));
 }
-
-
-LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
-  LOperand* string = UseRegisterAtStart(instr->value());
-  return DefineAsRegister(new(zone()) LStringLength(string));
-}


 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.h       Wed Jul 31 03:47:44 2013
+++ /branches/bleeding_edge/src/arm/lithium-arm.h       Thu Aug  1 01:42:47 2013
@@ -175,7 +175,6 @@
   V(StringCharCodeAt)                           \
   V(StringCharFromCode)                         \
   V(StringCompareAndBranch)                     \
-  V(StringLength)                               \
   V(SubI)                                       \
   V(RSubI)                                      \
   V(TaggedToI)                                  \
@@ -2314,19 +2313,6 @@
 };


-class LStringLength: public LTemplateInstruction<1, 1, 0> {
- public:
-  explicit LStringLength(LOperand* string) {
-    inputs_[0] = string;
-  }
-
-  LOperand* string() { return inputs_[0]; }
-
-  DECLARE_CONCRETE_INSTRUCTION(StringLength, "string-length")
-  DECLARE_HYDROGEN_ACCESSOR(StringLength)
-};
-
-
 class LCheckFunction: public LTemplateInstruction<0, 1, 0> {
  public:
   explicit LCheckFunction(LOperand* value) {
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Jul 31 05:46:54 2013 +++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Thu Aug 1 01:42:47 2013
@@ -4643,13 +4643,6 @@
   CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr);
   __ StoreToSafepointRegisterSlot(r0, result);
 }
-
-
-void LCodeGen::DoStringLength(LStringLength* instr) {
-  Register string = ToRegister(instr->string());
-  Register result = ToRegister(instr->result());
-  __ ldr(result, FieldMemOperand(string, String::kLengthOffset));
-}


 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Thu Aug 1 01:27:46 2013 +++ /branches/bleeding_edge/src/hydrogen-instructions.cc Thu Aug 1 01:42:47 2013
@@ -3048,6 +3048,14 @@
   }
   return HValue::InferRange(zone);
 }
+
+
+Range* HLoadNamedField::InferRange(Zone* zone) {
+  if (access().IsStringLength()) {
+    return new(zone) Range(0, String::kMaxLength);
+  }
+  return HValue::InferRange(zone);
+}


 Range* HLoadKeyed::InferRange(Zone* zone) {
@@ -3935,17 +3943,6 @@
   }
   return new(zone) HStringCharFromCode(context, char_code);
 }
-
-
-HInstruction* HStringLength::New(Zone* zone, HValue* context, HValue* string) {
-  if (FLAG_fold_constants && string->IsConstant()) {
-    HConstant* c_string = HConstant::cast(string);
-    if (c_string->HasStringValue()) {
- return HConstant::New(zone, context, c_string->StringValue()->length());
-    }
-  }
-  return new(zone) HStringLength(string);
-}


 HInstruction* HUnaryMathOperation::New(
@@ -4425,6 +4422,10 @@
       instr->SetGVNFlag(is_store
           ? kChangesArrayLengths : kDependsOnArrayLengths);
       break;
+    case kStringLengths:
+      instr->SetGVNFlag(is_store
+          ? kChangesStringLengths : kDependsOnStringLengths);
+      break;
     case kInobject:
       instr->SetGVNFlag(is_store
           ? kChangesInobjectFields : kDependsOnInobjectFields);
@@ -4458,6 +4459,7 @@

   switch (portion()) {
     case kArrayLengths:
+    case kStringLengths:
       stream->Add("%length");
       break;
     case kElementsPointer:
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Thu Aug 1 01:34:36 2013 +++ /branches/bleeding_edge/src/hydrogen-instructions.h Thu Aug 1 01:42:47 2013
@@ -178,7 +178,6 @@
   V(StringCharCodeAt)                          \
   V(StringCharFromCode)                        \
   V(StringCompareAndBranch)                    \
-  V(StringLength)                              \
   V(Sub)                                       \
   V(ThisFunction)                              \
   V(Throw)                                     \
@@ -200,6 +199,7 @@
 #define GVN_UNTRACKED_FLAG_LIST(V)             \
   V(ArrayElements)                             \
   V(ArrayLengths)                              \
+  V(StringLengths)                             \
   V(BackingStoreFields)                        \
   V(Calls)                                     \
   V(ContextSlots)                              \
@@ -5839,6 +5839,10 @@
   inline bool IsExternalMemory() const {
     return portion() == kExternalMemory;
   }
+
+  inline bool IsStringLength() const {
+    return portion() == kStringLengths;
+  }

   inline int offset() const {
     return OffsetField::decode(value_);
@@ -5892,6 +5896,14 @@
         FixedArray::kLengthOffset,
FLAG_track_fields ? Representation::Smi() : Representation::Tagged());
   }
+
+  static HObjectAccess ForStringLength() {
+    STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
+    return HObjectAccess(
+        kStringLengths,
+        String::kLengthOffset,
+ FLAG_track_fields ? Representation::Smi() : Representation::Tagged());
+  }

   static HObjectAccess ForPropertiesPointer() {
     return HObjectAccess(kInobject, JSObject::kPropertiesOffset);
@@ -5956,6 +5968,7 @@
   enum Portion {
     kMaps,             // map of an object
     kArrayLengths,     // the length of an array
+    kStringLengths,    // the length of a string
     kElementsPointer,  // elements pointer
     kBackingStore,     // some field in the backing store
     kDouble,           // some double field
@@ -6018,6 +6031,7 @@
     }
     return Representation::Tagged();
   }
+  virtual Range* InferRange(Zone* zone);
   virtual void PrintDataTo(StringStream* stream);

   DECLARE_CONCRETE_INSTRUCTION(LoadNamedField)
@@ -6853,36 +6867,6 @@
 };


-class HStringLength: public HUnaryOperation {
- public:
-  static HInstruction* New(Zone* zone, HValue* context, HValue* string);
-
-  virtual Representation RequiredInputRepresentation(int index) {
-    return Representation::Tagged();
-  }
-
-  DECLARE_CONCRETE_INSTRUCTION(StringLength)
-
- protected:
-  virtual bool DataEquals(HValue* other) { return true; }
-
-  virtual Range* InferRange(Zone* zone) {
-    return new(zone) Range(0, String::kMaxLength);
-  }
-
- private:
-  explicit HStringLength(HValue* string)
-      : HUnaryOperation(string, HType::Smi()) {
-    STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
-    set_representation(Representation::Tagged());
-    SetFlag(kUseGVN);
-    SetGVNFlag(kDependsOnMaps);
-  }
-
-  virtual bool IsDeletable() const { return true; }
-};
-
-
 template <int V>
 class HMaterializedLiteral: public HTemplateInstruction<V> {
  public:
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Thu Aug  1 01:34:36 2013
+++ /branches/bleeding_edge/src/hydrogen.cc     Thu Aug  1 01:42:47 2013
@@ -5314,7 +5314,8 @@


 HLoadNamedField* HGraphBuilder::BuildLoadNamedField(HValue* object,
-                                                    HObjectAccess access) {
+                                                    HObjectAccess access,
+                                                    HValue* typecheck) {
   if (FLAG_track_double_fields && access.representation().IsDouble()) {
     // load the heap number
     HLoadNamedField* heap_number = Add<HLoadNamedField>(
@@ -5322,9 +5323,23 @@
     heap_number->set_type(HType::HeapNumber());
     // load the double value from it
     return New<HLoadNamedField>(heap_number,
-                                HObjectAccess::ForHeapNumberValue());
+                                HObjectAccess::ForHeapNumberValue(),
+                                typecheck);
   }
-  return New<HLoadNamedField>(object, access);
+  return New<HLoadNamedField>(object, access, typecheck);
+}
+
+
+HInstruction* HGraphBuilder::BuildLoadStringLength(HValue* object,
+                                                   HValue* typecheck) {
+  if (FLAG_fold_constants && object->IsConstant()) {
+    HConstant* constant = HConstant::cast(object);
+    if (constant->HasStringValue()) {
+      return New<HConstant>(constant->StringValue()->length());
+    }
+  }
+  return BuildLoadNamedField(
+      object, HObjectAccess::ForStringLength(), typecheck);
 }


@@ -5808,8 +5823,9 @@
   if (expr->IsStringLength()) {
     HValue* string = Pop();
     BuildCheckHeapObject(string);
-    AddInstruction(HCheckInstanceType::NewIsString(string, zone()));
-    instr = NewUncasted<HStringLength>(string);
+    HInstruction* checkstring =
+        AddInstruction(HCheckInstanceType::NewIsString(string, zone()));
+    instr = BuildLoadStringLength(string, checkstring);
   } else if (expr->IsStringAccess()) {
     CHECK_ALIVE(VisitForValue(expr->key()));
     HValue* index = Pop();
@@ -7587,8 +7603,10 @@
     }
   }
   BuildCheckHeapObject(string);
-  AddInstruction(HCheckInstanceType::NewIsString(string, zone()));
-  HInstruction* length = Add<HStringLength>(string);
+  HValue* checkstring =
+      AddInstruction(HCheckInstanceType::NewIsString(string, zone()));
+  HInstruction* length = BuildLoadStringLength(string, checkstring);
+  AddInstruction(length);
   HInstruction* checked_index = Add<HBoundsCheck>(index, length);
   return New<HStringCharCodeAt>(string, checked_index);
 }
=======================================
--- /branches/bleeding_edge/src/hydrogen.h      Wed Jul 31 07:58:39 2013
+++ /branches/bleeding_edge/src/hydrogen.h      Thu Aug  1 01:42:47 2013
@@ -1237,10 +1237,6 @@
       LoadKeyedHoleMode load_mode,
       KeyedAccessStoreMode store_mode);

-  HLoadNamedField* BuildLoadNamedField(
-      HValue* object,
-      HObjectAccess access);
-
   HInstruction* AddExternalArrayElementAccess(
       HValue* external_elements,
       HValue* checked_key,
@@ -1259,6 +1255,11 @@
       LoadKeyedHoleMode load_mode,
       KeyedAccessStoreMode store_mode);

+  HLoadNamedField* BuildLoadNamedField(
+      HValue* object,
+      HObjectAccess access,
+      HValue* typecheck = NULL);
+ HInstruction* BuildLoadStringLength(HValue* object, HValue* typecheck = NULL);
   HStoreNamedField* AddStoreMapConstant(HValue *object, Handle<Map>);
HLoadNamedField* AddLoadElements(HValue *object, HValue *typecheck = NULL);
   HLoadNamedField* AddLoadFixedArrayLength(HValue *object);
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Jul 31 06:45:51 2013 +++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Aug 1 01:42:47 2013
@@ -4860,13 +4860,6 @@
CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context());
   __ StoreToSafepointRegisterSlot(result, eax);
 }
-
-
-void LCodeGen::DoStringLength(LStringLength* instr) {
-  Register string = ToRegister(instr->string());
-  Register result = ToRegister(instr->result());
-  __ mov(result, FieldOperand(string, String::kLengthOffset));
-}


 void LCodeGen::DoStringAdd(LStringAdd* instr) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.cc Wed Jul 31 03:47:44 2013 +++ /branches/bleeding_edge/src/ia32/lithium-ia32.cc Thu Aug 1 01:42:47 2013
@@ -2512,12 +2512,6 @@
       new(zone()) LStringCharFromCode(context, char_code);
   return AssignPointerMap(DefineAsRegister(result));
 }
-
-
-LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
-  LOperand* string = UseRegisterAtStart(instr->value());
-  return DefineAsRegister(new(zone()) LStringLength(string));
-}


 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.h     Wed Jul 31 03:47:44 2013
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.h     Thu Aug  1 01:42:47 2013
@@ -174,7 +174,6 @@
   V(StringCharCodeAt)                           \
   V(StringCharFromCode)                         \
   V(StringCompareAndBranch)                     \
-  V(StringLength)                               \
   V(SubI)                                       \
   V(TaggedToI)                                  \
   V(TaggedToINoSSE2)                            \
@@ -2411,19 +2410,6 @@
 };


-class LStringLength: public LTemplateInstruction<1, 1, 0> {
- public:
-  explicit LStringLength(LOperand* string) {
-    inputs_[0] = string;
-  }
-
-  LOperand* string() { return inputs_[0]; }
-
-  DECLARE_CONCRETE_INSTRUCTION(StringLength, "string-length")
-  DECLARE_HYDROGEN_ACCESSOR(StringLength)
-};
-
-
 class LCheckFunction: public LTemplateInstruction<0, 1, 0> {
  public:
   explicit LCheckFunction(LOperand* value) {
=======================================
--- /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Wed Jul 31 05:46:54 2013 +++ /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Thu Aug 1 01:42:47 2013
@@ -4594,13 +4594,6 @@
   CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr);
   __ StoreToSafepointRegisterSlot(v0, result);
 }
-
-
-void LCodeGen::DoStringLength(LStringLength* instr) {
-  Register string = ToRegister(instr->string());
-  Register result = ToRegister(instr->result());
-  __ lw(result, FieldMemOperand(string, String::kLengthOffset));
-}


 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) {
=======================================
--- /branches/bleeding_edge/src/mips/lithium-mips.cc Wed Jul 31 03:47:44 2013 +++ /branches/bleeding_edge/src/mips/lithium-mips.cc Thu Aug 1 01:42:47 2013
@@ -2314,12 +2314,6 @@
   LStringCharFromCode* result = new(zone()) LStringCharFromCode(char_code);
   return AssignPointerMap(DefineAsRegister(result));
 }
-
-
-LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
-  LOperand* string = UseRegisterAtStart(instr->value());
-  return DefineAsRegister(new(zone()) LStringLength(string));
-}


 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
=======================================
--- /branches/bleeding_edge/src/mips/lithium-mips.h     Wed Jul 31 03:47:44 2013
+++ /branches/bleeding_edge/src/mips/lithium-mips.h     Thu Aug  1 01:42:47 2013
@@ -174,7 +174,6 @@
   V(StringCharCodeAt)                           \
   V(StringCharFromCode)                         \
   V(StringCompareAndBranch)                     \
-  V(StringLength)                               \
   V(SubI)                                       \
   V(TaggedToI)                                  \
   V(ThisFunction)                               \
@@ -2286,19 +2285,6 @@
 };


-class LStringLength: public LTemplateInstruction<1, 1, 0> {
- public:
-  explicit LStringLength(LOperand* string) {
-    inputs_[0] = string;
-  }
-
-  LOperand* string() { return inputs_[0]; }
-
-  DECLARE_CONCRETE_INSTRUCTION(StringLength, "string-length")
-  DECLARE_HYDROGEN_ACCESSOR(StringLength)
-};
-
-
 class LCheckFunction: public LTemplateInstruction<0, 1, 0> {
  public:
   explicit LCheckFunction(LOperand* value) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Jul 31 06:45:51 2013 +++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Aug 1 01:42:47 2013
@@ -4443,13 +4443,6 @@
   CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr);
   __ StoreToSafepointRegisterSlot(result, rax);
 }
-
-
-void LCodeGen::DoStringLength(LStringLength* instr) {
-  Register string = ToRegister(instr->string());
-  Register result = ToRegister(instr->result());
-  __ movq(result, FieldOperand(string, String::kLengthOffset));
-}


 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.cc      Wed Jul 31 03:47:44 2013
+++ /branches/bleeding_edge/src/x64/lithium-x64.cc      Thu Aug  1 01:42:47 2013
@@ -2318,12 +2318,6 @@
   LStringCharFromCode* result = new(zone()) LStringCharFromCode(char_code);
   return AssignPointerMap(DefineAsRegister(result));
 }
-
-
-LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
-  LOperand* string = UseRegisterAtStart(instr->value());
-  return DefineAsRegister(new(zone()) LStringLength(string));
-}


 LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.h       Wed Jul 31 03:47:44 2013
+++ /branches/bleeding_edge/src/x64/lithium-x64.h       Thu Aug  1 01:42:47 2013
@@ -173,7 +173,6 @@
   V(StringCharCodeAt)                           \
   V(StringCharFromCode)                         \
   V(StringCompareAndBranch)                     \
-  V(StringLength)                               \
   V(SubI)                                       \
   V(TaggedToI)                                  \
   V(ThisFunction)                               \
@@ -2224,19 +2223,6 @@
 };


-class LStringLength: public LTemplateInstruction<1, 1, 0> {
- public:
-  explicit LStringLength(LOperand* string) {
-    inputs_[0] = string;
-  }
-
-  LOperand* string() { return inputs_[0]; }
-
-  DECLARE_CONCRETE_INSTRUCTION(StringLength, "string-length")
-  DECLARE_HYDROGEN_ACCESSOR(StringLength)
-};
-
-
 class LCheckFunction: public LTemplateInstruction<0, 1, 0> {
  public:
   explicit LCheckFunction(LOperand* value) {

--
--
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/groups/opt_out.


Reply via email to