Commit 10be4f7f authored by whesse@chromium.org's avatar whesse@chromium.org

Speed up the inner loop of free register allocation.

Review URL: http://codereview.chromium.org/42296

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1528 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 22f9dbf6
...@@ -83,11 +83,10 @@ void RegisterFile::CopyTo(RegisterFile* other) { ...@@ -83,11 +83,10 @@ void RegisterFile::CopyTo(RegisterFile* other) {
Result RegisterAllocator::AllocateWithoutSpilling() { Result RegisterAllocator::AllocateWithoutSpilling() {
// Return the first free register, if any. // Return the first free register, if any.
for (int i = 0; i < kNumRegisters; i++) { int free_reg = registers_.ScanForFreeRegister();
if (!is_used(i)) { if (free_reg < kNumRegisters) {
Register free_reg = { i }; Register free_result = { free_reg };
return Result(free_reg, cgen_); return Result(free_result, cgen_);
}
} }
return Result(cgen_); return Result(cgen_);
} }
......
...@@ -149,10 +149,9 @@ class RegisterFile BASE_EMBEDDED { ...@@ -149,10 +149,9 @@ class RegisterFile BASE_EMBEDDED {
// Record that a register will no longer be used by decrementing its // Record that a register will no longer be used by decrementing its
// reference count. // reference count.
void Unuse(Register reg) { void Unuse(Register reg) {
ASSERT(!reg.is(no_reg));
ASSERT(is_used(reg.code())); ASSERT(is_used(reg.code()));
if (is_used(reg.code())) { ref_counts_[reg.code()]--;
ref_counts_[reg.code()]--;
}
} }
// Copy the reference counts from this register file to the other. // Copy the reference counts from this register file to the other.
...@@ -161,6 +160,17 @@ class RegisterFile BASE_EMBEDDED { ...@@ -161,6 +160,17 @@ class RegisterFile BASE_EMBEDDED {
private: private:
int ref_counts_[kNumRegisters]; int ref_counts_[kNumRegisters];
// Very fast inlined loop to find a free register.
// Used in RegisterAllocator::AllocateWithoutSpilling.
// Returns kNumRegisters if no free register found.
inline int ScanForFreeRegister() {
int i = 0;
for (; i < kNumRegisters ; ++i) {
if (ref_counts_[i] == 0) break;
}
return i;
}
friend class RegisterAllocator; friend class RegisterAllocator;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment