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

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

Carry manager refactoring, progress towards bit packing

File size: 4.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
26using namespace llvm;
27
28namespace pablo {
29
30class PabloBlock;
31
32
33
34class CarryManager {
35public:
36 
37    CarryManager(IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one, IDISA::IDISA_Builder * idb)
38    : mBuilder(b)
39    , mBitBlockType(bitBlockType)
40#ifdef PACKING
41    , mPackType(b->getIntNTy(PACK_SIZE))
42#endif
43    , mZeroInitializer(zero)
44    , mOneInitializer(one)
45    , iBuilder(idb)
46    , mPabloRoot(nullptr)
47    , mCurrentScope(nullptr)
48    , mCarryInfo(nullptr)
49    , mCurrentFrameIndex(0)
50    , mCarryDataPtr(nullptr)
51    , mBlockNoPtr(nullptr)
52    , mBlockNo(nullptr)
53    , mTotalCarryDataBitBlocks(0)
54    {
55
56    }
57   
58    unsigned initialize(PabloBlock * blk, Value * carryDataPtr); 
59   
60    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
61   
62    void generateBlockNoIncrement();
63   
64    Value * getBlockNoPtr();
65   
66    /* Entering and leaving scopes. */
67   
68    void enterScope(PabloBlock * blk);
69
70    void leaveScope();
71   
72/* Helper routines */
73
74
75Value * getCarryPack(unsigned packIndex);
76
77void CarryPackStore(unsigned packIndex);
78
79Value * genCarryInRange(unsigned carryBit_lo, unsigned carryRangeSize);
80 
81Value * genCarryInBit(unsigned carryBitPos);
82
83    /* Methods for processing individual carry-generating operations. */
84   
85    Value * getCarryOpCarryIn(int localIndex);
86
87    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
88
89    Value * advanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
90 
91    /* Methods for getting and setting carry summary values for If statements */
92   
93    bool blockHasCarries();
94   
95    Value * getCarrySummaryExpr();
96   
97    void generateCarryOutSummaryCodeIfNeeded();
98   
99    void addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
100   
101    /* Methods for load/store of carries for non-while blocks. */
102   
103    void ensureCarriesLoadedLocal();
104
105    void ensureCarriesStoredLocal();
106   
107    /* Methods for handling while statements */
108   
109    void ensureCarriesLoadedRecursive();
110
111    void initializeCarryDataPhisAtWhileEntry(BasicBlock * whileBodyFinalBlock);
112
113    void extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock);
114
115    void ensureCarriesStoredRecursive();
116
117   
118private:
119    IRBuilder <> * mBuilder;
120    VectorType * mBitBlockType;
121#ifdef PACKING
122    Type * mPackType;
123#endif
124    ConstantAggregateZero * mZeroInitializer;
125    Constant * mOneInitializer;
126    IDISA::IDISA_Builder * iBuilder;
127    PabloBlock * mPabloRoot;
128    PabloBlock * mCurrentScope;
129    PabloBlockCarryData * mCarryInfo;
130    unsigned mCurrentFrameIndex;
131    Value * mCarryDataPtr;
132    Value * mBlockNoPtr;
133    Value * mBlockNo;
134    unsigned mTotalCarryDataBitBlocks;
135   
136    std::vector<PabloBlockCarryData *> mCarryInfoVector;
137
138
139    std::vector<Value *> mCarryPackPtr;
140    std::vector<Value *> mCarryInPack;
141    std::vector<PHINode *> mCarryInPhis; 
142    std::vector<PHINode *> mCarryOutAccumPhis; 
143    std::vector<Value *> mCarryOutVector;
144
145    Value * unitAdvanceCarryInCarryOut(int localIndex, Value * strm);
146    Value * shortAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
147    Value * longAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
148   
149};
150
151}
152
153#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.