source: icGREP/icgrep-devel/icgrep/pablo/pe_xor.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.1 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_xor.h>
8#include <pablo/codegenstate.h>
9
10namespace pablo {
11
12Xor::Xor(PabloAST * expr1, PabloAST * expr2, PabloBlock * parent)
13: Statement(ClassTypeId::Xor, parent->makeName("xor"), parent)
14, mExprs({{expr1, expr2}})
15{
16    expr1->addUser(this);
17    expr2->addUser(this);
18}
19
20PabloAST * OptimizeXor::operator()(PabloAST * expr1, PabloAST * expr2, PabloBlock * pb) {
21    if (isa<Ones>(expr1)) {
22        return pb->createNot(expr2);
23    }
24    else if (isa<Zeroes>(expr1)){
25        return expr2;       
26    }
27    else if (isa<Ones>(expr2)) {
28        return pb->createNot(expr1);
29    }
30    else if (isa<Zeroes>(expr2)){
31        return expr1;
32    }
33    else if (Not * not1 = dyn_cast<Not>(expr1)) {
34        if (Not * not2 = dyn_cast<Not>(expr2)) {
35            return pb->createXor(not1->getExpr(), not2->getExpr());
36        }
37    }
38    return pb->createXorImm(expr1, expr2);
39}
40
41}
Note: See TracBrowser for help on using the repository browser.