1 // Copyright 2014 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_CONTEXT_SPECIALIZATION_H_ 6 #define V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_ 7 8 #include "src/compiler/graph-reducer.h" 9 10 namespace v8 { 11 namespace internal { 12 namespace compiler { 13 14 // Forward declarations. 15 class JSGraph; 16 class JSOperatorBuilder; 17 18 19 // Specializes a given JSGraph to a given context, potentially constant folding 20 // some {LoadContext} nodes or strength reducing some {StoreContext} nodes. 21 class JSContextSpecialization final : public AdvancedReducer { 22 public: JSContextSpecialization(Editor * editor,JSGraph * jsgraph,MaybeHandle<Context> context)23 JSContextSpecialization(Editor* editor, JSGraph* jsgraph, 24 MaybeHandle<Context> context) 25 : AdvancedReducer(editor), jsgraph_(jsgraph), context_(context) {} 26 27 Reduction Reduce(Node* node) final; 28 29 private: 30 Reduction ReduceJSLoadContext(Node* node); 31 Reduction ReduceJSStoreContext(Node* node); 32 33 // Returns the {Context} to specialize {node} to (if any). 34 MaybeHandle<Context> GetSpecializationContext(Node* node); 35 36 Isolate* isolate() const; 37 JSOperatorBuilder* javascript() const; jsgraph()38 JSGraph* jsgraph() const { return jsgraph_; } context()39 MaybeHandle<Context> context() const { return context_; } 40 41 JSGraph* const jsgraph_; 42 MaybeHandle<Context> context_; 43 44 DISALLOW_COPY_AND_ASSIGN(JSContextSpecialization); 45 }; 46 47 } // namespace compiler 48 } // namespace internal 49 } // namespace v8 50 51 #endif // V8_COMPILER_JS_CONTEXT_SPECIALIZATION_H_ 52