Ignore:
Timestamp:
Jul 15, 2015, 5:01:42 PM (4 years ago)
Author:
nmedfort
Message:

Modified function signature of the existing external UCD functions to match that of the JITed function. Updated pablo_compiler to produce the correct CallInsts?.

File:
1 edited

Legend:

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

    r4670 r4674  
    133133    }
    134134    DeclareFunctions(engine);
    135     DeclareCallFunctions(function, engine);
     135    DeclareCallFunctions(engine);
    136136
    137137    auto func = compile(function, mMod);
     
    347347}
    348348
    349 inline void PabloCompiler::DeclareFunctions(ExecutionEngine * engine) {
     349inline void PabloCompiler::DeclareFunctions(ExecutionEngine * const engine) {
    350350    if (DumpTrace || TraceNext) {
    351351        //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    352352        mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(mMod->getContext()), Type::getInt8PtrTy(mMod->getContext()), mBitBlockType, NULL);
    353         engine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
    354     }
    355 }
    356    
    357 void PabloCompiler::DeclareCallFunctions(PabloFunction & function, ExecutionEngine * engine) {
     353        if (engine) engine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
     354    }
     355}
     356   
     357void PabloCompiler::DeclareCallFunctions(ExecutionEngine * const engine) {
    358358    for (auto mapping : mCalleeMap) {
    359359        const String * callee = mapping.first;
     
    361361        if (ei != mExternalMap.end()) {
    362362
    363             PointerType * inputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>(function.getParameters().size(), mBitBlockType)), 0);
    364             ArrayRef<Type*> args = {inputType};
    365             FunctionType * functionType = FunctionType::get(mBitBlockType, args, false);
    366 
    367             SmallVector<AttributeSet, 4> Attrs;
    368             Attrs.push_back(AttributeSet::get(mMod->getContext(), ~0U, { Attribute::NoUnwind, Attribute::UWTable }));
     363            Type * inputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>{8, mBitBlockType}), 0);
     364            Type * carryType = PointerType::get(mBitBlockType, 0);
     365            Type * outputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>{1, mBitBlockType}), 0);
     366            FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{inputType, carryType, outputType}, false);
     367
     368            //Starts on process_block
     369            SmallVector<AttributeSet, 3> Attrs;
    369370            Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, { Attribute::ReadOnly, Attribute::NoCapture }));
     371            Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::NoCapture }));
     372            Attrs.push_back(AttributeSet::get(mMod->getContext(), 3U, { Attribute::ReadNone, Attribute::NoCapture }));
    370373            AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
    371374
    372             Value * externalValue = mMod->getOrInsertFunction(callee->value(), functionType, AttrSet);
    373 
    374             if (LLVM_UNLIKELY(externalValue == nullptr)) {
     375            Function * externalFunction = cast<Function>(mMod->getOrInsertFunction(callee->value(), functionType, AttrSet));
     376            if (LLVM_UNLIKELY(externalFunction == nullptr)) {
    375377                throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
    376378            }
    377             engine->addGlobalMapping(cast<GlobalValue>(externalValue), ei->second);
    378             mCalleeMap[callee] = externalValue;
     379            externalFunction->setCallingConv(llvm::CallingConv::C);
     380
     381            if (engine) engine->addGlobalMapping(externalFunction, ei->second);
     382            mCalleeMap[callee] = externalFunction;
    379383        }
    380384        else {
     
    578582        if (LLVM_UNLIKELY(ci == mCalleeMap.end())) {
    579583            throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->to_string() + "\"");
    580         }
    581         expr = mBuilder->CreateCall(ci->second, mInputAddressPtr);
     584        }       
     585
     586        Function * function = ci->second;
     587        auto arg = function->getArgumentList().begin();
     588        Value * carryFramePtr = ConstantPointerNull::get(cast<PointerType>((++arg)->getType()));
     589        AllocaInst * outputStruct = mBuilder->CreateAlloca(cast<PointerType>((++arg)->getType())->getElementType());
     590        mBuilder->CreateCall3(function, mInputAddressPtr, carryFramePtr, outputStruct);
     591        Value * outputPtr = mBuilder->CreateGEP(outputStruct, { mBuilder->getInt32(0), mBuilder->getInt32(0) });
     592        expr = mBuilder->CreateAlignedLoad(outputPtr, BLOCK_SIZE / 8, false);
    582593    }
    583594    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
Note: See TracChangeset for help on using the changeset viewer.