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

Last change on this file since 4272 was 4247, checked in by cameron, 4 years ago

All -> Zeroes, Ones

File size: 977 bytes
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
12PabloAST * OptimizeSel::operator()(PabloAST * if_expr, PabloAST * t_expr, PabloAST * f_expr) {
13    if (isa<Ones>(if_expr)) {
14        return t_expr;
15    }
16    else if (isa<Zeroes>(if_expr)){
17        return f_expr;       
18    }
19    else if (isa<Ones>(t_expr)) {
20        return cg.createOr(if_expr, f_expr);
21    }
22    else if (isa<Zeroes>(t_expr)){
23        return cg.createAnd(cg.createNot(if_expr), f_expr);   
24    }
25    else if (isa<Ones>(f_expr)) {
26        return cg.createOr(cg.createNot(if_expr), t_expr);
27    }
28    else if (isa<Zeroes>(f_expr)){
29        return cg.createAnd(if_expr, t_expr);       
30    }
31    else if (equals(t_expr, f_expr)) {
32        return t_expr;
33    }
34    return new Sel(if_expr, t_expr, f_expr);
35}
36
37}
Note: See TracBrowser for help on using the repository browser.