js-native-context-specialization.h 5 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

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

namespace v8 {
namespace internal {

// Forward declarations.
class CompilationDependencies;
16
class Factory;
17
class FeedbackNexus;
18
class TypeCache;
19 20 21 22 23


namespace compiler {

// Forward declarations.
24
enum class AccessMode;
25
class CommonOperatorBuilder;
26 27
class JSGraph;
class JSOperatorBuilder;
28
class MachineOperatorBuilder;
29
class SimplifiedOperatorBuilder;
30 31


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

46
  JSNativeContextSpecialization(Editor* editor, JSGraph* jsgraph, Flags flags,
47
                                MaybeHandle<Context> native_context,
48 49
                                CompilationDependencies* dependencies,
                                Zone* zone);
50 51 52 53

  Reduction Reduce(Node* node) final;

 private:
54
  Reduction ReduceJSLoadContext(Node* node);
55
  Reduction ReduceJSLoadNamed(Node* node);
56
  Reduction ReduceJSStoreNamed(Node* node);
57 58
  Reduction ReduceJSLoadProperty(Node* node);
  Reduction ReduceJSStoreProperty(Node* node);
59

60 61 62
  Reduction ReduceElementAccess(Node* node, Node* index, Node* value,
                                MapHandleList const& receiver_maps,
                                AccessMode access_mode,
63 64
                                LanguageMode language_mode,
                                KeyedAccessStoreMode store_mode);
65 66
  Reduction ReduceKeyedAccess(Node* node, Node* index, Node* value,
                              FeedbackNexus const& nexus,
67
                              AccessMode access_mode,
68 69
                              LanguageMode language_mode,
                              KeyedAccessStoreMode store_mode);
70 71 72 73
  Reduction ReduceNamedAccess(Node* node, Node* value,
                              FeedbackNexus const& nexus, Handle<Name> name,
                              AccessMode access_mode,
                              LanguageMode language_mode);
74 75
  Reduction ReduceNamedAccess(Node* node, Node* value,
                              MapHandleList const& receiver_maps,
76
                              Handle<Name> name, AccessMode access_mode,
77 78
                              LanguageMode language_mode,
                              Node* index = nullptr);
79

80 81
  Reduction ReduceSoftDeoptimize(Node* node);

82 83
  // Adds stability dependencies on all prototypes of every class in
  // {receiver_type} up to (and including) the {holder}.
84 85 86
  void AssumePrototypesStable(Type* receiver_type,
                              Handle<Context> native_context,
                              Handle<JSObject> holder);
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101
  // Extract receiver maps from {nexus} and filter based on {receiver} if
  // possible.
  bool ExtractReceiverMaps(Node* receiver, Node* effect,
                           FeedbackNexus const& nexus,
                           MapHandleList* receiver_maps);

  // Try to infer a map for the given {receiver} at the current {effect}.
  // If a map is returned then you can be sure that the {receiver} definitely
  // has the returned map at this point in the program (identified by {effect}).
  MaybeHandle<Map> InferReceiverMap(Node* receiver, Node* effect);
  // Try to infer a root map for the {receiver} independent of the current
  // program location.
  MaybeHandle<Map> InferReceiverRootMap(Node* receiver);

102 103 104
  // Retrieve the native context from the given {node} if known.
  MaybeHandle<Context> GetNativeContext(Node* node);

105 106 107
  Graph* graph() const;
  JSGraph* jsgraph() const { return jsgraph_; }
  Isolate* isolate() const;
108
  Factory* factory() const;
109
  CommonOperatorBuilder* common() const;
110
  JSOperatorBuilder* javascript() const;
111
  SimplifiedOperatorBuilder* simplified() const;
112
  MachineOperatorBuilder* machine() const;
113
  Flags flags() const { return flags_; }
114
  MaybeHandle<Context> native_context() const { return native_context_; }
115
  CompilationDependencies* dependencies() const { return dependencies_; }
116
  Zone* zone() const { return zone_; }
117 118 119

  JSGraph* const jsgraph_;
  Flags const flags_;
120
  MaybeHandle<Context> native_context_;
121
  CompilationDependencies* const dependencies_;
122
  Zone* const zone_;
123
  TypeCache const& type_cache_;
124

125
  DISALLOW_COPY_AND_ASSIGN(JSNativeContextSpecialization);
126 127
};

128
DEFINE_OPERATORS_FOR_FLAGS(JSNativeContextSpecialization::Flags)
129

130 131 132 133
}  // namespace compiler
}  // namespace internal
}  // namespace v8

134
#endif  // V8_COMPILER_JS_NATIVE_CONTEXT_SPECIALIZATION_H_