blob: ef784fc442812ca1c9a7cac1622a4c194a389786 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009
10namespace v8 {
11namespace internal {
12namespace compiler {
13
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014// Forward declarations.
15class JSGraph;
16class JSOperatorBuilder;
17
18
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019// Specializes a given JSGraph to a given context, potentially constant folding
20// some {LoadContext} nodes or strength reducing some {StoreContext} nodes.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000021class JSContextSpecialization final : public AdvancedReducer {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000023 JSContextSpecialization(Editor* editor, JSGraph* jsgraph,
24 MaybeHandle<Context> context)
25 : AdvancedReducer(editor), jsgraph_(jsgraph), context_(context) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027 Reduction Reduce(Node* node) final;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030 Reduction ReduceJSLoadContext(Node* node);
31 Reduction ReduceJSStoreContext(Node* node);
32
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 // Returns the {Context} to specialize {node} to (if any).
34 MaybeHandle<Context> GetSpecializationContext(Node* node);
35
36 Isolate* isolate() const;
37 JSOperatorBuilder* javascript() const;
38 JSGraph* jsgraph() const { return jsgraph_; }
39 MaybeHandle<Context> context() const { return context_; }
40
41 JSGraph* const jsgraph_;
42 MaybeHandle<Context> context_;
43
44 DISALLOW_COPY_AND_ASSIGN(JSContextSpecialization);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046
47} // namespace compiler
48} // namespace internal
49} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050
51#endif // V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_