source: icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp @ 5023

Last change on this file since 5023 was 5023, checked in by cameron, 3 years ago

pablo.InFile? initial support

File size: 20.1 KB
RevLine 
[3850]1/*
[4533]2 *  Copyright (c) 2014-15 International Characters.
[3850]3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
[4237]7#include <pablo/pablo_compiler.h>
8#include <pablo/codegenstate.h>
[4566]9#include <pablo/carry_data.h>
[4647]10#include <pablo/carry_manager.h>
[4237]11#include <pablo/printer_pablos.h>
[4657]12#include <pablo/function.h>
[4249]13#include <re/re_name.h>
[4237]14#include <stdexcept>
[4416]15#include <sstream>
[4663]16#include <IDISA/idisa_builder.h>
[4892]17#include <IDISA/idisa_avx_builder.h>
[4274]18#include <llvm/Pass.h>
19#include <llvm/PassManager.h>
20#include <llvm/ADT/SmallVector.h>
21#include <llvm/Analysis/Passes.h>
22#include <llvm/IR/BasicBlock.h>
23#include <llvm/IR/CallingConv.h>
24#include <llvm/IR/DataLayout.h>
25#include <llvm/IR/DerivedTypes.h>
26#include <llvm/IR/Function.h>
27#include <llvm/IR/GlobalVariable.h>
28#include <llvm/IR/InlineAsm.h>
29#include <llvm/IR/Instructions.h>
30#include <llvm/IR/LLVMContext.h>
31#include <llvm/IR/Module.h>
32#include <llvm/Support/FormattedStream.h>
33#include <llvm/Support/MathExtras.h>
34#include <llvm/Support/Casting.h>
[4280]35#include <llvm/Support/Compiler.h>
[4274]36#include <llvm/Support/Debug.h>
37#include <llvm/Support/TargetSelect.h>
38#include <llvm/Support/Host.h>
39#include <llvm/Transforms/Scalar.h>
40#include <llvm/IRReader/IRReader.h>
41#include <llvm/Bitcode/ReaderWriter.h>
42#include <llvm/Support/MemoryBuffer.h>
43#include <llvm/IR/IRBuilder.h>
[4510]44#include <llvm/Support/CommandLine.h>
45#include <llvm/ADT/Twine.h>
[4438]46#include <iostream>
[4919]47#include <llvm/Support/raw_ostream.h>
48#include <llvm/Support/FileSystem.h>
[4922]49#ifndef NDEBUG
50#include <llvm/IR/Verifier.h>
51#endif
[4919]52#include <hrtime.h>
53
[4544]54static cl::OptionCategory fTracingOptions("Run-time Tracing Options", "These options control execution traces.");
55static cl::opt<bool> DumpTrace("dump-trace", cl::init(false), cl::desc("Generate dynamic traces of executed assignments."), cl::cat(fTracingOptions));
56
[4237]57namespace pablo {
58
[4974]59#define DSSLI_FIELDWIDTH 64
60
[4900]61PabloCompiler::PabloCompiler(Module * m, IDISA::IDISA_Builder * b)
62: mMod(m)
63, iBuilder(b)
64, mBitBlockType(b->getBitBlockType())
[4647]65, mCarryManager(nullptr)
[4959]66, mPabloFunction(nullptr)
67, mPabloBlock(nullptr)
[4970]68, mKernelBuilder(nullptr)
[4545]69, mWhileDepth(0)
70, mIfDepth(0)
[4274]71, mFunction(nullptr)
[4970]72, mMaxWhileDepth(0) {
[4892]73   
[4237]74}
75
[4974]76void PabloCompiler::setKernel(kernel::KernelBuilder * kBuilder){
[4970]77    mKernelBuilder = kBuilder;
[4939]78} 
79
[4734]80llvm::Function * PabloCompiler::compile(PabloFunction * function) {
[4665]81
[4919]82    #ifdef PRINT_TIMING_INFORMATION
83    const timestamp_t pablo_compilation_start = read_cycle_counter();
84    #endif
[4687]85 
[5000]86    Examine(function);
[4665]87
[4898]88    mCarryManager = new CarryManager(iBuilder);
[4237]89
[4959]90    GenerateKernel(function);
[4939]91       
[4919]92    delete mCarryManager;
93    mCarryManager = nullptr;
[4900]94   
[4919]95    #ifdef PRINT_TIMING_INFORMATION
96    const timestamp_t pablo_compilation_end = read_cycle_counter();
97    std::cerr << "PABLO COMPILATION TIME: " << (pablo_compilation_end - pablo_compilation_start) << std::endl;
98    #endif
99
[4726]100    return mFunction;
[4237]101}
102
[4959]103inline void PabloCompiler::GenerateKernel(PabloFunction * const function) {
[4939]104 
[4959]105    mPabloFunction = function;
106
107    for (unsigned i = 0; i < function->getNumOfParameters(); ++i) {
[4970]108        mKernelBuilder->addInputStream(1, function->getParameter(i)->getName()->to_string());
[4939]109    }
[4959]110    for (unsigned i = 0; i < function->getNumOfResults(); ++i) {
[4970]111        mKernelBuilder->addOutputStream(1);
[4959]112    }
[4939]113
[4970]114    mCarryManager->initialize(function, mKernelBuilder);
[4959]115
[5000]116    mFunction = mKernelBuilder->prepareFunction({mInputStreamOffset.begin(), mInputStreamOffset.end()});
[4959]117
[4974]118    mCarryManager->reset();
[4939]119
[4974]120    for (unsigned j = 0; j < function->getNumOfParameters(); ++j) {
[4986]121        Value * inputVal = mKernelBuilder->getInputStream(j);
[5000]122        const Var * const var = function->getParameter(j);
[4986]123        if (DumpTrace) {
[5000]124            iBuilder->CallPrintRegister(var->getName()->to_string(), iBuilder->CreateBlockAlignedLoad(inputVal));
[4986]125        }
[5000]126        mMarkerMap.insert(std::make_pair(var, inputVal));
[4974]127    }
[4939]128
[4974]129    compileBlock(function->getEntryBlock());
[4959]130
[4974]131    for (unsigned j = 0; j < function->getNumOfResults(); ++j) {
132        const auto f = mMarkerMap.find(function->getResult(j));
133        if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
[4995]134            throw std::runtime_error("PabloCompiler: result " + std::to_string(j) + " was not assigned a value!");
[4939]135        }
[4995]136        iBuilder->CreateBlockAlignedStore(f->second, mKernelBuilder->getOutputStream(j));
[4974]137    }
[4939]138
[4970]139    mKernelBuilder->finalize();
[4237]140}
[4659]141
[5000]142inline void PabloCompiler::Examine(const PabloFunction * const function) {
[4692]143    mWhileDepth = 0;
144    mIfDepth = 0;
145    mMaxWhileDepth = 0;
[5000]146    LookaheadOffsetMap offsetMap;
147    Examine(function->getEntryBlock(), offsetMap);
148    mInputStreamOffset.clear();
149    for (const auto & oi : offsetMap) {
150        for (const auto offset : oi.second) {
151            mInputStreamOffset.insert(offset / iBuilder->getBitBlockWidth());
152        }
153    }
[4659]154}
[4665]155
[5000]156void PabloCompiler::Examine(const PabloBlock * const block, LookaheadOffsetMap & offsetMap) {
157    for (const Statement * stmt : *block) {
158         boost::container::flat_set<unsigned> offsets;
159        if (LLVM_UNLIKELY(isa<Lookahead>(stmt))) {
160            const Lookahead * const la = cast<Lookahead>(stmt);
161            assert (isa<Var>(la->getExpr()));
162            offsets.insert(la->getAmount());
163            offsets.insert(la->getAmount() + iBuilder->getBitBlockWidth() - 1);
164        } else {
165            for (unsigned i = 0; i < stmt->getNumOperands(); ++i) {
166                const PabloAST * expr = stmt->getOperand(i);
167                if (isa<Var>(expr)) {
168                    offsets.insert(0);
169                } else if (LLVM_LIKELY(isa<Statement>(expr) && !isa<Assign>(expr) && !isa<Next>(expr))) {
170                    const auto f = offsetMap.find(expr);
171                    assert (f != offsetMap.end());
172                    const auto & o = f->second;
173                    offsets.insert(o.begin(), o.end());
174                }
175            }
176            if (LLVM_UNLIKELY(isa<If>(stmt))) {
177                Examine(cast<If>(stmt)->getBody(), offsetMap);
178            } else if (LLVM_UNLIKELY(isa<While>(stmt))) {
179                mMaxWhileDepth = std::max(mMaxWhileDepth, ++mWhileDepth);
180                Examine(cast<While>(stmt)->getBody(), offsetMap);
181                --mWhileDepth;
182            }
[4237]183        }
[5000]184        offsetMap.emplace(stmt, offsets);
[4237]185    }
186}
187
[4970]188void PabloCompiler::compileBlock(const PabloBlock * const block) {
[4870]189    mPabloBlock = block;
190    for (const Statement * statement : *block) {
[4343]191        compileStatement(statement);
[4237]192    }
[4870]193    mPabloBlock = block->getParent();
[4237]194}
195
[4827]196void PabloCompiler::compileIf(const If * ifStatement) {       
[4647]197    //
198    //  The If-ElseZero stmt:
199    //  if <predicate:expr> then <body:stmt>* elsezero <defined:var>* endif
200    //  If the value of the predicate is nonzero, then determine the values of variables
201    //  <var>* by executing the given statements.  Otherwise, the value of the
202    //  variables are all zero.  Requirements: (a) no variable that is defined within
203    //  the body of the if may be accessed outside unless it is explicitly
204    //  listed in the variable list, (b) every variable in the defined list receives
205    //  a value within the body, and (c) the logical consequence of executing
206    //  the statements in the event that the predicate is zero is that the
207    //  values of all defined variables indeed work out to be 0.
208    //
209    //  Simple Implementation with Phi nodes:  a phi node in the if exit block
210    //  is inserted for each variable in the defined variable list.  It receives
211    //  a zero value from the ifentry block and the defined value from the if
212    //  body.
213    //
[4665]214
[4925]215    BasicBlock * const ifEntryBlock = iBuilder->GetInsertBlock();
216    BasicBlock * const ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunction, 0);
217    BasicBlock * const ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunction, 0);
[4541]218   
[4870]219    PabloBlock * ifBody = ifStatement->getBody();
[4628]220   
[4925]221    Value * const condition = compileExpression(ifStatement->getCondition());
[4670]222   
[4870]223    mCarryManager->enterScope(ifBody);
[4925]224    iBuilder->CreateCondBr(mCarryManager->generateSummaryTest(condition), ifBodyBlock, ifEndBlock);
[4838]225   
[4647]226    // Entry processing is complete, now handle the body of the if.
[4898]227    iBuilder->SetInsertPoint(ifBodyBlock);
[4647]228   
229    compileBlock(ifBody);
[4925]230    BasicBlock * ifExitBlock = iBuilder->GetInsertBlock();
[4922]231
[4925]232    if (mCarryManager->hasCarries()) {
233        mCarryManager->storeCarryOutSummary();
[4647]234    }
[4927]235    mCarryManager->addOuterSummaryToNestedSummary();
[4922]236
[4898]237    iBuilder->CreateBr(ifEndBlock);
[4647]238    //End Block
[4898]239    iBuilder->SetInsertPoint(ifEndBlock);
[4647]240    for (const PabloAST * node : ifStatement->getDefined()) {
241        const Assign * assign = cast<Assign>(node);
[4898]242        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, assign->getName()->value());
[4647]243        auto f = mMarkerMap.find(assign);
244        assert (f != mMarkerMap.end());
[4892]245        phi->addIncoming(iBuilder->allZeroes(), ifEntryBlock);
[4925]246        phi->addIncoming(f->second, ifExitBlock);
[4647]247        mMarkerMap[assign] = phi;
248    }
249    // Create the phi Node for the summary variable, if needed.
[4925]250    mCarryManager->buildCarryDataPhisAfterIfBody(ifEntryBlock, ifExitBlock);
[4670]251    mCarryManager->leaveScope();
[4535]252}
253
[4647]254void PabloCompiler::compileWhile(const While * whileStatement) {
[4595]255
[4870]256    PabloBlock * const whileBody = whileStatement->getBody();
[4647]257   
[4898]258    BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
[4647]259    BasicBlock * whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunction, 0);
260    BasicBlock * whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunction, 0);
[4640]261
[4870]262    mCarryManager->enterScope(whileBody);
[4670]263    mCarryManager->ensureCarriesLoadedRecursive();
[4640]264
[4647]265    const auto & nextNodes = whileStatement->getVariants();
266    std::vector<PHINode *> nextPhis;
267    nextPhis.reserve(nextNodes.size());
[4640]268
[4647]269    // On entry to the while structure, proceed to execute the first iteration
270    // of the loop body unconditionally.   The while condition is tested at the end of
271    // the loop.
[4640]272
[4898]273    iBuilder->CreateBr(whileBodyBlock);
274    iBuilder->SetInsertPoint(whileBodyBlock);
[4640]275
[4647]276    //
277    // There are 3 sets of Phi nodes for the while loop.
278    // (1) Carry-ins: (a) incoming carry data first iterations, (b) zero thereafter
279    // (2) Carry-out accumulators: (a) zero first iteration, (b) |= carry-out of each iteration
280    // (3) Next nodes: (a) values set up before loop, (b) modified values calculated in loop.
[4640]281
[4925]282    mCarryManager->initializeWhileEntryCarryDataPhis(whileEntryBlock);
[4640]283
[4647]284    // for any Next nodes in the loop body, initialize to (a) pre-loop value.
285    for (const Next * n : nextNodes) {
[4898]286        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, n->getName()->value());
[4647]287        auto f = mMarkerMap.find(n->getInitial());
288        assert (f != mMarkerMap.end());
289        phi->addIncoming(f->second, whileEntryBlock);
290        mMarkerMap[n->getInitial()] = phi;
291        nextPhis.push_back(phi);
292    }
[4595]293
[4647]294    //
295    // Now compile the loop body proper.  Carry-out accumulated values
296    // and iterated values of Next nodes will be computed.
297    ++mWhileDepth;
298    compileBlock(whileBody);
[4640]299
[4925]300    BasicBlock * whileExitBlock = iBuilder->GetInsertBlock();
[4640]301
[4925]302    if (mCarryManager->hasCarries()) {
303        mCarryManager->storeCarryOutSummary();
[4688]304    }
[4925]305    mCarryManager->finalizeWhileBlockCarryDataPhis(whileExitBlock);
[4264]306
[4647]307    // Terminate the while loop body with a conditional branch back.
[4898]308    iBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
[4576]309
[4647]310    // and for any Next nodes in the loop body
311    for (unsigned i = 0; i < nextNodes.size(); i++) {
312        const Next * n = nextNodes[i];
313        auto f = mMarkerMap.find(n->getExpr());
314        if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
315            throw std::runtime_error("Next node expression was not compiled!");
[4264]316        }
[4925]317        nextPhis[i]->addIncoming(f->second, whileExitBlock);
[4647]318    }
[4237]319
[4898]320    iBuilder->SetInsertPoint(whileEndBlock);
[4647]321    --mWhileDepth;
[4640]322
[4670]323    mCarryManager->ensureCarriesStoredRecursive();
324    mCarryManager->leaveScope();
[4535]325}
326
[4640]327
[4643]328void PabloCompiler::compileStatement(const Statement * stmt) {
329    Value * expr = nullptr;
[4535]330    if (const Assign * assign = dyn_cast<const Assign>(stmt)) {
[4657]331        expr = compileExpression(assign->getExpression());
[4959]332    } else if (const Next * next = dyn_cast<const Next>(stmt)) {
[4643]333        expr = compileExpression(next->getExpr());
[4959]334    } else if (const If * ifStatement = dyn_cast<const If>(stmt)) {
[4535]335        compileIf(ifStatement);
[4643]336        return;
[4959]337    } else if (const While * whileStatement = dyn_cast<const While>(stmt)) {
[4535]338        compileWhile(whileStatement);
[4643]339        return;
[4959]340//    } else if (const Call* call = dyn_cast<Call>(stmt)) {
341//        // Call the callee once and store the result in the marker map.
342//        if (LLVM_UNLIKELY(mMarkerMap.count(call) == 0)) {
343//            return;
344//        }
[4674]345
[4959]346//        const Prototype * proto = call->getPrototype();
347//        const String * callee = proto->getName();
[4684]348
[4959]349//        Type * inputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfParameters(), mBitBlockType});
350//        Type * outputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfResults(), mBitBlockType});
351//        FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{PointerType::get(inputType, 0), PointerType::get(outputType, 0)}, false);
[4684]352
[4959]353//        //Starts on process_block
354//        SmallVector<AttributeSet, 3> Attrs;
355//        Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, std::vector<Attribute::AttrKind>({ Attribute::ReadOnly, Attribute::NoCapture })));
356//        Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, std::vector<Attribute::AttrKind>({ Attribute::ReadNone, Attribute::NoCapture })));
357//        AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
[4684]358
[4959]359//        Function * externalFunction = cast<Function>(mMod->getOrInsertFunction(callee->value(), functionType, AttrSet));
360//        if (LLVM_UNLIKELY(externalFunction == nullptr)) {
361//            throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
362//        }
363//        externalFunction->setCallingConv(llvm::CallingConv::C);
[4684]364
[4959]365//        AllocaInst * outputStruct = iBuilder->CreateAlloca(outputType);
366//        iBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
367//        Value * outputPtr = iBuilder->CreateGEP(outputStruct, std::vector<Value *>({ iBuilder->getInt32(0), iBuilder->getInt32(0) }));
[4684]368
[4968]369//        expr = iBuilder->CreateBlockAlignedLoad(outputPtr);
[4959]370    } else if (const And * pablo_and = dyn_cast<And>(stmt)) {
[4892]371        expr = iBuilder->simd_and(compileExpression(pablo_and->getOperand(0)), compileExpression(pablo_and->getOperand(1)));
[4959]372    } else if (const Or * pablo_or = dyn_cast<Or>(stmt)) {
[4892]373        expr = iBuilder->simd_or(compileExpression(pablo_or->getOperand(0)), compileExpression(pablo_or->getOperand(1)));
[4959]374    } else if (const Xor * pablo_xor = dyn_cast<Xor>(stmt)) {
[4892]375        expr = iBuilder->simd_xor(compileExpression(pablo_xor->getOperand(0)), compileExpression(pablo_xor->getOperand(1)));
[4959]376    } else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
[4264]377        Value* ifMask = compileExpression(sel->getCondition());
[4892]378        Value* ifTrue = iBuilder->simd_and(ifMask, compileExpression(sel->getTrueExpr()));
379        Value* ifFalse = iBuilder->simd_and(iBuilder->simd_not(ifMask), compileExpression(sel->getFalseExpr()));
380        expr = iBuilder->simd_or(ifTrue, ifFalse);
[4959]381    } else if (const Not * pablo_not = dyn_cast<Not>(stmt)) {
[4892]382        expr = iBuilder->simd_not(compileExpression(pablo_not->getExpr()));
[4959]383    } else if (const Advance * adv = dyn_cast<Advance>(stmt)) {
[4925]384        Value * const strm_value = compileExpression(adv->getExpr());
[4959]385        expr = mCarryManager->advanceCarryInCarryOut(adv->getLocalIndex(), adv->getAmount(), strm_value);
386    } else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
[4925]387        Value * const marker = compileExpression(mstar->getMarker());
388        Value * const cc = compileExpression(mstar->getCharClass());
389        Value * const marker_and_cc = iBuilder->simd_and(marker, cc);
390        Value * const sum = mCarryManager->addCarryInCarryOut(mstar->getLocalCarryIndex(), marker_and_cc, cc);
[4892]391        expr = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
[4959]392    } else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
[4925]393        Value * const  marker_expr = compileExpression(sthru->getScanFrom());
394        Value * const  cc_expr = compileExpression(sthru->getScanThru());
395        Value * const  sum = mCarryManager->addCarryInCarryOut(sthru->getLocalCarryIndex(), marker_expr, cc_expr);
[4892]396        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
[5023]397    } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
398        // Currently InFile(x) => x;  a no-op
399        expr = compileExpression(e->getExpr());
[4959]400    } else if (const Count * c = dyn_cast<Count>(stmt)) {
[4925]401        Value * const to_count = compileExpression(c->getExpr());
402        expr = mCarryManager->popCount(to_count, c->getGlobalCountIndex());
[4959]403    } else if (const Lookahead * l = dyn_cast<Lookahead>(stmt)) {
404        PabloAST * const var = l->getExpr();
405        if (LLVM_UNLIKELY(!isa<Var>(var))) {
406            throw std::runtime_error("Lookahead input type must be a Var object");
407        }
[4974]408        unsigned index = 0;
409        for (; index < mPabloFunction->getNumOfParameters(); ++index) {
410            if (mPabloFunction->getParameter(index) == var) {
[4959]411                break;
412            }
413        }
[4974]414        if (LLVM_UNLIKELY(index >= mPabloFunction->getNumOfParameters())) {
[4959]415            throw std::runtime_error("Lookahead has an illegal Var operand");
416        }
[5000]417        const unsigned offset0 = (l->getAmount() / iBuilder->getBitBlockWidth());
418        const unsigned offset1 = ((l->getAmount() + iBuilder->getBitBlockWidth() - 1) / iBuilder->getBitBlockWidth());
[4959]419        const unsigned shift = (l->getAmount() % iBuilder->getBitBlockWidth());
[5000]420        Value * const v0 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset0));
421        Value * const v1 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset1));
[4974]422        if (LLVM_UNLIKELY((shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
423            expr = iBuilder->mvmd_dslli(8, v1, v0, (shift / 8));
424        } else if (LLVM_LIKELY(shift < DSSLI_FIELDWIDTH)) {
425            Value * ahead = iBuilder->mvmd_dslli(DSSLI_FIELDWIDTH, v1, v0, 1);
426            ahead = iBuilder->simd_slli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH - shift);
427            Value * value = iBuilder->simd_srli(DSSLI_FIELDWIDTH, v0, shift);
428            expr = iBuilder->simd_or(value, ahead);
429        } else {
430            Type  * const streamType = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
431            Value * b0 = iBuilder->CreateBitCast(v0, streamType);
432            Value * b1 = iBuilder->CreateBitCast(v1, streamType);
433            Value * result = iBuilder->CreateOr(iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - shift), iBuilder->CreateLShr(b0, shift));
434            expr = iBuilder->CreateBitCast(result, mBitBlockType);
435        }
[4925]436    } else {
437        std::string tmp;
438        llvm::raw_string_ostream msg(tmp);
439        msg << "Internal error: ";
440        PabloPrinter::print(stmt, msg);
441        msg << " is not a recognized statement in the Pablo compiler.";
442        throw std::runtime_error(msg.str());
[4720]443    }
[4643]444    mMarkerMap[stmt] = expr;
[4647]445    if (DumpTrace) {
[4974]446        iBuilder->CallPrintRegister(stmt->getName()->to_string(), expr);
[4647]447    }
448   
[4410]449}
450
451Value * PabloCompiler::compileExpression(const PabloAST * expr) {
[4959]452    if (LLVM_UNLIKELY(isa<Ones>(expr))) {
[4892]453        return iBuilder->allOnes();
[4959]454    } else if (LLVM_UNLIKELY(isa<Zeroes>(expr))) {
[4892]455        return iBuilder->allZeroes();
[4410]456    }
457    auto f = mMarkerMap.find(expr);
[4643]458    if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
[4567]459        std::string o;
460        llvm::raw_string_ostream str(o);
[4416]461        str << "\"";
462        PabloPrinter::print(expr, str);
463        str << "\" was used before definition!";
464        throw std::runtime_error(str.str());
[4359]465    }
[4959]466    Value * result = f->second;
467    if (LLVM_UNLIKELY(isa<Var>(expr))) {
468        assert (isa<GetElementPtrInst>(result));
469        result = iBuilder->CreateBlockAlignedLoad(result);
[4684]470    }
[4959]471    return result;
[4237]472}
[4268]473
474}
Note: See TracBrowser for help on using the repository browser.