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

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

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

File size: 1.4 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#include <pablo/pe_not.h>
10#include <pablo/pe_zeroes.h>
11#include <pablo/pe_ones.h>
12
13namespace pablo {
14
15And::And(PabloAST * expr1, PabloAST * expr2, PabloBlock * parent)
16: Statement(ClassTypeId::And, {{expr1, expr2}}, parent->makeName("and"), parent)
17{
18
19}
20
21PabloAST * OptimizeAnd::operator ()(PabloAST * expr1, PabloAST * expr2, PabloBlock * pb) {
22
23    assert (expr1 && expr2 && pb);
24
25    if (isa<Zeroes>(expr2) || isa<Ones>(expr1)) {
26        return expr2;
27    }
28    else if (isa<Zeroes>(expr1) || isa<Ones>(expr2)){
29        return expr1;
30    }
31    else if (equals(expr1, expr2)) {
32        return expr1;
33    }
34    else if (Not * not1 = dyn_cast<Not>(expr1)) {
35        if (Not * not2 = dyn_cast<Not>(expr2)) {
36            return pb->createNot(pb->createOr(not1->getExpr(), not2->getExpr()));
37        }
38        else if (equals(not1->getExpr(), expr2)) {
39            return pb->createZeroes();
40        }
41    }
42    else if (Not * not2 = dyn_cast<Not>(expr2)) {
43        if (equals(expr1, not2->getExpr())) {
44            return pb->createZeroes();
45        }
46    }
47    if (isa<Not>(expr1)) {
48        std::swap(expr1, expr2);
49    }
50    return pb->createAndImm(expr1, expr2);
51}
52
53}
Note: See TracBrowser for help on using the repository browser.