Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: src/compiler/js-context-specialization.cc

Issue 2841613002: [compiler][modules] Constant-fold the loads of module cells. (Closed)
Patch Set: Rebase. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/compiler/js-context-specialization.cc
diff --git a/src/compiler/js-context-specialization.cc b/src/compiler/js-context-specialization.cc
index 0deb7cb38b668bbaf92fc2bb831ce501e6ab2f72..5fb4b30783c62a45eda0b13ab2b96bcc3f60f328 100644
--- a/src/compiler/js-context-specialization.cc
+++ b/src/compiler/js-context-specialization.cc
@@ -83,6 +83,42 @@ Reduction JSContextSpecialization::SimplifyJSStoreContext(Node* node,
return Changed(node);
}
+namespace {
+
+bool IsContextParameter(Node* node) {
+ DCHECK_EQ(IrOpcode::kParameter, node->opcode());
+ 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.
+ return index == start->op()->ValueOutputCount() - 2;
+}
+
+MaybeHandle<Context> GetSpecializationContext(Node* node,
Michael Starzinger 2017/05/03 17:28:16 nit: Needs a short comment explaining the semantic
neis 2017/05/04 10:36:21 Done.
+ size_t* requested_depth,
+ Maybe<OuterContext> maybe_outer) {
+ switch (node->opcode()) {
+ case IrOpcode::kHeapConstant:
+ return Handle<Context>::cast(OpParameter<Handle<HeapObject>>(node));
+ case IrOpcode::kParameter: {
+ OuterContext outer;
+ if (maybe_outer.To(&outer) && IsContextParameter(node) &&
+ *requested_depth >= outer.distance) {
+ *requested_depth -= outer.distance;
+ return outer.context;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ return MaybeHandle<Context>();
+}
+
+} // anonymous namespace
+
Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode());
@@ -90,14 +126,13 @@ Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) {
size_t depth = access.depth();
// First walk up the context chain in the graph as far as possible.
- Node* outer = NodeProperties::GetOuterContext(node, &depth);
+ Node* context = NodeProperties::GetOuterContext(node, &depth);
Handle<Context> concrete;
- if (!NodeProperties::GetSpecializationContext(outer, context())
- .ToHandle(&concrete)) {
+ if (!GetSpecializationContext(context, &depth, outer()).ToHandle(&concrete)) {
// We do not have a concrete context object, so we can only partially reduce
// the load by folding-in the outer context node.
- return SimplifyJSLoadContext(node, outer, depth);
+ return SimplifyJSLoadContext(node, context, depth);
}
// Now walk up the concrete context chain for the remaining depth.
@@ -139,14 +174,13 @@ Reduction JSContextSpecialization::ReduceJSStoreContext(Node* node) {
// First walk up the context chain in the graph until we reduce the depth to 0
// or hit a node that does not have a CreateXYZContext operator.
- Node* outer = NodeProperties::GetOuterContext(node, &depth);
+ Node* context = NodeProperties::GetOuterContext(node, &depth);
Handle<Context> concrete;
- if (!NodeProperties::GetSpecializationContext(outer, context())
- .ToHandle(&concrete)) {
+ if (!GetSpecializationContext(context, &depth, outer()).ToHandle(&concrete)) {
// We do not have a concrete context object, so we can only partially reduce
// the load by folding-in the outer context node.
- return SimplifyJSStoreContext(node, outer, depth);
+ return SimplifyJSStoreContext(node, context, depth);
}
// Now walk up the concrete context chain for the remaining depth.

Powered by Google App Engine
This is Rietveld 408576698