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

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

Generating carry data initialization routine

File size: 5.3 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    void generateCarryDataInitializer(Module * m);
70   
71    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
72   
73    void generateBlockNoIncrement();   
74    Value * getBlockNoPtr();
75   
76    /* Entering and leaving scopes. */
77   
78    void enterScope(PabloBlock * blk);
79    void leaveScope();
80   
81    /* Methods for processing individual carry-generating operations. */
82   
83    Value * getCarryOpCarryIn(int localIndex);
84    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
85    Value * addCarryInCarryOut(int localIndex, Value* e1, Value* e2);
86
87
88    Value * advanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
89 
90    /* Methods for getting and setting carry summary values for If statements */
91   
92    bool blockHasCarries();
93   
94    void initializeCarryDataAtIfEntry();
95   
96    Value * getCarrySummaryExpr();
97   
98    void generateCarryOutSummaryCodeIfNeeded();
99   
100    void buildCarryDataPhisAfterIfBody(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
101   
102    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
103   
104    /* Methods for handling while statements */
105   
106    void ensureCarriesLoadedRecursive();
107
108    void initializeCarryDataPhisAtWhileEntry(BasicBlock * whileBodyFinalBlock);
109
110    void extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock);
111
112    void ensureCarriesStoredRecursive();
113
114    void ensureCarriesStoredLocal();
115   
116    Value * popCount(Value * to_count, unsigned globalIdx);
117   
118    Value * declareCarryDataArray(Module * m);
119
120   
121private:
122    unsigned mPACK_SIZE;
123    unsigned mITEMS_PER_PACK;
124    IRBuilder <> * mBuilder;
125    IDISA::IDISA_Builder * iBuilder;
126    IDISA::IDISA_Builder * mPackBuilder;
127    Type * mBitBlockType;
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.