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

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

Encapsulating all-zeroes and all-ones initializers within IDISA builder

File size: 5.2 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, IDISA::IDISA_Builder * idb)
43    : mPACK_SIZE(BLOCK_SIZE)
44    , mITEMS_PER_PACK(1)
45    , mBuilder(b)
46    , iBuilder(idb)
47    , mPackBuilder(idb)
48    , mBitBlockType(idb->getBitBlockType())
49    , mPabloRoot(nullptr)
50    , mCurrentScope(nullptr)
51    , mCarryInfo(nullptr)
52    , mCurrentFrameIndex(0)
53    , mCarryPackBasePtr(nullptr)
54    , mCarryBitBlockPtr(nullptr)
55    , mPopcountBasePtr(nullptr)
56    , mBlockNoPtr(nullptr)
57    , mBlockNo(nullptr)
58    , mPabloCountCount(0)
59    , mTotalCarryDataBitBlocks(0)
60    , mCarryDataAllocationSize(0)
61    {
62
63    }
64
65    ~CarryManager();
66   
67    void initialize(Module * m, PabloBlock * blk);
68   
69    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
70   
71    void generateBlockNoIncrement();   
72    Value * getBlockNoPtr();
73   
74    /* Entering and leaving scopes. */
75   
76    void enterScope(PabloBlock * blk);
77    void leaveScope();
78   
79    /* Methods for processing individual carry-generating operations. */
80   
81    Value * getCarryOpCarryIn(int localIndex);
82    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
83    Value * addCarryInCarryOut(int localIndex, Value* e1, Value* e2);
84
85
86    Value * advanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
87 
88    /* Methods for getting and setting carry summary values for If statements */
89   
90    bool blockHasCarries();
91   
92    void initializeCarryDataAtIfEntry();
93   
94    Value * getCarrySummaryExpr();
95   
96    void generateCarryOutSummaryCodeIfNeeded();
97   
98    void buildCarryDataPhisAfterIfBody(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
99   
100    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
101   
102    /* Methods for handling while statements */
103   
104    void ensureCarriesLoadedRecursive();
105
106    void initializeCarryDataPhisAtWhileEntry(BasicBlock * whileBodyFinalBlock);
107
108    void extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock);
109
110    void ensureCarriesStoredRecursive();
111
112    void ensureCarriesStoredLocal();
113   
114    Value * popCount(Value * to_count, unsigned globalIdx);
115   
116    Value * declareCarryDataArray(Module * m);
117
118   
119private:
120    unsigned mPACK_SIZE;
121    unsigned mITEMS_PER_PACK;
122    IRBuilder <> * mBuilder;
123    IDISA::IDISA_Builder * iBuilder;
124    IDISA::IDISA_Builder * mPackBuilder;
125    Type * mBitBlockType;
126    PabloBlock * mPabloRoot;
127    PabloBlock * mCurrentScope;
128    PabloBlockCarryData * mCarryInfo;
129    unsigned mCurrentFrameIndex;
130    Value * mCarryPackBasePtr;
131    Type * mCarryPackType;
132    Value * mCarryBitBlockPtr;
133    Value * mPopcountBasePtr;
134    Value * mBlockNoPtr;
135    Value * mBlockNo;
136    unsigned mPabloCountCount; // Number of Pablo "Count" operations
137    unsigned mTotalCarryDataBitBlocks;
138    unsigned mCarryDataAllocationSize;
139   
140    std::vector<PabloBlockCarryData *> mCarryInfoVector;
141
142
143    std::vector<Value *> mCarryPackPtr;
144    std::vector<Value *> mCarryInPack;
145    std::vector<PHINode *> mCarryInPhis; 
146    std::vector<PHINode *> mCarryOutAccumPhis; 
147    std::vector<Value *> mCarryOutPack;
148
149    Value * unitAdvanceCarryInCarryOut(int localIndex, Value * strm);
150    Value * shortAdvanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
151    Value * longAdvanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
152   
153   
154    /* Helper routines */
155    Value * getCarryPack(unsigned packIndex);
156    void storeCarryPack(unsigned packIndex);
157   
158    Value * maskSelectBitRange(Value * pack, unsigned lo_bit, unsigned bitCount);     
159    Value * getCarryInBits(unsigned carryBitPos, unsigned bits);
160    void extractAndSaveCarryOutBits(Value * strm, unsigned carryBit_lo, unsigned carryBitCount);
161    Value * pack2bitblock(Value * pack);
162    Value* genShiftLeft64(Value* e);
163
164
165    unsigned absPosition(unsigned frameOffsetinBits, unsigned relPos);
166    unsigned carryOpPosition(unsigned localIndex) ;
167    unsigned advance1Position(unsigned localIndex);
168    unsigned shortAdvancePosition(unsigned localIndex);
169    unsigned longAdvanceBitBlockPosition(unsigned localIndex);
170    unsigned localBasePack();
171    unsigned scopeBasePack();
172    unsigned summaryPackIndex();
173    unsigned summaryPosition();
174    unsigned summaryBits();
175};
176
177}
178
179#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.