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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.