Changeset 250999 in webkit for trunk/Source/JavaScriptCore/b3


Ignore:
Timestamp:
Oct 10, 2019, 7:23:37 PM (6 years ago)
Author:
[email protected]
Message:

GenerateAndAllocateRegisters can trivially elide self moves at end of liveness
https://bugs.webkit.org/show_bug.cgi?id=202833

Reviewed by Saam Barati.

This also fixes a bug where if a tmp is moved to itself at the end of its lifetime
we would mess up the accounting for the tmp.

In order to catch these bugs earlier during generation I added a
checkConsistency function that if a tmp is in a reg that reg is
not available and that reg thinks the tmp is also allocated in it.

  • b3/B3Bank.h:

(JSC::B3::bankForReg):

  • b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp:

(JSC::B3::Air::GenerateAndAllocateRegisters::checkConsistency):
(JSC::B3::Air::GenerateAndAllocateRegisters::generate):

  • b3/air/AirAllocateRegistersAndStackAndGenerateCode.h:
Location:
trunk/Source/JavaScriptCore/b3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/b3/B3Bank.h

    r250005 r250999  
    2929
    3030#include "B3Type.h"
     31#include "Reg.h"
    3132
    3233namespace JSC { namespace B3 {
     
    6465}
    6566
     67inline Bank bankForReg(Reg reg)
     68{
     69    return reg.isGPR() ? GP : FP;
     70}
     71
    6672} } // namespace JSC::B3
    6773
  • trunk/Source/JavaScriptCore/b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp

    r250176 r250999  
    4646{ }
    4747
     48ALWAYS_INLINE void GenerateAndAllocateRegisters::checkConsistency()
     49{
     50#if !ASSERT_DISABLED
     51    m_code.forEachTmp([&] (Tmp tmp) {
     52        Reg reg = m_map[tmp].reg;
     53        if (!reg)
     54            return;
     55
     56        ASSERT(!m_availableRegs[tmp.bank()].contains(reg));
     57        ASSERT(m_currentAllocation->at(reg) == tmp);
     58    });
     59
     60    for (Reg reg : RegisterSet::allRegisters()) {
     61        if (isDisallowedRegister(reg))
     62            continue;
     63
     64        Tmp tmp = m_currentAllocation->at(reg);
     65        if (!tmp) {
     66            ASSERT(m_availableRegs[bankForReg(reg)].contains(reg));
     67            continue;
     68        }
     69
     70        ASSERT(!m_availableRegs[tmp.bank()].contains(reg));
     71        ASSERT(m_map[tmp].reg == reg);
     72    }
     73#endif
     74}
     75
    4876void GenerateAndAllocateRegisters::buildLiveRanges(UnifiedTmpLiveness& liveness)
    4977{
     
    417445        bool isReplayingSameInst = false;
    418446        for (size_t instIndex = 0; instIndex < block->size(); ++instIndex) {
     447            checkConsistency();
     448
    419449            if (instIndex && !isReplayingSameInst)
    420450                startLabel = m_jit->labelIgnoringWatchpoints();
     
    445475                    return true;
    446476
     477                // If we are doing a self move at the end of the temps liveness we can trivially elide the move.
     478                if (source == dest)
     479                    return false;
     480
    447481                Reg sourceReg = m_map[source.tmp()].reg;
    448482                // If the value is not already materialized into a register we may still move it into one so let the normal generation code run.
     
    463497                return false;
    464498            })();
     499            checkConsistency();
    465500
    466501            inst.forEachArg([&] (Arg& arg, Arg::Role role, Bank, Width) {
  • trunk/Source/JavaScriptCore/b3/air/AirAllocateRegistersAndStackAndGenerateCode.h

    r250176 r250999  
    6565    bool isDisallowedRegister(Reg);
    6666
     67    void checkConsistency();
     68
    6769    Code& m_code;
    6870    CCallHelpers* m_jit { nullptr };
Note: See TracChangeset for help on using the changeset viewer.