Changeset 245035 in webkit


Ignore:
Timestamp:
May 7, 2019 2:28:38 PM (5 years ago)
Author:
rmorisset@apple.com
Message:

[B3] Constants should be hoisted to the root block until moveConstants
https://bugs.webkit.org/show_bug.cgi?id=197265

Reviewed by Saam Barati.

This patch does the following:

  • B3ReduceStrength now hoists all constants to the root BB, and de-duplicates them along the way
  • B3PureCSE no longer bothers with constants, since they are already de-duplicated by the time it gets to see them
  • We now run eliminateDeadCode just after moveConstants, so that the Nops that moveConstants generates are freed instead of staying live throughout Air compilation, reducing memory pressure.
  • I also took the opportunity to fix typos in comments in various parts of the code base.

Here are a few numbers to justify this patch:

  • In JetStream2, about 27% of values at the beginning of B3 are constants
  • In JetStream2, about 11% of values at the end of B3 are Nops
  • In JetStream2, this patch increases the number of times that tail duplication happens from a bit less than 24k to a bit more than 25k (hoisting constants makes blocks smaller).

When I tried measuring the total effect on JetStream2 I got a tiny and almost certainly non-significant progression.

  • b3/B3Generate.cpp:

(JSC::B3::generateToAir):

  • b3/B3MoveConstants.cpp:
  • b3/B3PureCSE.cpp:

(JSC::B3::PureCSE::process):

  • b3/B3PureCSE.h:
  • b3/B3ReduceStrength.cpp:
  • bytecode/GetByIdStatus.cpp:

(JSC::GetByIdStatus::computeForStubInfoWithoutExitSiteFeedback):

  • dfg/DFGCSEPhase.cpp:
  • dfg/DFGOSRAvailabilityAnalysisPhase.h:
  • dfg/DFGOSRExit.cpp:

(JSC::DFG::OSRExit::executeOSRExit):

Location:
trunk/Source/JavaScriptCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r245031 r245035  
     12019-05-07  Robin Morisset  <rmorisset@apple.com>
     2
     3        [B3] Constants should be hoisted to the root block until moveConstants
     4        https://bugs.webkit.org/show_bug.cgi?id=197265
     5
     6        Reviewed by Saam Barati.
     7
     8        This patch does the following:
     9        - B3ReduceStrength now hoists all constants to the root BB, and de-duplicates them along the way
     10        - B3PureCSE no longer bothers with constants, since they are already de-duplicated by the time it gets to see them
     11        - We now run eliminateDeadCode just after moveConstants, so that the Nops that moveConstants generates are freed instead of staying live throughout Air compilation, reducing memory pressure.
     12        - I also took the opportunity to fix typos in comments in various parts of the code base.
     13
     14        Here are a few numbers to justify this patch:
     15        - In JetStream2, about 27% of values at the beginning of B3 are constants
     16        - In JetStream2, about 11% of values at the end of B3 are Nops
     17        - In JetStream2, this patch increases the number of times that tail duplication happens from a bit less than 24k to a bit more than 25k (hoisting constants makes blocks smaller).
     18
     19        When I tried measuring the total effect on JetStream2 I got a tiny and almost certainly non-significant progression.
     20
     21        * b3/B3Generate.cpp:
     22        (JSC::B3::generateToAir):
     23        * b3/B3MoveConstants.cpp:
     24        * b3/B3PureCSE.cpp:
     25        (JSC::B3::PureCSE::process):
     26        * b3/B3PureCSE.h:
     27        * b3/B3ReduceStrength.cpp:
     28        * bytecode/GetByIdStatus.cpp:
     29        (JSC::GetByIdStatus::computeForStubInfoWithoutExitSiteFeedback):
     30        * dfg/DFGCSEPhase.cpp:
     31        * dfg/DFGOSRAvailabilityAnalysisPhase.h:
     32        * dfg/DFGOSRExit.cpp:
     33        (JSC::DFG::OSRExit::executeOSRExit):
     34
    1352019-05-07  Robin Morisset  <rmorisset@apple.com>
    236
  • trunk/Source/JavaScriptCore/b3/B3Generate.cpp

    r243851 r245035  
    117117    legalizeMemoryOffsets(procedure);
    118118    moveConstants(procedure);
     119    eliminateDeadCode(procedure);
    119120
    120121    // FIXME: We should run pureCSE here to clean up some platform specific changes from the previous phases.
  • trunk/Source/JavaScriptCore/b3/B3MoveConstants.cpp

    r244309 r245035  
    155155               
    156156                // We call this when we have found a constant that we'd like to use. It's possible that
    157                 // we have computed that the constant should be meterialized in this block, but we
     157                // we have computed that the constant should be materialized in this block, but we
    158158                // haven't inserted it yet. This inserts the constant if necessary.
    159159                auto materialize = [&] (Value* child) {
  • trunk/Source/JavaScriptCore/b3/B3PureCSE.cpp

    r213714 r245035  
    6969bool PureCSE::process(Value* value, Dominators& dominators)
    7070{
    71     if (value->opcode() == Identity)
     71    if (value->opcode() == Identity || value->isConstant())
    7272        return false;
    7373
  • trunk/Source/JavaScriptCore/b3/B3PureCSE.h

    r213714 r245035  
    4141
    4242// This is a reusable utility for doing pure CSE. You can use it to do pure CSE on a program by just
    43 // proceeding in order an calling process().
     43// proceeding in order and calling process().
    4444class PureCSE {
    4545public:
  • trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp

    r243918 r245035  
    403403        , m_insertionSet(proc)
    404404        , m_blockInsertionSet(proc)
     405        , m_root(proc.at(0))
    405406    {
    406407    }
     
    443444            // put them. We're not actually smart enough to move things around at random.
    444445            m_changed |= eliminateDeadCodeImpl(m_proc);
     446            m_valueForConstant.clear();
    445447           
    446448            simplifySSA();
     
    21462148            break;
    21472149        }
    2148            
     2150
     2151        case Const32:
     2152        case Const64:
     2153        case ConstFloat:
     2154        case ConstDouble: {
     2155            ValueKey key = m_value->key();
     2156            if (Value* constInRoot = m_valueForConstant.get(key)) {
     2157                if (constInRoot != m_value) {
     2158                    m_value->replaceWithIdentity(constInRoot);
     2159                    m_changed = true;
     2160                }
     2161            } else if (m_block == m_root)
     2162                m_valueForConstant.add(key, m_value);
     2163            else {
     2164                Value* constInRoot = m_proc.clone(m_value);
     2165                m_root->appendNonTerminal(constInRoot);
     2166                m_valueForConstant.add(key, constInRoot);
     2167                m_value->replaceWithIdentity(constInRoot);
     2168                m_changed = true;
     2169            }
     2170            break;
     2171        }
     2172
    21492173        default:
    21502174            break;
     
    27952819    InsertionSet m_insertionSet;
    27962820    BlockInsertionSet m_blockInsertionSet;
     2821    HashMap<ValueKey, Value*> m_valueForConstant;
     2822    BasicBlock* m_root { nullptr };
    27972823    BasicBlock* m_block { nullptr };
    27982824    unsigned m_index { 0 };
  • trunk/Source/JavaScriptCore/bytecode/GetByIdStatus.cpp

    r243467 r245035  
    277277
    278278                if (domAttribute) {
    279                     // Give up when cutom accesses are not merged into one.
     279                    // Give up when custom accesses are not merged into one.
    280280                    if (result.numVariants() != 1)
    281281                        return GetByIdStatus(JSC::slowVersion(summary));
  • trunk/Source/JavaScriptCore/dfg/DFGCSEPhase.cpp

    r240114 r245035  
    258258    }
    259259
    260     // The majority of Impure Stack Slotsare unique per value.
     260    // The majority of Impure Stack Slots are unique per value.
    261261    // This is very useful for fast clobber(), we can just remove the slot addressed by AbstractHeap
    262262    // in O(1).
  • trunk/Source/JavaScriptCore/dfg/DFGOSRAvailabilityAnalysisPhase.h

    r218794 r245035  
    3434class Graph;
    3535
    36 // Computes BasicBlock::ssa->availabiltiyAtHead/Tail. This is a forward flow type inference
     36// Computes BasicBlock::ssa->availabilityAtHead/Tail. This is a forward flow type inference
    3737// over MovHints and SetLocals. This analysis is run directly by the Plan for preparing for
    3838// lowering to B3 IR, but it can also be used as a utility. Note that if you run it before
  • trunk/Source/JavaScriptCore/dfg/DFGOSRExit.cpp

    r244764 r245035  
    453453    context.sp() = context.fp<uint8_t*>() + exitState.stackPointerOffset;
    454454
    455     // The only reason for using this do while look is so we can break out midway when appropriate.
     455    // The only reason for using this do while loop is so we can break out midway when appropriate.
    456456    do {
    457457        auto extraInitializationLevel = static_cast<ExtraInitializationLevel>(exitState.extraInitializationLevel);
Note: See TracChangeset for help on using the changeset viewer.