Line data Source code
1 : // Copyright 2014 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_
6 : #define V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_
7 :
8 : #include "src/compiler/graph-reducer.h"
9 :
10 : namespace v8 {
11 : namespace internal {
12 : namespace compiler {
13 :
14 : // Forward declarations.
15 : class JSGraph;
16 : class JSOperatorBuilder;
17 :
18 : // Pair of a context and its distance from some point of reference.
19 : struct OuterContext {
20 23124 : OuterContext() : context(), distance() {}
21 : OuterContext(Handle<Context> context_, size_t distance_)
22 : : context(context_), distance(distance_) {}
23 : Handle<Context> context;
24 : size_t distance;
25 : };
26 :
27 : // Specializes a given JSGraph to a given context, potentially constant folding
28 : // some {LoadContext} nodes or strength reducing some {StoreContext} nodes.
29 : // Additionally, constant-folds the function parameter if {closure} is given.
30 : //
31 : // The context can be the incoming function context or any outer context
32 : // thereof, as indicated by {outer}'s {distance}.
33 443430 : class JSContextSpecialization final : public AdvancedReducer {
34 : public:
35 : JSContextSpecialization(Editor* editor, JSGraph* jsgraph,
36 : Maybe<OuterContext> outer,
37 : MaybeHandle<JSFunction> closure)
38 : : AdvancedReducer(editor),
39 : jsgraph_(jsgraph),
40 : outer_(outer),
41 443430 : closure_(closure) {}
42 :
43 0 : const char* reducer_name() const override {
44 0 : return "JSContextSpecialization";
45 : }
46 :
47 : Reduction Reduce(Node* node) final;
48 :
49 : private:
50 : Reduction ReduceParameter(Node* node);
51 : Reduction ReduceJSLoadContext(Node* node);
52 : Reduction ReduceJSStoreContext(Node* node);
53 :
54 : Reduction SimplifyJSStoreContext(Node* node, Node* new_context,
55 : size_t new_depth);
56 : Reduction SimplifyJSLoadContext(Node* node, Node* new_context,
57 : size_t new_depth);
58 :
59 : Isolate* isolate() const;
60 : JSGraph* jsgraph() const { return jsgraph_; }
61 1035924 : Maybe<OuterContext> outer() const { return outer_; }
62 : MaybeHandle<JSFunction> closure() const { return closure_; }
63 :
64 : JSGraph* const jsgraph_;
65 : Maybe<OuterContext> outer_;
66 : MaybeHandle<JSFunction> closure_;
67 :
68 : DISALLOW_COPY_AND_ASSIGN(JSContextSpecialization);
69 : };
70 :
71 : } // namespace compiler
72 : } // namespace internal
73 : } // namespace v8
74 :
75 : #endif // V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_
|