source: icGREP/icgrep-devel/icgrep/pablo/carry_manager.h @ 4704

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

Carry manager fixes, restructuring

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#ifndef CARRY_MANAGER_H
8#define CARRY_MANAGER_H
9#include <llvm/IR/IRBuilder.h>
10#include <llvm/IR/Module.h>
11#include <IDISA/idisa_builder.h>
12#include <pablo/codegenstate.h>
13#include <pablo/carry_data.h>
14
15/*
16 * Carry Data Manager.
17 *
18 * Each PabloBlock (Main, If, While) has a contiguous data area for carry information.
19 * The data area may be at a fixed or variable base offset from the base of the
20 * main function carry data area.
21 * The data area for each block consists of contiguous space for the local carries and
22 * advances of the block plus the areas of any ifs/whiles nested within the block.
23
24*/
25
26using namespace llvm;
27
28namespace pablo {
29
30class PabloBlock;
31
32
33
34class CarryManager {
35public:
36 
37    CarryManager(IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one, IDISA::IDISA_Builder * idb)
38    : mBuilder(b)
39    , mBitBlockType(bitBlockType)
40    , mZeroInitializer(zero)
41    , mOneInitializer(one)
42    , iBuilder(idb)
43    , mPabloRoot(nullptr)
44    , mCurrentScope(nullptr)
45    , mCarryInfo(nullptr)
46    , mCurrentFrameIndex(0)
47    , mCarryPackBasePtr(nullptr)
48#ifdef PACKING
49    , mCarryBitBlockPtr(nullptr)
50#endif
51    , mBlockNoPtr(nullptr)
52    , mBlockNo(nullptr)
53    , mTotalCarryDataBitBlocks(0)
54    {
55
56    }
57   
58    unsigned initialize(PabloBlock * blk, Value * carryDataPtr); 
59   
60    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
61   
62    void generateBlockNoIncrement();   
63    Value * getBlockNoPtr();
64   
65    /* Entering and leaving scopes. */
66   
67    void enterScope(PabloBlock * blk);
68    void leaveScope();
69   
70    /* Methods for processing individual carry-generating operations. */
71   
72    Value * getCarryOpCarryIn(int localIndex);
73    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
74
75    Value * advanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
76 
77    /* Methods for getting and setting carry summary values for If statements */
78   
79    bool blockHasCarries();
80   
81    void initializeCarryDataAtIfEntry();
82   
83    Value * getCarrySummaryExpr();
84   
85    void generateCarryOutSummaryCodeIfNeeded();
86   
87    void buildCarryDataPhisAfterIfBody(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
88   
89    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
90   
91    /* Methods for handling while statements */
92   
93    void ensureCarriesLoadedRecursive();
94
95    void initializeCarryDataPhisAtWhileEntry(BasicBlock * whileBodyFinalBlock);
96
97    void extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock);
98
99    void ensureCarriesStoredRecursive();
100
101   
102private:
103    IRBuilder <> * mBuilder;
104    VectorType * mBitBlockType;
105    Constant * mZeroInitializer;
106    Constant * mOneInitializer;
107    IDISA::IDISA_Builder * iBuilder;
108    PabloBlock * mPabloRoot;
109    PabloBlock * mCurrentScope;
110    PabloBlockCarryData * mCarryInfo;
111    unsigned mCurrentFrameIndex;
112    Value * mCarryPackBasePtr;
113#ifdef PACKING
114    Type * mCarryPackType;
115    Value * mCarryBitBlockPtr;
116#endif
117    Value * mBlockNoPtr;
118    Value * mBlockNo;
119    unsigned mTotalCarryDataBitBlocks;
120   
121    std::vector<PabloBlockCarryData *> mCarryInfoVector;
122
123
124    std::vector<Value *> mCarryPackPtr;
125    std::vector<Value *> mCarryInPack;
126    std::vector<PHINode *> mCarryInPhis; 
127    std::vector<PHINode *> mCarryOutAccumPhis; 
128    std::vector<Value *> mCarryOutPack;
129
130    Value * unitAdvanceCarryInCarryOut(int localIndex, Value * strm);
131    Value * shortAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
132    Value * longAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
133   
134   
135    /* Helper routines */
136    Value * getCarryPack(unsigned packIndex);
137    void storeCarryPack(unsigned packIndex);
138   
139    Value * getCarryRange(unsigned carryBit_lo, unsigned carryRangeSize);     
140    Value * getCarryBits(unsigned carryBitPos, unsigned bits);
141    Value * getCarryBit(unsigned carryBitPos);
142    void setCarryBits(unsigned carryBit_lo, unsigned carryRangeSize, Value * bits);
143
144    unsigned absPosition(unsigned frameOffsetinBits, unsigned relPos);
145    unsigned carryOpPosition(unsigned localIndex) ;
146    unsigned advance1Position(unsigned localIndex);
147    unsigned shortAdvancePosition(unsigned localIndex);
148    unsigned longAdvanceBitBlockPosition(unsigned localIndex);
149    unsigned localBasePack();
150    unsigned scopeBasePack();
151    unsigned summaryPosition();
152    unsigned summaryBits();
153
154};
155
156}
157
158#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.