Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: src/hydrogen-instructions.h

Issue 14284010: Introduce HObjectAccess, which is used by LoadNamedField and StoreNamedField to denote what parts (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make constructor of HObjectAccess and HObjectAccess::Portion private. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5168 matching lines...) Expand 10 before | Expand all | Expand 10 after
5179 virtual void PrintDataTo(StringStream* stream); 5179 virtual void PrintDataTo(StringStream* stream);
5180 5180
5181 DECLARE_CONCRETE_INSTRUCTION(StoreContextSlot) 5181 DECLARE_CONCRETE_INSTRUCTION(StoreContextSlot)
5182 5182
5183 private: 5183 private:
5184 int slot_index_; 5184 int slot_index_;
5185 Mode mode_; 5185 Mode mode_;
5186 }; 5186 };
5187 5187
5188 5188
5189 // Represents an access to a portion of an object, such as the map pointer,
5190 // array elements pointer, etc, but not accesses to array elements themselves.
5191 class HObjectAccess {
5192 public:
5193 inline bool IsInobject() const {
5194 return portion_ != kBackingStore;
5195 }
5196
5197 inline int offset() const {
5198 return offset_;
5199 }
5200
5201 inline Handle<String> name() const {
5202 return name_;
5203 }
5204
5205 static HObjectAccess ForElementsPointer() {
5206 return HObjectAccess(kElementsPointer, JSObject::kElementsOffset);
5207 }
5208
5209 static HObjectAccess ForArrayLength() {
5210 return HObjectAccess(kArrayLengths, JSArray::kLengthOffset);
5211 }
5212
5213 static HObjectAccess ForFixedArrayLength() {
5214 return HObjectAccess(kInobject, FixedArray::kLengthOffset);
5215 }
5216
5217 static HObjectAccess ForMap() {
5218 return HObjectAccess(kMaps, JSObject::kMapOffset);
5219 }
5220
5221 // Create an access to a property in an object or backing store
5222 static HObjectAccess For(bool is_inobject, int offset);
danno 2013/05/08 12:05:35 This should be "ForJSObjectField". It only works f
titzer 2013/05/08 15:15:45 The only remaining use of this is for accessing a
5223
5224 // Create an access to an in-object property in an object
5225 static HObjectAccess ForOffset(int offset,
danno 2013/05/08 12:05:35 This guy is *super* dangerous. Either it should on
titzer 2013/05/08 15:15:45 I've split it apart into ForJSObjectOffset, ForJSA
5226 Handle<String> name = Handle<String>::null());
5227
5228 // Create an access to a resolved field (in-object or backing store)
5229 static HObjectAccess ForField(Handle<Map> map,
5230 LookupResult *lookup, Handle<String> name = Handle<String>::null());
5231
5232 void PrintTo(StringStream* stream);
5233
5234 protected:
5235 void SetGVNFlags(HValue *instr, bool is_store);
5236
5237 private:
5238 // internal use only; different parts of an object or array
5239 enum Portion {
5240 kMaps, // map of an object
5241 kArrayLengths, // the length of an array
5242 kElementsPointer, // elements pointer
5243 kBackingStore, // some field in the backing store
5244 kInobject // some other in-object field
5245 };
5246
5247 HObjectAccess(Portion portion, int offset,
5248 Handle<String> name = Handle<String>::null())
5249 : portion_(portion), offset_(offset), name_(name) {
5250 ASSERT(offset_ == offset); // offset must fit
5251 ASSERT(portion_ == portion); // portion must fit
5252 }
5253
5254 unsigned portion_ : 3;
5255 unsigned offset_ : 29;
5256 Handle<String> name_;
5257
5258 friend class HLoadNamedField;
5259 friend class HStoreNamedField;
5260 };
5261
5262
5189 class HLoadNamedField: public HTemplateInstruction<2> { 5263 class HLoadNamedField: public HTemplateInstruction<2> {
5190 public: 5264 public:
5191 HLoadNamedField(HValue* object, bool is_in_object, 5265 HLoadNamedField(HValue* object,
5192 Representation field_representation, 5266 HObjectAccess access,
5193 int offset, HValue* typecheck = NULL) 5267 HValue* typecheck = NULL,
5194 : is_in_object_(is_in_object), 5268 Representation representation = Representation::Tagged())
5195 field_representation_(field_representation), 5269 : access_(access),
5196 offset_(offset) { 5270 field_representation_(representation) {
5197 ASSERT(object != NULL); 5271 ASSERT(object != NULL);
5198 SetOperandAt(0, object); 5272 SetOperandAt(0, object);
5199 SetOperandAt(1, typecheck != NULL ? typecheck : object); 5273 SetOperandAt(1, typecheck != NULL ? typecheck : object);
5200 5274
5201 if (FLAG_track_fields && field_representation.IsSmi()) { 5275 set_representation(Representation::Tagged());
5202 set_type(HType::Smi()); 5276 access.SetGVNFlags(this, false);
5203 set_representation(Representation::Tagged());
5204 } else if (FLAG_track_double_fields && field_representation.IsDouble()) {
5205 set_representation(field_representation);
5206 } else {
5207 set_representation(Representation::Tagged());
5208 }
5209 SetFlag(kUseGVN);
5210 SetGVNFlag(kDependsOnMaps);
5211 if (is_in_object) {
5212 SetGVNFlag(kDependsOnInobjectFields);
5213 } else {
5214 SetGVNFlag(kDependsOnBackingStoreFields);
5215 }
5216 }
5217
5218 static HLoadNamedField* NewArrayLength(Zone* zone, HValue* object,
5219 HValue* typecheck,
5220 HType type = HType::Tagged()) {
5221 Representation representation =
5222 type.IsSmi() ? Representation::Smi() : Representation::Tagged();
5223 HLoadNamedField* result = new(zone) HLoadNamedField(
5224 object, true, representation, JSArray::kLengthOffset, typecheck);
5225 result->set_type(type);
5226 result->SetGVNFlag(kDependsOnArrayLengths);
5227 result->ClearGVNFlag(kDependsOnInobjectFields);
5228 return result;
5229 } 5277 }
5230 5278
5231 HValue* object() { return OperandAt(0); } 5279 HValue* object() { return OperandAt(0); }
5232 HValue* typecheck() { 5280 HValue* typecheck() {
5233 ASSERT(HasTypeCheck()); 5281 ASSERT(HasTypeCheck());
5234 return OperandAt(1); 5282 return OperandAt(1);
5235 } 5283 }
5236 5284
5237 bool HasTypeCheck() const { return OperandAt(0) != OperandAt(1); } 5285 bool HasTypeCheck() const { return OperandAt(0) != OperandAt(1); }
5238 bool is_in_object() const { return is_in_object_; } 5286 bool is_in_object() const { return access_.IsInobject(); }
5239 Representation field_representation() const { return representation_; } 5287 Representation field_representation() const { return representation_; }
5240 int offset() const { return offset_; } 5288 int offset() const { return access_.offset(); }
5241 5289
5242 virtual Representation RequiredInputRepresentation(int index) { 5290 virtual Representation RequiredInputRepresentation(int index) {
5243 return Representation::Tagged(); 5291 return Representation::Tagged();
5244 } 5292 }
5245 virtual void PrintDataTo(StringStream* stream); 5293 virtual void PrintDataTo(StringStream* stream);
5246 5294
5247 DECLARE_CONCRETE_INSTRUCTION(LoadNamedField) 5295 DECLARE_CONCRETE_INSTRUCTION(LoadNamedField)
5248 5296
5249 protected: 5297 protected:
5250 virtual bool DataEquals(HValue* other) { 5298 virtual bool DataEquals(HValue* other) {
5251 HLoadNamedField* b = HLoadNamedField::cast(other); 5299 HLoadNamedField* b = HLoadNamedField::cast(other);
5252 return is_in_object_ == b->is_in_object_ && offset_ == b->offset_; 5300 return is_in_object() == b->is_in_object() && offset() == b->offset();
5253 } 5301 }
5254 5302
5255 private: 5303 private:
5256 virtual bool IsDeletable() const { return true; } 5304 virtual bool IsDeletable() const { return true; }
5257 5305
5258 bool is_in_object_; 5306 HObjectAccess access_;
5259 Representation field_representation_; 5307 Representation field_representation_;
5260 int offset_;
5261 }; 5308 };
5262 5309
5263 5310
5264 class HLoadNamedFieldPolymorphic: public HTemplateInstruction<2> { 5311 class HLoadNamedFieldPolymorphic: public HTemplateInstruction<2> {
5265 public: 5312 public:
5266 HLoadNamedFieldPolymorphic(HValue* context, 5313 HLoadNamedFieldPolymorphic(HValue* context,
5267 HValue* object, 5314 HValue* object,
5268 SmallMapList* types, 5315 SmallMapList* types,
5269 Handle<String> name, 5316 Handle<String> name,
5270 Zone* zone); 5317 Zone* zone);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
5544 5591
5545 virtual HValue* Canonicalize(); 5592 virtual HValue* Canonicalize();
5546 5593
5547 DECLARE_CONCRETE_INSTRUCTION(LoadKeyedGeneric) 5594 DECLARE_CONCRETE_INSTRUCTION(LoadKeyedGeneric)
5548 }; 5595 };
5549 5596
5550 5597
5551 class HStoreNamedField: public HTemplateInstruction<2> { 5598 class HStoreNamedField: public HTemplateInstruction<2> {
5552 public: 5599 public:
5553 HStoreNamedField(HValue* obj, 5600 HStoreNamedField(HValue* obj,
5554 Handle<String> name, 5601 HObjectAccess access,
5555 HValue* val, 5602 HValue* val,
5556 bool in_object, 5603 Representation representation = Representation::Tagged())
5557 Representation field_representation, 5604 : access_(access),
5558 int offset) 5605 field_representation_(representation),
5559 : name_(name),
5560 is_in_object_(in_object),
5561 field_representation_(field_representation),
5562 offset_(offset),
5563 transition_unique_id_(), 5606 transition_unique_id_(),
5564 new_space_dominator_(NULL) { 5607 new_space_dominator_(NULL) {
5565 SetOperandAt(0, obj); 5608 SetOperandAt(0, obj);
5566 SetOperandAt(1, val); 5609 SetOperandAt(1, val);
5567 SetFlag(kTrackSideEffectDominators); 5610 access.SetGVNFlags(this, true);
5568 SetGVNFlag(kDependsOnNewSpacePromotion);
5569 if (is_in_object_) {
5570 SetGVNFlag(kChangesInobjectFields);
5571 } else {
5572 SetGVNFlag(kChangesBackingStoreFields);
5573 }
5574 } 5611 }
5575 5612
5576 DECLARE_CONCRETE_INSTRUCTION(StoreNamedField) 5613 DECLARE_CONCRETE_INSTRUCTION(StoreNamedField)
5577 5614
5578 virtual Representation RequiredInputRepresentation(int index) { 5615 virtual Representation RequiredInputRepresentation(int index) {
5579 if (FLAG_track_fields && index == 1 && field_representation_.IsSmi()) { 5616 if (FLAG_track_fields && index == 1 && field_representation_.IsSmi()) {
5580 return Representation::Integer32(); 5617 return Representation::Integer32();
5581 } 5618 }
5582 return Representation::Tagged(); 5619 return Representation::Tagged();
5583 } 5620 }
5584 virtual void SetSideEffectDominator(GVNFlag side_effect, HValue* dominator) { 5621 virtual void SetSideEffectDominator(GVNFlag side_effect, HValue* dominator) {
5585 ASSERT(side_effect == kChangesNewSpacePromotion); 5622 ASSERT(side_effect == kChangesNewSpacePromotion);
5586 new_space_dominator_ = dominator; 5623 new_space_dominator_ = dominator;
5587 } 5624 }
5588 virtual void PrintDataTo(StringStream* stream); 5625 virtual void PrintDataTo(StringStream* stream);
5589 5626
5590 HValue* object() { return OperandAt(0); } 5627 HValue* object() { return OperandAt(0); }
5591 HValue* value() { return OperandAt(1); } 5628 HValue* value() { return OperandAt(1); }
5592 5629
5593 Handle<String> name() const { return name_; } 5630 Handle<String> name() const { return access_.name(); }
5594 bool is_in_object() const { return is_in_object_; } 5631 bool is_in_object() const { return access_.IsInobject(); }
5595 int offset() const { return offset_; } 5632 int offset() const { return access_.offset(); }
5596 Handle<Map> transition() const { return transition_; } 5633 Handle<Map> transition() const { return transition_; }
5597 UniqueValueId transition_unique_id() const { return transition_unique_id_; } 5634 UniqueValueId transition_unique_id() const { return transition_unique_id_; }
5598 void set_transition(Handle<Map> map) { transition_ = map; } 5635 void set_transition(Handle<Map> map) { transition_ = map; }
5599 HValue* new_space_dominator() const { return new_space_dominator_; } 5636 HValue* new_space_dominator() const { return new_space_dominator_; }
5600 5637
5601 bool NeedsWriteBarrier() { 5638 bool NeedsWriteBarrier() {
5602 return (!FLAG_track_fields || !field_representation_.IsSmi()) && 5639 return (!FLAG_track_fields || !field_representation_.IsSmi()) &&
5603 StoringValueNeedsWriteBarrier(value()) && 5640 StoringValueNeedsWriteBarrier(value()) &&
5604 ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator()); 5641 ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator());
5605 } 5642 }
5606 5643
5607 bool NeedsWriteBarrierForMap() { 5644 bool NeedsWriteBarrierForMap() {
5608 return ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator()); 5645 return ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator());
5609 } 5646 }
5610 5647
5611 virtual void FinalizeUniqueValueId() { 5648 virtual void FinalizeUniqueValueId() {
5612 transition_unique_id_ = UniqueValueId(transition_); 5649 transition_unique_id_ = UniqueValueId(transition_);
5613 } 5650 }
5614 5651
5615 Representation field_representation() const { 5652 Representation field_representation() const {
5616 return field_representation_; 5653 return field_representation_;
5617 } 5654 }
5618 5655
5619 private: 5656 private:
5620 Handle<String> name_; 5657 HObjectAccess access_;
5621 bool is_in_object_;
5622 Representation field_representation_; 5658 Representation field_representation_;
5623 int offset_;
5624 Handle<Map> transition_; 5659 Handle<Map> transition_;
5625 UniqueValueId transition_unique_id_; 5660 UniqueValueId transition_unique_id_;
5626 HValue* new_space_dominator_; 5661 HValue* new_space_dominator_;
5627 }; 5662 };
5628 5663
5629 5664
5630 class HStoreNamedGeneric: public HTemplateInstruction<3> { 5665 class HStoreNamedGeneric: public HTemplateInstruction<3> {
5631 public: 5666 public:
5632 HStoreNamedGeneric(HValue* context, 5667 HStoreNamedGeneric(HValue* context,
5633 HValue* object, 5668 HValue* object,
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
6522 virtual bool IsDeletable() const { return true; } 6557 virtual bool IsDeletable() const { return true; }
6523 }; 6558 };
6524 6559
6525 6560
6526 #undef DECLARE_INSTRUCTION 6561 #undef DECLARE_INSTRUCTION
6527 #undef DECLARE_CONCRETE_INSTRUCTION 6562 #undef DECLARE_CONCRETE_INSTRUCTION
6528 6563
6529 } } // namespace v8::internal 6564 } } // namespace v8::internal
6530 6565
6531 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ 6566 #endif // V8_HYDROGEN_INSTRUCTIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698