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

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

Carry Manager progress

File size: 3.5 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 <codegenstate.h>
13
14/*
15 * Carry Data Manager.
16 *
17 * Each PabloBlock (Main, If, While) has a contiguous data area for carry information.
18 * The data area may be at a fixed or variable base offset from the base of the
19 * main function carry data area.
20 * The data area for each block consists of contiguous space for the local carries and
21 * advances of the block plus the areas of any ifs/whiles nested within the block.
22
23*/
24
25using namespace llvm;
26
27namespace pablo {
28
29class PabloBlock;
30
31class CarryManager {
32public:
33 
34    CarryManager(IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one, IDISA::IDISA_Builder * idb)
35    : mBuilder(b)
36    , mBitBlockType(bitBlockType)
37    , mZeroInitializer(zero)
38    , mOneInitializer(one)
39    , iBuilder(idb)
40    , mPabloRoot(nullptr)
41    , mCurrentScope(nullptr)
42    , mCarryInfo(nullptr)
43    , mCurrentScopeIndex(0)
44    , mCarryDataPtr(nullptr)
45    , mBlockNoPtr(nullptr)
46    , mBlockNo(nullptr)
47    , mTotalCarryDataSize(0)
48    {
49
50    }
51   
52    unsigned initialize(PabloBlock * blk, Value * carryDataPtr); 
53   
54    void generateBlockNoIncrement();
55   
56    Value * getBlockNoPtr();
57   
58    /* Entering and leaving scopes. */
59   
60    void enterScope(PabloBlock * blk);
61
62    void leaveScope();
63   
64    /* Methods for processing individual carry-generating operations. */
65   
66    Value * getCarryOpCarryIn(int localIndex);
67
68    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
69
70    Value * advanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
71 
72    /* Methods for getting and setting carry summary values for If statements */
73   
74    bool blockHasCarries();
75   
76    Value * getCarrySummaryExpr();
77   
78    void generateCarryOutSummaryCode();
79   
80    bool summaryNeededInParentBlock();
81   
82    void addSummaryPhi(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock);
83   
84    /* Methods for load/store of carries for non-while blocks. */
85   
86    void ensureCarriesLoadedLocal();
87
88    void ensureCarriesStoredLocal();
89   
90    /* Methods for handling while statements */
91   
92    void ensureCarriesLoadedRecursive();
93
94    void initializeCarryDataPhisAtWhileEntry(BasicBlock * whileBodyFinalBlock);
95
96    void extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock);
97
98    void ensureCarriesStoredRecursive();
99
100   
101private:
102    IRBuilder <> * mBuilder;
103    VectorType * mBitBlockType;
104    ConstantAggregateZero * mZeroInitializer;
105    Constant * mOneInitializer;
106    IDISA::IDISA_Builder * iBuilder;
107    PabloBlock * mPabloRoot;
108    PabloBlock * mCurrentScope;
109    PabloBlockCarryData * mCarryInfo;
110    unsigned mCurrentScopeIndex;
111    Value * mCarryDataPtr;
112    Value * mBlockNoPtr;
113    Value * mBlockNo;
114    unsigned mTotalCarryDataSize;
115
116    std::vector<Value *> mCarryInVector;
117    std::vector<PHINode *> mCarryInPhis; 
118    std::vector<PHINode *> mCarryOutAccumPhis; 
119    std::vector<Value *> mCarryOutVector;
120
121    Value * unitAdvanceCarryInCarryOut(int localIndex, Value * strm);
122    Value * shortAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
123    Value * longAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
124   
125};
126
127}
128
129#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.