source: icGREP/icgrep-devel/icgrep/pablo/pe_sel.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_sel.h>
8#include <pablo/codegenstate.h>
9
10namespace pablo {
11
12Sel::Sel(PabloAST* if_expr, PabloAST* t_expr, PabloAST* f_expr, PabloBlock * parent)
13: Statement(ClassTypeId::Sel, parent->makeName("sel"), parent)
14, mExprs({{if_expr, t_expr, f_expr}})
15{
16    if_expr->addUser(this);
17    t_expr->addUser(this);
18    f_expr->addUser(this);
19}
20
21PabloAST * OptimizeSel::operator()(PabloAST * if_expr, PabloAST * t_expr, PabloAST * f_expr, PabloBlock * pb) {
22    if (isa<Ones>(if_expr)) {
23        return t_expr;
24    }
25    else if (isa<Zeroes>(if_expr)){
26        return f_expr;       
27    }
28    else if (isa<Ones>(t_expr)) {
29    return pb->createOr(if_expr, f_expr);
30    }
31    else if (isa<Zeroes>(t_expr)){
32        return pb->createAnd(pb->createNot(if_expr), f_expr);
33    }
34    else if (isa<Ones>(f_expr)) {
35    return pb->createOr(pb->createNot(if_expr), t_expr);
36    }
37    else if (isa<Zeroes>(f_expr)){
38        return pb->createAnd(if_expr, t_expr);
39    }
40    else if (equals(t_expr, f_expr)) {
41        return t_expr;
42    }
43    else if (isa<Not>(t_expr) && equals(cast<Not>(t_expr)->getExpr(), f_expr)) {
44        return pb->createXor(if_expr, f_expr);
45    }
46    else if (isa<Not>(f_expr) && equals(t_expr, cast<Not>(f_expr)->getExpr())){
47        return pb->createXor(if_expr, f_expr);
48    }
49    return pb->createSelImm(if_expr, t_expr, f_expr);
50}
51
52}
Note: See TracBrowser for help on using the repository browser.