@@ -1355,7 +1355,7 @@ class FeedbackMaker {
13551355 void AddCallRefCandidate (Tagged<WasmFuncRef> funcref, int count) {
13561356 Tagged<WasmInternalFunction> internal_function =
13571357 Cast<WasmFuncRef>(funcref)->internal (isolate_);
1358- // Only consider wasm function declared in this instance.
1358+ // Discard cross-instance calls, as we can only inline same- instance code .
13591359 if (internal_function->implicit_arg () != instance_data_) {
13601360 has_non_inlineable_targets_ = true ;
13611361 return ;
@@ -1368,7 +1368,16 @@ class FeedbackMaker {
13681368 AddCall (internal_function->function_index (), count);
13691369 }
13701370
1371- void AddCallIndirectCandidate (Tagged<Smi> target_truncated_smi, int count) {
1371+ void AddCallIndirectCandidate (Tagged<Object> target_truncated_obj,
1372+ int count) {
1373+ // Discard cross-instance calls, as we can only inline same-instance code.
1374+ bool is_cross_instance_call = IsUndefined (target_truncated_obj);
1375+ if (is_cross_instance_call) {
1376+ has_non_inlineable_targets_ = true ;
1377+ return ;
1378+ }
1379+ Tagged<Smi> target_truncated_smi = Cast<Smi>(target_truncated_obj);
1380+
13721381 // We need to map a truncated call target back to a function index.
13731382 // Generally there may be multiple jump tables if code spaces are far apart
13741383 // (to ensure that direct calls can always use a near call to the closest
@@ -1494,21 +1503,22 @@ void TransitiveTypeFeedbackProcessor::ProcessFunction(int func_index) {
14941503
14951504 // For each entry in {call_targets}, there are two {Object} slots in the
14961505 // {feedback} vector:
1506+ // +--------------------------+-----------------------+-------------------+
1507+ // | Call Type | Feedback: Entry 1 | Entry 2 |
14971508 // +-------------------------+-----------------------+-------------------+
1498- // | Call Type | Feedback: Entry 1 | Entry 2 |
1499- // +-------------------------+-----------------------+-------------------+
1500- // | direct | Smi(count) | Smi(0), unused |
1501- // +-------------------------+-----------------------+-------------------+
1502- // | ref, uninitialized | Smi(0) | Smi(0) |
1503- // | ref, monomorphic | WasmFuncRef(target) | Smi(count>0) |
1504- // | ref, polymorphic | FixedArray | Undefined |
1505- // | ref, megamorphic | MegamorphicSymbol | Undefined |
1506- // +-------------------------+-----------------------+-------------------+
1507- // | indirect, uninitialized | Smi(0) | Smi(0) |
1508- // | indirect, monomorphic | Smi(truncated_target) | Smi(count>0) |
1509- // | indirect, polymorphic | FixedArray | Undefined |
1510- // | indirect, megamorphic | MegamorphicSymbol | Undefined |
1511- // +-------------------------+-----------------------+-------------------+
1509+ // | direct | Smi(count) | Smi(0), unused |
1510+ // +--------------------------+-----------------------+-------------------+
1511+ // | ref, uninitialized | Smi(0) | Smi(0) |
1512+ // | ref, monomorphic | WasmFuncRef(target) | Smi(count>0) |
1513+ // | ref, polymorphic | FixedArray | Undefined |
1514+ // | ref, megamorphic | MegamorphicSymbol | Undefined |
1515+ // +--------------------------+-----------------------+-------------------+
1516+ // | indirect, uninitialized | Smi(0) | Smi(0) |
1517+ // | indirect, monomorphic | Smi(truncated_target) | Smi(count>0) |
1518+ // | indirect, wrong instance | Undefined | Smi(count>0) |
1519+ // | indirect, polymorphic | FixedArray | Undefined |
1520+ // | indirect, megamorphic | MegamorphicSymbol | Undefined |
1521+ // +--------------------------+-----------------------+-------------------+
15121522 // The FixedArray entries for the polymorphic cases look like the monomorphic
15131523 // entries in the feedback vector itself.
15141524 // See {UpdateCallRefOrIndirectIC} in {wasm.tq} for how this is written.
@@ -1543,11 +1553,11 @@ void TransitiveTypeFeedbackProcessor::ProcessFunction(int func_index) {
15431553 DCHECK_EQ (sentinel_or_target, FunctionTypeFeedback::kCallRef );
15441554 int count = Smi::ToInt (second_slot);
15451555 fm.AddCallRefCandidate (Cast<WasmFuncRef>(first_slot), count);
1546- } else if (IsSmi (first_slot)) {
1556+ } else if (IsSmi (first_slot) || IsUndefined (first_slot) ) {
15471557 // Monomorphic call_indirect.
15481558 DCHECK_EQ (sentinel_or_target, FunctionTypeFeedback::kCallIndirect );
15491559 int count = Smi::ToInt (second_slot);
1550- fm.AddCallIndirectCandidate (Cast<Smi>( first_slot) , count);
1560+ fm.AddCallIndirectCandidate (first_slot, count);
15511561 } else if (IsFixedArray (first_slot)) {
15521562 // Polymorphic call_ref or call_indirect.
15531563 Tagged<FixedArray> polymorphic = Cast<FixedArray>(first_slot);
@@ -1563,7 +1573,7 @@ void TransitiveTypeFeedbackProcessor::ProcessFunction(int func_index) {
15631573 } else {
15641574 DCHECK_EQ (sentinel_or_target, FunctionTypeFeedback::kCallIndirect );
15651575 for (int j = 0 ; j < checked_polymorphic_length; j += 2 ) {
1566- Tagged<Smi > target = Cast<Smi>( polymorphic->get (j) );
1576+ Tagged<Object > target = polymorphic->get (j);
15671577 int count = Smi::ToInt (polymorphic->get (j + 1 ));
15681578 fm.AddCallIndirectCandidate (target, count);
15691579 }
0 commit comments