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

Last change on this file since 4713 was 4712, checked in by nmedfort, 4 years ago

Memory leak fix.

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