Commit 8d741a9a authored by danno@chromium.org's avatar danno@chromium.org

Split GVN flags from flags in Hydrogen instructions.

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/9233005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10460 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c6166560
...@@ -416,18 +416,18 @@ void HValue::PrintRangeTo(StringStream* stream) { ...@@ -416,18 +416,18 @@ void HValue::PrintRangeTo(StringStream* stream) {
void HValue::PrintChangesTo(StringStream* stream) { void HValue::PrintChangesTo(StringStream* stream) {
int changes_flags = ChangesFlags(); GVNFlagSet changes_flags = ChangesFlags();
if (changes_flags == 0) return; if (changes_flags.IsEmpty()) return;
stream->Add(" changes["); stream->Add(" changes[");
if (changes_flags == AllSideEffects()) { if (changes_flags == AllSideEffectsFlagSet()) {
stream->Add("*"); stream->Add("*");
} else { } else {
bool add_comma = false; bool add_comma = false;
#define PRINT_DO(type) \ #define PRINT_DO(type) \
if (changes_flags & (1 << kChanges##type)) { \ if (changes_flags.Contains(kChanges##type)) { \
if (add_comma) stream->Add(","); \ if (add_comma) stream->Add(","); \
add_comma = true; \ add_comma = true; \
stream->Add(#type); \ stream->Add(#type); \
} }
GVN_FLAG_LIST(PRINT_DO); GVN_FLAG_LIST(PRINT_DO);
#undef PRINT_DO #undef PRINT_DO
...@@ -1408,7 +1408,7 @@ HLoadNamedFieldPolymorphic::HLoadNamedFieldPolymorphic(HValue* context, ...@@ -1408,7 +1408,7 @@ HLoadNamedFieldPolymorphic::HLoadNamedFieldPolymorphic(HValue* context,
SetOperandAt(0, context); SetOperandAt(0, context);
SetOperandAt(1, object); SetOperandAt(1, object);
set_representation(Representation::Tagged()); set_representation(Representation::Tagged());
SetFlag(kDependsOnMaps); SetGVNFlag(kDependsOnMaps);
for (int i = 0; for (int i = 0;
i < types->length() && types_.length() < kMaxLoadPolymorphism; i < types->length() && types_.length() < kMaxLoadPolymorphism;
++i) { ++i) {
...@@ -1420,9 +1420,9 @@ HLoadNamedFieldPolymorphic::HLoadNamedFieldPolymorphic(HValue* context, ...@@ -1420,9 +1420,9 @@ HLoadNamedFieldPolymorphic::HLoadNamedFieldPolymorphic(HValue* context,
case FIELD: { case FIELD: {
int index = lookup.GetLocalFieldIndexFromMap(*map); int index = lookup.GetLocalFieldIndexFromMap(*map);
if (index < 0) { if (index < 0) {
SetFlag(kDependsOnInobjectFields); SetGVNFlag(kDependsOnInobjectFields);
} else { } else {
SetFlag(kDependsOnBackingStoreFields); SetGVNFlag(kDependsOnBackingStoreFields);
} }
types_.Add(types->at(i)); types_.Add(types->at(i));
break; break;
......
This diff is collapsed.
...@@ -1110,10 +1110,10 @@ HValueMap::HValueMap(Zone* zone, const HValueMap* other) ...@@ -1110,10 +1110,10 @@ HValueMap::HValueMap(Zone* zone, const HValueMap* other)
} }
void HValueMap::Kill(int flags) { void HValueMap::Kill(GVNFlagSet flags) {
int depends_flags = HValue::ConvertChangesToDependsFlags(flags); GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(flags);
if ((present_flags_ & depends_flags) == 0) return; if (!present_flags_.ContainsAnyOf(depends_flags)) return;
present_flags_ = 0; present_flags_.RemoveAll();
for (int i = 0; i < array_size_; ++i) { for (int i = 0; i < array_size_; ++i) {
HValue* value = array_[i].value; HValue* value = array_[i].value;
if (value != NULL) { if (value != NULL) {
...@@ -1122,7 +1122,8 @@ void HValueMap::Kill(int flags) { ...@@ -1122,7 +1122,8 @@ void HValueMap::Kill(int flags) {
int next; int next;
for (int current = array_[i].next; current != kNil; current = next) { for (int current = array_[i].next; current != kNil; current = next) {
next = lists_[current].next; next = lists_[current].next;
if ((lists_[current].value->flags() & depends_flags) != 0) { HValue* value = lists_[current].value;
if (value->gvn_flags().ContainsAnyOf(depends_flags)) {
// Drop it. // Drop it.
count_--; count_--;
lists_[current].next = free_list_head_; lists_[current].next = free_list_head_;
...@@ -1131,13 +1132,14 @@ void HValueMap::Kill(int flags) { ...@@ -1131,13 +1132,14 @@ void HValueMap::Kill(int flags) {
// Keep it. // Keep it.
lists_[current].next = kept; lists_[current].next = kept;
kept = current; kept = current;
present_flags_ |= lists_[current].value->flags(); present_flags_.Add(value->gvn_flags());
} }
} }
array_[i].next = kept; array_[i].next = kept;
// Now possibly drop directly indexed element. // Now possibly drop directly indexed element.
if ((array_[i].value->flags() & depends_flags) != 0) { // Drop it. value = array_[i].value;
if (value->gvn_flags().ContainsAnyOf(depends_flags)) { // Drop it.
count_--; count_--;
int head = array_[i].next; int head = array_[i].next;
if (head == kNil) { if (head == kNil) {
...@@ -1149,7 +1151,7 @@ void HValueMap::Kill(int flags) { ...@@ -1149,7 +1151,7 @@ void HValueMap::Kill(int flags) {
free_list_head_ = head; free_list_head_ = head;
} }
} else { } else {
present_flags_ |= array_[i].value->flags(); // Keep it. present_flags_.Add(value->gvn_flags()); // Keep it.
} }
} }
} }
...@@ -1356,8 +1358,8 @@ class HGlobalValueNumberer BASE_EMBEDDED { ...@@ -1356,8 +1358,8 @@ class HGlobalValueNumberer BASE_EMBEDDED {
loop_side_effects_(graph->blocks()->length()), loop_side_effects_(graph->blocks()->length()),
visited_on_paths_(graph->zone(), graph->blocks()->length()) { visited_on_paths_(graph->zone(), graph->blocks()->length()) {
ASSERT(info->isolate()->heap()->allow_allocation(false)); ASSERT(info->isolate()->heap()->allow_allocation(false));
block_side_effects_.AddBlock(0, graph_->blocks()->length()); block_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length());
loop_side_effects_.AddBlock(0, graph_->blocks()->length()); loop_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length());
} }
~HGlobalValueNumberer() { ~HGlobalValueNumberer() {
ASSERT(!info_->isolate()->heap()->allow_allocation(true)); ASSERT(!info_->isolate()->heap()->allow_allocation(true));
...@@ -1367,14 +1369,15 @@ class HGlobalValueNumberer BASE_EMBEDDED { ...@@ -1367,14 +1369,15 @@ class HGlobalValueNumberer BASE_EMBEDDED {
bool Analyze(); bool Analyze();
private: private:
int CollectSideEffectsOnPathsToDominatedBlock(HBasicBlock* dominator, GVNFlagSet CollectSideEffectsOnPathsToDominatedBlock(
HBasicBlock* dominated); HBasicBlock* dominator,
HBasicBlock* dominated);
void AnalyzeBlock(HBasicBlock* block, HValueMap* map); void AnalyzeBlock(HBasicBlock* block, HValueMap* map);
void ComputeBlockSideEffects(); void ComputeBlockSideEffects();
void LoopInvariantCodeMotion(); void LoopInvariantCodeMotion();
void ProcessLoopBlock(HBasicBlock* block, void ProcessLoopBlock(HBasicBlock* block,
HBasicBlock* before_loop, HBasicBlock* before_loop,
int loop_kills); GVNFlagSet loop_kills);
bool AllowCodeMotion(); bool AllowCodeMotion();
bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header);
...@@ -1387,10 +1390,10 @@ class HGlobalValueNumberer BASE_EMBEDDED { ...@@ -1387,10 +1390,10 @@ class HGlobalValueNumberer BASE_EMBEDDED {
bool removed_side_effects_; bool removed_side_effects_;
// A map of block IDs to their side effects. // A map of block IDs to their side effects.
ZoneList<int> block_side_effects_; ZoneList<GVNFlagSet> block_side_effects_;
// A map of loop header block IDs to their loop's side effects. // A map of loop header block IDs to their loop's side effects.
ZoneList<int> loop_side_effects_; ZoneList<GVNFlagSet> loop_side_effects_;
// Used when collecting side effects on paths from dominator to // Used when collecting side effects on paths from dominator to
// dominated. // dominated.
...@@ -1415,23 +1418,24 @@ void HGlobalValueNumberer::ComputeBlockSideEffects() { ...@@ -1415,23 +1418,24 @@ void HGlobalValueNumberer::ComputeBlockSideEffects() {
HBasicBlock* block = graph_->blocks()->at(i); HBasicBlock* block = graph_->blocks()->at(i);
HInstruction* instr = block->first(); HInstruction* instr = block->first();
int id = block->block_id(); int id = block->block_id();
int side_effects = 0; GVNFlagSet side_effects;
while (instr != NULL) { while (instr != NULL) {
side_effects |= instr->ChangesFlags(); side_effects.Add(instr->ChangesFlags());
instr = instr->next(); instr = instr->next();
} }
block_side_effects_[id] |= side_effects; block_side_effects_[id].Add(side_effects);
// Loop headers are part of their loop. // Loop headers are part of their loop.
if (block->IsLoopHeader()) { if (block->IsLoopHeader()) {
loop_side_effects_[id] |= side_effects; loop_side_effects_[id].Add(side_effects);
} }
// Propagate loop side effects upwards. // Propagate loop side effects upwards.
if (block->HasParentLoopHeader()) { if (block->HasParentLoopHeader()) {
int header_id = block->parent_loop_header()->block_id(); int header_id = block->parent_loop_header()->block_id();
loop_side_effects_[header_id] |= loop_side_effects_[header_id].Add(block->IsLoopHeader()
block->IsLoopHeader() ? loop_side_effects_[id] : side_effects; ? loop_side_effects_[id]
: side_effects);
} }
} }
} }
...@@ -1441,10 +1445,10 @@ void HGlobalValueNumberer::LoopInvariantCodeMotion() { ...@@ -1441,10 +1445,10 @@ void HGlobalValueNumberer::LoopInvariantCodeMotion() {
for (int i = graph_->blocks()->length() - 1; i >= 0; --i) { for (int i = graph_->blocks()->length() - 1; i >= 0; --i) {
HBasicBlock* block = graph_->blocks()->at(i); HBasicBlock* block = graph_->blocks()->at(i);
if (block->IsLoopHeader()) { if (block->IsLoopHeader()) {
int side_effects = loop_side_effects_[block->block_id()]; GVNFlagSet side_effects = loop_side_effects_[block->block_id()];
TraceGVN("Try loop invariant motion for block B%d effects=0x%x\n", TraceGVN("Try loop invariant motion for block B%d effects=0x%x\n",
block->block_id(), block->block_id(),
side_effects); side_effects.ToIntegral());
HBasicBlock* last = block->loop_information()->GetLastBackEdge(); HBasicBlock* last = block->loop_information()->GetLastBackEdge();
for (int j = block->block_id(); j <= last->block_id(); ++j) { for (int j = block->block_id(); j <= last->block_id(); ++j) {
...@@ -1457,17 +1461,17 @@ void HGlobalValueNumberer::LoopInvariantCodeMotion() { ...@@ -1457,17 +1461,17 @@ void HGlobalValueNumberer::LoopInvariantCodeMotion() {
void HGlobalValueNumberer::ProcessLoopBlock(HBasicBlock* block, void HGlobalValueNumberer::ProcessLoopBlock(HBasicBlock* block,
HBasicBlock* loop_header, HBasicBlock* loop_header,
int loop_kills) { GVNFlagSet loop_kills) {
HBasicBlock* pre_header = loop_header->predecessors()->at(0); HBasicBlock* pre_header = loop_header->predecessors()->at(0);
int depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills); GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills);
TraceGVN("Loop invariant motion for B%d depends_flags=0x%x\n", TraceGVN("Loop invariant motion for B%d depends_flags=0x%x\n",
block->block_id(), block->block_id(),
depends_flags); depends_flags.ToIntegral());
HInstruction* instr = block->first(); HInstruction* instr = block->first();
while (instr != NULL) { while (instr != NULL) {
HInstruction* next = instr->next(); HInstruction* next = instr->next();
if (instr->CheckFlag(HValue::kUseGVN) && if (instr->CheckFlag(HValue::kUseGVN) &&
(instr->flags() & depends_flags) == 0) { !instr->gvn_flags().ContainsAnyOf(depends_flags)) {
TraceGVN("Checking instruction %d (%s)\n", TraceGVN("Checking instruction %d (%s)\n",
instr->id(), instr->id(),
instr->Mnemonic()); instr->Mnemonic());
...@@ -1503,20 +1507,20 @@ bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, ...@@ -1503,20 +1507,20 @@ bool HGlobalValueNumberer::ShouldMove(HInstruction* instr,
} }
int HGlobalValueNumberer::CollectSideEffectsOnPathsToDominatedBlock( GVNFlagSet HGlobalValueNumberer::CollectSideEffectsOnPathsToDominatedBlock(
HBasicBlock* dominator, HBasicBlock* dominated) { HBasicBlock* dominator, HBasicBlock* dominated) {
int side_effects = 0; GVNFlagSet side_effects;
for (int i = 0; i < dominated->predecessors()->length(); ++i) { for (int i = 0; i < dominated->predecessors()->length(); ++i) {
HBasicBlock* block = dominated->predecessors()->at(i); HBasicBlock* block = dominated->predecessors()->at(i);
if (dominator->block_id() < block->block_id() && if (dominator->block_id() < block->block_id() &&
block->block_id() < dominated->block_id() && block->block_id() < dominated->block_id() &&
visited_on_paths_.Add(block->block_id())) { visited_on_paths_.Add(block->block_id())) {
side_effects |= block_side_effects_[block->block_id()]; side_effects.Add(block_side_effects_[block->block_id()]);
if (block->IsLoopHeader()) { if (block->IsLoopHeader()) {
side_effects |= loop_side_effects_[block->block_id()]; side_effects.Add(loop_side_effects_[block->block_id()]);
} }
side_effects |= CollectSideEffectsOnPathsToDominatedBlock( side_effects.Add(CollectSideEffectsOnPathsToDominatedBlock(
dominator, block); dominator, block));
} }
} }
return side_effects; return side_effects;
...@@ -1537,8 +1541,8 @@ void HGlobalValueNumberer::AnalyzeBlock(HBasicBlock* block, HValueMap* map) { ...@@ -1537,8 +1541,8 @@ void HGlobalValueNumberer::AnalyzeBlock(HBasicBlock* block, HValueMap* map) {
HInstruction* instr = block->first(); HInstruction* instr = block->first();
while (instr != NULL) { while (instr != NULL) {
HInstruction* next = instr->next(); HInstruction* next = instr->next();
int flags = instr->ChangesFlags(); GVNFlagSet flags = instr->ChangesFlags();
if (flags != 0) { if (!flags.IsEmpty()) {
// Clear all instructions in the map that are affected by side effects. // Clear all instructions in the map that are affected by side effects.
map->Kill(flags); map->Kill(flags);
TraceGVN("Instruction %d kills\n", instr->id()); TraceGVN("Instruction %d kills\n", instr->id());
...@@ -3597,7 +3601,7 @@ HInstruction* HGraphBuilder::BuildStoreNamedField(HValue* object, ...@@ -3597,7 +3601,7 @@ HInstruction* HGraphBuilder::BuildStoreNamedField(HValue* object,
instr->set_transition(transition); instr->set_transition(transition);
// TODO(fschneider): Record the new map type of the object in the IR to // TODO(fschneider): Record the new map type of the object in the IR to
// enable elimination of redundant checks after the transition store. // enable elimination of redundant checks after the transition store.
instr->SetFlag(HValue::kChangesMaps); instr->SetGVNFlag(kChangesMaps);
} }
return instr; return instr;
} }
......
// Copyright 2011 the V8 project authors. All rights reserved. // Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -1056,10 +1056,10 @@ class HValueMap: public ZoneObject { ...@@ -1056,10 +1056,10 @@ class HValueMap: public ZoneObject {
Resize(kInitialSize); Resize(kInitialSize);
} }
void Kill(int flags); void Kill(GVNFlagSet flags);
void Add(HValue* value) { void Add(HValue* value) {
present_flags_ |= value->flags(); present_flags_.Add(value->gvn_flags());
Insert(value); Insert(value);
} }
...@@ -1092,7 +1092,8 @@ class HValueMap: public ZoneObject { ...@@ -1092,7 +1092,8 @@ class HValueMap: public ZoneObject {
int array_size_; int array_size_;
int lists_size_; int lists_size_;
int count_; // The number of values stored in the HValueMap. int count_; // The number of values stored in the HValueMap.
int present_flags_; // All flags that are in any value in the HValueMap. GVNFlagSet present_flags_; // All flags that are in any value in the
// HValueMap.
HValueMapListElement* array_; // Primary store - contains the first value HValueMapListElement* array_; // Primary store - contains the first value
// with a given hash. Colliding elements are stored in linked lists. // with a given hash. Colliding elements are stored in linked lists.
HValueMapListElement* lists_; // The linked lists containing hash collisions. HValueMapListElement* lists_; // The linked lists containing hash collisions.
......
// Copyright 2011 the V8 project authors. All rights reserved. // Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -931,9 +931,17 @@ class EnumSet { ...@@ -931,9 +931,17 @@ class EnumSet {
explicit EnumSet(T bits = 0) : bits_(bits) {} explicit EnumSet(T bits = 0) : bits_(bits) {}
bool IsEmpty() const { return bits_ == 0; } bool IsEmpty() const { return bits_ == 0; }
bool Contains(E element) const { return (bits_ & Mask(element)) != 0; } bool Contains(E element) const { return (bits_ & Mask(element)) != 0; }
bool ContainsAnyOf(const EnumSet& set) const {
return (bits_ & set.bits_) != 0;
}
void Add(E element) { bits_ |= Mask(element); } void Add(E element) { bits_ |= Mask(element); }
void Add(const EnumSet& set) { bits_ |= set.bits_; }
void Remove(E element) { bits_ &= ~Mask(element); } void Remove(E element) { bits_ &= ~Mask(element); }
void Remove(const EnumSet& set) { bits_ &= ~set.bits_; }
void RemoveAll() { bits_ = 0; }
void Intersect(const EnumSet& set) { bits_ &= set.bits_; }
T ToIntegral() const { return bits_; } T ToIntegral() const { return bits_; }
bool operator==(const EnumSet& set) { return bits_ == set.bits_; }
private: private:
T Mask(E element) const { T Mask(E element) const {
......
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