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