blob: 3ffc67a3773558256f2f120fdfb466f3f82a612f [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 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_GLOBAL_OBJECT_SPECIALIZATION_H_
6#define V8_COMPILER_JS_GLOBAL_OBJECT_SPECIALIZATION_H_
7
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/compiler/graph-reducer.h"
9
10namespace v8 {
11namespace internal {
12
13// Forward declarations.
14class CompilationDependencies;
15class TypeCache;
16
17
18namespace compiler {
19
20// Forward declarations.
21class CommonOperatorBuilder;
22class JSGraph;
23class JSOperatorBuilder;
24class SimplifiedOperatorBuilder;
25
26
27// Specializes a given JSGraph to a given global object, potentially constant
28// folding some {JSLoadGlobal} nodes or strength reducing some {JSStoreGlobal}
29// nodes.
30class JSGlobalObjectSpecialization final : public AdvancedReducer {
31 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +010032 JSGlobalObjectSpecialization(Editor* editor, JSGraph* jsgraph,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 MaybeHandle<Context> native_context,
34 CompilationDependencies* dependencies);
35
36 Reduction Reduce(Node* node) final;
37
38 private:
39 Reduction ReduceJSLoadGlobal(Node* node);
40 Reduction ReduceJSStoreGlobal(Node* node);
41
42 // Retrieve the global object from the given {node} if known.
43 MaybeHandle<JSGlobalObject> GetGlobalObject(Node* node);
44
45 struct ScriptContextTableLookupResult;
46 bool LookupInScriptContextTable(Handle<JSGlobalObject> global_object,
47 Handle<Name> name,
48 ScriptContextTableLookupResult* result);
49
50 Graph* graph() const;
51 JSGraph* jsgraph() const { return jsgraph_; }
52 Isolate* isolate() const;
53 CommonOperatorBuilder* common() const;
54 JSOperatorBuilder* javascript() const;
55 SimplifiedOperatorBuilder* simplified() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 MaybeHandle<Context> native_context() const { return native_context_; }
57 CompilationDependencies* dependencies() const { return dependencies_; }
58
59 JSGraph* const jsgraph_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 MaybeHandle<Context> native_context_;
61 CompilationDependencies* const dependencies_;
62 TypeCache const& type_cache_;
63
64 DISALLOW_COPY_AND_ASSIGN(JSGlobalObjectSpecialization);
65};
66
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000067} // namespace compiler
68} // namespace internal
69} // namespace v8
70
71#endif // V8_COMPILER_JS_GLOBAL_OBJECT_SPECIALIZATION_H_