Ignore:
Timestamp:
Apr 24, 2018, 2:57:34 PM (18 months ago)
Author:
nmedfort
Message:

Restructured MultiBlock? kernel. Removal of Swizzled buffers. Inclusion of PopCount? rates / non-linear access. Modifications to several kernels to better align them with the kernel and pipeline changes.

Location:
icGREP/icgrep-devel/icgrep/IR_Gen
Files:
4 edited

Legend:

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

    r5924 r5985  
    2222#include <unistd.h>
    2323#include <stdio.h>
     24#include <boost/format.hpp>
    2425
    2526#if defined(__i386__)
     
    9192}
    9293
     94static inline bool notConstantZeroArraySize(const AllocaInst * const Base) {
     95    if (const Constant * const as = dyn_cast_or_null<Constant>(Base->getArraySize())) {
     96        return !as->isNullValue();
     97    }
     98    return false;
     99}
     100
    93101static Value * checkStackAddress(CBuilder * const b, Value * const Ptr, Value * const Size, AllocaInst * const Base) {
    94102    DataLayout DL(b->getModule());
    95103    IntegerType * const intPtrTy = cast<IntegerType>(DL.getIntPtrType(Ptr->getType()));
    96104    Value * sz = ConstantExpr::getBitCast(ConstantExpr::getSizeOf(Base->getAllocatedType()), intPtrTy);
    97     if (dyn_cast_or_null<Constant>(Base->getArraySize()) && !cast<Constant>(Base->getArraySize())->isNullValue()) {
     105    if (notConstantZeroArraySize(Base)) {
    98106        sz = b->CreateMul(sz, b->CreateZExtOrTrunc(Base->getArraySize(), intPtrTy));
    99107    }
     
    141149}
    142150
    143 Value * CBuilder::CreateUDivCeil(Value * const number, Value * const divisor, const Twine & Name) {
     151Value * CBuilder::CreateCeilUDiv(Value * const number, Value * const divisor, const Twine & Name) {
    144152    assert (number->getType() == divisor->getType());
    145153    Type * const t = number->getType();
     
    155163        }
    156164    }
    157     CreateAssert(divisor, "CreateUDivCeil divisor cannot be 0!");
     165    CreateAssert(divisor, "CreateCeilUDiv divisor cannot be 0!");
    158166    return CreateUDiv(n, divisor, Name);
    159167}
    160168
    161169Value * CBuilder::CreateRoundUp(Value * const number, Value * const divisor, const Twine &Name) {
    162     return CreateMul(CreateUDivCeil(number, divisor), divisor, Name);
     170    return CreateMul(CreateCeilUDiv(number, divisor), divisor, Name);
    163171}
    164172
     
    835843
    836844void __report_failure(const char * msg, const uintptr_t * trace, const uint32_t n) {
     845    // TODO: look into boost stacktrace, available from version 1.65
    837846    raw_fd_ostream out(STDERR_FILENO, false);
    838847    if (trace) {
     
    842851            const auto pc = trace[i];
    843852            trace_string << format_hex(pc, 16) << "   ";
    844             const auto len = codegen::ProgramName.length() + 32;
    845             char cmd[len];
    846             snprintf(cmd, len,"addr2line -fpCe %s %p", codegen::ProgramName.data(), reinterpret_cast<void *>(pc));
    847             FILE * f = popen(cmd, "r");
     853            #ifdef __APPLE__
     854            const auto translator = "atos -o %s %p";
     855            #else
     856            const auto translator = "addr2line -fpCe %s %p";
     857            #endif
     858            const auto cmd = boost::format(translator) % codegen::ProgramName.data() % pc;
     859            FILE * const f = popen(cmd.str().data(), "r");
    848860            if (f) {
    849861                char buffer[1024] = {0};
     
    852864                }
    853865                pclose(f);
     866            } else { // TODO: internal default
     867
     868
    854869            }
    855870        }
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5919 r5985  
    5555    // Division with rounding up to the ceiling
    5656    // Equivalent to CreateUDiv(CreateAdd(number, CreateSub(divisor, ConstantInt::get(divisor->getType(), 1))), divisor)
    57     llvm::Value * CreateUDivCeil(llvm::Value * number, llvm::Value * divisor, const llvm::Twine &Name = "");
     57    llvm::Value * CreateCeilUDiv(llvm::Value * number, llvm::Value * divisor, const llvm::Twine &Name = "");
     58
     59    llvm::Value * CreateUDivCeil(llvm::Value * number, llvm::Value * divisor, const llvm::Twine &Name = "") {
     60        return CreateCeilUDiv(number, divisor, Name);
     61    }
    5862   
    5963    // Round up to a multiple of divisor.
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r5979 r5985  
    171171    VectorType * const vecTy = cast<VectorType>(value->getType());
    172172    IntegerType * const intTy = getIntNTy(vecTy->getBitWidth());
     173    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::EnableAsserts))) {
     174        Type * const ty = shift->getType();
     175        Value * const scaled = CreateMul(shift, ConstantInt::get(ty, fw));
     176        Value * const inbounds = CreateICmpULE(scaled, ConstantInt::get(ty, vecTy->getBitWidth()));
     177        CreateAssert(inbounds, "shift exceeds vector width");
     178    }
    173179    value = CreateBitCast(value, intTy);
    174180    shift = CreateZExtOrTrunc(CreateMul(shift, ConstantInt::get(shift->getType(), fw)), intTy);
     
    179185    VectorType * const vecTy = cast<VectorType>(value->getType());
    180186    IntegerType * const intTy = getIntNTy(vecTy->getBitWidth());
     187    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::EnableAsserts))) {
     188        Type * const ty = shift->getType();
     189        Value * const scaled = CreateMul(shift, ConstantInt::get(ty, fw));
     190        Value * const inbounds = CreateICmpULE(scaled, ConstantInt::get(ty, vecTy->getBitWidth()));
     191        CreateAssert(inbounds, "shift exceeds vector width");
     192    }
    181193    value = CreateBitCast(value, intTy);
    182194    shift = CreateZExtOrTrunc(CreateMul(shift, ConstantInt::get(shift->getType(), fw)), intTy);
     
    614626}
    615627
     628Value * IDISA_Builder::bitblock_popcount(Value * const to_count) {
     629    const auto fieldWidth = getSizeTy()->getBitWidth();
     630    auto fields = (getBitBlockWidth() / fieldWidth);
     631    Value * fieldCounts = simd_popcount(fieldWidth, to_count);
     632    while (fields > 1) {
     633        fields /= 2;
     634        fieldCounts = CreateAdd(fieldCounts, mvmd_srli(fieldWidth, fieldCounts, fields));
     635    }
     636    return mvmd_extract(fieldWidth, fieldCounts, 0);
     637}
     638
    616639Value * IDISA_Builder::simd_and(Value * a, Value * b) {
    617640    return a->getType() == b->getType() ? CreateAnd(a, b) : CreateAnd(bitCast(a), bitCast(b));
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5972 r5985  
    160160    virtual llvm::Value * bitblock_set_bit(llvm::Value * pos);
    161161
     162    // returns a scalar with the popcount of this block
     163    llvm::Value * bitblock_popcount(llvm::Value * const to_count);
     164
    162165    virtual void CreateBaseFunctions() {}
    163166   
     
    172175    }
    173176
    174     static llvm::VectorType * getStreamTy(llvm::LLVMContext & C, const unsigned FieldWidth = 1) {
     177    static llvm::VectorType * LLVM_READNONE getStreamTy(llvm::LLVMContext & C, const unsigned FieldWidth = 1) {
    175178        return llvm::VectorType::get(llvm::IntegerType::getIntNTy(C, FieldWidth), 0);
    176179    }
    177180
    178     static llvm::ArrayType * getStreamSetTy(llvm::LLVMContext & C, const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
     181    static llvm::ArrayType * LLVM_READNONE getStreamSetTy(llvm::LLVMContext & C, const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    179182        return llvm::ArrayType::get(getStreamTy(C, FieldWidth), NumElements);
    180183    }
Note: See TracChangeset for help on using the changeset viewer.