v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
loop-unrolling.h
Go to the documentation of this file.
1// Copyright 2021 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_LOOP_UNROLLING_H_
6#define V8_COMPILER_LOOP_UNROLLING_H_
7
8// Loop unrolling is an optimization that copies the body of a loop and creates
9// a fresh loop, whose iteration corresponds to 2 or more iterations of the
10// initial loop. For a high-level description of the algorithm see
11// https://bit.ly/3G0VdWW.
12
15
16namespace v8 {
17namespace internal {
18namespace compiler {
19
20static constexpr uint32_t kMaximumUnnestedSize = 50;
21static constexpr uint32_t kMaximumUnrollingCount = 5;
22
23// A simple heuristic to decide how many times to unroll a loop. Favors small
24// and deeply nested loops.
25// TODO(manoskouk): Investigate how this can be improved.
26V8_INLINE uint32_t unrolling_count_heuristic(uint32_t size, uint32_t depth) {
27 return std::min((depth + 1) * kMaximumUnnestedSize / size,
29}
30
31V8_INLINE uint32_t maximum_unrollable_size(uint32_t depth) {
32 return (depth + 1) * kMaximumUnnestedSize;
33}
34
35void UnrollLoop(Node* loop_node, ZoneUnorderedSet<Node*>* loop, uint32_t depth,
36 TFGraph* graph, CommonOperatorBuilder* common, Zone* tmp_zone,
38 NodeOriginTable* node_origins);
39
40} // namespace compiler
41} // namespace internal
42} // namespace v8
43
44#endif // V8_COMPILER_LOOP_UNROLLING_H_
SourcePositionTable * source_positions
static constexpr uint32_t kMaximumUnnestedSize
static constexpr uint32_t kMaximumUnrollingCount
V8_INLINE uint32_t unrolling_count_heuristic(uint32_t size, uint32_t depth)
V8_INLINE uint32_t maximum_unrollable_size(uint32_t depth)
void UnrollLoop(Node *loop_node, ZoneUnorderedSet< Node * > *loop, uint32_t depth, TFGraph *graph, CommonOperatorBuilder *common, Zone *tmp_zone, SourcePositionTable *source_positions, NodeOriginTable *node_origins)
#define V8_INLINE
Definition v8config.h:500