Ignore:
Timestamp:
Jan 31, 2017, 4:08:11 PM (2 years ago)
Author:
nmedfort
Message:

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

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5285 r5292  
    5555    mCurrentScope = kernel->getEntryBlock();
    5656
    57     mCarryMetadata.resize(enumerate(mCurrentScope));
    58 
    59     mKernel->addScalar(analyse(mCurrentScope), "carries");
     57    mCarryMetadata.resize(enumerate(kernel->getEntryBlock()));
     58
     59    mKernel->addScalar(analyse(kernel->getEntryBlock()), "carries");
    6060}
    6161
     
    6363 * @brief initializeCodeGen
    6464 ** ------------------------------------------------------------------------------------------------------------- */
    65 void CarryManager::initializeCodeGen(Value * self, Function * function) {
     65void CarryManager::initializeCodeGen() {
    6666    // TODO: need to look into abstracting the Initialize creation function in KernelBuilder::generateKernel
    6767    // so that we can allocate the variable length buffers if needed.
    6868
    69     mSelf = self;
    70     mFunction = function;
    71 
    72     assert(mCarryMetadata.size() > 0);
     69    assert(!mCarryMetadata.empty());
    7370    mCarryInfo = &mCarryMetadata[0];
    7471    assert (!mCarryInfo->hasSummary());
    7572
    76     mCurrentFrame = iBuilder->CreateGEP(mSelf, {iBuilder->getInt32(0), mKernel->getScalarIndex("carries")}, "carries");
     73    mCurrentFrame = mKernel->getScalarFieldPtr("carries");
    7774    mCurrentFrameIndex = 0;
    7875
     
    8481 * @brief enterLoopScope
    8582 ** ------------------------------------------------------------------------------------------------------------- */
    86 void CarryManager::enterLoopScope(PabloBlock * const scope) {
     83void CarryManager::enterLoopScope(const PabloBlock * const scope) {
    8784    assert (scope);
    8885    if (mLoopDepth++ == 0) {
    89         Value * const blockNo = mKernel->getBlockNo(mSelf);
     86        Value * const blockNo = mKernel->getBlockNo();
    9087        mLoopSelector = iBuilder->CreateAnd(blockNo, ConstantInt::get(blockNo->getType(), 1));
    9188    }
     
    10097    if (mCarryInfo->hasSummary()) {
    10198        PHINode * carrySummary = iBuilder->CreatePHI(mCarryPackType, 2, "summary");
    102         assert (mCarrySummary.size() > 0);
     99        assert (!mCarrySummary.empty());
    103100        carrySummary->addIncoming(mCarrySummary.back(), entryBlock);
    104101        // Replace the incoming carry summary with the phi node and add the phi node to the stack
     
    118115        Value * array = iBuilder->CreateLoad(arrayPtr, false, "array");
    119116
    120         LLVMContext & C = iBuilder->getContext();
    121 
    122         BasicBlock * resizeBlock = BasicBlock::Create(C, "", mFunction);
    123         BasicBlock * cleanUpBlock = BasicBlock::Create(C, "", mFunction);
    124         BasicBlock * zeroBlock = BasicBlock::Create(C, "", mFunction);
    125         BasicBlock * codeBlock = BasicBlock::Create(C, "", mFunction);
     117        BasicBlock * resizeBlock = mKernel->CreateBasicBlock("");
     118        BasicBlock * cleanUpBlock = mKernel->CreateBasicBlock("");
     119        BasicBlock * zeroBlock = mKernel->CreateBasicBlock("");
     120        BasicBlock * codeBlock = mKernel->CreateBasicBlock("");
    126121
    127122        Value * cond = iBuilder->CreateICmpULT(index, capacity);
     
    171166    }
    172167    if (LLVM_UNLIKELY(mCarryInfo->variableLength)) {
    173         assert (mLoopIndicies.size() > 0);
     168        assert (!mLoopIndicies.empty());
    174169        PHINode * index = mLoopIndicies.back();
    175170        index->addIncoming(iBuilder->CreateAdd(index, iBuilder->getSize(1)), exitBlock);
     
    192187 * @brief enterIfScope
    193188 ** ------------------------------------------------------------------------------------------------------------- */
    194 void CarryManager::enterIfScope(PabloBlock * const scope) {
     189void CarryManager::enterIfScope(const PabloBlock * const scope) {
    195190    ++mIfDepth;
    196191    enterScope(scope);
     
    242237    const auto n = mCarrySummary.size();
    243238    if (LLVM_LIKELY(mCarryInfo->hasExplicitSummary())) {
    244         assert (mCarrySummary.size() > 0);
     239        assert (!mCarrySummary.empty());
    245240        Value * ptr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    246241        Value * const value = iBuilder->CreateBitCast(mCarrySummary.back(), mBitBlockType);
     
    281276 * @brief enterScope
    282277 ** ------------------------------------------------------------------------------------------------------------- */
    283 void CarryManager::enterScope(PabloBlock * const scope) {
     278void CarryManager::enterScope(const PabloBlock * const scope) {
    284279    assert (scope);
    285280    // Store the state of the current frame and update the scope state
     
    305300    assert (mCurrentFrameIndex == mCurrentFrame->getType()->getPointerElementType()->getStructNumElements());
    306301    // Sanity test: are there remaining carry frames?
    307     assert (mCarryFrame.size() > 0);
     302    assert (!mCarryFrame.empty());
    308303
    309304    std::tie(mCurrentFrame, mCurrentFrameIndex) = mCarryFrame.back();
     
    393388    // Create a mask to implement circular buffer indexing
    394389    Value * indexMask = iBuilder->getSize(nearest_pow2(entries) - 1);
    395     Value * blockIndex = mKernel->getBlockNo(mSelf);
     390    Value * blockIndex = mKernel->getBlockNo();
    396391    Value * carryIndex0 = iBuilder->CreateSub(blockIndex, iBuilder->getSize(entries));
    397392    Value * loadIndex0 = iBuilder->CreateAnd(carryIndex0, indexMask);
     
    458453 ** ------------------------------------------------------------------------------------------------------------- */
    459454void CarryManager::addToSummary(Value * value) { assert (value);
    460     assert (mIfDepth > 0 && mCarrySummary.size() > 0);
     455    assert (mIfDepth > 0 && !mCarrySummary.empty());
    461456    Value * const summary = mCarrySummary.back(); assert (summary);
    462457    if (LLVM_UNLIKELY(summary == value)) {
     
    609604: iBuilder(idb)
    610605, mKernel(nullptr)
    611 , mSelf(nullptr)
    612 , mFunction(nullptr)
    613606, mBitBlockType(idb->getBitBlockType())
    614607, mBitBlockWidth(idb->getBitBlockWidth())
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5267 r5292  
    4646    void initializeCarryData(PabloKernel * const kernel);
    4747
    48     void initializeCodeGen(llvm::Value * const self, llvm::Function *function);
     48    void initializeCodeGen();
    4949
    5050    /* Entering and leaving loops. */
    5151
    52     void enterLoopScope(PabloBlock * const scope);
     52    void enterLoopScope(const PabloBlock * const scope);
    5353
    5454    void enterLoopBody(llvm::BasicBlock * const entryBlock);
     
    6060    /* Entering and leaving ifs. */
    6161
    62     void enterIfScope(PabloBlock * const scope);
     62    void enterIfScope(const PabloBlock * const scope);
    6363
    6464    void enterIfBody(llvm::BasicBlock * const entryBlock);
     
    8585
    8686    /* Entering and leaving scopes. */
    87     void enterScope(PabloBlock * const scope);
     87    void enterScope(const PabloBlock * const scope);
    8888    void leaveScope();
    8989
     
    103103    PabloKernel *                                   mKernel;
    104104    llvm::Value *                                   mSelf;
    105     llvm::Function *                                mFunction;
    106105    llvm::Type * const                              mBitBlockType;
    107106    const unsigned                                  mBitBlockWidth;
     
    110109    unsigned                                        mCurrentFrameIndex;
    111110
    112     PabloBlock *                                    mCurrentScope;
     111    const PabloBlock *                              mCurrentScope;
    113112    CarryData *                                     mCarryInfo;
    114113
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5285 r5292  
    4848}
    4949   
    50 void PabloCompiler::compile(Function * function, Value * const self, Value * const blockNo) {
    51 
    52     mSelf = self;
    53 
    54     mFunction = function;
    55 
    56     mCarryManager->initializeCodeGen(self, function);
     50void PabloCompiler::compile(Value * const blockNo) {
     51
     52    mCarryManager->initializeCodeGen();
    5753     
    5854    PabloBlock * const entryBlock = mKernel->getEntryBlock(); assert (entryBlock);
     
    6561        Value * input = nullptr;
    6662        if (var->getType()->isSingleValueType()) {
    67             input = mKernel->getScalarFieldPtr(mSelf, name);
     63            input = mKernel->getScalarFieldPtr(name);
    6864        } else {
    69             input = mKernel->getStreamSetPtr(mSelf, name, blockNo);
     65            input = mKernel->getStreamSetPtr(name, blockNo);
    7066        }
    7167        mMarker.emplace(var, input);
     
    7773        Value * output = nullptr;
    7874        if (var->getType()->isSingleValueType()) {
    79             output = mKernel->getScalarFieldPtr(mSelf, name);
     75            output = mKernel->getScalarFieldPtr(name);
    8076        } else {
    81             output = mKernel->getStreamSetPtr(mSelf, name, blockNo);
     77            output = mKernel->getStreamSetPtr(name, blockNo);
    8278        }
    8379        mMarker.emplace(var, output);
     
    134130
    135131    BasicBlock * const ifEntryBlock = iBuilder->GetInsertBlock();
    136     BasicBlock * const ifBodyBlock = BasicBlock::Create(mFunction->getContext(), "if.body", mFunction);
    137     BasicBlock * const ifEndBlock = BasicBlock::Create(mFunction->getContext(), "if.end", mFunction);
     132    BasicBlock * const ifBodyBlock = mKernel->CreateBasicBlock("if.body");
     133    BasicBlock * const ifEndBlock = mKernel->CreateBasicBlock("if.end");
    138134   
    139135    std::vector<std::pair<const Var *, Value *>> incoming;
     
    152148    }
    153149
    154     PabloBlock * ifBody = ifStatement->getBody();
     150    const PabloBlock * ifBody = ifStatement->getBody();
    155151   
    156152    mCarryManager->enterIfScope(ifBody);
     
    222218void PabloCompiler::compileWhile(const While * const whileStatement) {
    223219
    224     PabloBlock * const whileBody = whileStatement->getBody();
    225    
     220    const PabloBlock * const whileBody = whileStatement->getBody();
     221
    226222    BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
    227 
    228     BasicBlock * whileBodyBlock = BasicBlock::Create(iBuilder->getContext(), "while.body", mFunction);
    229 
    230     BasicBlock * whileEndBlock = BasicBlock::Create(iBuilder->getContext(), "while.end", mFunction);
     223    BasicBlock * whileBodyBlock = mKernel->CreateBasicBlock("while.body");
     224    BasicBlock * whileEndBlock = mKernel->CreateBasicBlock("while.end");
    231225
    232226    const auto escaped = whileStatement->getEscaped();
     
    432426            value = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    433427        } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
    434             Value * EOFmask = mKernel->getScalarField(mSelf, "EOFmask");
     428            Value * EOFmask = mKernel->getScalarField("EOFmask");
    435429            value = iBuilder->simd_xor(compileExpression(e->getExpr()), EOFmask);
    436430        } else if (const AtEOF * e = dyn_cast<AtEOF>(stmt)) {
    437             Value * EOFbit = mKernel->getScalarField(mSelf, "EOFbit");
     431            Value * EOFbit = mKernel->getScalarField("EOFbit");
    438432            value = iBuilder->simd_and(compileExpression(e->getExpr()), EOFbit);
    439433        } else if (const Count * c = dyn_cast<Count>(stmt)) {
     
    444438                llvm::report_fatal_error("Unknown accumulator: " + c->getName().str());
    445439            }
    446             Value * ptr = mKernel->getScalarFieldPtr(mSelf, f->second);
     440            Value * ptr = mKernel->getScalarFieldPtr(f->second);
    447441            Value * count = iBuilder->CreateAlignedLoad(ptr, getPointerElementAlignment(ptr));
    448442            Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
     
    477471            const unsigned block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    478472            std::string inputName = cast<Var>(var)->getName().str();
    479             Value * blockNo = mKernel->getBlockNo(mSelf);
    480             Value * lookAhead_blockPtr  = mKernel->getStreamSetPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
     473            Value * blockNo = mKernel->getBlockNo();
     474            Value * lookAhead_blockPtr  = mKernel->getStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
    481475            Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    482476            Value * lookAhead = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr);
     
    484478                value = lookAhead;
    485479            } else { // Need to form shift result from two adjacent blocks.
    486                 Value * lookAhead_blockPtr1  = mKernel->getStreamSetPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
     480                Value * lookAhead_blockPtr1  = mKernel->getStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
    487481                Value * lookAhead_inputPtr1 = iBuilder->CreateGEP(lookAhead_blockPtr1, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    488482                Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr1);
     
    586580: iBuilder(kernel->getBuilder())
    587581, mKernel(kernel)
    588 , mCarryManager(new CarryManager(iBuilder))
    589 , mFunction(nullptr) {
     582, mCarryManager(new CarryManager(iBuilder)) {
    590583
    591584}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5285 r5292  
    3434    ~PabloCompiler();
    3535    void initializeKernelData();
    36     void compile(llvm::Function * function, llvm::Value * const self, llvm::Value * const blockNo);
     36    void compile(llvm::Value * const blockNo);
    3737
    3838private:
     
    5757    PabloKernel * const             mKernel;
    5858    CarryManager * const            mCarryManager;
    59     llvm::Value *                   mSelf;
    60     llvm::Function *                mFunction;
    6159    TranslationMap                  mMarker;
    6260    TranslationMap                  mAccumulator;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5285 r5292  
    1010#include <pablo/pe_zeroes.h>
    1111#include <pablo/pe_ones.h>
    12 #include <llvm/IR/Module.h>
    13 #include <llvm/IR/Verifier.h>
    14 #include <IR_Gen/idisa_builder.h>
    15 #include <llvm/Support/raw_os_ostream.h>
     12//#include <llvm/IR/Module.h>
     13//#include <llvm/IR/Verifier.h>
     14//#include <IR_Gen/idisa_builder.h>
    1615
    1716using namespace pablo;
     
    8887}
    8988
    90 void PabloKernel::generateDoBlockMethod(Function * function, Value  *self, Value * blockNo) const {
    91     mPabloCompiler->compile(function, self, blockNo);
     89void PabloKernel::generateDoBlockMethod(Value * blockNo) {
     90    mPabloCompiler->compile(blockNo);
    9291}
    9392
    94 void PabloKernel::generateFinalBlockMethod(Function * function, Value *self, Value *remainingBytes, Value *blockNo) const {
     93void PabloKernel::generateFinalBlockMethod(Value *remainingBytes, Value * blockNo) {
    9594    // Standard Pablo convention for final block processing: set a bit marking
    9695    // the position just past EOF, as well as a mask marking all positions past EOF.
    97     setScalarField(self, "EOFbit", iBuilder->bitblock_set_bit(remainingBytes));
    98     setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
    99     iBuilder->CreateCall(getDoBlockFunction(), { self });
     96    setScalarField("EOFbit", iBuilder->bitblock_set_bit(remainingBytes));
     97    setScalarField("EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
     98    CreateDoBlockMethodCall();
    10099}
    101100
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5285 r5292  
    116116    void prepareKernel()  override final;
    117117
    118     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override final;
     118    void generateDoBlockMethod(llvm::Value * blockNo) override final;
    119119
    120120    // The default method for Pablo final block processing sets the
    121121    // EOFmark bit and then calls the standard DoBlock function.
    122122    // This may be overridden for specialized processing.
    123     virtual void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override final;
     123    virtual void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override final;
    124124
    125125    inline String * makeName(const llvm::StringRef & prefix) const {
Note: See TracChangeset for help on using the changeset viewer.