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

Last change on this file since 5431 was 5431, checked in by nmedfort, 2 years ago

partial refactoring check in with change for Linda.

File size: 4.8 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
10#include <pablo/carry_data.h>
11#include <vector>
12namespace IDISA { class IDISA_Builder; }
13namespace llvm { class BasicBlock; }
14namespace llvm { class ConstantInt; }
15namespace llvm { class Function; }
16namespace llvm { class PHINode; }
17namespace llvm { class StructType; }
18namespace llvm { class Type; }
19namespace llvm { class Value; }
20namespace pablo { class Advance; }
21namespace pablo { class PabloBlock; }
22namespace pablo { class PabloKernel; }
23namespace pablo { class Statement; }
24
25/*
26 * Carry Data Manager.
27 *
28 * Each PabloBlock (Main, If, While) has a contiguous data area for carry information.
29 * The data area may be at a fixed or variable base offset from the base of the
30 * main function carry data area.
31 * The data area for each block consists of contiguous space for the local carries and
32 * advances of the block plus the areas of any ifs/whiles nested within the block.
33
34*/
35
36namespace pablo {
37
38class CarryManager {
39
40    enum { LONG_ADVANCE_BASE = 64 };
41
42public:
43 
44    CarryManager(PabloKernel * const kernel) noexcept;
45
46    void initializeCarryData();
47
48    void initializeCodeGen();
49
50    void finalizeCodeGen();
51
52    /* Entering and leaving loops. */
53
54    void enterLoopScope(const PabloBlock * const scope);
55
56    void enterLoopBody(llvm::BasicBlock * const entryBlock);
57
58    void leaveLoopBody(llvm::BasicBlock * const exitBlock);
59
60    void leaveLoopScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
61
62    /* Entering and leaving ifs. */
63
64    void enterIfScope(const PabloBlock * const scope);
65
66    void enterIfBody(llvm::BasicBlock * const entryBlock);
67
68    void leaveIfBody(llvm::BasicBlock * const exitBlock);
69
70    void leaveIfScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
71
72    /* Methods for processing individual carry-generating operations. */
73   
74    llvm::Value * addCarryInCarryOut(const Statement * operation, llvm::Value * const e1, llvm::Value * const e2);
75
76    llvm::Value * advanceCarryInCarryOut(const Advance * advance, llvm::Value * const strm);
77 
78    /* Methods for getting and setting carry summary values for If statements */
79         
80    llvm::Value * generateSummaryTest(llvm::Value * condition);
81
82protected:
83
84    static unsigned getScopeCount(PabloBlock * const scope, unsigned index = 0);
85
86    static bool hasIterationSpecificAssignment(const PabloBlock * const scope);
87
88    llvm::StructType * analyse(PabloBlock * const scope, const unsigned ifDepth = 0, const unsigned whileDepth = 0, const bool isNestedWithinNonCarryCollapsingLoop = false);
89
90    /* Entering and leaving scopes. */
91    void enterScope(const PabloBlock * const scope);
92    void leaveScope();
93
94    /* Methods for processing individual carry-generating operations. */
95    llvm::Value * getNextCarryIn();
96    void setNextCarryOut(llvm::Value * const carryOut);
97    llvm::Value * longAdvanceCarryInCarryOut(llvm::Value * const value, const unsigned shiftAmount);
98    llvm::Value * readCarryInSummary(llvm::ConstantInt *index) const;
99    void writeCarryOutSummary(llvm::Value * const summary, llvm::ConstantInt * index) const;
100
101    /* Summary handling routines */
102    void addToCarryOutSummary(llvm::Value * const value);
103
104    llvm::Type * getBitBlockType() const;
105
106    unsigned getBitBlockWidth() const;
107
108    llvm::Type * getCarryPackType() const;
109
110private:
111
112    PabloKernel * const                             mKernel;
113    IDISA::IDISA_Builder *                          iBuilder;
114
115    llvm::Value *                                   mCurrentFrame;
116    unsigned                                        mCurrentFrameIndex;
117
118    const PabloBlock *                              mCurrentScope;
119    CarryData *                                     mCarryInfo;
120
121    llvm::Value *                                   mNextSummaryTest;
122
123    unsigned                                        mIfDepth;
124
125    bool                                            mHasLongAdvance;
126
127    bool                                            mHasLoop;
128    unsigned                                        mLoopDepth;
129    llvm::Value *                                   mLoopSelector;   
130    llvm::Value *                                   mNextLoopSelector;
131    llvm::Value *                                   mCarryPackPtr;
132    std::vector<llvm::PHINode *>                    mLoopIndicies;
133
134    std::vector<CarryData>                          mCarryMetadata;
135
136    std::vector<std::pair<llvm::Value *, unsigned>> mCarryFrameStack;
137
138    unsigned                                        mCarryScopes;
139    std::vector<unsigned>                           mCarryScopeIndex;
140
141    std::vector<llvm::Value *>                      mCarrySummaryStack;
142};
143
144}
145
146#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.