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

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

UnicodeSet? bug fix and compile warning clean-up.

File size: 2.0 KB
RevLine 
[4404]1#include <pablo/ps_if.h>
2#include <pablo/codegenstate.h>
[4416]3#include <pablo/ps_assign.h>
[4404]4
5namespace pablo {
6
[5037]7If::DefinedAllocator If::mDefinedAllocator;
8
[4870]9If::If(PabloAST * expr, const std::initializer_list<Assign *> definedVars, PabloBlock * body)
[4650]10: Statement(ClassTypeId::If, {expr}, nullptr)
[4404]11, mBody(body)
[5037]12, mDefined(definedVars.begin(), definedVars.end(), mDefinedAllocator) {
[4415]13    // Conceptually, having a defined var X is identical to having:
14    //
15    // Assign(X, 0)
16    // If (...)
17    //    Next(Assign(X), ...)
18    //
19    // Since the implied 'Next' node is a user of the Assign node, and the Assign node is
[4419]20    // embedded into the If, the defined var is a user of the If node. However, since the
21    // Assign's value is also dependant on the 'Next' value, the If node is also a user
22    // of it.
[4896]23    mBody->setBranch(this);
[4878]24    mBody->setParent(getParent());
[4876]25    for (Assign * def : mDefined) {
[4764]26        def->addUser(this);
[4856]27        this->addUser(def);
[4415]28    }
[4404]29}
30
[4870]31If::If(PabloAST * expr, const std::vector<Assign *> & definedVars, PabloBlock * body)
[4650]32: Statement(ClassTypeId::If, {expr}, nullptr)
[4511]33, mBody(body)
[5037]34, mDefined(definedVars.begin(), definedVars.end(), mDefinedAllocator) {
[4896]35    mBody->setBranch(this);
[4878]36    mBody->setParent(getParent());
[4876]37    for (Assign * def : mDefined) {
[4764]38        def->addUser(this);
[4856]39        this->addUser(def);
[4511]40    }
41}
[4416]42
[4764]43void If::addDefined(Assign * def) {
[4856]44    if (LLVM_LIKELY(std::find(mDefined.begin(), mDefined.end(), def) == mDefined.end())) {
[4764]45        mDefined.push_back(def);
46        def->addUser(this);
[4856]47        this->addUser(def);
[4764]48    }
49}
[4419]50
[4868]51If::DefinedVars::iterator If::removeDefined(Assign * def) {
[4856]52    auto f = std::find(mDefined.begin(), mDefined.end(), def);
53    if (LLVM_LIKELY(f != mDefined.end())) {
54        def->removeUser(this);
55        this->removeUser(def);
[4868]56        return mDefined.erase(f);
[4856]57    }
[4868]58    return mDefined.end();
[4416]59}
[4856]60
[4870]61PabloBlock * If::setBody(PabloBlock * body) {
62    body->setParent(mBody->getParent());
63    std::swap(mBody, body);
64    body->setParent(nullptr);
65    return body;
[4856]66}
[4870]67
68}
Note: See TracBrowser for help on using the repository browser.