Home | History | Annotate | Download | only in src
      1 // Copyright 2018 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_UNOPTIMIZED_COMPILATION_INFO_H_
      6 #define V8_UNOPTIMIZED_COMPILATION_INFO_H_
      7 
      8 #include <memory>
      9 
     10 #include "src/feedback-vector.h"
     11 #include "src/globals.h"
     12 #include "src/handles.h"
     13 #include "src/objects.h"
     14 #include "src/source-position-table.h"
     15 #include "src/utils.h"
     16 
     17 namespace v8 {
     18 namespace internal {
     19 
     20 class CoverageInfo;
     21 class DeclarationScope;
     22 class FunctionLiteral;
     23 class Isolate;
     24 class ParseInfo;
     25 class SourceRangeMap;
     26 class Zone;
     27 
     28 // UnoptimizedCompilationInfo encapsulates the information needed to compile
     29 // unoptimized code for a given function, and the results of the compilation.
     30 class V8_EXPORT_PRIVATE UnoptimizedCompilationInfo final {
     31  public:
     32   UnoptimizedCompilationInfo(Zone* zone, ParseInfo* parse_info,
     33                              FunctionLiteral* literal);
     34 
     35   Zone* zone() { return zone_; }
     36 
     37   // Compilation flag accessors.
     38 
     39   void MarkAsEval() { SetFlag(kIsEval); }
     40   bool is_eval() const { return GetFlag(kIsEval); }
     41 
     42   void MarkAsNative() { SetFlag(kIsNative); }
     43   bool is_native() const { return GetFlag(kIsNative); }
     44 
     45   void MarkAsCollectTypeProfile() { SetFlag(kCollectTypeProfile); }
     46   bool collect_type_profile() const { return GetFlag(kCollectTypeProfile); }
     47 
     48   // Accessors for the input data of the function being compiled.
     49 
     50   FunctionLiteral* literal() const { return literal_; }
     51   void set_literal(FunctionLiteral* literal) {
     52     DCHECK_NOT_NULL(literal);
     53     literal_ = literal;
     54   }
     55 
     56   DeclarationScope* scope() const;
     57 
     58   int num_parameters() const;
     59   int num_parameters_including_this() const;
     60 
     61   // Accessors for optional compilation features.
     62 
     63   SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const;
     64 
     65   bool has_source_range_map() const { return source_range_map_ != nullptr; }
     66   SourceRangeMap* source_range_map() const { return source_range_map_; }
     67   void set_source_range_map(SourceRangeMap* source_range_map) {
     68     source_range_map_ = source_range_map;
     69   }
     70 
     71   bool has_coverage_info() const { return !coverage_info_.is_null(); }
     72   Handle<CoverageInfo> coverage_info() const { return coverage_info_; }
     73   void set_coverage_info(Handle<CoverageInfo> coverage_info) {
     74     coverage_info_ = coverage_info;
     75   }
     76 
     77   // Accessors for the output of compilation.
     78 
     79   bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
     80   Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
     81   void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) {
     82     bytecode_array_ = bytecode_array;
     83   }
     84 
     85   bool has_asm_wasm_data() const { return !asm_wasm_data_.is_null(); }
     86   Handle<FixedArray> asm_wasm_data() const { return asm_wasm_data_; }
     87   void SetAsmWasmData(Handle<FixedArray> asm_wasm_data) {
     88     asm_wasm_data_ = asm_wasm_data;
     89   }
     90 
     91   FeedbackVectorSpec* feedback_vector_spec() { return &feedback_vector_spec_; }
     92 
     93  private:
     94   // Various configuration flags for a compilation, as well as some properties
     95   // of the compiled code produced by a compilation.
     96   enum Flag {
     97     kIsEval = 1 << 0,
     98     kIsNative = 1 << 1,
     99     kCollectTypeProfile = 1 << 2,
    100     kUntrustedCodeMitigations = 1 << 3,
    101   };
    102 
    103   void SetFlag(Flag flag) { flags_ |= flag; }
    104   bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
    105 
    106   // Compilation flags.
    107   unsigned flags_;
    108 
    109   // The zone from which the compilation pipeline working on this
    110   // OptimizedCompilationInfo allocates.
    111   Zone* zone_;
    112 
    113   // The root AST node of the function literal being compiled.
    114   FunctionLiteral* literal_;
    115 
    116   // Used when block coverage is enabled.
    117   SourceRangeMap* source_range_map_;
    118 
    119   // Encapsulates coverage information gathered by the bytecode generator.
    120   // Needs to be stored on the shared function info once compilation completes.
    121   Handle<CoverageInfo> coverage_info_;
    122 
    123   // Holds the bytecode array generated by the interpreter.
    124   Handle<BytecodeArray> bytecode_array_;
    125 
    126   // Holds the asm_wasm array generated by the asmjs compiler.
    127   Handle<FixedArray> asm_wasm_data_;
    128 
    129   // Holds the feedback vector spec generated during compilation
    130   FeedbackVectorSpec feedback_vector_spec_;
    131 };
    132 
    133 }  // namespace internal
    134 }  // namespace v8
    135 
    136 #endif  // V8_UNOPTIMIZED_COMPILATION_INFO_H_
    137