P4C
The P4 Compiler
Loading...
Searching...
No Matches
unrollLoops.h
1/*
2 * Copyright 2024 Nvidia Corp.
3 * SPDX-FileCopyrightText: 2024 Nvidia Corp.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef MIDEND_UNROLLLOOPS_H_
9#define MIDEND_UNROLLLOOPS_H_
10
11#include "def_use.h"
12#include "ir/ir.h"
13
14namespace P4 {
15
16class UnrollLoops : public Transform, public P4::ResolutionContext {
17 NameGenerator &nameGen;
18 const ComputeDefUse *defUse;
19
20 public:
22 const IR::Declaration_Variable *index = nullptr;
23 std::vector<long> indexes;
24 };
25 struct Policy {
26 bool unroll_default;
27 virtual bool operator()(const IR::LoopStatement *, bool, const loop_bounds_t &);
28 explicit Policy(bool ud) : unroll_default(ud) {}
29 } & policy;
30 static Policy default_unroll, default_nounroll;
31
32 private:
33 long evalLoop(const IR::Expression *, long, const ComputeDefUse::locset_t &, bool &);
34 long evalLoop(const IR::BaseAssignmentStatement *, long, const ComputeDefUse::locset_t &,
35 bool &);
36 bool findLoopBounds(IR::ForStatement *, loop_bounds_t &);
37 bool findLoopBounds(IR::ForInStatement *, loop_bounds_t &);
38 const IR::Statement *doUnroll(const loop_bounds_t &, const IR::Statement *,
39 const IR::IndexedVector<IR::StatOrDecl> * = nullptr);
40
41 const IR::Statement *preorder(IR::ForStatement *) override;
42 const IR::Statement *preorder(IR::ForInStatement *) override;
43
44 public:
45 explicit UnrollLoops(NameGenerator &ng, const ComputeDefUse *du, Policy &p = default_unroll)
46 : nameGen(ng), defUse(du), policy(p) {}
47};
48
49} // namespace P4
50
51#endif /* MIDEND_UNROLLLOOPS_H_ */
Compute defuse info within P4Parser and P4Control blocks in the midend.
Definition midend/def_use.h:38
Definition indexed_vector.h:31
Definition referenceMap.h:29
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35
Definition visitor.h:442
Definition unrollLoops.h:21
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
Definition unrollLoops.h:25