Ignore:
Timestamp:
Jan 13, 2015, 4:01:06 PM (4 years ago)
Author:
nmedfort
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r4415 r4416  
    111111}
    112112
    113 PabloAST * Statement::setOperand(const unsigned index, PabloAST * value) {
     113void PabloAST::replaceAllUsesWith(PabloAST * expr) {
     114    #ifndef NDEBUG
     115    unsigned __userCount = getNumUses();
     116    #endif
     117    while (!mUsers.empty()) {
     118        PabloAST * user = mUsers.pop_back_val();
     119        assert(--__userCount == getNumUses());
     120        if (isa<Statement>(user)) {
     121            cast<Statement>(user)->replaceUsesOfWith(this, expr);
     122        }
     123        assert(__userCount == getNumUses());
     124    }
     125    assert (getNumUses() == 0);
     126}
     127
     128void Statement::setOperand(const unsigned index, PabloAST * value) {
    114129    assert (index < getNumOperands());
    115     return mParent->setOperandOf(this, index, value);
     130    if (LLVM_UNLIKELY(mOperand[index] == value)) {
     131        return;
     132    }
     133    PabloAST * priorValue = mOperand[index];
     134    // Test just to be sure we don't have multiple operands pointing to
     135    // what we're replacing. If not, remove this from the prior value's
     136    // user list.
     137    unsigned count = 0;
     138    for (unsigned i = 0; i != getNumOperands(); ++i) {
     139        count += (mOperand[index] == priorValue) ? 1 : 0;
     140    }
     141    assert (count >= 1);
     142    if (LLVM_LIKELY(count == 1)) {
     143        priorValue->removeUser(this);
     144    }
     145    mOperand[index] = value;
     146    value->addUser(this);
    116147}
    117148
     
    150181}
    151182
    152 void Statement::removeFromParent() {
     183Statement * Statement::removeFromParent() {
     184    Statement * next = mNext;
    153185    if (LLVM_LIKELY(mParent != nullptr)) {
    154186        if (LLVM_UNLIKELY(mParent->mFirst == this)) {
     
    171203    mNext = nullptr;
    172204    mParent = nullptr;
    173 }
    174 
    175 void Statement::replaceWith(Statement * const statement) {
    176     if (statement != this) {
    177         statement->removeFromParent();
    178         statement->mParent = mParent;
    179         statement->mNext = mNext;
    180         statement->mPrev = mPrev;
     205    return next;
     206}
     207
     208Statement * Statement::eraseFromParent(const bool recursively) {
     209    Statement * next = removeFromParent();
     210    // remove this statement from its operands' users list
     211    for (PabloAST * op : mOperand) {
     212        op->removeUser(this);
     213        if (recursively && isa<Statement>(op) && op->getNumUses() == 0) {
     214            cast<Statement>(op)->eraseFromParent();
     215        }
     216    }
     217    return next;
     218}
     219
     220void Statement::replaceWith(PabloAST * const expr) {
     221
     222    if (LLVM_UNLIKELY(expr == this)) {
     223        return;
     224    }
     225
     226    if (isa<Statement>(expr)) {
     227        Statement * stmt = cast<Statement>(expr);
     228        stmt->removeFromParent();
     229        stmt->mParent = mParent;
     230        stmt->mNext = mNext;
     231        stmt->mPrev = mPrev;
    181232        if (LLVM_LIKELY(mPrev != nullptr)) {
    182             mPrev->mNext = statement;
     233            mPrev->mNext = stmt;
    183234        }
    184235        if (LLVM_LIKELY(mNext != nullptr)) {
    185             mNext->mPrev = statement;
     236            mNext->mPrev = stmt;
    186237        }
    187238        mParent=nullptr;
     
    189240        mPrev=nullptr;
    190241    }
     242    else {
     243        removeFromParent();
     244    }
     245
     246    // remove this statement from its operands' users list
     247    for (PabloAST * op : mOperand) {
     248        op->removeUser(this);
     249    }
     250
     251    while (!mUsers.empty()) {
     252        PabloAST * user = mUsers.pop_back_val();
     253        if (isa<Statement>(user)) {
     254            assert(std::count(cast<Statement>(user)->mOperand.begin(), cast<Statement>(user)->mOperand.end(), this) == 1);
     255            cast<Statement>(user)->replaceUsesOfWith(this, expr);
     256        }
     257    }
     258
    191259}
    192260
    193261Statement::~Statement() {
    194262
    195 }
    196 
    197 void StatementList::setInsertPoint(Statement * const statement) {
    198     mInsertionPoint = statement;
    199 }
    200 
    201 void StatementList::setInsertPoint(StatementList * const list) {
    202     mInsertionPoint = list->mLast;
    203263}
    204264
     
    220280}
    221281
    222 void StatementList::insertAfterLastOperand(Statement * const statement) {
    223     assert (false);
    224 }
    225 
    226 }
     282}
Note: See TracChangeset for help on using the changeset viewer.