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

Last change on this file since 5705 was 5705, checked in by cameron, 22 months ago

Drop linebreak normalization; add1 attribute for grep kernel; pablo indexed advance initial check-in

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