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

Added a simple CreateAssert? function in CBuilder and ReadOnly? flag for getStreamSetBufferPtr method to prevent expanding input stream sets. Begun work on CarryManager? to preallocate variable-length carry data slots.

File:
1 edited

Legend:

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

    r5337 r5340  
    99#include <llvm/IR/Constants.h>
    1010#include <llvm/IR/Intrinsics.h>
    11 //#include <llvm/IR/Function.h>
    1211#include <llvm/IR/TypeBuilder.h>
    13 #include <fcntl.h>  // for
     12#include <fcntl.h>
    1413
    1514using namespace llvm;
     
    364363}
    365364
     365void CBuilder::CreateAssert(llvm::Value * const toCheck, llvm::StringRef failureMessage) {
     366    #ifndef NDEBUG
     367    Module * m = getModule();
     368    Function * assertion = m->getFunction("__assert");
     369    if (LLVM_UNLIKELY(assertion == nullptr)) {
     370        auto ip = saveIP();
     371        assertion = cast<Function>(m->getOrInsertFunction("__assert", getVoidTy(), getInt1Ty(), getInt8PtrTy(), getSizeTy(), nullptr));
     372        BasicBlock * entry = BasicBlock::Create(getContext(), "", assertion);
     373        BasicBlock * failure = BasicBlock::Create(getContext(), "", assertion);
     374        BasicBlock * success = BasicBlock::Create(getContext(), "", assertion);
     375        auto arg = assertion->arg_begin();
     376        arg->setName("e");
     377        Value * e = &*arg++;
     378        arg->setName("msg");
     379        Value * msg = &*arg++;
     380        arg->setName("sz");
     381        Value * sz = &*arg;
     382        SetInsertPoint(entry);
     383        CreateCondBr(e, failure, success);
     384        SetInsertPoint(failure);
     385        CreateWriteCall(getInt32(2), msg, sz);
     386        Function * exit = m->getFunction("exit");
     387        if (LLVM_UNLIKELY(exit == nullptr)) {
     388            exit = cast<Function>(m->getOrInsertFunction("exit", getVoidTy(), getInt32Ty(), nullptr));
     389            exit->setDoesNotReturn();
     390            exit->setDoesNotThrow();
     391        }
     392        CreateCall(exit, getInt32(-1));
     393        CreateBr(success); // we're forced to have this to satisfy the LLVM verifier. this is not actually executed.
     394        SetInsertPoint(success);
     395        CreateRetVoid();
     396        restoreIP(ip);
     397    }
     398    CreateCall(assertion, {CreateICmpEQ(toCheck, Constant::getNullValue(toCheck->getType())), CreateGlobalStringPtr(failureMessage), getSize(failureMessage.size())});
     399    #endif
     400}
     401
    366402CBuilder::CBuilder(llvm::Module * m, unsigned GeneralRegisterWidthInBits, unsigned CacheLineAlignmentInBytes)
    367403: IRBuilder<>(m->getContext())
Note: See TracChangeset for help on using the changeset viewer.