Commit 7fce6dec authored by Tobias Tebbi's avatar Tobias Tebbi Committed by V8 LUCI CQ

[turboshaft] performance tweak: source positions only if needed

Change-Id: I2a35ae0d07bcd5c570bcaae8ae6ef886a5b5e926
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3852484Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83185}
parent 6b13d258
......@@ -32,11 +32,16 @@ SourcePositionTable::SourcePositionTable(Graph* graph)
void SourcePositionTable::AddDecorator() {
DCHECK_NULL(decorator_);
if (!enabled_) return;
decorator_ = graph_->zone()->New<Decorator>(this);
graph_->AddDecorator(decorator_);
}
void SourcePositionTable::RemoveDecorator() {
if (!enabled_) {
DCHECK_NULL(decorator_);
return;
}
DCHECK_NOT_NULL(decorator_);
graph_->RemoveDecorator(decorator_);
decorator_ = nullptr;
......@@ -51,6 +56,7 @@ SourcePosition SourcePositionTable::GetSourcePosition(NodeId id) const {
void SourcePositionTable::SetSourcePosition(Node* node,
SourcePosition position) {
DCHECK(IsEnabled());
table_.Set(node, position);
}
......
......@@ -57,6 +57,10 @@ class V8_EXPORT_PRIVATE SourcePositionTable final
}
SourcePosition GetCurrentPosition() const { return current_position_; }
void Disable() { enabled_ = false; }
bool IsEnabled() const { return enabled_; }
void PrintJson(std::ostream& os) const;
private:
......@@ -70,6 +74,7 @@ class V8_EXPORT_PRIVATE SourcePositionTable final
Decorator* decorator_;
SourcePosition current_position_;
NodeAuxData<SourcePosition, UnknownSourcePosition> table_;
bool enabled_ = true;
};
} // namespace compiler
......
......@@ -2799,7 +2799,9 @@ void PipelineImpl::InitializeHeapBroker() {
TurboCfgFile tcf(isolate());
tcf << AsC1VCompilation(info());
}
if (data->info()->bytecode_array()->SourcePositionTable().DataSize() == 0) {
data->source_positions()->Disable();
}
data->source_positions()->AddDecorator();
if (data->info()->trace_turbo_json()) {
data->node_origins()->AddDecorator();
......
......@@ -224,7 +224,7 @@ base::Optional<BailoutReason> GraphBuilder::Run() {
DCHECK_NULL(assembler.current_block());
}
if (source_positions) {
if (source_positions->IsEnabled()) {
for (OpIndex index : assembler.graph().AllOperationIndices()) {
compiler::NodeId origin =
assembler.graph().operation_origins()[index].DecodeTurbofanNodeId();
......
......@@ -156,7 +156,7 @@ void ScheduleBuilder::ProcessOperation(const Operation& op) {
OpIndex index = input_graph.Index(op);
DCHECK_LT(index.id(), nodes.size());
nodes[index.id()] = node;
if (source_positions && node) {
if (source_positions->IsEnabled() && node) {
source_positions->SetSourcePosition(node,
input_graph.source_positions()[index]);
}
......
......@@ -1247,6 +1247,8 @@ static void TickLines(bool optimize) {
i::Isolate* isolate = CcTest::i_isolate();
i::Factory* factory = isolate->factory();
i::HandleScope scope(isolate);
// Ensure that source positions are collected everywhere.
isolate->SetIsProfiling(true);
base::EmbeddedVector<char, 512> script;
base::EmbeddedVector<char, 64> prepare_opt;
......@@ -1850,6 +1852,8 @@ TEST(Inlining) {
v8::Local<v8::Context> env = CcTest::NewContext({PROFILER_EXTENSION_ID});
v8::Context::Scope context_scope(env);
ProfilerHelper helper(env);
// Ensure that source positions are collected everywhere.
CcTest::i_isolate()->SetIsProfiling(true);
CompileRun(inlining_test_source);
v8::Local<v8::Function> function = GetFunction(env, "start");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment