LCOV - code coverage report
Current view: top level - src/compiler - bytecode-analysis.h (source / functions) Hit Total Coverage
Test: app.info Lines: 2 2 100.0 %
Date: 2017-10-20 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // Copyright 2016 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_BYTECODE_ANALYSIS_H_
       6             : #define V8_COMPILER_BYTECODE_ANALYSIS_H_
       7             : 
       8             : #include "src/base/hashmap.h"
       9             : #include "src/bit-vector.h"
      10             : #include "src/compiler/bytecode-liveness-map.h"
      11             : #include "src/handles.h"
      12             : #include "src/interpreter/bytecode-register.h"
      13             : #include "src/utils.h"
      14             : #include "src/zone/zone-containers.h"
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : 
      19             : class BytecodeArray;
      20             : 
      21             : namespace compiler {
      22             : 
      23             : class V8_EXPORT_PRIVATE BytecodeLoopAssignments {
      24             :  public:
      25             :   BytecodeLoopAssignments(int parameter_count, int register_count, Zone* zone);
      26             : 
      27             :   void Add(interpreter::Register r);
      28             :   void AddList(interpreter::Register r, uint32_t count);
      29             :   void Union(const BytecodeLoopAssignments& other);
      30             : 
      31             :   bool ContainsParameter(int index) const;
      32             :   bool ContainsLocal(int index) const;
      33             : 
      34             :   int parameter_count() const { return parameter_count_; }
      35             :   int local_count() const { return bit_vector_->length() - parameter_count_; }
      36             : 
      37             :  private:
      38             :   int parameter_count_;
      39             :   BitVector* bit_vector_;
      40             : };
      41             : 
      42             : struct V8_EXPORT_PRIVATE LoopInfo {
      43             :  public:
      44             :   LoopInfo(int parent_offset, int parameter_count, int register_count,
      45             :            Zone* zone)
      46             :       : parent_offset_(parent_offset),
      47       61601 :         assignments_(parameter_count, register_count, zone) {}
      48             : 
      49             :   int parent_offset() const { return parent_offset_; }
      50             : 
      51             :   BytecodeLoopAssignments& assignments() { return assignments_; }
      52             :   const BytecodeLoopAssignments& assignments() const { return assignments_; }
      53             : 
      54             :  private:
      55             :   // The offset to the parent loop, or -1 if there is no parent.
      56             :   int parent_offset_;
      57             :   BytecodeLoopAssignments assignments_;
      58             : };
      59             : 
      60     1009836 : class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED {
      61             :  public:
      62             :   BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone,
      63             :                    bool do_liveness_analysis);
      64             : 
      65             :   // Analyze the bytecodes to find the loop ranges, loop nesting, loop
      66             :   // assignments and liveness, under the assumption that there is an OSR bailout
      67             :   // at {osr_bailout_id}.
      68             :   //
      69             :   // No other methods in this class return valid information until this has been
      70             :   // called.
      71             :   void Analyze(BailoutId osr_bailout_id);
      72             : 
      73             :   // Return true if the given offset is a loop header
      74             :   bool IsLoopHeader(int offset) const;
      75             :   // Get the loop header offset of the containing loop for arbitrary
      76             :   // {offset}, or -1 if the {offset} is not inside any loop.
      77             :   int GetLoopOffsetFor(int offset) const;
      78             :   // Get the loop info of the loop header at {header_offset}.
      79             :   const LoopInfo& GetLoopInfoFor(int header_offset) const;
      80             : 
      81             :   // True if the current analysis has an OSR entry point.
      82             :   bool HasOsrEntryPoint() const { return osr_entry_point_ != -1; }
      83             : 
      84             :   int osr_entry_point() const { return osr_entry_point_; }
      85             :   // Gets the in-liveness for the bytecode at {offset}.
      86             :   const BytecodeLivenessState* GetInLivenessFor(int offset) const;
      87             : 
      88             :   // Gets the out-liveness for the bytecode at {offset}.
      89             :   const BytecodeLivenessState* GetOutLivenessFor(int offset) const;
      90             : 
      91             :   std::ostream& PrintLivenessTo(std::ostream& os) const;
      92             : 
      93             :  private:
      94             :   struct LoopStackEntry {
      95             :     int header_offset;
      96             :     LoopInfo* loop_info;
      97             :   };
      98             : 
      99             :   void PushLoop(int loop_header, int loop_end);
     100             : 
     101             : #if DEBUG
     102             :   bool LivenessIsValid();
     103             : #endif
     104             : 
     105             :   Zone* zone() const { return zone_; }
     106             :   Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
     107             : 
     108             :  private:
     109             :   Handle<BytecodeArray> bytecode_array_;
     110             :   bool do_liveness_analysis_;
     111             :   Zone* zone_;
     112             : 
     113             :   ZoneStack<LoopStackEntry> loop_stack_;
     114             :   ZoneVector<int> loop_end_index_queue_;
     115             : 
     116             :   ZoneMap<int, int> end_to_header_;
     117             :   ZoneMap<int, LoopInfo> header_to_info_;
     118             :   int osr_entry_point_;
     119             : 
     120             :   BytecodeLivenessMap liveness_map_;
     121             : 
     122             :   DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis);
     123             : };
     124             : 
     125             : }  // namespace compiler
     126             : }  // namespace internal
     127             : }  // namespace v8
     128             : 
     129             : #endif  // V8_COMPILER_BYTECODE_ANALYSIS_H_

Generated by: LCOV version 1.10