source: icGREP/icgrep-devel/icgrep/pablo/carry_data.cpp @ 4596

Last change on this file since 4596 was 4595, checked in by cameron, 4 years ago

Restructure compilation of while statements.

File size: 4.6 KB
Line 
1/*
2 *  Copyright (c) 2015 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
8#include <include/simd-lib/bitblock.hpp>
9#include <pablo/pablo_compiler.h>
10#include <pablo/codegenstate.h>
11#include <pablo/carry_data.h>
12#include <iostream>
13
14namespace pablo {
15 
16unsigned PabloBlockCarryData::enumerate(PabloBlock & blk) {
17    for (Statement * stmt : blk) {
18        if (Advance * adv = dyn_cast<Advance>(stmt)) {
19            unsigned shift_amount = adv->getAdvanceAmount();
20            if (shift_amount == 1) {
21                adv->setLocalAdvanceIndex(unitAdvances);
22                unitAdvances++;               
23            }
24            else if (shift_amount < LongAdvanceBase) {
25                //EnsurePackHasSpace(shortAdvanceTotal, shift_amount);
26                //adv->setLocalAdvanceIndex(shortAdvanceTotal);
27                adv->setLocalAdvanceIndex(shortAdvances);
28                shortAdvances++;
29                shortAdvanceTotal += shift_amount;
30            }
31            else {
32                adv->setLocalAdvanceIndex(longAdvanceTotalBlocks);
33                longAdvances++;
34                longAdvanceTotalBlocks += longAdvanceBufferSize(shift_amount);
35            }
36        }
37        else if (MatchStar * m = dyn_cast<MatchStar>(stmt)) {
38            m->setLocalCarryIndex(localCarries);
39            ++localCarries;
40        }
41        else if (ScanThru * s = dyn_cast<ScanThru>(stmt)) {
42            s->setLocalCarryIndex(localCarries);
43            ++localCarries;
44        }
45    }
46    unsigned localCarryDataIndex = localCarries + unitAdvances + shortAdvances + longAdvanceTotalBlocks;
47    localCarryDataSize = localCarryDataIndex;
48    /*
49    totalCarryDataSize = longAdvanceTotalBlocks * BLOCK_SIZE;
50    totalCarryDataSize += shortAdvanceTotal;
51    EnsurePackHasSpace(totalCarryDataSize, localCarries);
52    totalCarryDataSize += localCarries;
53    EnsurePackHasSpace(totalCarryDataSize, unitAdvances);
54    totalCarryDataSize += unitAdvances;
55     */
56   
57    for (Statement * stmt : blk) {
58        if (If * ifStatement = dyn_cast<If>(stmt)) {
59            PabloBlockCarryData & nestedBlockData = ifStatement->getBody().carryData;
60            nestedBlockData.setIfDepth(ifDepth + 1);
61            nestedBlockData.setBlockCarryDataIndex(blockCarryDataIndex + localCarryDataIndex);
62            const unsigned ifCarryDataSize = nestedBlockData.enumerate(ifStatement->getBody());
63            nestedBlockCount++;
64            //EnsurePackHasSpace(totalCarryDataSize, ifCarryDataSize);
65            nestedCarryDataSize += ifCarryDataSize;
66            localCarryDataIndex += ifCarryDataSize;           
67        }
68        else if (While * whileStatement = dyn_cast<While>(stmt)) {
69            PabloBlockCarryData & nestedBlockData = whileStatement->getBody().carryData;
70            nestedBlockData.setWhileDepth(whileDepth + 1);
71            nestedBlockData.setBlockCarryDataIndex(blockCarryDataIndex + localCarryDataIndex);
72            unsigned whileCarryDataSize = nestedBlockData.enumerate(whileStatement->getBody());
73            //if (whileStatement->isMultiCarry()) whileCarryDataSize *= whileStatement->getMaxIterations();
74            nestedBlockCount++;
75            //EnsurePackHasSpace(totalCarryDataSize, whileCarryDataSize);
76            nestedCarryDataSize += whileCarryDataSize;
77            localCarryDataIndex += whileCarryDataSize;
78        }
79    }
80    totalCarryDataSize = localCarryDataIndex;
81    if ((ifDepth > 0) && (totalCarryDataSize > 1)) {
82        // Need extra space for the summary variable, always the last
83        // entry within an if block.
84        totalCarryDataSize += 1;
85    }
86    longAdvanceOffset = 0;
87    /*
88    if (totalCarryDataSize > CarryPackSize) {
89        // Need extra space for the summary variable, always the first
90        // entry within an if block.
91        totalCarryDataSize += BLOCK_SIZE;
92        longAdvanceOffset = BLOCK_SIZE;
93    }
94     */
95    carryOffset = longAdvanceOffset + longAdvanceTotalBlocks;
96    unitAdvanceOffset = carryOffset + localCarries;
97    shortAdvanceOffset = unitAdvanceOffset + unitAdvances;
98
99//     std::cerr << "blockCarryDataIndex = " << blockCarryDataIndex << " nestedBlockCount = " << nestedBlockCount << std::endl;
100//     std::cerr << "longAdvanceOffset = " << longAdvanceOffset << " carryOffset = " << carryOffset << std::endl;
101//     std::cerr << "unitAdvanceOffset = " << unitAdvanceOffset << " shortAdvanceOffset = " << shortAdvanceOffset << std::endl;
102//     std::cerr << "ifDepth = " << ifDepth << " whileDepth = " << whileDepth << std::endl;
103//     std::cerr << "totalCarryDataSize = " << totalCarryDataSize << std::endl;
104    return totalCarryDataSize;
105}
106
107}
Note: See TracBrowser for help on using the repository browser.