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