1 // 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 
11 namespace v8 {
12 namespace internal {
13 
14 // Forward declarations.
15 class CompilationDependencies;
16 class TypeCache;
17 
18 
19 namespace compiler {
20 
21 // Forward declarations.
22 class CommonOperatorBuilder;
23 class JSGraph;
24 class JSOperatorBuilder;
25 class 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.
31 class 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;
jsgraph()59   JSGraph* jsgraph() const { return jsgraph_; }
60   Isolate* isolate() const;
61   CommonOperatorBuilder* common() const;
62   JSOperatorBuilder* javascript() const;
63   SimplifiedOperatorBuilder* simplified() const;
flags()64   Flags flags() const { return flags_; }
native_context()65   MaybeHandle<Context> native_context() const { return native_context_; }
dependencies()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 
77 DEFINE_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_
84