@@ -1938,6 +1938,19 @@ ExternalReference convert_ccall_ref(WasmGraphBuilder* builder,
19381938 }
19391939}
19401940
1941+ template <typename BuiltinDescriptor>
1942+ CallDescriptor* GetBuiltinCallDescriptor (WasmGraphBuilder* builder,
1943+ StubCallMode stub_mode) {
1944+ BuiltinDescriptor interface_descriptor;
1945+ return Linkage::GetStubCallDescriptor (
1946+ builder->mcgraph ()->zone (), // zone
1947+ interface_descriptor, // descriptor
1948+ interface_descriptor.GetStackParameterCount (), // stack parameter count
1949+ CallDescriptor::kNoFlags , // flags
1950+ Operator::kNoProperties , // properties
1951+ stub_mode); // stub call mode
1952+ }
1953+
19411954} // namespace
19421955
19431956Node* WasmGraphBuilder::BuildCcallConvertFloat (Node* input,
@@ -3348,114 +3361,32 @@ Node* WasmGraphBuilder::GlobalSet(uint32_t index, Node* val) {
33483361 graph ()->NewNode (op, base, offset, val, effect (), control ()));
33493362}
33503363
3351- void WasmGraphBuilder::BoundsCheckTable (uint32_t table_index, Node* entry_index,
3352- wasm::WasmCodePosition position,
3353- wasm::TrapReason trap_reason,
3354- Node** base_node) {
3355- Node* tables = LOAD_INSTANCE_FIELD (Tables, MachineType::TaggedPointer ());
3356- Node* table = LOAD_FIXED_ARRAY_SLOT_ANY (tables, table_index);
3357-
3358- int length_field_size = WasmTableObject::kCurrentLengthOffsetEnd -
3359- WasmTableObject::kCurrentLengthOffset + 1 ;
3360- Node* length_smi = gasm_->Load (
3361- assert_size (length_field_size, MachineType::TaggedSigned ()), table,
3362- wasm::ObjectAccess::ToTagged (WasmTableObject::kCurrentLengthOffset ));
3363- Node* length = BuildChangeSmiToInt32 (length_smi);
3364-
3365- // Bounds check against the table size.
3366- Node* in_bounds = graph ()->NewNode (mcgraph ()->machine ()->Uint32LessThan (),
3367- entry_index, length);
3368- TrapIfFalse (trap_reason, in_bounds, position);
3369-
3370- if (base_node) {
3371- int storage_field_size = WasmTableObject::kEntriesOffsetEnd -
3372- WasmTableObject::kEntriesOffset + 1 ;
3373- *base_node = gasm_->Load (
3374- assert_size (storage_field_size, MachineType::TaggedPointer ()), table,
3375- wasm::ObjectAccess::ToTagged (WasmTableObject::kEntriesOffset ));
3376- }
3377- }
3378-
3379- void WasmGraphBuilder::GetTableBaseAndOffset (uint32_t table_index,
3380- Node* entry_index,
3381- wasm::WasmCodePosition position,
3382- Node** base_node,
3383- Node** offset_node) {
3384- BoundsCheckTable (table_index, entry_index, position,
3385- wasm::kTrapTableOutOfBounds , base_node);
3386- // From the index, calculate the actual offset in the FixeArray. This
3387- // is kHeaderSize + (index * kTaggedSize). kHeaderSize can be acquired with
3388- // wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0).
3389- Node* index_times_tagged_size = graph ()->NewNode (
3390- mcgraph ()->machine ()->IntMul (), Uint32ToUintptr (entry_index),
3391- mcgraph ()->Int32Constant (kTaggedSize ));
3392-
3393- *offset_node = graph ()->NewNode (
3394- mcgraph ()->machine ()->IntAdd (), index_times_tagged_size,
3395- mcgraph ()->IntPtrConstant (
3396- wasm::ObjectAccess::ElementOffsetInTaggedFixedArray (0 )));
3397- }
3398-
33993364Node* WasmGraphBuilder::TableGet (uint32_t table_index, Node* index,
34003365 wasm::WasmCodePosition position) {
3401- if (env_->module ->tables [table_index].type == wasm::kWasmAnyRef ||
3402- env_->module ->tables [table_index].type == wasm::kWasmNullRef ||
3403- env_->module ->tables [table_index].type == wasm::kWasmExnRef ) {
3404- Node* base = nullptr ;
3405- Node* offset = nullptr ;
3406- GetTableBaseAndOffset (table_index, index, position, &base, &offset);
3407- return gasm_->Load (MachineType::AnyTagged (), base, offset);
3408- }
3409- // We access funcref tables through runtime calls.
3410- WasmTableGetDescriptor interface_descriptor;
3411- auto call_descriptor = Linkage::GetStubCallDescriptor (
3412- mcgraph ()->zone (), // zone
3413- interface_descriptor, // descriptor
3414- interface_descriptor.GetStackParameterCount (), // stack parameter count
3415- CallDescriptor::kNoFlags , // flags
3416- Operator::kNoProperties , // properties
3417- StubCallMode::kCallWasmRuntimeStub ); // stub call mode
3366+ auto call_descriptor = GetBuiltinCallDescriptor<WasmTableGetDescriptor>(
3367+ this , StubCallMode::kCallWasmRuntimeStub );
34183368 // A direct call to a wasm runtime stub defined in this module.
34193369 // Just encode the stub index. This will be patched at relocation.
34203370 Node* call_target = mcgraph ()->RelocatableIntPtrConstant (
34213371 wasm::WasmCode::kWasmTableGet , RelocInfo::WASM_STUB_CALL );
34223372
34233373 return SetEffectControl (graph ()->NewNode (
34243374 mcgraph ()->common ()->Call (call_descriptor), call_target,
3425- graph ()->NewNode (mcgraph ()->common ()->NumberConstant (table_index)), index,
3426- effect (), control ()));
3375+ IntPtrConstant (table_index), index, effect (), control ()));
34273376}
34283377
34293378Node* WasmGraphBuilder::TableSet (uint32_t table_index, Node* index, Node* val,
34303379 wasm::WasmCodePosition position) {
3431- if (env_->module ->tables [table_index].type == wasm::kWasmAnyRef ||
3432- env_->module ->tables [table_index].type == wasm::kWasmNullRef ||
3433- env_->module ->tables [table_index].type == wasm::kWasmExnRef ) {
3434- Node* base = nullptr ;
3435- Node* offset = nullptr ;
3436- GetTableBaseAndOffset (table_index, index, position, &base, &offset);
3437- return STORE_RAW_NODE_OFFSET (
3438- base, offset, val, MachineRepresentation::kTagged , kFullWriteBarrier );
3439- } else {
3440- // We access funcref tables through runtime calls.
3441- WasmTableSetDescriptor interface_descriptor;
3442- auto call_descriptor = Linkage::GetStubCallDescriptor (
3443- mcgraph ()->zone (), // zone
3444- interface_descriptor, // descriptor
3445- interface_descriptor.GetStackParameterCount (), // stack parameter count
3446- CallDescriptor::kNoFlags , // flags
3447- Operator::kNoProperties , // properties
3448- StubCallMode::kCallWasmRuntimeStub ); // stub call mode
3449- // A direct call to a wasm runtime stub defined in this module.
3450- // Just encode the stub index. This will be patched at relocation.
3451- Node* call_target = mcgraph ()->RelocatableIntPtrConstant (
3452- wasm::WasmCode::kWasmTableSet , RelocInfo::WASM_STUB_CALL );
3380+ auto call_descriptor = GetBuiltinCallDescriptor<WasmTableSetDescriptor>(
3381+ this , StubCallMode::kCallWasmRuntimeStub );
3382+ // A direct call to a wasm runtime stub defined in this module.
3383+ // Just encode the stub index. This will be patched at relocation.
3384+ Node* call_target = mcgraph ()->RelocatableIntPtrConstant (
3385+ wasm::WasmCode::kWasmTableSet , RelocInfo::WASM_STUB_CALL );
34533386
3454- return SetEffectControl (graph ()->NewNode (
3455- mcgraph ()->common ()->Call (call_descriptor), call_target,
3456- graph ()->NewNode (mcgraph ()->common ()->NumberConstant (table_index)),
3457- index, val, effect (), control ()));
3458- }
3387+ return SetEffectControl (graph ()->NewNode (
3388+ mcgraph ()->common ()->Call (call_descriptor), call_target,
3389+ IntPtrConstant (table_index), index, val, effect (), control ()));
34593390}
34603391
34613392Node* WasmGraphBuilder::CheckBoundsAndAlignment (
@@ -4029,19 +3960,6 @@ Signature<MachineRepresentation>* CreateMachineSignature(
40293960 return builder.Build ();
40303961}
40313962
4032- template <typename BuiltinDescriptor>
4033- CallDescriptor* GetBuiltinCallDescriptor (WasmGraphBuilder* builder,
4034- StubCallMode stub_mode) {
4035- BuiltinDescriptor interface_descriptor;
4036- return Linkage::GetStubCallDescriptor (
4037- builder->mcgraph ()->zone (), // zone
4038- interface_descriptor, // descriptor
4039- interface_descriptor.GetStackParameterCount (), // stack parameter count
4040- CallDescriptor::kNoFlags , // flags
4041- Operator::kNoProperties , // properties
4042- stub_mode); // stub call mode
4043- }
4044-
40453963} // namespace
40463964
40473965void WasmGraphBuilder::AddInt64LoweringReplacement (
0 commit comments