@@ -713,7 +713,14 @@ class ExceptionHandlerTrampolineBuilder {
713713class MaglevCodeGeneratingNodeProcessor {
714714 public:
715715 MaglevCodeGeneratingNodeProcessor (MaglevAssembler* masm, Zone* zone)
716- : masm_(masm), zone_(zone) {}
716+ : masm_(masm),
717+ zone_ (zone),
718+ // Cache for faster check.
719+ collect_source_positions_(masm->code_gen_state ()
720+ ->compilation_info()
721+ ->collect_source_positions()) {
722+ DCHECK_IMPLIES (collect_source_positions_, graph_labeller () != nullptr );
723+ }
717724
718725 void PreProcessGraph (Graph* graph) {
719726 // TODO(victorgomes): I wonder if we want to create a struct that shares
@@ -807,6 +814,15 @@ class MaglevCodeGeneratingNodeProcessor {
807814 << PrintNode (node);
808815 __ RecordComment (ss.str ());
809816 }
817+ if (collect_source_positions_) {
818+ // TODO(leszeks): Consider collecting source position in a more memory
819+ // friendly way, if we don't need the whole graph labeller.
820+ const auto & provenance = graph_labeller ()->GetNodeProvenance (node);
821+ if (provenance.position .IsKnown ()) {
822+ code_gen_state ()->source_position_table_builder ()->AddPosition (
823+ masm_->pc_offset (), provenance.position , false );
824+ }
825+ }
810826
811827 if (v8_flags.maglev_assert_stack_size ) {
812828 __ AssertStackSizeCorrect ();
@@ -1113,6 +1129,7 @@ class MaglevCodeGeneratingNodeProcessor {
11131129 }
11141130 MaglevAssembler* const masm_;
11151131 Zone* zone_;
1132+ bool collect_source_positions_;
11161133};
11171134
11181135class SafepointingNodeProcessor {
@@ -1713,8 +1730,9 @@ MaglevCodeGenerator::MaglevCodeGenerator(
17131730 safepoint_table_builder_(compilation_info->zone (),
17141731 graph->tagged_stack_slots()),
17151732 frame_translation_builder_(compilation_info->zone ()),
1733+ source_position_table_builder_(compilation_info->zone ()),
17161734 code_gen_state_(compilation_info, &safepoint_table_builder_,
1717- graph->max_block_id ()),
1735+ &source_position_table_builder_, graph->max_block_id ()),
17181736 masm_(isolate->GetMainThreadIsolateUnsafe (), compilation_info->zone(),
17191737 &code_gen_state_),
17201738 graph_(graph),
@@ -1953,6 +1971,10 @@ MaybeHandle<Code> MaglevCodeGenerator::BuildCodeObject(
19531971 LocalIsolate* local_isolate) {
19541972 if (!code_gen_succeeded_) return {};
19551973
1974+ // Allocate the source position table.
1975+ Handle<TrustedByteArray> source_positions =
1976+ source_position_table_builder_.ToSourcePositionTable (local_isolate);
1977+
19561978 Handle<DeoptimizationData> deopt_data =
19571979 (v8_flags.maglev_deopt_data_on_background &&
19581980 !v8_flags.maglev_build_code_on_background )
@@ -1968,7 +1990,7 @@ MaybeHandle<Code> MaglevCodeGenerator::BuildCodeObject(
19681990 .set_stack_slots (stack_slot_count_with_fixed_frame ())
19691991 .set_parameter_count (parameter_count ())
19701992 .set_deoptimization_data (deopt_data)
1971- .set_empty_source_position_table ( )
1993+ .set_source_position_table (source_positions )
19721994 .set_inlined_bytecode_size (
19731995 graph_->total_inlined_bytecode_size () +
19741996 graph_->total_inlined_bytecode_size_small ())
0 commit comments