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

Last change on this file since 5299 was 5292, checked in by nmedfort, 3 years ago

Removed 'function' and 'self' parameters from generateXXXMethod() functions.

File size: 4.3 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    explicit CarryManager(IDISA::IDISA_Builder * idb) noexcept;
45
46    void initializeCarryData(PabloKernel * const kernel);
47
48    void initializeCodeGen();
49
50    /* Entering and leaving loops. */
51
52    void enterLoopScope(const PabloBlock * const scope);
53
54    void enterLoopBody(llvm::BasicBlock * const entryBlock);
55
56    void leaveLoopBody(llvm::BasicBlock * const exitBlock);
57
58    void leaveLoopScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
59
60    /* Entering and leaving ifs. */
61
62    void enterIfScope(const PabloBlock * const scope);
63
64    void enterIfBody(llvm::BasicBlock * const entryBlock);
65
66    void leaveIfBody(llvm::BasicBlock * const exitBlock);
67
68    void leaveIfScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
69
70    /* Methods for processing individual carry-generating operations. */
71   
72    llvm::Value * addCarryInCarryOut(const Statement * operation, llvm::Value * const e1, llvm::Value * const e2);
73
74    llvm::Value * advanceCarryInCarryOut(const Advance * advance, llvm::Value * const strm);
75 
76    /* Methods for getting and setting carry summary values for If statements */
77         
78    llvm::Value * generateSummaryTest(llvm::Value * condition);
79   
80protected:
81
82    static unsigned enumerate(PabloBlock * const scope, unsigned index = 0);
83    static bool requiresVariableLengthMode(const PabloBlock * const scope);
84    llvm::StructType * analyse(PabloBlock * const scope, const unsigned ifDepth = 0, const unsigned whileDepth = 0);
85
86    /* Entering and leaving scopes. */
87    void enterScope(const PabloBlock * const scope);
88    void leaveScope();
89
90    /* Methods for processing individual carry-generating operations. */
91    llvm::Value * getNextCarryIn();
92    void setNextCarryOut(llvm::Value * const carryOut);
93    llvm::Value * longAdvanceCarryInCarryOut(const unsigned shiftAmount, llvm::Value * const value);
94
95    /* Summary handling routines */
96    void addToSummary(llvm::Value * const value);
97
98    bool inCollapsingCarryMode() const;
99
100private:
101
102    IDISA::IDISA_Builder * const                    iBuilder;
103    PabloKernel *                                   mKernel;
104    llvm::Value *                                   mSelf;
105    llvm::Type * const                              mBitBlockType;
106    const unsigned                                  mBitBlockWidth;
107
108    llvm::Value *                                   mCurrentFrame;
109    unsigned                                        mCurrentFrameIndex;
110
111    const PabloBlock *                              mCurrentScope;
112    CarryData *                                     mCarryInfo;
113
114    llvm::Type *                                    mCarryPackType;
115    llvm::Value *                                   mCarryPackPtr;
116
117    unsigned                                        mIfDepth;
118
119    unsigned                                        mLoopDepth;
120    llvm::Value *                                   mLoopSelector;
121    std::vector<llvm::PHINode *>                    mLoopIndicies;
122
123    std::vector<CarryData>                          mCarryMetadata;
124    std::vector<std::pair<llvm::Value *, unsigned>> mCarryFrame;
125
126    std::vector<llvm::Value *>                      mCarrySummary;
127};
128
129}
130
131#endif // CARRY_MANAGER_H
Note: See TracBrowser for help on using the repository browser.