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

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

Added a simple CreateAssert? function in CBuilder and ReadOnly? flag for getStreamSetBufferPtr method to prevent expanding input stream sets. Begun work on CarryManager? to preallocate variable-length carry data slots.

File size: 4.7 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 Function; }
15namespace llvm { class PHINode; }
16namespace llvm { class StructType; }
17namespace llvm { class Type; }
18namespace llvm { class Value; }
19namespace pablo { class Advance; }
20namespace pablo { class PabloBlock; }
21namespace pablo { class PabloKernel; }
22namespace pablo { class Statement; }
23
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(IDISA::IDISA_Builder * idb) noexcept;
45
46    void initializeCarryData(PabloKernel * const kernel);
47
48    void allocateCarryData(PabloKernel * const kernels);
49
50    void initializeCodeGen();
51
52    void finalizeCodeGen();
53
54    /* Entering and leaving loops. */
55
56    void enterLoopScope(const PabloBlock * const scope);
57
58    void enterLoopBody(llvm::BasicBlock * const entryBlock);
59
60    void leaveLoopBody(llvm::BasicBlock * const exitBlock);
61
62    void leaveLoopScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
63
64    /* Entering and leaving ifs. */
65
66    void enterIfScope(const PabloBlock * const scope);
67
68    void enterIfBody(llvm::BasicBlock * const entryBlock);
69
70    void leaveIfBody(llvm::BasicBlock * const exitBlock);
71
72    void leaveIfScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
73
74    /* Methods for processing individual carry-generating operations. */
75   
76    llvm::Value * addCarryInCarryOut(const Statement * operation, llvm::Value * const e1, llvm::Value * const e2);
77
78    llvm::Value * advanceCarryInCarryOut(const Advance * advance, llvm::Value * const strm);
79 
80    /* Methods for getting and setting carry summary values for If statements */
81         
82    llvm::Value * generateSummaryTest(llvm::Value * condition);
83   
84protected:
85
86    static unsigned getScopeCount(PabloBlock * const scope, unsigned index = 0);
87    static bool requiresVariableLengthMode(const PabloBlock * const scope);
88    llvm::StructType * analyse(PabloBlock * const scope, const unsigned ifDepth = 0, const unsigned whileDepth = 0);
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(const unsigned shiftAmount, llvm::Value * const value);
98
99    /* Summary handling routines */
100    void addToSummary(llvm::Value * const value);
101
102    bool inCollapsingCarryMode() const;
103
104private:
105
106    IDISA::IDISA_Builder * const                    iBuilder;
107    PabloKernel *                                   mKernel;
108    llvm::Value *                                   mSelf;
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 *                                   mCarryPackPtr;
120
121    unsigned                                        mIfDepth;
122
123    bool                                            mHasLongAdvance;
124
125    bool                                            mHasLoop;
126    unsigned                                        mLoopDepth;
127    llvm::Value *                                   mLoopSelector;
128    std::vector<llvm::PHINode *>                    mLoopIndicies;
129
130    std::vector<CarryData>                          mCarryMetadata;
131
132    std::vector<std::pair<llvm::Value *, unsigned>> mCarryFrame;
133
134    unsigned                                        mCarryScopes;
135    std::vector<unsigned>                           mCarryScopeIndex;
136
137    std::vector<llvm::Value *>                      mCarrySummary;
138};
139
140}
141
142#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.