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