| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 static inline LifetimePosition Min(LifetimePosition a, LifetimePosition b) { | 64 static inline LifetimePosition Min(LifetimePosition a, LifetimePosition b) { |
| 65 return a.Value() < b.Value() ? a : b; | 65 return a.Value() < b.Value() ? a : b; |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 static inline LifetimePosition Max(LifetimePosition a, LifetimePosition b) { | 69 static inline LifetimePosition Max(LifetimePosition a, LifetimePosition b) { |
| 70 return a.Value() > b.Value() ? a : b; | 70 return a.Value() > b.Value() ? a : b; |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 void LOperand::PrintTo(StringStream* stream) { | 74 UsePosition::UsePosition(LifetimePosition pos, LOperand* operand) |
| 75 LUnallocated* unalloc = NULL; | 75 : operand_(operand), |
| 76 switch (kind()) { | 76 hint_(NULL), |
| 77 case INVALID: | 77 pos_(pos), |
| 78 break; | 78 next_(NULL), |
| 79 case UNALLOCATED: | 79 requires_reg_(false), |
| 80 unalloc = LUnallocated::cast(this); | 80 register_beneficial_(true) { |
| 81 stream->Add("v%d", unalloc->virtual_register()); | 81 if (operand_ != NULL && operand_->IsUnallocated()) { |
| 82 switch (unalloc->policy()) { | 82 LUnallocated* unalloc = LUnallocated::cast(operand_); |
| 83 case LUnallocated::NONE: | 83 requires_reg_ = unalloc->HasRegisterPolicy(); |
| 84 break; | 84 register_beneficial_ = !unalloc->HasAnyPolicy(); |
| 85 case LUnallocated::FIXED_REGISTER: { | |
| 86 const char* register_name = | |
| 87 Register::AllocationIndexToString(unalloc->fixed_index()); | |
| 88 stream->Add("(=%s)", register_name); | |
| 89 break; | |
| 90 } | |
| 91 case LUnallocated::FIXED_DOUBLE_REGISTER: { | |
| 92 const char* double_register_name = | |
| 93 DoubleRegister::AllocationIndexToString(unalloc->fixed_index()); | |
| 94 stream->Add("(=%s)", double_register_name); | |
| 95 break; | |
| 96 } | |
| 97 case LUnallocated::FIXED_SLOT: | |
| 98 stream->Add("(=%dS)", unalloc->fixed_index()); | |
| 99 break; | |
| 100 case LUnallocated::MUST_HAVE_REGISTER: | |
| 101 stream->Add("(R)"); | |
| 102 break; | |
| 103 case LUnallocated::WRITABLE_REGISTER: | |
| 104 stream->Add("(WR)"); | |
| 105 break; | |
| 106 case LUnallocated::SAME_AS_FIRST_INPUT: | |
| 107 stream->Add("(1)"); | |
| 108 break; | |
| 109 case LUnallocated::ANY: | |
| 110 stream->Add("(-)"); | |
| 111 break; | |
| 112 case LUnallocated::IGNORE: | |
| 113 stream->Add("(0)"); | |
| 114 break; | |
| 115 } | |
| 116 break; | |
| 117 case CONSTANT_OPERAND: | |
| 118 stream->Add("[constant:%d]", index()); | |
| 119 break; | |
| 120 case STACK_SLOT: | |
| 121 stream->Add("[stack:%d]", index()); | |
| 122 break; | |
| 123 case DOUBLE_STACK_SLOT: | |
| 124 stream->Add("[double_stack:%d]", index()); | |
| 125 break; | |
| 126 case REGISTER: | |
| 127 stream->Add("[%s|R]", Register::AllocationIndexToString(index())); | |
| 128 break; | |
| 129 case DOUBLE_REGISTER: | |
| 130 stream->Add("[%s|R]", DoubleRegister::AllocationIndexToString(index())); | |
| 131 break; | |
| 132 case ARGUMENT: | |
| 133 stream->Add("[arg:%d]", index()); | |
| 134 break; | |
| 135 } | 85 } |
| 136 } | 86 ASSERT(pos_.IsValid()); |
| 137 | |
| 138 int LOperand::VirtualRegister() { | |
| 139 LUnallocated* unalloc = LUnallocated::cast(this); | |
| 140 return unalloc->virtual_register(); | |
| 141 } | 87 } |
| 142 | 88 |
| 143 | 89 |
| 90 bool UsePosition::HasHint() const { |
| 91 return hint_ != NULL && !hint_->IsUnallocated(); |
| 92 } |
| 93 |
| 94 |
| 144 bool UsePosition::RequiresRegister() const { | 95 bool UsePosition::RequiresRegister() const { |
| 145 return requires_reg_; | 96 return requires_reg_; |
| 146 } | 97 } |
| 147 | 98 |
| 148 | 99 |
| 149 bool UsePosition::RegisterIsBeneficial() const { | 100 bool UsePosition::RegisterIsBeneficial() const { |
| 150 return register_beneficial_; | 101 return register_beneficial_; |
| 151 } | 102 } |
| 152 | 103 |
| 153 | 104 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 183 } | 134 } |
| 184 current_interval = current_interval->next(); | 135 current_interval = current_interval->next(); |
| 185 } | 136 } |
| 186 return false; | 137 return false; |
| 187 } | 138 } |
| 188 | 139 |
| 189 | 140 |
| 190 #endif | 141 #endif |
| 191 | 142 |
| 192 | 143 |
| 144 LiveRange::LiveRange(int id) |
| 145 : id_(id), |
| 146 spilled_(false), |
| 147 assigned_register_(kInvalidAssignment), |
| 148 assigned_register_kind_(NONE), |
| 149 last_interval_(NULL), |
| 150 first_interval_(NULL), |
| 151 first_pos_(NULL), |
| 152 parent_(NULL), |
| 153 next_(NULL), |
| 154 current_interval_(NULL), |
| 155 last_processed_use_(NULL), |
| 156 spill_start_index_(kMaxInt) { |
| 157 spill_operand_ = new LUnallocated(LUnallocated::IGNORE); |
| 158 } |
| 159 |
| 160 |
| 161 void LiveRange::set_assigned_register(int reg, RegisterKind register_kind) { |
| 162 ASSERT(!HasRegisterAssigned() && !IsSpilled()); |
| 163 assigned_register_ = reg; |
| 164 assigned_register_kind_ = register_kind; |
| 165 ConvertOperands(); |
| 166 } |
| 167 |
| 168 |
| 169 void LiveRange::MakeSpilled() { |
| 170 ASSERT(!IsSpilled()); |
| 171 ASSERT(TopLevel()->HasAllocatedSpillOperand()); |
| 172 spilled_ = true; |
| 173 assigned_register_ = kInvalidAssignment; |
| 174 ConvertOperands(); |
| 175 } |
| 176 |
| 177 |
| 178 bool LiveRange::HasAllocatedSpillOperand() const { |
| 179 return spill_operand_ != NULL && !spill_operand_->IsUnallocated(); |
| 180 } |
| 181 |
| 182 |
| 183 void LiveRange::SetSpillOperand(LOperand* operand) { |
| 184 ASSERT(!operand->IsUnallocated()); |
| 185 ASSERT(spill_operand_ != NULL); |
| 186 ASSERT(spill_operand_->IsUnallocated()); |
| 187 spill_operand_->ConvertTo(operand->kind(), operand->index()); |
| 188 } |
| 189 |
| 190 |
| 193 UsePosition* LiveRange::NextUsePosition(LifetimePosition start) { | 191 UsePosition* LiveRange::NextUsePosition(LifetimePosition start) { |
| 194 UsePosition* use_pos = last_processed_use_; | 192 UsePosition* use_pos = last_processed_use_; |
| 195 if (use_pos == NULL) use_pos = first_pos(); | 193 if (use_pos == NULL) use_pos = first_pos(); |
| 196 while (use_pos != NULL && use_pos->pos().Value() < start.Value()) { | 194 while (use_pos != NULL && use_pos->pos().Value() < start.Value()) { |
| 197 use_pos = use_pos->next(); | 195 use_pos = use_pos->next(); |
| 198 } | 196 } |
| 199 last_processed_use_ = use_pos; | 197 last_processed_use_ = use_pos; |
| 200 return use_pos; | 198 return use_pos; |
| 201 } | 199 } |
| 202 | 200 |
| (...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2008 } | 2006 } |
| 2009 } | 2007 } |
| 2010 | 2008 |
| 2011 | 2009 |
| 2012 bool LAllocator::IsBlockBoundary(LifetimePosition pos) { | 2010 bool LAllocator::IsBlockBoundary(LifetimePosition pos) { |
| 2013 return pos.IsInstructionStart() && | 2011 return pos.IsInstructionStart() && |
| 2014 chunk_->instructions()->at(pos.InstructionIndex())->IsLabel(); | 2012 chunk_->instructions()->at(pos.InstructionIndex())->IsLabel(); |
| 2015 } | 2013 } |
| 2016 | 2014 |
| 2017 | 2015 |
| 2018 void LAllocator::AddGapMove(int pos, LiveRange* prev, LiveRange* next) { | |
| 2019 UsePosition* prev_pos = prev->AddUsePosition( | |
| 2020 LifetimePosition::FromInstructionIndex(pos)); | |
| 2021 UsePosition* next_pos = next->AddUsePosition( | |
| 2022 LifetimePosition::FromInstructionIndex(pos)); | |
| 2023 LOperand* prev_operand = prev_pos->operand(); | |
| 2024 LOperand* next_operand = next_pos->operand(); | |
| 2025 LGap* gap = chunk_->GetGapAt(pos); | |
| 2026 gap->GetOrCreateParallelMove(LGap::START)-> | |
| 2027 AddMove(prev_operand, next_operand); | |
| 2028 next_pos->set_hint(prev_operand); | |
| 2029 } | |
| 2030 | |
| 2031 | |
| 2032 LiveRange* LAllocator::SplitAt(LiveRange* range, LifetimePosition pos) { | 2016 LiveRange* LAllocator::SplitAt(LiveRange* range, LifetimePosition pos) { |
| 2033 ASSERT(!range->IsFixed()); | 2017 ASSERT(!range->IsFixed()); |
| 2034 TraceAlloc("Splitting live range %d at %d\n", range->id(), pos.Value()); | 2018 TraceAlloc("Splitting live range %d at %d\n", range->id(), pos.Value()); |
| 2035 | 2019 |
| 2036 if (pos.Value() <= range->Start().Value()) return range; | 2020 if (pos.Value() <= range->Start().Value()) return range; |
| 2037 | 2021 |
| 2038 LiveRange* result = LiveRangeFor(next_virtual_register_++); | 2022 LiveRange* result = LiveRangeFor(next_virtual_register_++); |
| 2039 range->SplitAt(pos, result); | 2023 range->SplitAt(pos, result); |
| 2040 return result; | 2024 return result; |
| 2041 } | 2025 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 LiveRange* current = live_ranges()->at(i); | 2132 LiveRange* current = live_ranges()->at(i); |
| 2149 if (current != NULL) current->Verify(); | 2133 if (current != NULL) current->Verify(); |
| 2150 } | 2134 } |
| 2151 } | 2135 } |
| 2152 | 2136 |
| 2153 | 2137 |
| 2154 #endif | 2138 #endif |
| 2155 | 2139 |
| 2156 | 2140 |
| 2157 } } // namespace v8::internal | 2141 } } // namespace v8::internal |
| OLD | NEW |