blob: 83d890c938db2a010714c6b41ab10d4cb4538f1b [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
8#include "src/base/flags.h"
9#include "src/compiler/graph-reducer.h"
10
11namespace v8 {
12namespace internal {
13
14// Forward declarations.
15class CompilationDependencies;
16class TypeCache;
17
18
19namespace compiler {
20
21// Forward declarations.
22class CommonOperatorBuilder;
23class JSGraph;
24class JSOperatorBuilder;
25class SimplifiedOperatorBuilder;
26
27
28// Specializes a given JSGraph to a given global object, potentially constant
29// folding some {JSLoadGlobal} nodes or strength reducing some {JSStoreGlobal}
30// nodes.
31class JSGlobalObjectSpecialization final : public AdvancedReducer {
32 public:
33 // Flags that control the mode of operation.
34 enum Flag {
35 kNoFlags = 0u,
36 kDeoptimizationEnabled = 1u << 0,
37 };
38 typedef base::Flags<Flag> Flags;
39
40 JSGlobalObjectSpecialization(Editor* editor, JSGraph* jsgraph, Flags flags,
41 MaybeHandle<Context> native_context,
42 CompilationDependencies* dependencies);
43
44 Reduction Reduce(Node* node) final;
45
46 private:
47 Reduction ReduceJSLoadGlobal(Node* node);
48 Reduction ReduceJSStoreGlobal(Node* node);
49
50 // Retrieve the global object from the given {node} if known.
51 MaybeHandle<JSGlobalObject> GetGlobalObject(Node* node);
52
53 struct ScriptContextTableLookupResult;
54 bool LookupInScriptContextTable(Handle<JSGlobalObject> global_object,
55 Handle<Name> name,
56 ScriptContextTableLookupResult* result);
57
58 Graph* graph() const;
59 JSGraph* jsgraph() const { return jsgraph_; }
60 Isolate* isolate() const;
61 CommonOperatorBuilder* common() const;
62 JSOperatorBuilder* javascript() const;
63 SimplifiedOperatorBuilder* simplified() const;
64 Flags flags() const { return flags_; }
65 MaybeHandle<Context> native_context() const { return native_context_; }
66 CompilationDependencies* dependencies() const { return dependencies_; }
67
68 JSGraph* const jsgraph_;
69 Flags const flags_;
70 MaybeHandle<Context> native_context_;
71 CompilationDependencies* const dependencies_;
72 TypeCache const& type_cache_;
73
74 DISALLOW_COPY_AND_ASSIGN(JSGlobalObjectSpecialization);
75};
76
77DEFINE_OPERATORS_FOR_FLAGS(JSGlobalObjectSpecialization::Flags)
78
79} // namespace compiler
80} // namespace internal
81} // namespace v8
82
83#endif // V8_COMPILER_JS_GLOBAL_OBJECT_SPECIALIZATION_H_