Split HPhase for Lithium and Hydrogen using common CompilationPhase base.

Add new base class CompilationPhase, which is the base for both HPhase, LPhase and LAllocatorPhase. HPhase is now for Hydrogen passes only, LPhase is for Lithium passes and LAllocatorPhase is for LAllocator phases.

R=svenpanne@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15321 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2013-06-25 12:22:26 +00:00
parent bd5fafd58a
commit 9f05d61a1d
17 changed files with 128 additions and 101 deletions

View File

@ -451,7 +451,7 @@ LOperand* LPlatformChunk::GetNextSpillSlot(bool is_double) {
LPlatformChunk* LChunkBuilder::Build() {
ASSERT(is_unused());
chunk_ = new(zone()) LPlatformChunk(info(), graph());
HPhase phase("L_Building chunk", chunk_);
LPhase phase("L_Building chunk", chunk_);
status_ = BUILDING;
const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
for (int i = 0; i < blocks->length(); i++) {

View File

@ -62,7 +62,7 @@ class SafepointGenerator : public CallWrapper {
#define __ masm()->
bool LCodeGen::GenerateCode() {
HPhase phase("Z_Code generation", chunk());
LPhase phase("Z_Code generation", chunk());
ASSERT(is_unused());
status_ = GENERATING;

View File

@ -1224,4 +1224,32 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
info));
}
CompilationPhase::CompilationPhase(const char* name,
Isolate* isolate,
Zone* zone)
: name_(name), isolate_(isolate), zone_scope_(zone, DELETE_ON_EXIT) {
if (FLAG_hydrogen_stats) {
start_allocation_size_ = zone->allocation_size();
start_ticks_ = OS::Ticks();
}
}
CompilationPhase::~CompilationPhase() {
if (FLAG_hydrogen_stats) {
unsigned size = zone()->allocation_size() - start_allocation_size_;
int64_t ticks = OS::Ticks() - start_ticks_;
isolate_->GetHStatistics()->SaveTiming(name_, ticks, size);
}
}
bool CompilationPhase::ShouldProduceTraceOutput() const {
// Produce trace output if flag is set so that the first letter of the
// phase name matches the command line parameter FLAG_trace_phase.
return (FLAG_trace_hydrogen &&
OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
}
} } // namespace v8::internal

View File

@ -633,6 +633,29 @@ class Compiler : public AllStatic {
};
class CompilationPhase BASE_EMBEDDED {
public:
CompilationPhase(const char* name, Isolate* isolate, Zone* zone);
~CompilationPhase();
protected:
bool ShouldProduceTraceOutput() const;
const char* name() const { return name_; }
Isolate* isolate() const { return isolate_; }
Zone* zone() const { return zone_scope_.zone(); }
private:
const char* name_;
Isolate* isolate_;
ZoneScope zone_scope_;
unsigned start_allocation_size_;
int64_t start_ticks_;
DISALLOW_COPY_AND_ASSIGN(CompilationPhase);
};
} } // namespace v8::internal
#endif // V8_COMPILER_H_

View File

@ -963,7 +963,7 @@ void HGraphBuilder::LoopBuilder::EndBody() {
HGraph* HGraphBuilder::CreateGraph() {
graph_ = new(zone()) HGraph(info_);
if (FLAG_hydrogen_stats) isolate()->GetHStatistics()->Initialize(info_);
HPhase phase("H_Block building", isolate(), zone());
CompilationPhase phase("H_Block building", isolate(), zone());
set_current_block(graph()->entry_block());
if (!BuildGraph()) return NULL;
graph()->FinalizeUniqueValueIds();
@ -2384,7 +2384,7 @@ class PostorderProcessor : public ZoneObject {
void HGraph::OrderBlocks() {
HPhase phase("H_Block ordering", isolate(), zone());
CompilationPhase phase("H_Block ordering", isolate(), zone());
BitVector visited(blocks_.length(), zone());
ZoneList<HBasicBlock*> reverse_result(8, zone());
@ -11554,73 +11554,13 @@ void HStatistics::SaveTiming(const char* name, int64_t ticks, unsigned size) {
}
HPhase::HPhase(const char* name, Isolate* isolate, Zone* zone) {
Init(isolate, name, zone, NULL, NULL, NULL);
}
HPhase::HPhase(const char* name, HGraph* graph) {
Init(graph->isolate(), name, graph->zone(), graph, NULL, NULL);
}
HPhase::HPhase(const char* name, LChunk* chunk) {
Init(chunk->isolate(), name, chunk->zone(), NULL, chunk, NULL);
}
HPhase::HPhase(const char* name, LAllocator* allocator) {
Init(allocator->isolate(), name, allocator->zone(), NULL, NULL, allocator);
}
void HPhase::Init(Isolate* isolate,
const char* name,
Zone* zone,
HGraph* graph,
LChunk* chunk,
LAllocator* allocator) {
isolate_ = isolate;
name_ = name;
zone_ = zone;
graph_ = graph;
chunk_ = chunk;
allocator_ = allocator;
if (allocator != NULL && chunk_ == NULL) {
chunk_ = allocator->chunk();
}
if (FLAG_hydrogen_stats) {
start_ticks_ = OS::Ticks();
start_allocation_size_ = zone_->allocation_size();
}
}
HPhase::~HPhase() {
if (FLAG_hydrogen_stats) {
int64_t ticks = OS::Ticks() - start_ticks_;
unsigned size = zone_->allocation_size() - start_allocation_size_;
isolate_->GetHStatistics()->SaveTiming(name_, ticks, size);
}
// Produce trace output if flag is set so that the first letter of the
// phase name matches the command line parameter FLAG_trace_phase.
if (FLAG_trace_hydrogen &&
OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL) {
if (graph_ != NULL) {
isolate_->GetHTracer()->TraceHydrogen(name_, graph_);
}
if (chunk_ != NULL) {
isolate_->GetHTracer()->TraceLithium(name_, chunk_);
}
if (allocator_ != NULL) {
isolate_->GetHTracer()->TraceLiveRanges(name_, allocator_);
}
if (ShouldProduceTraceOutput()) {
isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
}
#ifdef DEBUG
if (graph_ != NULL) graph_->Verify(false); // No full verify.
if (allocator_ != NULL) allocator_->Verify();
graph_->Verify(false); // No full verify.
#endif
}

View File

@ -1955,30 +1955,17 @@ class HStatistics: public Malloced {
};
class HPhase BASE_EMBEDDED {
class HPhase : public CompilationPhase {
public:
HPhase(const char* name, Isolate* isolate, Zone* zone);
HPhase(const char* name, HGraph* graph);
HPhase(const char* name, LChunk* chunk);
HPhase(const char* name, LAllocator* allocator);
HPhase(const char* name, HGraph* graph)
: CompilationPhase(name, graph->isolate(), graph->zone()),
graph_(graph) { }
~HPhase();
private:
void Init(Isolate* isolate,
const char* name,
Zone* zone,
HGraph* graph,
LChunk* chunk,
LAllocator* allocator);
Isolate* isolate_;
const char* name_;
Zone* zone_;
HGraph* graph_;
LChunk* chunk_;
LAllocator* allocator_;
int64_t start_ticks_;
unsigned start_allocation_size_;
DISALLOW_COPY_AND_ASSIGN(HPhase);
};

View File

@ -74,7 +74,7 @@ class SafepointGenerator : public CallWrapper {
#define __ masm()->
bool LCodeGen::GenerateCode() {
HPhase phase("Z_Code generation", chunk());
LPhase phase("Z_Code generation", chunk());
ASSERT(is_unused());
status_ = GENERATING;

View File

@ -481,7 +481,7 @@ void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
LPlatformChunk* LChunkBuilder::Build() {
ASSERT(is_unused());
chunk_ = new(zone()) LPlatformChunk(info(), graph());
HPhase phase("L_Building chunk", chunk_);
LPhase phase("L_Building chunk", chunk_);
status_ = BUILDING;
// Reserve the first spill slot for the state of dynamic alignment.

View File

@ -1101,7 +1101,7 @@ bool LAllocator::Allocate(LChunk* chunk) {
void LAllocator::MeetRegisterConstraints() {
HPhase phase("L_Register constraints", chunk_);
LAllocatorPhase phase("L_Register constraints", this);
first_artificial_register_ = next_virtual_register_;
const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
for (int i = 0; i < blocks->length(); ++i) {
@ -1113,7 +1113,7 @@ void LAllocator::MeetRegisterConstraints() {
void LAllocator::ResolvePhis() {
HPhase phase("L_Resolve phis", chunk_);
LAllocatorPhase phase("L_Resolve phis", this);
// Process the blocks in reverse order.
const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
@ -1204,7 +1204,7 @@ HBasicBlock* LAllocator::GetBlock(LifetimePosition pos) {
void LAllocator::ConnectRanges() {
HPhase phase("L_Connect ranges", this);
LAllocatorPhase phase("L_Connect ranges", this);
for (int i = 0; i < live_ranges()->length(); ++i) {
LiveRange* first_range = live_ranges()->at(i);
if (first_range == NULL || first_range->parent() != NULL) continue;
@ -1244,7 +1244,7 @@ bool LAllocator::CanEagerlyResolveControlFlow(HBasicBlock* block) const {
void LAllocator::ResolveControlFlow() {
HPhase phase("L_Resolve control flow", this);
LAllocatorPhase phase("L_Resolve control flow", this);
const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
for (int block_id = 1; block_id < blocks->length(); ++block_id) {
HBasicBlock* block = blocks->at(block_id);
@ -1265,7 +1265,7 @@ void LAllocator::ResolveControlFlow() {
void LAllocator::BuildLiveRanges() {
HPhase phase("L_Build live ranges", this);
LAllocatorPhase phase("L_Build live ranges", this);
InitializeLivenessAnalysis();
// Process the blocks in reverse order.
const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
@ -1377,7 +1377,7 @@ bool LAllocator::SafePointsAreInOrder() const {
void LAllocator::PopulatePointerMaps() {
HPhase phase("L_Populate pointer maps", this);
LAllocatorPhase phase("L_Populate pointer maps", this);
const ZoneList<LPointerMap*>* pointer_maps = chunk_->pointer_maps();
ASSERT(SafePointsAreInOrder());
@ -1496,14 +1496,14 @@ void LAllocator::ProcessOsrEntry() {
void LAllocator::AllocateGeneralRegisters() {
HPhase phase("L_Allocate general registers", this);
LAllocatorPhase phase("L_Allocate general registers", this);
num_registers_ = Register::NumAllocatableRegisters();
AllocateRegisters();
}
void LAllocator::AllocateDoubleRegisters() {
HPhase phase("L_Allocate double registers", this);
LAllocatorPhase phase("L_Allocate double registers", this);
num_registers_ = DoubleRegister::NumAllocatableRegisters();
mode_ = DOUBLE_REGISTERS;
AllocateRegisters();
@ -2192,4 +2192,16 @@ void LAllocator::Verify() const {
#endif
LAllocatorPhase::~LAllocatorPhase() {
if (ShouldProduceTraceOutput()) {
isolate()->GetHTracer()->TraceLithium(name(), allocator_->chunk());
isolate()->GetHTracer()->TraceLiveRanges(name(), allocator_);
}
#ifdef DEBUG
if (allocator_ != NULL) allocator_->Verify();
#endif
}
} } // namespace v8::internal

View File

@ -646,6 +646,20 @@ class LAllocator BASE_EMBEDDED {
};
class LAllocatorPhase : public CompilationPhase {
public:
LAllocatorPhase(const char* name, LAllocator* allocator)
: CompilationPhase(name, allocator->isolate(), allocator->zone()),
allocator_(allocator) { }
~LAllocatorPhase();
private:
LAllocator* allocator_;
DISALLOW_COPY_AND_ASSIGN(LAllocatorPhase);
};
} } // namespace v8::internal
#endif // V8_LITHIUM_ALLOCATOR_H_

View File

@ -307,7 +307,7 @@ Label* LChunk::GetAssemblyLabel(int block_id) const {
}
void LChunk::MarkEmptyBlocks() {
HPhase phase("L_Mark empty blocks", this);
LPhase phase("L_Mark empty blocks", this);
for (int i = 0; i < graph()->blocks()->length(); ++i) {
HBasicBlock* block = graph()->blocks()->at(i);
int first = block->first_instruction_index();
@ -491,4 +491,11 @@ void LChunk::set_allocated_double_registers(BitVector* allocated_registers) {
}
LPhase::~LPhase() {
if (ShouldProduceTraceOutput()) {
isolate()->GetHTracer()->TraceLithium(name(), chunk_);
}
}
} } // namespace v8::internal

View File

@ -778,6 +778,20 @@ enum NumberUntagDMode {
};
class LPhase : public CompilationPhase {
public:
LPhase(const char* name, LChunk* chunk)
: CompilationPhase(name, chunk->isolate(), chunk->zone()),
chunk_(chunk) { }
~LPhase();
private:
LChunk* chunk_;
DISALLOW_COPY_AND_ASSIGN(LPhase);
};
} } // namespace v8::internal
#endif // V8_LITHIUM_H_

View File

@ -62,7 +62,7 @@ class SafepointGenerator : public CallWrapper {
#define __ masm()->
bool LCodeGen::GenerateCode() {
HPhase phase("Z_Code generation", chunk());
LPhase phase("Z_Code generation", chunk());
ASSERT(is_unused());
status_ = GENERATING;

View File

@ -455,7 +455,7 @@ LOperand* LPlatformChunk::GetNextSpillSlot(bool is_double) {
LPlatformChunk* LChunkBuilder::Build() {
ASSERT(is_unused());
chunk_ = new(zone()) LPlatformChunk(info(), graph());
HPhase phase("L_Building chunk", chunk_);
LPhase phase("L_Building chunk", chunk_);
status_ = BUILDING;
const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
for (int i = 0; i < blocks->length(); i++) {

View File

@ -67,7 +67,7 @@ class SafepointGenerator : public CallWrapper {
#define __ masm()->
bool LCodeGen::GenerateCode() {
HPhase phase("Z_Code generation", chunk());
LPhase phase("Z_Code generation", chunk());
ASSERT(is_unused());
status_ = GENERATING;

View File

@ -456,7 +456,7 @@ void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
LPlatformChunk* LChunkBuilder::Build() {
ASSERT(is_unused());
chunk_ = new(zone()) LPlatformChunk(info(), graph());
HPhase phase("L_Building chunk", chunk_);
LPhase phase("L_Building chunk", chunk_);
status_ = BUILDING;
const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
for (int i = 0; i < blocks->length(); i++) {

View File

@ -241,6 +241,8 @@ class ZoneScope BASE_EMBEDDED {
virtual ~ZoneScope();
Zone* zone() const { return zone_; }
inline bool ShouldDeleteOnExit();
// For ZoneScopes that do not delete on exit by default, call this