Changeset 5422 for icGREP


Ignore:
Timestamp:
Apr 24, 2017, 2:58:47 PM (2 years ago)
Author:
cameron
Message:

lz4d - LZ4 decompressor - initial check-in

Location:
icGREP/icgrep-devel/icgrep
Files:
7 added
6 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5421 r5422  
    116116    }
    117117    return printf;
     118}
     119
     120Function * CBuilder::GetDprintf() {
     121    Function * dprintf = mMod->getFunction("dprintf");
     122    if (dprintf == nullptr) {
     123        FunctionType * fty = FunctionType::get(getInt32Ty(), {getInt32Ty(), getInt8PtrTy()}, true);
     124        dprintf = Function::Create(fty, Function::ExternalLinkage, "dprintf", mMod);
     125    }
     126    return dprintf;
    118127}
    119128
     
    149158    assert (num->getType()->isIntegerTy());
    150159    CreateCall(printRegister, {GetString(name.c_str()), num});
     160}
     161
     162void CBuilder::CallPrintIntToStderr(const std::string & name, Value * const value) {
     163    Constant * printRegister = mMod->getFunction("PrintIntToStderr");
     164    if (LLVM_UNLIKELY(printRegister == nullptr)) {
     165        FunctionType *FT = FunctionType::get(getVoidTy(), { PointerType::get(getInt8Ty(), 0), getSizeTy() }, false);
     166        Function * function = Function::Create(FT, Function::InternalLinkage, "PrintIntToStderr", mMod);
     167        auto arg = function->arg_begin();
     168        std::string out = "%-40s = %" PRIx64 "\n";
     169        BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     170        IRBuilder<> builder(entry);
     171        std::vector<Value *> args;
     172        args.push_back(getInt32(2));    // fd 2 (stderr)
     173        args.push_back(GetString(out.c_str()));
     174        Value * const name = &*(arg++);
     175        name->setName("name");
     176        args.push_back(name);
     177        Value * value = &*arg;
     178        value->setName("value");
     179        args.push_back(value);
     180        builder.CreateCall(GetDprintf(), args);
     181        builder.CreateRetVoid();
     182
     183        printRegister = function;
     184    }
     185    Value * num = nullptr;
     186    if (value->getType()->isPointerTy()) {
     187        num = CreatePtrToInt(value, getSizeTy());
     188    } else {
     189        num = CreateZExtOrBitCast(value, getSizeTy());
     190    }
     191    assert (num->getType()->isIntegerTy());
     192    CreateCall(printRegister, {GetString(name.c_str()), num});
     193}
     194
     195void CBuilder::CallPrintMsgToStderr(const std::string & message) {
     196    Constant * printMsg = mMod->getFunction("PrintMsgToStderr");
     197    if (LLVM_UNLIKELY(printMsg == nullptr)) {
     198        FunctionType *FT = FunctionType::get(getVoidTy(), { PointerType::get(getInt8Ty(), 0) }, false);
     199        Function * function = Function::Create(FT, Function::InternalLinkage, "PrintMsgToStderr", mMod);
     200        auto arg = function->arg_begin();
     201        std::string out = "%s\n";
     202        BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     203        IRBuilder<> builder(entry);
     204        std::vector<Value *> args;
     205        args.push_back(getInt32(2));    // fd 2 (stderr)
     206        args.push_back(GetString(out.c_str()));
     207        Value * const msg = &*(arg++);
     208        msg->setName("msg");
     209        args.push_back(msg);
     210        builder.CreateCall(GetDprintf(), args);
     211        builder.CreateRetVoid();
     212
     213        printMsg = function;
     214    }
     215    CreateCall(printMsg, {GetString(message.c_str())});
    151216}
    152217
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5419 r5422  
    7070    llvm::Function * GetPrintf();
    7171
     72    llvm::Function * GetDprintf();
     73
    7274    //  Create calls to unistd.h functions.
    7375    //
     
    129131    void CallPrintInt(const std::string & name, llvm::Value * const value);
    130132   
     133    void CallPrintIntToStderr(const std::string & name, llvm::Value * const value);
     134   
    131135    llvm::Value * GetString(llvm::StringRef Str);
     136   
     137    void CallPrintMsgToStderr(const std::string & message);
    132138
    133139    inline llvm::IntegerType * getSizeTy() const {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5419 r5422  
    386386private:
    387387
    388     bool useIndirectBr() const {
     388    virtual bool useIndirectBr() const {
    389389        return iBuilder->supportsIndirectBr();
    390390    }
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5391 r5422  
    124124    Value * bytepack[8];
    125125    for (unsigned i = 0; i < 8; i++) {
    126         bytepack[i] = loadInputStreamPack("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
     126        if (mAligned) {
     127            bytepack[i] = loadInputStreamPack("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
     128        } else {
     129            Value * ptr = getInputStreamPackPtr("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
     130            // CreateLoad defaults to aligned here, so we need to force the alignment to 1 byte.
     131            bytepack[i] = iBuilder->CreateAlignedLoad(ptr, 1);
     132        }
    127133    }
    128134    Value * basisbits[8];
     
    161167}
    162168
    163 S2PKernel::S2PKernel(IDISA::IDISA_Builder * builder)
    164 : BlockOrientedKernel(builder, "Parabix:s2p",
    165     {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {Binding{builder->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}) {
     169S2PKernel::S2PKernel(IDISA::IDISA_Builder * builder, bool aligned)
     170: BlockOrientedKernel(builder, aligned ? "Parabix:s2p" : "Parabix:s2p_unaligned",
     171    {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {Binding{builder->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}),
     172  mAligned(aligned) {
    166173    setNoTerminateAttribute(true);
    167174}
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5392 r5422  
    1414class S2PKernel : public BlockOrientedKernel {
    1515public:   
    16     S2PKernel(IDISA::IDISA_Builder * builder);
     16    S2PKernel(IDISA::IDISA_Builder * builder, bool aligned = true);
    1717    bool moduleIDisSignature() override {return true;}
    1818    virtual ~S2PKernel() {}
     
    2020    void generateDoBlockMethod() override;
    2121    void generateFinalBlockMethod(llvm::Value * remainingBytes) override;
     22private:
     23    bool mAligned;
    2224};
    2325
  • icGREP/icgrep-devel/icgrep/kernels/toolchain.cpp

    r5418 r5422  
    295295    PM.add(createVerifierPass());
    296296    #endif
     297    PM.add(createPromoteMemoryToRegisterPass()); //Force the use of mem2reg to promote stack variables.
    297298    PM.add(createReassociatePass());             //Reassociate expressions.
    298299    PM.add(createGVNPass());                     //Eliminate common subexpressions.
Note: See TracChangeset for help on using the changeset viewer.