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

Unified Diff: src/lithium-allocator.cc

Issue 6352006: Remove instruction summaries and provide a LIR-interface for the register all... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: addressed comments, rebased and ported to ARM and x64 Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/lithium-allocator.h ('k') | src/lithium-allocator-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lithium-allocator.cc
===================================================================
--- src/lithium-allocator.cc (revision 6471)
+++ src/lithium-allocator.cc (working copy)
@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "lithium-allocator.h"
+#include "lithium-allocator-inl.h"
#include "hydrogen.h"
#include "string-stream.h"
@@ -532,7 +532,7 @@
void LAllocator::InitializeLivenessAnalysis() {
// Initialize the live_in sets for each block to NULL.
- int block_count = graph()->blocks()->length();
+ int block_count = graph_->blocks()->length();
live_in_sets_.Initialize(block_count);
live_in_sets_.AddBlock(NULL, block_count);
}
@@ -613,7 +613,7 @@
}
if (is_tagged) {
TraceAlloc("Fixed reg is tagged at %d\n", pos);
- LInstruction* instr = chunk_->instructions()->at(pos);
+ LInstruction* instr = InstructionAt(pos);
if (instr->HasPointerMap()) {
instr->pointer_map()->RecordPointer(operand);
}
@@ -668,17 +668,17 @@
}
-LGap* LAllocator::GetLastGap(HBasicBlock* block) const {
+LGap* LAllocator::GetLastGap(HBasicBlock* block) {
int last_instruction = block->last_instruction_index();
int index = chunk_->NearestGapPos(last_instruction);
- return chunk_->GetGapAt(index);
+ return GapAt(index);
}
HPhi* LAllocator::LookupPhi(LOperand* operand) const {
if (!operand->IsUnallocated()) return NULL;
int index = operand->VirtualRegister();
- HValue* instr = graph()->LookupValue(index);
+ HValue* instr = graph_->LookupValue(index);
if (instr != NULL && instr->IsPhi()) {
return HPhi::cast(instr);
}
@@ -737,7 +737,7 @@
void LAllocator::AddConstraintsGapMove(int index,
LOperand* from,
LOperand* to) {
- LGap* gap = chunk_->GetGapAt(index);
+ LGap* gap = GapAt(index);
LParallelMove* move = gap->GetOrCreateParallelMove(LGap::START);
if (from->IsUnallocated()) {
const ZoneList<LMoveOperands>* move_operands = move->move_operands();
@@ -760,24 +760,24 @@
int start = block->first_instruction_index();
int end = block->last_instruction_index();
for (int i = start; i <= end; ++i) {
- if (chunk_->IsGapAt(i)) {
- InstructionSummary* summary = NULL;
- InstructionSummary* prev_summary = NULL;
- if (i < end) summary = GetSummary(i + 1);
- if (i > start) prev_summary = GetSummary(i - 1);
- MeetConstraintsBetween(prev_summary, summary, i);
+ if (IsGapAt(i)) {
+ LInstruction* instr = NULL;
+ LInstruction* prev_instr = NULL;
+ if (i < end) instr = InstructionAt(i + 1);
+ if (i > start) prev_instr = InstructionAt(i - 1);
+ MeetConstraintsBetween(prev_instr, instr, i);
}
}
}
-void LAllocator::MeetConstraintsBetween(InstructionSummary* first,
- InstructionSummary* second,
+void LAllocator::MeetConstraintsBetween(LInstruction* first,
+ LInstruction* second,
int gap_index) {
// Handle fixed temporaries.
if (first != NULL) {
- for (int i = 0; i < first->TempCount(); ++i) {
- LUnallocated* temp = LUnallocated::cast(first->TempAt(i));
+ for (TempIterator it(first); it.HasNext(); it.Advance()) {
+ LUnallocated* temp = LUnallocated::cast(it.Next());
if (temp->HasFixedPolicy()) {
AllocateFixed(temp, gap_index - 1, false);
}
@@ -810,7 +810,7 @@
// and splitting of live ranges do not account for it.
// Thus it should be inserted to a lifetime position corresponding to
// the instruction end.
- LGap* gap = chunk_->GetGapAt(gap_index);
+ LGap* gap = GapAt(gap_index);
LParallelMove* move = gap->GetOrCreateParallelMove(LGap::BEFORE);
move->AddMove(first_output, range->GetSpillOperand());
}
@@ -818,8 +818,8 @@
// Handle fixed input operands of second instruction.
if (second != NULL) {
- for (int i = 0; i < second->InputCount(); ++i) {
- LUnallocated* cur_input = LUnallocated::cast(second->InputAt(i));
+ for (UseIterator it(second); it.HasNext(); it.Advance()) {
+ LUnallocated* cur_input = LUnallocated::cast(it.Next());
if (cur_input->HasFixedPolicy()) {
LUnallocated* input_copy = cur_input->CopyUnconstrained();
bool is_tagged = HasTaggedValue(cur_input->VirtualRegister());
@@ -848,7 +848,7 @@
if (second != NULL && second->Output() != NULL) {
LUnallocated* second_output = LUnallocated::cast(second->Output());
if (second_output->HasSameAsInputPolicy()) {
- LUnallocated* cur_input = LUnallocated::cast(second->InputAt(0));
+ LUnallocated* cur_input = LUnallocated::cast(second->FirstInput());
int output_vreg = second_output->VirtualRegister();
int input_vreg = cur_input->VirtualRegister();
@@ -858,7 +858,7 @@
if (HasTaggedValue(input_vreg) && !HasTaggedValue(output_vreg)) {
int index = gap_index + 1;
- LInstruction* instr = chunk_->instructions()->at(index);
+ LInstruction* instr = InstructionAt(index);
if (instr->HasPointerMap()) {
instr->pointer_map()->RecordPointer(input_copy);
}
@@ -886,9 +886,9 @@
LifetimePosition curr_position =
LifetimePosition::FromInstructionIndex(index);
- if (chunk_->IsGapAt(index)) {
+ if (IsGapAt(index)) {
// We have a gap at this position.
- LGap* gap = chunk_->GetGapAt(index);
+ LGap* gap = GapAt(index);
LParallelMove* move = gap->GetOrCreateParallelMove(LGap::START);
const ZoneList<LMoveOperands>* move_operands = move->move_operands();
for (int i = 0; i < move_operands->length(); ++i) {
@@ -922,17 +922,17 @@
}
}
} else {
- ASSERT(!chunk_->IsGapAt(index));
- InstructionSummary* summary = GetSummary(index);
+ ASSERT(!IsGapAt(index));
+ LInstruction* instr = InstructionAt(index);
- if (summary != NULL) {
- LOperand* output = summary->Output();
+ if (instr != NULL) {
+ LOperand* output = instr->Output();
if (output != NULL) {
if (output->IsUnallocated()) live->Remove(output->VirtualRegister());
Define(curr_position, output, NULL);
}
- if (summary->IsCall()) {
+ if (instr->IsMarkedAsCall()) {
for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) {
if (output == NULL || !output->IsRegister() ||
output->index() != i) {
@@ -943,7 +943,7 @@
}
}
- if (summary->IsCall() || summary->IsSaveDoubles()) {
+ if (instr->IsMarkedAsCall() || instr->IsMarkedAsSaveDoubles()) {
for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) {
if (output == NULL || !output->IsDoubleRegister() ||
output->index() != i) {
@@ -954,8 +954,8 @@
}
}
- for (int i = 0; i < summary->InputCount(); ++i) {
- LOperand* input = summary->InputAt(i);
+ for (UseIterator it(instr); it.HasNext(); it.Advance()) {
+ LOperand* input = it.Next();
LifetimePosition use_pos;
if (input->IsUnallocated() &&
@@ -969,9 +969,9 @@
if (input->IsUnallocated()) live->Add(input->VirtualRegister());
}
- for (int i = 0; i < summary->TempCount(); ++i) {
- LOperand* temp = summary->TempAt(i);
- if (summary->IsCall()) {
+ for (TempIterator it(instr); it.HasNext(); it.Advance()) {
+ LOperand* temp = it.Next();
+ if (instr->IsMarkedAsCall()) {
if (temp->IsRegister()) continue;
if (temp->IsUnallocated()) {
LUnallocated* temp_unalloc = LUnallocated::cast(temp);
@@ -1042,9 +1042,9 @@
void LAllocator::MeetRegisterConstraints() {
- HPhase phase("Register constraints", chunk());
+ HPhase phase("Register constraints", chunk_);
first_artificial_register_ = next_virtual_register_;
- const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
+ const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
for (int i = 0; i < blocks->length(); ++i) {
HBasicBlock* block = blocks->at(i);
MeetRegisterConstraints(block);
@@ -1053,10 +1053,10 @@
void LAllocator::ResolvePhis() {
- HPhase phase("Resolve phis", chunk());
+ HPhase phase("Resolve phis", chunk_);
// Process the blocks in reverse order.
- const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
+ const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
for (int block_id = blocks->length() - 1; block_id >= 0; --block_id) {
HBasicBlock* block = blocks->at(block_id);
ResolvePhis(block);
@@ -1096,7 +1096,7 @@
if (!pred_op->Equals(cur_op)) {
LGap* gap = NULL;
if (block->predecessors()->length() == 1) {
- gap = chunk_->GetGapAt(block->first_instruction_index());
+ gap = GapAt(block->first_instruction_index());
} else {
ASSERT(pred->end()->SecondSuccessor() == NULL);
gap = GetLastGap(pred);
@@ -1109,19 +1109,19 @@
LParallelMove* LAllocator::GetConnectingParallelMove(LifetimePosition pos) {
int index = pos.InstructionIndex();
- if (chunk_->IsGapAt(index)) {
- LGap* gap = chunk_->GetGapAt(index);
+ if (IsGapAt(index)) {
+ LGap* gap = GapAt(index);
return gap->GetOrCreateParallelMove(
pos.IsInstructionStart() ? LGap::START : LGap::END);
}
int gap_pos = pos.IsInstructionStart() ? (index - 1) : (index + 1);
- return chunk_->GetGapAt(gap_pos)->GetOrCreateParallelMove(
+ return GapAt(gap_pos)->GetOrCreateParallelMove(
(gap_pos < index) ? LGap::AFTER : LGap::BEFORE);
}
HBasicBlock* LAllocator::GetBlock(LifetimePosition pos) {
- LGap* gap = chunk_->GetGapAt(chunk_->NearestGapPos(pos.InstructionIndex()));
+ LGap* gap = GapAt(chunk_->NearestGapPos(pos.InstructionIndex()));
return gap->block();
}
@@ -1168,7 +1168,7 @@
void LAllocator::ResolveControlFlow() {
HPhase phase("Resolve control flow", this);
- const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
+ const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
for (int block_id = 1; block_id < blocks->length(); ++block_id) {
HBasicBlock* block = blocks->at(block_id);
if (CanEagerlyResolveControlFlow(block)) continue;
@@ -1191,7 +1191,7 @@
HPhase phase("Build live ranges", this);
InitializeLivenessAnalysis();
// Process the blocks in reverse order.
- const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
+ const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
for (int block_id = blocks->length() - 1; block_id >= 0; --block_id) {
HBasicBlock* block = blocks->at(block_id);
BitVector* live = ComputeLiveOut(block);
@@ -1266,7 +1266,7 @@
found = true;
int operand_index = iterator.Current();
PrintF("Function: %s\n",
- *graph()->info()->function()->debug_name()->ToCString());
+ *graph_->info()->function()->debug_name()->ToCString());
PrintF("Value %d used before first definition!\n", operand_index);
LiveRange* range = LiveRangeFor(operand_index);
PrintF("First use is at %d\n", range->first_pos()->pos().Value());
@@ -1471,7 +1471,7 @@
if (current->HasAllocatedSpillOperand()) {
TraceAlloc("Live range %d already has a spill operand\n", current->id());
LifetimePosition next_pos = position;
- if (chunk_->IsGapAt(next_pos.InstructionIndex())) {
+ if (IsGapAt(next_pos.InstructionIndex())) {
next_pos = next_pos.NextInstruction();
}
UsePosition* pos = current->NextUsePositionRegisterIsBeneficial(next_pos);
@@ -1558,14 +1558,8 @@
}
-void LAllocator::RecordUse(HValue* value, LUnallocated* operand) {
- operand->set_virtual_register(value->id());
- current_summary()->AddInput(operand);
-}
-
-
bool LAllocator::HasTaggedValue(int virtual_register) const {
- HValue* value = graph()->LookupValue(virtual_register);
+ HValue* value = graph_->LookupValue(virtual_register);
if (value == NULL) return false;
return value->representation().IsTagged();
}
@@ -1573,7 +1567,7 @@
RegisterKind LAllocator::RequiredRegisterKind(int virtual_register) const {
if (virtual_register < first_artificial_register_) {
- HValue* value = graph()->LookupValue(virtual_register);
+ HValue* value = graph_->LookupValue(virtual_register);
if (value != NULL && value->representation().IsDouble()) {
return DOUBLE_REGISTERS;
}
@@ -1586,39 +1580,8 @@
}
-void LAllocator::MarkAsCall() {
- // Call instructions can use only fixed registers as
- // temporaries and outputs because all registers
- // are blocked by the calling convention.
- // Inputs can use either fixed register or have a short lifetime (be
- // used at start of the instruction).
- InstructionSummary* summary = current_summary();
-#ifdef DEBUG
- ASSERT(summary->Output() == NULL ||
- LUnallocated::cast(summary->Output())->HasFixedPolicy() ||
- !LUnallocated::cast(summary->Output())->HasRegisterPolicy());
- for (int i = 0; i < summary->InputCount(); i++) {
- ASSERT(LUnallocated::cast(summary->InputAt(i))->HasFixedPolicy() ||
- LUnallocated::cast(summary->InputAt(i))->IsUsedAtStart() ||
- !LUnallocated::cast(summary->InputAt(i))->HasRegisterPolicy());
- }
- for (int i = 0; i < summary->TempCount(); i++) {
- ASSERT(LUnallocated::cast(summary->TempAt(i))->HasFixedPolicy() ||
- !LUnallocated::cast(summary->TempAt(i))->HasRegisterPolicy());
- }
-#endif
- summary->MarkAsCall();
-}
-
-
-void LAllocator::MarkAsSaveDoubles() {
- current_summary()->MarkAsSaveDoubles();
-}
-
-
void LAllocator::RecordDefinition(HInstruction* instr, LUnallocated* operand) {
operand->set_virtual_register(instr->id());
- current_summary()->SetOutput(operand);
}
@@ -1627,43 +1590,19 @@
if (!operand->HasFixedPolicy()) {
operand->set_virtual_register(next_virtual_register_++);
}
- current_summary()->AddTemp(operand);
}
-int LAllocator::max_initial_value_ids() {
- return LUnallocated::kMaxVirtualRegisters / 32;
+void LAllocator::RecordUse(HValue* value, LUnallocated* operand) {
+ operand->set_virtual_register(value->id());
}
-void LAllocator::BeginInstruction() {
- if (next_summary_ == NULL) {
- next_summary_ = new InstructionSummary();
- }
- summary_stack_.Add(next_summary_);
- next_summary_ = NULL;
+int LAllocator::max_initial_value_ids() {
+ return LUnallocated::kMaxVirtualRegisters / 32;
}
-void LAllocator::SummarizeInstruction(int index) {
- InstructionSummary* sum = summary_stack_.RemoveLast();
- if (summaries_.length() <= index) {
- summaries_.AddBlock(NULL, index + 1 - summaries_.length());
- }
- ASSERT(summaries_[index] == NULL);
- if (sum->Output() != NULL || sum->InputCount() > 0 || sum->TempCount() > 0) {
- summaries_[index] = sum;
- } else {
- next_summary_ = sum;
- }
-}
-
-
-void LAllocator::OmitInstruction() {
- summary_stack_.RemoveLast();
-}
-
-
void LAllocator::AddToActive(LiveRange* range) {
TraceAlloc("Add live range %d to active\n", range->id());
active_live_ranges_.Add(range);
@@ -2009,7 +1948,7 @@
bool LAllocator::IsBlockBoundary(LifetimePosition pos) {
return pos.IsInstructionStart() &&
- chunk_->instructions()->at(pos.InstructionIndex())->IsLabel();
+ InstructionAt(pos.InstructionIndex())->IsLabel();
}
« no previous file with comments | « src/lithium-allocator.h ('k') | src/lithium-allocator-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698