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
This commit is contained in:
parent
22f9dbf651
commit
10be4f7ffd
@ -83,11 +83,10 @@ void RegisterFile::CopyTo(RegisterFile* other) {
|
||||
|
||||
Result RegisterAllocator::AllocateWithoutSpilling() {
|
||||
// Return the first free register, if any.
|
||||
for (int i = 0; i < kNumRegisters; i++) {
|
||||
if (!is_used(i)) {
|
||||
Register free_reg = { i };
|
||||
return Result(free_reg, cgen_);
|
||||
}
|
||||
int free_reg = registers_.ScanForFreeRegister();
|
||||
if (free_reg < kNumRegisters) {
|
||||
Register free_result = { free_reg };
|
||||
return Result(free_result, cgen_);
|
||||
}
|
||||
return Result(cgen_);
|
||||
}
|
||||
|
@ -149,10 +149,9 @@ class RegisterFile BASE_EMBEDDED {
|
||||
// Record that a register will no longer be used by decrementing its
|
||||
// reference count.
|
||||
void Unuse(Register reg) {
|
||||
ASSERT(!reg.is(no_reg));
|
||||
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.
|
||||
@ -161,6 +160,17 @@ class RegisterFile BASE_EMBEDDED {
|
||||
private:
|
||||
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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user