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

Last change on this file since 5423 was 5400, checked in by cameron, 2 years ago

Eliminate struct/class and unused variable warnings

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