Ignore:
Timestamp:
Oct 24, 2014, 1:35:16 PM (5 years ago)
Author:
nmedfort
Message:

Generalized the writing of output variables by adding a 'flag' to the Assign nodes.

File:
1 edited

Legend:

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

    r4267 r4268  
    7474namespace pablo {
    7575
    76 PabloCompiler::PabloCompiler(const cc::CC_NameMap & nameMap, const BasisBitVars & basisBitVars, int bits)
     76PabloCompiler::PabloCompiler(const BasisBitVars & basisBitVars, int bits)
    7777: mBits(bits)
    7878, mBasisBitVars(basisBitVars)
     
    9393, mBasisBitsAddr(nullptr)
    9494, mOutputAddrPtr(nullptr)
    95 , mNameMap(nameMap)
    9695{
    9796    //Create the jit execution engine.up
     
    149148{
    150149    mCarryQueueSize = 0;
    151     DeclareCallFunctions(pb.expressions());
     150    DeclareCallFunctions(pb.statements());
    152151    mCarryQueueVector.resize(mCarryQueueSize);
    153152
     
    176175
    177176    //Generate the IR instructions for the function.
    178     Value * result = compileStatements(pb.expressions());
    179     SetReturnMarker(result, 0); // matches
    180     const String * lf = mNameMap["LineFeed"]->getVar()->getName();
    181     SetReturnMarker(mMarkerMap.find(lf)->second, 1); // line feeds
     177    compileStatements(pb.statements());
    182178
    183179    assert (mCarryQueueIdx == mCarryQueueSize);
     
    485481}
    486482
    487 inline Value* PabloCompiler::GetMarker(const String * name) {
    488     auto itr = mMarkerMap.find(name);
    489     if (itr == mMarkerMap.end()) {
    490         IRBuilder<> b(mBasicBlock);
    491         itr = mMarkerMap.insert(std::make_pair(name, b.CreateAlloca(mXi64Vect))).first;
    492     }
    493     return itr->second;
    494 }
    495 
    496 void PabloCompiler::SetReturnMarker(Value * marker, const unsigned index) {
    497     IRBuilder<> b(mBasicBlock);
    498     if (marker->getType()->isPointerTy()) {
    499         marker = b.CreateAlignedLoad(marker, BLOCK_SIZE/8, false);
    500     }
    501     Value* indices[] = {b.getInt64(0), b.getInt32(index)};
    502     Value* gep = b.CreateGEP(mOutputAddrPtr, indices);
    503     b.CreateAlignedStore(marker, gep, BLOCK_SIZE/8, false);
    504 }
    505 
    506 
    507483Value * PabloCompiler::compileStatements(const StatementList & stmts) {
    508484    Value * retVal = nullptr;
     
    520496        Value* expr = compileExpression(assign->getExpr());
    521497        mMarkerMap[assign->getName()] = expr;
     498        if (unlikely(assign->isOutputAssignment())) {
     499            SetOutputValue(expr, assign->getOutputIndex());
     500        }
    522501        retVal = expr;
    523502    }
     
    611590        BasicBlock* whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunc_process_block, 0);
    612591
    613         // Note: compileStatements may update the mBasicBlock pointer if the body contains nested loops. Do not
    614         // assume it is the same one in which we entered the function with.
     592        // Note: compileStatements may update the mBasicBlock pointer if the body contains nested loops. It
     593        // may not be same one that we entered the function with.
    615594        IRBuilder<> bEntry(mBasicBlock);
    616595        bEntry.CreateBr(whileCondBlock);
     
    897876}
    898877
    899 }
     878void PabloCompiler::SetOutputValue(Value * marker, const unsigned index) {
     879    IRBuilder<> b(mBasicBlock);
     880    if (marker->getType()->isPointerTy()) {
     881        marker = b.CreateAlignedLoad(marker, BLOCK_SIZE/8, false);
     882    }
     883    Value* indices[] = {b.getInt64(0), b.getInt32(index)};
     884    Value* gep = b.CreateGEP(mOutputAddrPtr, indices);
     885    b.CreateAlignedStore(marker, gep, BLOCK_SIZE/8, false);
     886}
     887
     888}
Note: See TracChangeset for help on using the changeset viewer.