Changeset 5243


Ignore:
Timestamp:
Dec 29, 2016, 11:23:44 PM (12 months ago)
Author:
cameron
Message:

Support for write function in CBuilder, use IRBuilder CreateMemMove? for llvm.memmove.p0i8.p0i8.i64

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

Legend:

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

    r5242 r5243  
    1313#include <llvm/IR/TypeBuilder.h>
    1414
    15    
     15
     16
     17// ssize_t write(int fildes, const void *buf, size_t nbyte);
     18Value * CBuilder::CreateWriteCall(Value * fildes, Value * buf, Value * nbyte) {
     19    Function * write = mMod->getFunction("write");
     20    if (write == nullptr) {
     21        IntegerType * sizeTy = getSizeTy();
     22        IntegerType * int32Ty = getInt32Ty();
     23        PointerType * int8PtrTy = getInt8PtrTy();
     24        write = cast<Function>(mMod->getOrInsertFunction("write",
     25                                                        AttributeSet().addAttribute(mMod->getContext(), 2U, Attribute::NoAlias),
     26                                                        sizeTy, int32Ty, int8PtrTy, sizeTy, nullptr));
     27    }
     28    return CreateCall(write, {fildes, buf, nbyte});
     29}
     30
    1631Function * CBuilder::GetPrintf() {
    1732    Function * printf = mMod->getFunction("printf");
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5242 r5243  
    5050   
    5151   
     52    // Create calls to unistd.h functions.
     53    //
     54    // ssize_t write(int fildes, const void *buf, size_t nbyte);
     55    Value * CreateWriteCall(Value * fildes, Value * buf, Value * nbyte);
     56   
    5257    // Create calls to Posix thread (pthread.h) functions.
    5358    //
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5238 r5243  
    88
    99namespace kernel {
    10 
    11 static Function * create_write(Module * const mod, IDISA::IDISA_Builder * builder) {
    12     Function * write = mod->getFunction("write");
    13     if (write == nullptr) {
    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));
    20     }
    21     return write;
    22 }
    2310
    2411// The doBlock method is deprecated.   But in case it is used, just call doSegment with
     
    4128    auto savePoint = iBuilder->saveIP();
    4229    Module * m = iBuilder->getModule();
    43     Function * writefn = create_write(m, iBuilder);
    4430    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    4531    Type * i8PtrTy = iBuilder->getInt8PtrTy();
     
    7359    Value * bytePtr = iBuilder->CreateGEP(iBuilder->CreateBitCast(basePtr, i8PtrTy), byteOffset);
    7460
    75     iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes)}));
    76    
     61    iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes));
     62
    7763    processed = iBuilder->CreateAdd(processed, itemsToDo);
    7864    setProcessedItemCount(self, processed);
     
    9783    auto savePoint = iBuilder->saveIP();
    9884    Module * m = iBuilder->getModule();
    99     Function * writefn = create_write(m, iBuilder);
    10085    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    10186    Type * i8PtrTy = iBuilder->getInt8PtrTy();
     
    11398    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    11499    Value * bytePtr = iBuilder->CreateGEP(iBuilder->CreateBitCast(basePtr, i8PtrTy), byteOffset);
    115     iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsAvail, itemBytes)}));
     100    iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsAvail, itemBytes));
    116101    setProcessedItemCount(self, producerPos);
    117102    mStreamSetInputBuffers[0]->setConsumerPos(streamStructPtr, producerPos);
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5240 r5243  
    128128
    129129void LinearCopybackBuffer::setConsumerPos(Value * bufferStructPtr, Value * new_consumer_pos) {
    130     Type * const i1 = iBuilder->getInt1Ty();
    131130    Type * const i8 = iBuilder->getInt8Ty();
    132     Type * const i32 = iBuilder->getInt32Ty();
    133131    Type * const i8_ptr = i8->getPointerTo(mAddrSpace);
    134132    IntegerType * const sizeTy = iBuilder->getSizeTy();
     
    136134    Module * const M = iBuilder->getModule();
    137135
    138     Function * const memmoveFunc = cast<Function>(M->getOrInsertFunction("llvm.memmove.p0i8.p0i8.i" + std::to_string(sizeTy->getBitWidth()),
    139                                                                   iBuilder->getVoidTy(), i8_ptr, i8_ptr, sizeTy, i32, i1, nullptr));
    140136    Function * const current = iBuilder->GetInsertBlock()->getParent();
    141137    BasicBlock * const copyBackBody = BasicBlock::Create(M->getContext(), "copy_back", current, 0);
     
    175171    Value * const consumerBlock = iBuilder->CreateUDiv(consumerPos, blockWidth);
    176172    Value * copyFrom = iBuilder->CreateGEP(bufferPtr, iBuilder->CreateSub(new_consumer_block, consumerBlock));
    177     Value * alignment = ConstantInt::get(iBuilder->getInt32Ty(), iBuilder->getBitBlockWidth() / 8);
    178    
    179     iBuilder->CreateCall(memmoveFunc, {iBuilder->CreateBitCast(bufferPtr, i8_ptr), iBuilder->CreateBitCast(copyFrom, i8_ptr), copyLength, alignment, ConstantInt::getNullValue(i1)});
     173    unsigned alignment = iBuilder->getBitBlockWidth() / 8;
     174    iBuilder->CreateMemMove(iBuilder->CreateBitCast(bufferPtr, i8_ptr), iBuilder->CreateBitCast(copyFrom, i8_ptr), copyLength, alignment);
    180175    iBuilder->CreateBr(setConsumerPosExit);
    181176    // Copy back done, store the new consumer position.
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5242 r5243  
    308308    Type * const inputType = ArrayType::get(ArrayType::get(bitBlockType, 8), 1)->getPointerTo();
    309309    Type * const outputType = ArrayType::get(ArrayType::get(bitBlockType, 16), 1)->getPointerTo();
    310     Type * const int32ty = iBuilder->getInt32Ty();
    311     Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    312     Type * const voidPtrTy = iBuilder->getVoidPtrTy();
    313310   
    314311    Function * const main = cast<Function>(mod->getOrInsertFunction("Main", voidTy, inputType, outputType, size_ty, nullptr));
Note: See TracChangeset for help on using the changeset viewer.