1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2014 the V8 project authors. All rights reserved.
2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file.
4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifndef V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_
6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_
7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/compiler/graph-reducer.h"
9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace v8 {
11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace internal {
12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace compiler {
13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
14014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Forward declarations.
15014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochclass JSGraph;
16014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochclass JSOperatorBuilder;
17014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
18014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Specializes a given JSGraph to a given context, potentially constant folding
20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// some {LoadContext} nodes or strength reducing some {StoreContext} nodes.
21014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochclass JSContextSpecialization final : public AdvancedReducer {
22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public:
23014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  JSContextSpecialization(Editor* editor, JSGraph* jsgraph,
24014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                          MaybeHandle<Context> context)
25014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      : AdvancedReducer(editor), jsgraph_(jsgraph), context_(context) {}
26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
27014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Reduction Reduce(Node* node) final;
28958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
29014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch private:
30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Reduction ReduceJSLoadContext(Node* node);
31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Reduction ReduceJSStoreContext(Node* node);
32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
33014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // Returns the {Context} to specialize {node} to (if any).
34014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  MaybeHandle<Context> GetSpecializationContext(Node* node);
35014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
36014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Isolate* isolate() const;
37014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  JSOperatorBuilder* javascript() const;
38014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  JSGraph* jsgraph() const { return jsgraph_; }
39014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  MaybeHandle<Context> context() const { return context_; }
40014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  JSGraph* const jsgraph_;
42014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  MaybeHandle<Context> context_;
43014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
44014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  DISALLOW_COPY_AND_ASSIGN(JSContextSpecialization);
45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch};
46014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
47014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}  // namespace compiler
48014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}  // namespace internal
49014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}  // namespace v8
50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif  // V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_
52