Ignore:
Timestamp:
Apr 25, 2017, 2:33:31 PM (2 years ago)
Author:
nmedfort
Message:

Changes towards separate compilation

File:
1 edited

Legend:

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

    r5424 r5425  
    1212#include <llvm/IR/MDBuilder.h>
    1313#include <llvm/Support/raw_ostream.h>
    14 #include <kernels/toolchain.h>
    15 #include <llvm/ADT/Triple.h>
    16 #include <fcntl.h>
    17 #include <unistd.h>
     14#include <toolchain/toolchain.h>
    1815#include <sys/mman.h>
    19 #include <sys/stat.h>
    20 #include <errno.h>
    2116
    2217using namespace llvm;
     
    4136        PointerType * int8PtrTy = getInt8PtrTy();
    4237        write = cast<Function>(mMod->getOrInsertFunction("write",
    43                                                         AttributeSet().addAttribute(mMod->getContext(), 2U, Attribute::NoAlias),
     38                                                        AttributeSet().addAttribute(getContext(), 2U, Attribute::NoAlias),
    4439                                                        sizeTy, int32Ty, int8PtrTy, sizeTy, nullptr));
    4540    }
     
    4742}
    4843
    49 Value * CBuilder::CreateReadCall(Value * fildes, Value * buf, Value * nbyte) {
     44Value * CBuilder::CreateReadCall(Value * fileDescriptor, Value * buf, Value * nbyte) {
    5045    Function * readFn = mMod->getFunction("read");
    5146    if (readFn == nullptr) {
     
    5449        PointerType * int8PtrTy = getInt8PtrTy();
    5550        readFn = cast<Function>(mMod->getOrInsertFunction("read",
    56                                                          AttributeSet().addAttribute(mMod->getContext(), 2U, Attribute::NoAlias),
     51                                                         AttributeSet().addAttribute(getContext(), 2U, Attribute::NoAlias),
    5752                                                         sizeTy, int32Ty, int8PtrTy, sizeTy, nullptr));
    5853    }
    59     return CreateCall(readFn, {fildes, buf, nbyte});
     54    return CreateCall(readFn, {fileDescriptor, buf, nbyte});
    6055}
    6156
     
    6762        closeFn = Function::Create(fty, Function::ExternalLinkage, "close", mMod);
    6863    }
    69     return CreateCall(closeFn, {fileDescriptor});
     64    return CreateCall(closeFn, fileDescriptor);
    7065}
    7166
     
    7873        unlinkFunc->setCallingConv(CallingConv::C);
    7974    }
    80     return CreateCall(unlinkFunc, {path});
    81 }
    82 
    83 Value * CBuilder::CreateFileSize(Value * fileDescriptor) {
    84     Function * fileSizeFunc = mMod->getFunction("file_size");
    85     if (fileSizeFunc == nullptr) {
    86         FunctionType * fty = FunctionType::get(getSizeTy(), {getInt32Ty()}, true);
    87         fileSizeFunc = Function::Create(fty, Function::ExternalLinkage, "file_size", mMod);
    88     }
    89     return CreateCall(fileSizeFunc, {fileDescriptor});
     75    return CreateCall(unlinkFunc, path);
    9076}
    9177
     
    9581        mkstempFn = cast<Function>(mMod->getOrInsertFunction("mkstemp", getInt32Ty(), getInt8PtrTy(), nullptr));
    9682    }
    97     return CreateCall(mkstempFn, {ftemplate});
     83    return CreateCall(mkstempFn, ftemplate);
    9884}
    9985
     
    10490        strlenFn = cast<Function>(mMod->getOrInsertFunction("strlen", getSizeTy(), getInt8PtrTy(), nullptr));
    10591    }
    106     return CreateCall(strlenFn, {str});
     92    return CreateCall(strlenFn, str);
    10793}
    10894
     
    135121        auto arg = function->arg_begin();
    136122        std::string out = "%-40s = %" PRIx64 "\n";
    137         BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     123        BasicBlock * entry = BasicBlock::Create(getContext(), "entry", function);
    138124        IRBuilder<> builder(entry);
    139125        std::vector<Value *> args;
     
    167153        auto arg = function->arg_begin();
    168154        std::string out = "%-40s = %" PRIx64 "\n";
    169         BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     155        BasicBlock * entry = BasicBlock::Create(getContext(), "entry", function);
    170156        IRBuilder<> builder(entry);
    171157        std::vector<Value *> args;
     
    200186        auto arg = function->arg_begin();
    201187        std::string out = "%s\n";
    202         BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     188        BasicBlock * entry = BasicBlock::Create(getContext(), "entry", function);
    203189        IRBuilder<> builder(entry);
    204190        std::vector<Value *> args;
     
    260246        aligned_malloc->addFnAttr(Attribute::AlwaysInline);
    261247        Value * size = &*aligned_malloc->arg_begin();
    262         SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", aligned_malloc));
     248        SetInsertPoint(BasicBlock::Create(getContext(), "entry", aligned_malloc));
    263249        const auto byteWidth = (intTy->getBitWidth() / 8);
    264250        Constant * const offset = ConstantInt::get(intTy, alignment + byteWidth - 1);
     
    341327 */
    342328Value * CBuilder::CreateMAdvise(Value * addr, Value * length, Advice advice) {
    343     Triple T(mMod->getTargetTriple());
     329    Triple T(mTriple);
    344330    Value * result = nullptr;
    345331    if (T.isOSLinux() || T.isOSDarwin()) {
     
    383369
    384370Value * CBuilder::CreateMRemap(Value * addr, Value * oldSize, Value * newSize) {
    385     Triple T(mMod->getTargetTriple());
     371    Triple T(mTriple);
    386372    Value * ptr = nullptr;
    387373    if (T.isOSLinux()) {
     
    714700    IntegerType * ty = cast<IntegerType>(value->getType());
    715701    CreateAssert(value, "CreateCeilLog2: value cannot be zero");
    716     Value * m = CreateCountForwardZeroes(CreateSub(value, ConstantInt::get(ty, 1)));
     702    Value * m = CreateCountReverseZeroes(CreateSub(value, ConstantInt::get(ty, 1)));
    717703    return CreateSub(ConstantInt::get(m->getType(), ty->getBitWidth() - 1), m);
    718704}
     
    732718}
    733719
    734 
    735 CBuilder::CBuilder(Module * const m, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes)
    736 : IRBuilder<>(m->getContext())
    737 , mMod(m)
     720Function * CBuilder::LinkFunction(llvm::StringRef name, FunctionType * type, void * functionPtr) const {
     721    assert (mDriver);
     722    return mDriver->LinkFunction(mMod, name, type, functionPtr);
     723}
     724
     725CBuilder::CBuilder(Module * const module, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes)
     726: IRBuilder<>(module->getContext())
     727, mMod(module)
    738728, mCacheLineAlignment(CacheLineAlignmentInBytes)
    739729, mSizeType(getIntNTy(GeneralRegisterWidthInBits))
    740730, mFILEtype(nullptr)
    741 , mSupportsIndirectBr(SupportsIndirectBr) {
    742 }
     731, mSupportsIndirectBr(SupportsIndirectBr)
     732, mDriver(nullptr) {
     733
     734}
Note: See TracChangeset for help on using the changeset viewer.