Author: [email protected]
Date: Wed Mar 18 03:31:31 2009
New Revision: 1528
Modified:
branches/bleeding_edge/src/register-allocator.cc
branches/bleeding_edge/src/register-allocator.h
Log:
Speed up the inner loop of free register allocation.
Review URL: http://codereview.chromium.org/42296
Modified: branches/bleeding_edge/src/register-allocator.cc
==============================================================================
--- branches/bleeding_edge/src/register-allocator.cc (original)
+++ branches/bleeding_edge/src/register-allocator.cc Wed Mar 18 03:31:31
2009
@@ -83,11 +83,10 @@
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_);
}
Modified: branches/bleeding_edge/src/register-allocator.h
==============================================================================
--- branches/bleeding_edge/src/register-allocator.h (original)
+++ branches/bleeding_edge/src/register-allocator.h Wed Mar 18 03:31:31 2009
@@ -149,10 +149,9 @@
// 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.
@@ -160,6 +159,17 @@
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;
};
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---