Ignore:
Timestamp:
Jul 21, 2014, 11:49:25 AM (5 years ago)
Author:
cameron
Message:

Updates for icgrep-0.9: re simplifications, re names, replimit mods, debugged while loops

File:
1 edited

Legend:

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

    r3854 r3914  
    66
    77#include "llvm_gen.h"
     8#include "printer_pablos.h"
    89
    910extern "C" {
     
    1819}
    1920
    20 LLVM_Generator::LLVM_Generator(std::string basis_pattern, int bits)
     21LLVM_Generator::LLVM_Generator(std::string basis_pattern, std::string lf_ccname, int bits)
    2122{
    2223    mBasis_Pattern = basis_pattern;
     24    m_lf_ccname = lf_ccname;
    2325    mBits = bits;
    2426    mInWhile = false;
     
    3840    InitializeNativeTarget();
    3941    std::string ErrStr;
    40     mExecutionEngine = EngineBuilder(mMod).setUseMCJIT(true).setErrorStr(&ErrStr).setOptLevel(CodeGenOpt::Default).create();
     42
     43    mExecutionEngine = EngineBuilder(mMod).setUseMCJIT(true).setErrorStr(&ErrStr).setOptLevel(CodeGenOpt::Level::Less).create();
    4144    if (!mExecutionEngine)
    4245    {
     
    6164    //Create the carry queue.
    6265    mCarryQueueIdx = 0;
     66    mCarryQueueSize = LLVM_Generator_Helper::CarryCount_PabloStatements(cg_state.stmtsl);
    6367
    6468    mBasicBlock = BasicBlock::Create(mMod->getContext(), "parabix_entry", mFunc_process_block,0);
     
    8185    Generate_PabloStatements(cg_state.stmtsl);
    8286    SetReturnMarker(cg_state.newsym, 0);
    83     SetReturnMarker("lex.cclf", 1);
     87    SetReturnMarker(m_lf_ccname, 1);
    8488
    8589    //Terminate the block
     
    98102    fpm.add(new DataLayout(*mExecutionEngine->getDataLayout()));
    99103
    100     fpm.add(createPromoteMemoryToRegisterPass());
     104    fpm.add(createPromoteMemoryToRegisterPass()); //Transform to SSA form.
     105
     106    fpm.add(createBasicAliasAnalysisPass());      //Provide basic AliasAnalysis support for GVN. (Global Value Numbering)
     107    fpm.add(createInstructionCombiningPass());    //Simple peephole optimizations and bit-twiddling.
     108    fpm.add(createCFGSimplificationPass());       //Simplify the control flow graph (deleting unreachable blocks, etc).
     109    fpm.add(createReassociatePass());             //Reassociate expressions.
     110    fpm.add(createGVNPass());                     //Eliminate common subexpressions.
    101111
    102112    fpm.doInitialization();
     
    110120    LLVM_Gen_RetVal retVal;
    111121    //Return the required size of the carry queue and a pointer to the process_block function.
    112     retVal.carry_q_size = LLVM_Generator_Helper::CarryCount_PabloStatements(cg_state.stmtsl);;
     122    retVal.carry_q_size = mCarryQueueSize;
    113123    retVal.process_block_fptr = mExecutionEngine->getPointerToFunction(mFunc_process_block);
    114124
     
    293303    else if (While* whl = dynamic_cast<While*>(stmt))
    294304    {
    295         IRBuilder<> b(mBasicBlock);
    296 
    297         mWhileCondBlock = BasicBlock::Create(mMod->getContext(), "while.cond", mFunc_process_block, 0);
    298         mWhileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body",mFunc_process_block, 0);
    299         mWhileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end",mFunc_process_block, 0);
    300 
    301305        int idx = mCarryQueueIdx;
    302306
     307        //With this call to the while body we will account for all of the carry in values.
    303308        std::string returnMarker = Generate_PabloStatements(whl->getPSList());
    304309
    305         b.CreateBr(mWhileCondBlock);
    306         mBasicBlock = mWhileCondBlock;
    307         IRBuilder<> b_cond(mWhileCondBlock);
     310        BasicBlock*  whileCondBlock = BasicBlock::Create(mMod->getContext(), "while.cond", mFunc_process_block, 0);
     311        BasicBlock*  whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body",mFunc_process_block, 0);
     312        BasicBlock*  whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end",mFunc_process_block, 0);
     313
     314        IRBuilder<> b(mBasicBlock);
     315        b.CreateBr(whileCondBlock);
     316        mBasicBlock = whileCondBlock;
     317        IRBuilder<> b_cond(whileCondBlock);
    308318
    309319        Value* expression_marker_value = Generate_PabloE(whl->getExpr());
    310        
    311320        // Use an i128 compare for simplicity and speed.
    312321        Value* cast_marker_value_1 = b_cond.CreateBitCast(expression_marker_value, IntegerType::get(mMod->getContext(), 128));
    313322        Value* int_tobool1 = b_cond.CreateICmpEQ(cast_marker_value_1, ConstantInt::get(IntegerType::get(mMod->getContext(), 128), 0));
    314         b_cond.CreateCondBr(int_tobool1, mWhileEndBlock, mWhileBodyBlock);
    315 
    316         //Note: Everything that happens during the recursive calls for the pablo statements in the body of this while loop will
    317         //happen within the basic block of the body of the while loop.  This strategy will not support kstars within
    318         //kstars, a more complex stragegy for basicblocks will have to be devised for that.
    319         mBasicBlock = mWhileBodyBlock;
    320 
    321         mInWhile = true;
    322         mCarryQueueIdx = idx;
     323        b_cond.CreateCondBr(int_tobool1, whileEndBlock, whileBodyBlock);
     324
     325        mBasicBlock = whileBodyBlock;
     326        mCarryQueueIdx = 0;
     327        //Store the current carry queue.
     328        Value* ptr_last_carry_q = mptr_carry_q;
     329
     330        IRBuilder<> b_wb1(mBasicBlock);
     331        //Create and initialize a new carry queue.
     332        Value* ptr_while_carry_q = b_wb1.CreateAlloca(m64x2Vect, b_wb1.getInt64(mCarryQueueSize - idx));
     333        for (int i=0; i<(mCarryQueueSize-idx); i++)
     334        {
     335            Value* carryq_idx1 = b_wb1.getInt64(i);
     336            Value* carryq_GEP1 = b_wb1.CreateGEP(ptr_while_carry_q, carryq_idx1);
     337            Value* void_1 = b_wb1.CreateStore(mConst_Aggregate_64x2_0, carryq_GEP1);
     338        }
     339
     340        //Point mptr_carry_q to the new local carry queue.
     341        mptr_carry_q = ptr_while_carry_q;
     342
    323343        returnMarker = Generate_PabloStatements(whl->getPSList());
    324         mInWhile = false;
    325         IRBuilder<> b_wb(mWhileBodyBlock);
    326         b_wb.CreateBr(mWhileCondBlock);
    327 
    328         mBasicBlock = mWhileEndBlock;
     344
     345        IRBuilder<> b_wb2(mBasicBlock);
     346        //Copy back to the last carry queue the carries from the execution of the while statement list.
     347        for (int c=0; c<(mCarryQueueSize-idx); c++)
     348        {
     349            Value* carryq_idx = b_wb2.getInt64(c);
     350            Value* carryq_GEP = b_wb2.CreateGEP(mptr_carry_q, carryq_idx);
     351            Value* carryq_value = b_wb2.CreateLoad(carryq_GEP);
     352
     353            Value* last_carryq_idx = b_wb2.getInt64(idx + c);
     354            Value* last_carryq_GEP = b_wb2.CreateGEP(ptr_last_carry_q, last_carryq_idx);
     355            Value* last_carryq_value = b_wb2.CreateLoad(last_carryq_GEP);
     356
     357            Value* new_carryq_value = b_wb2.CreateOr(carryq_value, last_carryq_value);
     358            Value* void_1 = b_wb2.CreateStore(new_carryq_value, last_carryq_GEP);
     359        }
     360
     361        b_wb2.CreateBr(whileCondBlock);
     362
     363        mBasicBlock = whileEndBlock;
     364        mptr_carry_q = ptr_last_carry_q;
     365        mCarryQueueIdx += idx;
    329366
    330367        retVal = returnMarker;
     
    419456
    420457        Value* packed_shuffle;
    421         if (mInWhile)
    422         {
    423             Constant* const_packed_1_elems [] = {b.getInt32(0), b.getInt32(2)};
    424             Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
    425             packed_shuffle = b.CreateShuffleVector(mConst_Aggregate_64x2_0, srli_1_value, const_packed_1, "packed_shuffle iw");
    426         }
    427         else
    428         {
    429             Constant* const_packed_1_elems [] = {b.getInt32(0), b.getInt32(2)};
    430             Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
    431             packed_shuffle = b.CreateShuffleVector(carryq_value, srli_1_value, const_packed_1, "packed_shuffle nw");
    432         }
     458        Constant* const_packed_1_elems [] = {b.getInt32(0), b.getInt32(2)};
     459        Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
     460        packed_shuffle = b.CreateShuffleVector(carryq_value, srli_1_value, const_packed_1, "packed_shuffle nw");
    433461
    434462        Constant* const_packed_2_elems[] = {b.getInt64(1), b.getInt64(1)};
     
    442470        Value* srli_2_value = b.CreateLShr(cast_marker_value_1, 127);
    443471        Value* carryout_2_carry = b.CreateBitCast(srli_2_value, m64x2Vect);
    444 
    445         if (mInWhile)
    446         {
    447             Value* carryout = b.CreateOr(carryq_value, carryout_2_carry);
    448             Value* void_1 = b.CreateStore(carryout, carryq_GEP);
    449         }
    450         else
    451         {
    452             Value* void_1 = b.CreateStore(carryout_2_carry, carryq_GEP);
    453         }
     472        Value* void_1 = b.CreateStore(carryout_2_carry, carryq_GEP);
    454473
    455474        //Increment the idx for the next advance or scan through.
Note: See TracChangeset for help on using the changeset viewer.