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