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

Last change on this file since 5828 was 5267, checked in by nmedfort, 3 years ago

Code clean-up. Removed Pablo Call, SetIthBit? and Prototype.

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