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

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

Rewrite of the CarryManager? to support non-carry-collapsing loops.

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