P4C
The P4 Compiler
Loading...
Searching...
No Matches
unrollLoops.h
1/*
2Copyright 2024 Nvidia Corp.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef MIDEND_UNROLLLOOPS_H_
18#define MIDEND_UNROLLLOOPS_H_
19
20#include "def_use.h"
21#include "ir/ir.h"
22
23namespace P4 {
24
26 NameGenerator &nameGen;
27 const ComputeDefUse *defUse;
28
29 public:
31 const IR::Declaration_Variable *index = nullptr;
32 std::vector<long> indexes;
33 };
34 struct Policy {
35 bool unroll_default;
36 virtual bool operator()(const IR::LoopStatement *, bool, const loop_bounds_t &);
37 explicit Policy(bool ud) : unroll_default(ud) {}
38 } & policy;
39 static Policy default_unroll, default_nounroll;
40
41 private:
42 long evalLoop(const IR::Expression *, long, const ComputeDefUse::locset_t &, bool &);
43 bool findLoopBounds(IR::ForStatement *, loop_bounds_t &);
44 bool findLoopBounds(IR::ForInStatement *, loop_bounds_t &);
45 const IR::Statement *doUnroll(const loop_bounds_t &, const IR::Statement *,
46 const IR::IndexedVector<IR::StatOrDecl> * = nullptr);
47
48 const IR::Statement *preorder(IR::ForStatement *) override;
49 const IR::Statement *preorder(IR::ForInStatement *) override;
50
51 public:
52 explicit UnrollLoops(NameGenerator &ng, const ComputeDefUse *du, Policy &p = default_unroll)
53 : nameGen(ng), defUse(du), policy(p) {}
54};
55
56} // namespace P4
57
58#endif /* MIDEND_UNROLLLOOPS_H_ */
Compute defuse info within P4Parser and P4Control blocks in the midend.
Definition midend/def_use.h:47
Definition node.h:52
Definition referenceMap.h:29
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:33
Definition visitor.h:424
Definition unrollLoops.h:25
Definition unrollLoops.h:30
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition unrollLoops.h:34