v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-context-specialization.h
Go to the documentation of this file.
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
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15// Forward declarations.
16class JSGraph;
17class JSOperatorBuilder;
18
19// Pair of a context and its distance from some point of reference.
21 OuterContext() = default;
23 : context(context_), distance(distance_) {}
24
26 size_t distance = 0;
27};
28
29// Specializes a given JSGraph to a given context, potentially constant folding
30// some {LoadContext} nodes or strength reducing some {StoreContext} nodes.
31// Additionally, constant-folds the function parameter if {closure} is given,
32// and constant-folds import.meta loads if the corresponding object already
33// exists.
34//
35// The context can be the incoming function context or any outer context
36// thereof, as indicated by {outer}'s {distance}.
38 public:
42 : AdvancedReducer(editor),
43 jsgraph_(jsgraph),
44 outer_(outer),
45 closure_(closure),
46 broker_(broker) {}
49
50 const char* reducer_name() const override {
51 return "JSContextSpecialization";
52 }
53
54 Reduction Reduce(Node* node) final;
55
56 private:
57 Reduction ReduceParameter(Node* node);
58 Reduction ReduceJSLoadContext(Node* node);
59 Reduction ReduceJSLoadScriptContext(Node* node);
60 Reduction ReduceJSStoreContext(Node* node);
61 Reduction ReduceJSStoreScriptContext(Node* node);
62 Reduction ReduceJSGetImportMeta(Node* node);
63
64 Reduction SimplifyJSLoadContext(Node* node, Node* new_context,
65 size_t new_depth);
66 Reduction SimplifyJSLoadScriptContext(Node* node, Node* new_context,
67 size_t new_depth);
68 Reduction SimplifyJSStoreContext(Node* node, Node* new_context,
69 size_t new_depth);
70 Reduction SimplifyJSStoreScriptContext(Node* node, Node* new_context,
71 size_t new_depth);
72
73 Isolate* isolate() const;
74 JSGraph* jsgraph() const { return jsgraph_; }
75 Maybe<OuterContext> outer() const { return outer_; }
76 MaybeHandle<JSFunction> closure() const { return closure_; }
77 JSHeapBroker* broker() const { return broker_; }
78
83};
84
85} // namespace compiler
86} // namespace internal
87} // namespace v8
88
89#endif // V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_
JSGraph * jsgraph
JSContextSpecialization(const JSContextSpecialization &)=delete
JSContextSpecialization & operator=(const JSContextSpecialization &)=delete
JSContextSpecialization(Editor *editor, JSGraph *jsgraph, JSHeapBroker *broker, Maybe< OuterContext > outer, MaybeHandle< JSFunction > closure)
JSHeapBroker *const broker_
Handle< Context > context_
Isolate * isolate
JSHeapBroker * broker
#define V8_EXPORT_PRIVATE
Definition macros.h:460
OuterContext(IndirectHandle< Context > context_, size_t distance_)