Skip to content

Commit 4a278ce

Browse files
committed
[JSC] Add WasmStruct related B3 Values
https://bugs.webkit.org/show_bug.cgi?id=305735 rdar://168415672 Reviewed by Yijia Huang. This patch introduces high-level wasm struct B3 values: WasmStructNew, WasmStructNew, WasmStructSet. This saves high-level semantics through B3 optimization pipeline, and we can apply data flow analysis onto Wasm GC related operations. We lower them to the original B3 values in B3LowerMacros phase, so after that phase, nothing changes. Critically important thing is keeping WasmStructGet / WasmStructSet CSE active. Previously it was achieved by memory decoration. But now we achieve it by handling these wasm struct values in B3EliminateCommonSubexpressions as the same way to what MemoryValue is doing. This is the first step torward optimizing Wasm GC in B3 significantly. Our plans are, 1. Adding WasmRefCast / WasmRefTest values next. And then data flow analysis can filter wasm GC types and potentially remove many of these type test operations. This is effective if the source program is having many of them because of generics, and B3 successfully inlined these functions. 2. Adding scalar replacement with escape analysis. Now WasmStructNew, WasmStructGet, and WasmStructSet (and other type cast / test operations) semantics are kept in B3. We can easily construct escape analysis for them and we can perform scalar replacement (and this eliminates allocations). 3. We are working on B3 sparse conditional constant propagation right now. That lattice can start including the current flow-sensitive Wasm Ref types. And we can further remove many unnecessary type test operations. Basically saying we will do DFG CheckStructure-like things in B3 for wasm GC types. * Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj: * Source/JavaScriptCore/Sources.txt: * Source/JavaScriptCore/b3/B3AbstractHeapRepository.cpp: (JSC::B3::AbstractHeapRepository::decorateWasmStructGet): (JSC::B3::AbstractHeapRepository::decorateWasmStructSet): (JSC::B3::AbstractHeapRepository::computeRangesAndDecorateInstructions): * Source/JavaScriptCore/b3/B3AbstractHeapRepository.h: * Source/JavaScriptCore/b3/B3EliminateCommonSubexpressions.cpp: * Source/JavaScriptCore/b3/B3Kind.h: (JSC::B3::Kind::hasTraps const): * Source/JavaScriptCore/b3/B3LowerMacros.cpp: * Source/JavaScriptCore/b3/B3Opcode.h: * Source/JavaScriptCore/b3/B3ReduceStrength.cpp: * Source/JavaScriptCore/b3/B3SlotBaseValue.h: * Source/JavaScriptCore/b3/B3Validate.cpp: * Source/JavaScriptCore/b3/B3Value.cpp: (JSC::B3::Value::effects const): (JSC::B3::Value::key const): * Source/JavaScriptCore/b3/B3Value.h: * Source/JavaScriptCore/b3/B3ValueInlines.h: * Source/JavaScriptCore/b3/B3ValueKey.cpp: (JSC::B3::ValueKey::materialize const): * Source/JavaScriptCore/b3/B3WasmStructFieldValue.cpp: Copied from Source/JavaScriptCore/b3/B3SlotBaseValue.h. * Source/JavaScriptCore/b3/B3WasmStructFieldValue.h: Added. (JSC::B3::WasmStructFieldValue::accepts): (JSC::B3::WasmStructFieldValue::rtt const): (JSC::B3::WasmStructFieldValue::structType const): (JSC::B3::WasmStructFieldValue::fieldIndex const): (JSC::B3::WasmStructFieldValue::fieldHeapKey const): (JSC::B3::WasmStructFieldValue::range const): (JSC::B3::WasmStructFieldValue::setRange): (JSC::B3::WasmStructFieldValue::mutability const): (JSC::B3::WasmStructFieldValue::WasmStructFieldValue): * Source/JavaScriptCore/b3/B3WasmStructGetValue.cpp: Copied from Source/JavaScriptCore/b3/B3SlotBaseValue.h. (JSC::B3::WasmStructGetValue::WasmStructGetValue): (JSC::B3::WasmStructGetValue::dumpMeta const): * Source/JavaScriptCore/b3/B3WasmStructGetValue.h: Copied from Source/JavaScriptCore/b3/B3SlotBaseValue.h. * Source/JavaScriptCore/b3/B3WasmStructNewValue.cpp: Copied from Source/JavaScriptCore/b3/B3SlotBaseValue.h. (JSC::B3::WasmStructNewValue::dumpMeta const): * Source/JavaScriptCore/b3/B3WasmStructNewValue.h: Added. * Source/JavaScriptCore/b3/B3WasmStructSetValue.cpp: Copied from Source/JavaScriptCore/b3/B3SlotBaseValue.h. (JSC::B3::WasmStructSetValue::WasmStructSetValue): (JSC::B3::WasmStructSetValue::dumpMeta const): * Source/JavaScriptCore/b3/B3WasmStructSetValue.h: Copied from Source/JavaScriptCore/b3/B3SlotBaseValue.h. * Source/JavaScriptCore/wasm/WasmOMGIRGenerator.cpp: (JSC::Wasm::OMGIRGenerator::emitStructSet): (JSC::Wasm::OMGIRGenerator::addStructNew): (JSC::Wasm::OMGIRGenerator::addStructNewDefault): (JSC::Wasm::OMGIRGenerator::addStructGet): (JSC::Wasm::OMGIRGenerator::addStructSet): (JSC::Wasm::OMGIRGenerator::allocatorForWasmGCHeapCellSize): (JSC::Wasm::OMGIRGenerator::allocateWasmGCStructUninitialized): Deleted. * Source/JavaScriptCore/wasm/WasmTypeDefinition.h: Canonical link: https://commits.webkit.org/305925@main
1 parent 309186d commit 4a278ce

25 files changed

Lines changed: 1259 additions & 143 deletions

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,10 @@
20772077
E392E6F824D25FA600B20767 /* B3BottomTupleValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E392E6F624D25FA600B20767 /* B3BottomTupleValue.cpp */; };
20782078
E392E6F924D25FA900B20767 /* B3BottomTupleValue.h in Headers */ = {isa = PBXBuildFile; fileRef = E392E6F724D25FA600B20767 /* B3BottomTupleValue.h */; };
20792079
E393ADD81FE702D00022D681 /* WeakMapImplInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = E393ADD71FE702CC0022D681 /* WeakMapImplInlines.h */; };
2080+
E3952C182F1DDF5700F5BEE8 /* B3WasmStructGetValue.h in Headers */ = {isa = PBXBuildFile; fileRef = E3952C122F1DDF5700F5BEE8 /* B3WasmStructGetValue.h */; };
2081+
E3952C192F1DDF5700F5BEE8 /* B3WasmStructNewValue.h in Headers */ = {isa = PBXBuildFile; fileRef = E3952C142F1DDF5700F5BEE8 /* B3WasmStructNewValue.h */; };
2082+
E3952C1A2F1DDF5700F5BEE8 /* B3WasmStructFieldValue.h in Headers */ = {isa = PBXBuildFile; fileRef = E3952C102F1DDF5700F5BEE8 /* B3WasmStructFieldValue.h */; };
2083+
E3952C1B2F1DDF5700F5BEE8 /* B3WasmStructSetValue.h in Headers */ = {isa = PBXBuildFile; fileRef = E3952C162F1DDF5700F5BEE8 /* B3WasmStructSetValue.h */; };
20802084
E399AEC32559457F00B78485 /* IntlDateTimeFormat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1587D671B4DC14100D69849 /* IntlDateTimeFormat.cpp */; };
20812085
E39BF39922A2288B00BD183E /* SymbolTableInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = E39BF39822A2288B00BD183E /* SymbolTableInlines.h */; };
20822086
E39D45F51D39005600B3B377 /* InterpreterInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = E39D9D841D39000600667282 /* InterpreterInlines.h */; };
@@ -5941,6 +5945,14 @@
59415945
E392E6F624D25FA600B20767 /* B3BottomTupleValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3BottomTupleValue.cpp; path = b3/B3BottomTupleValue.cpp; sourceTree = "<group>"; };
59425946
E392E6F724D25FA600B20767 /* B3BottomTupleValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3BottomTupleValue.h; path = b3/B3BottomTupleValue.h; sourceTree = "<group>"; };
59435947
E393ADD71FE702CC0022D681 /* WeakMapImplInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapImplInlines.h; sourceTree = "<group>"; };
5948+
E3952C102F1DDF5700F5BEE8 /* B3WasmStructFieldValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = B3WasmStructFieldValue.h; path = b3/B3WasmStructFieldValue.h; sourceTree = "<group>"; };
5949+
E3952C112F1DDF5700F5BEE8 /* B3WasmStructFieldValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = B3WasmStructFieldValue.cpp; path = b3/B3WasmStructFieldValue.cpp; sourceTree = "<group>"; };
5950+
E3952C122F1DDF5700F5BEE8 /* B3WasmStructGetValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = B3WasmStructGetValue.h; path = b3/B3WasmStructGetValue.h; sourceTree = "<group>"; };
5951+
E3952C132F1DDF5700F5BEE8 /* B3WasmStructGetValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = B3WasmStructGetValue.cpp; path = b3/B3WasmStructGetValue.cpp; sourceTree = "<group>"; };
5952+
E3952C142F1DDF5700F5BEE8 /* B3WasmStructNewValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = B3WasmStructNewValue.h; path = b3/B3WasmStructNewValue.h; sourceTree = "<group>"; };
5953+
E3952C152F1DDF5700F5BEE8 /* B3WasmStructNewValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = B3WasmStructNewValue.cpp; path = b3/B3WasmStructNewValue.cpp; sourceTree = "<group>"; };
5954+
E3952C162F1DDF5700F5BEE8 /* B3WasmStructSetValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = B3WasmStructSetValue.h; path = b3/B3WasmStructSetValue.h; sourceTree = "<group>"; };
5955+
E3952C172F1DDF5700F5BEE8 /* B3WasmStructSetValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = B3WasmStructSetValue.cpp; path = b3/B3WasmStructSetValue.cpp; sourceTree = "<group>"; };
59445956
E3963CEC1B73F75000EB4CE5 /* NodesAnalyzeModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NodesAnalyzeModule.cpp; sourceTree = "<group>"; };
59455957
E39BF39822A2288B00BD183E /* SymbolTableInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SymbolTableInlines.h; sourceTree = "<group>"; };
59465958
E39D8B2C23021E1E00265852 /* WasmOperations.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmOperations.cpp; sourceTree = "<group>"; };
@@ -6919,6 +6931,14 @@
69196931
53D444DB1DAF08AB00B92784 /* B3WasmAddressValue.h */,
69206932
5341FC6F1DAC33E500E7E4D7 /* B3WasmBoundsCheckValue.cpp */,
69216933
5341FC711DAC343C00E7E4D7 /* B3WasmBoundsCheckValue.h */,
6934+
E3952C112F1DDF5700F5BEE8 /* B3WasmStructFieldValue.cpp */,
6935+
E3952C102F1DDF5700F5BEE8 /* B3WasmStructFieldValue.h */,
6936+
E3952C132F1DDF5700F5BEE8 /* B3WasmStructGetValue.cpp */,
6937+
E3952C122F1DDF5700F5BEE8 /* B3WasmStructGetValue.h */,
6938+
E3952C152F1DDF5700F5BEE8 /* B3WasmStructNewValue.cpp */,
6939+
E3952C142F1DDF5700F5BEE8 /* B3WasmStructNewValue.h */,
6940+
E3952C172F1DDF5700F5BEE8 /* B3WasmStructSetValue.cpp */,
6941+
E3952C162F1DDF5700F5BEE8 /* B3WasmStructSetValue.h */,
69226942
0F2C63AD1E60AE3C00C13839 /* B3Width.cpp */,
69236943
0F2C63AE1E60AE3D00C13839 /* B3Width.h */,
69246944
5C3A77BB22F24890003827FF /* testb3.h */,
@@ -10889,6 +10909,10 @@
1088910909
0F2BBD9A1C5FF3F50023EF23 /* B3VariableValue.h in Headers */,
1089010910
53D444DC1DAF08AB00B92784 /* B3WasmAddressValue.h in Headers */,
1089110911
5341FC721DAC343C00E7E4D7 /* B3WasmBoundsCheckValue.h in Headers */,
10912+
E3952C1A2F1DDF5700F5BEE8 /* B3WasmStructFieldValue.h in Headers */,
10913+
E3952C182F1DDF5700F5BEE8 /* B3WasmStructGetValue.h in Headers */,
10914+
E3952C192F1DDF5700F5BEE8 /* B3WasmStructNewValue.h in Headers */,
10915+
E3952C1B2F1DDF5700F5BEE8 /* B3WasmStructSetValue.h in Headers */,
1089210916
0F2C63B21E60AE4700C13839 /* B3Width.h in Headers */,
1089310917
52DD000826E039B90054E408 /* BaselineJITCode.h in Headers */,
1089410918
723998F7265DBCDB0057867F /* BaselineJITPlan.h in Headers */,

‎Source/JavaScriptCore/Sources.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ b3/B3VariableLiveness.cpp
195195
b3/B3VariableValue.cpp
196196
b3/B3WasmAddressValue.cpp
197197
b3/B3WasmBoundsCheckValue.cpp
198+
b3/B3WasmStructFieldValue.cpp
199+
b3/B3WasmStructGetValue.cpp
200+
b3/B3WasmStructNewValue.cpp
201+
b3/B3WasmStructSetValue.cpp
198202
b3/B3Width.cpp
199203

200204
builtins/BuiltinExecutables.cpp

‎Source/JavaScriptCore/b3/B3AbstractHeapRepository.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ void AbstractHeapRepository::decorateFencedAccess(const AbstractHeap* heap, Valu
158158
m_heapForFencedAccess.append(HeapForValue(heap, value));
159159
}
160160

161+
void AbstractHeapRepository::decorateWasmStructGet(const AbstractHeap* heap, Value* value)
162+
{
163+
m_heapForWasmStructGet.append(HeapForValue(heap, value));
164+
}
165+
166+
void AbstractHeapRepository::decorateWasmStructSet(const AbstractHeap* heap, Value* value)
167+
{
168+
m_heapForWasmStructSet.append(HeapForValue(heap, value));
169+
}
170+
161171
void AbstractHeapRepository::computeRangesAndDecorateInstructions()
162172
{
163173
root.compute();
@@ -195,6 +205,14 @@ void AbstractHeapRepository::computeRangesAndDecorateInstructions()
195205
entry.value->as<FenceValue>()->write = rangeFor(entry.heap);
196206
for (HeapForValue entry : m_heapForFencedAccess)
197207
entry.value->as<MemoryValue>()->setFenceRange(rangeFor(entry.heap));
208+
for (HeapForValue entry : m_heapForWasmStructGet) {
209+
auto* wasmStructGet = entry.value->as<WasmStructGetValue>();
210+
wasmStructGet->setRange(rangeFor(entry.heap));
211+
}
212+
for (HeapForValue entry : m_heapForWasmStructSet) {
213+
auto* wasmStructSet = entry.value->as<WasmStructSetValue>();
214+
wasmStructSet->setRange(rangeFor(entry.heap));
215+
}
198216
}
199217

200218
} // namespace JSC::B3

‎Source/JavaScriptCore/b3/B3AbstractHeapRepository.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ class AbstractHeapRepository {
347347
void decorateFenceRead(const AbstractHeap*, Value*);
348348
void decorateFenceWrite(const AbstractHeap*, Value*);
349349
void decorateFencedAccess(const AbstractHeap*, Value*);
350+
void decorateWasmStructGet(const AbstractHeap*, Value*);
351+
void decorateWasmStructSet(const AbstractHeap*, Value*);
350352

351353
void computeRangesAndDecorateInstructions();
352354

@@ -375,6 +377,8 @@ class AbstractHeapRepository {
375377
Vector<HeapForValue> m_heapForFenceRead;
376378
Vector<HeapForValue> m_heapForFenceWrite;
377379
Vector<HeapForValue> m_heapForFencedAccess;
380+
Vector<HeapForValue> m_heapForWasmStructGet;
381+
Vector<HeapForValue> m_heapForWasmStructSet;
378382
};
379383

380384
} // namespace JSC::B3

0 commit comments

Comments
 (0)