source: icGREP/icgrep-devel/icgrep/pablo/pe_sel.cpp @ 4414

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

Minor changes towards maintaining UseDef? information.

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