Home | History | Annotate | Download | only in compiler
      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/compiler/graph-reducer.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 
     13 // Forward declarations.
     14 class CompilationDependencies;
     15 class TypeCache;
     16 
     17 
     18 namespace compiler {
     19 
     20 // Forward declarations.
     21 class CommonOperatorBuilder;
     22 class JSGraph;
     23 class JSOperatorBuilder;
     24 class 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.
     30 class JSGlobalObjectSpecialization final : public AdvancedReducer {
     31  public:
     32   JSGlobalObjectSpecialization(Editor* editor, JSGraph* jsgraph,
     33                                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;
     56   MaybeHandle<Context> native_context() const { return native_context_; }
     57   CompilationDependencies* dependencies() const { return dependencies_; }
     58 
     59   JSGraph* const jsgraph_;
     60   MaybeHandle<Context> native_context_;
     61   CompilationDependencies* const dependencies_;
     62   TypeCache const& type_cache_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(JSGlobalObjectSpecialization);
     65 };
     66 
     67 }  // namespace compiler
     68 }  // namespace internal
     69 }  // namespace v8
     70 
     71 #endif  // V8_COMPILER_JS_GLOBAL_OBJECT_SPECIALIZATION_H_
     72