From 07a2a9cd19cb58c9de2c9717bab46c68c7b7d306 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Mon, 22 Apr 2013 09:48:35 +0000 Subject: [PATCH] Various improvements regarding the way we print code code comments. * All Lithium instructions have an associated Hydrogen instruction now, simplifying things. * Consistently print prefixes. * Do not print uninteresting Lithium instructions like empty gaps, jumps to the next instruction, etc. * Removed special handling of HChange-like instructions, it is totally unclear why they had this special treatment. If we really want to print more information about Lithium instructions, we should do it in a totally way, anyway (e.g. by unifying things with the generation of hydrogen*.cfg files). * Made deferred code and the jump table stand out a little bit more. * Print info about special blocks like loop headers and OSR entries. Review URL: https://codereview.chromium.org/14371005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14370 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-arm.cc | 5 +++ src/arm/lithium-arm.h | 12 ++++++ src/arm/lithium-codegen-arm.cc | 81 ++++++++++++++++------------------ src/arm/lithium-codegen-arm.h | 13 +++++- src/ia32/lithium-codegen-ia32.cc | 93 ++++++++++++++++++---------------------- src/ia32/lithium-codegen-ia32.h | 13 +++++- src/ia32/lithium-ia32.cc | 5 +++ src/ia32/lithium-ia32.h | 12 ++++++ src/lithium.cc | 1 + src/mips/lithium-codegen-mips.cc | 80 ++++++++++++++++------------------ src/mips/lithium-codegen-mips.h | 13 +++++- src/mips/lithium-mips.cc | 5 +++ src/mips/lithium-mips.h | 12 ++++++ src/x64/lithium-codegen-x64.cc | 79 ++++++++++++++++------------------ src/x64/lithium-codegen-x64.h | 13 +++++- src/x64/lithium-x64.cc | 5 +++ src/x64/lithium-x64.h | 12 ++++++ 17 files changed, 262 insertions(+), 192 deletions(-) diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index 618ac10..b240de7 100644 --- a/src/arm/lithium-arm.cc +++ b/src/arm/lithium-arm.cc @@ -192,6 +192,11 @@ const char* LArithmeticT::Mnemonic() const { } +bool LGoto::HasInterestingComment(LCodeGen* gen) const { + return !gen->IsNextEmittedBlock(block_id()); +} + + void LGoto::PrintDataTo(StringStream* stream) { stream->Add("B%d", block_id()); } diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h index 6486cad..d5aef29 100644 --- a/src/arm/lithium-arm.h +++ b/src/arm/lithium-arm.h @@ -282,6 +282,8 @@ class LInstruction: public ZoneObject { LOperand* FirstInput() { return InputAt(0); } LOperand* Output() { return HasResult() ? result() : NULL; } + virtual bool HasInterestingComment(LCodeGen* gen) const { return true; } + #ifdef DEBUG void VerifyCall(); #endif @@ -381,6 +383,10 @@ class LInstructionGap: public LGap { public: explicit LInstructionGap(HBasicBlock* block) : LGap(block) { } + virtual bool HasInterestingComment(LCodeGen* gen) const { + return !IsRedundant(); + } + DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap") }; @@ -389,6 +395,7 @@ class LGoto: public LTemplateInstruction<0, 0, 0> { public: explicit LGoto(int block_id) : block_id_(block_id) { } + virtual bool HasInterestingComment(LCodeGen* gen) const; DECLARE_CONCRETE_INSTRUCTION(Goto, "goto") virtual void PrintDataTo(StringStream* stream); virtual bool IsControl() const { return true; } @@ -436,12 +443,14 @@ class LLabel: public LGap { explicit LLabel(HBasicBlock* block) : LGap(block), replacement_(NULL) { } + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Label, "label") virtual void PrintDataTo(StringStream* stream); int block_id() const { return block()->block_id(); } bool is_loop_header() const { return block()->IsLoopHeader(); } + bool is_osr_entry() const { return block()->is_osr_entry(); } Label* label() { return &label_; } LLabel* replacement() const { return replacement_; } void set_replacement(LLabel* label) { replacement_ = label; } @@ -455,6 +464,7 @@ class LLabel: public LGap { class LParameter: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter") }; @@ -472,6 +482,7 @@ class LCallStub: public LTemplateInstruction<1, 0, 0> { class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value") }; @@ -2566,6 +2577,7 @@ class LOsrEntry: public LTemplateInstruction<0, 0, 0> { public: LOsrEntry(); + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr-entry") LOperand** SpilledRegisterArray() { return register_spills_; } diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 5c15d49..24231c5 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -264,38 +264,21 @@ bool LCodeGen::GenerateBody() { !is_aborted() && current_instruction_ < instructions_->length(); current_instruction_++) { LInstruction* instr = instructions_->at(current_instruction_); + + // Don't emit code for basic blocks with a replacement. if (instr->IsLabel()) { - LLabel* label = LLabel::cast(instr); - emit_instructions = !label->HasReplacement(); + emit_instructions = !LLabel::cast(instr)->HasReplacement(); } + if (!emit_instructions) continue; - if (emit_instructions) { - if (FLAG_code_comments) { - HValue* hydrogen = instr->hydrogen_value(); - if (hydrogen != NULL) { - if (hydrogen->IsChange()) { - HValue* changed_value = HChange::cast(hydrogen)->value(); - int use_id = 0; - const char* use_mnemo = "dead"; - if (hydrogen->UseCount() >= 1) { - HValue* use_value = hydrogen->uses().value(); - use_id = use_value->id(); - use_mnemo = use_value->Mnemonic(); - } - Comment(";;; @%d: %s. ", - current_instruction_, instr->Mnemonic(), - changed_value->id(), changed_value->Mnemonic(), - use_id, use_mnemo); - } else { - Comment(";;; @%d: %s. <#%d>", current_instruction_, - instr->Mnemonic(), hydrogen->id()); - } - } else { - Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); - } - } - instr->CompileToNative(this); + if (FLAG_code_comments && instr->HasInterestingComment(this)) { + Comment(";;; <@%d,#%d> %s", + current_instruction_, + instr->hydrogen_value()->id(), + instr->Mnemonic()); } + + instr->CompileToNative(this); } EnsureSpaceForLazyDeopt(); return !is_aborted(); @@ -307,11 +290,14 @@ bool LCodeGen::GenerateDeferredCode() { if (deferred_.length() > 0) { for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { LDeferredCode* code = deferred_[i]; + Comment(";;; <@%d,#%d> " + "-------------------- Deferred %s --------------------", + code->instruction_index(), + code->instr()->hydrogen_value()->id(), + code->instr()->Mnemonic()); __ bind(code->entry()); if (NeedsDeferredFrame()) { - Comment(";;; Deferred build frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Build frame"); ASSERT(!frame_is_built_); ASSERT(info()->IsStub()); frame_is_built_ = true; @@ -319,15 +305,11 @@ bool LCodeGen::GenerateDeferredCode() { __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); __ push(scratch0()); __ add(fp, sp, Operand(2 * kPointerSize)); + Comment(";;; Deferred code"); } - Comment(";;; Deferred code @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); code->Generate(); if (NeedsDeferredFrame()) { - Comment(";;; Deferred destroy frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Destroy frame"); ASSERT(frame_is_built_); __ pop(ip); __ ldm(ia_w, sp, cp.bit() | fp.bit() | lr.bit()); @@ -358,7 +340,9 @@ bool LCodeGen::GenerateDeoptJumpTable() { Abort("Generated code is too large"); } - __ RecordComment("[ Deoptimisation jump table"); + if (deopt_jump_table_.length() > 0) { + Comment(";;; -------------------- Jump table --------------------"); + } Label table_start; __ bind(&table_start); Label needs_frame_not_call; @@ -419,7 +403,6 @@ bool LCodeGen::GenerateDeoptJumpTable() { } masm()->CheckConstPool(false, false); } - __ RecordComment("]"); // Force constant pool emission at the end of the deopt jump table to make // sure that no constant pools are emitted after. @@ -1047,10 +1030,19 @@ void LCodeGen::RecordPosition(int position) { } +static const char* LabelType(LLabel* label) { + if (label->is_loop_header()) return " (loop header)"; + if (label->is_osr_entry()) return " (OSR entry)"; + return ""; +} + + void LCodeGen::DoLabel(LLabel* label) { - Comment(";;; -------------------- B%d%s --------------------", + Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", + current_instruction_, + label->hydrogen_value()->id(), label->block_id(), - label->is_loop_header() ? " (loop header)" : ""); + LabelType(label)); __ bind(label->label()); current_block_ = label->block_id(); DoGap(label); @@ -2175,7 +2167,7 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { } -int LCodeGen::GetNextEmittedBlock() { +int LCodeGen::GetNextEmittedBlock() const { for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { if (!chunk_->GetLabel(i)->HasReplacement()) return i; } @@ -2321,9 +2313,8 @@ void LCodeGen::DoBranch(LBranch* instr) { void LCodeGen::EmitGoto(int block) { - int destination = chunk_->LookupDestination(block); - if (destination != GetNextEmittedBlock()) { - __ jmp(chunk_->GetAssemblyLabel(destination)); + if (!IsNextEmittedBlock(block)) { + __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); } } diff --git a/src/arm/lithium-codegen-arm.h b/src/arm/lithium-codegen-arm.h index c104132..7df1070 100644 --- a/src/arm/lithium-codegen-arm.h +++ b/src/arm/lithium-codegen-arm.h @@ -80,6 +80,15 @@ class LCodeGen BASE_EMBEDDED { Heap* heap() const { return isolate()->heap(); } Zone* zone() const { return zone_; } + // TODO(svenpanne) Use this consistently. + int LookupDestination(int block_id) const { + return chunk()->LookupDestination(block_id); + } + + bool IsNextEmittedBlock(int block_id) const { + return LookupDestination(block_id) == GetNextEmittedBlock(); + } + bool NeedsEagerFrame() const { return GetStackSlotCount() > 0 || info()->is_non_deferred_calling() || @@ -196,12 +205,12 @@ class LCodeGen BASE_EMBEDDED { LPlatformChunk* chunk() const { return chunk_; } Scope* scope() const { return scope_; } - HGraph* graph() const { return chunk_->graph(); } + HGraph* graph() const { return chunk()->graph(); } Register scratch0() { return r9; } DwVfpRegister double_scratch0() { return kScratchDoubleReg; } - int GetNextEmittedBlock(); + int GetNextEmittedBlock() const; LInstruction* GetNextInstruction(); void EmitClassOfTest(Label* if_true, diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index de62e1f..ce51ec7 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -336,49 +336,28 @@ bool LCodeGen::GenerateBody() { !is_aborted() && current_instruction_ < instructions_->length(); current_instruction_++) { LInstruction* instr = instructions_->at(current_instruction_); + + // Don't emit code for basic blocks with a replacement. if (instr->IsLabel()) { - LLabel* label = LLabel::cast(instr); - emit_instructions = !label->HasReplacement(); + emit_instructions = !LLabel::cast(instr)->HasReplacement(); } + if (!emit_instructions) continue; - if (emit_instructions) { - if (FLAG_code_comments) { - HValue* hydrogen = instr->hydrogen_value(); - if (hydrogen != NULL) { - if (hydrogen->IsChange()) { - HValue* changed_value = HChange::cast(hydrogen)->value(); - int use_id = 0; - const char* use_mnemo = "dead"; - if (hydrogen->UseCount() >= 1) { - HValue* use_value = hydrogen->uses().value(); - use_id = use_value->id(); - use_mnemo = use_value->Mnemonic(); - } - Comment(";;; @%d: %s. ", - current_instruction_, instr->Mnemonic(), - changed_value->id(), changed_value->Mnemonic(), - use_id, use_mnemo); - } else { - Comment(";;; @%d: %s. <#%d>", current_instruction_, - instr->Mnemonic(), hydrogen->id()); - } - } else { - Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); - } - } - - if (!CpuFeatures::IsSupported(SSE2)) { - FlushX87StackIfNecessary(instr); - } + if (FLAG_code_comments && instr->HasInterestingComment(this)) { + Comment(";;; <@%d,#%d> %s", + current_instruction_, + instr->hydrogen_value()->id(), + instr->Mnemonic()); + } - instr->CompileToNative(this); + if (!CpuFeatures::IsSupported(SSE2)) FlushX87StackIfNecessary(instr); - if (!CpuFeatures::IsSupported(SSE2)) { - ASSERT(!instr->HasDoubleRegisterResult() || x87_stack_depth_ == 1); + instr->CompileToNative(this); - if (FLAG_debug_code && FLAG_enable_slow_asserts) { - __ VerifyX87StackDepth(x87_stack_depth_); - } + if (!CpuFeatures::IsSupported(SSE2)) { + ASSERT(!instr->HasDoubleRegisterResult() || x87_stack_depth_ == 1); + if (FLAG_debug_code && FLAG_enable_slow_asserts) { + __ VerifyX87StackDepth(x87_stack_depth_); } } } @@ -390,6 +369,9 @@ bool LCodeGen::GenerateBody() { bool LCodeGen::GenerateJumpTable() { Label needs_frame_not_call; Label needs_frame_is_call; + if (jump_table_.length() > 0) { + Comment(";;; -------------------- Jump table --------------------"); + } for (int i = 0; i < jump_table_.length(); i++) { __ bind(&jump_table_[i].label); Address entry = jump_table_[i].address; @@ -465,11 +447,14 @@ bool LCodeGen::GenerateDeferredCode() { if (deferred_.length() > 0) { for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { LDeferredCode* code = deferred_[i]; + Comment(";;; <@%d,#%d> " + "-------------------- Deferred %s --------------------", + code->instruction_index(), + code->instr()->hydrogen_value()->id(), + code->instr()->Mnemonic()); __ bind(code->entry()); if (NeedsDeferredFrame()) { - Comment(";;; Deferred build frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Build frame"); ASSERT(!frame_is_built_); ASSERT(info()->IsStub()); frame_is_built_ = true; @@ -478,15 +463,11 @@ bool LCodeGen::GenerateDeferredCode() { __ push(Operand(ebp, StandardFrameConstants::kContextOffset)); __ push(Immediate(Smi::FromInt(StackFrame::STUB))); __ lea(ebp, Operand(esp, 2 * kPointerSize)); + Comment(";;; Deferred code"); } - Comment(";;; Deferred code @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); code->Generate(); if (NeedsDeferredFrame()) { - Comment(";;; Deferred destroy frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Destroy frame"); ASSERT(frame_is_built_); frame_is_built_ = false; __ mov(esp, ebp); @@ -1125,10 +1106,19 @@ void LCodeGen::RecordPosition(int position) { } +static const char* LabelType(LLabel* label) { + if (label->is_loop_header()) return " (loop header)"; + if (label->is_osr_entry()) return " (OSR entry)"; + return ""; +} + + void LCodeGen::DoLabel(LLabel* label) { - Comment(";;; -------------------- B%d%s --------------------", + Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", + current_instruction_, + label->hydrogen_value()->id(), label->block_id(), - label->is_loop_header() ? " (loop header)" : ""); + LabelType(label)); __ bind(label->label()); current_block_ = label->block_id(); DoGap(label); @@ -2056,7 +2046,7 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { } -int LCodeGen::GetNextEmittedBlock() { +int LCodeGen::GetNextEmittedBlock() const { for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { if (!chunk_->GetLabel(i)->HasReplacement()) return i; } @@ -2203,9 +2193,8 @@ void LCodeGen::DoBranch(LBranch* instr) { void LCodeGen::EmitGoto(int block) { - int destination = chunk_->LookupDestination(block); - if (destination != GetNextEmittedBlock()) { - __ jmp(chunk_->GetAssemblyLabel(destination)); + if (!IsNextEmittedBlock(block)) { + __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); } } diff --git a/src/ia32/lithium-codegen-ia32.h b/src/ia32/lithium-codegen-ia32.h index a59b368..345e945 100644 --- a/src/ia32/lithium-codegen-ia32.h +++ b/src/ia32/lithium-codegen-ia32.h @@ -84,6 +84,15 @@ class LCodeGen BASE_EMBEDDED { Heap* heap() const { return isolate()->heap(); } Zone* zone() const { return zone_; } + // TODO(svenpanne) Use this consistently. + int LookupDestination(int block_id) const { + return chunk()->LookupDestination(block_id); + } + + bool IsNextEmittedBlock(int block_id) const { + return LookupDestination(block_id) == GetNextEmittedBlock(); + } + bool NeedsEagerFrame() const { return GetStackSlotCount() > 0 || info()->is_non_deferred_calling() || @@ -189,9 +198,9 @@ class LCodeGen BASE_EMBEDDED { LPlatformChunk* chunk() const { return chunk_; } Scope* scope() const { return scope_; } - HGraph* graph() const { return chunk_->graph(); } + HGraph* graph() const { return chunk()->graph(); } - int GetNextEmittedBlock(); + int GetNextEmittedBlock() const; void EmitClassOfTest(Label* if_true, Label* if_false, diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index 4daf309..08ab698 100644 --- a/src/ia32/lithium-ia32.cc +++ b/src/ia32/lithium-ia32.cc @@ -210,6 +210,11 @@ const char* LArithmeticT::Mnemonic() const { } +bool LGoto::HasInterestingComment(LCodeGen* gen) const { + return !gen->IsNextEmittedBlock(block_id()); +} + + void LGoto::PrintDataTo(StringStream* stream) { stream->Add("B%d", block_id()); } diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h index 10272fd..032d17e 100644 --- a/src/ia32/lithium-ia32.h +++ b/src/ia32/lithium-ia32.h @@ -278,6 +278,8 @@ class LInstruction: public ZoneObject { LOperand* FirstInput() { return InputAt(0); } LOperand* Output() { return HasResult() ? result() : NULL; } + virtual bool HasInterestingComment(LCodeGen* gen) const { return true; } + #ifdef DEBUG void VerifyCall(); #endif @@ -378,6 +380,10 @@ class LInstructionGap: public LGap { explicit LInstructionGap(HBasicBlock* block) : LGap(block) { } virtual bool ClobbersDoubleRegisters() const { return false; } + virtual bool HasInterestingComment(LCodeGen* gen) const { + return !IsRedundant(); + } + DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap") }; @@ -386,6 +392,7 @@ class LGoto: public LTemplateInstruction<0, 0, 0> { public: explicit LGoto(int block_id) : block_id_(block_id) { } + virtual bool HasInterestingComment(LCodeGen* gen) const; DECLARE_CONCRETE_INSTRUCTION(Goto, "goto") virtual void PrintDataTo(StringStream* stream); virtual bool IsControl() const { return true; } @@ -423,12 +430,14 @@ class LLabel: public LGap { explicit LLabel(HBasicBlock* block) : LGap(block), replacement_(NULL) { } + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Label, "label") virtual void PrintDataTo(StringStream* stream); int block_id() const { return block()->block_id(); } bool is_loop_header() const { return block()->IsLoopHeader(); } + bool is_osr_entry() const { return block()->is_osr_entry(); } Label* label() { return &label_; } LLabel* replacement() const { return replacement_; } void set_replacement(LLabel* label) { replacement_ = label; } @@ -442,6 +451,7 @@ class LLabel: public LGap { class LParameter: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter") }; @@ -465,6 +475,7 @@ class LCallStub: public LTemplateInstruction<1, 1, 0> { class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value") }; @@ -2673,6 +2684,7 @@ class LOsrEntry: public LTemplateInstruction<0, 0, 0> { public: LOsrEntry(); + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr-entry") LOperand** SpilledRegisterArray() { return register_spills_; } diff --git a/src/lithium.cc b/src/lithium.cc index b4a57f5..9f50d6c 100644 --- a/src/lithium.cc +++ b/src/lithium.cc @@ -341,6 +341,7 @@ void LChunk::MarkEmptyBlocks() { void LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) { LInstructionGap* gap = new(graph_->zone()) LInstructionGap(block); + gap->set_hydrogen_value(instr->hydrogen_value()); int index = -1; if (instr->IsControl()) { instructions_.Add(gap, zone()); diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index bf227a2..9ae5132 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -257,38 +257,21 @@ bool LCodeGen::GenerateBody() { !is_aborted() && current_instruction_ < instructions_->length(); current_instruction_++) { LInstruction* instr = instructions_->at(current_instruction_); + + // Don't emit code for basic blocks with a replacement. if (instr->IsLabel()) { - LLabel* label = LLabel::cast(instr); - emit_instructions = !label->HasReplacement(); + emit_instructions = !LLabel::cast(instr)->HasReplacement(); } + if (!emit_instructions) continue; - if (emit_instructions) { - if (FLAG_code_comments) { - HValue* hydrogen = instr->hydrogen_value(); - if (hydrogen != NULL) { - if (hydrogen->IsChange()) { - HValue* changed_value = HChange::cast(hydrogen)->value(); - int use_id = 0; - const char* use_mnemo = "dead"; - if (hydrogen->UseCount() >= 1) { - HValue* use_value = hydrogen->uses().value(); - use_id = use_value->id(); - use_mnemo = use_value->Mnemonic(); - } - Comment(";;; @%d: %s. ", - current_instruction_, instr->Mnemonic(), - changed_value->id(), changed_value->Mnemonic(), - use_id, use_mnemo); - } else { - Comment(";;; @%d: %s. <#%d>", current_instruction_, - instr->Mnemonic(), hydrogen->id()); - } - } else { - Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); - } - } - instr->CompileToNative(this); + if (FLAG_code_comments && instr->HasInterestingComment(this)) { + Comment(";;; <@%d,#%d> %s", + current_instruction_, + instr->hydrogen_value()->id(), + instr->Mnemonic()); } + + instr->CompileToNative(this); } return !is_aborted(); } @@ -299,11 +282,14 @@ bool LCodeGen::GenerateDeferredCode() { if (deferred_.length() > 0) { for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { LDeferredCode* code = deferred_[i]; + Comment(";;; <@%d,#%d> " + "-------------------- Deferred %s --------------------", + code->instruction_index(), + code->instr()->hydrogen_value()->id(), + code->instr()->Mnemonic()); __ bind(code->entry()); if (NeedsDeferredFrame()) { - Comment(";;; Deferred build frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Build frame"); ASSERT(!frame_is_built_); ASSERT(info()->IsStub()); frame_is_built_ = true; @@ -311,15 +297,11 @@ bool LCodeGen::GenerateDeferredCode() { __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); __ push(scratch0()); __ Addu(fp, sp, Operand(2 * kPointerSize)); + Comment(";;; Deferred code"); } - Comment(";;; Deferred code @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); code->Generate(); if (NeedsDeferredFrame()) { - Comment(";;; Deferred destroy frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Destroy frame"); ASSERT(frame_is_built_); __ pop(at); __ MultiPop(cp.bit() | fp.bit() | ra.bit()); @@ -346,8 +328,10 @@ bool LCodeGen::GenerateDeoptJumpTable() { Abort("Generated code is too large"); } + if (deopt_jump_table_.length() > 0) { + Comment(";;; -------------------- Jump table --------------------"); + } Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); - __ RecordComment("[ Deoptimization jump table"); Label table_start; __ bind(&table_start); Label needs_frame_not_call; @@ -1023,10 +1007,19 @@ void LCodeGen::RecordPosition(int position) { } +static const char* LabelType(LLabel* label) { + if (label->is_loop_header()) return " (loop header)"; + if (label->is_osr_entry()) return " (OSR entry)"; + return ""; +} + + void LCodeGen::DoLabel(LLabel* label) { - Comment(";;; -------------------- B%d%s --------------------", + Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", + current_instruction_, + label->hydrogen_value()->id(), label->block_id(), - label->is_loop_header() ? " (loop header)" : ""); + LabelType(label)); __ bind(label->label()); current_block_ = label->block_id(); DoGap(label); @@ -1756,7 +1749,7 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { } -int LCodeGen::GetNextEmittedBlock() { +int LCodeGen::GetNextEmittedBlock() const { for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { if (!chunk_->GetLabel(i)->HasReplacement()) return i; } @@ -1915,9 +1908,8 @@ void LCodeGen::DoBranch(LBranch* instr) { void LCodeGen::EmitGoto(int block) { - int destination = chunk_->LookupDestination(block); - if (destination != GetNextEmittedBlock()) { - __ jmp(chunk_->GetAssemblyLabel(destination)); + if (!IsNextEmittedBlock(block)) { + __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); } } diff --git a/src/mips/lithium-codegen-mips.h b/src/mips/lithium-codegen-mips.h index 0dbfe65..27e3061 100644 --- a/src/mips/lithium-codegen-mips.h +++ b/src/mips/lithium-codegen-mips.h @@ -79,6 +79,15 @@ class LCodeGen BASE_EMBEDDED { Heap* heap() const { return isolate()->heap(); } Zone* zone() const { return zone_; } + // TODO(svenpanne) Use this consistently. + int LookupDestination(int block_id) const { + return chunk()->LookupDestination(block_id); + } + + bool IsNextEmittedBlock(int block_id) const { + return LookupDestination(block_id) == GetNextEmittedBlock(); + } + bool NeedsEagerFrame() const { return GetStackSlotCount() > 0 || info()->is_non_deferred_calling() || @@ -190,13 +199,13 @@ class LCodeGen BASE_EMBEDDED { LPlatformChunk* chunk() const { return chunk_; } Scope* scope() const { return scope_; } - HGraph* graph() const { return chunk_->graph(); } + HGraph* graph() const { return chunk()->graph(); } Register scratch0() { return kLithiumScratchReg; } Register scratch1() { return kLithiumScratchReg2; } DoubleRegister double_scratch0() { return kLithiumScratchDouble; } - int GetNextEmittedBlock(); + int GetNextEmittedBlock() const; LInstruction* GetNextInstruction(); void EmitClassOfTest(Label* if_true, diff --git a/src/mips/lithium-mips.cc b/src/mips/lithium-mips.cc index 5c0b85e..fb8826b 100644 --- a/src/mips/lithium-mips.cc +++ b/src/mips/lithium-mips.cc @@ -192,6 +192,11 @@ const char* LArithmeticT::Mnemonic() const { } +bool LGoto::HasInterestingComment(LCodeGen* gen) const { + return !gen->IsNextEmittedBlock(block_id()); +} + + void LGoto::PrintDataTo(StringStream* stream) { stream->Add("B%d", block_id()); } diff --git a/src/mips/lithium-mips.h b/src/mips/lithium-mips.h index b0fc59a..70d0909 100644 --- a/src/mips/lithium-mips.h +++ b/src/mips/lithium-mips.h @@ -279,6 +279,8 @@ class LInstruction: public ZoneObject { LOperand* FirstInput() { return InputAt(0); } LOperand* Output() { return HasResult() ? result() : NULL; } + virtual bool HasInterestingComment(LCodeGen* gen) const { return true; } + #ifdef DEBUG void VerifyCall(); #endif @@ -378,6 +380,10 @@ class LInstructionGap: public LGap { public: explicit LInstructionGap(HBasicBlock* block) : LGap(block) { } + virtual bool HasInterestingComment(LCodeGen* gen) const { + return !IsRedundant(); + } + DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap") }; @@ -386,6 +392,7 @@ class LGoto: public LTemplateInstruction<0, 0, 0> { public: explicit LGoto(int block_id) : block_id_(block_id) { } + virtual bool HasInterestingComment(LCodeGen* gen) const; DECLARE_CONCRETE_INSTRUCTION(Goto, "goto") virtual void PrintDataTo(StringStream* stream); virtual bool IsControl() const { return true; } @@ -433,12 +440,14 @@ class LLabel: public LGap { explicit LLabel(HBasicBlock* block) : LGap(block), replacement_(NULL) { } + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Label, "label") virtual void PrintDataTo(StringStream* stream); int block_id() const { return block()->block_id(); } bool is_loop_header() const { return block()->IsLoopHeader(); } + bool is_osr_entry() const { return block()->is_osr_entry(); } Label* label() { return &label_; } LLabel* replacement() const { return replacement_; } void set_replacement(LLabel* label) { replacement_ = label; } @@ -452,6 +461,7 @@ class LLabel: public LGap { class LParameter: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter") }; @@ -469,6 +479,7 @@ class LCallStub: public LTemplateInstruction<1, 0, 0> { class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value") }; @@ -2507,6 +2518,7 @@ class LOsrEntry: public LTemplateInstruction<0, 0, 0> { public: LOsrEntry(); + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr-entry") LOperand** SpilledRegisterArray() { return register_spills_; } diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index fa12270..054dd60 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -261,38 +261,21 @@ bool LCodeGen::GenerateBody() { !is_aborted() && current_instruction_ < instructions_->length(); current_instruction_++) { LInstruction* instr = instructions_->at(current_instruction_); + + // Don't emit code for basic blocks with a replacement. if (instr->IsLabel()) { - LLabel* label = LLabel::cast(instr); - emit_instructions = !label->HasReplacement(); + emit_instructions = !LLabel::cast(instr)->HasReplacement(); } + if (!emit_instructions) continue; - if (emit_instructions) { - if (FLAG_code_comments) { - HValue* hydrogen = instr->hydrogen_value(); - if (hydrogen != NULL) { - if (hydrogen->IsChange()) { - HValue* changed_value = HChange::cast(hydrogen)->value(); - int use_id = 0; - const char* use_mnemo = "dead"; - if (hydrogen->UseCount() >= 1) { - HValue* use_value = hydrogen->uses().value(); - use_id = use_value->id(); - use_mnemo = use_value->Mnemonic(); - } - Comment(";;; @%d: %s. ", - current_instruction_, instr->Mnemonic(), - changed_value->id(), changed_value->Mnemonic(), - use_id, use_mnemo); - } else { - Comment(";;; @%d: %s. <#%d>", current_instruction_, - instr->Mnemonic(), hydrogen->id()); - } - } else { - Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); - } - } - instr->CompileToNative(this); + if (FLAG_code_comments && instr->HasInterestingComment(this)) { + Comment(";;; <@%d,#%d> %s", + current_instruction_, + instr->hydrogen_value()->id(), + instr->Mnemonic()); } + + instr->CompileToNative(this); } EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); return !is_aborted(); @@ -302,6 +285,9 @@ bool LCodeGen::GenerateBody() { bool LCodeGen::GenerateJumpTable() { Label needs_frame_not_call; Label needs_frame_is_call; + if (jump_table_.length() > 0) { + Comment(";;; -------------------- Jump table --------------------"); + } for (int i = 0; i < jump_table_.length(); i++) { __ bind(&jump_table_[i].label); Address entry = jump_table_[i].address; @@ -368,11 +354,14 @@ bool LCodeGen::GenerateDeferredCode() { if (deferred_.length() > 0) { for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { LDeferredCode* code = deferred_[i]; + Comment(";;; <@%d,#%d> " + "-------------------- Deferred %s --------------------", + code->instruction_index(), + code->instr()->hydrogen_value()->id(), + code->instr()->Mnemonic()); __ bind(code->entry()); if (NeedsDeferredFrame()) { - Comment(";;; Deferred build frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Build frame"); ASSERT(!frame_is_built_); ASSERT(info()->IsStub()); frame_is_built_ = true; @@ -381,15 +370,11 @@ bool LCodeGen::GenerateDeferredCode() { __ push(Operand(rbp, StandardFrameConstants::kContextOffset)); __ Push(Smi::FromInt(StackFrame::STUB)); __ lea(rbp, Operand(rsp, 2 * kPointerSize)); + Comment(";;; Deferred code"); } - Comment(";;; Deferred code @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); code->Generate(); if (NeedsDeferredFrame()) { - Comment(";;; Deferred destroy frame @%d: %s.", - code->instruction_index(), - code->instr()->Mnemonic()); + Comment(";;; Destroy frame"); ASSERT(frame_is_built_); frame_is_built_ = false; __ movq(rsp, rbp); @@ -925,10 +910,19 @@ void LCodeGen::RecordPosition(int position) { } +static const char* LabelType(LLabel* label) { + if (label->is_loop_header()) return " (loop header)"; + if (label->is_osr_entry()) return " (OSR entry)"; + return ""; +} + + void LCodeGen::DoLabel(LLabel* label) { - Comment(";;; -------------------- B%d%s --------------------", + Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", + current_instruction_, + label->hydrogen_value()->id(), label->block_id(), - label->is_loop_header() ? " (loop header)" : ""); + LabelType(label)); __ bind(label->label()); current_block_ = label->block_id(); DoGap(label); @@ -1822,7 +1816,7 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { } -int LCodeGen::GetNextEmittedBlock() { +int LCodeGen::GetNextEmittedBlock() const { for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { if (!chunk_->GetLabel(i)->HasReplacement()) return i; } @@ -1961,9 +1955,8 @@ void LCodeGen::DoBranch(LBranch* instr) { void LCodeGen::EmitGoto(int block) { - int destination = chunk_->LookupDestination(block); - if (destination != GetNextEmittedBlock()) { - __ jmp(chunk_->GetAssemblyLabel(destination)); + if (!IsNextEmittedBlock(block)) { + __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); } } diff --git a/src/x64/lithium-codegen-x64.h b/src/x64/lithium-codegen-x64.h index a988a7a..2fe277f 100644 --- a/src/x64/lithium-codegen-x64.h +++ b/src/x64/lithium-codegen-x64.h @@ -80,6 +80,15 @@ class LCodeGen BASE_EMBEDDED { Heap* heap() const { return isolate()->heap(); } Zone* zone() const { return zone_; } + // TODO(svenpanne) Use this consistently. + int LookupDestination(int block_id) const { + return chunk()->LookupDestination(block_id); + } + + bool IsNextEmittedBlock(int block_id) const { + return LookupDestination(block_id) == GetNextEmittedBlock(); + } + bool NeedsEagerFrame() const { return GetStackSlotCount() > 0 || info()->is_non_deferred_calling() || @@ -160,9 +169,9 @@ class LCodeGen BASE_EMBEDDED { LPlatformChunk* chunk() const { return chunk_; } Scope* scope() const { return scope_; } - HGraph* graph() const { return chunk_->graph(); } + HGraph* graph() const { return chunk()->graph(); } - int GetNextEmittedBlock(); + int GetNextEmittedBlock() const; void EmitClassOfTest(Label* if_true, Label* if_false, diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index e78cee4..f564e1c 100644 --- a/src/x64/lithium-x64.cc +++ b/src/x64/lithium-x64.cc @@ -194,6 +194,11 @@ const char* LArithmeticT::Mnemonic() const { } +bool LGoto::HasInterestingComment(LCodeGen* gen) const { + return !gen->IsNextEmittedBlock(block_id()); +} + + void LGoto::PrintDataTo(StringStream* stream) { stream->Add("B%d", block_id()); } diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h index 54f117c..967b645 100644 --- a/src/x64/lithium-x64.h +++ b/src/x64/lithium-x64.h @@ -280,6 +280,8 @@ class LInstruction: public ZoneObject { LOperand* FirstInput() { return InputAt(0); } LOperand* Output() { return HasResult() ? result() : NULL; } + virtual bool HasInterestingComment(LCodeGen* gen) const { return true; } + #ifdef DEBUG void VerifyCall(); #endif @@ -381,6 +383,10 @@ class LInstructionGap: public LGap { public: explicit LInstructionGap(HBasicBlock* block) : LGap(block) { } + virtual bool HasInterestingComment(LCodeGen* gen) const { + return !IsRedundant(); + } + DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap") }; @@ -389,6 +395,7 @@ class LGoto: public LTemplateInstruction<0, 0, 0> { public: explicit LGoto(int block_id) : block_id_(block_id) { } + virtual bool HasInterestingComment(LCodeGen* gen) const; DECLARE_CONCRETE_INSTRUCTION(Goto, "goto") virtual void PrintDataTo(StringStream* stream); virtual bool IsControl() const { return true; } @@ -436,12 +443,14 @@ class LLabel: public LGap { explicit LLabel(HBasicBlock* block) : LGap(block), replacement_(NULL) { } + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Label, "label") virtual void PrintDataTo(StringStream* stream); int block_id() const { return block()->block_id(); } bool is_loop_header() const { return block()->IsLoopHeader(); } + bool is_osr_entry() const { return block()->is_osr_entry(); } Label* label() { return &label_; } LLabel* replacement() const { return replacement_; } void set_replacement(LLabel* label) { replacement_ = label; } @@ -455,6 +464,7 @@ class LLabel: public LGap { class LParameter: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter") }; @@ -472,6 +482,7 @@ class LCallStub: public LTemplateInstruction<1, 0, 0> { class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { public: + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value") }; @@ -2471,6 +2482,7 @@ class LOsrEntry: public LTemplateInstruction<0, 0, 0> { public: LOsrEntry(); + virtual bool HasInterestingComment(LCodeGen* gen) const { return false; } DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr-entry") LOperand** SpilledRegisterArray() { return register_spills_; } -- 2.7.4