source: icGREP/icgrep-devel/icgrep/llvm_gen_helper.cpp @ 4207

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

Minor changes; moved printers to re and pablo folders.

File size: 2.7 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 "llvm_gen_helper.h"
8
9//Pablo Expressions
10#include <pablo/codegenstate.h>
11#include <pablo/pe_pabloe.h>
12#include <pablo/pe_advance.h>
13#include <pablo/pe_and.h>
14#include <pablo/pe_charclass.h>
15#include <pablo/pe_not.h>
16#include <pablo/pe_or.h>
17#include <pablo/pe_matchstar.h>
18#include <pablo/pe_scanthru.h>
19
20//Pablo Statements
21#include <pablo/ps_assign.h>
22#include <pablo/ps_if.h>
23#include <pablo/ps_while.h>
24
25using namespace pablo;
26
27LLVM_Generator_Helper::LLVM_Generator_Helper(){}
28
29int LLVM_Generator_Helper::CarryCount_PabloStatements(std::list<PabloE *> stmts)
30{
31    int retVal = 0;
32    for (auto it = stmts.begin(); it != stmts.end(); ++it)
33    {
34        retVal += CarryCount_PabloS(*it);
35    }
36
37    return retVal;
38}
39
40int LLVM_Generator_Helper::CarryCount_PabloS(PabloE *stmt)
41{
42    int retVal = 0;
43
44    if (Assign* sm = dyn_cast<Assign>(stmt))
45    {
46        retVal = CarryCount_PabloE(sm->getExpr());
47    }
48    else if (If* ifstmt = dyn_cast<If>(stmt)) {
49        retVal = CarryCount_PabloE(ifstmt->getExpr());
50        retVal += CarryCount_PabloStatements(ifstmt->getPSList());
51        // If there is more than one internal carry, we create a stored
52        // accumulator value that Ors together all the carries, so add 1
53        // to the carry count.
54        if (retVal > 1) retVal++;
55    }
56    else if (While* whl = dyn_cast<While>(stmt))
57    {
58        retVal = CarryCount_PabloE(whl->getExpr());
59        retVal += CarryCount_PabloStatements(whl->getPSList());
60    }
61
62    return retVal;
63}
64
65int LLVM_Generator_Helper::CarryCount_PabloE(PabloE* expr)
66{
67    int retVal = 0;
68
69    if (And* pablo_and = dyn_cast<And>(expr))
70    {
71        retVal =  CarryCount_PabloE(pablo_and->getExpr1()) + CarryCount_PabloE(pablo_and->getExpr2());
72    }
73    else if (Or* pablo_or = dyn_cast<Or>(expr))
74    {
75        retVal = CarryCount_PabloE(pablo_or->getExpr1()) + CarryCount_PabloE(pablo_or->getExpr2());
76    }
77    else if (Not* pablo_not = dyn_cast<Not>(expr))
78    {
79        retVal = CarryCount_PabloE(pablo_not->getExpr());
80    }
81    else if (Advance* adv = dyn_cast<Advance>(expr))
82    {
83        //Carry queues are needed for advances.
84        retVal = 1 + CarryCount_PabloE(adv->getExpr());
85    }
86    else if(MatchStar* mstar = dyn_cast<MatchStar>(expr))
87    {
88        //Carry queues are also needed for MatchStar.
89        retVal = 1 + CarryCount_PabloE(mstar->getExpr1()) + CarryCount_PabloE(mstar->getExpr2());
90    }
91    else if (ScanThru* sthru = dyn_cast<ScanThru>(expr))
92    {
93        retVal = 1 + CarryCount_PabloE(sthru->getScanFrom()) + CarryCount_PabloE(sthru->getScanThru());
94    }
95
96    return retVal;
97}
98
99
Note: See TracBrowser for help on using the repository browser.