js-native-context-specialization.h 3.64 KB
Newer Older
1 2 3 4
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_COMPILER_JS_NATIVE_CONTEXT_SPECIALIZATION_H_
#define V8_COMPILER_JS_NATIVE_CONTEXT_SPECIALIZATION_H_
7 8 9 10 11 12 13 14 15 16

#include "src/base/flags.h"
#include "src/compiler/graph-reducer.h"
#include "src/compiler/simplified-operator.h"

namespace v8 {
namespace internal {

// Forward declarations.
class CompilationDependencies;
17
class Factory;
18 19 20 21 22


namespace compiler {

// Forward declarations.
23
class CommonOperatorBuilder;
24 25
class JSGraph;
class JSOperatorBuilder;
26
class MachineOperatorBuilder;
27 28


29
// Specializes a given JSGraph to a given native context, potentially constant
30
// folding some {LoadGlobal} nodes or strength reducing some {StoreGlobal}
31 32 33
// nodes.  And also specializes {LoadNamed} and {StoreNamed} nodes according
// to type feedback (if available).
class JSNativeContextSpecialization final : public AdvancedReducer {
34 35 36 37 38 39 40 41
 public:
  // Flags that control the mode of operation.
  enum Flag {
    kNoFlags = 0u,
    kDeoptimizationEnabled = 1u << 0,
  };
  typedef base::Flags<Flag> Flags;

42 43 44 45
  JSNativeContextSpecialization(Editor* editor, JSGraph* jsgraph, Flags flags,
                                Handle<GlobalObject> global_object,
                                CompilationDependencies* dependencies,
                                Zone* zone);
46 47 48 49 50 51

  Reduction Reduce(Node* node) final;

 private:
  Reduction ReduceJSLoadGlobal(Node* node);
  Reduction ReduceJSStoreGlobal(Node* node);
52
  Reduction ReduceJSLoadNamed(Node* node);
53
  Reduction ReduceJSStoreNamed(Node* node);
54 55 56 57 58 59 60 61

  Reduction Replace(Node* node, Node* value, Node* effect = nullptr,
                    Node* control = nullptr) {
    ReplaceWithValue(node, value, effect, control);
    return Changed(value);
  }
  Reduction Replace(Node* node, Handle<Object> value);

62
  enum PropertyAccessMode { kLoad, kStore };
63 64
  class PropertyAccessInfo;
  bool ComputePropertyAccessInfo(Handle<Map> map, Handle<Name> name,
65
                                 PropertyAccessMode access_mode,
66 67
                                 PropertyAccessInfo* access_info);
  bool ComputePropertyAccessInfos(MapHandleList const& maps, Handle<Name> name,
68
                                  PropertyAccessMode access_mode,
69 70
                                  ZoneVector<PropertyAccessInfo>* access_infos);

71 72 73 74
  struct ScriptContextTableLookupResult;
  bool LookupInScriptContextTable(Handle<Name> name,
                                  ScriptContextTableLookupResult* result);

75 76 77 78
  // Adds stability dependencies on all prototypes of every class in
  // {receiver_type} up to (and including) the {holder}.
  void AssumePrototypesStable(Type* receiver_type, Handle<JSObject> holder);

79 80 81
  Graph* graph() const;
  JSGraph* jsgraph() const { return jsgraph_; }
  Isolate* isolate() const;
82
  Factory* factory() const;
83
  CommonOperatorBuilder* common() const;
84
  JSOperatorBuilder* javascript() const;
85
  SimplifiedOperatorBuilder* simplified() const;
86
  MachineOperatorBuilder* machine() const;
87 88 89
  Flags flags() const { return flags_; }
  Handle<GlobalObject> global_object() const { return global_object_; }
  CompilationDependencies* dependencies() const { return dependencies_; }
90
  Zone* zone() const { return zone_; }
91 92 93 94 95

  JSGraph* const jsgraph_;
  Flags const flags_;
  Handle<GlobalObject> global_object_;
  CompilationDependencies* const dependencies_;
96
  Zone* const zone_;
97

98
  DISALLOW_COPY_AND_ASSIGN(JSNativeContextSpecialization);
99 100
};

101
DEFINE_OPERATORS_FOR_FLAGS(JSNativeContextSpecialization::Flags)
102

103 104 105 106
}  // namespace compiler
}  // namespace internal
}  // namespace v8

107
#endif  // V8_COMPILER_JS_NATIVE_CONTEXT_SPECIALIZATION_H_