Changeset 5204 for icGREP


Ignore:
Timestamp:
Nov 7, 2016, 12:08:13 PM (3 years ago)
Author:
nmedfort
Message:

More 32-bit fixes.

Location:
icGREP/icgrep-devel/icgrep
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.cpp

    r5202 r5204  
    1111#include <llvm/IR/Intrinsics.h>
    1212#include <llvm/IR/Function.h>
    13 #include <llvm/IR/TypeBuilder.h>
    1413#include <llvm/Support/raw_ostream.h>
    1514#include <iostream>
     
    3433
    3534   
    36 static Function * create_printf(Module * const mod) {
     35static Function * create_printf(Module * const mod, IDISA_Builder * builder) {
    3736    Function * printf = mod->getFunction("printf");
    3837    if (printf == nullptr) {
    39         FunctionType *printf_type =
    40             TypeBuilder<int(char *, ...), false>::get(mod->getContext());
    41         printf = cast<Function>(mod->getOrInsertFunction("printf", printf_type,
    42             AttributeSet().addAttribute(mod->getContext(), 1U, Attribute::NoAlias)));
     38        printf = cast<Function>(mod->getOrInsertFunction("printf"
     39                                , FunctionType::get(builder->getInt32Ty(), {builder->getInt8PtrTy()}, true)
     40                                , AttributeSet().addAttribute(mod->getContext(), 1U, Attribute::NoAlias)));
     41
    4342    }
    4443    return printf;
     
    7271            args.push_back(builder.CreateExtractElement(value, builder.getInt32(i - 1)));
    7372        }
    74         builder.CreateCall(create_printf(mMod), args);
     73        builder.CreateCall(create_printf(mMod, this), args);
    7574        builder.CreateRetVoid();
    7675
     
    9998        value->setName("value");
    10099        args.push_back(value);
    101         builder.CreateCall(create_printf(mMod), args);
     100        builder.CreateCall(create_printf(mMod, this), args);
    102101        builder.CreateRetVoid();
    103102
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.h

    r5192 r5204  
    2626    , mMod(m)
    2727    , mCacheLineAlignment(CacheAlignment)
     28    , mIsArch32Bit(Triple(llvm::sys::getProcessTriple()).isArch32Bit())
    2829    , mBitBlockType(bitBlockType)
    2930    , mBitBlockWidth(bitBlockType->isIntegerTy() ? cast<IntegerType>(bitBlockType)->getIntegerBitWidth() : cast<VectorType>(bitBlockType)->getBitWidth())
     
    141142    Value * fwCast(unsigned fw, Value * a);
    142143   
    143     inline llvm::Type * getSizeTy() {return Triple(llvm::sys::getProcessTriple()).isArch32Bit() ? getInt32Ty() : getInt64Ty();}
     144    inline bool isArch32Bit() const {
     145        return mIsArch32Bit;
     146    }
     147
     148    inline llvm::IntegerType * getSizeTy() {
     149        return isArch32Bit() ? getInt32Ty() : getInt64Ty();
     150    }
    144151   
    145152    inline llvm::AllocaInst * CreateCacheAlignedAlloca(llvm::Type * Ty, llvm::Value * ArraySize = nullptr) {
     
    155162    Module * mMod;
    156163    unsigned mCacheLineAlignment;
     164    const bool mIsArch32Bit;
    157165    Type * mBitBlockType;
    158166    unsigned mBitBlockWidth;
     
    161169    Constant * mOneInitializer;
    162170    Constant * mPrintRegisterFunction;
     171
    163172   
    164173    VectorType * fwVectorType(unsigned fw);
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5202 r5204  
    2424                  {}, {}, {}, {}),
    2525    mEditDistance(dist),
    26     mScanwordBitWidth(Triple(llvm::sys::getProcessTriple()).isArch32Bit() ? 32 : 64) {}
     26    mScanwordBitWidth(iBuilder->getSizeTy()->getBitWidth()) {}
    2727       
    2828private:
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5203 r5204  
    219219    MatchResults.setStreamSetBuffer(rsltStream, fileSize);
    220220
    221     kernel::scanMatchKernel scanMatchK(iBuilder, isNameExpression);
     221    kernel::ScanMatchKernel scanMatchK(iBuilder, isNameExpression);
    222222    scanMatchK.generateKernel({&MatchResults}, {});
    223223           
     
    255255    IDISA::IDISA_Builder * CPUBuilder = IDISA::GetIDISA_Builder(cpuM);
    256256
    257     if(CPU_Only) {
     257    if (CPU_Only) {
    258258        M = cpuM;
    259259        iBuilder = CPUBuilder;
     
    272272
    273273    Type * const int32ty = iBuilder->getInt32Ty();
    274     Type * const int64ty = iBuilder->getInt64Ty();
     274    Type * const size_ty = iBuilder->getSizeTy();
    275275    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    276276    Type * const voidTy = Type::getVoidTy(M->getContext());   
    277277    Type * const voidPtrTy = TypeBuilder<void *, false>::get(M->getContext());
    278278    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), (UTF_16 ? 16 : 8)), 1), addrSpace);
    279     Type * const resultTy = CountOnly ? int64ty : iBuilder->getVoidTy();
     279    Type * const resultTy = CountOnly ? size_ty : iBuilder->getVoidTy();
    280280
    281281    Function * mainFn = nullptr;
     
    314314#endif
    315315    if (CPU_Only){
    316         mainFn = cast<Function>(M->getOrInsertFunction("Main", resultTy, inputType, int64ty, int64ty, nullptr));
     316        mainFn = cast<Function>(M->getOrInsertFunction("Main", resultTy, inputType, size_ty, size_ty, nullptr));
    317317        mainFn->setCallingConv(CallingConv::C);
    318318        iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFn, 0));
     
    342342    Value * s2pInstance = s2pk.createInstance({});
    343343 
    344     Type * pthreadTy = int64ty;
     344    Type * pthreadTy = size_ty;
    345345    FunctionType * funVoidPtrVoidTy = FunctionType::get(voidTy, int8PtrTy, false);   
    346346   
     
    402402            Value * icgrepInstance = icgrepK.createInstance({});
    403403
    404             kernel::scanMatchKernel scanMatchK(iBuilder, mIsNameExpression);
     404            kernel::ScanMatchKernel scanMatchK(iBuilder, mIsNameExpression);
    405405            scanMatchK.generateKernel({&MatchResults}, {});               
    406406            Value * scanMatchInstance = scanMatchK.createInstance({iBuilder->CreateBitCast(inputStream, int8PtrTy), fileSize, fileIdx});
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5202 r5204  
    4040
    4141       
    42 void scanMatchKernel::generateDoBlockMethod() {
     42void ScanMatchKernel::generateDoBlockMethod() {
    4343    auto savePoint = iBuilder->saveIP();
    4444    Module * m = iBuilder->getModule();
    4545    Function * scanWordFunction = generateScanWordRoutine(m);
    46     const unsigned fieldCount = iBuilder->getBitBlockWidth() / mScanwordBitWidth;
    47     Type * T = iBuilder->getIntNTy(mScanwordBitWidth);
     46    IntegerType * T = iBuilder->getSizeTy();
     47    const unsigned fieldCount = iBuilder->getBitBlockWidth() / T->getBitWidth();
     48
    4849    Type * scanwordVectorType =  VectorType::get(T, fieldCount);
    4950
     
    6667        Value * recordBreaksWord = iBuilder->CreateExtractElement(breakWordVector, ConstantInt::get(T, i));
    6768        Value * wordResult = iBuilder->CreateCall(scanWordFunction, {kernelStuctParam, matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum});
    68         scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, mScanwordBitWidth));
     69        scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, T->getBitWidth()));
    6970        recordStart = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({0}));
    7071        recordNum = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({1}));
     
    7778
    7879   
    79 Function * scanMatchKernel::generateScanWordRoutine(Module * m) {
     80Function * ScanMatchKernel::generateScanWordRoutine(Module * m) {
    8081    Function * function = m->getFunction("scan_matches_in_scanword");
    8182    if (LLVM_UNLIKELY(function != nullptr)) {
     
    8485   
    8586    LLVMContext & ctxt = m->getContext();
    86     Type * T = iBuilder->getIntNTy(mScanwordBitWidth);
     87
     88    IntegerType * T = iBuilder->getSizeTy();
    8789    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
    8890    Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
     
    174176    Value * matchRecordNum = iBuilder->CreateAdd(generatePopcount(iBuilder, prior_breaks), recordNum_phi);
    175177    Value * reverseDistance = generateCountReverseZeroes(iBuilder, prior_breaks);
    176     Value * width = ConstantInt::get(T, mScanwordBitWidth);
     178    Value * width = ConstantInt::get(T, T->getBitWidth());
    177179    Value * matchRecordStart = iBuilder->CreateAdd(scanwordPos, iBuilder->CreateSub(width, reverseDistance));
    178180    iBuilder->CreateBr(loop_final_block);
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5202 r5204  
    1717namespace kernel {
    1818   
    19 class scanMatchKernel : public KernelBuilder {
     19class ScanMatchKernel : public KernelBuilder {
    2020public:
    21     scanMatchKernel(IDISA::IDISA_Builder * iBuilder, bool isNameExpression) :
     21    ScanMatchKernel(IDISA::IDISA_Builder * iBuilder, bool isNameExpression) :
    2222    KernelBuilder(iBuilder, "scanMatch",
    2323                  {Binding{parabix::StreamSetType(iBuilder,2, 1), "matchResults"}},
     
    2727                    {Binding{iBuilder->getSizeTy(), "BlockNo"}, Binding{iBuilder->getSizeTy(), "LineStart"}, Binding{iBuilder->getSizeTy(), "LineNum"}}),
    2828
    29     mScanwordBitWidth(Triple(llvm::sys::getProcessTriple()).isArch32Bit() ? 32 : 64),
    3029    mIsNameExpression(isNameExpression) {}
    3130       
     
    3433    llvm::Function * generateScanWordRoutine(llvm::Module * m);
    3534       
    36     unsigned mScanwordBitWidth;
    3735    bool mIsNameExpression;
    3836};
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5202 r5204  
    66#include <kernels/kernel.h>
    77#include <IDISA/idisa_builder.h>
    8 #include <llvm/IR/TypeBuilder.h>
    98
    109namespace kernel {
    1110
    12 static Function * create_write(Module * const mod) {
     11static Function * create_write(Module * const mod, IDISA::IDISA_Builder * builder) {
    1312    Function * write = mod->getFunction("write");
    1413    if (write == nullptr) {
    15         FunctionType *write_type =
    16         TypeBuilder<long(int, char *, long), false>::get(mod->getContext());
    17         write = cast<Function>(mod->getOrInsertFunction("write", write_type,
    18                                                          AttributeSet().addAttribute(mod->getContext(), 2U, Attribute::NoAlias)));
     14        IntegerType * sizeTy = builder->getSizeTy();
     15        IntegerType * int32Ty = builder->getInt32Ty();
     16        PointerType * int8PtrTy = builder->getInt8PtrTy();
     17        write = cast<Function>(mod->getOrInsertFunction("write",
     18                                 AttributeSet().addAttribute(mod->getContext(), 2U, Attribute::NoAlias),
     19                                 sizeTy, int32Ty, int8PtrTy, sizeTy, nullptr));
    1920    }
    2021    return write;
     
    4041    auto savePoint = iBuilder->saveIP();
    4142    Module * m = iBuilder->getModule();
    42     Function * writefn = create_write(m);
     43    Function * writefn = create_write(m, iBuilder);
    4344    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    4445    Type * i8PtrTy = iBuilder->getInt8PtrTy();
     
    106107    auto savePoint = iBuilder->saveIP();
    107108    Module * m = iBuilder->getModule();
    108     Function * writefn = create_write(m);
     109    Function * writefn = create_write(m, iBuilder);
    109110    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    110111    Type * i8PtrTy = iBuilder->getInt8PtrTy();
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5202 r5204  
    145145    Type * const i32 = iBuilder->getInt32Ty();
    146146    Type * const i8_ptr = PointerType::get(i8, mAddrSpace);
     147
     148
    147149    Module * M = iBuilder->getModule();
    148     Function * memmoveFunc = cast<Function>(M->getOrInsertFunction("llvm.memmove.p0i8.p0i8.i" + std::to_string(sizeof(size_t) * 8),
    149                                                                   iBuilder->getVoidTy(), i8_ptr, i8_ptr, iBuilder->getSizeTy(), i32, i1, nullptr));
     150
     151    IntegerType * sizeTy = iBuilder->getSizeTy();
     152
     153    Function * memmoveFunc = cast<Function>(M->getOrInsertFunction("llvm.memmove.p0i8.p0i8.i" + std::to_string(sizeTy->getBitWidth()),
     154                                                                  iBuilder->getVoidTy(), i8_ptr, i8_ptr, sizeTy, i32, i1, nullptr));
    150155    Function * current = iBuilder->GetInsertBlock()->getParent();
    151156    BasicBlock * copyBackBody = BasicBlock::Create(M->getContext(), "copy_back", current, 0);
    152157    BasicBlock * setConsumerPosExit = BasicBlock::Create(M->getContext(), "setConsumerPos_done", current, 0);
    153     Constant * blockWidth = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride());
    154     Constant * one = ConstantInt::get(iBuilder->getSizeTy(), 1);
     158    Constant * blockWidth = ConstantInt::get(sizeTy, iBuilder->getStride());
     159    Constant * one = ConstantInt::get(sizeTy, 1);
    155160    Value * consumerPos_ptr = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)});
    156161    Value * consumerPos = iBuilder->CreateLoad(consumerPos_ptr);
     
    176181    DataLayout dl(iBuilder->getModule());
    177182
    178     Constant * blockBytes = ConstantInt::get(iBuilder->getSizeTy(), dl.getTypeAllocSize(mStreamSetType) * iBuilder->getStride());
     183    Constant * blockBytes = ConstantInt::get(sizeTy, dl.getTypeAllocSize(mStreamSetType) * iBuilder->getStride());
    179184    Value * copyLength = iBuilder->CreateMul(copyBlocks, blockBytes);
    180185    //iBuilder->CallPrintInt("memmove copyLength", copyLength);
     
    182187    Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    183188    Value * bufferPtr = iBuilder->CreateLoad(handle);
    184     //iBuilder->CallPrintInt("memmove bufferPtr", iBuilder->CreatePtrToInt(bufferPtr, iBuilder->getSizeTy()));
     189    //iBuilder->CallPrintInt("memmove bufferPtr", iBuilder->CreatePtrToInt(bufferPtr, sizeTy));
    185190
    186191    Value * copyFrom = iBuilder->CreateGEP(bufferPtr, {iBuilder->CreateSub(new_consumer_block, consumerBlock)});
    187     //iBuilder->CallPrintInt("memmove copyFrom", iBuilder->CreatePtrToInt(copyFrom, iBuilder->getSizeTy()));
     192    //iBuilder->CallPrintInt("memmove copyFrom", iBuilder->CreatePtrToInt(copyFrom, sizeTy));
    188193    Value * alignment = ConstantInt::get(iBuilder->getInt32Ty(), iBuilder->getBitBlockWidth()/8);
    189194   
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5202 r5204  
    387387                if (isa<Count>(cast<Assign>(stmt)->getValue())) {
    388388                    Value * count = iBuilder->CreateLoad(ptr);
    389                     Value * accum = iBuilder->CreateAdd(value, count);
    390                     iBuilder->CreateStore(accum, ptr);
     389                    value = iBuilder->CreateTruncOrBitCast(value, count->getType());
     390                    value = iBuilder->CreateAdd(value, count);
     391                    iBuilder->CreateStore(value, ptr);
    391392                } else {
    392393                    iBuilder->CreateBlockAlignedStore(value, ptr);
     
    488489
    489490        mMarkerMap[expr] = value;
    490 
    491491        if (DebugOptionIsSet(DumpTrace)) {
    492             iBuilder->CallPrintRegister(stmt->getName()->to_string(), value);
     492            assert (expr->getName());
     493            iBuilder->CallPrintRegister(expr->getName()->to_string(), value);
    493494        }
    494495    }
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5202 r5204  
    2424{
    2525    for (unsigned i = 0; i < function->getNumOfParameters(); ++i) {
    26         const auto param = function->getParameter(i);
    27         Type * type = param->getType();
     26        const auto var = function->getParameter(i);
     27        Type * type = var->getType();
    2828        bool scalar = false;
    2929        if (isa<StreamType>(type)) {
    3030            type = cast<StreamType>(type)->resolveType(builder);
    3131        } else if (type->isSingleValueType()) {
     32            if (isa<IntegerType>(type) && cast<IntegerType>(type)->getBitWidth() == 0) {
     33                type = builder->getSizeTy();
     34            }
    3235            scalar = true;
    3336        }
    34         std::string name = param->getName()->to_string();
     37
     38        std::string name = var->getName()->to_string();
    3539        if (scalar) {
    3640            mScalarInputs.emplace_back(type, std::move(name));
     
    4145
    4246    for (unsigned i = 0; i < function->getNumOfResults(); ++i) {
    43         const auto param = function->getResult(i);
    44         Type * type = param->getType();
     47        const auto var = function->getResult(i);
     48        Type * type = var->getType();
    4549        bool scalar = false;
    4650        if (isa<StreamType>(type)) {
    4751            type = cast<StreamType>(type)->resolveType(builder);
    4852        } else if (type->isSingleValueType()) {
     53            if (isa<IntegerType>(type) && cast<IntegerType>(type)->getBitWidth() == 0) {
     54                type = builder->getSizeTy();
     55            }
    4956            scalar = true;
    5057        }
    51         std::string name = param->getName()->to_string();
     58
     59        std::string name = var->getName()->to_string();
    5260        if (scalar) {
    5361            mScalarOutputs.emplace_back(type, std::move(name));
  • icGREP/icgrep-devel/icgrep/pablo/pe_count.h

    r5202 r5204  
    2828protected:
    2929    explicit Count(PabloAST * expr, const String * counter)
    30         : Statement(ClassTypeId::Count, getScalarTy(64), {expr}, counter)
     30        : Statement(ClassTypeId::Count, getScalarTy(), {expr}, counter)
    3131    {
    3232
  • icGREP/icgrep-devel/icgrep/pablo/pe_integer.h

    r5202 r5204  
    2424protected:
    2525    Integer(Type value) noexcept
    26     : PabloAST(ClassTypeId::Integer, getScalarTy(64), nullptr)
     26    : PabloAST(ClassTypeId::Integer, getScalarTy(), nullptr)
    2727    , mValue(value)
    2828    {
  • icGREP/icgrep-devel/icgrep/pablo/type/streamtype.h

    r5202 r5204  
    4949}
    5050
    51 inline llvm::Type * getScalarTy(const uint64_t FieldWidth = 64) {
     51inline llvm::Type * getScalarTy(const uint64_t FieldWidth = 0) {
    5252    return llvm::Type::getIntNTy(llvm::getGlobalContext(), FieldWidth);
    5353}
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5202 r5204  
    235235    PabloAST * matches = mPB.createAnd(match_follow, mLineBreak, "matches");
    236236    if (mCountOnly) {
    237         Var * const output = mFunction.addResult("matchedLineCount", getScalarTy(64));
     237        Var * const output = mFunction.addResult("matchedLineCount", getScalarTy());
    238238        PabloBuilder nestedCount = PabloBuilder::Create(mPB);
    239239        mPB.createIf(matches, nestedCount);
Note: See TracChangeset for help on using the changeset viewer.