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

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: Split apart ForOffset into ForJSObjectOffset, ForJSArrayOffset, and ForFixedArrayOffset 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 ForPropertiesPointer() {
5218 return HObjectAccess(kInobject, JSObject::kPropertiesOffset);
5219 }
5220
5221 static HObjectAccess ForMap() {
5222 return HObjectAccess(kMaps, JSObject::kMapOffset);
5223 }
5224
5225 // Create an access to a property in an object or backing store.
5226 static HObjectAccess For(bool is_inobject, int offset,
danno 2013/05/08 15:40:18 If you add ForAllocationSitePayload, then you can
titzer 2013/05/13 11:23:19 Done.
5227 Handle<String> name = Handle<String>::null());
5228
5229 // Create an access to an offset in a fixed array.
5230 static HObjectAccess ForFixedArrayOffset(int offset);
5231
5232 // Create an access to an in-object property in a JSObject.
5233 static HObjectAccess ForJSObjectOffset(int offset,
5234 Handle<String> name = Handle<String>::null());
5235
5236 // Create an access to an in-object property in a JSArray.
5237 static HObjectAccess ForJSArrayOffset(int offset,
5238 Handle<String> name = Handle<String>::null());
5239
5240 // Create an access to a resolved field (in-object or backing store).
5241 static HObjectAccess ForField(Handle<Map> map,
5242 LookupResult *lookup, Handle<String> name = Handle<String>::null());
5243
5244 void PrintTo(StringStream* stream);
5245
5246 protected:
5247 void SetGVNFlags(HValue *instr, bool is_store);
5248
5249 private:
5250 // internal use only; different parts of an object or array
5251 enum Portion {
5252 kMaps, // map of an object
5253 kArrayLengths, // the length of an array
5254 kElementsPointer, // elements pointer
5255 kBackingStore, // some field in the backing store
5256 kInobject // some other in-object field
5257 };
5258
5259 HObjectAccess(Portion portion, int offset,
5260 Handle<String> name = Handle<String>::null())
5261 : portion_(portion), offset_(offset), name_(name) {
5262 ASSERT(offset_ == offset); // offset must fit
5263 ASSERT(portion_ == portion); // portion must fit
5264 }
5265
5266 unsigned portion_ : 3;
5267 unsigned offset_ : 29;
5268 Handle<String> name_;
5269
5270 friend class HLoadNamedField;
5271 friend class HStoreNamedField;
5272 };
5273
5274
5189 class HLoadNamedField: public HTemplateInstruction<2> { 5275 class HLoadNamedField: public HTemplateInstruction<2> {
5190 public: 5276 public:
5191 HLoadNamedField(HValue* object, bool is_in_object, 5277 HLoadNamedField(HValue* object,
5192 Representation field_representation, 5278 HObjectAccess access,
5193 int offset, HValue* typecheck = NULL) 5279 HValue* typecheck = NULL,
5194 : is_in_object_(is_in_object), 5280 Representation representation = Representation::Tagged())
5195 field_representation_(field_representation), 5281 : access_(access),
5196 offset_(offset) { 5282 field_representation_(representation) {
5197 ASSERT(object != NULL); 5283 ASSERT(object != NULL);
5198 SetOperandAt(0, object); 5284 SetOperandAt(0, object);
5199 SetOperandAt(1, typecheck != NULL ? typecheck : object); 5285 SetOperandAt(1, typecheck != NULL ? typecheck : object);
5200 5286
5201 if (FLAG_track_fields && field_representation.IsSmi()) { 5287 set_representation(Representation::Tagged());
5202 set_type(HType::Smi()); 5288 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 } 5289 }
5230 5290
5231 HValue* object() { return OperandAt(0); } 5291 HValue* object() { return OperandAt(0); }
5232 HValue* typecheck() { 5292 HValue* typecheck() {
5233 ASSERT(HasTypeCheck()); 5293 ASSERT(HasTypeCheck());
5234 return OperandAt(1); 5294 return OperandAt(1);
5235 } 5295 }
5236 5296
5237 bool HasTypeCheck() const { return OperandAt(0) != OperandAt(1); } 5297 bool HasTypeCheck() const { return OperandAt(0) != OperandAt(1); }
5238 bool is_in_object() const { return is_in_object_; } 5298 bool is_in_object() const { return access_.IsInobject(); }
5239 Representation field_representation() const { return representation_; } 5299 Representation field_representation() const { return representation_; }
5240 int offset() const { return offset_; } 5300 int offset() const { return access_.offset(); }
5241 5301
5242 virtual Representation RequiredInputRepresentation(int index) { 5302 virtual Representation RequiredInputRepresentation(int index) {
5243 return Representation::Tagged(); 5303 return Representation::Tagged();
5244 } 5304 }
5245 virtual void PrintDataTo(StringStream* stream); 5305 virtual void PrintDataTo(StringStream* stream);
5246 5306
5247 DECLARE_CONCRETE_INSTRUCTION(LoadNamedField) 5307 DECLARE_CONCRETE_INSTRUCTION(LoadNamedField)
5248 5308
5249 protected: 5309 protected:
5250 virtual bool DataEquals(HValue* other) { 5310 virtual bool DataEquals(HValue* other) {
5251 HLoadNamedField* b = HLoadNamedField::cast(other); 5311 HLoadNamedField* b = HLoadNamedField::cast(other);
5252 return is_in_object_ == b->is_in_object_ && offset_ == b->offset_; 5312 return is_in_object() == b->is_in_object() && offset() == b->offset();
5253 } 5313 }
5254 5314
5255 private: 5315 private:
5256 virtual bool IsDeletable() const { return true; } 5316 virtual bool IsDeletable() const { return true; }
5257 5317
5258 bool is_in_object_; 5318 HObjectAccess access_;
5259 Representation field_representation_; 5319 Representation field_representation_;
5260 int offset_;
5261 }; 5320 };
5262 5321
5263 5322
5264 class HLoadNamedFieldPolymorphic: public HTemplateInstruction<2> { 5323 class HLoadNamedFieldPolymorphic: public HTemplateInstruction<2> {
5265 public: 5324 public:
5266 HLoadNamedFieldPolymorphic(HValue* context, 5325 HLoadNamedFieldPolymorphic(HValue* context,
5267 HValue* object, 5326 HValue* object,
5268 SmallMapList* types, 5327 SmallMapList* types,
5269 Handle<String> name, 5328 Handle<String> name,
5270 Zone* zone); 5329 Zone* zone);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
5544 5603
5545 virtual HValue* Canonicalize(); 5604 virtual HValue* Canonicalize();
5546 5605
5547 DECLARE_CONCRETE_INSTRUCTION(LoadKeyedGeneric) 5606 DECLARE_CONCRETE_INSTRUCTION(LoadKeyedGeneric)
5548 }; 5607 };
5549 5608
5550 5609
5551 class HStoreNamedField: public HTemplateInstruction<2> { 5610 class HStoreNamedField: public HTemplateInstruction<2> {
5552 public: 5611 public:
5553 HStoreNamedField(HValue* obj, 5612 HStoreNamedField(HValue* obj,
5554 Handle<String> name, 5613 HObjectAccess access,
5555 HValue* val, 5614 HValue* val,
5556 bool in_object, 5615 Representation representation = Representation::Tagged())
5557 Representation field_representation, 5616 : access_(access),
5558 int offset) 5617 field_representation_(representation),
5559 : name_(name),
5560 is_in_object_(in_object),
5561 field_representation_(field_representation),
5562 offset_(offset),
5563 transition_unique_id_(), 5618 transition_unique_id_(),
5564 new_space_dominator_(NULL) { 5619 new_space_dominator_(NULL) {
5565 SetOperandAt(0, obj); 5620 SetOperandAt(0, obj);
5566 SetOperandAt(1, val); 5621 SetOperandAt(1, val);
5567 SetFlag(kTrackSideEffectDominators); 5622 access.SetGVNFlags(this, true);
5568 SetGVNFlag(kDependsOnNewSpacePromotion);
5569 if (is_in_object_) {
5570 SetGVNFlag(kChangesInobjectFields);
5571 } else {
5572 SetGVNFlag(kChangesBackingStoreFields);
5573 }
5574 } 5623 }
5575 5624
5576 DECLARE_CONCRETE_INSTRUCTION(StoreNamedField) 5625 DECLARE_CONCRETE_INSTRUCTION(StoreNamedField)
5577 5626
5578 virtual Representation RequiredInputRepresentation(int index) { 5627 virtual Representation RequiredInputRepresentation(int index) {
5579 if (FLAG_track_fields && index == 1 && field_representation_.IsSmi()) { 5628 if (FLAG_track_fields && index == 1 && field_representation_.IsSmi()) {
5580 return Representation::Integer32(); 5629 return Representation::Integer32();
5581 } 5630 }
5582 return Representation::Tagged(); 5631 return Representation::Tagged();
5583 } 5632 }
5584 virtual void SetSideEffectDominator(GVNFlag side_effect, HValue* dominator) { 5633 virtual void SetSideEffectDominator(GVNFlag side_effect, HValue* dominator) {
5585 ASSERT(side_effect == kChangesNewSpacePromotion); 5634 ASSERT(side_effect == kChangesNewSpacePromotion);
5586 new_space_dominator_ = dominator; 5635 new_space_dominator_ = dominator;
5587 } 5636 }
5588 virtual void PrintDataTo(StringStream* stream); 5637 virtual void PrintDataTo(StringStream* stream);
5589 5638
5590 HValue* object() { return OperandAt(0); } 5639 HValue* object() { return OperandAt(0); }
5591 HValue* value() { return OperandAt(1); } 5640 HValue* value() { return OperandAt(1); }
5592 5641
5593 Handle<String> name() const { return name_; } 5642 Handle<String> name() const { return access_.name(); }
5594 bool is_in_object() const { return is_in_object_; } 5643 bool is_in_object() const { return access_.IsInobject(); }
5595 int offset() const { return offset_; } 5644 int offset() const { return access_.offset(); }
5596 Handle<Map> transition() const { return transition_; } 5645 Handle<Map> transition() const { return transition_; }
5597 UniqueValueId transition_unique_id() const { return transition_unique_id_; } 5646 UniqueValueId transition_unique_id() const { return transition_unique_id_; }
5598 void set_transition(Handle<Map> map) { transition_ = map; } 5647 void set_transition(Handle<Map> map) { transition_ = map; }
5599 HValue* new_space_dominator() const { return new_space_dominator_; } 5648 HValue* new_space_dominator() const { return new_space_dominator_; }
5600 5649
5601 bool NeedsWriteBarrier() { 5650 bool NeedsWriteBarrier() {
5602 return (!FLAG_track_fields || !field_representation_.IsSmi()) && 5651 return (!FLAG_track_fields || !field_representation_.IsSmi()) &&
5603 StoringValueNeedsWriteBarrier(value()) && 5652 StoringValueNeedsWriteBarrier(value()) &&
5604 ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator()); 5653 ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator());
5605 } 5654 }
5606 5655
5607 bool NeedsWriteBarrierForMap() { 5656 bool NeedsWriteBarrierForMap() {
5608 return ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator()); 5657 return ReceiverObjectNeedsWriteBarrier(object(), new_space_dominator());
5609 } 5658 }
5610 5659
5611 virtual void FinalizeUniqueValueId() { 5660 virtual void FinalizeUniqueValueId() {
5612 transition_unique_id_ = UniqueValueId(transition_); 5661 transition_unique_id_ = UniqueValueId(transition_);
5613 } 5662 }
5614 5663
5615 Representation field_representation() const { 5664 Representation field_representation() const {
5616 return field_representation_; 5665 return field_representation_;
5617 } 5666 }
5618 5667
5619 private: 5668 private:
5620 Handle<String> name_; 5669 HObjectAccess access_;
5621 bool is_in_object_;
5622 Representation field_representation_; 5670 Representation field_representation_;
5623 int offset_;
5624 Handle<Map> transition_; 5671 Handle<Map> transition_;
5625 UniqueValueId transition_unique_id_; 5672 UniqueValueId transition_unique_id_;
5626 HValue* new_space_dominator_; 5673 HValue* new_space_dominator_;
5627 }; 5674 };
5628 5675
5629 5676
5630 class HStoreNamedGeneric: public HTemplateInstruction<3> { 5677 class HStoreNamedGeneric: public HTemplateInstruction<3> {
5631 public: 5678 public:
5632 HStoreNamedGeneric(HValue* context, 5679 HStoreNamedGeneric(HValue* context,
5633 HValue* object, 5680 HValue* object,
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
6522 virtual bool IsDeletable() const { return true; } 6569 virtual bool IsDeletable() const { return true; }
6523 }; 6570 };
6524 6571
6525 6572
6526 #undef DECLARE_INSTRUCTION 6573 #undef DECLARE_INSTRUCTION
6527 #undef DECLARE_CONCRETE_INSTRUCTION 6574 #undef DECLARE_CONCRETE_INSTRUCTION
6528 6575
6529 } } // namespace v8::internal 6576 } } // namespace v8::internal
6530 6577
6531 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ 6578 #endif // V8_HYDROGEN_INSTRUCTIONS_H_
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/hydrogen-instructions.cc » ('j') | src/hydrogen-instructions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698