Ignore:
Timestamp:
Jan 28, 2017, 3:12:03 PM (2 years ago)
Author:
nmedfort
Message:

Start of work to simplify kernel writing. Removed generateDoBlockLogic method.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r5283 r5285  
    248248    }
    249249
    250     inline String * getName(const llvm::StringRef & name) const {
    251         return mPb->getName(name);
    252     }
    253 
    254250    inline String * makeName(const llvm::StringRef & prefix) const {
    255251        return mPb->makeName(prefix);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5267 r5285  
    8787    assert (scope);
    8888    if (mLoopDepth++ == 0) {
    89         Value * const blockNo = mKernel->getScalarField(mSelf, blockNoScalar);
     89        Value * const blockNo = mKernel->getBlockNo(mSelf);
    9090        mLoopSelector = iBuilder->CreateAnd(blockNo, ConstantInt::get(blockNo->getType(), 1));
    9191    }
     
    393393    // Create a mask to implement circular buffer indexing
    394394    Value * indexMask = iBuilder->getSize(nearest_pow2(entries) - 1);
    395     Value * blockIndex = mKernel->getScalarField(mSelf, blockNoScalar);
     395    Value * blockIndex = mKernel->getBlockNo(mSelf);
    396396    Value * carryIndex0 = iBuilder->CreateSub(blockIndex, iBuilder->getSize(entries));
    397397    Value * loadIndex0 = iBuilder->CreateAnd(carryIndex0, indexMask);
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5283 r5285  
    276276    }
    277277
    278     inline String * getName(const llvm::StringRef & name) const {
    279         return mParent->getName(name);
    280     }
    281 
    282278    inline String * makeName(const llvm::StringRef & prefix) const {
    283279        return mParent->makeName(prefix);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5283 r5285  
    4848}
    4949   
    50 void PabloCompiler::compile(Value * const self, Function * function) {
    51 
    52     // Make sure that we generate code into the right module.
     50void PabloCompiler::compile(Function * function, Value * const self, Value * const blockNo) {
     51
    5352    mSelf = self;
     53
    5454    mFunction = function;
    55 
    56     //Generate Kernel//
    57     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", function, 0));
    5855
    5956    mCarryManager->initializeCodeGen(self, function);
     
    6259    mMarker.emplace(entryBlock->createZeroes(), iBuilder->allZeroes());
    6360    mMarker.emplace(entryBlock->createOnes(), iBuilder->allOnes());
    64 
    65     Value * const blockNo = mKernel->getScalarField(mSelf, blockNoScalar);
    6661
    6762    for (unsigned i = 0; i < mKernel->getNumOfInputs(); ++i) {
     
    482477            const unsigned block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    483478            std::string inputName = cast<Var>(var)->getName().str();
    484             Value * blockNo = mKernel->getScalarField(mSelf, blockNoScalar);
     479            Value * blockNo = mKernel->getBlockNo(mSelf);
    485480            Value * lookAhead_blockPtr  = mKernel->getStreamSetPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
    486481            Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5283 r5285  
    3434    ~PabloCompiler();
    3535    void initializeKernelData();
    36     void compile(llvm::Value * const self, llvm::Function * doBlockFunction);
     36    void compile(llvm::Function * function, llvm::Value * const self, llvm::Value * const blockNo);
    3737
    3838private:
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5283 r5285  
    8888}
    8989
    90 void PabloKernel::generateDoBlockMethod() const {
    91     auto savePoint = iBuilder->saveIP();
    92     Module * const m = iBuilder->getModule();
    93     Function * const f = m->getFunction(mKernelName + doBlock_suffix);
    94     Value * const self = &*(f->arg_begin());
    95     mPabloCompiler->compile(self, f);
    96     iBuilder->CreateRetVoid();
    97     #ifndef NDEBUG
    98     llvm::verifyFunction(*f, &errs());
    99     #endif
    100     iBuilder->restoreIP(savePoint);
     90void PabloKernel::generateDoBlockMethod(Function * function, Value  *self, Value * blockNo) const {
     91    mPabloCompiler->compile(function, self, blockNo);
    10192}
    10293
    103 void PabloKernel::generateFinalBlockMethod() const {
    104     auto savePoint = iBuilder->saveIP();
    105     Module * m = iBuilder->getModule();
    106     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    107     Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    108     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
    109     // Final Block arguments: self, remaining, then the standard DoBlock args.
    110     Function::arg_iterator args = finalBlockFunction->arg_begin();
    111     Value * self = &*(args++);
    112     Value * remaining = &*(args++);
    113     std::vector<Value *> doBlockArgs = {self};
    114     while (args != finalBlockFunction->arg_end()){
    115         doBlockArgs.push_back(&*args++);
    116     }
     94void PabloKernel::generateFinalBlockMethod(Function * function, Value *self, Value *remainingBytes, Value *blockNo) const {
    11795    // Standard Pablo convention for final block processing: set a bit marking
    11896    // the position just past EOF, as well as a mask marking all positions past EOF.
    119     setScalarField(self, "EOFbit", iBuilder->bitblock_set_bit(remaining));
    120     setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remaining));
    121     iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    122     iBuilder->CreateRetVoid();
    123     #ifndef NDEBUG
    124     llvm::verifyFunction(*finalBlockFunction, &errs());
    125     #endif
    126     iBuilder->restoreIP(savePoint);
     97    setScalarField(self, "EOFbit", iBuilder->bitblock_set_bit(remainingBytes));
     98    setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
     99    iBuilder->CreateCall(getDoBlockFunction(), { self });
    127100}
    128101
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5283 r5285  
    114114    // so that the carry data requirements may be accommodated before
    115115    // finalizing the KernelStateType.
    116     void prepareKernel() override;
     116    void prepareKernel()  override final;
    117117
    118     void generateDoBlockMethod() const override;
    119    
     118    void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override final;
     119
    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() const override;
    124 
    125     inline String * getName(const llvm::StringRef & name) const {
    126         return mSymbolTable->getString(name, iBuilder);
    127     }
     123    virtual void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override final;
    128124
    129125    inline String * makeName(const llvm::StringRef & prefix) const {
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.cpp

    r5283 r5285  
    1515    auto f = mPrefixMap.find(prefix);
    1616    if (f == mPrefixMap.end()) {   
    17         return getString(prefix, builder);
     17        char * const data = mAllocator.allocate<char>(prefix.size() + 1);
     18        std::memcpy(data, prefix.data(), prefix.size());
     19        data[prefix.size()] = '\0';
     20        llvm::StringRef name(data, prefix.size());
     21        mPrefixMap.insert(std::make_pair(name, 1));
     22        return new (mAllocator) String(builder->getInt8PtrTy(), name, mAllocator);
    1823    } else { // this string already exists; make a new string using the given prefix
    1924
     
    3944}
    4045
    41 String * SymbolGenerator::getString(const llvm::StringRef name, IDISA::IDISA_Builder * builder) noexcept {
    42     if (LLVM_UNLIKELY(name.size() == 0)) {
    43         throw std::runtime_error("symbol name cannot be 0-length");
    44     }
    45     const auto f = mStringMap.find(name);
    46     if (LLVM_LIKELY(f == mStringMap.end())) {
    47         assert ("prefix cannot exist for a non-existant key!" && (mPrefixMap.count(name) == 0));
    48         // create an internal copy of this name to prevent a temporary string from being added to the maps
    49         char * const data = mAllocator.allocate<char>(name.size() + 1);
    50         std::memcpy(data, name.data(), name.size());
    51         data[name.size()] = '\0';
    52         llvm::StringRef duplicate(data, name.size());
    53         mPrefixMap.insert(std::make_pair(duplicate, 1));
    54         String * result = new (mAllocator) String(builder->getInt8PtrTy(), duplicate, mAllocator); assert (result);
    55         mStringMap.insert(std::make_pair(duplicate, result));
    56         return result;
    57     }
    58     assert ("prefix must exist for a known key!" && (mPrefixMap.count(name) != 0));
    59     return f->second;
    60 }
    61 
    6246Integer * SymbolGenerator::getInteger(const IntTy value, IDISA::IDISA_Builder * builder) noexcept {
    6347    auto f = mIntegerMap.find(value);
     
    6650        result = new (mAllocator) Integer(value, builder->getSizeTy(), mAllocator);
    6751        assert (result->value() == value);
    68         mIntegerMap.emplace(std::make_pair(value, result));
     52        mIntegerMap.emplace(value, result);
    6953    } else {
    7054        result = f->second;
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.h

    r5283 r5285  
    2323public:
    2424    using IntTy = int64_t;
    25     String * getString(const llvm::StringRef name, IDISA::IDISA_Builder * builder) noexcept;
    2625    String * makeString(const llvm::StringRef prefix, IDISA::IDISA_Builder * builder) noexcept;
    2726    Integer * getInteger(const IntTy value, IDISA::IDISA_Builder * builder) noexcept;
Note: See TracChangeset for help on using the changeset viewer.