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

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

Clean ups

File size: 5.4 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#include <llvm/IR/Constants.h>
15
16
17/*
18 * Carry Data Manager.
19 *
20 * Each PabloBlock (Main, If, While) has a contiguous data area for carry information.
21 * The data area may be at a fixed or variable base offset from the base of the
22 * main function carry data area.
23 * The data area for each block consists of contiguous space for the local carries and
24 * advances of the block plus the areas of any ifs/whiles nested within the block.
25
26*/
27
28enum CarryManagerStrategy {BitBlockStrategy, SequentialFullyPackedStrategy};
29
30
31using namespace llvm;
32
33namespace pablo {
34
35class PabloBlock;
36
37
38
39class CarryManager {
40public:
41 
42    CarryManager(IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, IDISA::IDISA_Builder * idb)
43    : mPACK_SIZE(BLOCK_SIZE)
44    , mITEMS_PER_PACK(1)
45    , mBuilder(b)
46    , mBitBlockType(bitBlockType)
47    , mZeroInitializer(zero)
48    , mOneInitializer(ConstantVector::getAllOnesValue(bitBlockType))
49    , iBuilder(idb)
50    , mPabloRoot(nullptr)
51    , mCurrentScope(nullptr)
52    , mCarryInfo(nullptr)
53    , mCurrentFrameIndex(0)
54    , mCarryPackBasePtr(nullptr)
55    , mCarryBitBlockPtr(nullptr)
56    , mPopcountBasePtr(nullptr)
57    , mBlockNoPtr(nullptr)
58    , mBlockNo(nullptr)
59    , mPabloCountCount(0)
60    , mTotalCarryDataBitBlocks(0)
61    , mCarryDataAllocationSize(0)
62    {
63
64    }
65
66    ~CarryManager();
67   
68    void initialize(Module * m, PabloBlock * blk);
69   
70    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
71   
72    void generateBlockNoIncrement();   
73    Value * getBlockNoPtr();
74   
75    /* Entering and leaving scopes. */
76   
77    void enterScope(PabloBlock * blk);
78    void leaveScope();
79   
80    /* Methods for processing individual carry-generating operations. */
81   
82    Value * getCarryOpCarryIn(int localIndex);
83    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
84    Value * addCarryInCarryOut(int localIndex, Value* e1, Value* e2);
85
86
87    Value * advanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
88 
89    /* Methods for getting and setting carry summary values for If statements */
90   
91    bool blockHasCarries();
92   
93    void initializeCarryDataAtIfEntry();
94   
95    Value * getCarrySummaryExpr();
96   
97    void generateCarryOutSummaryCodeIfNeeded();
98   
99    void buildCarryDataPhisAfterIfBody(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
100   
101    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
102   
103    /* Methods for handling while statements */
104   
105    void ensureCarriesLoadedRecursive();
106
107    void initializeCarryDataPhisAtWhileEntry(BasicBlock * whileBodyFinalBlock);
108
109    void extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock);
110
111    void ensureCarriesStoredRecursive();
112
113    void ensureCarriesStoredLocal();
114   
115    Value * popCount(Value * to_count, unsigned globalIdx);
116   
117    Value * declareCarryDataArray(Module * m);
118
119   
120private:
121    unsigned mPACK_SIZE;
122    unsigned mITEMS_PER_PACK;
123    IRBuilder <> * mBuilder;
124    VectorType * mBitBlockType;
125    Constant * mZeroInitializer;
126    Constant * mOneInitializer;
127    IDISA::IDISA_Builder * iBuilder;
128    PabloBlock * mPabloRoot;
129    PabloBlock * mCurrentScope;
130    PabloBlockCarryData * mCarryInfo;
131    unsigned mCurrentFrameIndex;
132    Value * mCarryPackBasePtr;
133    Type * mCarryPackType;
134    Value * mCarryBitBlockPtr;
135    Value * mPopcountBasePtr;
136    Value * mBlockNoPtr;
137    Value * mBlockNo;
138    unsigned mPabloCountCount; // Number of Pablo "Count" operations
139    unsigned mTotalCarryDataBitBlocks;
140    unsigned mCarryDataAllocationSize;
141   
142    std::vector<PabloBlockCarryData *> mCarryInfoVector;
143
144
145    std::vector<Value *> mCarryPackPtr;
146    std::vector<Value *> mCarryInPack;
147    std::vector<PHINode *> mCarryInPhis; 
148    std::vector<PHINode *> mCarryOutAccumPhis; 
149    std::vector<Value *> mCarryOutPack;
150
151    Value * unitAdvanceCarryInCarryOut(int localIndex, Value * strm);
152    Value * shortAdvanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
153    Value * longAdvanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
154   
155   
156    /* Helper routines */
157    Value * getCarryPack(unsigned packIndex);
158    void storeCarryPack(unsigned packIndex);
159   
160    Value * maskSelectBitRange(Value * pack, unsigned lo_bit, unsigned bitCount);     
161    Value * getCarryInBits(unsigned carryBitPos, unsigned bits);
162    void extractAndSaveCarryOutBits(Value * strm, unsigned carryBit_lo, unsigned carryBitCount);
163    Value * pack2bitblock(Value * pack);
164    Value* genShiftLeft64(Value* e);
165
166
167    unsigned absPosition(unsigned frameOffsetinBits, unsigned relPos);
168    unsigned carryOpPosition(unsigned localIndex) ;
169    unsigned advance1Position(unsigned localIndex);
170    unsigned shortAdvancePosition(unsigned localIndex);
171    unsigned longAdvanceBitBlockPosition(unsigned localIndex);
172    unsigned localBasePack();
173    unsigned scopeBasePack();
174    unsigned summaryPackIndex();
175    unsigned summaryPosition();
176    unsigned summaryBits();
177};
178
179}
180
181#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.