Commit f30b53bd authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[nci] Add native_context_independent flags

... to OptimizedCompilationInfo, BytecodeGraphBuilder, and
JSHeapBroker.

Also add first uses of these flags in pipeline.cc by skipping certain
phases when nci is enabled. With this change, tests in the NCI variant
will start to fail since generic lowering is not fully implemented.
These implementations will follow incrementally in the next days.

Bug: v8:8888
Change-Id: I3f570fb92f09059d1f1f4015f88ffe80ccf746ad
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2239572
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68339}
parent 340c5458
......@@ -19,7 +19,7 @@ namespace internal {
OptimizedCompilationInfo::OptimizedCompilationInfo(
Zone* zone, Isolate* isolate, Handle<SharedFunctionInfo> shared,
Handle<JSFunction> closure)
Handle<JSFunction> closure, bool native_context_independent)
: OptimizedCompilationInfo(Code::OPTIMIZED_FUNCTION, zone) {
DCHECK_EQ(*shared, closure->shared());
DCHECK(shared->is_compiled());
......@@ -35,6 +35,7 @@ OptimizedCompilationInfo::OptimizedCompilationInfo(
set_source_positions();
}
if (native_context_independent) set_native_context_independent();
SetTracingFlags(shared->PassesFilter(FLAG_trace_turbo_filter));
}
......
......@@ -67,7 +67,8 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
V(WasmRuntimeExceptionSupport, wasm_runtime_exception_support, 18) \
V(TurboControlFlowAwareAllocation, turbo_control_flow_aware_allocation, 19) \
V(TurboPreprocessRanges, turbo_preprocess_ranges, 20) \
V(ConcurrentInlining, concurrent_inlining, 21)
V(ConcurrentInlining, concurrent_inlining, 21) \
V(NativeContextIndependent, native_context_independent, 22)
enum Flag {
#define DEF_ENUM(Camel, Lower, Bit) k##Camel = 1 << Bit,
......@@ -99,7 +100,8 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
// Construct a compilation info for optimized compilation.
OptimizedCompilationInfo(Zone* zone, Isolate* isolate,
Handle<SharedFunctionInfo> shared,
Handle<JSFunction> closure);
Handle<JSFunction> closure,
bool native_context_independent);
// Construct a compilation info for stub compilation, Wasm, and testing.
OptimizedCompilationInfo(Vector<const char> debug_name, Zone* zone,
Code::Kind code_kind);
......
......@@ -33,6 +33,7 @@ enum class BytecodeGraphBuilderFlag : uint8_t {
// bytecode analysis.
kAnalyzeEnvironmentLiveness = 1 << 1,
kBailoutOnUninitialized = 1 << 2,
kNativeContextIndependent = 1 << 3,
};
using BytecodeGraphBuilderFlags = base::Flags<BytecodeGraphBuilderFlag>;
......
......@@ -2385,7 +2385,8 @@ base::Optional<ObjectRef> ContextRef::get(int index,
}
JSHeapBroker::JSHeapBroker(Isolate* isolate, Zone* broker_zone,
bool tracing_enabled, bool is_concurrent_inlining)
bool tracing_enabled, bool is_concurrent_inlining,
bool is_native_context_independent)
: isolate_(isolate),
zone_(broker_zone),
refs_(new (zone())
......@@ -2394,6 +2395,7 @@ JSHeapBroker::JSHeapBroker(Isolate* isolate, Zone* broker_zone,
array_and_object_prototypes_(zone()),
tracing_enabled_(tracing_enabled),
is_concurrent_inlining_(is_concurrent_inlining),
is_native_context_independent_(is_native_context_independent),
feedback_(zone()),
bytecode_analyses_(zone()),
property_access_infos_(zone()),
......
......@@ -74,7 +74,13 @@ struct PropertyAccessTarget {
class V8_EXPORT_PRIVATE JSHeapBroker {
public:
JSHeapBroker(Isolate* isolate, Zone* broker_zone, bool tracing_enabled,
bool is_concurrent_inlining);
bool is_concurrent_inlining, bool is_native_context_independent);
// For use only in tests, sets default values for some arguments. Avoids
// churn when new flags are added.
JSHeapBroker(Isolate* isolate, Zone* broker_zone)
: JSHeapBroker(isolate, broker_zone, FLAG_trace_heap_broker, false,
false) {}
// The compilation target's native context. We need the setter because at
// broker construction time we don't yet have the canonical handle.
......@@ -89,6 +95,9 @@ class V8_EXPORT_PRIVATE JSHeapBroker {
Zone* zone() const { return zone_; }
bool tracing_enabled() const { return tracing_enabled_; }
bool is_concurrent_inlining() const { return is_concurrent_inlining_; }
bool is_native_context_independent() const {
return is_native_context_independent_;
}
enum BrokerMode { kDisabled, kSerializing, kSerialized, kRetired };
BrokerMode mode() const { return mode_; }
......@@ -242,6 +251,7 @@ class V8_EXPORT_PRIVATE JSHeapBroker {
BrokerMode mode_ = kDisabled;
bool const tracing_enabled_;
bool const is_concurrent_inlining_;
bool const is_native_context_independent_;
unsigned trace_indentation_ = 0;
PerIsolateCompilerCache* compiler_cache_ = nullptr;
ZoneUnorderedMap<FeedbackSource, ProcessedFeedback const*,
......
......@@ -150,9 +150,9 @@ class PipelineData {
instruction_zone_(instruction_zone_scope_.zone()),
codegen_zone_scope_(zone_stats_, kCodegenZoneName),
codegen_zone_(codegen_zone_scope_.zone()),
broker_(new JSHeapBroker(isolate_, info_->zone(),
info_->trace_heap_broker(),
is_concurrent_inlining)),
broker_(new JSHeapBroker(
isolate_, info_->zone(), info_->trace_heap_broker(),
is_concurrent_inlining, info->native_context_independent())),
register_allocation_zone_scope_(zone_stats_,
kRegisterAllocationZoneName),
register_allocation_zone_(register_allocation_zone_scope_.zone()),
......@@ -1008,7 +1008,8 @@ PipelineCompilationJob::PipelineCompilationJob(
zone_(function->GetIsolate()->allocator(),
kPipelineCompilationJobZoneName),
zone_stats_(function->GetIsolate()->allocator()),
compilation_info_(&zone_, function->GetIsolate(), shared_info, function),
compilation_info_(&zone_, function->GetIsolate(), shared_info, function,
FLAG_turbo_nci),
pipeline_statistics_(CreatePipelineStatistics(
handle(Script::cast(shared_info->script()), isolate),
compilation_info(), function->GetIsolate(), &zone_stats_)),
......@@ -1051,13 +1052,14 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl(
return AbortOptimization(BailoutReason::kFunctionTooBig);
}
if (!FLAG_always_opt) {
if (!FLAG_always_opt && !compilation_info()->native_context_independent()) {
compilation_info()->set_bailout_on_uninitialized();
}
if (FLAG_turbo_loop_peeling) {
compilation_info()->set_loop_peeling();
}
if (FLAG_turbo_inlining) {
if (FLAG_turbo_inlining &&
!compilation_info()->native_context_independent()) {
compilation_info()->set_inlining();
}
......@@ -1340,6 +1342,9 @@ struct GraphBuilderPhase {
if (data->info()->bailout_on_uninitialized()) {
flags |= BytecodeGraphBuilderFlag::kBailoutOnUninitialized;
}
if (data->info()->native_context_independent()) {
flags |= BytecodeGraphBuilderFlag::kNativeContextIndependent;
}
JSFunctionRef closure(data->broker(), data->info()->closure());
CallFrequency frequency(1.0f);
......@@ -1397,8 +1402,10 @@ struct InliningPhase {
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &checkpoint_elimination);
AddReducer(data, &graph_reducer, &common_reducer);
AddReducer(data, &graph_reducer, &native_context_specialization);
AddReducer(data, &graph_reducer, &context_specialization);
if (!data->info()->native_context_independent()) {
AddReducer(data, &graph_reducer, &native_context_specialization);
AddReducer(data, &graph_reducer, &context_specialization);
}
AddReducer(data, &graph_reducer, &intrinsic_lowering);
AddReducer(data, &graph_reducer, &call_reducer);
if (data->info()->inlining()) {
......@@ -1538,7 +1545,9 @@ struct TypedLoweringPhase {
data->broker(), data->common(),
data->machine(), temp_zone);
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &create_lowering);
if (!data->info()->native_context_independent()) {
AddReducer(data, &graph_reducer, &create_lowering);
}
AddReducer(data, &graph_reducer, &constant_folding_reducer);
AddReducer(data, &graph_reducer, &typed_lowering);
AddReducer(data, &graph_reducer, &typed_optimization);
......
......@@ -244,6 +244,8 @@ HandleAndZoneScope::HandleAndZoneScope()
HandleAndZoneScope::~HandleAndZoneScope() = default;
static constexpr bool kNativeContextDependent = false;
i::Handle<i::JSFunction> Optimize(
i::Handle<i::JSFunction> function, i::Zone* zone, i::Isolate* isolate,
uint32_t flags, std::unique_ptr<i::compiler::JSHeapBroker>* out_broker) {
......@@ -255,7 +257,8 @@ i::Handle<i::JSFunction> Optimize(
CHECK_NOT_NULL(zone);
i::OptimizedCompilationInfo info(zone, isolate, shared, function);
i::OptimizedCompilationInfo info(zone, isolate, shared, function,
kNativeContextDependent);
if (flags & i::OptimizedCompilationInfo::kInlining) {
info.set_inlining();
......
......@@ -145,12 +145,15 @@ Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
return Optimize(function, &zone, isolate, flags_);
}
static constexpr bool kNativeContextDependent = false;
// Compile the given machine graph instead of the source of the function
// and replace the JSFunction's code with the result.
Handle<JSFunction> FunctionTester::CompileGraph(Graph* graph) {
Handle<SharedFunctionInfo> shared(function->shared(), isolate);
Zone zone(isolate->allocator(), ZONE_NAME);
OptimizedCompilationInfo info(&zone, isolate, shared, function);
OptimizedCompilationInfo info(&zone, isolate, shared, function,
kNativeContextDependent);
auto call_descriptor = Linkage::ComputeIncoming(&zone, &info);
Handle<Code> code =
......
......@@ -38,7 +38,7 @@ class JSConstantCacheTester : public HandleAndZoneScope,
JSGraph(main_isolate(), &main_graph_, &main_common_, &main_javascript_,
nullptr, &main_machine_),
canonical_(main_isolate()),
broker_(main_isolate(), main_zone(), false, false) {
broker_(main_isolate(), main_zone()) {
main_graph_.SetStart(main_graph_.NewNode(common()->Start(0)));
main_graph_.SetEnd(
main_graph_.NewNode(common()->End(1), main_graph_.start()));
......
......@@ -33,8 +33,7 @@ class ContextSpecializationTester : public HandleAndZoneScope {
jsgraph_(main_isolate(), graph(), common(), &javascript_, &simplified_,
&machine_),
reducer_(main_zone(), graph(), &tick_counter_),
js_heap_broker_(main_isolate(), main_zone(), FLAG_trace_heap_broker,
false),
js_heap_broker_(main_isolate(), main_zone()),
spec_(&reducer_, jsgraph(), &js_heap_broker_, context,
MaybeHandle<JSFunction>()) {}
......
......@@ -27,7 +27,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
explicit JSTypedLoweringTester(int num_parameters = 0)
: isolate(main_isolate()),
canonical(isolate),
js_heap_broker(isolate, main_zone(), FLAG_trace_heap_broker, false),
js_heap_broker(isolate, main_zone()),
binop(nullptr),
unop(nullptr),
javascript(main_zone()),
......
......@@ -26,6 +26,8 @@ namespace compiler {
static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
"dummy", 0, 0, 0, 0, 0, 0);
static constexpr bool kNativeContextDependent = false;
// So we can get a real JS function.
static Handle<JSFunction> Compile(const char* source) {
Isolate* isolate = CcTest::i_isolate();
......@@ -49,7 +51,7 @@ TEST(TestLinkageCreate) {
Handle<JSFunction> function = Compile("a + b");
Handle<SharedFunctionInfo> shared(function->shared(), handles.main_isolate());
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
shared, function);
shared, function, kNativeContextDependent);
auto call_descriptor = Linkage::ComputeIncoming(info.zone(), &info);
CHECK(call_descriptor);
}
......@@ -67,7 +69,7 @@ TEST(TestLinkageJSFunctionIncoming) {
Handle<SharedFunctionInfo> shared(function->shared(),
handles.main_isolate());
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
shared, function);
shared, function, kNativeContextDependent);
auto call_descriptor = Linkage::ComputeIncoming(info.zone(), &info);
CHECK(call_descriptor);
......@@ -84,7 +86,7 @@ TEST(TestLinkageJSCall) {
Handle<JSFunction> function = Compile("a + c");
Handle<SharedFunctionInfo> shared(function->shared(), handles.main_isolate());
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
shared, function);
shared, function, kNativeContextDependent);
for (int i = 0; i < 32; i++) {
auto call_descriptor = Linkage::GetJSCallDescriptor(
......
......@@ -27,7 +27,7 @@ class RepresentationChangerTester : public HandleAndZoneScope,
javascript_(main_zone()),
jsgraph_(main_isolate(), main_graph_, &main_common_, &javascript_,
&main_simplified_, &main_machine_),
broker_{main_isolate(), main_zone(), FLAG_trace_heap_broker, false},
broker_{main_isolate(), main_zone()},
changer_(&jsgraph_, &broker_) {
Node* s = graph()->NewNode(common()->Start(num_parameters));
graph()->SetStart(s);
......
......@@ -71,6 +71,8 @@ class BytecodeGraphCallable {
Handle<JSFunction> function_;
};
static constexpr bool kNativeContextDependent = false;
class BytecodeGraphTester {
public:
BytecodeGraphTester(Isolate* isolate, const char* script,
......@@ -121,8 +123,8 @@ class BytecodeGraphTester {
Zone zone(isolate_->allocator(), ZONE_NAME);
Handle<SharedFunctionInfo> shared(function->shared(), isolate_);
OptimizedCompilationInfo compilation_info(&zone, isolate_, shared,
function);
OptimizedCompilationInfo compilation_info(&zone, isolate_, shared, function,
kNativeContextDependent);
// Compiler relies on canonicalized handles, let's create
// a canonicalized scope and migrate existing handles there.
......
......@@ -41,9 +41,7 @@ namespace compiler {
class Types {
public:
Types(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng)
: zone_(zone),
js_heap_broker_(isolate, zone, FLAG_trace_heap_broker, false),
rng_(rng) {
: zone_(zone), js_heap_broker_(isolate, zone), rng_(rng) {
#define DECLARE_TYPE(name, value) \
name = Type::name(); \
types.push_back(name);
......
......@@ -24,6 +24,8 @@ using OptimizingCompileDispatcherTest = TestWithNativeContext;
namespace {
static constexpr bool kNativeContextDependent = false;
class BlockingCompilationJob : public OptimizedCompilationJob {
public:
BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function)
......@@ -31,7 +33,7 @@ class BlockingCompilationJob : public OptimizedCompilationJob {
State::kReadyToExecute),
shared_(function->shared(), isolate),
zone_(isolate->allocator(), ZONE_NAME),
info_(&zone_, isolate, shared_, function),
info_(&zone_, isolate, shared_, function, kNativeContextDependent),
blocking_(false),
semaphore_(0) {}
~BlockingCompilationJob() override = default;
......
......@@ -29,7 +29,7 @@ class CommonOperatorReducerTest : public GraphTest {
Reduction Reduce(
AdvancedReducer::Editor* editor, Node* node,
MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) {
JSHeapBroker broker(isolate(), zone(), FLAG_trace_heap_broker, false);
JSHeapBroker broker(isolate(), zone());
MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(),
flags);
CommonOperatorReducer reducer(editor, graph(), &broker, common(), &machine,
......
......@@ -63,7 +63,7 @@ class ConstantFoldingReducerTest : public TypedGraphTest {
public:
ConstantFoldingReducerTest()
: TypedGraphTest(3),
broker_(isolate(), zone(), FLAG_trace_heap_broker, false),
broker_(isolate(), zone()),
simplified_(zone()),
deps_(&broker_, zone()) {}
~ConstantFoldingReducerTest() override = default;
......
......@@ -18,7 +18,7 @@ GraphTest::GraphTest(int num_parameters)
: canonical_(isolate()),
common_(zone()),
graph_(zone()),
broker_(isolate(), zone(), FLAG_trace_heap_broker, false),
broker_(isolate(), zone()),
source_positions_(&graph_),
node_origins_(&graph_) {
graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
......
......@@ -30,7 +30,7 @@ class SimplifiedOperatorReducerTest : public GraphTest {
protected:
Reduction Reduce(Node* node) {
JSHeapBroker broker(isolate(), zone(), FLAG_trace_heap_broker, false);
JSHeapBroker broker(isolate(), zone());
MachineOperatorBuilder machine(zone());
JSOperatorBuilder javascript(zone());
JSGraph jsgraph(isolate(), graph(), common(), &javascript, simplified(),
......
......@@ -22,7 +22,7 @@ class TyperTest : public TypedGraphTest {
public:
TyperTest()
: TypedGraphTest(3),
broker_(isolate(), zone(), FLAG_trace_heap_broker, false),
broker_(isolate(), zone()),
operation_typer_(&broker_, zone()),
types_(zone(), isolate(), random_number_generator()),
javascript_(zone()),
......
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