source: icGREP/icgrep-devel/icgrep/pablo/pe_and.cpp @ 4410

Last change on this file since 4410 was 4410, checked in by nmedfort, 5 years ago

Changes to support 3-operand form for all instructions. CSE disabled but partially redundant now.

File size: 1.5 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <pablo/pe_and.h>
8#include <pablo/codegenstate.h>
9
10namespace pablo {
11
12And::And(PabloAST * expr1, PabloAST * expr2, PabloBlock * parent)
13: Statement(ClassTypeId::And, parent->makeName("and"), parent)
14, mExprs({{expr1, expr2}})
15{
16    expr1->addUser(this);
17    expr2->addUser(this);
18}
19
20PabloAST * OptimizeAnd::operator ()(PabloAST * expr1, PabloAST * expr2, PabloBlock * pb) {
21    if (isa<Ones>(expr1)) {
22        return expr2;
23    }
24    else if (isa<Zeroes>(expr1)){
25        return expr1;       
26    }
27    else if (isa<Ones>(expr2)) {
28        return expr1;
29    }
30    else if (isa<Zeroes>(expr2)){
31        return expr2;
32    }
33    else if (equals(expr1, expr2)) {
34        return expr1;
35    }
36    else if (Not * pe_not_e1 = dyn_cast<Not>(expr1)) {
37        if (Not * pe_not_e2 = dyn_cast<Not>(expr2)) {
38            return pb->createNot(pb->createOr(pe_not_e1->getExpr(), pe_not_e2->getExpr()));
39        }
40        else if (equals(pe_not_e1->getExpr(), expr2)) {
41            return pb->createZeroes();
42        }
43    }
44    else if (Not * pe_not_e2 = dyn_cast<Not>(expr2)) {
45        if (equals(expr1, pe_not_e2->getExpr())) {
46            return pb->createZeroes();
47        }
48    }
49    if (isa<Not>(expr1)) {
50        std::swap(expr1, expr2);
51    }
52    return pb->createAndImm(expr1, expr2);
53}
54
55}
Note: See TracBrowser for help on using the repository browser.