Ignore:
Timestamp:
Jul 13, 2015, 3:55:59 PM (4 years ago)
Author:
nmedfort
Message:

Made pablo compiler reenterant through alternate compile method that takes a Module parameter.

Location:
icGREP/icgrep-devel/icgrep/IDISA
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.cpp

    r4662 r4665  
    1010#include <llvm/IR/Intrinsics.h>
    1111#include <llvm/IR/Function.h>
    12 #include <iostream>
    1312
    14 using namespace IDISA;
     13namespace IDISA {
    1514
    1615Value * IDISA_Builder::bitBlockCast(Value * a) {
    17     return llvm_builder->CreateBitCast(a, mBitBlockType);
     16    return mLLVMBuilder->CreateBitCast(a, mBitBlockType);
    1817}
    1918
    2019VectorType * IDISA_Builder::fwVectorType(unsigned fw) {
    2120    int fieldCount = mBitBlockSize/fw;
    22     return VectorType::get(llvm_builder->getIntNTy(fw), fieldCount);
     21    return VectorType::get(mLLVMBuilder->getIntNTy(fw), fieldCount);
    2322}
    2423
    2524Value * IDISA_Builder::fwCast(unsigned fw, Value * a) {
    26     return llvm_builder->CreateBitCast(a, fwVectorType(fw));
     25    return mLLVMBuilder->CreateBitCast(a, fwVectorType(fw));
    2726}
    2827
    2928Value * IDISA_Builder::simd_add(unsigned fw, Value * a, Value * b) {
    30     return bitBlockCast(llvm_builder->CreateAdd(fwCast(fw, a), fwCast(fw, b)));
     29    return bitBlockCast(mLLVMBuilder->CreateAdd(fwCast(fw, a), fwCast(fw, b)));
    3130}
    3231
    3332Value * IDISA_Builder::simd_sub(unsigned fw, Value * a, Value * b) {
    34     return bitBlockCast(llvm_builder->CreateSub(fwCast(fw, a), fwCast(fw, b)));
     33    return bitBlockCast(mLLVMBuilder->CreateSub(fwCast(fw, a), fwCast(fw, b)));
    3534}
    3635
    3736Value * IDISA_Builder::simd_mult(unsigned fw, Value * a, Value * b) {
    38     return bitBlockCast(llvm_builder->CreateMul(fwCast(fw, a), fwCast(fw, b)));
     37    return bitBlockCast(mLLVMBuilder->CreateMul(fwCast(fw, a), fwCast(fw, b)));
    3938}
    4039
    4140Value * IDISA_Builder::simd_eq(unsigned fw, Value * a, Value * b) {
    42     return bitBlockCast(llvm_builder->CreateSExt(llvm_builder->CreateICmpEQ(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
     41    return bitBlockCast(mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpEQ(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
    4342}
    4443
    4544Value * IDISA_Builder::simd_gt(unsigned fw, Value * a, Value * b) {
    46     return bitBlockCast(llvm_builder->CreateSExt(llvm_builder->CreateICmpSGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
     45    return bitBlockCast(mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpSGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
    4746}
    4847
    4948Value * IDISA_Builder::simd_ugt(unsigned fw, Value * a, Value * b) {
    50     return bitBlockCast(llvm_builder->CreateSExt(llvm_builder->CreateICmpUGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
     49    return bitBlockCast(mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpUGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
    5150}
    5251
    5352Value * IDISA_Builder::simd_lt(unsigned fw, Value * a, Value * b) {
    54     return bitBlockCast(llvm_builder->CreateSExt(llvm_builder->CreateICmpSLT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
     53    return bitBlockCast(mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpSLT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
    5554}
    5655
    5756Value * IDISA_Builder::simd_ult(unsigned fw, Value * a, Value * b) {
    58     return bitBlockCast(llvm_builder->CreateSExt(llvm_builder->CreateICmpULT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
     57    return bitBlockCast(mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpULT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw)));
    5958}
    6059
     
    6261    Value * aVec = fwCast(fw, a);
    6362    Value * bVec = fwCast(fw, b);
    64     return bitBlockCast(llvm_builder->CreateSelect(llvm_builder->CreateICmpSGT(aVec, bVec), aVec, bVec));
     63    return bitBlockCast(mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpSGT(aVec, bVec), aVec, bVec));
    6564}
    6665
     
    6867    Value * aVec = fwCast(fw, a);
    6968    Value * bVec = fwCast(fw, b);
    70     return bitBlockCast(llvm_builder->CreateSelect(llvm_builder->CreateICmpUGT(aVec, bVec), aVec, bVec));
     69    return bitBlockCast(mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpUGT(aVec, bVec), aVec, bVec));
    7170}
    7271
     
    7473    Value * aVec = fwCast(fw, a);
    7574    Value * bVec = fwCast(fw, b);
    76     return bitBlockCast(llvm_builder->CreateSelect(llvm_builder->CreateICmpSLT(aVec, bVec), aVec, bVec));
     75    return bitBlockCast(mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpSLT(aVec, bVec), aVec, bVec));
    7776}
    7877
     
    8079    Value * aVec = fwCast(fw, a);
    8180    Value * bVec = fwCast(fw, b);
    82     return bitBlockCast(llvm_builder->CreateSelect(llvm_builder->CreateICmpULT(aVec, bVec), aVec, bVec));
     81    return bitBlockCast(mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpULT(aVec, bVec), aVec, bVec));
    8382}
    8483
    8584Value * IDISA_Builder::simd_slli(unsigned fw, Value * a, unsigned shift) {
    86     return bitBlockCast(llvm_builder->CreateShl(fwCast(fw, a), shift));
     85    return bitBlockCast(mLLVMBuilder->CreateShl(fwCast(fw, a), shift));
    8786}
    8887
    8988Value * IDISA_Builder::simd_srli(unsigned fw, Value * a, unsigned shift) {
    90     return bitBlockCast(llvm_builder->CreateLShr(fwCast(fw, a), shift));
     89    return bitBlockCast(mLLVMBuilder->CreateLShr(fwCast(fw, a), shift));
    9190}
    9291
    9392Value * IDISA_Builder::simd_srai(unsigned fw, Value * a, unsigned shift) {
    94     return bitBlockCast(llvm_builder->CreateAShr(fwCast(fw, a), shift));
     93    return bitBlockCast(mLLVMBuilder->CreateAShr(fwCast(fw, a), shift));
    9594}
    9695
    9796Value * IDISA_Builder::simd_cttz(unsigned fw, Value * a) {
    9897    Value * cttzFunc = Intrinsic::getDeclaration(mMod, Intrinsic::cttz, fwVectorType(fw));
    99     Value * rslt = llvm_builder->CreateCall(cttzFunc, {fwCast(fw, a), ConstantInt::get(llvm_builder->getInt1Ty(), 0)});
     98    Value * rslt = mLLVMBuilder->CreateCall(cttzFunc, {fwCast(fw, a), ConstantInt::get(mLLVMBuilder->getInt1Ty(), 0)});
    10099    return bitBlockCast(rslt);
    101100}
     
    107106    std::vector<Constant*> Idxs;
    108107    for (unsigned i = field_count/2; i < field_count; i++) {
    109         Idxs.push_back(llvm_builder->getInt32(i));    // selects elements from first reg.
    110         Idxs.push_back(llvm_builder->getInt32(i + field_count)); // selects elements from second reg.
     108        Idxs.push_back(mLLVMBuilder->getInt32(i));    // selects elements from first reg.
     109        Idxs.push_back(mLLVMBuilder->getInt32(i + field_count)); // selects elements from second reg.
    111110    }
    112     return bitBlockCast(llvm_builder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
     111    return bitBlockCast(mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
    113112}
    114113
     
    119118    std::vector<Constant*> Idxs;
    120119    for (unsigned i = 0; i < field_count/2; i++) {
    121         Idxs.push_back(llvm_builder->getInt32(i));    // selects elements from first reg.
    122         Idxs.push_back(llvm_builder->getInt32(i + field_count)); // selects elements from second reg.
     120        Idxs.push_back(mLLVMBuilder->getInt32(i));    // selects elements from first reg.
     121        Idxs.push_back(mLLVMBuilder->getInt32(i + field_count)); // selects elements from second reg.
    123122    }
    124     return bitBlockCast(llvm_builder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
     123    return bitBlockCast(mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
    125124}
    126125
     
    131130    std::vector<Constant*> Idxs;
    132131    for (unsigned i = 0; i < field_count; i++) {
    133         Idxs.push_back(llvm_builder->getInt32(2*i));
     132        Idxs.push_back(mLLVMBuilder->getInt32(2*i));
    134133    }
    135     return bitBlockCast(llvm_builder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
     134    return bitBlockCast(mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
    136135}
    137136
     
    142141    std::vector<Constant*> Idxs;
    143142    for (unsigned i = 0; i < field_count; i++) {
    144         Idxs.push_back(llvm_builder->getInt32(2*i+1));
     143        Idxs.push_back(mLLVMBuilder->getInt32(2*i+1));
    145144    }
    146     return bitBlockCast(llvm_builder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
     145    return bitBlockCast(mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
    147146}
    148147
    149148Value * IDISA_Builder::hsimd_signmask(unsigned fw, Value * a) {
    150     Value * mask = llvm_builder->CreateICmpSLT(fwCast(fw, a), ConstantAggregateZero::get(fwVectorType(fw)));
    151     return llvm_builder->CreateBitCast(mask, llvm_builder->getIntNTy(mBitBlockSize/fw));
     149    Value * mask = mLLVMBuilder->CreateICmpSLT(fwCast(fw, a), ConstantAggregateZero::get(fwVectorType(fw)));
     150    return mLLVMBuilder->CreateBitCast(mask, mLLVMBuilder->getIntNTy(mBitBlockSize/fw));
    152151}
    153152
     
    158157    std::vector<Constant*> Idxs;
    159158    for (unsigned i = shift; i < field_count + shift; i++) {
    160         Idxs.push_back(llvm_builder->getInt32(i));
     159        Idxs.push_back(mLLVMBuilder->getInt32(i));
    161160    }
    162     return bitBlockCast(llvm_builder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
     161    return bitBlockCast(mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs)));
    163162}
    164163
    165164Value * IDISA_Builder::bitblock_any(Value * a) {
    166     Type * iBitBlock = llvm_builder->getIntNTy(mBitBlockSize);
    167     return llvm_builder->CreateICmpNE(llvm_builder->CreateBitCast(a, iBitBlock),  ConstantInt::get(iBitBlock, 0));
     165    Type * iBitBlock = mLLVMBuilder->getIntNTy(mBitBlockSize);
     166    return mLLVMBuilder->CreateICmpNE(mLLVMBuilder->CreateBitCast(a, iBitBlock),  ConstantInt::get(iBitBlock, 0));
    168167}
     168
     169}
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.h

    r4662 r4665  
    1818class IDISA_Builder {
    1919public:
    20     IDISA_Builder(Module * m, IRBuilder <> * b, Type * bitBlockType): mMod(m), llvm_builder(b), mBitBlockType(bitBlockType) {
    21         if (bitBlockType->isIntegerTy()) mBitBlockSize = dyn_cast<IntegerType>(bitBlockType)-> getIntegerBitWidth();
    22         else mBitBlockSize = dyn_cast<VectorType>(bitBlockType)-> getBitWidth();
     20
     21    IDISA_Builder(Type * bitBlockType)
     22    : mMod(nullptr)
     23    , mLLVMBuilder(nullptr)
     24    , mBitBlockType(bitBlockType)
     25    , mBitBlockSize(bitBlockType->isIntegerTy() ? cast<IntegerType>(bitBlockType)->getIntegerBitWidth() : cast<VectorType>(bitBlockType)->getBitWidth()) {
     26
     27    }
     28
     29    void initialize(Module * m, IRBuilder <> * b) {
     30        mMod = m;
     31        mLLVMBuilder = b;
    2332    }
    2433       
     
    5665private:
    5766    Module * mMod;
    58     IRBuilder <> * llvm_builder;
     67    IRBuilder <> * mLLVMBuilder;
    5968    Type * mBitBlockType;
    6069    unsigned mBitBlockSize;
Note: See TracChangeset for help on using the changeset viewer.