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

Changes towards separate compilation

Location:
icGREP/icgrep-devel/icgrep/IR_Gen
Files:
1 added
11 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}
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5424 r5425  
    66#define CBUILDER_H
    77
    8 #include <string>
     8#include <IR_Gen/FunctionTypeBuilder.h>
    99#include <llvm/IR/IRBuilder.h>
    1010#include <llvm/IR/Constants.h>
     11#include <llvm/ADT/Triple.h>
     12
     13namespace kernels { class KernelBuilder; }
    1114namespace llvm { class Function; }
    1215namespace llvm { class IntegerType; }
     
    1619namespace llvm { class Value; }
    1720
     21class ParabixDriver;
     22
    1823class CBuilder : public llvm::IRBuilder<> {
    19    
     24    friend class ParabixDriver;
    2025public:
    2126
    22     CBuilder(llvm::Module * m, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes = 64);
     27    CBuilder(llvm::Module * const module, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes = 64);
    2328   
    2429    virtual ~CBuilder() {}
     
    2833    }
    2934   
    30     void setModule(llvm::Module * m)  {
     35    void setModule(llvm::Module * m) {
     36        assert (m);
    3137        mMod = m;
    3238    }
     39
    3340
    3441    llvm::Value * CreateMalloc(llvm::Value * size);
     
    138145
    139146    inline llvm::IntegerType * getSizeTy() const {
     147        assert (mSizeType);
    140148        return mSizeType;
    141149    }
     
    180188    llvm::Value * CreateReadCycleCounter();
    181189
     190    template <typename ExternalFunctionType>
     191    llvm::Function * LinkFunction(llvm::StringRef name, ExternalFunctionType * functionPtr) const;
     192
    182193protected:
    183     llvm::Module *                  mMod;
     194
     195    llvm::Function * LinkFunction(llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
     196
     197    void setDriver(ParabixDriver * driver) {
     198        mDriver = driver;
     199    }
     200
     201protected:
     202    llvm::Module *                  mMod;   
    184203    unsigned                        mCacheLineAlignment;
    185204    llvm::IntegerType *             mSizeType;
    186205    llvm::StructType *              mFILEtype;
    187206    const bool                      mSupportsIndirectBr;
     207    ParabixDriver *                 mDriver;
     208    llvm::LLVMContext               mContext;
     209    const std::string               mTriple;
    188210};
    189211
     212template <typename ExternalFunctionType>
     213llvm::Function *CBuilder::LinkFunction(llvm::StringRef name, ExternalFunctionType * functionPtr) const {
     214    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(getContext());
     215    assert ("FunctionTypeBuilder did not resolve a function type." && type);
     216    return LinkFunction(name, type, reinterpret_cast<void *>(functionPtr));
     217}
     218
    190219#endif
  • icGREP/icgrep-devel/icgrep/IR_Gen/CudaDriver.h

    r5402 r5425  
    66#include <unistd.h>
    77#include <cassert>
    8 #include <kernels/toolchain.h>
     8#include <toolchain/toolchain.h>
    99#include "cuda.h"
    1010
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_avx_builder.h

    r5374 r5425  
    1616public:
    1717   
    18     IDISA_AVX_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    19     : IDISA_SSE2_Builder(m, archBitWidth, bitBlockWidth) {
     18    IDISA_AVX_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     19    : IDISA_SSE2_Builder(module, archBitWidth, bitBlockWidth) {
    2020    }
     21
    2122    virtual std::string getBuilderUniqueName() override;
    2223    Value * hsimd_signmask(unsigned fw, Value * a) override;
     
    2829public:
    2930   
    30     IDISA_AVX2_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    31     : IDISA_AVX_Builder(m, archBitWidth, bitBlockWidth) {
     31    IDISA_AVX2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     32    : IDISA_AVX_Builder(module, archBitWidth, bitBlockWidth) {
    3233    }
     34
    3335    virtual std::string getBuilderUniqueName() override;
    3436    Value * hsimd_packh(unsigned fw, Value * a, Value * b) override;
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r5402 r5425  
    1313#include <llvm/Support/raw_ostream.h>
    1414#include <llvm/IR/TypeBuilder.h>
    15 #include <kernels/toolchain.h>
     15#include <toolchain/toolchain.h>
    1616
    1717using namespace llvm;
     
    376376}
    377377
    378 IDISA_Builder::IDISA_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr, unsigned CacheAlignment)
    379 : CBuilder(m, archBitWidth, SupportsIndirectBr, CacheAlignment)
     378IDISA_Builder::IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr, unsigned CacheAlignment)
     379: CBuilder(module, archBitWidth, SupportsIndirectBr, CacheAlignment)
    380380, mBitBlockWidth(bitBlockWidth)
    381381, mStride(stride)
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5398 r5425  
    2020public:
    2121
    22     IDISA_Builder(llvm::Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr=true, unsigned CacheAlignment=64);
     22    IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr=true, unsigned CacheAlignment=64);
    2323
    2424    virtual ~IDISA_Builder();
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_i64_builder.h

    r5374 r5425  
    1616public:
    1717 
    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) {
     18    IDISA_I64_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth = 64, unsigned stride = 64, const bool SupportsIndirectBr = true)
     19    : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride, SupportsIndirectBr) {
     20
    2021    }
     22
    2123    virtual std::string getBuilderUniqueName() override;
    2224
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_nvptx_builder.h

    r5374 r5425  
    1616public:
    1717   
    18     IDISA_NVPTX20_Builder(Module * m, unsigned groupSize)
    19     : IDISA_I64_Builder(m, 64, 64, 64 * groupSize, false)
     18    IDISA_NVPTX20_Builder(llvm::Module * const module, unsigned groupSize)
     19    : IDISA_I64_Builder(module, 64, 64, 64 * groupSize, false)
    2020    , groupThreads(groupSize) {
    2121        CreateGlobals();
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_sse_builder.h

    r5374 r5425  
    1717public:
    1818 
    19     IDISA_SSE_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    20     : IDISA_Builder(m, archBitWidth, bitBlockWidth, bitBlockWidth) {
     19    IDISA_SSE_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     20    : IDISA_Builder(module, archBitWidth, bitBlockWidth, bitBlockWidth) {
    2121    }
     22
    2223    virtual std::string getBuilderUniqueName() override;
    2324    Value * hsimd_signmask(unsigned fw, Value * a) override;
     
    2930public:
    3031 
    31     IDISA_SSE2_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    32     : IDISA_SSE_Builder(m, archBitWidth, bitBlockWidth) {
     32    IDISA_SSE2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     33    : IDISA_SSE_Builder(module, archBitWidth, bitBlockWidth) {
    3334    }
     35
    3436    virtual std::string getBuilderUniqueName() override;
    3537    Value * hsimd_signmask(unsigned fw, Value * a) override;
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.cpp

    r5402 r5425  
    55
    66#include "idisa_target.h"
    7 #include <kernels/toolchain.h>
     7#include <toolchain/toolchain.h>
    88#include <IR_Gen/idisa_avx_builder.h>
    99#include <IR_Gen/idisa_sse_builder.h>
     
    1515namespace IDISA {
    1616   
    17 IDISA_Builder * GetIDISA_Builder(llvm::Module * const mod) {
    18     if (LLVM_UNLIKELY(mod == nullptr)) {
    19         report_fatal_error("GetIDISA_Builder: module cannot be null");
    20     }
    21     if (LLVM_LIKELY(mod->getTargetTriple().empty())) {
    22         mod->setTargetTriple(llvm::sys::getProcessTriple());
    23     }
     17IDISA_Builder * GetIDISA_Builder(llvm::Module * const module) {
    2418    unsigned registerWidth = 0;
    25     Triple T(mod->getTargetTriple());
     19    Triple T(module->getTargetTriple());
    2620    if (T.isArch64Bit()) {
    2721        registerWidth = 64;
     
    3731    if (codegen::BlockSize >= 256) {
    3832        if (hasAVX2) {
    39             return new IDISA_AVX2_Builder(mod, registerWidth, codegen::BlockSize);
     33            return new IDISA_AVX2_Builder(module, registerWidth, codegen::BlockSize);
    4034        }
    4135    } else if (codegen::BlockSize == 64) {
    42         return new IDISA_I64_Builder(mod, registerWidth);
     36        return new IDISA_I64_Builder(module, registerWidth);
    4337    }
    44     return new IDISA_SSE2_Builder(mod, registerWidth, codegen::BlockSize);
     38    return new IDISA_SSE2_Builder(module, registerWidth, codegen::BlockSize);
    4539}
    4640
    47 IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const mod) {
    48     return new IDISA_NVPTX20_Builder(mod, 64);
     41IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const module) {
     42    return new IDISA_NVPTX20_Builder(module, 64);
    4943}
    5044
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.h

    r5361 r5425  
    77#define IDISA_TARGET_H
    88
     9#include <string>
    910namespace llvm { class Module; }
    1011namespace IDISA { class IDISA_Builder; }
     
    1213namespace IDISA {
    1314   
    14 IDISA::IDISA_Builder * GetIDISA_Builder(llvm::Module * const m);
     15IDISA::IDISA_Builder * GetIDISA_Builder(llvm::Module * const module);
    1516
    16 IDISA::IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const m);
     17IDISA::IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const module);
    1718
    1819}
Note: See TracChangeset for help on using the changeset viewer.