source: icGREP/icgrep-devel/icgrep/pablo/passes/flattenif.cpp @ 5202

Last change on this file since 5202 was 5202, checked in by nmedfort, 2 years ago

Initial work on adding types to PabloAST and mutable Var objects.

File size: 1.4 KB
Line 
1#include <pablo/passes/flattenif.hpp>
2#include <pablo/codegenstate.h>
3#include <pablo/analysis/pabloverifier.hpp>
4
5namespace pablo {
6   
7void FlattenIf::flattenIf(PabloBlock * const block) {
8    Statement * stmt = block->front();
9    while (stmt) {
10        if (LLVM_UNLIKELY(isa<If>(stmt))) {
11            Statement * prior = stmt;
12            Statement * const initial = cast<If>(stmt)->getBody()->front();
13            Statement * body_stmt = initial;
14            while (body_stmt) {
15                assert (body_stmt->getPrevNode() == nullptr);
16                Statement * const next = body_stmt->getNextNode();
17                body_stmt->insertAfter(prior);
18                assert (body_stmt->getPrevNode() == prior);
19                prior = body_stmt;
20                body_stmt = next;
21            }
22            stmt = stmt->eraseFromParent(true);
23            assert (stmt == initial);
24        } else {
25            stmt = stmt->getNextNode();
26        }
27    }
28}
29
30/** ------------------------------------------------------------------------------------------------------------- *
31 * @brief transform
32 ** ------------------------------------------------------------------------------------------------------------- */
33void FlattenIf::transform(PabloFunction & function) {
34    flattenIf(function.getEntryBlock());
35    #ifndef NDEBUG
36    PabloVerifier::verify(function, "flatten-if");
37    #endif
38}
39
40}
Note: See TracBrowser for help on using the repository browser.