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

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

Dynamic selection of carry strategy options

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