2014-11-03 17:41:53 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/compiler/common-operator.h"
|
This CL enables precise source positions for all V8 compilers. It merges compiler::SourcePosition and internal::SourcePosition to a single class used throughout the codebase. The new internal::SourcePosition instances store an id identifying an inlined function in addition to a script offset.
SourcePosition::InliningId() refers to a the new table DeoptimizationInputData::InliningPositions(), which provides the following data for every inlining id:
- The inlined SharedFunctionInfo as an offset into DeoptimizationInfo::LiteralArray
- The SourcePosition of the inlining. Recursively, this yields the full inlining stack.
Before the Code object is created, the same information can be found in CompilationInfo::inlined_functions().
If SourcePosition::InliningId() is SourcePosition::kNotInlined, it refers to the outer (non-inlined) function.
So every SourcePosition has full information about its inlining stack, as long as the corresponding Code object is known. The internal represenation of a source position is a positive 64bit integer.
All compilers create now appropriate source positions for inlined functions. In the case of Turbofan, this required using AstGraphBuilderWithPositions for inlined functions too. So this class is now moved to a header file.
At the moment, the additional information in source positions is only used in --trace-deopt and --code-comments. The profiler needs to be updated, at the moment it gets the correct script offsets from the deopt info, but the wrong script id from the reconstructed deopt stack, which can lead to wrong outputs. This should be resolved by making the profiler use the new inlining information for deopts.
I activated the inlined deoptimization tests in test-cpu-profiler.cc for Turbofan, changing them to a case where the deopt stack and the inlining position agree. It is currently still broken for other cases.
The following additional changes were necessary:
- The source position table (internal::SourcePositionTableBuilder etc.) supports now 64bit source positions. Encoding source positions in a single 64bit int together with the difference encoding in the source position table results in very little overhead for the inlining id, since only 12% of the source positions in Octane have a changed inlining id.
- The class HPositionInfo was effectively dead code and is now removed.
- SourcePosition has new printing and information facilities, including computing a full inlining stack.
- I had to rename compiler/source-position.{h,cc} to compiler/compiler-source-position-table.{h,cc} to avoid clashes with the new src/source-position.cc file.
- I wrote the new wrapper PodArray for ByteArray. It is a template working with any POD-type. This is used in DeoptimizationInputData::InliningPositions().
- I removed HInlinedFunctionInfo and HGraph::inlined_function_infos, because they were only used for the now obsolete Crankshaft inlining ids.
- Crankshaft managed a list of inlined functions in Lithium: LChunk::inlined_functions. This is an analog structure to CompilationInfo::inlined_functions. So I removed LChunk::inlined_functions and made Crankshaft use CompilationInfo::inlined_functions instead, because this was necessary to register the offsets into the literal array in a uniform way. This is a safe change because LChunk::inlined_functions has no other uses and the functions in CompilationInfo::inlined_functions have a strictly longer lifespan, being created earlier (in Hydrogen already).
BUG=v8:5432
Review-Url: https://codereview.chromium.org/2451853002
Cr-Commit-Position: refs/heads/master@{#40975}
2016-11-14 17:21:37 +00:00
|
|
|
#include "src/compiler/compiler-source-position-table.h"
|
2014-11-03 17:41:53 +00:00
|
|
|
#include "src/compiler/graph-visualizer.h"
|
This CL enables precise source positions for all V8 compilers. It merges compiler::SourcePosition and internal::SourcePosition to a single class used throughout the codebase. The new internal::SourcePosition instances store an id identifying an inlined function in addition to a script offset.
SourcePosition::InliningId() refers to a the new table DeoptimizationInputData::InliningPositions(), which provides the following data for every inlining id:
- The inlined SharedFunctionInfo as an offset into DeoptimizationInfo::LiteralArray
- The SourcePosition of the inlining. Recursively, this yields the full inlining stack.
Before the Code object is created, the same information can be found in CompilationInfo::inlined_functions().
If SourcePosition::InliningId() is SourcePosition::kNotInlined, it refers to the outer (non-inlined) function.
So every SourcePosition has full information about its inlining stack, as long as the corresponding Code object is known. The internal represenation of a source position is a positive 64bit integer.
All compilers create now appropriate source positions for inlined functions. In the case of Turbofan, this required using AstGraphBuilderWithPositions for inlined functions too. So this class is now moved to a header file.
At the moment, the additional information in source positions is only used in --trace-deopt and --code-comments. The profiler needs to be updated, at the moment it gets the correct script offsets from the deopt info, but the wrong script id from the reconstructed deopt stack, which can lead to wrong outputs. This should be resolved by making the profiler use the new inlining information for deopts.
I activated the inlined deoptimization tests in test-cpu-profiler.cc for Turbofan, changing them to a case where the deopt stack and the inlining position agree. It is currently still broken for other cases.
The following additional changes were necessary:
- The source position table (internal::SourcePositionTableBuilder etc.) supports now 64bit source positions. Encoding source positions in a single 64bit int together with the difference encoding in the source position table results in very little overhead for the inlining id, since only 12% of the source positions in Octane have a changed inlining id.
- The class HPositionInfo was effectively dead code and is now removed.
- SourcePosition has new printing and information facilities, including computing a full inlining stack.
- I had to rename compiler/source-position.{h,cc} to compiler/compiler-source-position-table.{h,cc} to avoid clashes with the new src/source-position.cc file.
- I wrote the new wrapper PodArray for ByteArray. It is a template working with any POD-type. This is used in DeoptimizationInputData::InliningPositions().
- I removed HInlinedFunctionInfo and HGraph::inlined_function_infos, because they were only used for the now obsolete Crankshaft inlining ids.
- Crankshaft managed a list of inlined functions in Lithium: LChunk::inlined_functions. This is an analog structure to CompilationInfo::inlined_functions. So I removed LChunk::inlined_functions and made Crankshaft use CompilationInfo::inlined_functions instead, because this was necessary to register the offsets into the literal array in a uniform way. This is a safe change because LChunk::inlined_functions has no other uses and the functions in CompilationInfo::inlined_functions have a strictly longer lifespan, being created earlier (in Hydrogen already).
BUG=v8:5432
Review-Url: https://codereview.chromium.org/2451853002
Cr-Commit-Position: refs/heads/master@{#40975}
2016-11-14 17:21:37 +00:00
|
|
|
#include "src/compiler/graph.h"
|
2014-11-03 17:41:53 +00:00
|
|
|
#include "src/compiler/js-operator.h"
|
|
|
|
#include "src/compiler/machine-operator.h"
|
2018-05-18 14:04:36 +00:00
|
|
|
#include "src/compiler/node-origin-table.h"
|
2014-11-03 17:41:53 +00:00
|
|
|
#include "src/compiler/node.h"
|
|
|
|
#include "src/compiler/operator.h"
|
|
|
|
#include "src/compiler/schedule.h"
|
|
|
|
#include "src/compiler/scheduler.h"
|
|
|
|
#include "src/compiler/verifier.h"
|
2015-10-28 13:32:17 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2014-11-03 17:41:53 +00:00
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-11-03 17:41:53 +00:00
|
|
|
|
2015-09-23 09:08:15 +00:00
|
|
|
static Operator dummy_operator1(IrOpcode::kParameter, Operator::kNoWrite,
|
|
|
|
"dummy", 1, 0, 0, 1, 0, 0);
|
|
|
|
static Operator dummy_operator6(IrOpcode::kParameter, Operator::kNoWrite,
|
|
|
|
"dummy", 6, 0, 0, 1, 0, 0);
|
2015-04-29 14:13:17 +00:00
|
|
|
|
|
|
|
|
2014-11-03 17:41:53 +00:00
|
|
|
TEST(NodeWithNullInputReachableFromEnd) {
|
2020-07-23 10:06:02 +00:00
|
|
|
HandleAndZoneScope scope(kCompressGraphZone);
|
2014-11-03 17:41:53 +00:00
|
|
|
Graph graph(scope.main_zone());
|
|
|
|
CommonOperatorBuilder common(scope.main_zone());
|
|
|
|
|
|
|
|
Node* start = graph.NewNode(common.Start(0));
|
|
|
|
graph.SetStart(start);
|
|
|
|
Node* k = graph.NewNode(common.Int32Constant(0));
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi =
|
|
|
|
graph.NewNode(common.Phi(MachineRepresentation::kTagged, 1), k, start);
|
2017-10-13 16:33:03 +00:00
|
|
|
phi->ReplaceInput(0, nullptr);
|
2014-11-03 17:41:53 +00:00
|
|
|
graph.SetEnd(phi);
|
|
|
|
|
2015-01-29 12:14:55 +00:00
|
|
|
SourcePositionTable table(&graph);
|
2018-05-18 14:04:36 +00:00
|
|
|
NodeOriginTable table2(&graph);
|
2018-06-14 12:46:07 +00:00
|
|
|
StdoutStream{} << AsJSON(graph, &table, &table2);
|
2014-11-03 17:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NodeWithNullControlReachableFromEnd) {
|
2020-07-23 10:06:02 +00:00
|
|
|
HandleAndZoneScope scope(kCompressGraphZone);
|
2014-11-03 17:41:53 +00:00
|
|
|
Graph graph(scope.main_zone());
|
|
|
|
CommonOperatorBuilder common(scope.main_zone());
|
|
|
|
|
|
|
|
Node* start = graph.NewNode(common.Start(0));
|
|
|
|
graph.SetStart(start);
|
|
|
|
Node* k = graph.NewNode(common.Int32Constant(0));
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi =
|
|
|
|
graph.NewNode(common.Phi(MachineRepresentation::kTagged, 1), k, start);
|
2017-10-13 16:33:03 +00:00
|
|
|
phi->ReplaceInput(1, nullptr);
|
2014-11-03 17:41:53 +00:00
|
|
|
graph.SetEnd(phi);
|
|
|
|
|
2015-01-29 12:14:55 +00:00
|
|
|
SourcePositionTable table(&graph);
|
2018-05-18 14:04:36 +00:00
|
|
|
NodeOriginTable table2(&graph);
|
2018-06-14 12:46:07 +00:00
|
|
|
StdoutStream{} << AsJSON(graph, &table, &table2);
|
2014-11-03 17:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NodeWithNullInputReachableFromStart) {
|
2020-07-23 10:06:02 +00:00
|
|
|
HandleAndZoneScope scope(kCompressGraphZone);
|
2014-11-03 17:41:53 +00:00
|
|
|
Graph graph(scope.main_zone());
|
|
|
|
CommonOperatorBuilder common(scope.main_zone());
|
|
|
|
|
|
|
|
Node* start = graph.NewNode(common.Start(0));
|
|
|
|
graph.SetStart(start);
|
|
|
|
Node* k = graph.NewNode(common.Int32Constant(0));
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi =
|
|
|
|
graph.NewNode(common.Phi(MachineRepresentation::kTagged, 1), k, start);
|
2017-10-13 16:33:03 +00:00
|
|
|
phi->ReplaceInput(0, nullptr);
|
2014-11-03 17:41:53 +00:00
|
|
|
graph.SetEnd(start);
|
|
|
|
|
2015-01-29 12:14:55 +00:00
|
|
|
SourcePositionTable table(&graph);
|
2018-05-18 14:04:36 +00:00
|
|
|
NodeOriginTable table2(&graph);
|
2018-06-14 12:46:07 +00:00
|
|
|
StdoutStream{} << AsJSON(graph, &table, &table2);
|
2014-11-03 17:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NodeWithNullControlReachableFromStart) {
|
2020-07-23 10:06:02 +00:00
|
|
|
HandleAndZoneScope scope(kCompressGraphZone);
|
2014-11-03 17:41:53 +00:00
|
|
|
Graph graph(scope.main_zone());
|
|
|
|
CommonOperatorBuilder common(scope.main_zone());
|
|
|
|
|
|
|
|
Node* start = graph.NewNode(common.Start(0));
|
|
|
|
graph.SetStart(start);
|
|
|
|
Node* merge = graph.NewNode(common.Merge(2), start, start);
|
2017-10-13 16:33:03 +00:00
|
|
|
merge->ReplaceInput(1, nullptr);
|
2014-11-03 17:41:53 +00:00
|
|
|
graph.SetEnd(merge);
|
|
|
|
|
2015-01-29 12:14:55 +00:00
|
|
|
SourcePositionTable table(&graph);
|
2018-05-18 14:04:36 +00:00
|
|
|
NodeOriginTable table2(&graph);
|
2018-06-14 12:46:07 +00:00
|
|
|
StdoutStream{} << AsJSON(graph, &table, &table2);
|
2014-11-03 17:41:53 +00:00
|
|
|
}
|
2015-04-29 14:13:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(NodeNetworkOfDummiesReachableFromEnd) {
|
2020-07-23 10:06:02 +00:00
|
|
|
HandleAndZoneScope scope(kCompressGraphZone);
|
2015-04-29 14:13:17 +00:00
|
|
|
Graph graph(scope.main_zone());
|
|
|
|
CommonOperatorBuilder common(scope.main_zone());
|
|
|
|
|
|
|
|
Node* start = graph.NewNode(common.Start(0));
|
|
|
|
graph.SetStart(start);
|
2015-09-23 09:08:15 +00:00
|
|
|
Node* n2 = graph.NewNode(&dummy_operator1, graph.start());
|
|
|
|
Node* n3 = graph.NewNode(&dummy_operator1, graph.start());
|
|
|
|
Node* n4 = graph.NewNode(&dummy_operator1, n2);
|
|
|
|
Node* n5 = graph.NewNode(&dummy_operator1, n2);
|
|
|
|
Node* n6 = graph.NewNode(&dummy_operator1, n3);
|
|
|
|
Node* n7 = graph.NewNode(&dummy_operator1, n3);
|
|
|
|
Node* n8 = graph.NewNode(&dummy_operator1, n5);
|
|
|
|
Node* n9 = graph.NewNode(&dummy_operator1, n5);
|
|
|
|
Node* n10 = graph.NewNode(&dummy_operator1, n9);
|
|
|
|
Node* n11 = graph.NewNode(&dummy_operator1, n9);
|
2015-04-29 14:13:17 +00:00
|
|
|
Node* end_dependencies[6] = {n4, n8, n10, n11, n6, n7};
|
2015-09-23 09:08:15 +00:00
|
|
|
Node* end = graph.NewNode(&dummy_operator6, 6, end_dependencies);
|
2015-04-29 14:13:17 +00:00
|
|
|
graph.SetEnd(end);
|
|
|
|
|
|
|
|
SourcePositionTable table(&graph);
|
2018-05-18 14:04:36 +00:00
|
|
|
NodeOriginTable table2(&graph);
|
2018-06-14 12:46:07 +00:00
|
|
|
StdoutStream{} << AsJSON(graph, &table, &table2);
|
2015-04-29 14:13:17 +00:00
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
2018-05-24 13:45:12 +00:00
|
|
|
TEST(TestSourceIdAssigner) {
|
|
|
|
Handle<SharedFunctionInfo> shared1;
|
|
|
|
Handle<SharedFunctionInfo> shared2;
|
|
|
|
|
|
|
|
SourceIdAssigner assigner(2);
|
|
|
|
const int source_id1 = assigner.GetIdFor(shared1);
|
|
|
|
const int source_id2 = assigner.GetIdFor(shared2);
|
|
|
|
|
|
|
|
CHECK_EQ(source_id1, source_id2);
|
|
|
|
CHECK_EQ(source_id1, assigner.GetIdAt(0));
|
|
|
|
CHECK_EQ(source_id2, assigner.GetIdAt(1));
|
|
|
|
}
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|