⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243744 in webkit


Ignore:
Timestamp:
Apr 2, 2019, 8:58:34 AM (7 years ago)
Author:
sbarati@apple.com
Message:

Add a ValueRepReduction phase
https://bugs.webkit.org/show_bug.cgi?id=196234

Reviewed by Filip Pizlo.

This patch adds a ValueRepReduction phase. The main idea here is
to try to reduce DoubleRep(RealNumberUse:ValueRep(DoubleRepUse:@x))
to just be @x. This patch handles such above strengh reduction rules
as long as we prove that all users of the ValueRep can be converted
to using the incoming double value. That way we prevent introducing
a parallel live range for the double value.

This patch tracks the uses of the ValueRep through Phi variables,
so we can convert entire Phi variables to being Double instead
of JSValue if the Phi also has only double uses.

This is implemented through a simple escape analysis. DoubleRep(RealNumberUse:)
and OSR exit hints are not counted as escapes. All other uses are counted
as escapes. Connected Phi graphs are converted to being Double only if the
entire graph is ok with the result being Double.

Some ways we could extend this phase in the future:

  • There are a lot of DoubleRep(NumberUse:@ValueRep(@x)) uses. This ensures that the result of the DoubleRep of @x is not impure NaN. We could handle this case if we introduced a PurifyNaN node and replace the DoubleRep with PurifyNaN(@x). Alternatively, we could see if certain users of this DoubleRep are okay with impure NaN flowing into them and we'd need to ensure their output type is always treated as if the input is impure NaN.
  • We could do sinking of ValueRep where we think it's profitable. So instead of an escape making it so we never represent the variable as a Double, we could make the escape reconstruct the JSValueRep where profitable.
  • We can extend this phase to handle Int52Rep if it's profitable.
  • We can opt other nodes into accepting incoming Doubles so we no longer treat them as escapes.

This patch is somewhere between neutral and a 1% progression on JetStream 2.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • dfg/DFGPlan.cpp:

(JSC::DFG::Plan::compileInThreadImpl):

  • dfg/DFGValueRepReductionPhase.cpp: Added.

(JSC::DFG::ValueRepReductionPhase::ValueRepReductionPhase):
(JSC::DFG::ValueRepReductionPhase::run):
(JSC::DFG::ValueRepReductionPhase::convertValueRepsToDouble):
(JSC::DFG::performValueRepReduction):

  • dfg/DFGValueRepReductionPhase.h: Added.
  • runtime/Options.h:
Location:
trunk/Source/JavaScriptCore
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r243702 r243744  
     12019-04-02  Saam barati  <sbarati@apple.com>
     2
     3        Add a ValueRepReduction phase
     4        https://bugs.webkit.org/show_bug.cgi?id=196234
     5
     6        Reviewed by Filip Pizlo.
     7
     8        This patch adds a ValueRepReduction phase. The main idea here is
     9        to try to reduce DoubleRep(RealNumberUse:ValueRep(DoubleRepUse:@x))
     10        to just be @x. This patch handles such above strengh reduction rules
     11        as long as we prove that all users of the ValueRep can be converted
     12        to using the incoming double value. That way we prevent introducing
     13        a parallel live range for the double value.
     14       
     15        This patch tracks the uses of the ValueRep through Phi variables,
     16        so we can convert entire Phi variables to being Double instead
     17        of JSValue if the Phi also has only double uses.
     18       
     19        This is implemented through a simple escape analysis. DoubleRep(RealNumberUse:)
     20        and OSR exit hints are not counted as escapes. All other uses are counted
     21        as escapes. Connected Phi graphs are converted to being Double only if the
     22        entire graph is ok with the result being Double.
     23       
     24        Some ways we could extend this phase in the future:
     25        - There are a lot of DoubleRep(NumberUse:@ValueRep(@x)) uses. This ensures
     26          that the result of the DoubleRep of @x is not impure NaN. We could
     27          handle this case if we introduced a PurifyNaN node and replace the DoubleRep
     28          with PurifyNaN(@x). Alternatively, we could see if certain users of this
     29          DoubleRep are okay with impure NaN flowing into them and we'd need to ensure
     30          their output type is always treated as if the input is impure NaN.
     31        - We could do sinking of ValueRep where we think it's profitable. So instead
     32          of an escape making it so we never represent the variable as a Double, we
     33          could make the escape reconstruct the JSValueRep where profitable.
     34        - We can extend this phase to handle Int52Rep if it's profitable.
     35        - We can opt other nodes into accepting incoming Doubles so we no longer
     36          treat them as escapes.
     37       
     38        This patch is somewhere between neutral and a 1% progression on JetStream 2.
     39
     40        * JavaScriptCore.xcodeproj/project.pbxproj:
     41        * Sources.txt:
     42        * dfg/DFGPlan.cpp:
     43        (JSC::DFG::Plan::compileInThreadImpl):
     44        * dfg/DFGValueRepReductionPhase.cpp: Added.
     45        (JSC::DFG::ValueRepReductionPhase::ValueRepReductionPhase):
     46        (JSC::DFG::ValueRepReductionPhase::run):
     47        (JSC::DFG::ValueRepReductionPhase::convertValueRepsToDouble):
     48        (JSC::DFG::performValueRepReduction):
     49        * dfg/DFGValueRepReductionPhase.h: Added.
     50        * runtime/Options.h:
     51
    1522019-04-01  Yusuke Suzuki  <ysuzuki@apple.com>
    253
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r243560 r243744  
    884884                52B311011975B4670080857C /* TypeLocationCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 52B311001975B4670080857C /* TypeLocationCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
    885885                52C0611F1AA51E1C00B4ADBA /* RuntimeType.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */; settings = {ATTRIBUTES = (Private, ); }; };
     886                52C55566224C2AEA0099F5CC /* DFGValueRepReductionPhase.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C55565224C2AE70099F5CC /* DFGValueRepReductionPhase.h */; };
    886887                52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
    887888                52CD0F5D2242F569004A18A5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */; };
     
    33903391                52B717B41A0597E1007AF4F3 /* ControlFlowProfiler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ControlFlowProfiler.cpp; sourceTree = "<group>"; };
    33913392                52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeType.h; sourceTree = "<group>"; };
     3393                52C55564224C2AE70099F5CC /* DFGValueRepReductionPhase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DFGValueRepReductionPhase.cpp; path = dfg/DFGValueRepReductionPhase.cpp; sourceTree = "<group>"; };
     3394                52C55565224C2AE70099F5CC /* DFGValueRepReductionPhase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DFGValueRepReductionPhase.h; path = dfg/DFGValueRepReductionPhase.h; sourceTree = "<group>"; };
    33923395                52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; };
    33933396                52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; };
     
    76527655                                0F3B3A2915474FF4003ED0FF /* DFGValidate.cpp */,
    76537656                                0F3B3A2A15474FF4003ED0FF /* DFGValidate.h */,
     7657                                52C55564224C2AE70099F5CC /* DFGValueRepReductionPhase.cpp */,
     7658                                52C55565224C2AE70099F5CC /* DFGValueRepReductionPhase.h */,
    76547659                                0F2BDC4E15228BE700CD8910 /* DFGValueSource.cpp */,
    76557660                                0F2BDC401522801700CD8910 /* DFGValueSource.h */,
     
    93809385                                996B73201BDA08EF00331B84 /* JSModuleLoader.lut.h in Headers */,
    93819386                                E318CBC11B8AEF5100A2929D /* JSModuleNamespaceObject.h in Headers */,
     9387                                52C55566224C2AEA0099F5CC /* DFGValueRepReductionPhase.h in Headers */,
    93829388                                E39DA4A71B7E8B7C0084F33A /* JSModuleRecord.h in Headers */,
    93839389                                E33E8D1D1B9013C300346B52 /* JSNativeStdFunction.h in Headers */,
  • trunk/Source/JavaScriptCore/Sources.txt

    r243560 r243744  
    417417dfg/DFGUseKind.cpp
    418418dfg/DFGValidate.cpp
     419dfg/DFGValueRepReductionPhase.cpp
    419420dfg/DFGValueSource.cpp
    420421dfg/DFGValueStrength.cpp
  • trunk/Source/JavaScriptCore/dfg/DFGPlan.cpp

    r243467 r243744  
    7272#include "DFGUnificationPhase.h"
    7373#include "DFGValidate.h"
     74#include "DFGValueRepReductionPhase.h"
    7475#include "DFGVarargsForwardingPhase.h"
    7576#include "DFGVirtualRegisterAllocationPhase.h"
     
    425426            RUN_PHASE(performObjectAllocationSinking);
    426427        }
     428        if (Options::useValueRepElimination())
     429            RUN_PHASE(performValueRepReduction);
    427430        if (changed) {
    428431            // State-at-tail and state-at-head will be invalid if we did strength reduction since
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r243530 r243744  
    284284    v(bool, usePutStackSinking, true, Normal, nullptr) \
    285285    v(bool, useObjectAllocationSinking, true, Normal, nullptr) \
     286    v(bool, useValueRepElimination, true, Normal, nullptr) \
    286287    v(bool, useArityFixupInlining, true, Normal, nullptr) \
    287288    v(bool, logExecutableAllocation, false, Normal, nullptr) \
Note: See TracChangeset for help on using the changeset viewer.