Ignore:
Timestamp:
Dec 25, 2014, 8:30:38 AM (4 years ago)
Author:
cameron
Message:

Sel -> Xor optimization; implement Pablo Xor in printer, compiler

File:
1 edited

Legend:

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

    r4353 r4359  
    6060//#define DUMP_GENERATED_IR
    6161#include "llvm/Support/CommandLine.h"
    62 
    63 cl::OptionCategory eIRDumpOptions("LLVM IR Dump Options",
    64                                     "These options control dumping of LLVM IR.");
    65 
    66 static cl::opt<bool> DumpGeneratedIR("dump-generated-IR", cl::init(false), cl::desc("print LLVM IR generated by RE compilation"), cl::cat(eIRDumpOptions));
     62static cl::opt<bool> DumpGeneratedIR("dump-generated-IR", cl::init(false), cl::desc("print LLVM IR generated by RE compilation"));
    6763
    6864extern "C" {
     
    831827Value * PabloCompiler::compileExpression(const PabloAST * expr)
    832828{
    833     Value * retVal = nullptr;
    834829    IRBuilder<> b(mBasicBlock);
    835830    if (isa<Ones>(expr)) {
    836         retVal = mOneInitializer;
     831        return mOneInitializer;
    837832    }
    838833    else if (isa<Zeroes>(expr)) {
    839         retVal = mZeroInitializer;
     834        return mZeroInitializer;
    840835    }
    841836    else if (const Call* call = dyn_cast<Call>(expr)) {
     
    849844            mi = mMarkerMap.insert(std::make_pair(call->getCallee(), b.CreateCall(ci->second, mBasisBitsAddr))).first;
    850845        }
    851         retVal = mi->second;
     846        return mi->second;
    852847    }
    853848    else if (const Var * var = dyn_cast<Var>(expr))
     
    857852            throw std::runtime_error((var->getName()->str()) + " used before creation.");
    858853        }
    859         retVal = f->second;
     854        return f->second;
    860855    }
    861856    else if (const And * pablo_and = dyn_cast<And>(expr))
    862857    {
    863         retVal = b.CreateAnd(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()), "and");
     858        return b.CreateAnd(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()), "and");
    864859    }
    865860    else if (const Or * pablo_or = dyn_cast<Or>(expr))
    866861    {
    867         retVal = b.CreateOr(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()), "or");
     862        return b.CreateOr(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()), "or");
     863    }
     864    else if (const Xor * pablo_xor = dyn_cast<Xor>(expr))
     865    {
     866        return b.CreateXor(compileExpression(pablo_xor->getExpr1()), compileExpression(pablo_xor->getExpr2()), "xor");
    868867    }
    869868    else if (const Sel * sel = dyn_cast<Sel>(expr))
     
    872871        Value* ifTrue = b.CreateAnd(ifMask, compileExpression(sel->getTrueExpr()));
    873872        Value* ifFalse = b.CreateAnd(genNot(ifMask), compileExpression(sel->getFalseExpr()));
    874         retVal = b.CreateOr(ifTrue, ifFalse);
     873        return b.CreateOr(ifTrue, ifFalse);
    875874    }
    876875    else if (const Not * pablo_not = dyn_cast<Not>(expr))
    877876    {
    878         retVal = genNot(compileExpression(pablo_not->getExpr()));
     877        return genNot(compileExpression(pablo_not->getExpr()));
    879878    }
    880879    else if (const Advance * adv = dyn_cast<Advance>(expr))
     
    882881        Value* strm_value = compileExpression(adv->getExpr());
    883882        int shift = adv->getAdvanceAmount();
    884         retVal = genAdvanceWithCarry(strm_value, shift);
     883        return genAdvanceWithCarry(strm_value, shift);
    885884    }
    886885    else if (const MatchStar * mstar = dyn_cast<MatchStar>(expr))
     
    889888        Value* cc = compileExpression(mstar->getCharClass());
    890889        Value* marker_and_cc = b.CreateAnd(marker, cc);
    891         retVal = b.CreateOr(b.CreateXor(genAddWithCarry(marker_and_cc, cc), cc), marker, "matchstar");
     890        return b.CreateOr(b.CreateXor(genAddWithCarry(marker_and_cc, cc), cc), marker, "matchstar");
    892891    }
    893892    else if (const ScanThru * sthru = dyn_cast<ScanThru>(expr))
     
    895894        Value* marker_expr = compileExpression(sthru->getScanFrom());
    896895        Value* cc_expr = compileExpression(sthru->getScanThru());
    897         retVal = b.CreateAnd(genAddWithCarry(marker_expr, cc_expr), genNot(cc_expr), "scanthru");
    898     }
    899     return retVal;
     896        return b.CreateAnd(genAddWithCarry(marker_expr, cc_expr), genNot(cc_expr), "scanthru");
     897    }
     898    else {
     899        throw std::runtime_error("Unrecognized Pablo expression type; can't compile.");
     900    }
     901
    900902}
    901903
Note: See TracChangeset for help on using the changeset viewer.