From a25460eaebca890d4a4021573158dddca8787d65 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sun, 7 Jul 2013 22:11:39 -0700 Subject: [PATCH] Micro-optimize a hot spot in LinearScan; this partially addresses Bug 741317. r=jandem --- js/src/ion/LIR.h | 3 +++ js/src/ion/LinearScan.cpp | 39 +++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/js/src/ion/LIR.h b/js/src/ion/LIR.h index e953c39271c5..233508d4f7f9 100644 --- a/js/src/ion/LIR.h +++ b/js/src/ion/LIR.h @@ -164,6 +164,9 @@ class LAllocation : public TempObject bool isRegister() const { return isGeneralReg() || isFloatReg(); } + bool isRegister(bool needFloat) const { + return needFloat ? isFloatReg() : isGeneralReg(); + } bool isMemory() const { return isStackSlot() || isArgument(); } diff --git a/js/src/ion/LinearScan.cpp b/js/src/ion/LinearScan.cpp index b18cdc9b3cd5..d790fbe00210 100644 --- a/js/src/ion/LinearScan.cpp +++ b/js/src/ion/LinearScan.cpp @@ -906,21 +906,22 @@ LinearScanAllocator::findBestFreeRegister(CodePosition *freeUntil) // Compute free-until positions for all registers CodePosition freeUntilPos[AnyRegister::Total]; bool needFloat = vregs[current->vreg()].isDouble(); - for (AnyRegisterIterator regs(allRegisters_); regs.more(); regs++) { - AnyRegister reg = *regs; - if (reg.isFloat() == needFloat) - freeUntilPos[reg.code()] = CodePosition::MAX; + for (RegisterSet regs(allRegisters_); !regs.empty(needFloat); ) { + AnyRegister reg = regs.takeAny(needFloat); + freeUntilPos[reg.code()] = CodePosition::MAX; } for (IntervalIterator i(active.begin()); i != active.end(); i++) { - if (i->getAllocation()->isRegister()) { - AnyRegister reg = i->getAllocation()->toRegister(); + LAllocation *alloc = i->getAllocation(); + if (alloc->isRegister(needFloat)) { + AnyRegister reg = alloc->toRegister(); IonSpew(IonSpew_RegAlloc, " Register %s not free", reg.name()); freeUntilPos[reg.code()] = CodePosition::MIN; } } for (IntervalIterator i(inactive.begin()); i != inactive.end(); i++) { - if (i->getAllocation()->isRegister()) { - AnyRegister reg = i->getAllocation()->toRegister(); + LAllocation *alloc = i->getAllocation(); + if (alloc->isRegister(needFloat)) { + AnyRegister reg = alloc->toRegister(); CodePosition pos = current->intersect(*i); if (pos != CodePosition::MIN && pos < freeUntilPos[reg.code()]) { freeUntilPos[reg.code()] = pos; @@ -948,8 +949,9 @@ LinearScanAllocator::findBestFreeRegister(CodePosition *freeUntil) // As an optimization, use the allocation from the previous interval if // it is available. LiveInterval *previous = vregs[current->vreg()].getInterval(current->index() - 1); - if (previous->getAllocation()->isRegister()) { - AnyRegister prevReg = previous->getAllocation()->toRegister(); + LAllocation *alloc = previous->getAllocation(); + if (alloc->isRegister(needFloat)) { + AnyRegister prevReg = alloc->toRegister(); if (freeUntilPos[prevReg.code()] != CodePosition::MIN) bestCode = prevReg.code(); } @@ -999,14 +1001,14 @@ LinearScanAllocator::findBestBlockedRegister(CodePosition *nextUsed) // Compute next-used positions for all registers CodePosition nextUsePos[AnyRegister::Total]; bool needFloat = vregs[current->vreg()].isDouble(); - for (AnyRegisterIterator regs(allRegisters_); regs.more(); regs++) { - AnyRegister reg = *regs; - if (reg.isFloat() == needFloat) - nextUsePos[reg.code()] = CodePosition::MAX; + for (RegisterSet regs(allRegisters_); !regs.empty(needFloat); ) { + AnyRegister reg = regs.takeAny(needFloat); + nextUsePos[reg.code()] = CodePosition::MAX; } for (IntervalIterator i(active.begin()); i != active.end(); i++) { - if (i->getAllocation()->isRegister()) { - AnyRegister reg = i->getAllocation()->toRegister(); + LAllocation *alloc = i->getAllocation(); + if (alloc->isRegister(needFloat)) { + AnyRegister reg = alloc->toRegister(); if (i->start().ins() == current->start().ins()) { nextUsePos[reg.code()] = CodePosition::MIN; IonSpew(IonSpew_RegAlloc, " Disqualifying %s due to recency", reg.name()); @@ -1018,8 +1020,9 @@ LinearScanAllocator::findBestBlockedRegister(CodePosition *nextUsed) } } for (IntervalIterator i(inactive.begin()); i != inactive.end(); i++) { - if (i->getAllocation()->isRegister()) { - AnyRegister reg = i->getAllocation()->toRegister(); + LAllocation *alloc = i->getAllocation(); + if (alloc->isRegister(needFloat)) { + AnyRegister reg = alloc->toRegister(); CodePosition pos = i->nextUsePosAfter(current->start()); if (pos < nextUsePos[reg.code()]) { nextUsePos[reg.code()] = pos;