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_INLINING_H_ 6 #define V8_COMPILER_JS_INLINING_H_ 7 8 #include "src/compiler/graph-reducer.h" 9 #include "src/compiler/js-graph.h" 10 11 namespace v8 { 12 namespace internal { 13 14 class BytecodeOffset; 15 class OptimizedCompilationInfo; 16 17 namespace compiler { 18 19 class SourcePositionTable; 20 21 // The JSInliner provides the core graph inlining machinery. Note that this 22 // class only deals with the mechanics of how to inline one graph into another, 23 // heuristics that decide what and how much to inline are beyond its scope. 24 class JSInliner final : public AdvancedReducer { 25 public: JSInliner(Editor * editor,Zone * local_zone,OptimizedCompilationInfo * info,JSGraph * jsgraph,JSHeapBroker * broker,SourcePositionTable * source_positions)26 JSInliner(Editor* editor, Zone* local_zone, OptimizedCompilationInfo* info, 27 JSGraph* jsgraph, JSHeapBroker* broker, 28 SourcePositionTable* source_positions) 29 : AdvancedReducer(editor), 30 local_zone_(local_zone), 31 info_(info), 32 jsgraph_(jsgraph), 33 broker_(broker), 34 source_positions_(source_positions) {} 35 reducer_name()36 const char* reducer_name() const override { return "JSInliner"; } 37 Reduce(Node * node)38 Reduction Reduce(Node* node) final { UNREACHABLE(); } 39 40 // Can be used by inlining heuristics or by testing code directly, without 41 // using the above generic reducer interface of the inlining machinery. 42 Reduction ReduceJSCall(Node* node); 43 44 #if V8_ENABLE_WEBASSEMBLY 45 Reduction ReduceJSWasmCall(Node* node); 46 #endif // V8_ENABLE_WEBASSEMBLY 47 48 private: zone()49 Zone* zone() const { return local_zone_; } 50 CommonOperatorBuilder* common() const; 51 JSOperatorBuilder* javascript() const; 52 SimplifiedOperatorBuilder* simplified() const; 53 Graph* graph() const; jsgraph()54 JSGraph* jsgraph() const { return jsgraph_; } 55 // TODO(neis): Make heap broker a component of JSGraph? broker()56 JSHeapBroker* broker() const { return broker_; } isolate()57 Isolate* isolate() const { return jsgraph_->isolate(); } 58 59 Zone* const local_zone_; 60 OptimizedCompilationInfo* info_; 61 JSGraph* const jsgraph_; 62 JSHeapBroker* const broker_; 63 SourcePositionTable* const source_positions_; 64 65 base::Optional<SharedFunctionInfoRef> DetermineCallTarget(Node* node); 66 FeedbackCellRef DetermineCallContext(Node* node, Node** context_out); 67 68 FrameState CreateArtificialFrameState( 69 Node* node, FrameState outer_frame_state, int parameter_count, 70 BytecodeOffset bailout_id, FrameStateType frame_state_type, 71 SharedFunctionInfoRef shared, Node* context = nullptr); 72 73 Reduction InlineCall(Node* call, Node* new_target, Node* context, 74 Node* frame_state, StartNode start, Node* end, 75 Node* exception_target, 76 const NodeVector& uncaught_subcalls, int argument_count); 77 78 #if V8_ENABLE_WEBASSEMBLY 79 Reduction InlineJSWasmCall(Node* call, Node* new_target, Node* context, 80 Node* frame_state, StartNode start, Node* end, 81 Node* exception_target, 82 const NodeVector& uncaught_subcalls); 83 #endif // V8_ENABLE_WEBASSEMBLY 84 }; 85 86 } // namespace compiler 87 } // namespace internal 88 } // namespace v8 89 90 #endif // V8_COMPILER_JS_INLINING_H_ 91