• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
zone()35   Zone* zone() { return zone_; }
36 
37   // Compilation flag accessors.
38 
MarkAsEval()39   void MarkAsEval() { SetFlag(kIsEval); }
is_eval()40   bool is_eval() const { return GetFlag(kIsEval); }
41 
MarkAsNative()42   void MarkAsNative() { SetFlag(kIsNative); }
is_native()43   bool is_native() const { return GetFlag(kIsNative); }
44 
MarkAsCollectTypeProfile()45   void MarkAsCollectTypeProfile() { SetFlag(kCollectTypeProfile); }
collect_type_profile()46   bool collect_type_profile() const { return GetFlag(kCollectTypeProfile); }
47 
48   // Accessors for the input data of the function being compiled.
49 
literal()50   FunctionLiteral* literal() const { return literal_; }
set_literal(FunctionLiteral * 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 
has_source_range_map()65   bool has_source_range_map() const { return source_range_map_ != nullptr; }
source_range_map()66   SourceRangeMap* source_range_map() const { return source_range_map_; }
set_source_range_map(SourceRangeMap * source_range_map)67   void set_source_range_map(SourceRangeMap* source_range_map) {
68     source_range_map_ = source_range_map;
69   }
70 
has_coverage_info()71   bool has_coverage_info() const { return !coverage_info_.is_null(); }
coverage_info()72   Handle<CoverageInfo> coverage_info() const { return coverage_info_; }
set_coverage_info(Handle<CoverageInfo> 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 
has_bytecode_array()79   bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
bytecode_array()80   Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
SetBytecodeArray(Handle<BytecodeArray> bytecode_array)81   void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) {
82     bytecode_array_ = bytecode_array;
83   }
84 
has_asm_wasm_data()85   bool has_asm_wasm_data() const { return !asm_wasm_data_.is_null(); }
asm_wasm_data()86   Handle<FixedArray> asm_wasm_data() const { return asm_wasm_data_; }
SetAsmWasmData(Handle<FixedArray> asm_wasm_data)87   void SetAsmWasmData(Handle<FixedArray> asm_wasm_data) {
88     asm_wasm_data_ = asm_wasm_data;
89   }
90 
feedback_vector_spec()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 
SetFlag(Flag flag)103   void SetFlag(Flag flag) { flags_ |= flag; }
GetFlag(Flag 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