Ignore:
Timestamp:
Feb 26, 2017, 4:30:51 PM (2 years ago)
Author:
nmedfort
Message:

First attempt at inlining all DoBlock? and FinalBlock? functions by using indirect jumps. Disabled for NVPTX until Linda can check whether they're supported by the LLVM NVPTX library.

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

Legend:

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

    r5347 r5350  
    1010#include <llvm/IR/Intrinsics.h>
    1111#include <llvm/IR/TypeBuilder.h>
     12#include <llvm/IR/MDBuilder.h>
    1213#include <fcntl.h>
    1314#include <toolchain.h>
     
    1516using namespace llvm;
    1617
    17 llvm::Value * CBuilder::CreateOpenCall(Value * filename, Value * oflag, Value * mode) {
     18Value * CBuilder::CreateOpenCall(Value * filename, Value * oflag, Value * mode) {
    1819    Function * openFn = mMod->getFunction("open");
    1920    if (openFn == nullptr) {
     
    5354}
    5455
    55 llvm::Value * CBuilder::CreateCloseCall(Value * fildes) {
     56Value * CBuilder::CreateCloseCall(Value * fildes) {
    5657    Function * closeFn = mMod->getFunction("close");
    5758    if (closeFn == nullptr) {
     
    293294    if (fOpenFunc == nullptr) {
    294295        fOpenFunc = cast<Function>(mMod->getOrInsertFunction("fopen", getFILEptrTy(), getInt8Ty()->getPointerTo(), getInt8Ty()->getPointerTo(), nullptr));
    295         fOpenFunc->setCallingConv(llvm::CallingConv::C);
     296        fOpenFunc->setCallingConv(CallingConv::C);
    296297    }
    297298    return CreateCall(fOpenFunc, {filename, mode});
     
    302303    if (fReadFunc == nullptr) {
    303304        fReadFunc = cast<Function>(mMod->getOrInsertFunction("fread", getSizeTy(), getVoidPtrTy(), getSizeTy(), getSizeTy(), getFILEptrTy(), nullptr));
    304         fReadFunc->setCallingConv(llvm::CallingConv::C);
     305        fReadFunc->setCallingConv(CallingConv::C);
    305306    }
    306307    return CreateCall(fReadFunc, {ptr, size, nitems, stream});
     
    311312    if (fWriteFunc == nullptr) {
    312313        fWriteFunc = cast<Function>(mMod->getOrInsertFunction("fwrite", getSizeTy(), getVoidPtrTy(), getSizeTy(), getSizeTy(), getFILEptrTy(), nullptr));
    313         fWriteFunc->setCallingConv(llvm::CallingConv::C);
     314        fWriteFunc->setCallingConv(CallingConv::C);
    314315    }
    315316    return CreateCall(fWriteFunc, {ptr, size, nitems, stream});
     
    320321    if (fCloseFunc == nullptr) {
    321322        fCloseFunc = cast<Function>(mMod->getOrInsertFunction("fclose", getInt32Ty(), getFILEptrTy(), nullptr));
    322         fCloseFunc->setCallingConv(llvm::CallingConv::C);
     323        fCloseFunc->setCallingConv(CallingConv::C);
    323324    }
    324325    return CreateCall(fCloseFunc, {stream});
     
    337338                                                                     static_cast<Type *>(funVoidPtrVoidTy)->getPointerTo(),
    338339                                                                     getVoidPtrTy(), nullptr));
    339         pthreadCreateFunc->setCallingConv(llvm::CallingConv::C);
     340        pthreadCreateFunc->setCallingConv(CallingConv::C);
    340341    }
    341342    return CreateCall(pthreadCreateFunc, {thread, attr, start_routine, arg});
     
    346347    if (pthreadExitFunc == nullptr) {
    347348        pthreadExitFunc = cast<Function>(mMod->getOrInsertFunction("pthread_exit", getVoidTy(), getVoidPtrTy(), nullptr));
    348         pthreadExitFunc->addFnAttr(llvm::Attribute::NoReturn);
    349         pthreadExitFunc->setCallingConv(llvm::CallingConv::C);
     349        pthreadExitFunc->addFnAttr(Attribute::NoReturn);
     350        pthreadExitFunc->setCallingConv(CallingConv::C);
    350351    }
    351352    CallInst * exitThread = CreateCall(pthreadExitFunc, {value_ptr});
     
    360361                                                                       pthreadTy,
    361362                                                                       getVoidPtrTy()->getPointerTo(), nullptr));
    362     pthreadJoinFunc->setCallingConv(llvm::CallingConv::C);
     363    pthreadJoinFunc->setCallingConv(CallingConv::C);
    363364    return CreateCall(pthreadJoinFunc, {thread, value_ptr});
    364365}
    365366
    366 void CBuilder::CreateAssert(llvm::Value * const assertion, llvm::StringRef failureMessage) {
     367void CBuilder::CreateAssert(Value * const assertion, StringRef failureMessage) {
    367368    if (codegen::EnableAsserts) {
    368369        Module * const m = getModule();
     
    414415}
    415416
    416 CBuilder::CBuilder(llvm::Module * m, unsigned GeneralRegisterWidthInBits, unsigned CacheLineAlignmentInBytes)
     417BranchInst * CBuilder::CreateLikelyCondBr(Value * Cond, BasicBlock * True, BasicBlock * False, const int probability) {
     418    MDBuilder mdb(getContext());
     419    if (probability < 0 || probability > 100) {
     420        report_fatal_error("branch weight probability must be in [0,100]");
     421    }
     422    return CreateCondBr(Cond, True, False, mdb.createBranchWeights(probability, 100 - probability));
     423}
     424
     425CBuilder::CBuilder(Module * const m, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes)
    417426: IRBuilder<>(m->getContext())
    418427, mMod(m)
    419428, mCacheLineAlignment(CacheLineAlignmentInBytes)
    420429, mSizeType(getIntNTy(GeneralRegisterWidthInBits))
    421 , mFILEtype(nullptr) {
    422 }
     430, mFILEtype(nullptr)
     431, mSupportsIndirectBr(SupportsIndirectBr) {
     432}
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5347 r5350  
    2020public:
    2121   
    22     CBuilder(llvm::Module * m, unsigned GeneralRegisterWidthInBits, unsigned CacheLineAlignmentInBytes = 64);
     22    CBuilder(llvm::Module * m, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes = 64);
    2323   
    2424    virtual ~CBuilder() {}
     
    113113    void CreateExit(const int exitCode);
    114114
     115    llvm::BranchInst * CreateLikelyCondBr(llvm::Value * Cond, llvm::BasicBlock * True, llvm::BasicBlock * False, const int probability = 90);
     116
     117    llvm::BranchInst * CreateUnlikelyCondBr(llvm::Value * Cond, llvm::BasicBlock * True, llvm::BasicBlock * False, const int probability = 90) {
     118        return CreateLikelyCondBr(Cond, True, False, 100 - probability);
     119    }
     120
     121    bool supportsIndirectBr() const {
     122        return mSupportsIndirectBr;
     123    }
     124
    115125protected:
    116126    llvm::Module *      mMod;
     
    118128    llvm::IntegerType * mSizeType;
    119129    llvm::StructType *  mFILEtype;
     130    const bool          mSupportsIndirectBr;
    120131};
    121132
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r5309 r5350  
    356356}
    357357
    358 IDISA_Builder::IDISA_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, unsigned CacheAlignment)
    359 : CBuilder(m, archBitWidth, CacheAlignment)
     358IDISA_Builder::IDISA_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr, unsigned CacheAlignment)
     359: CBuilder(m, archBitWidth, SupportsIndirectBr, CacheAlignment)
    360360, mBitBlockWidth(bitBlockWidth)
    361361, mStride(stride)
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5307 r5350  
    2020public:
    2121
    22     IDISA_Builder(llvm::Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, unsigned CacheAlignment=64);
     22    IDISA_Builder(llvm::Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr=true, unsigned CacheAlignment=64);
    2323
    2424    virtual ~IDISA_Builder();
     
    4646    }
    4747   
    48 
    4948    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr);
    5049    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr, llvm::Value * const index);
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_i64_builder.h

    r5260 r5350  
    1616public:
    1717 
    18     IDISA_I64_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth = 64, unsigned stride = 64)
    19     : IDISA_Builder(m, archBitWidth, bitBlockWidth, stride) {
     18    IDISA_I64_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth = 64, unsigned stride = 64, const bool SupportsIndirectBr = true)
     19    : IDISA_Builder(m, archBitWidth, bitBlockWidth, stride, SupportsIndirectBr) {
    2020    }
    2121
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_nvptx_builder.h

    r5260 r5350  
    1717   
    1818    IDISA_NVPTX20_Builder(Module * m, unsigned groupSize)
    19     : IDISA_I64_Builder(m, 64, 64, 64 * groupSize)
     19    : IDISA_I64_Builder(m, 64, 64, 64 * groupSize, false)
    2020    , groupThreads(groupSize) {
    2121        CreateGlobals();
Note: See TracChangeset for help on using the changeset viewer.