source: icGREP/icgrep-devel/icgrep/pablo/ps_if.cpp @ 4416

Last change on this file since 4416 was 4416, checked in by nmedfort, 5 years ago

Many use def info changes; removed dependency on boost system library. More work still needed on CSE.

File size: 1.1 KB
Line 
1#include <pablo/ps_if.h>
2#include <pablo/codegenstate.h>
3#include <pablo/ps_assign.h>
4
5namespace pablo {
6
7If::If(PabloAST * expr, DefinedVars && definedVars, PabloBlock & body, PabloBlock * parent)
8: Statement(ClassTypeId::If, {expr}, nullptr, parent)
9, mBody(body)
10, mDefined(definedVars.begin(), definedVars.end())
11, mCarryCount(0)
12, mAdvanceCount(0)
13{
14    // Conceptually, having a defined var X is identical to having:
15    //
16    // Assign(X, 0)
17    // If (...)
18    //    Next(Assign(X), ...)
19    //
20    // Since the implied 'Next' node is a user of the Assign node, and the Assign node is
21    // embedded into the If, the defined var is a user of the If node.
22
23    for (PabloAST * assign : mDefined) {
24        assign->addUser(this);
25        addUser(assign);
26    }
27}
28
29void If::replaceCondOrDefinedVar(PabloAST * from, PabloAST * to) {
30    if (mOperand[0] == from) {
31        mOperand[0] = to;
32    }
33    if (isa<Statement>(from) && mDefined.remove(cast<Statement>(from))) {
34        if (isa<Statement>(to)) {
35            mDefined.insert(cast<Statement>(to));
36        }
37    }
38}
39
40}
Note: See TracBrowser for help on using the repository browser.