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

Last change on this file since 5239 was 5217, checked in by nmedfort, 3 years ago

Merged PabloFunction? and PabloKernel? classes. Updated projects where necessary.

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