Index: src/compiler/node-properties.cc |
diff --git a/src/compiler/node-properties.cc b/src/compiler/node-properties.cc |
index 552e1bc1765673587da79590882b4263831971b1..2719749546f8c5cd43eb02dcb25e06d83336e4ee 100644 |
--- a/src/compiler/node-properties.cc |
+++ b/src/compiler/node-properties.cc |
@@ -4,6 +4,7 @@ |
#include "src/compiler/common-operator.h" |
#include "src/compiler/graph.h" |
+#include "src/compiler/linkage.h" |
#include "src/compiler/node-properties.h" |
#include "src/compiler/operator-properties.h" |
#include "src/compiler/verifier.h" |
@@ -293,6 +294,90 @@ void NodeProperties::CollectControlProjections(Node* node, Node** projections, |
// static |
+MaybeHandle<Context> NodeProperties::GetSpecializationContext( |
+ Node* node, MaybeHandle<Context> context) { |
+ switch (node->opcode()) { |
+ case IrOpcode::kHeapConstant: |
+ return Handle<Context>::cast(OpParameter<Handle<HeapObject>>(node)); |
+ case IrOpcode::kParameter: { |
+ Node* const start = NodeProperties::GetValueInput(node, 0); |
+ DCHECK_EQ(IrOpcode::kStart, start->opcode()); |
+ int const index = ParameterIndexOf(node->op()); |
+ // The context is always the last parameter to a JavaScript function, and |
+ // {Parameter} indices start at -1, so value outputs of {Start} look like |
+ // this: closure, receiver, param0, ..., paramN, context. |
+ if (index == start->op()->ValueOutputCount() - 2) { |
+ return context; |
+ } |
+ break; |
+ } |
+ default: |
+ break; |
+ } |
+ return MaybeHandle<Context>(); |
+} |
+ |
+ |
+// static |
+MaybeHandle<Context> NodeProperties::GetSpecializationNativeContext( |
+ Node* node, MaybeHandle<Context> native_context) { |
+ while (true) { |
+ switch (node->opcode()) { |
+ case IrOpcode::kJSCreateBlockContext: |
+ case IrOpcode::kJSCreateCatchContext: |
+ case IrOpcode::kJSCreateFunctionContext: |
+ case IrOpcode::kJSCreateModuleContext: |
+ case IrOpcode::kJSCreateScriptContext: |
+ case IrOpcode::kJSCreateWithContext: { |
+ // Skip over the intermediate contexts, we're only interested in the |
+ // very last context in the context chain anyway. |
+ node = NodeProperties::GetContextInput(node); |
+ break; |
+ } |
+ case IrOpcode::kHeapConstant: { |
+ // Extract the native context from the actual {context}. |
+ Handle<Context> context = |
+ Handle<Context>::cast(OpParameter<Handle<HeapObject>>(node)); |
+ return handle(context->native_context()); |
+ } |
+ case IrOpcode::kOsrValue: { |
+ int const index = OpParameter<int>(node); |
+ if (index == Linkage::kOsrContextSpillSlotIndex) { |
+ return native_context; |
+ } |
+ return MaybeHandle<Context>(); |
+ } |
+ case IrOpcode::kParameter: { |
+ Node* const start = NodeProperties::GetValueInput(node, 0); |
+ DCHECK_EQ(IrOpcode::kStart, start->opcode()); |
+ int const index = ParameterIndexOf(node->op()); |
+ // The context is always the last parameter to a JavaScript function, |
+ // and {Parameter} indices start at -1, so value outputs of {Start} |
+ // look like this: closure, receiver, param0, ..., paramN, context. |
+ if (index == start->op()->ValueOutputCount() - 2) { |
+ return native_context; |
+ } |
+ return MaybeHandle<Context>(); |
+ } |
+ default: |
+ return MaybeHandle<Context>(); |
+ } |
+ } |
+} |
+ |
+ |
+// static |
+MaybeHandle<JSGlobalObject> NodeProperties::GetSpecializationGlobalObject( |
+ Node* node, MaybeHandle<Context> native_context) { |
+ Handle<Context> context; |
+ if (GetSpecializationNativeContext(node, native_context).ToHandle(&context)) { |
+ return handle(context->global_object()); |
+ } |
+ return MaybeHandle<JSGlobalObject>(); |
+} |
+ |
+ |
+// static |
Type* NodeProperties::GetTypeOrAny(Node* node) { |
return IsTyped(node) ? node->type() : Type::Any(); |
} |