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

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

First stage of refactoring PabloE classes.

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 "pe_pabloe.h"
11#include "pe_advance.h"
12#include "pe_and.h"
13#include "pe_charclass.h"
14#include "pe_not.h"
15#include "pe_or.h"
16#include "pe_matchstar.h"
17#include "pe_scanthru.h"
18
19//Pablo Statements
20#include "ps_pablos.h"
21#include "ps_assign.h"
22#include "ps_if.h"
23#include "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 = dynamic_cast<Assign*>(stmt))
45    {
46        retVal = CarryCount_PabloE(sm->getExpr());
47    }
48    else if (If* ifstmt = dynamic_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 = dynamic_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 = dynamic_cast<And*>(expr))
70    {
71        retVal =  CarryCount_PabloE(pablo_and->getExpr1()) + CarryCount_PabloE(pablo_and->getExpr2());
72    }
73    else if (Or* pablo_or = dynamic_cast<Or*>(expr))
74    {
75        retVal = CarryCount_PabloE(pablo_or->getExpr1()) + CarryCount_PabloE(pablo_or->getExpr2());
76    }
77    else if (Not* pablo_not = dynamic_cast<Not*>(expr))
78    {
79        retVal = CarryCount_PabloE(pablo_not->getExpr());
80    }
81    else if (Advance* adv = dynamic_cast<Advance*>(expr))
82    {
83        //Carry queues are needed for advances.
84        retVal = 1 + CarryCount_PabloE(adv->getExpr());
85    }
86    else if(MatchStar* mstar = dynamic_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 = dynamic_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.