Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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_NATIVE_CONTEXT_SPECIALIZATION_H_ |
| 6 | #define V8_COMPILER_JS_NATIVE_CONTEXT_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 Factory; |
| 17 | class FeedbackNexus; |
| 18 | class TypeCache; |
| 19 | |
| 20 | |
| 21 | namespace compiler { |
| 22 | |
| 23 | // Forward declarations. |
| 24 | enum class AccessMode; |
| 25 | class CommonOperatorBuilder; |
| 26 | class JSGraph; |
| 27 | 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 | // nodes. And also specializes {LoadNamed} and {StoreNamed} nodes according |
| 35 | // to type feedback (if available). |
| 36 | class JSNativeContextSpecialization final : public AdvancedReducer { |
| 37 | public: |
| 38 | // Flags that control the mode of operation. |
| 39 | enum Flag { |
| 40 | kNoFlags = 0u, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 41 | kBailoutOnUninitialized = 1u << 0, |
| 42 | kDeoptimizationEnabled = 1u << 1, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | }; |
| 44 | typedef base::Flags<Flag> Flags; |
| 45 | |
| 46 | JSNativeContextSpecialization(Editor* editor, JSGraph* jsgraph, Flags flags, |
| 47 | MaybeHandle<Context> native_context, |
| 48 | CompilationDependencies* dependencies, |
| 49 | Zone* zone); |
| 50 | |
| 51 | Reduction Reduce(Node* node) final; |
| 52 | |
| 53 | private: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 54 | Reduction ReduceJSLoadContext(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | Reduction ReduceJSLoadNamed(Node* node); |
| 56 | Reduction ReduceJSStoreNamed(Node* node); |
| 57 | Reduction ReduceJSLoadProperty(Node* node); |
| 58 | Reduction ReduceJSStoreProperty(Node* node); |
| 59 | |
| 60 | Reduction ReduceElementAccess(Node* node, Node* index, Node* value, |
| 61 | MapHandleList const& receiver_maps, |
| 62 | AccessMode access_mode, |
| 63 | LanguageMode language_mode, |
| 64 | KeyedAccessStoreMode store_mode); |
| 65 | Reduction ReduceKeyedAccess(Node* node, Node* index, Node* value, |
| 66 | FeedbackNexus const& nexus, |
| 67 | AccessMode access_mode, |
| 68 | LanguageMode language_mode, |
| 69 | KeyedAccessStoreMode store_mode); |
| 70 | Reduction ReduceNamedAccess(Node* node, Node* value, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 71 | FeedbackNexus const& nexus, Handle<Name> name, |
| 72 | AccessMode access_mode, |
| 73 | LanguageMode language_mode); |
| 74 | Reduction ReduceNamedAccess(Node* node, Node* value, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 75 | MapHandleList const& receiver_maps, |
| 76 | Handle<Name> name, AccessMode access_mode, |
| 77 | LanguageMode language_mode, |
| 78 | Node* index = nullptr); |
| 79 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 80 | Reduction ReduceSoftDeoptimize(Node* node); |
| 81 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 82 | // Adds stability dependencies on all prototypes of every class in |
| 83 | // {receiver_type} up to (and including) the {holder}. |
| 84 | void AssumePrototypesStable(Type* receiver_type, |
| 85 | Handle<Context> native_context, |
| 86 | Handle<JSObject> holder); |
| 87 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 88 | // Extract receiver maps from {nexus} and filter based on {receiver} if |
| 89 | // possible. |
| 90 | bool ExtractReceiverMaps(Node* receiver, Node* effect, |
| 91 | FeedbackNexus const& nexus, |
| 92 | MapHandleList* receiver_maps); |
| 93 | |
| 94 | // Try to infer a map for the given {receiver} at the current {effect}. |
| 95 | // If a map is returned then you can be sure that the {receiver} definitely |
| 96 | // has the returned map at this point in the program (identified by {effect}). |
| 97 | MaybeHandle<Map> InferReceiverMap(Node* receiver, Node* effect); |
| 98 | // Try to infer a root map for the {receiver} independent of the current |
| 99 | // program location. |
| 100 | MaybeHandle<Map> InferReceiverRootMap(Node* receiver); |
| 101 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 102 | // Retrieve the native context from the given {node} if known. |
| 103 | MaybeHandle<Context> GetNativeContext(Node* node); |
| 104 | |
| 105 | Graph* graph() const; |
| 106 | JSGraph* jsgraph() const { return jsgraph_; } |
| 107 | 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 | JSGraph* const jsgraph_; |
| 119 | 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 | } // namespace compiler |
| 131 | } // namespace internal |
| 132 | } // namespace v8 |
| 133 | |
| 134 | #endif // V8_COMPILER_JS_NATIVE_CONTEXT_SPECIALIZATION_H_ |