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

Last change on this file since 4941 was 4941, checked in by lindanl, 4 years ago

Some clean up.

File size: 5.1 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>
[4816]14#include <llvm/IR/Constants.h>
[4939]15#include "../kernels/kernel.h"
[4644]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
28using namespace llvm;
29
30namespace pablo {
31
32class PabloBlock;
33
[4687]34
35
[4644]36class CarryManager {
37public:
38 
[4898]39    CarryManager(IDISA::IDISA_Builder * idb)
40    : iBuilder(idb)
[4821]41    , mBitBlockType(idb->getBitBlockType())
[4925]42    , mBitBlockWidth(idb->getBitBlockWidth())
43    , mRootScope(nullptr)
[4670]44    , mCurrentScope(nullptr)
45    , mCarryInfo(nullptr)
[4691]46    , mCurrentFrameIndex(0)
[4698]47    , mCarryPackBasePtr(nullptr)
48    , mCarryBitBlockPtr(nullptr)
[4720]49    , mPopcountBasePtr(nullptr)
[4670]50    , mBlockNoPtr(nullptr)
51    , mBlockNo(nullptr)
[4720]52    , mPabloCountCount(0)
[4672]53    , mTotalCarryDataBitBlocks(0)
[4726]54    , mCarryDataAllocationSize(0)
[4939]55    , mFilePosIdx(2)
[4670]56    {
[4659]57
58    }
[4712]59
60    ~CarryManager();
[4644]61   
[4939]62    void initialize(PabloBlock * blk, KernelBuilder * kBuilder);
63
64    void initialize_setPtrs(KernelBuilder * kBuilder);
65
66    void set_BlockNo(KernelBuilder * kBuilder);
[4644]67   
[4689]68    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
[4941]69       
[4925]70    Value * getBlockNoPtr() const;
[4644]71   
[4670]72    /* Entering and leaving scopes. */
73   
[4925]74    void enterScope(PabloBlock * const scope);
[4670]75    void leaveScope();
76   
[4654]77    /* Methods for processing individual carry-generating operations. */
[4644]78   
[4925]79    Value * addCarryInCarryOut(const unsigned localIndex, Value * const e1, Value * const e2);
[4644]80
[4925]81    Value * advanceCarryInCarryOut(const unsigned localIndex, const unsigned shiftAmount, Value * const strm);
[4644]82 
83    /* Methods for getting and setting carry summary values for If statements */
84   
[4925]85    bool hasCarries() const;
86       
87    Value * generateSummaryTest(Value * condition);
[4644]88   
[4925]89    void storeCarryOutSummary();
90
[4927]91    void addOuterSummaryToNestedSummary();
[4925]92
93    void buildCarryDataPhisAfterIfBody(BasicBlock * const entry, BasicBlock * const end);
94       
[4644]95    /* Methods for handling while statements */
96   
[4670]97    void ensureCarriesLoadedRecursive();
[4644]98
[4925]99    void initializeWhileEntryCarryDataPhis(BasicBlock * const end);
[4644]100
[4925]101    void finalizeWhileBlockCarryDataPhis(BasicBlock * const end);
[4644]102
[4670]103    void ensureCarriesStoredRecursive();
[4644]104   
[4720]105    Value * popCount(Value * to_count, unsigned globalIdx);
106   
[4726]107    Value * declareCarryDataArray(Module * m);
108
[4925]109protected:
110
111    Value * shortAdvanceCarryInCarryOut(const unsigned index, const unsigned shiftAmount, Value * const value);
112    Value * longAdvanceCarryInCarryOut(const unsigned index, const unsigned shiftAmount, Value * const value);
113
114    /* Methods for processing individual carry-generating operations. */
115
116    Value * getCarryIn(const unsigned localIndex);
117    void setCarryOut(const unsigned idx, Value * carryOut);
118
119    /* Helper routines */
120    Value * getCarryPack(const unsigned packIndex);
121    void storeCarryOut(const unsigned packIndex);
[4726]122   
[4925]123    Value * addToSummary(Value * const value);
124
125    bool hasSummary() const;
126    unsigned relativeFrameOffset(const unsigned frameOffset, const unsigned index) const;
127    unsigned addPosition(const unsigned localIndex) const;
128    unsigned unitAdvancePosition(const unsigned localIndex) const;
129    unsigned shortAdvancePosition(const unsigned localIndex) const;
130    unsigned longAdvancePosition(const unsigned localIndex) const;
131    unsigned localBasePack() const;
132    unsigned scopeBasePack() const;
133    unsigned summaryPack() const;
134
[4644]135private:
[4925]136    IDISA::IDISA_Builder * const iBuilder;
137    Type * const mBitBlockType;
138    const unsigned mBitBlockWidth;
139    PabloBlock * mRootScope;
[4670]140    PabloBlock * mCurrentScope;
[4925]141    CarryData * mCarryInfo;
[4691]142    unsigned mCurrentFrameIndex;
[4698]143    Value * mCarryPackBasePtr;
[4700]144    Type * mCarryPackType;
[4698]145    Value * mCarryBitBlockPtr;
[4720]146    Value * mPopcountBasePtr;
[4654]147    Value * mBlockNoPtr;
148    Value * mBlockNo;
[4720]149    unsigned mPabloCountCount; // Number of Pablo "Count" operations
[4672]150    unsigned mTotalCarryDataBitBlocks;
[4726]151    unsigned mCarryDataAllocationSize;
[4925]152    std::vector<CarryData *> mCarryInfoVector;
[4694]153    std::vector<Value *> mCarryPackPtr;
154    std::vector<Value *> mCarryInPack;
[4925]155    std::vector<PHINode *> mCarryInPhis;
156    std::vector<PHINode *> mCarryOutAccumPhis;
[4696]157    std::vector<Value *> mCarryOutPack;
[4925]158    std::vector<Value *> mCarrySummary;
[4939]159    int mCdArrayIdx;
160    int mPcArrayIdx;
161    int mFilePosIdx;
[4925]162};
[4654]163
[4925]164inline bool CarryManager::hasCarries() const {
165    return mCarryInfo->hasCarries();
166}
[4696]167
[4925]168inline Value * CarryManager::getBlockNoPtr() const {
169    return mBlockNoPtr;
170}
[4708]171
[4644]172}
173
174#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.