Ignore:
Timestamp:
Aug 16, 2015, 3:55:50 PM (4 years ago)
Author:
cameron
Message:

Embed carry data in compiled LLVM module; eliminate passing of carry data pointers/size

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4720 r4726  
    7070, mBuilder(nullptr)
    7171, mCarryManager(nullptr)
    72 , mCarryOffset(0)
    7372, mBitBlockType(VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE / 64))
    7473, iBuilder(mBitBlockType)
     
    145144    mExecutionEngine = nullptr; // <-- pass ownership of the execution engine to the caller
    146145
    147     return CompiledPabloFunction(func.second, func.first, engine);
    148 }
    149 
    150 std::pair<llvm::Function *, size_t> PabloCompiler::compile(PabloFunction & function, Module * module) {
     146    return CompiledPabloFunction(func, engine);
     147}
     148
     149llvm::Function * PabloCompiler::compile(PabloFunction & function, Module * module) {
    151150
    152151 
    153     function.getEntryBlock().enumerateScopes(0);
     152    PabloBlock & mainScope = function.getEntryBlock();
     153
     154    mainScope.enumerateScopes(0);
    154155   
    155156    Examine(function);
     
    162163
    163164    mCarryManager = new CarryManager(mBuilder, mBitBlockType, mZeroInitializer, mOneInitializer, &iBuilder);
    164 
     165   
     166       
    165167    GenerateFunction(function);
    166168
     
    178180    }
    179181     
    180     PabloBlock & mainScope = function.getEntryBlock();
    181 
    182     mCarryOffset = mCarryManager->initialize(&mainScope, mCarryDataPtr);
    183    
    184182    //Generate the IR instructions for the function.
     183   
     184    mCarryManager->initialize(mMod, &mainScope);
    185185   
    186186    compileBlock(mainScope);
     
    204204    //Terminate the block
    205205    ReturnInst::Create(mMod->getContext(), mBuilder->GetInsertBlock());
     206   
    206207
    207208    // Clean up
     
    211212
    212213    //Return the required size of the carry data area to the process_block function.
    213     return std::make_pair(mFunction, mCarryOffset * sizeof(BitBlock));
     214    return mFunction;
    214215}
    215216
    216217inline void PabloCompiler::GenerateFunction(PabloFunction & function) {
    217218    mInputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>(function.getNumOfParameters(), mBitBlockType)), 0);
    218     Type * carryType = PointerType::get(mBitBlockType, 0);
    219219    Type * outputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>(function.getNumOfResults(), mBitBlockType)), 0);
    220     FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), {{mInputType, carryType, outputType}}, false);
     220    FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), {{mInputType, outputType}}, false);
    221221
    222222#ifdef USE_UADD_OVERFLOW
     
    304304
    305305    //Starts on process_block
    306     SmallVector<AttributeSet, 4> Attrs;
     306    SmallVector<AttributeSet, 3> Attrs;
    307307    Attrs.push_back(AttributeSet::get(mMod->getContext(), ~0U, { Attribute::NoUnwind, Attribute::UWTable }));
    308308    Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, { Attribute::ReadOnly, Attribute::NoCapture }));
    309     Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::NoCapture }));
    310     Attrs.push_back(AttributeSet::get(mMod->getContext(), 3U, { Attribute::ReadNone, Attribute::NoCapture }));
     309    Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::ReadNone, Attribute::NoCapture }));
    311310    AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
    312311
     
    319318    mInputAddressPtr = args++;
    320319    mInputAddressPtr->setName("input");
    321     mCarryDataPtr = args++;
    322     mCarryDataPtr->setName("carry");
    323320    mOutputAddressPtr = args++;
    324321    mOutputAddressPtr->setName("output");
     
    550547
    551548        Type * inputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfParameters(), mBitBlockType});
    552         Type * carryType = mBitBlockType;
    553549        Type * outputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfResults(), mBitBlockType});
    554         FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{PointerType::get(inputType, 0), PointerType::get(carryType, 0), PointerType::get(outputType, 0)}, false);
     550        FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{PointerType::get(inputType, 0), PointerType::get(outputType, 0)}, false);
    555551
    556552        //Starts on process_block
    557553        SmallVector<AttributeSet, 3> Attrs;
    558554        Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, { Attribute::ReadOnly, Attribute::NoCapture }));
    559         Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::NoCapture }));
    560         Attrs.push_back(AttributeSet::get(mMod->getContext(), 3U, { Attribute::ReadNone, Attribute::NoCapture }));
     555        Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::ReadNone, Attribute::NoCapture }));
    561556        AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
    562557
     
    569564        if (mExecutionEngine) mExecutionEngine->addGlobalMapping(externalFunction, proto->getFunctionPtr());
    570565
    571         // add mCarryOffset to mCarryDataPtr
    572         Value * carryFramePtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(mCarryOffset));
    573566        AllocaInst * outputStruct = mBuilder->CreateAlloca(outputType);
    574         mBuilder->CreateCall3(externalFunction, mInputAddressPtr, carryFramePtr, outputStruct);
     567        mBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
    575568        Value * outputPtr = mBuilder->CreateGEP(outputStruct, { mBuilder->getInt32(0), mBuilder->getInt32(0) });
    576569        expr = mBuilder->CreateAlignedLoad(outputPtr, BLOCK_SIZE / 8, false);
    577 
    578         mCarryOffset += (proto->getRequiredStateSpace() + (BLOCK_SIZE / 8) - 1) / (BLOCK_SIZE / 8);
    579570    }
    580571    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
     
    814805}
    815806
    816 CompiledPabloFunction::CompiledPabloFunction(size_t carryDataSize, Function * function, ExecutionEngine * executionEngine)
    817 : CarryDataSize(carryDataSize)
    818 , FunctionPointer(executionEngine->getPointerToFunction(function))
     807CompiledPabloFunction::CompiledPabloFunction(Function * function, ExecutionEngine * executionEngine)
     808: FunctionPointer(executionEngine->getPointerToFunction(function))
    819809, mFunction(function)
    820810, mExecutionEngine(executionEngine)
Note: See TracChangeset for help on using the changeset viewer.