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

Last change on this file since 5157 was 4959, checked in by nmedfort, 4 years ago

Initial modifications to Pablo Compiler and Kernel Builder to support circular buffers for Lookahead.

File size: 4.5 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#include <pablo/pablo_compiler.h>
8#include <pablo/codegenstate.h>
9#include <pablo/carry_data.h>
10#include <iostream>
11
12namespace pablo {
13
14void CarryData::enumerateLocal() {
15    for (Statement * stmt : *theScope) {
16        if (Advance * adv = dyn_cast<Advance>(stmt)) {
17            unsigned shift_amount = adv->getAmount();
18            if (shift_amount == 1) {
19                adv->setLocalIndex(unitAdvance.entries);
20                unitAdvance.entries++;               
21            }
22            else if (shift_amount < LongAdvanceBase) {
23                // short Advance
24                if (mItemsPerPack >= LongAdvanceBase) {
25                    // Packing is possible.   We will use the allocated bit position as
26                    // the index.
27                    if (roomInFinalPack(shortAdvance.allocatedBits) < shift_amount) {
28                        // Start a new pack.
29                        shortAdvance.allocatedBits = alignCeiling(shortAdvance.allocatedBits, mPackSize);
30                    }
31                    adv->setLocalIndex(shortAdvance.allocatedBits);
32                }
33                else {
34                    adv->setLocalIndex(shortAdvance.entries);
35                }
36                shortAdvance.entries++;
37                shortAdvance.allocatedBits += shift_amount;
38            }
39            else {
40                adv->setLocalIndex(longAdvance.allocatedBitBlocks);
41                longAdvance.entries++;
42                longAdvance.allocatedBitBlocks += longAdvanceBufferSize(shift_amount);
43            }
44        }
45        else if (MatchStar * m = dyn_cast<MatchStar>(stmt)) {
46            m->setLocalCarryIndex(addWithCarry.entries);
47            ++addWithCarry.entries;
48        }
49        else if (ScanThru * s = dyn_cast<ScanThru>(stmt)) {
50            s->setLocalCarryIndex(addWithCarry.entries);
51            ++addWithCarry.entries;
52        }
53    }
54    longAdvance.frameOffset = 0;
55    shortAdvance.frameOffset = longAdvance.frameOffset + longAdvance.allocatedBitBlocks * mPositionsPerBlock;
56    if (mItemsPerPack == mPackSize) {
57        addWithCarry.frameOffset = shortAdvance.frameOffset + shortAdvance.allocatedBits;
58        if (roomInFinalPack(addWithCarry.frameOffset) < addWithCarry.entries) {
59            addWithCarry.frameOffset = alignCeiling(addWithCarry.frameOffset, mPackSize);
60        }
61        unitAdvance.frameOffset = addWithCarry.frameOffset + addWithCarry.entries;
62        if (roomInFinalPack(unitAdvance.frameOffset) < unitAdvance.entries) {
63            unitAdvance.frameOffset = alignCeiling(unitAdvance.frameOffset, mPackSize);
64        }
65    }
66    else {
67        addWithCarry.frameOffset = shortAdvance.frameOffset + shortAdvance.entries;
68        unitAdvance.frameOffset = addWithCarry.frameOffset + addWithCarry.entries;
69
70    }
71    nested.frameOffset = unitAdvance.frameOffset + unitAdvance.entries;
72}
73       
74void CarryData::dumpCarryData(llvm::raw_ostream & strm) {
75    unsigned totalDepth = ifDepth + whileDepth;
76    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
77    strm << "scope index = " << theScope->getScopeIndex();
78    strm << " framePosition: " << framePosition << ", ifDepth: " << ifDepth << ", whileDepth:" << whileDepth << ", maxNestingDepth: " << maxNestingDepth << "\n";
79    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
80    strm << "longAdvance: offset = " << longAdvance.frameOffset << ", entries = " << longAdvance.entries << "\n";
81    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
82    strm << "shortAdvance: offset = " << shortAdvance.frameOffset << ", entries = " << shortAdvance.entries << "\n";
83    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
84    strm << "advance1: offset = " << unitAdvance.frameOffset << ", entries = " << unitAdvance.entries << "\n";
85    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
86    strm << "addWithCarry: offset = " << addWithCarry.frameOffset << ", entries = " << addWithCarry.entries << "\n";
87    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
88    strm << "nested: offset = " << nested.frameOffset << ", allocatedBits = " << nested.allocatedBits << "\n";
89    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
90    strm << "summary: offset = " << summary.frameOffset << "\n";
91    for (unsigned i = 0; i < totalDepth; i++) strm << "  ";
92    strm << "scopeCarryDataSize = " << scopeCarryDataSize  << "\n";
93    strm.flush();
94
95}
96
97}
Note: See TracBrowser for help on using the repository browser.