Commit 3ccf0d30 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[nci] Load the native context from the current context

Similar to the feedback vector, we cannot embed the native context as
a constant in NCI code (it is trivially native-context-dependent). In
NCI mode, load it from the current context. In default turbofan, we
keep the HeapConstant.

Bug: v8:8888
Change-Id: Iff95c673b25245c701c7755416abf2038b5fdf08
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2282532
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68712}
parent db5d8d19
...@@ -624,6 +624,16 @@ FieldAccess AccessBuilder::ForMapPrototype() { ...@@ -624,6 +624,16 @@ FieldAccess AccessBuilder::ForMapPrototype() {
return access; return access;
} }
// static
FieldAccess AccessBuilder::ForMapNativeContext() {
FieldAccess access = {
kTaggedBase, Map::kConstructorOrBackPointerOrNativeContextOffset,
Handle<Name>(), MaybeHandle<Map>(),
Type::Any(), MachineType::TaggedPointer(),
kPointerWriteBarrier};
return access;
}
// static // static
FieldAccess AccessBuilder::ForModuleRegularExports() { FieldAccess AccessBuilder::ForModuleRegularExports() {
FieldAccess access = { FieldAccess access = {
......
...@@ -209,6 +209,9 @@ class V8_EXPORT_PRIVATE AccessBuilder final ...@@ -209,6 +209,9 @@ class V8_EXPORT_PRIVATE AccessBuilder final
// Provides access to Map::prototype() field. // Provides access to Map::prototype() field.
static FieldAccess ForMapPrototype(); static FieldAccess ForMapPrototype();
// Provides access to Map::native_context() field.
static FieldAccess ForMapNativeContext();
// Provides access to Module::regular_exports() field. // Provides access to Module::regular_exports() field.
static FieldAccess ForModuleRegularExports(); static FieldAccess ForModuleRegularExports();
......
...@@ -80,6 +80,14 @@ class BytecodeGraphBuilder { ...@@ -80,6 +80,14 @@ class BytecodeGraphBuilder {
return feedback_vector_node_; return feedback_vector_node_;
} }
// Same as above for the feedback vector node.
void CreateNativeContextNode();
Node* BuildLoadNativeContext();
Node* native_context_node() const {
DCHECK_NOT_NULL(native_context_node_);
return native_context_node_;
}
Node* BuildLoadFeedbackCell(int index); Node* BuildLoadFeedbackCell(int index);
// Builder for loading the a native context field. // Builder for loading the a native context field.
...@@ -411,6 +419,7 @@ class BytecodeGraphBuilder { ...@@ -411,6 +419,7 @@ class BytecodeGraphBuilder {
const bool native_context_independent_; const bool native_context_independent_;
Node* feedback_vector_node_; Node* feedback_vector_node_;
Node* native_context_node_;
// Optimization to only create checkpoints when the current position in the // Optimization to only create checkpoints when the current position in the
// control-flow is not effect-dominated by another checkpoint already. All // control-flow is not effect-dominated by another checkpoint already. All
...@@ -977,6 +986,7 @@ BytecodeGraphBuilder::BytecodeGraphBuilder( ...@@ -977,6 +986,7 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
native_context_independent_( native_context_independent_(
flags & BytecodeGraphBuilderFlag::kNativeContextIndependent), flags & BytecodeGraphBuilderFlag::kNativeContextIndependent),
feedback_vector_node_(nullptr), feedback_vector_node_(nullptr),
native_context_node_(nullptr),
needs_eager_checkpoint_(true), needs_eager_checkpoint_(true),
exit_controls_(local_zone), exit_controls_(local_zone),
state_values_cache_(jsgraph), state_values_cache_(jsgraph),
...@@ -1061,10 +1071,36 @@ Node* BytecodeGraphBuilder::BuildLoadFeedbackCell(int index) { ...@@ -1061,10 +1071,36 @@ Node* BytecodeGraphBuilder::BuildLoadFeedbackCell(int index) {
} }
} }
void BytecodeGraphBuilder::CreateNativeContextNode() {
DCHECK_NULL(native_context_node_);
native_context_node_ = native_context_independent()
? BuildLoadNativeContext()
: jsgraph()->Constant(native_context());
}
Node* BytecodeGraphBuilder::BuildLoadNativeContext() {
DCHECK(native_context_independent());
DCHECK_NULL(native_context_node_);
Environment* env = environment();
Node* control = env->GetControlDependency();
Node* effect = env->GetEffectDependency();
Node* context = env->Context();
Node* context_map = effect =
graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()),
context, effect, control);
Node* native_context = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForMapNativeContext()),
context_map, effect, control);
env->UpdateEffectDependency(effect);
return native_context;
}
Node* BytecodeGraphBuilder::BuildLoadNativeContextField(int index) { Node* BytecodeGraphBuilder::BuildLoadNativeContextField(int index) {
Node* result = NewNode(javascript()->LoadContext(0, index, true)); Node* result = NewNode(javascript()->LoadContext(0, index, true));
NodeProperties::ReplaceContextInput(result, NodeProperties::ReplaceContextInput(result, native_context_node());
jsgraph()->Constant(native_context()));
return result; return result;
} }
...@@ -1093,6 +1129,7 @@ void BytecodeGraphBuilder::CreateGraph() { ...@@ -1093,6 +1129,7 @@ void BytecodeGraphBuilder::CreateGraph() {
set_environment(&env); set_environment(&env);
CreateFeedbackVectorNode(); CreateFeedbackVectorNode();
CreateNativeContextNode();
VisitBytecodes(); VisitBytecodes();
// Finish the basic structure of the graph. // Finish the basic structure of the graph.
...@@ -4160,7 +4197,7 @@ Node* BytecodeGraphBuilder::MakeNode(const Operator* op, int value_input_count, ...@@ -4160,7 +4197,7 @@ Node* BytecodeGraphBuilder::MakeNode(const Operator* op, int value_input_count,
if (has_context) { if (has_context) {
*current_input++ = OperatorProperties::NeedsExactContext(op) *current_input++ = OperatorProperties::NeedsExactContext(op)
? environment()->Context() ? environment()->Context()
: jsgraph()->Constant(native_context()); : native_context_node();
} }
if (has_frame_state) { if (has_frame_state) {
// The frame state will be inserted later. Here we misuse the {Dead} node // The frame state will be inserted later. Here we misuse the {Dead} node
......
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