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

Last change on this file since 4766 was 4764, checked in by nmedfort, 4 years ago

More work on reassociation pass

File size: 1.6 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, const std::initializer_list<Assign *> definedVars, PabloBlock & body)
8: Statement(ClassTypeId::If, {expr}, nullptr)
9, mBody(body)
10, mDefined(definedVars.begin(), definedVars.end(), reinterpret_cast<DefinedAllocator &>(mVectorAllocator))
11{
12    // Conceptually, having a defined var X is identical to having:
13    //
14    // Assign(X, 0)
15    // If (...)
16    //    Next(Assign(X), ...)
17    //
18    // Since the implied 'Next' node is a user of the Assign node, and the Assign node is
19    // embedded into the If, the defined var is a user of the If node. However, since the
20    // Assign's value is also dependant on the 'Next' value, the If node is also a user
21    // of it.
22
23    for (PabloAST * def : mDefined) {
24        def->addUser(this);
25        addUser(def);
26    }
27}
28
29If::If(PabloAST * expr, const std::vector<Assign *> & definedVars, PabloBlock & body)
30: Statement(ClassTypeId::If, {expr}, nullptr)
31, mBody(body)
32, mDefined(definedVars.begin(), definedVars.end(), reinterpret_cast<DefinedAllocator &>(mVectorAllocator))
33{
34    for (PabloAST * def : mDefined) {
35        def->addUser(this);
36        addUser(def);
37    }
38}
39
40void If::addDefined(Assign * def) {
41    if (LLVM_LIKELY(std::find(mDefined.begin(), mDefined.end(), def) != mDefined.end())) {
42        const auto size = mDefined.size();
43        mDefined.push_back(def);
44        assert (mDefined.size() == size + 1);
45        assert (mDefined.back() == def);
46        def->addUser(this);
47        addUser(def);
48    }
49}
50
51}
Note: See TracBrowser for help on using the repository browser.