- Source/JavaScriptCore/ChangeLog +83 lines
Lines 1-3 Source/JavaScriptCore/ChangeLog_sec1
1
2014-04-19  Filip Pizlo  <fpizlo@apple.com>
2
3
        Take block execution count estimates into account when voting double
4
        https://bugs.webkit.org/show_bug.cgi?id=131906
5
6
        Reviewed by NOBODY (OOPS!).
7
        
8
        This was a drama in three acts.
9
        
10
        Act I: Slurp in BasicBlock::executionCount and use it as a weight when counting the
11
            number of uses of a variable that want double or non-double. Easy as pie. This
12
            gave me a huge speed-up on FloatMM and a huge slow-down on basically everything
13
            else.
14
        
15
        Act II: Realize that there were some programs where our previous double voting was
16
            just on the edge of disaster and making it more precise tipped it over. In
17
            particular, if you had an integer variable that would infrequently be used in a
18
            computation that resulted in a variable that was frequently used as an array index,
19
            the outer infrequentness would be the thing we'd use in the vote. So, an array
20
            index would become double. We fix this by reviving global backwards propagation
21
            and introducing the concept of ReallyWantsInt, which is used just for array
22
            indices. Any variable transitively flagged as ReallyWantsInt will never be forced
23
            double. We need that flag to be separate from UsedAsInt, since UsedAsInt needs to
24
            be set in bitops for RageConversion but using it for double forcing is too much.
25
            Basically, it's cheaper to have to convert a double to an int for a bitop than it
26
            is to convert a double to an int for an array index; also a variable being used as
27
            an array index is a much stronger hint that it ought to be an int. This recovered
28
            performance on everything except programs that used FTL OSR entry.
29
        
30
        Act III: Realize that OSR entrypoint creation creates blocks that have NaN execution
31
            count, which then completely pollutes the weighting - essentially all votes go
32
            NaN. Fix this with some surgical defenses. Basically, any client of execution
33
            counts should allow for them to be NaN and shouldn't completely fall off a cliff
34
            when it happens.
35
        
36
        This is awesome. 75% speed-up on FloatMM. 11% speed-up on audio-dft. This leads to
37
        7% speed-up on AsmBench and 2% speed-up on Kraken.
38
39
        * CMakeLists.txt:
40
        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
41
        * JavaScriptCore.xcodeproj/project.pbxproj:
42
        * dfg/DFGBackwardsPropagationPhase.cpp:
43
        (JSC::DFG::BackwardsPropagationPhase::run):
44
        (JSC::DFG::BackwardsPropagationPhase::propagate):
45
        * dfg/DFGGraph.cpp:
46
        (JSC::DFG::Graph::dumpBlockHeader):
47
        * dfg/DFGGraph.h:
48
        (JSC::DFG::Graph::voteNode):
49
        (JSC::DFG::Graph::voteChildren):
50
        * dfg/DFGNodeFlags.cpp:
51
        (JSC::DFG::dumpNodeFlags):
52
        * dfg/DFGNodeFlags.h:
53
        * dfg/DFGOSREntrypointCreationPhase.cpp:
54
        (JSC::DFG::OSREntrypointCreationPhase::run):
55
        * dfg/DFGPlan.cpp:
56
        (JSC::DFG::Plan::compileInThreadImpl):
57
        * dfg/DFGPredictionPropagationPhase.cpp:
58
        (JSC::DFG::PredictionPropagationPhase::doDoubleVoting):
59
        (JSC::DFG::PredictionPropagationPhase::doRoundOfDoubleVoting):
60
        * dfg/DFGVariableAccessData.cpp: Added.
61
        (JSC::DFG::VariableAccessData::VariableAccessData):
62
        (JSC::DFG::VariableAccessData::mergeIsCaptured):
63
        (JSC::DFG::VariableAccessData::mergeShouldNeverUnbox):
64
        (JSC::DFG::VariableAccessData::predict):
65
        (JSC::DFG::VariableAccessData::mergeArgumentAwarePrediction):
66
        (JSC::DFG::VariableAccessData::shouldUseDoubleFormatAccordingToVote):
67
        (JSC::DFG::VariableAccessData::tallyVotesForShouldUseDoubleFormat):
68
        (JSC::DFG::VariableAccessData::mergeDoubleFormatState):
69
        (JSC::DFG::VariableAccessData::makePredictionForDoubleFormat):
70
        (JSC::DFG::VariableAccessData::flushFormat):
71
        * dfg/DFGVariableAccessData.h:
72
        (JSC::DFG::VariableAccessData::vote):
73
        (JSC::DFG::VariableAccessData::VariableAccessData): Deleted.
74
        (JSC::DFG::VariableAccessData::mergeIsCaptured): Deleted.
75
        (JSC::DFG::VariableAccessData::mergeShouldNeverUnbox): Deleted.
76
        (JSC::DFG::VariableAccessData::predict): Deleted.
77
        (JSC::DFG::VariableAccessData::mergeArgumentAwarePrediction): Deleted.
78
        (JSC::DFG::VariableAccessData::shouldUseDoubleFormatAccordingToVote): Deleted.
79
        (JSC::DFG::VariableAccessData::tallyVotesForShouldUseDoubleFormat): Deleted.
80
        (JSC::DFG::VariableAccessData::mergeDoubleFormatState): Deleted.
81
        (JSC::DFG::VariableAccessData::makePredictionForDoubleFormat): Deleted.
82
        (JSC::DFG::VariableAccessData::flushFormat): Deleted.
83
1
2014-04-19  Filip Pizlo  <fpizlo@apple.com>
84
2014-04-19  Filip Pizlo  <fpizlo@apple.com>
2
85
3
        It should be OK to store new fields into objects that have no prototypes
86
        It should be OK to store new fields into objects that have no prototypes
- Source/JavaScriptCore/CMakeLists.txt +1 lines
Lines 197-202 set(JavaScriptCore_SOURCES Source/JavaScriptCore/CMakeLists.txt_sec1
197
    dfg/DFGUseKind.cpp
197
    dfg/DFGUseKind.cpp
198
    dfg/DFGValidate.cpp
198
    dfg/DFGValidate.cpp
199
    dfg/DFGValueSource.cpp
199
    dfg/DFGValueSource.cpp
200
    dfg/DFGVariableAccessData.cpp
200
    dfg/DFGVariableAccessDataDump.cpp
201
    dfg/DFGVariableAccessDataDump.cpp
201
    dfg/DFGVariableEvent.cpp
202
    dfg/DFGVariableEvent.cpp
202
    dfg/DFGVariableEventStream.cpp
203
    dfg/DFGVariableEventStream.cpp
- Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj +1 lines
Lines 450-455 Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj_sec1
450
    <ClCompile Include="..\dfg\DFGUseKind.cpp" />
450
    <ClCompile Include="..\dfg\DFGUseKind.cpp" />
451
    <ClCompile Include="..\dfg\DFGValidate.cpp" />
451
    <ClCompile Include="..\dfg\DFGValidate.cpp" />
452
    <ClCompile Include="..\dfg\DFGValueSource.cpp" />
452
    <ClCompile Include="..\dfg\DFGValueSource.cpp" />
453
    <ClCompile Include="..\dfg\DFGVariableAccessData.cpp" />
453
    <ClCompile Include="..\dfg\DFGVariableAccessDataDump.cpp" />
454
    <ClCompile Include="..\dfg\DFGVariableAccessDataDump.cpp" />
454
    <ClCompile Include="..\dfg\DFGVariableEvent.cpp" />
455
    <ClCompile Include="..\dfg\DFGVariableEvent.cpp" />
455
    <ClCompile Include="..\dfg\DFGVariableEventStream.cpp" />
456
    <ClCompile Include="..\dfg\DFGVariableEventStream.cpp" />
- Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj +4 lines
Lines 325-330 Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec1
325
		0F6B1CC61862C47800845D97 /* FTLUnwindInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F6B1CC21862C47800845D97 /* FTLUnwindInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
325
		0F6B1CC61862C47800845D97 /* FTLUnwindInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F6B1CC21862C47800845D97 /* FTLUnwindInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
326
		0F6B1CC918641DF800845D97 /* ArityCheckFailReturnThunks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F6B1CC718641DF800845D97 /* ArityCheckFailReturnThunks.cpp */; };
326
		0F6B1CC918641DF800845D97 /* ArityCheckFailReturnThunks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F6B1CC718641DF800845D97 /* ArityCheckFailReturnThunks.cpp */; };
327
		0F6B1CCA18641DF800845D97 /* ArityCheckFailReturnThunks.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F6B1CC818641DF800845D97 /* ArityCheckFailReturnThunks.h */; settings = {ATTRIBUTES = (Private, ); }; };
327
		0F6B1CCA18641DF800845D97 /* ArityCheckFailReturnThunks.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F6B1CC818641DF800845D97 /* ArityCheckFailReturnThunks.h */; settings = {ATTRIBUTES = (Private, ); }; };
328
		0F6E845A19030BEF00562741 /* DFGVariableAccessData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F6E845919030BEF00562741 /* DFGVariableAccessData.cpp */; };
328
		0F7025A91714B0FA00382C0E /* DFGOSRExitCompilerCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F7025A71714B0F800382C0E /* DFGOSRExitCompilerCommon.cpp */; };
329
		0F7025A91714B0FA00382C0E /* DFGOSRExitCompilerCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F7025A71714B0F800382C0E /* DFGOSRExitCompilerCommon.cpp */; };
329
		0F7025AA1714B0FC00382C0E /* DFGOSRExitCompilerCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7025A81714B0F800382C0E /* DFGOSRExitCompilerCommon.h */; settings = {ATTRIBUTES = (Private, ); }; };
330
		0F7025AA1714B0FC00382C0E /* DFGOSRExitCompilerCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7025A81714B0F800382C0E /* DFGOSRExitCompilerCommon.h */; settings = {ATTRIBUTES = (Private, ); }; };
330
		0F714CA416EA92F000F3EBEB /* DFGBackwardsPropagationPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F714CA116EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.cpp */; };
331
		0F714CA416EA92F000F3EBEB /* DFGBackwardsPropagationPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F714CA116EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.cpp */; };
Lines 2127-2132 Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec2
2127
		0F6B1CC21862C47800845D97 /* FTLUnwindInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FTLUnwindInfo.h; path = ftl/FTLUnwindInfo.h; sourceTree = "<group>"; };
2128
		0F6B1CC21862C47800845D97 /* FTLUnwindInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FTLUnwindInfo.h; path = ftl/FTLUnwindInfo.h; sourceTree = "<group>"; };
2128
		0F6B1CC718641DF800845D97 /* ArityCheckFailReturnThunks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArityCheckFailReturnThunks.cpp; sourceTree = "<group>"; };
2129
		0F6B1CC718641DF800845D97 /* ArityCheckFailReturnThunks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArityCheckFailReturnThunks.cpp; sourceTree = "<group>"; };
2129
		0F6B1CC818641DF800845D97 /* ArityCheckFailReturnThunks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArityCheckFailReturnThunks.h; sourceTree = "<group>"; };
2130
		0F6B1CC818641DF800845D97 /* ArityCheckFailReturnThunks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArityCheckFailReturnThunks.h; sourceTree = "<group>"; };
2131
		0F6E845919030BEF00562741 /* DFGVariableAccessData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGVariableAccessData.cpp; path = dfg/DFGVariableAccessData.cpp; sourceTree = "<group>"; };
2130
		0F7025A71714B0F800382C0E /* DFGOSRExitCompilerCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGOSRExitCompilerCommon.cpp; path = dfg/DFGOSRExitCompilerCommon.cpp; sourceTree = "<group>"; };
2132
		0F7025A71714B0F800382C0E /* DFGOSRExitCompilerCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGOSRExitCompilerCommon.cpp; path = dfg/DFGOSRExitCompilerCommon.cpp; sourceTree = "<group>"; };
2131
		0F7025A81714B0F800382C0E /* DFGOSRExitCompilerCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGOSRExitCompilerCommon.h; path = dfg/DFGOSRExitCompilerCommon.h; sourceTree = "<group>"; };
2133
		0F7025A81714B0F800382C0E /* DFGOSRExitCompilerCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGOSRExitCompilerCommon.h; path = dfg/DFGOSRExitCompilerCommon.h; sourceTree = "<group>"; };
2132
		0F714CA116EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGBackwardsPropagationPhase.cpp; path = dfg/DFGBackwardsPropagationPhase.cpp; sourceTree = "<group>"; };
2134
		0F714CA116EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGBackwardsPropagationPhase.cpp; path = dfg/DFGBackwardsPropagationPhase.cpp; sourceTree = "<group>"; };
Lines 4810-4815 Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec3
4810
				0F2BDC3F1522801700CD8910 /* DFGValueRecoveryOverride.h */,
4812
				0F2BDC3F1522801700CD8910 /* DFGValueRecoveryOverride.h */,
4811
				0F2BDC4E15228BE700CD8910 /* DFGValueSource.cpp */,
4813
				0F2BDC4E15228BE700CD8910 /* DFGValueSource.cpp */,
4812
				0F2BDC401522801700CD8910 /* DFGValueSource.h */,
4814
				0F2BDC401522801700CD8910 /* DFGValueSource.h */,
4815
				0F6E845919030BEF00562741 /* DFGVariableAccessData.cpp */,
4813
				0F620172143FCD2F0068B77C /* DFGVariableAccessData.h */,
4816
				0F620172143FCD2F0068B77C /* DFGVariableAccessData.h */,
4814
				0FDDBFB21666EED500C55FEF /* DFGVariableAccessDataDump.cpp */,
4817
				0FDDBFB21666EED500C55FEF /* DFGVariableAccessDataDump.cpp */,
4815
				0FDDBFB31666EED500C55FEF /* DFGVariableAccessDataDump.h */,
4818
				0FDDBFB31666EED500C55FEF /* DFGVariableAccessDataDump.h */,
Lines 7088-7093 Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec4
7088
				0FB14E1E18124ACE009B6B4D /* JITInlineCacheGenerator.cpp in Sources */,
7091
				0FB14E1E18124ACE009B6B4D /* JITInlineCacheGenerator.cpp in Sources */,
7089
				BCDD51EB0FB8DF74004A8BDC /* JITOpcodes.cpp in Sources */,
7092
				BCDD51EB0FB8DF74004A8BDC /* JITOpcodes.cpp in Sources */,
7090
				A71236E51195F33C00BD2174 /* JITOpcodes32_64.cpp in Sources */,
7093
				A71236E51195F33C00BD2174 /* JITOpcodes32_64.cpp in Sources */,
7094
				0F6E845A19030BEF00562741 /* DFGVariableAccessData.cpp in Sources */,
7091
				0F24E54C17EE274900ABB217 /* JITOperations.cpp in Sources */,
7095
				0F24E54C17EE274900ABB217 /* JITOperations.cpp in Sources */,
7092
				86CC85C40EE7A89400288682 /* JITPropertyAccess.cpp in Sources */,
7096
				86CC85C40EE7A89400288682 /* JITPropertyAccess.cpp in Sources */,
7093
				A7C1E8E4112E72EF00A37F98 /* JITPropertyAccess32_64.cpp in Sources */,
7097
				A7C1E8E4112E72EF00A37F98 /* JITPropertyAccess32_64.cpp in Sources */,
- Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp -19 / +35 lines
Lines 44-60 public: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec1
44
    
44
    
45
    bool run()
45
    bool run()
46
    {
46
    {
47
        for (BlockIndex blockIndex = 0; blockIndex < m_graph.numBlocks(); ++blockIndex) {
47
        m_changed = true;
48
            BasicBlock* block = m_graph.block(blockIndex);
48
        while (m_changed) {
49
            if (!block)
49
            m_changed = false;
50
                continue;
50
            for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
51
            
51
                BasicBlock* block = m_graph.block(blockIndex);
52
            // Prevent a tower of overflowing additions from creating a value that is out of the
52
                if (!block)
53
            // safe 2^48 range.
53
                    continue;
54
            m_allowNestedOverflowingAdditions = block->size() < (1 << 16);
54
            
55
                // Prevent a tower of overflowing additions from creating a value that is out of the
56
                // safe 2^48 range.
57
                m_allowNestedOverflowingAdditions = block->size() < (1 << 16);
55
            
58
            
56
            for (unsigned indexInBlock = block->size(); indexInBlock--;)
59
                for (unsigned indexInBlock = block->size(); indexInBlock--;)
57
                propagate(block->at(indexInBlock));
60
                    propagate(block->at(indexInBlock));
61
            }
58
        }
62
        }
59
        
63
        
60
        return true;
64
        return true;
Lines 174-180 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec2
174
        switch (node->op()) {
178
        switch (node->op()) {
175
        case GetLocal: {
179
        case GetLocal: {
176
            VariableAccessData* variableAccessData = node->variableAccessData();
180
            VariableAccessData* variableAccessData = node->variableAccessData();
177
            variableAccessData->mergeFlags(flags);
181
            flags &= ~NodeBytecodeUsesAsInt; // We don't care about cross-block uses-as-int.
182
            m_changed |= variableAccessData->mergeFlags(flags);
178
            break;
183
            break;
179
        }
184
        }
180
            
185
            
Lines 182-188 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec3
182
            VariableAccessData* variableAccessData = node->variableAccessData();
187
            VariableAccessData* variableAccessData = node->variableAccessData();
183
            if (!variableAccessData->isLoadedFrom())
188
            if (!variableAccessData->isLoadedFrom())
184
                break;
189
                break;
185
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue);
190
            flags = variableAccessData->flags();
191
            RELEASE_ASSERT(!(flags & ~NodeBytecodeBackPropMask));
192
            flags |= NodeBytecodeUsesAsNumber; // Account for the fact that control flow may cause overflows that our modeling can't handle.
193
            node->child1()->mergeFlags(flags);
194
            break;
195
        }
196
            
197
        case Flush: {
198
            VariableAccessData* variableAccessData = node->variableAccessData();
199
            m_changed |= variableAccessData->mergeFlags(NodeBytecodeUsesAsValue);
186
            break;
200
            break;
187
        }
201
        }
188
            
202
            
Lines 199-204 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec4
199
        case ArithIMul: {
213
        case ArithIMul: {
200
            flags |= NodeBytecodeUsesAsInt;
214
            flags |= NodeBytecodeUsesAsInt;
201
            flags &= ~(NodeBytecodeUsesAsNumber | NodeBytecodeNeedsNegZero | NodeBytecodeUsesAsOther);
215
            flags &= ~(NodeBytecodeUsesAsNumber | NodeBytecodeNeedsNegZero | NodeBytecodeUsesAsOther);
216
            flags &= ~NodeBytecodeReallyWantsInt;
202
            node->child1()->mergeFlags(flags);
217
            node->child1()->mergeFlags(flags);
203
            node->child2()->mergeFlags(flags);
218
            node->child2()->mergeFlags(flags);
204
            break;
219
            break;
Lines 206-212 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec5
206
            
221
            
207
        case StringCharCodeAt: {
222
        case StringCharCodeAt: {
208
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue);
223
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue);
209
            node->child2()->mergeFlags(NodeBytecodeUsesAsValue | NodeBytecodeUsesAsInt);
224
            node->child2()->mergeFlags(NodeBytecodeUsesAsValue | NodeBytecodeUsesAsInt | NodeBytecodeReallyWantsInt);
210
            break;
225
            break;
211
        }
226
        }
212
            
227
            
Lines 305-321 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec6
305
            
320
            
306
        case GetByVal: {
321
        case GetByVal: {
307
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue);
322
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue);
308
            node->child2()->mergeFlags(NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther | NodeBytecodeUsesAsInt);
323
            node->child2()->mergeFlags(NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther | NodeBytecodeUsesAsInt | NodeBytecodeReallyWantsInt);
309
            break;
324
            break;
310
        }
325
        }
311
            
326
            
312
        case GetMyArgumentByValSafe: {
327
        case GetMyArgumentByValSafe: {
313
            node->child1()->mergeFlags(NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther | NodeBytecodeUsesAsInt);
328
            node->child1()->mergeFlags(NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther | NodeBytecodeUsesAsInt | NodeBytecodeReallyWantsInt);
314
            break;
329
            break;
315
        }
330
        }
316
            
331
            
317
        case NewArrayWithSize: {
332
        case NewArrayWithSize: {
318
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue | NodeBytecodeUsesAsInt);
333
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue | NodeBytecodeUsesAsInt | NodeBytecodeReallyWantsInt);
319
            break;
334
            break;
320
        }
335
        }
321
            
336
            
Lines 323-335 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec7
323
            // Negative zero is not observable. NaN versus undefined are only observable
338
            // Negative zero is not observable. NaN versus undefined are only observable
324
            // in that you would get a different exception message. So, like, whatever: we
339
            // in that you would get a different exception message. So, like, whatever: we
325
            // claim here that NaN v. undefined is observable.
340
            // claim here that NaN v. undefined is observable.
326
            node->child1()->mergeFlags(NodeBytecodeUsesAsInt | NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther);
341
            node->child1()->mergeFlags(NodeBytecodeUsesAsInt | NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther | NodeBytecodeReallyWantsInt);
327
            break;
342
            break;
328
        }
343
        }
329
            
344
            
330
        case StringCharAt: {
345
        case StringCharAt: {
331
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue);
346
            node->child1()->mergeFlags(NodeBytecodeUsesAsValue);
332
            node->child2()->mergeFlags(NodeBytecodeUsesAsValue | NodeBytecodeUsesAsInt);
347
            node->child2()->mergeFlags(NodeBytecodeUsesAsValue | NodeBytecodeUsesAsInt | NodeBytecodeReallyWantsInt);
333
            break;
348
            break;
334
        }
349
        }
335
            
350
            
Lines 346-352 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec8
346
        case PutByValDirect:
361
        case PutByValDirect:
347
        case PutByVal: {
362
        case PutByVal: {
348
            m_graph.varArgChild(node, 0)->mergeFlags(NodeBytecodeUsesAsValue);
363
            m_graph.varArgChild(node, 0)->mergeFlags(NodeBytecodeUsesAsValue);
349
            m_graph.varArgChild(node, 1)->mergeFlags(NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther | NodeBytecodeUsesAsInt);
364
            m_graph.varArgChild(node, 1)->mergeFlags(NodeBytecodeUsesAsNumber | NodeBytecodeUsesAsOther | NodeBytecodeUsesAsInt | NodeBytecodeReallyWantsInt);
350
            m_graph.varArgChild(node, 2)->mergeFlags(NodeBytecodeUsesAsValue);
365
            m_graph.varArgChild(node, 2)->mergeFlags(NodeBytecodeUsesAsValue);
351
            break;
366
            break;
352
        }
367
        }
Lines 396-401 private: Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp_sec9
396
    }
411
    }
397
    
412
    
398
    bool m_allowNestedOverflowingAdditions;
413
    bool m_allowNestedOverflowingAdditions;
414
    bool m_changed;
399
};
415
};
400
416
401
bool performBackwardsPropagation(Graph& graph)
417
bool performBackwardsPropagation(Graph& graph)
- Source/JavaScriptCore/dfg/DFGGraph.cpp +2 lines
Lines 357-362 void Graph::dump(PrintStream& out, const Source/JavaScriptCore/dfg/DFGGraph.cpp_sec1
357
void Graph::dumpBlockHeader(PrintStream& out, const char* prefix, BasicBlock* block, PhiNodeDumpMode phiNodeDumpMode, DumpContext* context)
357
void Graph::dumpBlockHeader(PrintStream& out, const char* prefix, BasicBlock* block, PhiNodeDumpMode phiNodeDumpMode, DumpContext* context)
358
{
358
{
359
    out.print(prefix, "Block ", *block, " (", inContext(block->at(0)->origin.semantic, context), "): ", block->isReachable ? "" : "(skipped)", block->isOSRTarget ? " (OSR target)" : "", "\n");
359
    out.print(prefix, "Block ", *block, " (", inContext(block->at(0)->origin.semantic, context), "): ", block->isReachable ? "" : "(skipped)", block->isOSRTarget ? " (OSR target)" : "", "\n");
360
    if (block->executionCount == block->executionCount)
361
        out.print(prefix, "  Execution count: ", block->executionCount, "\n");
360
    out.print(prefix, "  Predecessors:");
362
    out.print(prefix, "  Predecessors:");
361
    for (size_t i = 0; i < block->predecessors.size(); ++i)
363
    for (size_t i = 0; i < block->predecessors.size(); ++i)
362
        out.print(" ", *block->predecessors[i]);
364
        out.print(" ", *block->predecessors[i]);
- Source/JavaScriptCore/dfg/DFGGraph.h -9 / +9 lines
Lines 701-707 public: Source/JavaScriptCore/dfg/DFGGraph.h_sec1
701
        return node->children.child(index);
701
        return node->children.child(index);
702
    }
702
    }
703
    
703
    
704
    void voteNode(Node* node, unsigned ballot)
704
    void voteNode(Node* node, unsigned ballot, float weight = 1)
705
    {
705
    {
706
        switch (node->op()) {
706
        switch (node->op()) {
707
        case ValueToInt32:
707
        case ValueToInt32:
Lines 713-747 public: Source/JavaScriptCore/dfg/DFGGraph.h_sec2
713
        }
713
        }
714
        
714
        
715
        if (node->op() == GetLocal)
715
        if (node->op() == GetLocal)
716
            node->variableAccessData()->vote(ballot);
716
            node->variableAccessData()->vote(ballot, weight);
717
    }
717
    }
718
    
718
    
719
    void voteNode(Edge edge, unsigned ballot)
719
    void voteNode(Edge edge, unsigned ballot, float weight = 1)
720
    {
720
    {
721
        voteNode(edge.node(), ballot);
721
        voteNode(edge.node(), ballot, weight);
722
    }
722
    }
723
    
723
    
724
    void voteChildren(Node* node, unsigned ballot)
724
    void voteChildren(Node* node, unsigned ballot, float weight = 1)
725
    {
725
    {
726
        if (node->flags() & NodeHasVarArgs) {
726
        if (node->flags() & NodeHasVarArgs) {
727
            for (unsigned childIdx = node->firstChild();
727
            for (unsigned childIdx = node->firstChild();
728
                childIdx < node->firstChild() + node->numChildren();
728
                childIdx < node->firstChild() + node->numChildren();
729
                childIdx++) {
729
                childIdx++) {
730
                if (!!m_varArgChildren[childIdx])
730
                if (!!m_varArgChildren[childIdx])
731
                    voteNode(m_varArgChildren[childIdx], ballot);
731
                    voteNode(m_varArgChildren[childIdx], ballot, weight);
732
            }
732
            }
733
            return;
733
            return;
734
        }
734
        }
735
        
735
        
736
        if (!node->child1())
736
        if (!node->child1())
737
            return;
737
            return;
738
        voteNode(node->child1(), ballot);
738
        voteNode(node->child1(), ballot, weight);
739
        if (!node->child2())
739
        if (!node->child2())
740
            return;
740
            return;
741
        voteNode(node->child2(), ballot);
741
        voteNode(node->child2(), ballot, weight);
742
        if (!node->child3())
742
        if (!node->child3())
743
            return;
743
            return;
744
        voteNode(node->child3(), ballot);
744
        voteNode(node->child3(), ballot, weight);
745
    }
745
    }
746
    
746
    
747
    template<typename T> // T = Node* or Edge
747
    template<typename T> // T = Node* or Edge
- Source/JavaScriptCore/dfg/DFGNodeFlags.cpp +3 lines
Lines 99-104 void dumpNodeFlags(PrintStream& actualOu Source/JavaScriptCore/dfg/DFGNodeFlags.cpp_sec1
99
    
99
    
100
    if (flags & NodeBytecodeUsesAsInt)
100
    if (flags & NodeBytecodeUsesAsInt)
101
        out.print(comma, "UseAsInt");
101
        out.print(comma, "UseAsInt");
102
103
    if (flags & NodeBytecodeReallyWantsInt)
104
        out.print(comma, "ReallyWantsInt");
102
    
105
    
103
    if (!(flags & NodeDoesNotExit))
106
    if (!(flags & NodeDoesNotExit))
104
        out.print(comma, "CanExit");
107
        out.print(comma, "CanExit");
- Source/JavaScriptCore/dfg/DFGNodeFlags.h -4 / +5 lines
Lines 53-73 namespace JSC { namespace DFG { Source/JavaScriptCore/dfg/DFGNodeFlags.h_sec1
53
#define NodeMayOverflow                  0x0080
53
#define NodeMayOverflow                  0x0080
54
#define NodeMayNegZero                   0x0100
54
#define NodeMayNegZero                   0x0100
55
                                
55
                                
56
#define NodeBytecodeBackPropMask         0x1E00
56
#define NodeBytecodeBackPropMask         0x3E00
57
#define NodeBytecodeUseBottom            0x0000
57
#define NodeBytecodeUseBottom            0x0000
58
#define NodeBytecodeUsesAsNumber         0x0200 // The result of this computation may be used in a context that observes fractional, or bigger-than-int32, results.
58
#define NodeBytecodeUsesAsNumber         0x0200 // The result of this computation may be used in a context that observes fractional, or bigger-than-int32, results.
59
#define NodeBytecodeNeedsNegZero         0x0400 // The result of this computation may be used in a context that observes -0.
59
#define NodeBytecodeNeedsNegZero         0x0400 // The result of this computation may be used in a context that observes -0.
60
#define NodeBytecodeUsesAsOther          0x0800 // The result of this computation may be used in a context that distinguishes between NaN and other things (like undefined).
60
#define NodeBytecodeUsesAsOther          0x0800 // The result of this computation may be used in a context that distinguishes between NaN and other things (like undefined).
61
#define NodeBytecodeUsesAsValue          (NodeBytecodeUsesAsNumber | NodeBytecodeNeedsNegZero | NodeBytecodeUsesAsOther)
61
#define NodeBytecodeUsesAsValue          (NodeBytecodeUsesAsNumber | NodeBytecodeNeedsNegZero | NodeBytecodeUsesAsOther)
62
#define NodeBytecodeUsesAsInt            0x1000 // The result of this computation is known to be used in a context that prefers, but does not require, integer values.
62
#define NodeBytecodeUsesAsInt            0x1000 // The result of this computation is known to be used in a context that prefers, but does not require, integer values.
63
#define NodeBytecodeReallyWantsInt       0x2000 // The result of this computation is known to be used in a context that strongly prefers integer values, to the point that we should avoid using doubles if at all possible.
63
64
64
#define NodeArithFlagsMask               (NodeBehaviorMask | NodeBytecodeBackPropMask)
65
#define NodeArithFlagsMask               (NodeBehaviorMask | NodeBytecodeBackPropMask)
65
66
66
#define NodeDoesNotExit                  0x2000 // This flag is negated to make it natural for the default to be that a node does exit.
67
#define NodeDoesNotExit                  0x4000 // This flag is negated to make it natural for the default to be that a node does exit.
67
68
68
#define NodeRelevantToOSR                0x4000
69
#define NodeRelevantToOSR                0x8000
69
70
70
#define NodeIsFlushed                    0x8000 // Used by Graph::computeIsFlushed(), will tell you which local nodes are backwards-reachable from a Flush.
71
#define NodeIsFlushed                   0x10000 // Used by Graph::computeIsFlushed(), will tell you which local nodes are backwards-reachable from a Flush.
71
72
72
typedef uint32_t NodeFlags;
73
typedef uint32_t NodeFlags;
73
74
- Source/JavaScriptCore/dfg/DFGOSREntrypointCreationPhase.cpp -1 / +1 lines
Lines 83-89 public: Source/JavaScriptCore/dfg/DFGOSREntrypointCreationPhase.cpp_sec1
83
        
83
        
84
        BlockInsertionSet insertionSet(m_graph);
84
        BlockInsertionSet insertionSet(m_graph);
85
        
85
        
86
        BasicBlock* newRoot = insertionSet.insert(0, PNaN);
86
        BasicBlock* newRoot = insertionSet.insert(0, 1);
87
        NodeOrigin origin = target->at(0)->origin;
87
        NodeOrigin origin = target->at(0)->origin;
88
        
88
        
89
        Vector<Node*> locals(baseline->m_numCalleeRegisters);
89
        Vector<Node*> locals(baseline->m_numCalleeRegisters);
- Source/JavaScriptCore/dfg/DFGPlan.cpp -2 / +1 lines
Lines 209-216 Plan::CompilationPath Plan::compileInThr Source/JavaScriptCore/dfg/DFGPlan.cpp_sec1
209
    performUnification(dfg);
209
    performUnification(dfg);
210
    performPredictionInjection(dfg);
210
    performPredictionInjection(dfg);
211
    
211
    
212
    if (isFTL(mode))
212
    performStaticExecutionCountEstimation(dfg);
213
        performStaticExecutionCountEstimation(dfg);
214
    
213
    
215
    if (mode == FTLForOSREntryMode) {
214
    if (mode == FTLForOSREntryMode) {
216
        bool result = performOSREntrypointCreation(dfg);
215
        bool result = performOSREntrypointCreation(dfg);
- Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp -17 / +23 lines
Lines 641-648 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec1
641
        }
641
        }
642
    }
642
    }
643
    
643
    
644
    void doDoubleVoting(Node* node)
644
    void doDoubleVoting(Node* node, float weight)
645
    {
645
    {
646
        // Loop pre-headers created by OSR entrypoint creation may have NaN weight to indicate
647
        // that we actually don't know they weight. Assume that they execute once. This turns
648
        // out to be an OK assumption since the pre-header doesn't have any meaningful code.
649
        if (weight != weight)
650
            weight = 1;
651
        
646
        switch (node->op()) {
652
        switch (node->op()) {
647
        case ValueAdd:
653
        case ValueAdd:
648
        case ArithAdd:
654
        case ArithAdd:
Lines 659-666 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec2
659
            else
665
            else
660
                ballot = VoteValue;
666
                ballot = VoteValue;
661
                
667
                
662
            m_graph.voteNode(node->child1(), ballot);
668
            m_graph.voteNode(node->child1(), ballot, weight);
663
            m_graph.voteNode(node->child2(), ballot);
669
            m_graph.voteNode(node->child2(), ballot, weight);
664
            break;
670
            break;
665
        }
671
        }
666
                
672
                
Lines 677-684 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec3
677
            else
683
            else
678
                ballot = VoteValue;
684
                ballot = VoteValue;
679
                
685
                
680
            m_graph.voteNode(node->child1(), ballot);
686
            m_graph.voteNode(node->child1(), ballot, weight);
681
            m_graph.voteNode(node->child2(), ballot);
687
            m_graph.voteNode(node->child2(), ballot, weight);
682
            break;
688
            break;
683
        }
689
        }
684
690
Lines 697-704 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec4
697
            else
703
            else
698
                ballot = VoteValue;
704
                ballot = VoteValue;
699
                
705
                
700
            m_graph.voteNode(node->child1(), ballot);
706
            m_graph.voteNode(node->child1(), ballot, weight);
701
            m_graph.voteNode(node->child2(), ballot);
707
            m_graph.voteNode(node->child2(), ballot, weight);
702
            break;
708
            break;
703
        }
709
        }
704
                
710
                
Lines 709-731 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec5
709
            else
715
            else
710
                ballot = VoteValue;
716
                ballot = VoteValue;
711
                
717
                
712
            m_graph.voteNode(node->child1(), ballot);
718
            m_graph.voteNode(node->child1(), ballot, weight);
713
            break;
719
            break;
714
                
720
                
715
        case ArithSqrt:
721
        case ArithSqrt:
716
        case ArithCos:
722
        case ArithCos:
717
        case ArithSin:
723
        case ArithSin:
718
            m_graph.voteNode(node->child1(), VoteDouble);
724
            m_graph.voteNode(node->child1(), VoteDouble, weight);
719
            break;
725
            break;
720
                
726
                
721
        case SetLocal: {
727
        case SetLocal: {
722
            SpeculatedType prediction = node->child1()->prediction();
728
            SpeculatedType prediction = node->child1()->prediction();
723
            if (isDoubleSpeculation(prediction))
729
            if (isDoubleSpeculation(prediction))
724
                node->variableAccessData()->vote(VoteDouble);
730
                node->variableAccessData()->vote(VoteDouble, weight);
725
            else if (
731
            else if (
726
                !isFullNumberSpeculation(prediction)
732
                !isFullNumberSpeculation(prediction)
727
                || isInt32Speculation(prediction) || isMachineIntSpeculation(prediction))
733
                || isInt32Speculation(prediction) || isMachineIntSpeculation(prediction))
728
                node->variableAccessData()->vote(VoteValue);
734
                node->variableAccessData()->vote(VoteValue, weight);
729
            break;
735
            break;
730
        }
736
        }
731
737
Lines 735-748 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec6
735
            Edge child1 = m_graph.varArgChild(node, 0);
741
            Edge child1 = m_graph.varArgChild(node, 0);
736
            Edge child2 = m_graph.varArgChild(node, 1);
742
            Edge child2 = m_graph.varArgChild(node, 1);
737
            Edge child3 = m_graph.varArgChild(node, 2);
743
            Edge child3 = m_graph.varArgChild(node, 2);
738
            m_graph.voteNode(child1, VoteValue);
744
            m_graph.voteNode(child1, VoteValue, weight);
739
            m_graph.voteNode(child2, VoteValue);
745
            m_graph.voteNode(child2, VoteValue, weight);
740
            switch (node->arrayMode().type()) {
746
            switch (node->arrayMode().type()) {
741
            case Array::Double:
747
            case Array::Double:
742
                m_graph.voteNode(child3, VoteDouble);
748
                m_graph.voteNode(child3, VoteDouble, weight);
743
                break;
749
                break;
744
            default:
750
            default:
745
                m_graph.voteNode(child3, VoteValue);
751
                m_graph.voteNode(child3, VoteValue, weight);
746
                break;
752
                break;
747
            }
753
            }
748
            break;
754
            break;
Lines 753-759 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec7
753
            break;
759
            break;
754
            
760
            
755
        default:
761
        default:
756
            m_graph.voteChildren(node, VoteValue);
762
            m_graph.voteChildren(node, VoteValue, weight);
757
            break;
763
            break;
758
        }
764
        }
759
    }
765
    }
Lines 769-775 private: Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp_sec8
769
            ASSERT(block->isReachable);
775
            ASSERT(block->isReachable);
770
            for (unsigned i = 0; i < block->size(); ++i) {
776
            for (unsigned i = 0; i < block->size(); ++i) {
771
                m_currentNode = block->at(i);
777
                m_currentNode = block->at(i);
772
                doDoubleVoting(m_currentNode);
778
                doDoubleVoting(m_currentNode, block->executionCount);
773
            }
779
            }
774
        }
780
        }
775
        for (unsigned i = 0; i < m_graph.m_variableAccessData.size(); ++i) {
781
        for (unsigned i = 0; i < m_graph.m_variableAccessData.size(); ++i) {
- Source/JavaScriptCore/dfg/DFGVariableAccessData.cpp +206 lines
Line 0 Source/JavaScriptCore/dfg/DFGVariableAccessData.cpp_sec1
1
/*
2
 * Copyright (C) 2014 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#include "config.h"
27
#include "DFGVariableAccessData.h"
28
29
#if ENABLE(DFG_JIT)
30
31
namespace JSC { namespace DFG {
32
33
VariableAccessData::VariableAccessData()
34
    : m_local(static_cast<VirtualRegister>(std::numeric_limits<int>::min()))
35
    , m_prediction(SpecNone)
36
    , m_argumentAwarePrediction(SpecNone)
37
    , m_flags(0)
38
    , m_isCaptured(false)
39
    , m_shouldNeverUnbox(false)
40
    , m_isArgumentsAlias(false)
41
    , m_structureCheckHoistingFailed(false)
42
    , m_checkArrayHoistingFailed(false)
43
    , m_isProfitableToUnbox(false)
44
    , m_isLoadedFrom(false)
45
    , m_doubleFormatState(EmptyDoubleFormatState)
46
{
47
    clearVotes();
48
}
49
50
VariableAccessData::VariableAccessData(VirtualRegister local, bool isCaptured)
51
    : m_local(local)
52
    , m_prediction(SpecNone)
53
    , m_argumentAwarePrediction(SpecNone)
54
    , m_flags(0)
55
    , m_isCaptured(isCaptured)
56
    , m_shouldNeverUnbox(isCaptured)
57
    , m_isArgumentsAlias(false)
58
    , m_structureCheckHoistingFailed(false)
59
    , m_checkArrayHoistingFailed(false)
60
    , m_isProfitableToUnbox(false)
61
    , m_isLoadedFrom(false)
62
    , m_doubleFormatState(EmptyDoubleFormatState)
63
{
64
    clearVotes();
65
}
66
67
bool VariableAccessData::mergeIsCaptured(bool isCaptured)
68
{
69
    return checkAndSet(m_shouldNeverUnbox, m_shouldNeverUnbox | isCaptured)
70
        | checkAndSet(m_isCaptured, m_isCaptured | isCaptured);
71
}
72
73
bool VariableAccessData::mergeShouldNeverUnbox(bool shouldNeverUnbox)
74
{
75
    bool newShouldNeverUnbox = m_shouldNeverUnbox | shouldNeverUnbox;
76
    if (newShouldNeverUnbox == m_shouldNeverUnbox)
77
        return false;
78
    m_shouldNeverUnbox = newShouldNeverUnbox;
79
    return true;
80
}
81
82
bool VariableAccessData::predict(SpeculatedType prediction)
83
{
84
    VariableAccessData* self = find();
85
    bool result = mergeSpeculation(self->m_prediction, prediction);
86
    if (result)
87
        mergeSpeculation(m_argumentAwarePrediction, m_prediction);
88
    return result;
89
}
90
91
bool VariableAccessData::mergeArgumentAwarePrediction(SpeculatedType prediction)
92
{
93
    return mergeSpeculation(find()->m_argumentAwarePrediction, prediction);
94
}
95
96
bool VariableAccessData::shouldUseDoubleFormatAccordingToVote()
97
{
98
    // We don't support this facility for arguments, yet.
99
    // FIXME: make this work for arguments.
100
    if (local().isArgument())
101
        return false;
102
        
103
    // If the variable is not a number prediction, then this doesn't
104
    // make any sense.
105
    if (!isFullNumberSpeculation(prediction())) {
106
        // FIXME: we may end up forcing a local in inlined argument position to be a double even
107
        // if it is sometimes not even numeric, since this never signals the fact that it doesn't
108
        // want doubles. https://bugs.webkit.org/show_bug.cgi?id=109511
109
        return false;
110
    }
111
        
112
    // If the variable is predicted to hold only doubles, then it's a
113
    // no-brainer: it should be formatted as a double.
114
    if (isDoubleSpeculation(prediction()))
115
        return true;
116
        
117
    // If the variable is known to be used as an integer, then be safe -
118
    // don't force it to be a double.
119
    if (flags() & NodeBytecodeUsesAsInt)
120
        return false;
121
        
122
    // If the variable has been voted to become a double, then make it a
123
    // double.
124
    if (voteRatio() >= Options::doubleVoteRatioForDoubleFormat())
125
        return true;
126
        
127
    return false;
128
}
129
130
bool VariableAccessData::tallyVotesForShouldUseDoubleFormat()
131
{
132
    ASSERT(isRoot());
133
        
134
    if (local().isArgument() || shouldNeverUnbox()
135
        || (flags() & NodeBytecodeReallyWantsInt))
136
        return DFG::mergeDoubleFormatState(m_doubleFormatState, NotUsingDoubleFormat);
137
    
138
    if (m_doubleFormatState == CantUseDoubleFormat)
139
        return false;
140
        
141
    bool newValueOfShouldUseDoubleFormat = shouldUseDoubleFormatAccordingToVote();
142
    if (!newValueOfShouldUseDoubleFormat) {
143
        // We monotonically convert to double. Hence, if the fixpoint leads us to conclude that we should
144
        // switch back to int, we instead ignore this and stick with double.
145
        return false;
146
    }
147
        
148
    if (m_doubleFormatState == UsingDoubleFormat)
149
        return false;
150
        
151
    return DFG::mergeDoubleFormatState(m_doubleFormatState, UsingDoubleFormat);
152
}
153
154
bool VariableAccessData::mergeDoubleFormatState(DoubleFormatState doubleFormatState)
155
{
156
    return DFG::mergeDoubleFormatState(find()->m_doubleFormatState, doubleFormatState);
157
}
158
159
bool VariableAccessData::makePredictionForDoubleFormat()
160
{
161
    ASSERT(isRoot());
162
    
163
    if (m_doubleFormatState != UsingDoubleFormat)
164
        return false;
165
    
166
    SpeculatedType type = m_prediction;
167
    if (type & ~SpecBytecodeNumber)
168
        type |= SpecDoublePureNaN;
169
    if (type & SpecMachineInt)
170
        type |= SpecInt52AsDouble;
171
    return checkAndSet(m_prediction, type);
172
}
173
174
FlushFormat VariableAccessData::flushFormat()
175
{
176
    ASSERT(find() == this);
177
    
178
    if (isArgumentsAlias())
179
        return FlushedArguments;
180
    
181
    if (!shouldUnboxIfPossible())
182
        return FlushedJSValue;
183
    
184
    if (shouldUseDoubleFormat())
185
        return FlushedDouble;
186
    
187
    SpeculatedType prediction = argumentAwarePrediction();
188
    if (isInt32Speculation(prediction))
189
        return FlushedInt32;
190
    
191
    if (enableInt52() && !m_local.isArgument() && isMachineIntSpeculation(prediction))
192
        return FlushedInt52;
193
    
194
    if (isCellSpeculation(prediction))
195
        return FlushedCell;
196
    
197
    if (isBooleanSpeculation(prediction))
198
        return FlushedBoolean;
199
    
200
    return FlushedJSValue;
201
}
202
203
} } // namespace JSC::DFG
204
205
#endif // ENABLE(DFG_JIT)
206
- Source/JavaScriptCore/dfg/DFGVariableAccessData.h -162 / +18 lines
Lines 1-5 Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec1
1
/*
1
/*
2
 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved.
2
 * Copyright (C) 2011-2014 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 26-31 Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec2
26
#ifndef DFGVariableAccessData_h
26
#ifndef DFGVariableAccessData_h
27
#define DFGVariableAccessData_h
27
#define DFGVariableAccessData_h
28
28
29
#if ENABLE(DFG_JIT)
30
29
#include "DFGCommon.h"
31
#include "DFGCommon.h"
30
#include "DFGDoubleFormatState.h"
32
#include "DFGDoubleFormatState.h"
31
#include "DFGFlushFormat.h"
33
#include "DFGFlushFormat.h"
Lines 45-83 enum DoubleBallot { VoteValue, VoteDoubl Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec3
45
47
46
class VariableAccessData : public UnionFind<VariableAccessData> {
48
class VariableAccessData : public UnionFind<VariableAccessData> {
47
public:
49
public:
48
    VariableAccessData()
50
    VariableAccessData();
49
        : m_local(static_cast<VirtualRegister>(std::numeric_limits<int>::min()))
51
    VariableAccessData(VirtualRegister local, bool isCaptured);
50
        , m_prediction(SpecNone)
51
        , m_argumentAwarePrediction(SpecNone)
52
        , m_flags(0)
53
        , m_isCaptured(false)
54
        , m_shouldNeverUnbox(false)
55
        , m_isArgumentsAlias(false)
56
        , m_structureCheckHoistingFailed(false)
57
        , m_checkArrayHoistingFailed(false)
58
        , m_isProfitableToUnbox(false)
59
        , m_isLoadedFrom(false)
60
        , m_doubleFormatState(EmptyDoubleFormatState)
61
    {
62
        clearVotes();
63
    }
64
    
65
    VariableAccessData(VirtualRegister local, bool isCaptured)
66
        : m_local(local)
67
        , m_prediction(SpecNone)
68
        , m_argumentAwarePrediction(SpecNone)
69
        , m_flags(0)
70
        , m_isCaptured(isCaptured)
71
        , m_shouldNeverUnbox(isCaptured)
72
        , m_isArgumentsAlias(false)
73
        , m_structureCheckHoistingFailed(false)
74
        , m_checkArrayHoistingFailed(false)
75
        , m_isProfitableToUnbox(false)
76
        , m_isLoadedFrom(false)
77
        , m_doubleFormatState(EmptyDoubleFormatState)
78
    {
79
        clearVotes();
80
    }
81
    
52
    
82
    VirtualRegister local()
53
    VirtualRegister local()
83
    {
54
    {
Lines 91-101 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec4
91
        return m_machineLocal;
62
        return m_machineLocal;
92
    }
63
    }
93
64
94
    bool mergeIsCaptured(bool isCaptured)
65
    bool mergeIsCaptured(bool isCaptured);
95
    {
96
        return checkAndSet(m_shouldNeverUnbox, m_shouldNeverUnbox | isCaptured)
97
            | checkAndSet(m_isCaptured, m_isCaptured | isCaptured);
98
    }
99
    
66
    
100
    bool isCaptured()
67
    bool isCaptured()
101
    {
68
    {
Lines 112-125 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec5
112
        return m_isProfitableToUnbox;
79
        return m_isProfitableToUnbox;
113
    }
80
    }
114
    
81
    
115
    bool mergeShouldNeverUnbox(bool shouldNeverUnbox)
82
    bool mergeShouldNeverUnbox(bool shouldNeverUnbox);
116
    {
117
        bool newShouldNeverUnbox = m_shouldNeverUnbox | shouldNeverUnbox;
118
        if (newShouldNeverUnbox == m_shouldNeverUnbox)
119
            return false;
120
        m_shouldNeverUnbox = newShouldNeverUnbox;
121
        return true;
122
    }
123
    
83
    
124
    // Returns true if it would be unsound to store the value in an unboxed fashion.
84
    // Returns true if it would be unsound to store the value in an unboxed fashion.
125
    // If this returns false, it simply means that it is sound to unbox; it doesn't
85
    // If this returns false, it simply means that it is sound to unbox; it doesn't
Lines 183-196 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec6
183
        return m_isLoadedFrom;
143
        return m_isLoadedFrom;
184
    }
144
    }
185
    
145
    
186
    bool predict(SpeculatedType prediction)
146
    bool predict(SpeculatedType prediction);
187
    {
188
        VariableAccessData* self = find();
189
        bool result = mergeSpeculation(self->m_prediction, prediction);
190
        if (result)
191
            mergeSpeculation(m_argumentAwarePrediction, m_prediction);
192
        return result;
193
    }
194
    
147
    
195
    SpeculatedType nonUnifiedPrediction()
148
    SpeculatedType nonUnifiedPrediction()
196
    {
149
    {
Lines 207-216 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec7
207
        return find()->m_argumentAwarePrediction;
160
        return find()->m_argumentAwarePrediction;
208
    }
161
    }
209
    
162
    
210
    bool mergeArgumentAwarePrediction(SpeculatedType prediction)
163
    bool mergeArgumentAwarePrediction(SpeculatedType prediction);
211
    {
212
        return mergeSpeculation(find()->m_argumentAwarePrediction, prediction);
213
    }
214
    
164
    
215
    void clearVotes()
165
    void clearVotes()
216
    {
166
    {
Lines 219-228 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec8
219
        m_votes[1] = 0;
169
        m_votes[1] = 0;
220
    }
170
    }
221
    
171
    
222
    void vote(unsigned ballot)
172
    void vote(unsigned ballot, float weight = 1)
223
    {
173
    {
224
        ASSERT(ballot < 2);
174
        ASSERT(ballot < 2);
225
        m_votes[ballot]++;
175
        m_votes[ballot] += weight;
226
    }
176
    }
227
    
177
    
228
    double voteRatio()
178
    double voteRatio()
Lines 231-269 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec9
231
        return static_cast<double>(m_votes[1]) / m_votes[0];
181
        return static_cast<double>(m_votes[1]) / m_votes[0];
232
    }
182
    }
233
    
183
    
234
    bool shouldUseDoubleFormatAccordingToVote()
184
    bool shouldUseDoubleFormatAccordingToVote();
235
    {
236
        // We don't support this facility for arguments, yet.
237
        // FIXME: make this work for arguments.
238
        if (local().isArgument())
239
            return false;
240
        
241
        // If the variable is not a number prediction, then this doesn't
242
        // make any sense.
243
        if (!isFullNumberSpeculation(prediction())) {
244
            // FIXME: we may end up forcing a local in inlined argument position to be a double even
245
            // if it is sometimes not even numeric, since this never signals the fact that it doesn't
246
            // want doubles. https://bugs.webkit.org/show_bug.cgi?id=109511
247
            return false;
248
        }
249
        
250
        // If the variable is predicted to hold only doubles, then it's a
251
        // no-brainer: it should be formatted as a double.
252
        if (isDoubleSpeculation(prediction()))
253
            return true;
254
        
255
        // If the variable is known to be used as an integer, then be safe -
256
        // don't force it to be a double.
257
        if (flags() & NodeBytecodeUsesAsInt)
258
            return false;
259
        
260
        // If the variable has been voted to become a double, then make it a
261
        // double.
262
        if (voteRatio() >= Options::doubleVoteRatioForDoubleFormat())
263
            return true;
264
        
265
        return false;
266
    }
267
    
185
    
268
    DoubleFormatState doubleFormatState()
186
    DoubleFormatState doubleFormatState()
269
    {
187
    {
Lines 279-326 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec10
279
        return doubleState && isProfitableToUnbox();
197
        return doubleState && isProfitableToUnbox();
280
    }
198
    }
281
    
199
    
282
    bool tallyVotesForShouldUseDoubleFormat()
200
    bool tallyVotesForShouldUseDoubleFormat();
283
    {
284
        ASSERT(isRoot());
285
        
286
        if (local().isArgument() || shouldNeverUnbox())
287
            return DFG::mergeDoubleFormatState(m_doubleFormatState, NotUsingDoubleFormat);
288
        
289
        if (m_doubleFormatState == CantUseDoubleFormat)
290
            return false;
291
        
292
        bool newValueOfShouldUseDoubleFormat = shouldUseDoubleFormatAccordingToVote();
293
        if (!newValueOfShouldUseDoubleFormat) {
294
            // We monotonically convert to double. Hence, if the fixpoint leads us to conclude that we should
295
            // switch back to int, we instead ignore this and stick with double.
296
            return false;
297
        }
298
        
299
        if (m_doubleFormatState == UsingDoubleFormat)
300
            return false;
301
        
302
        return DFG::mergeDoubleFormatState(m_doubleFormatState, UsingDoubleFormat);
303
    }
304
    
201
    
305
    bool mergeDoubleFormatState(DoubleFormatState doubleFormatState)
202
    bool mergeDoubleFormatState(DoubleFormatState doubleFormatState);
306
    {
307
        return DFG::mergeDoubleFormatState(find()->m_doubleFormatState, doubleFormatState);
308
    }
309
    
203
    
310
    bool makePredictionForDoubleFormat()
204
    bool makePredictionForDoubleFormat();
311
    {
312
        ASSERT(isRoot());
313
        
314
        if (m_doubleFormatState != UsingDoubleFormat)
315
            return false;
316
        
317
        SpeculatedType type = m_prediction;
318
        if (type & ~SpecBytecodeNumber)
319
            type |= SpecDoublePureNaN;
320
        if (type & SpecMachineInt)
321
            type |= SpecInt52AsDouble;
322
        return checkAndSet(m_prediction, type);
323
    }
324
    
205
    
325
    NodeFlags flags() const { return m_flags; }
206
    NodeFlags flags() const { return m_flags; }
326
    
207
    
Lines 329-362 public: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec11
329
        return checkAndSet(m_flags, m_flags | newFlags);
210
        return checkAndSet(m_flags, m_flags | newFlags);
330
    }
211
    }
331
    
212
    
332
    FlushFormat flushFormat()
213
    FlushFormat flushFormat();
333
    {
334
        ASSERT(find() == this);
335
        
336
        if (isArgumentsAlias())
337
            return FlushedArguments;
338
        
339
        if (!shouldUnboxIfPossible())
340
            return FlushedJSValue;
341
        
342
        if (shouldUseDoubleFormat())
343
            return FlushedDouble;
344
        
345
        SpeculatedType prediction = argumentAwarePrediction();
346
        if (isInt32Speculation(prediction))
347
            return FlushedInt32;
348
        
349
        if (enableInt52() && !m_local.isArgument() && isMachineIntSpeculation(prediction))
350
            return FlushedInt52;
351
        
352
        if (isCellSpeculation(prediction))
353
            return FlushedCell;
354
        
355
        if (isBooleanSpeculation(prediction))
356
            return FlushedBoolean;
357
        
358
        return FlushedJSValue;
359
    }
360
    
214
    
361
    FlushedAt flushedAt()
215
    FlushedAt flushedAt()
362
    {
216
    {
Lines 389-392 private: Source/JavaScriptCore/dfg/DFGVariableAccessData.h_sec12
389
243
390
} } // namespace JSC::DFG
244
} } // namespace JSC::DFG
391
245
246
#endif // ENABLE(DFG_JIT)
247
392
#endif // DFGVariableAccessData_h
248
#endif // DFGVariableAccessData_h

Return to Bug 131906