Ignore:
Timestamp:
Jan 14, 2015, 3:58:52 PM (4 years ago)
Author:
nmedfort
Message:

Some code clean up and improvements to the CSE optimization.

File:
1 edited

Legend:

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

    r4416 r4419  
    55 */
    66
    7 #include "pabloAST.h"
    8 #include "pe_advance.h"
    9 #include "pe_and.h"
    10 #include "pe_call.h"
    11 #include "pe_matchstar.h"
    12 #include "pe_not.h"
    13 #include "pe_or.h"
    14 #include "pabloAST.h"
    15 #include "pe_scanthru.h"
    16 #include "pe_sel.h"
    17 #include "pe_var.h"
    18 #include "pe_xor.h"
    19 #include "pe_zeroes.h"
    20 #include "pe_ones.h"
     7#include <pablo/pabloAST.h>
    218#include <pablo/codegenstate.h>
    229#include <llvm/Support/Compiler.h>
     10
     11#include <pablo/printer_pablos.h>
    2312
    2413namespace pablo {
     
    207196
    208197Statement * Statement::eraseFromParent(const bool recursively) {
    209     Statement * next = removeFromParent();
     198
    210199    // remove this statement from its operands' users list
    211200    for (PabloAST * op : mOperand) {
    212201        op->removeUser(this);
    213         if (recursively && isa<Statement>(op) && op->getNumUses() == 0) {
    214             cast<Statement>(op)->eraseFromParent();
    215         }
    216     }
    217     return next;
    218 }
    219 
    220 void Statement::replaceWith(PabloAST * const expr) {
    221 
     202    }
     203
     204    if (recursively) {
     205        for (PabloAST * op : mOperand) {
     206            if (op->getNumUses() == 0 && isa<Statement>(op)) {
     207                cast<Statement>(op)->eraseFromParent(true);
     208            }
     209        }
     210    }
     211
     212    return removeFromParent();
     213}
     214
     215Statement * Statement::replaceWith(PabloAST * const expr) {
    222216    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;
    232         if (LLVM_LIKELY(mPrev != nullptr)) {
    233             mPrev->mNext = stmt;
    234         }
    235         if (LLVM_LIKELY(mNext != nullptr)) {
    236             mNext->mPrev = stmt;
    237         }
    238         mParent=nullptr;
    239         mNext=nullptr;
    240         mPrev=nullptr;
    241     }
    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 
     217        return getNextNode();
     218    }
     219    replaceAllUsesWith(expr);
     220    return eraseFromParent();
    259221}
    260222
Note: See TracChangeset for help on using the changeset viewer.