Ignore:
Timestamp:
Feb 18, 2017, 4:13:44 PM (2 years ago)
Author:
nmedfort
Message:

Continued work on parenthesis matching; addition of Pablo ScanTo? and AdvanceThenScanTo/Thru? statements. Bug fix for Pablo Compiler for escaping variables.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.cpp

    r5326 r5329  
    1818}
    1919
    20 inline void p2s(IDISA::IDISA_Builder * iBuilder, Value * p[], Value * s[]) {
     20void p2s(IDISA::IDISA_Builder * iBuilder, Value * p[], Value * s[]) {
    2121    Value * bit00004444[2];
    2222    Value * bit22226666[2];
     
    8585}
    8686
    87 PrintableBits::PrintableBits(IDISA::IDISA_Builder * builder)
    88 : BlockOrientedKernel(builder, "PrintableBits", {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {}, {}, {})
    89 {
    90     setNoTerminateAttribute(true);
    91     setDoBlockUpdatesProducedItemCountsAttribute(false);
    92 
    93 }
    94 
    95 SelectStream::SelectStream(IDISA::IDISA_Builder * builder, unsigned sizeInputStreamSet, unsigned streamIndex)
    96 : BlockOrientedKernel(builder, "SelectStream", {Binding{builder->getStreamSetTy(sizeInputStreamSet, 1), "bitStreams"}}, {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {}, {}, {}), mSizeInputStreamSet(sizeInputStreamSet), mStreamIndex(streamIndex)
    97 {
    98     setNoTerminateAttribute(true);
    99     setDoBlockUpdatesProducedItemCountsAttribute(false);
    100 
    101 }
    102 
    10387void SelectStream::generateDoBlockMethod() {
    10488    if (mStreamIndex >= mSizeInputStreamSet)
     
    10993    storeOutputStreamBlock("bitStream", iBuilder->getInt32(0), bitStrmVal);
    11094}
     95
     96void PrintableStreamSet::generateDoBlockMethod() {
     97
     98    /*
     99    00110001 is the Unicode codepoint for '1' and 00101110 is the codepoint for '.'.
     100    We want to output a byte stream that is aligned with the input bitstream such that it contains 00110001 in each 1 position and 00101110 in each 0 position.
     101
     102    For example, consider input bitstream 101. Our desired output is:
     103    00110001 00101110 00110001
     104
     105    We can do the bitstream to bytestream conversion in parallel by viewing the output stream in terms of parallel bit streams.
     106
     107    0   0   0 -> First bit position of every byte is all zeros
     108    0   0   0 -> Same for second bit
     109    1   1   1 -> Third bit is all ones
     110    1   0   1 -> 4th bit is 1 for a '1' byte and '0' for a zero byte. Matches input bit stream
     111    0   1   0 -> opposite
     112    0   1   0 -> opposite
     113    0   1   0 -> opposite
     114    1   0   1 -> same as 4th bit position.
     115
     116    Armed with the above we can do the bit->byte conversion all at once
     117    rather than byte at a time! That's what we do below.
     118    */
     119
     120    BasicBlock * entry = iBuilder->GetInsertBlock();
     121    BasicBlock * cond = CreateBasicBlock("cond");
     122    BasicBlock * body = CreateBasicBlock("body");
     123    BasicBlock * exit = CreateBasicBlock("exit");
     124
     125    Value * count = getInputStreamSetCount("bitStream");
     126    iBuilder->CreateBr(cond);
     127    iBuilder->SetInsertPoint(cond);
     128    PHINode * i = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2, "i");
     129    i->addIncoming(iBuilder->getSize(0), entry);
     130
     131    iBuilder->CreateCondBr(iBuilder->CreateICmpNE(i, count), body, exit);
     132    iBuilder->SetInsertPoint(body);
     133    // Load current block
     134    Value * bitStrmVal = loadInputStreamBlock("bitStream", i);
     135
     136    Value * bits[8];
     137
     138    bits[0] = ConstantInt::getNullValue(iBuilder->getBitBlockType());
     139    bits[1] = ConstantInt::getNullValue(iBuilder->getBitBlockType());
     140    bits[2] = ConstantInt::getAllOnesValue(iBuilder->getBitBlockType());
     141    bits[3] = bitStrmVal;
     142    Value * negBitStrmVal = iBuilder->simd_not(bitStrmVal);
     143    bits[4] = negBitStrmVal;
     144    bits[5] = negBitStrmVal;
     145    bits[6] = negBitStrmVal;
     146    bits[7] = bitStrmVal;
     147
     148    // Reassemble the paralell bit streams into a byte stream
     149    Value * printableBytes[8];
     150    p2s(iBuilder, bits, printableBytes);
     151    for (unsigned j = 0; j < 8; ++j) {
     152        storeOutputStreamPack("byteStream", i, iBuilder->getInt32(j), iBuilder->bitCast(printableBytes[j]));
     153    }
     154
     155    i->addIncoming(iBuilder->CreateAdd(i, iBuilder->getSize(1)), iBuilder->GetInsertBlock());
     156    iBuilder->CreateBr(cond);
     157
     158    iBuilder->SetInsertPoint(exit);
    111159}
     160
     161PrintableBits::PrintableBits(IDISA::IDISA_Builder * builder)
     162: BlockOrientedKernel(builder, "PrintableBits", {Binding{builder->getStreamSetTy(1), "bitStream"}}, {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {}, {}, {})
     163{
     164    setNoTerminateAttribute(true);
     165    setDoBlockUpdatesProducedItemCountsAttribute(false);
     166}
     167
     168SelectStream::SelectStream(IDISA::IDISA_Builder * builder, unsigned sizeInputStreamSet, unsigned streamIndex)
     169: BlockOrientedKernel(builder, "SelectStream", {Binding{builder->getStreamSetTy(sizeInputStreamSet), "bitStreams"}}, {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {}, {}, {}), mSizeInputStreamSet(sizeInputStreamSet), mStreamIndex(streamIndex)
     170{
     171    setNoTerminateAttribute(true);
     172    setDoBlockUpdatesProducedItemCountsAttribute(false);
     173
     174}
     175
     176PrintableStreamSet::PrintableStreamSet(IDISA::IDISA_Builder * builder)
     177: BlockOrientedKernel(builder, "PrintableStreamSet", {Binding{builder->getStreamSetTy(0), "bitStream"}}, {Binding{builder->getStreamSetTy(0, 8), "byteStream"}}, {}, {}, {}) {
     178    setNoTerminateAttribute(true);
     179    setDoBlockUpdatesProducedItemCountsAttribute(false);
     180}
     181
     182
     183
     184}
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.h

    r5297 r5329  
    3030};
    3131
     32class PrintableStreamSet : public BlockOrientedKernel {
     33public:
     34    PrintableStreamSet(IDISA::IDISA_Builder * builder);
     35    virtual ~PrintableStreamSet() {}
     36private:
     37    void generateDoBlockMethod() override;
     38};
     39
    3240}
    3341#endif
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5328 r5329  
    1414#include <llvm/IR/LegacyPassManager.h>
    1515#include <llvm/Transforms/Scalar.h>
     16#ifndef NDEBUG
     17#include <llvm/IR/Verifier.h>
     18#endif
    1619
    1720static const auto DO_BLOCK_SUFFIX = "_DoBlock";
     
    323326}
    324327
     328llvm::Value * KernelBuilder::getInputStreamSetCount(const std::string & name) const {
     329    return getInputStreamSetBuffer(name)->getStreamSetCount(getStreamSetBufferPtr(name));
     330}
     331
    325332llvm::Value * KernelBuilder::getAdjustedInputStreamBlockPtr(Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const {
    326333    Value * blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
     
    350357}
    351358
     359llvm::Value * KernelBuilder::getOutputStreamSetCount(const std::string & name) const {
     360    return getOutputStreamSetBuffer(name)->getStreamSetCount(getStreamSetBufferPtr(name));
     361}
     362
    352363Value * KernelBuilder::getRawInputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    353364    return getInputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     
    361372    const auto f = mStreamSetNameMap.find(name);
    362373    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
    363         throw std::runtime_error(getName() + " does not contain stream set: " + name);
     374        report_fatal_error(getName() + " does not contain stream set: " + name);
    364375    }
    365376    return f->second;
     
    524535    generateDoBlockMethod(); // must be implemented by the KernelBuilder subtype
    525536    iBuilder->CreateRetVoid();
    526 
     537    #ifndef NDEBUG
     538    std::string tmp;
     539    raw_string_ostream out(tmp);
     540    if (verifyFunction(*mCurrentFunction, &out)) {
     541        mCurrentFunction->dump();
     542        report_fatal_error(getName() + ": " + out.str());
     543    }
     544    #endif
    527545    // Use the pass manager to optimize the function.
    528546    FunctionPassManager fpm(iBuilder->getModule());
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5317 r5329  
    172172
    173173    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) const;
    174    
     174
    175175    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex) const;
    176176   
     
    179179    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) const;
    180180   
     181    llvm::Value * getInputStreamSetCount(const std::string & name) const;
     182
    181183    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) const;
    182184   
     
    186188   
    187189    void storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore) const;
    188    
     190
     191    llvm::Value * getOutputStreamSetCount(const std::string & name) const;
     192
    189193    llvm::Value * getAdjustedInputStreamBlockPtr(llvm::Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const;
    190194
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5320 r5329  
    3535Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex) const {
    3636    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
     37}
     38
     39llvm::Value * StreamSetBuffer::getStreamSetCount(Value *) const {
     40    uint64_t count = 1;
     41    if (isa<ArrayType>(mBaseType)) {
     42        count = mBaseType->getArrayNumElements();
     43    }
     44    return iBuilder->getInt32(count);
    3745}
    3846
     
    100108
    101109Value * ExternalFileBuffer::getLinearlyAccessibleItems(llvm::Value *) const {
    102     report_fatal_error("External buffers: getLinearlyAccessibleItems not supported.");
     110    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    103111}
    104112
     
    177185// Expandable Buffer
    178186
    179 // Expandable Buffer
    180 
    181187void ExpandableBuffer::allocateBuffer() {
    182188    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType());
     
    269275}
    270276
     277llvm::Value * ExpandableBuffer::getStreamSetCount(llvm::Value * self) const {
     278    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
     279}
     280
    271281Value * ExpandableBuffer::getStreamSetBlockPtr(Value *, Value *) const {
    272     report_fatal_error("Expandable buffers: getStreamSetPtr is not supported.");
     282    report_fatal_error("Expandable buffers: getStreamSetBlockPtr is not supported.");
    273283}
    274284
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5320 r5329  
    5151    virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex) const;
    5252   
     53    virtual llvm::Value * getStreamSetCount(llvm::Value * self) const;
     54
    5355    llvm::Value * getRawItemPointer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    5456
     
    165167    void allocateBuffer() override;
    166168
     169    llvm::Value * getStreamSetCount(llvm::Value * self) const override;
     170
    167171protected:
    168172
Note: See TracChangeset for help on using the changeset viewer.