Changeset 4659


Ignore:
Timestamp:
Jul 11, 2015, 5:16:37 PM (4 years ago)
Author:
nmedfort
Message:

Minor changes to function compilation preceeding any modification of the pablo Call class.

Location:
icGREP/icgrep-devel/icgrep
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4657 r4659  
    135135    }
    136136
    137     PabloFunction function = PabloFunction::Create();
     137    PabloFunction function = PabloFunction::Create("process_block");
    138138
    139139    CC_Compiler cc_compiler(function, encoding);
  • icGREP/icgrep-devel/icgrep/do_grep.cpp

    r4538 r4659  
    131131void GrepExecutor::doGrep(const std::string infilename) {
    132132
    133     struct Basis_bits basis_bits;
    134     struct Output output;
     133    Basis_bits basis_bits;
    135134    BitBlock match_vector;
    136135    BitBlock process_block_state_data[(mProcessBlockStateSize + sizeof(BitBlock) - 1)/sizeof(BitBlock)];   
     
    196195            block_base = blk*BLOCK_SIZE + segment_base;
    197196            s2p_do_block((BytePack *) &mFileBuffer[block_base], basis_bits);
     197            Output output;
    198198            mProcessBlockFcn(basis_bits, process_block_state_data, output);
    199199
     200            mMatch_scanner.load_block(output.matches, blk);
    200201            mLineBreak_scanner.load_block(output.LF, blk);
    201             mMatch_scanner.load_block(output.matches, blk);
     202
    202203            if (mCountOnlyOption){
    203204                if (bitblock::any(output.matches))
     
    241242        block_base = block_pos + segment_base;
    242243        s2p_do_block((BytePack *) &mFileBuffer[block_base], basis_bits);
     244        Output output;
    243245        mProcessBlockFcn(basis_bits, process_block_state_data, output);
    244246
     
    284286    }
    285287   
     288    Output output;
    286289    mProcessBlockFcn(basis_bits, process_block_state_data, output);
    287290
  • icGREP/icgrep-devel/icgrep/do_grep.h

    r4538 r4659  
    22#define DO_GREP_H
    33/*
    4  *  Copyright (c) 2014 International Characters.
     4 *  Copyright (c) 2015 International Characters.
    55 *  This software is licensed to the public under the Open Software License 3.0.
    66 *  icgrep is a trademark of International Characters.
     
    1212#include <string>
    1313#include <stdint.h>
     14#include <array>
    1415
    1516#include "include/simd-lib/bitblock.hpp"
     
    4243
    4344
    44 typedef void (*process_block_fcn)(const Basis_bits &basis_bits, BitBlock process_block_state_data[], Output &output);
    45 
    46 
     45typedef void (*process_block_fcn)(const Basis_bits & basis_bits, BitBlock process_block_state_data[], Output & output);
    4746
    4847class GrepExecutor {
    4948public:
    50     GrepExecutor(size_t process_block_state_size, process_block_fcn process_block):
    51     mCountOnlyOption(false), mShowFileNameOption(false), mShowLineNumberingOption(false),
    52     mProcessBlockStateSize(process_block_state_size),
    53     mProcessBlockFcn(process_block)
    54     {}
     49
     50    GrepExecutor(size_t process_block_state_size, void * process_block)
     51    : mCountOnlyOption(false)
     52    , mShowFileNameOption(false)
     53    , mShowLineNumberingOption(false)
     54    , mProcessBlockStateSize(process_block_state_size)
     55    , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
     56
     57    }
    5558         
    5659    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4626 r4659  
    107107   
    108108    const auto llvm_codegen = icgrep::compile(encoding, regexVector, globalFlags);
    109 
    110109    if (llvm_codegen.FunctionPointer) {
    111         void (*FP)(const Basis_bits &basis_bits, BitBlock process_block_state_data[], Output &output) =
    112            (void (*)(const Basis_bits &basis_bits, BitBlock process_block_state_data[], Output &output))(void*)llvm_codegen.FunctionPointer;
    113         GrepExecutor grepEngine = GrepExecutor(llvm_codegen.CarryDataSize, FP);
     110        GrepExecutor grepEngine = GrepExecutor(llvm_codegen.CarryDataSize, llvm_codegen.FunctionPointer);
    114111        grepEngine.setCountOnlyOption(CountOnly);
    115112        grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4655 r4659  
    2121    mPabloRoot = pb;
    2222    mCarryDataPtr = carryPtr;
    23     iBuilder = new IDISA::IDISA_Builder(mMod, mBuilder, mBitBlockType);
    2423   
    2524    PabloBlockCarryData & cd = pb->carryData;
     
    9190   
    9291#if (BLOCK_SIZE == 128) && !defined(USE_LONG_INTEGER_SHIFT)
    93     Value * ahead64 = iBuilder->mvmd_dslli(64, carry_in, strm, 1);
    94     result_value = mBuilder->CreateOr(iBuilder->simd_srli(64, ahead64, 63), iBuilder->simd_slli(64, strm, 1));
     92    Value * ahead64 = iBuilder.mvmd_dslli(64, carry_in, strm, 1);
     93    result_value = mBuilder->CreateOr(iBuilder.simd_srli(64, ahead64, 63), iBuilder.simd_slli(64, strm, 1));
    9594#else
    9695    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4654 r4659  
    3131public:
    3232 
    33     CarryManager(Module * m, IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one) :
    34         mMod(m), mBuilder(b), mBitBlockType(bitBlockType), mZeroInitializer(zero), mOneInitializer(one) {}
     33    CarryManager(Module * m, IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one)
     34    : mMod(m)
     35    , mBuilder(b)
     36    , mBitBlockType(bitBlockType)
     37    , mZeroInitializer(zero)
     38    , mOneInitializer(one)
     39    , iBuilder(mMod, mBuilder, mBitBlockType) {
     40
     41    }
    3542   
    3643    unsigned initialize(PabloBlock * blk, Value * carryDataPtr); 
     
    8390    ConstantAggregateZero * mZeroInitializer;
    8491    Constant * mOneInitializer;
    85     IDISA::IDISA_Builder * iBuilder;
     92    IDISA::IDISA_Builder iBuilder;
    8693    PabloBlock * mPabloRoot;
    8794    Value * mCarryDataPtr;
  • icGREP/icgrep-devel/icgrep/pablo/function.cpp

    r4657 r4659  
    44namespace pablo {
    55
    6 PabloFunction::PabloFunction()
     6PabloFunction::PabloFunction(std::string && name)
    77: PabloAST(ClassTypeId::Function)
    88, mEntryBlock(PabloBlock::Create(mSymbolTable))
    99, mParameters(reinterpret_cast<ParamAllocator &>(mVectorAllocator))
    10 , mResults(reinterpret_cast<ResultAllocator &>(mVectorAllocator)) {
     10, mResults(reinterpret_cast<ResultAllocator &>(mVectorAllocator))
     11, mName(mSymbolTable.get(name, false)) {
    1112
    1213}
  • icGREP/icgrep-devel/icgrep/pablo/function.h

    r4657 r4659  
    1212class Assign;
    1313class PabloBlock;
     14class String;
    1415
    1516class PabloFunction : public PabloAST {
     
    2930    }
    3031
    31     static PabloFunction Create();
     32    static PabloFunction Create(std::string && name);
    3233
    3334    virtual bool operator==(const PabloAST & other) const {
     
    3738    PabloBlock & getEntryBlock() {
    3839        return mEntryBlock;
     40    }
     41
     42    const String * getName() const {
     43        return mName;
    3944    }
    4045
     
    8691
    8792protected:
    88     PabloFunction();
     93    PabloFunction(std::string && name);
    8994private:
    9095    PabloBlock &        mEntryBlock;
     
    9297    Results             mResults;
    9398    SymbolGenerator     mSymbolTable;
     99    String *            mName;
    94100};
    95101
    96 inline PabloFunction PabloFunction::Create() {
    97     return PabloFunction();
     102inline PabloFunction PabloFunction::Create(std::string && name) {
     103    return PabloFunction(std::move(name));
    98104}
    99105
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.cpp

    r4657 r4659  
    155155    LOG("Shutdown:                " << (end_shutdown - start_shutdown));
    156156
    157     LOG_NUMBER_OF_ADVANCES(entry);
     157    LOG_NUMBER_OF_ADVANCES(function.getEntryBlock());
    158158
    159159    return multiplex;
     
    189189            }
    190190
    191             assert ("Run the Simplifer pass prior to this!" && (stmt->getNumUses() != 0 || (isa<Assign>(stmt) ? !cast<Assign>(stmt)->superfluous() : false)));
     191            assert ("Run the Simplifer pass prior to this!" && (stmt->getNumUses() > 0));
    192192
    193193            switch (stmt->getClassTypeId()) {
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4657 r4659  
    7676, mExecutionEngine(nullptr)
    7777, mBitBlockType(VectorType::get(IntegerType::get(mMod->getContext(), 64), BLOCK_SIZE / 64))
    78 , mBasisBitsInputPtr(nullptr)
     78, mInputPtr(nullptr)
    7979, mCarryDataPtr(nullptr)
    8080, mWhileDepth(0)
     
    8282, mZeroInitializer(ConstantAggregateZero::get(mBitBlockType))
    8383, mOneInitializer(ConstantVector::getAllOnesValue(mBitBlockType))
    84 , mFunctionType(nullptr)
    8584, mFunction(nullptr)
    86 , mParameterAddr(nullptr)
    87 , mOutputAddrPtr(nullptr)
     85, mInputAddressPtr(nullptr)
     86, mOutputAddressPtr(nullptr)
    8887, mMaxWhileDepth(0)
    8988, mPrintRegisterFunction(nullptr)
     
    139138    }
    140139
    141     DefineTypes(function);
     140    GenerateFunction(function);
    142141    DeclareFunctions();
    143142
    144143    Examine(function.getEntryBlock());
    145144    DeclareCallFunctions();
    146 
    147     Function::arg_iterator args = mFunction->arg_begin();
    148     mParameterAddr = args++;
    149     mParameterAddr->setName("basis_bits");
    150     mCarryDataPtr = args++;
    151     mCarryDataPtr->setName("carry_data");
    152     mOutputAddrPtr = args++;
    153     mOutputAddrPtr->setName("output");
    154145
    155146    mWhileDepth = 0;
    156147    mIfDepth = 0;
    157148    mMaxWhileDepth = 0;
    158     BasicBlock * b = BasicBlock::Create(mMod->getContext(), "parabix_entry", mFunction,0);
     149    BasicBlock * b = BasicBlock::Create(mMod->getContext(), "entry", mFunction,0);
    159150    mBuilder->SetInsertPoint(b);
    160151
    161152    //The basis bits structure
    162 
    163153    for (unsigned i = 0; i != function.getParameters().size(); ++i) {
    164154        Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(i)};
    165         Value * gep = mBuilder->CreateGEP(mParameterAddr, indices);
     155        Value * gep = mBuilder->CreateGEP(mInputAddressPtr, indices);
    166156        LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, BLOCK_SIZE/8, false, function.getParameter(i)->getName()->to_string());
    167157        mMarkerMap.insert(std::make_pair(function.getParameter(i), basisBit));
     158        if (DumpTrace) {
     159            genPrintRegister(function.getParameter(i)->getName()->to_string(), basisBit);
     160        }
    168161    }
    169162       
     
    207200}
    208201
    209 void PabloCompiler::DefineTypes(PabloFunction & function) {
    210 
    211     StructType * structBasisBits = mMod->getTypeByName("struct.Basis_bits");
    212     if (structBasisBits == nullptr) {
    213         structBasisBits = StructType::create(mMod->getContext(), "struct.Basis_bits");
    214     }
    215     std::vector<Type*> StructTy_struct_Basis_bits_fields;
    216     for (int i = 0; i != function.getParameters().size(); i++) {
    217         StructTy_struct_Basis_bits_fields.push_back(mBitBlockType);
    218     }
    219     if (structBasisBits->isOpaque()) {
    220         structBasisBits->setBody(StructTy_struct_Basis_bits_fields, /*isPacked=*/false);
    221     }
    222     mBasisBitsInputPtr = PointerType::get(structBasisBits, 0);
    223 
    224     std::vector<Type*>functionTypeArgs;
    225     functionTypeArgs.push_back(mBasisBitsInputPtr);
    226 
    227     //The carry data array.
    228     //A pointer to the BitBlock vector.
    229     functionTypeArgs.push_back(PointerType::get(mBitBlockType, 0));
    230 
    231     //The output structure.
    232     StructType * outputStruct = mMod->getTypeByName("struct.Output");
    233     if (!outputStruct) {
    234         outputStruct = StructType::create(mMod->getContext(), "struct.Output");
    235     }
    236     if (outputStruct->isOpaque()) {
    237         std::vector<Type*>fields;
    238         for (int i = 0; i != function.getResults().size(); i++) {
    239             fields.push_back(mBitBlockType);
    240         }
    241         outputStruct->setBody(fields, /*isPacked=*/false);
    242     }
    243     PointerType * outputStructPtr = PointerType::get(outputStruct, 0);
    244 
    245     //The &output parameter.
    246     functionTypeArgs.push_back(outputStructPtr);
    247 
    248     mFunctionType = FunctionType::get(
    249      /*Result=*/Type::getVoidTy(mMod->getContext()),
    250      /*Params=*/functionTypeArgs,
    251      /*isVarArg=*/false);
    252 }
    253 
    254 void PabloCompiler::DeclareFunctions()
    255 {
    256     //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    257     mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), Type::getInt8PtrTy(getGlobalContext()), mBitBlockType, NULL);
    258     mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
    259     // to call->  mBuilder->CreateCall(mFunc_print_register, unicode_category);
     202inline void PabloCompiler::GenerateFunction(PabloFunction & function) {
     203    std::vector<Type *> inputType(function.getParameters().size(), mBitBlockType);
     204    std::vector<Type *> outputType(function.getResults().size(), mBitBlockType);
     205    mInputPtr = PointerType::get(StructType::get(mMod->getContext(), inputType), 0);
     206    Type * carryPtr = PointerType::get(mBitBlockType, 0);
     207    Type * outputPtr = PointerType::get(StructType::get(mMod->getContext(), outputType), 0);
     208    FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), {{mInputPtr, carryPtr, outputPtr}}, false);
     209
    260210
    261211#ifdef USE_UADD_OVERFLOW
     
    344294    //Starts on process_block
    345295    SmallVector<AttributeSet, 4> Attrs;
    346     AttributeSet PAS;
    347     {
    348         AttrBuilder B;
    349         B.addAttribute(Attribute::ReadOnly);
    350         B.addAttribute(Attribute::NoCapture);
    351         PAS = AttributeSet::get(mMod->getContext(), 1U, B);
    352     }
    353     Attrs.push_back(PAS);
    354     {
    355         AttrBuilder B;
    356         B.addAttribute(Attribute::NoCapture);
    357         PAS = AttributeSet::get(mMod->getContext(), 2U, B);
    358     }
    359     Attrs.push_back(PAS);
    360     {
    361         AttrBuilder B;
    362         B.addAttribute(Attribute::NoCapture);
    363         PAS = AttributeSet::get(mMod->getContext(), 3U, B);
    364     }
    365     Attrs.push_back(PAS);
    366     {
    367         AttrBuilder B;
    368         B.addAttribute(Attribute::NoUnwind);
    369         B.addAttribute(Attribute::UWTable);
    370         PAS = AttributeSet::get(mMod->getContext(), ~0U, B);
    371     }
     296    Attrs.push_back(AttributeSet::get(mMod->getContext(), ~0U, { Attribute::NoUnwind, Attribute::UWTable }));
     297    Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, { Attribute::ReadOnly, Attribute::NoCapture }));
     298    Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::NoCapture }));
     299    Attrs.push_back(AttributeSet::get(mMod->getContext(), 3U, { Attribute::ReadNone, Attribute::NoCapture }));
    372300    AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
    373301
    374     //Create the function that will be generated.
    375     mFunction = mMod->getFunction("process_block");
    376     if (!mFunction) {
    377         mFunction = Function::Create(
    378             /*Type=*/mFunctionType,
    379             /*Linkage=*/GlobalValue::ExternalLinkage,
    380             /*Name=*/"process_block", mMod);
    381         mFunction->setCallingConv(CallingConv::C);
    382     }
     302    // Create the function that will be generated.
     303    mFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, function.getName()->value(), mMod);
     304    mFunction->setCallingConv(CallingConv::C);
    383305    mFunction->setAttributes(AttrSet);
     306
     307    Function::arg_iterator args = mFunction->arg_begin();
     308    mInputAddressPtr = args++;
     309    mInputAddressPtr->setName("input");
     310    mCarryDataPtr = args++;
     311    mCarryDataPtr->setName("carry");
     312    mOutputAddressPtr = args++;
     313    mOutputAddressPtr->setName("output");
     314}
     315
     316inline void PabloCompiler::DeclareFunctions() {
     317    if (DumpTrace || TraceNext) {
     318        //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
     319        mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), Type::getInt8PtrTy(getGlobalContext()), mBitBlockType, NULL);
     320        mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
     321    }
    384322}
    385323   
     
    409347        if (ei != mExternalMap.end()) {
    410348            void * fn_ptr = ei->second;
    411             //std::cerr << "Ptr found:" <<  std::hex << ((intptr_t) fn_ptr) << std::endl;
    412             Value * externalValue = mMod->getOrInsertFunction(callee->value(), mBitBlockType, mBasisBitsInputPtr, NULL);
     349            Value * externalValue = mMod->getOrInsertFunction(callee->value(), mBitBlockType, mInputPtr, NULL);
    413350            if (LLVM_UNLIKELY(externalValue == nullptr)) {
    414351                throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
     
    590527            throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->to_string() + "\"");
    591528        }
    592         expr = mBuilder->CreateCall(ci->second, mParameterAddr);
     529        expr = mBuilder->CreateCall(ci->second, mInputAddressPtr);
    593530    }
    594531    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
     
    795732    return mBuilder->CreateXor(expr, mOneInitializer, "not");
    796733}
    797 
    798734   
    799735void PabloCompiler::SetOutputValue(Value * marker, const unsigned index) {
     
    802738    }
    803739    Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(index)};
    804     Value* gep = mBuilder->CreateGEP(mOutputAddrPtr, indices);
     740    Value* gep = mBuilder->CreateGEP(mOutputAddressPtr, indices);
    805741    mBuilder->CreateAlignedStore(marker, gep, BLOCK_SIZE/8, false);
    806742}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4657 r4659  
    103103    CompiledPabloFunction compile(pablo::PabloFunction &function);
    104104private:
    105     void DefineTypes(PabloFunction & function);
     105    void GenerateFunction(PabloFunction & function);
    106106    void DeclareFunctions();
    107107    void Examine(PabloBlock & blk);
     
    150150
    151151    VectorType* const                   mBitBlockType;
    152     PointerType*                        mBasisBitsInputPtr;
     152    PointerType*                        mInputPtr;
    153153
    154154    PabloBlock *                        mPabloBlock;
     
    161161    Constant* const                     mOneInitializer;
    162162
    163     FunctionType*                       mFunctionType;
    164     Function*                           mFunction;
    165 
    166 
    167     Value*                              mParameterAddr;
    168     Value*                              mOutputAddrPtr;
     163    Function *                          mFunction;
     164    Value *                             mInputAddressPtr;
     165    Value *                             mOutputAddressPtr;
    169166
    170167    unsigned                            mMaxWhileDepth;
Note: See TracChangeset for help on using the changeset viewer.