LCOV - code coverage report
Current view: top level - src/compiler - js-inlining-heuristic.h (source / functions) Hit Total Coverage
Test: app.info Lines: 4 4 100.0 %
Date: 2019-04-18 Functions: 2 3 66.7 %

          Line data    Source code
       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_INLINING_HEURISTIC_H_
       6             : #define V8_COMPILER_JS_INLINING_HEURISTIC_H_
       7             : 
       8             : #include "src/compiler/js-inlining.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : namespace compiler {
      13             : 
      14      927848 : class JSInliningHeuristic final : public AdvancedReducer {
      15             :  public:
      16             :   enum Mode { kGeneralInlining, kRestrictedInlining, kStressInlining };
      17             :   JSInliningHeuristic(Editor* editor, Mode mode, Zone* local_zone,
      18             :                       OptimizedCompilationInfo* info, JSGraph* jsgraph,
      19             :                       JSHeapBroker* broker,
      20             :                       SourcePositionTable* source_positions)
      21             :       : AdvancedReducer(editor),
      22             :         mode_(mode),
      23             :         inliner_(editor, local_zone, info, jsgraph, broker, source_positions),
      24             :         candidates_(local_zone),
      25             :         seen_(local_zone),
      26             :         source_positions_(source_positions),
      27             :         jsgraph_(jsgraph),
      28      927852 :         broker_(broker) {}
      29             : 
      30          18 :   const char* reducer_name() const override { return "JSInliningHeuristic"; }
      31             : 
      32             :   Reduction Reduce(Node* node) final;
      33             : 
      34             :   // Processes the list of candidates gathered while the reducer was running,
      35             :   // and inlines call sites that the heuristic determines to be important.
      36             :   void Finalize() final;
      37             : 
      38             :  private:
      39             :   // This limit currently matches what the old compiler did. We may want to
      40             :   // re-evaluate and come up with a proper limit for TurboFan.
      41             :   static const int kMaxCallPolymorphism = 4;
      42             : 
      43     1782831 :   struct Candidate {
      44             :     base::Optional<JSFunctionRef> functions[kMaxCallPolymorphism];
      45             :     // In the case of polymorphic inlining, this tells if each of the
      46             :     // functions could be inlined.
      47             :     bool can_inline_function[kMaxCallPolymorphism];
      48             :     // Strong references to bytecode to ensure it is not flushed from SFI
      49             :     // while choosing inlining candidates.
      50             :     base::Optional<BytecodeArrayRef> bytecode[kMaxCallPolymorphism];
      51             :     // TODO(2206): For now polymorphic inlining is treated orthogonally to
      52             :     // inlining based on SharedFunctionInfo. This should be unified and the
      53             :     // above array should be switched to SharedFunctionInfo instead. Currently
      54             :     // we use {num_functions == 1 && functions[0].is_null()} as an indicator.
      55             :     base::Optional<SharedFunctionInfoRef> shared_info;
      56             :     int num_functions;
      57             :     Node* node = nullptr;     // The call site at which to inline.
      58             :     CallFrequency frequency;  // Relative frequency of this call site.
      59             :     int total_size = 0;
      60             :   };
      61             : 
      62             :   // Comparator for candidates.
      63             :   struct CandidateCompare {
      64             :     bool operator()(const Candidate& left, const Candidate& right) const;
      65             :   };
      66             : 
      67             :   // Candidates are kept in a sorted set of unique candidates.
      68             :   using Candidates = ZoneSet<Candidate, CandidateCompare>;
      69             : 
      70             :   // Dumps candidates to console.
      71             :   void PrintCandidates();
      72             :   Reduction InlineCandidate(Candidate const& candidate, bool small_function);
      73             :   void CreateOrReuseDispatch(Node* node, Node* callee,
      74             :                              Candidate const& candidate, Node** if_successes,
      75             :                              Node** calls, Node** inputs, int input_count);
      76             :   bool TryReuseDispatch(Node* node, Node* callee, Candidate const& candidate,
      77             :                         Node** if_successes, Node** calls, Node** inputs,
      78             :                         int input_count);
      79             :   enum StateCloneMode { kCloneState, kChangeInPlace };
      80             :   Node* DuplicateFrameStateAndRename(Node* frame_state, Node* from, Node* to,
      81             :                                      StateCloneMode mode);
      82             :   Node* DuplicateStateValuesAndRename(Node* state_values, Node* from, Node* to,
      83             :                                       StateCloneMode mode);
      84             :   Candidate CollectFunctions(Node* node, int functions_size);
      85             : 
      86             :   CommonOperatorBuilder* common() const;
      87             :   Graph* graph() const;
      88             :   JSGraph* jsgraph() const { return jsgraph_; }
      89             :   // TODO(neis): Make heap broker a component of JSGraph?
      90             :   JSHeapBroker* broker() const { return broker_; }
      91             :   Isolate* isolate() const { return jsgraph_->isolate(); }
      92             :   SimplifiedOperatorBuilder* simplified() const;
      93             : 
      94             :   Mode const mode_;
      95             :   JSInliner inliner_;
      96             :   Candidates candidates_;
      97             :   ZoneSet<NodeId> seen_;
      98             :   SourcePositionTable* source_positions_;
      99             :   JSGraph* const jsgraph_;
     100             :   JSHeapBroker* const broker_;
     101             :   int cumulative_count_ = 0;
     102             : };
     103             : 
     104             : }  // namespace compiler
     105             : }  // namespace internal
     106             : }  // namespace v8
     107             : 
     108             : #endif  // V8_COMPILER_JS_INLINING_HEURISTIC_H_

Generated by: LCOV version 1.10