vendor/v8/src/lithium-allocator.cc in mustang-0.0.1 vs vendor/v8/src/lithium-allocator.cc in mustang-0.1.0

- old
+ new

@@ -23,10 +23,11 @@ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (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 "v8.h" #include "lithium-allocator-inl.h" #include "hydrogen.h" #include "string-stream.h" @@ -34,25 +35,32 @@ #include "ia32/lithium-ia32.h" #elif V8_TARGET_ARCH_X64 #include "x64/lithium-x64.h" #elif V8_TARGET_ARCH_ARM #include "arm/lithium-arm.h" +#elif V8_TARGET_ARCH_MIPS +#include "mips/lithium-mips.h" #else #error "Unknown architecture." #endif namespace v8 { namespace internal { -#define DEFINE_OPERAND_CACHE(name, type) \ - name name::cache[name::kNumCachedOperands]; \ - void name::SetupCache() { \ - for (int i = 0; i < kNumCachedOperands; i++) { \ - cache[i].ConvertTo(type, i); \ - } \ - } +#define DEFINE_OPERAND_CACHE(name, type) \ + name name::cache[name::kNumCachedOperands]; \ + void name::SetupCache() { \ + for (int i = 0; i < kNumCachedOperands; i++) { \ + cache[i].ConvertTo(type, i); \ + } \ + } \ + static bool name##_initialize() { \ + name::SetupCache(); \ + return true; \ + } \ + static bool name##_cache_initialized = name##_initialize(); DEFINE_OPERAND_CACHE(LConstantOperand, CONSTANT_OPERAND) DEFINE_OPERAND_CACHE(LStackSlot, STACK_SLOT) DEFINE_OPERAND_CACHE(LDoubleStackSlot, DOUBLE_STACK_SLOT) DEFINE_OPERAND_CACHE(LRegister, REGISTER) @@ -523,10 +531,28 @@ } return LifetimePosition::Invalid(); } +LAllocator::LAllocator(int num_values, HGraph* graph) + : chunk_(NULL), + live_in_sets_(graph->blocks()->length()), + live_ranges_(num_values * 2), + fixed_live_ranges_(NULL), + fixed_double_live_ranges_(NULL), + unhandled_live_ranges_(num_values * 2), + active_live_ranges_(8), + inactive_live_ranges_(8), + reusable_slots_(8), + next_virtual_register_(num_values), + first_artificial_register_(num_values), + mode_(NONE), + num_registers_(-1), + graph_(graph), + has_osr_entry_(false) {} + + void LAllocator::InitializeLivenessAnalysis() { // Initialize the live_in sets for each block to NULL. int block_count = graph_->blocks()->length(); live_in_sets_.Initialize(block_count); live_in_sets_.AddBlock(NULL, block_count); @@ -616,15 +642,11 @@ return operand; } LiveRange* LAllocator::FixedLiveRangeFor(int index) { - if (index >= fixed_live_ranges_.length()) { - fixed_live_ranges_.AddBlock(NULL, - index - fixed_live_ranges_.length() + 1); - } - + ASSERT(index < Register::kNumAllocatableRegisters); LiveRange* result = fixed_live_ranges_[index]; if (result == NULL) { result = new LiveRange(FixedLiveRangeID(index)); ASSERT(result->IsFixed()); result->set_assigned_register(index, GENERAL_REGISTERS); @@ -633,25 +655,22 @@ return result; } LiveRange* LAllocator::FixedDoubleLiveRangeFor(int index) { - if (index >= fixed_double_live_ranges_.length()) { - fixed_double_live_ranges_.AddBlock(NULL, - index - fixed_double_live_ranges_.length() + 1); - } - + ASSERT(index < DoubleRegister::kNumAllocatableRegisters); LiveRange* result = fixed_double_live_ranges_[index]; if (result == NULL) { result = new LiveRange(FixedDoubleLiveRangeID(index)); ASSERT(result->IsFixed()); result->set_assigned_register(index, DOUBLE_REGISTERS); fixed_double_live_ranges_[index] = result; } return result; } + LiveRange* LAllocator::LiveRangeFor(int index) { if (index >= live_ranges_.length()) { live_ranges_.AddBlock(NULL, index - live_ranges_.length() + 1); } LiveRange* result = live_ranges_[index]; @@ -1272,11 +1291,11 @@ bool found = false; while (!iterator.Done()) { found = true; int operand_index = iterator.Current(); PrintF("Function: %s\n", - *graph_->info()->function()->debug_name()->ToCString()); + *chunk_->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()); iterator.Advance(); } @@ -1434,11 +1453,11 @@ } void LAllocator::AllocateRegisters() { ASSERT(mode_ != NONE); - reusable_slots_.Clear(); + ASSERT(unhandled_live_ranges_.is_empty()); for (int i = 0; i < live_ranges_.length(); ++i) { if (live_ranges_[i] != NULL) { if (RequiredRegisterKind(live_ranges_[i]->id()) == mode_) { AddToUnhandledUnsorted(live_ranges_[i]); @@ -1446,10 +1465,11 @@ } } SortUnhandled(); ASSERT(UnhandledIsSorted()); + ASSERT(reusable_slots_.is_empty()); ASSERT(active_live_ranges_.is_empty()); ASSERT(inactive_live_ranges_.is_empty()); if (mode_ == DOUBLE_REGISTERS) { for (int i = 0; i < fixed_double_live_ranges_.length(); ++i) { @@ -1530,20 +1550,12 @@ if (current->HasRegisterAssigned()) { AddToActive(current); } } - active_live_ranges_.Clear(); - inactive_live_ranges_.Clear(); -} - - -void LAllocator::Setup() { - LConstantOperand::SetupCache(); - LStackSlot::SetupCache(); - LDoubleStackSlot::SetupCache(); - LRegister::SetupCache(); - LDoubleRegister::SetupCache(); + reusable_slots_.Rewind(0); + active_live_ranges_.Rewind(0); + inactive_live_ranges_.Rewind(0); } const char* LAllocator::RegisterName(int allocation_index) { ASSERT(mode_ != NONE);