blob: 3cdb94158be1b2ee833b80559c54c99db769e147 [file] [log] [blame]
Kaido Kertf309f9a2021-04-30 12:09:15 -07001// 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_CODEGEN_UNOPTIMIZED_COMPILATION_INFO_H_
6#define V8_CODEGEN_UNOPTIMIZED_COMPILATION_INFO_H_
7
8#include <memory>
9
10#include "src/codegen/source-position-table.h"
11#include "src/common/globals.h"
12#include "src/handles/handles.h"
13#include "src/objects/feedback-vector.h"
14#include "src/objects/objects.h"
15#include "src/parsing/parse-info.h"
16#include "src/utils/utils.h"
17
18namespace v8 {
19namespace internal {
20
21class AsmWasmData;
22class CoverageInfo;
23class DeclarationScope;
24class FunctionLiteral;
25class Isolate;
26class ParseInfo;
27class SourceRangeMap;
28class Zone;
29
30// UnoptimizedCompilationInfo encapsulates the information needed to compile
31// unoptimized code for a given function, and the results of the compilation.
32class V8_EXPORT_PRIVATE UnoptimizedCompilationInfo final {
33 public:
34 UnoptimizedCompilationInfo(Zone* zone, ParseInfo* parse_info,
35 FunctionLiteral* literal);
36
37 const UnoptimizedCompileFlags& flags() const { return flags_; }
38
39 // Accessors for the input data of the function being compiled.
40
41 FunctionLiteral* literal() const { return literal_; }
42 void set_literal(FunctionLiteral* literal) {
43 DCHECK_NOT_NULL(literal);
44 literal_ = literal;
45 }
46 void ClearLiteral() { literal_ = nullptr; }
47
48 DeclarationScope* scope() const;
49
50 int num_parameters() const;
51 int num_parameters_including_this() const;
52
53 // Accessors for optional compilation features.
54
55 SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const;
56
57 bool has_source_range_map() const { return source_range_map_ != nullptr; }
58 SourceRangeMap* source_range_map() const { return source_range_map_; }
59 void set_source_range_map(SourceRangeMap* source_range_map) {
60 source_range_map_ = source_range_map;
61 }
62
63 bool has_coverage_info() const { return !coverage_info_.is_null(); }
64 Handle<CoverageInfo> coverage_info() const { return coverage_info_; }
65 void set_coverage_info(Handle<CoverageInfo> coverage_info) {
66 coverage_info_ = coverage_info;
67 }
68
69 // Accessors for the output of compilation.
70
71 bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
72 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
73 void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) {
74 bytecode_array_ = bytecode_array;
75 }
76
77 bool has_asm_wasm_data() const { return !asm_wasm_data_.is_null(); }
78 Handle<AsmWasmData> asm_wasm_data() const { return asm_wasm_data_; }
79 void SetAsmWasmData(Handle<AsmWasmData> asm_wasm_data) {
80 asm_wasm_data_ = asm_wasm_data;
81 }
82
83 FeedbackVectorSpec* feedback_vector_spec() { return &feedback_vector_spec_; }
84
85 private:
86 // Compilation flags.
87 const UnoptimizedCompileFlags flags_;
88
89 // The root AST node of the function literal being compiled.
90 FunctionLiteral* literal_;
91
92 // Used when block coverage is enabled.
93 SourceRangeMap* source_range_map_;
94
95 // Encapsulates coverage information gathered by the bytecode generator.
96 // Needs to be stored on the shared function info once compilation completes.
97 Handle<CoverageInfo> coverage_info_;
98
99 // Holds the bytecode array generated by the interpreter.
100 Handle<BytecodeArray> bytecode_array_;
101
102 // Holds the asm_wasm data struct generated by the asmjs compiler.
103 Handle<AsmWasmData> asm_wasm_data_;
104
105 // Holds the feedback vector spec generated during compilation
106 FeedbackVectorSpec feedback_vector_spec_;
107};
108
109} // namespace internal
110} // namespace v8
111
112#endif // V8_CODEGEN_UNOPTIMIZED_COMPILATION_INFO_H_