v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
instruction-selection-phase.h
Go to the documentation of this file.
1// Copyright 2023 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_COMPILER_TURBOSHAFT_INSTRUCTION_SELECTION_PHASE_H_
6#define V8_COMPILER_TURBOSHAFT_INSTRUCTION_SELECTION_PHASE_H_
7
8#include <optional>
9
11
12namespace v8::internal {
13class ProfileDataFromFile;
14class SparseBitVector;
15}
16
18
19// Compute the special reverse-post-order block ordering, which is essentially
20// a RPO of the graph where loop bodies are contiguous. Properties:
21// 1. If block A is a predecessor of B, then A appears before B in the order,
22// unless B is a loop header and A is in the loop headed at B
23// (i.e. A -> B is a backedge).
24// => If block A dominates block B, then A appears before B in the order.
25// => If block A is a loop header, A appears before all blocks in the loop
26// headed at A.
27// 2. All loops are contiguous in the order (i.e. no intervening blocks that
28// do not belong to the loop.)
29// Note a simple RPO traversal satisfies (1) but not (2).
30// TODO(nicohartmann@): Investigate faster and simpler alternatives.
32 public:
33 // Numbering for BasicBlock::rpo_number for this block traversal:
34 static const int kBlockOnStack = -2;
35 static const int kBlockVisited1 = -3;
36 static const int kBlockVisited2 = -4;
37 static const int kBlockUnvisited = -1;
38
39 using Backedge = std::pair<const Block*, size_t>;
40
42 const Block* block = nullptr;
43 size_t index = 0;
45
46 SpecialRPOStackFrame(const Block* block, size_t index,
48 : block(block), index(index), successors(std::move(successors)) {}
49 };
50
51 struct LoopInfo {
52 const Block* header;
56 const Block* end;
57 const Block* start;
58
59 void AddOutgoing(Zone* zone, const Block* block) {
60 outgoing.push_back(block);
61 }
62 };
63
64 struct BlockData {
65 static constexpr size_t kNoLoopNumber = std::numeric_limits<size_t>::max();
66 int32_t rpo_number = kBlockUnvisited;
67 size_t loop_number = kNoLoopNumber;
68 const Block* rpo_next = nullptr;
69 };
70
72 : graph_(&graph), block_data_(graph.block_count(), zone), loops_(zone) {}
73
74 ZoneVector<uint32_t> ComputeSpecialRPO();
75
76 private:
77 void ComputeLoopInfo(size_t num_loops, ZoneVector<Backedge>& backedges);
78 ZoneVector<uint32_t> ComputeBlockPermutation(const Block* entry);
79
80 int32_t rpo_number(const Block* block) const {
81 return block_data_[block->index()].rpo_number;
82 }
83
84 void set_rpo_number(const Block* block, int32_t rpo_number) {
85 block_data_[block->index()].rpo_number = rpo_number;
86 }
87
88 bool has_loop_number(const Block* block) const {
89 return block_data_[block->index()].loop_number != BlockData::kNoLoopNumber;
90 }
91
92 size_t loop_number(const Block* block) const {
93 DCHECK(has_loop_number(block));
94 return block_data_[block->index()].loop_number;
95 }
96
97 void set_loop_number(const Block* block, size_t loop_number) {
98 block_data_[block->index()].loop_number = loop_number;
99 }
100
101 const Block* PushFront(const Block* head, const Block* block) {
102 block_data_[block->index()].rpo_next = head;
103 return block;
104 }
105
106 Zone* zone() const { return loops_.zone(); }
107
108 const Graph* graph_;
111};
112
114
116 DECL_TURBOSHAFT_PHASE_CONSTANTS(ProfileApplication)
117
118 void Run(PipelineData* data, Zone* temp_zone,
119 const ProfileDataFromFile* profile);
120};
121
123 DECL_TURBOSHAFT_PHASE_CONSTANTS(SpecialRPOScheduling)
124
125 void Run(PipelineData* data, Zone* temp_zone);
126};
127
129 DECL_TURBOSHAFT_PHASE_CONSTANTS(InstructionSelection)
130 static constexpr bool kOutputIsTraceableGraph = false;
131
132 std::optional<BailoutReason> Run(PipelineData* data, Zone* temp_zone,
133 const CallDescriptor* call_descriptor,
134 Linkage* linkage, CodeTracer* code_tracer);
135};
136
137} // namespace v8::internal::compiler::turboshaft
138
139#endif // V8_COMPILER_TURBOSHAFT_INSTRUCTION_SELECTION_PHASE_H_
const Block * PushFront(const Block *head, const Block *block)
Linkage * linkage
RpoNumber block
STL namespace.
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460
std::optional< BailoutReason > Run(PipelineData *data, Zone *temp_zone, const CallDescriptor *call_descriptor, Linkage *linkage, CodeTracer *code_tracer)
void Run(PipelineData *data, Zone *temp_zone, const ProfileDataFromFile *profile)
SpecialRPOStackFrame(const Block *block, size_t index, base::SmallVector< Block *, 4 > successors)
#define DECL_TURBOSHAFT_PHASE_CONSTANTS(Name)
Definition phase.h:39
TFGraph * graph_