Commit 3575f970 authored by titzer@chromium.org's avatar titzer@chromium.org

Refactor HCheckMaps to have a private constructor, removing duplicated code...

Refactor HCheckMaps to have a private constructor, removing duplicated code and simplifying calls in clients.
Ignore bsuite directory.

Review URL: https://codereview.chromium.org/14367023

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14362 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 7155b96d
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
*~ *~
.cpplint-cache .cpplint-cache
.d8_history .d8_history
bsuite
d8 d8
d8_g d8_g
shell shell
......
...@@ -2680,39 +2680,27 @@ class HLoadExternalArrayPointer: public HUnaryOperation { ...@@ -2680,39 +2680,27 @@ class HLoadExternalArrayPointer: public HUnaryOperation {
class HCheckMaps: public HTemplateInstruction<2> { class HCheckMaps: public HTemplateInstruction<2> {
public: public:
HCheckMaps(HValue* value, Handle<Map> map, Zone* zone, static HCheckMaps* New(HValue* value, Handle<Map> map, Zone* zone,
HValue* typecheck = NULL) HValue *typecheck = NULL) {
: map_unique_ids_(0, zone) { HCheckMaps* check_map = new(zone) HCheckMaps(value, zone, typecheck);
SetOperandAt(0, value); check_map->map_set_.Add(map, zone);
// If callers don't depend on a typecheck, they can pass in NULL. In that return check_map;
// case we use a copy of the |value| argument as a dummy value.
SetOperandAt(1, typecheck != NULL ? typecheck : value);
set_representation(Representation::Tagged());
SetFlag(kUseGVN);
SetFlag(kTrackSideEffectDominators);
SetGVNFlag(kDependsOnMaps);
SetGVNFlag(kDependsOnElementsKind);
map_set()->Add(map, zone);
} }
HCheckMaps(HValue* value, SmallMapList* maps, Zone* zone)
: map_unique_ids_(0, zone) { static HCheckMaps* New(HValue* value, SmallMapList* maps, Zone* zone,
SetOperandAt(0, value); HValue *typecheck = NULL) {
SetOperandAt(1, value); HCheckMaps* check_map = new(zone) HCheckMaps(value, zone, typecheck);
set_representation(Representation::Tagged());
SetFlag(kUseGVN);
SetFlag(kTrackSideEffectDominators);
SetGVNFlag(kDependsOnMaps);
SetGVNFlag(kDependsOnElementsKind);
for (int i = 0; i < maps->length(); i++) { for (int i = 0; i < maps->length(); i++) {
map_set()->Add(maps->at(i), zone); check_map->map_set_.Add(maps->at(i), zone);
} }
map_set()->Sort(); check_map->map_set_.Sort();
return check_map;
} }
static HCheckMaps* NewWithTransitions(HValue* object, Handle<Map> map, static HCheckMaps* NewWithTransitions(HValue* value, Handle<Map> map,
Zone* zone) { Zone* zone) {
HCheckMaps* check_map = new(zone) HCheckMaps(object, map, zone); HCheckMaps* check_map = new(zone) HCheckMaps(value, zone, value);
SmallMapList* map_set = check_map->map_set(); check_map->map_set_.Add(map, zone);
// Since transitioned elements maps of the initial map don't fail the map // Since transitioned elements maps of the initial map don't fail the map
// check, the CheckMaps instruction doesn't need to depend on ElementsKinds. // check, the CheckMaps instruction doesn't need to depend on ElementsKinds.
...@@ -2725,10 +2713,10 @@ class HCheckMaps: public HTemplateInstruction<2> { ...@@ -2725,10 +2713,10 @@ class HCheckMaps: public HTemplateInstruction<2> {
Map* transitioned_map = Map* transitioned_map =
map->LookupElementsTransitionMap(kind); map->LookupElementsTransitionMap(kind);
if (transitioned_map) { if (transitioned_map) {
map_set->Add(Handle<Map>(transitioned_map), zone); check_map->map_set_.Add(Handle<Map>(transitioned_map), zone);
} }
}; };
map_set->Sort(); check_map->map_set_.Sort();
return check_map; return check_map;
} }
...@@ -2763,6 +2751,20 @@ class HCheckMaps: public HTemplateInstruction<2> { ...@@ -2763,6 +2751,20 @@ class HCheckMaps: public HTemplateInstruction<2> {
} }
private: private:
// Clients should use one of the static New* methods above.
HCheckMaps(HValue* value, Zone *zone, HValue* typecheck)
: map_unique_ids_(0, zone) {
SetOperandAt(0, value);
// Use the object value for the dependency if NULL is passed.
// TODO(titzer): do GVN flags already express this dependency?
SetOperandAt(1, typecheck != NULL ? typecheck : value);
set_representation(Representation::Tagged());
SetFlag(kUseGVN);
SetFlag(kTrackSideEffectDominators);
SetGVNFlag(kDependsOnMaps);
SetGVNFlag(kDependsOnElementsKind);
}
SmallMapList map_set_; SmallMapList map_set_;
ZoneList<UniqueValueId> map_unique_ids_; ZoneList<UniqueValueId> map_unique_ids_;
}; };
......
...@@ -1077,7 +1077,7 @@ HValue* HGraphBuilder::BuildCheckNonSmi(HValue* obj) { ...@@ -1077,7 +1077,7 @@ HValue* HGraphBuilder::BuildCheckNonSmi(HValue* obj) {
HValue* HGraphBuilder::BuildCheckMap(HValue* obj, HValue* HGraphBuilder::BuildCheckMap(HValue* obj,
Handle<Map> map) { Handle<Map> map) {
HCheckMaps* check = new(zone()) HCheckMaps(obj, map, zone()); HCheckMaps* check = HCheckMaps::New(obj, map, zone());
AddInstruction(check); AddInstruction(check);
return check; return check;
} }
...@@ -1293,7 +1293,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1293,7 +1293,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
AddInstruction(new(zone) HLoadElements(object, mapcheck)); AddInstruction(new(zone) HLoadElements(object, mapcheck));
if (is_store && (fast_elements || fast_smi_only_elements) && if (is_store && (fast_elements || fast_smi_only_elements) &&
store_mode != STORE_NO_TRANSITION_HANDLE_COW) { store_mode != STORE_NO_TRANSITION_HANDLE_COW) {
HCheckMaps* check_cow_map = new(zone) HCheckMaps( HCheckMaps* check_cow_map = HCheckMaps::New(
elements, isolate()->factory()->fixed_array_map(), zone); elements, isolate()->factory()->fixed_array_map(), zone);
check_cow_map->ClearGVNFlag(kDependsOnElementsKind); check_cow_map->ClearGVNFlag(kDependsOnElementsKind);
AddInstruction(check_cow_map); AddInstruction(check_cow_map);
...@@ -1370,7 +1370,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1370,7 +1370,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
elements = BuildCopyElementsOnWrite(object, elements, elements_kind, elements = BuildCopyElementsOnWrite(object, elements, elements_kind,
length); length);
} else { } else {
HCheckMaps* check_cow_map = new(zone) HCheckMaps( HCheckMaps* check_cow_map = HCheckMaps::New(
elements, isolate()->factory()->fixed_array_map(), zone); elements, isolate()->factory()->fixed_array_map(), zone);
check_cow_map->ClearGVNFlag(kDependsOnElementsKind); check_cow_map->ClearGVNFlag(kDependsOnElementsKind);
AddInstruction(check_cow_map); AddInstruction(check_cow_map);
...@@ -6651,7 +6651,7 @@ static int ComputeLoadStoreFieldIndex(Handle<Map> type, ...@@ -6651,7 +6651,7 @@ static int ComputeLoadStoreFieldIndex(Handle<Map> type,
void HOptimizedGraphBuilder::AddCheckMap(HValue* object, Handle<Map> map) { void HOptimizedGraphBuilder::AddCheckMap(HValue* object, Handle<Map> map) {
AddInstruction(new(zone()) HCheckNonSmi(object)); AddInstruction(new(zone()) HCheckNonSmi(object));
AddInstruction(new(zone()) HCheckMaps(object, map, zone())); AddInstruction(HCheckMaps::New(object, map, zone()));
} }
...@@ -6780,7 +6780,7 @@ bool HOptimizedGraphBuilder::HandlePolymorphicArrayLengthLoad( ...@@ -6780,7 +6780,7 @@ bool HOptimizedGraphBuilder::HandlePolymorphicArrayLengthLoad(
AddInstruction(new(zone()) HCheckNonSmi(object)); AddInstruction(new(zone()) HCheckNonSmi(object));
HInstruction* typecheck = HInstruction* typecheck =
AddInstruction(new(zone()) HCheckMaps(object, types, zone())); AddInstruction(HCheckMaps::New(object, types, zone()));
HInstruction* instr = HInstruction* instr =
HLoadNamedField::NewArrayLength(zone(), object, typecheck); HLoadNamedField::NewArrayLength(zone(), object, typecheck);
instr->set_position(expr->position()); instr->set_position(expr->position());
...@@ -6832,7 +6832,7 @@ void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField(Property* expr, ...@@ -6832,7 +6832,7 @@ void HOptimizedGraphBuilder::HandlePolymorphicLoadNamedField(Property* expr,
AddInstruction(new(zone()) HCheckNonSmi(object)); AddInstruction(new(zone()) HCheckNonSmi(object));
HInstruction* instr; HInstruction* instr;
if (count == types->length() && is_monomorphic_field) { if (count == types->length() && is_monomorphic_field) {
AddInstruction(new(zone()) HCheckMaps(object, types, zone())); AddInstruction(HCheckMaps::New(object, types, zone()));
instr = BuildLoadNamedField(object, map, &lookup); instr = BuildLoadNamedField(object, map, &lookup);
} else { } else {
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
...@@ -7509,8 +7509,7 @@ HInstruction* HOptimizedGraphBuilder::BuildMonomorphicElementAccess( ...@@ -7509,8 +7509,7 @@ HInstruction* HOptimizedGraphBuilder::BuildMonomorphicElementAccess(
Handle<Map> map, Handle<Map> map,
bool is_store, bool is_store,
KeyedAccessStoreMode store_mode) { KeyedAccessStoreMode store_mode) {
HCheckMaps* mapcheck = new(zone()) HCheckMaps(object, map, HCheckMaps* mapcheck = HCheckMaps::New(object, map, zone(), dependency);
zone(), dependency);
AddInstruction(mapcheck); AddInstruction(mapcheck);
if (dependency) { if (dependency) {
mapcheck->ClearGVNFlag(kDependsOnElementsKind); mapcheck->ClearGVNFlag(kDependsOnElementsKind);
...@@ -7567,7 +7566,7 @@ HInstruction* HOptimizedGraphBuilder::TryBuildConsolidatedElementLoad( ...@@ -7567,7 +7566,7 @@ HInstruction* HOptimizedGraphBuilder::TryBuildConsolidatedElementLoad(
} }
if (!has_double_maps && !has_smi_or_object_maps) return NULL; if (!has_double_maps && !has_smi_or_object_maps) return NULL;
HCheckMaps* check_maps = new(zone()) HCheckMaps(object, maps, zone()); HCheckMaps* check_maps = HCheckMaps::New(object, maps, zone());
AddInstruction(check_maps); AddInstruction(check_maps);
HInstruction* instr = BuildUncheckedMonomorphicElementAccess( HInstruction* instr = BuildUncheckedMonomorphicElementAccess(
object, key, val, check_maps, object, key, val, check_maps,
...@@ -7719,7 +7718,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -7719,7 +7718,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
HInstruction* access; HInstruction* access;
if (IsFastElementsKind(elements_kind)) { if (IsFastElementsKind(elements_kind)) {
if (is_store && !IsFastDoubleElementsKind(elements_kind)) { if (is_store && !IsFastDoubleElementsKind(elements_kind)) {
AddInstruction(new(zone()) HCheckMaps( AddInstruction(HCheckMaps::New(
elements, isolate()->factory()->fixed_array_map(), elements, isolate()->factory()->fixed_array_map(),
zone(), elements_kind_branch)); zone(), elements_kind_branch));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment