Skip to content

Commit 5a22d96

Browse files
author
Filip Pizlo
committed
FTL B3 does not logicalNot correctly
https://bugs.webkit.org/show_bug.cgi?id=152512 Reviewed by Saam Barati. Source/JavaScriptCore: I'm working on a bug where V8/richards does not run correctly. I noticed that the codegen was doing a log of Not32's followed by branches, which smelled like badness. To debug this, I needed B3's origins to dump as something other than a hexed pointer to a node. The node index would be better. So, I added the notion of an origin printer to Procedure. The bug was easy enough to fix. This introduces Output::logicalNot(). In LLVM, it's the same as bitNot(). In B3, it's compiled to Equal(value, 0). We could have also compiled it to BitXor(value, 1), except that B3 will strength-reduce to that anyway whenever it's safe. It's sort of nice that right now, you could use logicalNot() on non-bool values and get C-like behavior. Richards still doesn't run, though. There are more bugs! * JavaScriptCore.xcodeproj/project.pbxproj: * b3/B3BasicBlock.cpp: (JSC::B3::BasicBlock::dump): (JSC::B3::BasicBlock::deepDump): * b3/B3BasicBlock.h: (JSC::B3::BasicBlock::frequency): (JSC::B3::DeepBasicBlockDump::DeepBasicBlockDump): (JSC::B3::DeepBasicBlockDump::dump): (JSC::B3::deepDump): * b3/B3LowerToAir.cpp: (JSC::B3::Air::LowerToAir::run): (JSC::B3::Air::LowerToAir::lower): * b3/B3Origin.h: (JSC::B3::Origin::data): * b3/B3OriginDump.h: Added. (JSC::B3::OriginDump::OriginDump): (JSC::B3::OriginDump::dump): * b3/B3Procedure.cpp: (JSC::B3::Procedure::~Procedure): (JSC::B3::Procedure::printOrigin): (JSC::B3::Procedure::addBlock): (JSC::B3::Procedure::dump): * b3/B3Procedure.h: (JSC::B3::Procedure::setOriginPrinter): * b3/B3Value.cpp: (JSC::B3::Value::dumpChildren): (JSC::B3::Value::deepDump): * b3/B3Value.h: (JSC::B3::DeepValueDump::DeepValueDump): (JSC::B3::DeepValueDump::dump): (JSC::B3::deepDump): * ftl/FTLB3Output.cpp: (JSC::FTL::Output::lockedStackSlot): (JSC::FTL::Output::bitNot): (JSC::FTL::Output::logicalNot): (JSC::FTL::Output::load): * ftl/FTLB3Output.h: (JSC::FTL::Output::aShr): (JSC::FTL::Output::lShr): (JSC::FTL::Output::ctlz32): (JSC::FTL::Output::addWithOverflow32): (JSC::FTL::Output::lessThanOrEqual): (JSC::FTL::Output::doubleEqual): (JSC::FTL::Output::doubleEqualOrUnordered): (JSC::FTL::Output::doubleNotEqualOrUnordered): (JSC::FTL::Output::doubleLessThan): (JSC::FTL::Output::doubleLessThanOrEqual): (JSC::FTL::Output::doubleGreaterThan): (JSC::FTL::Output::doubleGreaterThanOrEqual): (JSC::FTL::Output::doubleNotEqualAndOrdered): (JSC::FTL::Output::doubleLessThanOrUnordered): (JSC::FTL::Output::doubleLessThanOrEqualOrUnordered): (JSC::FTL::Output::doubleGreaterThanOrUnordered): (JSC::FTL::Output::doubleGreaterThanOrEqualOrUnordered): (JSC::FTL::Output::isZero32): (JSC::FTL::Output::notZero32): (JSC::FTL::Output::addIncomingToPhi): (JSC::FTL::Output::bitCast): (JSC::FTL::Output::bitNot): Deleted. * ftl/FTLLowerDFGToLLVM.cpp: (JSC::FTL::DFG::LowerDFGToLLVM::compileCheckArray): (JSC::FTL::DFG::LowerDFGToLLVM::compileGetTypedArrayByteOffset): (JSC::FTL::DFG::LowerDFGToLLVM::compileLogicalNot): (JSC::FTL::DFG::LowerDFGToLLVM::compileCallOrConstruct): (JSC::FTL::DFG::LowerDFGToLLVM::compileInstanceOfCustom): (JSC::FTL::DFG::LowerDFGToLLVM::compileCountExecution): (JSC::FTL::DFG::LowerDFGToLLVM::boolify): (JSC::FTL::DFG::LowerDFGToLLVM::isMisc): (JSC::FTL::DFG::LowerDFGToLLVM::isNotBoolean): (JSC::FTL::DFG::LowerDFGToLLVM::isBoolean): (JSC::FTL::DFG::LowerDFGToLLVM::unboxBoolean): (JSC::FTL::DFG::LowerDFGToLLVM::isNotType): (JSC::FTL::DFG::LowerDFGToLLVM::speculateObject): * ftl/FTLOutput.h: (JSC::FTL::Output::aShr): (JSC::FTL::Output::lShr): (JSC::FTL::Output::bitNot): (JSC::FTL::Output::logicalNot): (JSC::FTL::Output::insertElement): * ftl/FTLState.cpp: (JSC::FTL::State::State): Source/WTF: This change introduces yet another use of SharedTask in JSC. While doing this, I noticed that SharedTask::run() always demands that whatever arguments the callback takes, they must be passed as rvalue references. This was a clear misuse of perfect forwarding. This change makes SharedTask's approach to forwarding match what we were already doing in ScopedLambda. * wtf/SharedTask.h: Canonical link: https://commits.webkit.org/170612@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194372 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent eb06d79 commit 5a22d96

18 files changed

Lines changed: 259 additions & 69 deletions

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,105 @@
1+
2015-12-22 Filip Pizlo <fpizlo@apple.com>
2+
3+
FTL B3 does not logicalNot correctly
4+
https://bugs.webkit.org/show_bug.cgi?id=152512
5+
6+
Reviewed by Saam Barati.
7+
8+
I'm working on a bug where V8/richards does not run correctly. I noticed that the codegen was
9+
doing a log of Not32's followed by branches, which smelled like badness. To debug this, I
10+
needed B3's origins to dump as something other than a hexed pointer to a node. The node index
11+
would be better. So, I added the notion of an origin printer to Procedure.
12+
13+
The bug was easy enough to fix. This introduces Output::logicalNot(). In LLVM, it's the same
14+
as bitNot(). In B3, it's compiled to Equal(value, 0). We could have also compiled it to
15+
BitXor(value, 1), except that B3 will strength-reduce to that anyway whenever it's safe. It's
16+
sort of nice that right now, you could use logicalNot() on non-bool values and get C-like
17+
behavior.
18+
19+
Richards still doesn't run, though. There are more bugs!
20+
21+
* JavaScriptCore.xcodeproj/project.pbxproj:
22+
* b3/B3BasicBlock.cpp:
23+
(JSC::B3::BasicBlock::dump):
24+
(JSC::B3::BasicBlock::deepDump):
25+
* b3/B3BasicBlock.h:
26+
(JSC::B3::BasicBlock::frequency):
27+
(JSC::B3::DeepBasicBlockDump::DeepBasicBlockDump):
28+
(JSC::B3::DeepBasicBlockDump::dump):
29+
(JSC::B3::deepDump):
30+
* b3/B3LowerToAir.cpp:
31+
(JSC::B3::Air::LowerToAir::run):
32+
(JSC::B3::Air::LowerToAir::lower):
33+
* b3/B3Origin.h:
34+
(JSC::B3::Origin::data):
35+
* b3/B3OriginDump.h: Added.
36+
(JSC::B3::OriginDump::OriginDump):
37+
(JSC::B3::OriginDump::dump):
38+
* b3/B3Procedure.cpp:
39+
(JSC::B3::Procedure::~Procedure):
40+
(JSC::B3::Procedure::printOrigin):
41+
(JSC::B3::Procedure::addBlock):
42+
(JSC::B3::Procedure::dump):
43+
* b3/B3Procedure.h:
44+
(JSC::B3::Procedure::setOriginPrinter):
45+
* b3/B3Value.cpp:
46+
(JSC::B3::Value::dumpChildren):
47+
(JSC::B3::Value::deepDump):
48+
* b3/B3Value.h:
49+
(JSC::B3::DeepValueDump::DeepValueDump):
50+
(JSC::B3::DeepValueDump::dump):
51+
(JSC::B3::deepDump):
52+
* ftl/FTLB3Output.cpp:
53+
(JSC::FTL::Output::lockedStackSlot):
54+
(JSC::FTL::Output::bitNot):
55+
(JSC::FTL::Output::logicalNot):
56+
(JSC::FTL::Output::load):
57+
* ftl/FTLB3Output.h:
58+
(JSC::FTL::Output::aShr):
59+
(JSC::FTL::Output::lShr):
60+
(JSC::FTL::Output::ctlz32):
61+
(JSC::FTL::Output::addWithOverflow32):
62+
(JSC::FTL::Output::lessThanOrEqual):
63+
(JSC::FTL::Output::doubleEqual):
64+
(JSC::FTL::Output::doubleEqualOrUnordered):
65+
(JSC::FTL::Output::doubleNotEqualOrUnordered):
66+
(JSC::FTL::Output::doubleLessThan):
67+
(JSC::FTL::Output::doubleLessThanOrEqual):
68+
(JSC::FTL::Output::doubleGreaterThan):
69+
(JSC::FTL::Output::doubleGreaterThanOrEqual):
70+
(JSC::FTL::Output::doubleNotEqualAndOrdered):
71+
(JSC::FTL::Output::doubleLessThanOrUnordered):
72+
(JSC::FTL::Output::doubleLessThanOrEqualOrUnordered):
73+
(JSC::FTL::Output::doubleGreaterThanOrUnordered):
74+
(JSC::FTL::Output::doubleGreaterThanOrEqualOrUnordered):
75+
(JSC::FTL::Output::isZero32):
76+
(JSC::FTL::Output::notZero32):
77+
(JSC::FTL::Output::addIncomingToPhi):
78+
(JSC::FTL::Output::bitCast):
79+
(JSC::FTL::Output::bitNot): Deleted.
80+
* ftl/FTLLowerDFGToLLVM.cpp:
81+
(JSC::FTL::DFG::LowerDFGToLLVM::compileCheckArray):
82+
(JSC::FTL::DFG::LowerDFGToLLVM::compileGetTypedArrayByteOffset):
83+
(JSC::FTL::DFG::LowerDFGToLLVM::compileLogicalNot):
84+
(JSC::FTL::DFG::LowerDFGToLLVM::compileCallOrConstruct):
85+
(JSC::FTL::DFG::LowerDFGToLLVM::compileInstanceOfCustom):
86+
(JSC::FTL::DFG::LowerDFGToLLVM::compileCountExecution):
87+
(JSC::FTL::DFG::LowerDFGToLLVM::boolify):
88+
(JSC::FTL::DFG::LowerDFGToLLVM::isMisc):
89+
(JSC::FTL::DFG::LowerDFGToLLVM::isNotBoolean):
90+
(JSC::FTL::DFG::LowerDFGToLLVM::isBoolean):
91+
(JSC::FTL::DFG::LowerDFGToLLVM::unboxBoolean):
92+
(JSC::FTL::DFG::LowerDFGToLLVM::isNotType):
93+
(JSC::FTL::DFG::LowerDFGToLLVM::speculateObject):
94+
* ftl/FTLOutput.h:
95+
(JSC::FTL::Output::aShr):
96+
(JSC::FTL::Output::lShr):
97+
(JSC::FTL::Output::bitNot):
98+
(JSC::FTL::Output::logicalNot):
99+
(JSC::FTL::Output::insertElement):
100+
* ftl/FTLState.cpp:
101+
(JSC::FTL::State::State):
102+
1103
2015-12-22 Keith Miller <keith_miller@apple.com>
2104

3105
Remove OverridesHasInstance from TypeInfoFlags

‎Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@
373373
0F48532A187DFDEC0083B687 /* FTLRecoveryOpcode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F485326187DFDEC0083B687 /* FTLRecoveryOpcode.h */; settings = {ATTRIBUTES = (Private, ); }; };
374374
0F493AFA16D0CAD30084508B /* SourceProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F493AF816D0CAD10084508B /* SourceProvider.cpp */; };
375375
0F4B94DC17B9F07500DD03A4 /* TypedArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4B94DB17B9F07500DD03A4 /* TypedArrayInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
376+
0F4C91661C29F4F2004341A6 /* B3OriginDump.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4C91651C29F4F2004341A6 /* B3OriginDump.h */; };
376377
0F4F29DF18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F4F29DD18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.cpp */; };
377378
0F4F29E018B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4F29DE18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.h */; };
378379
0F50AF3C193E8B3900674EE8 /* DFGStructureClobberState.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F50AF3B193E8B3900674EE8 /* DFGStructureClobberState.h */; };
@@ -2506,6 +2507,7 @@
25062507
0F485326187DFDEC0083B687 /* FTLRecoveryOpcode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FTLRecoveryOpcode.h; path = ftl/FTLRecoveryOpcode.h; sourceTree = "<group>"; };
25072508
0F493AF816D0CAD10084508B /* SourceProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SourceProvider.cpp; sourceTree = "<group>"; };
25082509
0F4B94DB17B9F07500DD03A4 /* TypedArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypedArrayInlines.h; sourceTree = "<group>"; };
2510+
0F4C91651C29F4F2004341A6 /* B3OriginDump.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3OriginDump.h; path = b3/B3OriginDump.h; sourceTree = "<group>"; };
25092511
0F4F29DD18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGStaticExecutionCountEstimationPhase.cpp; path = dfg/DFGStaticExecutionCountEstimationPhase.cpp; sourceTree = "<group>"; };
25102512
0F4F29DE18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGStaticExecutionCountEstimationPhase.h; path = dfg/DFGStaticExecutionCountEstimationPhase.h; sourceTree = "<group>"; };
25112513
0F50AF3B193E8B3900674EE8 /* DFGStructureClobberState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGStructureClobberState.h; path = dfg/DFGStructureClobberState.h; sourceTree = "<group>"; };
@@ -4701,6 +4703,7 @@
47014703
0FEC84D81BDACDAC0080FF74 /* B3Opcode.h */,
47024704
0FEC84D91BDACDAC0080FF74 /* B3Origin.cpp */,
47034705
0FEC84DA1BDACDAC0080FF74 /* B3Origin.h */,
4706+
0F4C91651C29F4F2004341A6 /* B3OriginDump.h */,
47044707
0FEC84DB1BDACDAC0080FF74 /* B3PatchpointSpecial.cpp */,
47054708
0FEC84DC1BDACDAC0080FF74 /* B3PatchpointSpecial.h */,
47064709
0FEC84DD1BDACDAC0080FF74 /* B3PatchpointValue.cpp */,
@@ -6986,6 +6989,7 @@
69866989
969A07230ED1CE3300F1F681 /* BytecodeGenerator.h in Headers */,
69876990
7094C4DF1AE439530041A2EE /* BytecodeIntrinsicRegistry.h in Headers */,
69886991
0F2DD80B1AB3D85800BBB8E8 /* BytecodeKills.h in Headers */,
6992+
0F4C91661C29F4F2004341A6 /* B3OriginDump.h in Headers */,
69896993
C2FCAE1317A9C24E0034C735 /* BytecodeLivenessAnalysis.h in Headers */,
69906994
0F666EC0183566F900D017F1 /* BytecodeLivenessAnalysisInlines.h in Headers */,
69916995
6514F21918B3E1670098FF8B /* Bytecodes.h in Headers */,

‎Source/JavaScriptCore/b3/B3BasicBlock.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ void BasicBlock::dump(PrintStream& out) const
108108
out.print(dumpPrefix, m_index);
109109
}
110110

111-
void BasicBlock::deepDump(PrintStream& out) const
111+
void BasicBlock::deepDump(const Procedure& proc, PrintStream& out) const
112112
{
113113
out.print("BB", *this, ": ; frequency = ", m_frequency, "\n");
114114
if (predecessors().size())
115115
out.print(" Predecessors: ", pointerListDump(predecessors()), "\n");
116116
for (Value* value : *this)
117-
out.print(" ", B3::deepDump(value), "\n");
117+
out.print(" ", B3::deepDump(proc, value), "\n");
118118
}
119119

120120
} } // namespace JSC::B3

‎Source/JavaScriptCore/b3/B3BasicBlock.h‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class BasicBlock {
114114
double frequency() const { return m_frequency; }
115115

116116
void dump(PrintStream&) const;
117-
void deepDump(PrintStream&) const;
117+
void deepDump(const Procedure&, PrintStream&) const;
118118

119119
private:
120120
friend class BlockInsertionSet;
@@ -132,26 +132,28 @@ class BasicBlock {
132132

133133
class DeepBasicBlockDump {
134134
public:
135-
DeepBasicBlockDump(const BasicBlock* block)
136-
: m_block(block)
135+
DeepBasicBlockDump(const Procedure& proc, const BasicBlock* block)
136+
: m_proc(proc)
137+
, m_block(block)
137138
{
138139
}
139140

140141
void dump(PrintStream& out) const
141142
{
142143
if (m_block)
143-
m_block->deepDump(out);
144+
m_block->deepDump(m_proc, out);
144145
else
145146
out.print("<null>");
146147
}
147148

148149
private:
150+
const Procedure& m_proc;
149151
const BasicBlock* m_block;
150152
};
151153

152-
inline DeepBasicBlockDump deepDump(const BasicBlock* block)
154+
inline DeepBasicBlockDump deepDump(const Procedure& proc, const BasicBlock* block)
153155
{
154-
return DeepBasicBlockDump(block);
156+
return DeepBasicBlockDump(proc, block);
155157
}
156158

157159
} } // namespace JSC::B3

‎Source/JavaScriptCore/b3/B3LowerToAir.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class LowerToAir {
102102
continue;
103103
m_insts.append(Vector<Inst>());
104104
if (verbose)
105-
dataLog("Lowering ", deepDump(m_value), ":\n");
105+
dataLog("Lowering ", deepDump(m_procedure, m_value), ":\n");
106106
lower();
107107
if (verbose) {
108108
for (Inst& inst : m_insts.last())
@@ -2147,7 +2147,7 @@ class LowerToAir {
21472147
break;
21482148
}
21492149

2150-
dataLog("FATAL: could not lower ", deepDump(m_value), "\n");
2150+
dataLog("FATAL: could not lower ", deepDump(m_procedure, m_value), "\n");
21512151
RELEASE_ASSERT_NOT_REACHED();
21522152
}
21532153

‎Source/JavaScriptCore/b3/B3Origin.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Origin {
4747

4848
const void* data() const { return m_data; }
4949

50+
// You should avoid using this. Use OriginDump instead.
5051
void dump(PrintStream&) const;
5152

5253
private:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2015 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+
#ifndef B3OriginDump_h
27+
#define B3OriginDump_h
28+
29+
#if ENABLE(B3_JIT)
30+
31+
#include "B3Origin.h"
32+
#include "B3Procedure.h"
33+
34+
namespace JSC { namespace B3 {
35+
36+
class OriginDump {
37+
public:
38+
OriginDump(const Procedure& proc, Origin origin)
39+
: m_proc(proc)
40+
, m_origin(origin)
41+
{
42+
}
43+
44+
void dump(PrintStream& out) const
45+
{
46+
m_proc.printOrigin(out, m_origin);
47+
}
48+
49+
private:
50+
const Procedure& m_proc;
51+
Origin m_origin;
52+
};
53+
54+
} } // namespace JSC::B3
55+
56+
#endif // ENABLE(B3_JIT)
57+
58+
#endif // B3OriginDump_h
59+

‎Source/JavaScriptCore/b3/B3Procedure.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ Procedure::~Procedure()
5252
{
5353
}
5454

55+
void Procedure::printOrigin(PrintStream& out, Origin origin) const
56+
{
57+
if (m_originPrinter)
58+
m_originPrinter->run(out, origin);
59+
else
60+
out.print(origin);
61+
}
62+
5563
BasicBlock* Procedure::addBlock(double frequency)
5664
{
5765
std::unique_ptr<BasicBlock> block(new BasicBlock(m_blocks.size(), frequency));
@@ -126,7 +134,7 @@ void Procedure::invalidateCFG()
126134
void Procedure::dump(PrintStream& out) const
127135
{
128136
for (BasicBlock* block : *this)
129-
out.print(deepDump(block));
137+
out.print(deepDump(*this, block));
130138
if (m_byproducts->count())
131139
out.print(*m_byproducts);
132140
}

‎Source/JavaScriptCore/b3/B3Procedure.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <wtf/HashSet.h>
4040
#include <wtf/Noncopyable.h>
4141
#include <wtf/PrintStream.h>
42+
#include <wtf/SharedTask.h>
4243
#include <wtf/TriState.h>
4344
#include <wtf/Vector.h>
4445

@@ -60,6 +61,16 @@ class Procedure {
6061
JS_EXPORT_PRIVATE Procedure();
6162
JS_EXPORT_PRIVATE ~Procedure();
6263

64+
template<typename Callback>
65+
void setOriginPrinter(Callback&& callback)
66+
{
67+
m_originPrinter = createSharedTask<void(PrintStream&, Origin)>(
68+
std::forward<Callback>(callback));
69+
}
70+
71+
// Usually you use this via OriginDump, though it's cool to use it directly.
72+
void printOrigin(PrintStream& out, Origin origin) const;
73+
6374
JS_EXPORT_PRIVATE BasicBlock* addBlock(double frequency = 1);
6475

6576
template<typename ValueType, typename... Arguments>
@@ -261,6 +272,7 @@ class Procedure {
261272
const char* m_lastPhaseName;
262273
std::unique_ptr<OpaqueByproducts> m_byproducts;
263274
std::unique_ptr<Air::Code> m_code;
275+
RefPtr<SharedTask<void(PrintStream&, Origin)>> m_originPrinter;
264276
};
265277

266278
} } // namespace JSC::B3

‎Source/JavaScriptCore/b3/B3Value.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "B3CCallValue.h"
3333
#include "B3ControlValue.h"
3434
#include "B3MemoryValue.h"
35+
#include "B3OriginDump.h"
3536
#include "B3ProcedureInlines.h"
3637
#include "B3StackSlotValue.h"
3738
#include "B3UpsilonValue.h"
@@ -99,7 +100,7 @@ void Value::dumpChildren(CommaPrinter& comma, PrintStream& out) const
99100
out.print(comma, pointerDump(child));
100101
}
101102

102-
void Value::deepDump(PrintStream& out) const
103+
void Value::deepDump(const Procedure& proc, PrintStream& out) const
103104
{
104105
out.print(m_type, " ", *this, " = ", m_opcode);
105106

@@ -108,7 +109,7 @@ void Value::deepDump(PrintStream& out) const
108109
dumpChildren(comma, out);
109110

110111
if (m_origin)
111-
out.print(comma, m_origin);
112+
out.print(comma, OriginDump(proc, m_origin));
112113

113114
dumpMeta(comma, out);
114115

0 commit comments

Comments
 (0)