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

#include "src/base/flags.h"
9
#include "src/compiler/access-info.h"
10 11 12 13 14 15 16
#include "src/compiler/graph-reducer.h"

namespace v8 {
namespace internal {

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


namespace compiler {

// Forward declarations.
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 41 42 43 44
 public:
  // Flags that control the mode of operation.
  enum Flag {
    kNoFlags = 0u,
    kDeoptimizationEnabled = 1u << 0,
  };
  typedef base::Flags<Flag> Flags;

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

  Reduction Reduce(Node* node) final;

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

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

74 75 76 77
  // 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);

78 79 80 81
  // Assuming that {if_projection} is either IfTrue or IfFalse, adds a hint on
  // the dominating Branch that {if_projection} is the unlikely (deferred) case.
  void MarkAsDeferred(Node* if_projection);

82 83 84
  Graph* graph() const;
  JSGraph* jsgraph() const { return jsgraph_; }
  Isolate* isolate() const;
85
  Factory* factory() const;
86
  CommonOperatorBuilder* common() const;
87
  JSOperatorBuilder* javascript() const;
88
  SimplifiedOperatorBuilder* simplified() const;
89
  MachineOperatorBuilder* machine() const;
90
  Flags flags() const { return flags_; }
91
  Handle<Context> native_context() const { return native_context_; }
92
  CompilationDependencies* dependencies() const { return dependencies_; }
93
  Zone* zone() const { return zone_; }
94
  AccessInfoFactory& access_info_factory() { return access_info_factory_; }
95 96 97

  JSGraph* const jsgraph_;
  Flags const flags_;
98
  Handle<Context> native_context_;
99
  CompilationDependencies* const dependencies_;
100
  Zone* const zone_;
101
  TypeCache const& type_cache_;
102
  AccessInfoFactory access_info_factory_;
103

104
  DISALLOW_COPY_AND_ASSIGN(JSNativeContextSpecialization);
105 106
};

107
DEFINE_OPERATORS_FOR_FLAGS(JSNativeContextSpecialization::Flags)
108

109 110 111 112
}  // namespace compiler
}  // namespace internal
}  // namespace v8

113
#endif  // V8_COMPILER_JS_NATIVE_CONTEXT_SPECIALIZATION_H_