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

Last change on this file since 4861 was 4860, checked in by nmedfort, 4 years ago

Back up check in. Memory leaks should be fixed.

File size: 1.7 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 &>(mAllocator))
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        this->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 &>(mAllocator))
33{
34    for (PabloAST * def : mDefined) {
35        def->addUser(this);
36        this->addUser(def);
37    }
38}
39
40void If::addDefined(Assign * def) {
41    if (LLVM_LIKELY(std::find(mDefined.begin(), mDefined.end(), def) == mDefined.end())) {
42        mDefined.push_back(def);
43        def->addUser(this);
44        this->addUser(def);
45    }
46}
47
48void If::removeDefined(Assign * def) {
49    auto f = std::find(mDefined.begin(), mDefined.end(), def);
50    if (LLVM_LIKELY(f != mDefined.end())) {
51        mDefined.erase(f);
52        def->removeUser(this);
53        this->removeUser(def);
54    }
55}
56
57}
Note: See TracBrowser for help on using the repository browser.