LCOV - code coverage report
Current view: top level - src/compiler - js-inlining-heuristic.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 4 75.0 %
Date: 2017-10-20 Functions: 1 3 33.3 %

          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      886762 : class JSInliningHeuristic final : public AdvancedReducer {
      15             :  public:
      16             :   enum Mode { kGeneralInlining, kRestrictedInlining, kStressInlining };
      17             :   JSInliningHeuristic(Editor* editor, Mode mode, Zone* local_zone,
      18             :                       CompilationInfo* info, JSGraph* jsgraph,
      19             :                       SourcePositionTable* source_positions)
      20             :       : AdvancedReducer(editor),
      21             :         mode_(mode),
      22             :         inliner_(editor, local_zone, info, jsgraph, source_positions),
      23             :         candidates_(local_zone),
      24             :         seen_(local_zone),
      25      886764 :         jsgraph_(jsgraph) {}
      26             : 
      27           0 :   const char* reducer_name() const override { return "JSInliningHeuristic"; }
      28             : 
      29             :   Reduction Reduce(Node* node) final;
      30             : 
      31             :   // Processes the list of candidates gathered while the reducer was running,
      32             :   // and inlines call sites that the heuristic determines to be important.
      33             :   void Finalize() final;
      34             : 
      35             :  private:
      36             :   // This limit currently matches what Crankshaft does. We may want to
      37             :   // re-evaluate and come up with a proper limit for TurboFan.
      38             :   static const int kMaxCallPolymorphism = 4;
      39             : 
      40     3605774 :   struct Candidate {
      41             :     Handle<JSFunction> functions[kMaxCallPolymorphism];
      42             :     // In the case of polymorphic inlining, this tells if each of the
      43             :     // functions could be inlined.
      44             :     bool can_inline_function[kMaxCallPolymorphism];
      45             :     // TODO(2206): For now polymorphic inlining is treated orthogonally to
      46             :     // inlining based on SharedFunctionInfo. This should be unified and the
      47             :     // above array should be switched to SharedFunctionInfo instead. Currently
      48             :     // we use {num_functions == 1 && functions[0].is_null()} as an indicator.
      49             :     Handle<SharedFunctionInfo> shared_info;
      50             :     int num_functions;
      51             :     Node* node = nullptr;     // The call site at which to inline.
      52             :     CallFrequency frequency;  // Relative frequency of this call site.
      53             :     int total_size = 0;
      54             :   };
      55             : 
      56             :   // Comparator for candidates.
      57             :   struct CandidateCompare {
      58             :     bool operator()(const Candidate& left, const Candidate& right) const;
      59             :   };
      60             : 
      61             :   // Candidates are kept in a sorted set of unique candidates.
      62             :   typedef ZoneSet<Candidate, CandidateCompare> Candidates;
      63             : 
      64             :   // Dumps candidates to console.
      65             :   void PrintCandidates();
      66             :   Reduction InlineCandidate(Candidate const& candidate, bool small_function);
      67             :   void CreateOrReuseDispatch(Node* node, Node* callee,
      68             :                              Candidate const& candidate, Node** if_successes,
      69             :                              Node** calls, Node** inputs, int input_count);
      70             :   bool TryReuseDispatch(Node* node, Node* callee, Candidate const& candidate,
      71             :                         Node** if_successes, Node** calls, Node** inputs,
      72             :                         int input_count);
      73             :   enum StateCloneMode { kCloneState, kChangeInPlace };
      74             :   Node* DuplicateFrameStateAndRename(Node* frame_state, Node* from, Node* to,
      75             :                                      StateCloneMode mode);
      76             :   Node* DuplicateStateValuesAndRename(Node* state_values, Node* from, Node* to,
      77             :                                       StateCloneMode mode);
      78             : 
      79             :   CommonOperatorBuilder* common() const;
      80             :   Graph* graph() const;
      81             :   JSGraph* jsgraph() const { return jsgraph_; }
      82             :   SimplifiedOperatorBuilder* simplified() const;
      83             : 
      84             :   Mode const mode_;
      85             :   JSInliner inliner_;
      86             :   Candidates candidates_;
      87             :   ZoneSet<NodeId> seen_;
      88             :   JSGraph* const jsgraph_;
      89             :   int cumulative_count_ = 0;
      90             : };
      91             : 
      92             : }  // namespace compiler
      93             : }  // namespace internal
      94             : }  // namespace v8
      95             : 
      96             : #endif  // V8_COMPILER_JS_INLINING_HEURISTIC_H_

Generated by: LCOV version 1.10