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

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

Clean ups for compilation with gcc 4.8

File size: 5.3 KB
RevLine 
[4644]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>
[4654]10#include <llvm/IR/Module.h>
11#include <IDISA/idisa_builder.h>
[4683]12#include <pablo/codegenstate.h>
[4687]13#include <pablo/carry_data.h>
[4644]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
[4715]26enum CarryManagerStrategy {BitBlockStrategy, SequentialFullyPackedStrategy};
27
28
[4644]29using namespace llvm;
30
31namespace pablo {
32
33class PabloBlock;
34
[4687]35
36
[4644]37class CarryManager {
38public:
39 
[4663]40    CarryManager(IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one, IDISA::IDISA_Builder * idb)
[4715]41    : mPACK_SIZE(BLOCK_SIZE)
42    , mITEMS_PER_PACK(1)
43    , mBuilder(b)
[4659]44    , mBitBlockType(bitBlockType)
45    , mZeroInitializer(zero)
46    , mOneInitializer(one)
[4670]47    , iBuilder(idb)
48    , mPabloRoot(nullptr)
49    , mCurrentScope(nullptr)
50    , mCarryInfo(nullptr)
[4691]51    , mCurrentFrameIndex(0)
[4698]52    , mCarryPackBasePtr(nullptr)
53    , mCarryBitBlockPtr(nullptr)
[4720]54    , mPopcountBasePtr(nullptr)
[4670]55    , mBlockNoPtr(nullptr)
56    , mBlockNo(nullptr)
[4720]57    , mPabloCountCount(0)
[4672]58    , mTotalCarryDataBitBlocks(0)
[4726]59    , mCarryDataAllocationSize(0)
[4670]60    {
[4659]61
62    }
[4712]63
64    ~CarryManager();
[4644]65   
[4726]66    void initialize(Module * m, PabloBlock * blk);
[4644]67   
[4689]68    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
[4687]69   
[4696]70    void generateBlockNoIncrement();   
[4644]71    Value * getBlockNoPtr();
72   
[4670]73    /* Entering and leaving scopes. */
74   
75    void enterScope(PabloBlock * blk);
76    void leaveScope();
77   
[4654]78    /* Methods for processing individual carry-generating operations. */
[4644]79   
[4670]80    Value * getCarryOpCarryIn(int localIndex);
81    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
[4707]82    Value * addCarryInCarryOut(int localIndex, Value* e1, Value* e2);
[4644]83
[4707]84
[4750]85    Value * advanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
[4644]86 
87    /* Methods for getting and setting carry summary values for If statements */
88   
[4670]89    bool blockHasCarries();
[4644]90   
[4703]91    void initializeCarryDataAtIfEntry();
92   
[4670]93    Value * getCarrySummaryExpr();
[4644]94   
[4676]95    void generateCarryOutSummaryCodeIfNeeded();
[4644]96   
[4703]97    void buildCarryDataPhisAfterIfBody(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
98   
[4676]99    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
[4644]100   
101    /* Methods for handling while statements */
102   
[4670]103    void ensureCarriesLoadedRecursive();
[4644]104
[4670]105    void initializeCarryDataPhisAtWhileEntry(BasicBlock * whileBodyFinalBlock);
[4644]106
[4670]107    void extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock);
[4644]108
[4670]109    void ensureCarriesStoredRecursive();
[4644]110
[4710]111    void ensureCarriesStoredLocal();
[4644]112   
[4720]113    Value * popCount(Value * to_count, unsigned globalIdx);
114   
[4726]115    Value * declareCarryDataArray(Module * m);
116
117   
[4644]118private:
[4715]119    unsigned mPACK_SIZE;
120    unsigned mITEMS_PER_PACK;
[4654]121    IRBuilder <> * mBuilder;
122    VectorType * mBitBlockType;
[4700]123    Constant * mZeroInitializer;
[4654]124    Constant * mOneInitializer;
[4663]125    IDISA::IDISA_Builder * iBuilder;
[4654]126    PabloBlock * mPabloRoot;
[4670]127    PabloBlock * mCurrentScope;
128    PabloBlockCarryData * mCarryInfo;
[4691]129    unsigned mCurrentFrameIndex;
[4698]130    Value * mCarryPackBasePtr;
[4700]131    Type * mCarryPackType;
[4698]132    Value * mCarryBitBlockPtr;
[4720]133    Value * mPopcountBasePtr;
[4654]134    Value * mBlockNoPtr;
135    Value * mBlockNo;
[4720]136    unsigned mPabloCountCount; // Number of Pablo "Count" operations
[4672]137    unsigned mTotalCarryDataBitBlocks;
[4726]138    unsigned mCarryDataAllocationSize;
[4687]139   
140    std::vector<PabloBlockCarryData *> mCarryInfoVector;
[4654]141
[4687]142
[4694]143    std::vector<Value *> mCarryPackPtr;
144    std::vector<Value *> mCarryInPack;
[4654]145    std::vector<PHINode *> mCarryInPhis; 
146    std::vector<PHINode *> mCarryOutAccumPhis; 
[4696]147    std::vector<Value *> mCarryOutPack;
[4654]148
[4670]149    Value * unitAdvanceCarryInCarryOut(int localIndex, Value * strm);
[4750]150    Value * shortAdvanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
151    Value * longAdvanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * strm);
[4654]152   
[4696]153   
154    /* Helper routines */
155    Value * getCarryPack(unsigned packIndex);
156    void storeCarryPack(unsigned packIndex);
157   
[4707]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);
[4708]162    Value* genShiftLeft64(Value* e);
[4696]163
[4708]164
[4697]165    unsigned absPosition(unsigned frameOffsetinBits, unsigned relPos);
166    unsigned carryOpPosition(unsigned localIndex) ;
167    unsigned advance1Position(unsigned localIndex);
168    unsigned shortAdvancePosition(unsigned localIndex);
[4698]169    unsigned longAdvanceBitBlockPosition(unsigned localIndex);
[4700]170    unsigned localBasePack();
171    unsigned scopeBasePack();
[4710]172    unsigned summaryPackIndex();
[4697]173    unsigned summaryPosition();
174    unsigned summaryBits();
[4644]175};
176
177}
178
179#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.