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

Last change on this file since 4839 was 4839, checked in by cameron, 4 years ago

Parameterize PabloCompiler? on bitBlockType

File size: 21.8 KB
Line 
1/*
2 *  Copyright (c) 2014-15 International Characters.
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
7#include <pablo/pablo_compiler.h>
8#include <pablo/codegenstate.h>
9#include <pablo/carry_data.h>
10#include <pablo/carry_manager.h>
11#include <pablo/printer_pablos.h>
12#include <pablo/function.h>
13#include <re/re_name.h>
14#include <stdexcept>
15#include <include/simd-lib/bitblock.hpp>
16#include <sstream>
17#include <IDISA/idisa_builder.h>
18#include <llvm/IR/Verifier.h>
19#include <llvm/Pass.h>
20#include <llvm/PassManager.h>
21#include <llvm/ADT/SmallVector.h>
22#include <llvm/Analysis/Passes.h>
23#include <llvm/IR/BasicBlock.h>
24#include <llvm/IR/CallingConv.h>
25#include <llvm/IR/DataLayout.h>
26#include <llvm/IR/DerivedTypes.h>
27#include <llvm/IR/Function.h>
28#include <llvm/IR/GlobalVariable.h>
29#include <llvm/IR/InlineAsm.h>
30#include <llvm/IR/Instructions.h>
31#include <llvm/IR/LLVMContext.h>
32#include <llvm/IR/Module.h>
33#include <llvm/Support/FormattedStream.h>
34#include <llvm/Support/MathExtras.h>
35#include <llvm/Support/Casting.h>
36#include <llvm/Support/Compiler.h>
37#include <llvm/Support/Debug.h>
38#include <llvm/Support/TargetSelect.h>
39#include <llvm/Support/Host.h>
40#include <llvm/Transforms/Scalar.h>
41#include <llvm/IRReader/IRReader.h>
42#include <llvm/Bitcode/ReaderWriter.h>
43#include <llvm/Support/MemoryBuffer.h>
44#include <llvm/IR/IRBuilder.h>
45#include <llvm/Support/CommandLine.h>
46#include <llvm/ADT/Twine.h>
47#include <iostream>
48
49static cl::OptionCategory eIRDumpOptions("LLVM IR Dump Options", "These options control dumping of LLVM IR.");
50static cl::opt<bool> DumpGeneratedIR("dump-generated-IR", cl::init(false), cl::desc("Print LLVM IR generated by Pablo Compiler."), cl::cat(eIRDumpOptions));
51
52static cl::OptionCategory fTracingOptions("Run-time Tracing Options", "These options control execution traces.");
53static cl::opt<bool> DumpTrace("dump-trace", cl::init(false), cl::desc("Generate dynamic traces of executed assignments."), cl::cat(fTracingOptions));
54
55namespace pablo {
56
57PabloCompiler::PabloCompiler(Type * bitBlockType)
58: mMod(nullptr)
59, mBuilder(nullptr)
60, mCarryManager(nullptr)
61, mBitBlockType(bitBlockType)
62, iBuilder(mBitBlockType)
63, mInputType(nullptr)
64, mWhileDepth(0)
65, mIfDepth(0)
66, mFunction(nullptr)
67, mInputAddressPtr(nullptr)
68, mOutputAddressPtr(nullptr)
69, mMaxWhileDepth(0)
70, mPrintRegisterFunction(nullptr) {
71
72}
73
74PabloCompiler::~PabloCompiler() {
75}
76   
77
78void PabloCompiler::genPrintRegister(std::string regName, Value * bitblockValue) {
79    Constant * regNameData = ConstantDataArray::getString(mMod->getContext(), regName);
80    GlobalVariable *regStrVar = new GlobalVariable(*mMod,
81                                                   ArrayType::get(IntegerType::get(mMod->getContext(), 8), regName.length()+1),
82                                                   /*isConstant=*/ true,
83                                                   /*Linkage=*/ GlobalValue::PrivateLinkage,
84                                                   /*Initializer=*/ regNameData);
85    Value * regStrPtr = mBuilder->CreateGEP(regStrVar, std::vector<Value *>({mBuilder->getInt64(0), mBuilder->getInt32(0)}));
86    mBuilder->CreateCall(mPrintRegisterFunction, std::vector<Value *>({regStrPtr, bitblockValue}));
87}
88
89llvm::Function * PabloCompiler::compile(PabloFunction * function) {
90    Module * module = new Module("", getGlobalContext());
91   
92    auto func = compile(function, module);
93   
94    //Display the IR that has been generated by this module.
95    if (LLVM_UNLIKELY(DumpGeneratedIR)) {
96        module->dump();
97    }
98    //Create a verifier.  The verifier will print an error message if our module is malformed in any way.
99    verifyModule(*module, &dbgs());
100
101    return func;
102}
103
104llvm::Function * PabloCompiler::compile(PabloFunction * function, Module * module) {
105
106 
107    PabloBlock & mainScope = function->getEntryBlock();
108
109    mainScope.enumerateScopes(0);
110   
111    Examine(*function);
112
113    mMod = module;
114
115    mBuilder = new IRBuilder<>(mMod->getContext());
116
117    iBuilder.initialize(mMod, mBuilder);
118
119    mCarryManager = new CarryManager(mBuilder, &iBuilder);
120   
121    if (DumpTrace) DeclareDebugFunctions();
122       
123    GenerateFunction(*function);
124   
125    mBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
126
127    //The basis bits structure
128    for (unsigned i = 0; i != function->getNumOfParameters(); ++i) {
129        Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(i)};
130        Value * gep = mBuilder->CreateGEP(mInputAddressPtr, indices);
131        LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, iBuilder.getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
132        mMarkerMap[function->getParameter(i)] = basisBit;
133        if (DumpTrace) {
134            genPrintRegister(function->getParameter(i)->getName()->to_string(), basisBit);
135        }
136    }
137     
138    //Generate the IR instructions for the function.
139   
140    mCarryManager->initialize(mMod, &mainScope);
141   
142    compileBlock(mainScope);
143   
144    mCarryManager->ensureCarriesStoredLocal();
145    mCarryManager->leaveScope();
146   
147   
148    mCarryManager->generateBlockNoIncrement();
149
150    if (DumpTrace) {
151        genPrintRegister("mBlockNo", mBuilder->CreateAlignedLoad(mBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder.getBitBlockWidth()/8, false));
152    }
153   
154    // Write the output values out
155    for (unsigned i = 0; i != function->getNumOfResults(); ++i) {
156        assert (function->getResult(i));
157        SetOutputValue(mMarkerMap[function->getResult(i)], i);
158    }
159
160    //Terminate the block
161    ReturnInst::Create(mMod->getContext(), mBuilder->GetInsertBlock());
162   
163    // Clean up
164    delete mCarryManager; mCarryManager = nullptr;
165    delete mBuilder; mBuilder = nullptr;
166    mMod = nullptr; // don't delete this. It's either owned by the ExecutionEngine or the calling function.
167
168    return mFunction;
169}
170
171inline void PabloCompiler::GenerateFunction(PabloFunction & function) {
172    mInputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>(function.getNumOfParameters(), mBitBlockType)), 0);
173    Type * outputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>(function.getNumOfResults(), mBitBlockType)), 0);
174    FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>({mInputType, outputType}), false);
175
176
177    //Starts on process_block
178    SmallVector<AttributeSet, 3> Attrs;
179    Attrs.push_back(AttributeSet::get(mMod->getContext(), ~0U, std::vector<Attribute::AttrKind>({ Attribute::NoUnwind, Attribute::UWTable })));
180    Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, std::vector<Attribute::AttrKind>({ Attribute::ReadOnly, Attribute::NoCapture })));
181    Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, std::vector<Attribute::AttrKind>({ Attribute::ReadNone, Attribute::NoCapture })));
182    AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
183
184    // Create the function that will be generated.
185    mFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, function.getName()->value(), mMod);
186    mFunction->setCallingConv(CallingConv::C);
187    mFunction->setAttributes(AttrSet);
188
189    Function::arg_iterator args = mFunction->arg_begin();
190    mInputAddressPtr = args++;
191    mInputAddressPtr->setName("input");
192    mOutputAddressPtr = args++;
193    mOutputAddressPtr->setName("output");
194}
195
196inline void PabloCompiler::Examine(PabloFunction & function) {
197    mWhileDepth = 0;
198    mIfDepth = 0;
199    mMaxWhileDepth = 0;
200    Examine(function.getEntryBlock());
201    if (LLVM_UNLIKELY(mWhileDepth != 0 || mIfDepth != 0)) {
202        throw std::runtime_error("Malformed Pablo AST: Unbalanced If or While nesting depth!");
203    }
204}
205
206
207void PabloCompiler::Examine(PabloBlock & block) {
208    for (Statement * stmt : block) {
209        if (If * ifStatement = dyn_cast<If>(stmt)) {
210            Examine(ifStatement->getBody());
211        }
212        else if (While * whileStatement = dyn_cast<While>(stmt)) {
213            mMaxWhileDepth = std::max(mMaxWhileDepth, ++mWhileDepth);
214            Examine(whileStatement->getBody());
215            --mWhileDepth;
216        }
217    }
218}
219
220inline void PabloCompiler::DeclareDebugFunctions() {
221        //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
222        mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(mMod->getContext()), Type::getInt8PtrTy(mMod->getContext()), mBitBlockType, NULL);
223}
224
225void PabloCompiler::compileBlock(PabloBlock & block) {
226    mPabloBlock = & block;
227    for (const Statement * statement : block) {
228        compileStatement(statement);
229    }
230    mPabloBlock = block.getParent();
231}
232
233void PabloCompiler::compileIf(const If * ifStatement) {       
234    //
235    //  The If-ElseZero stmt:
236    //  if <predicate:expr> then <body:stmt>* elsezero <defined:var>* endif
237    //  If the value of the predicate is nonzero, then determine the values of variables
238    //  <var>* by executing the given statements.  Otherwise, the value of the
239    //  variables are all zero.  Requirements: (a) no variable that is defined within
240    //  the body of the if may be accessed outside unless it is explicitly
241    //  listed in the variable list, (b) every variable in the defined list receives
242    //  a value within the body, and (c) the logical consequence of executing
243    //  the statements in the event that the predicate is zero is that the
244    //  values of all defined variables indeed work out to be 0.
245    //
246    //  Simple Implementation with Phi nodes:  a phi node in the if exit block
247    //  is inserted for each variable in the defined variable list.  It receives
248    //  a zero value from the ifentry block and the defined value from the if
249    //  body.
250    //
251
252    BasicBlock * ifEntryBlock = mBuilder->GetInsertBlock();
253    BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunction, 0);
254    BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunction, 0);
255   
256    PabloBlock & ifBody = ifStatement -> getBody();
257   
258    Value * if_test_value = compileExpression(ifStatement->getCondition());
259   
260    mCarryManager->enterScope(&ifBody);
261    mBuilder->CreateCondBr(mCarryManager->generateBitBlockOrSummaryTest(if_test_value), ifBodyBlock, ifEndBlock);
262   
263    // Entry processing is complete, now handle the body of the if.
264    mBuilder->SetInsertPoint(ifBodyBlock);
265   
266    mCarryManager->initializeCarryDataAtIfEntry();
267    compileBlock(ifBody);
268    if (mCarryManager->blockHasCarries()) {
269        mCarryManager->generateCarryOutSummaryCodeIfNeeded();
270    }
271    BasicBlock * ifBodyFinalBlock = mBuilder->GetInsertBlock();
272    mCarryManager->ensureCarriesStoredLocal();
273    mBuilder->CreateBr(ifEndBlock);
274    //End Block
275    mBuilder->SetInsertPoint(ifEndBlock);
276    for (const PabloAST * node : ifStatement->getDefined()) {
277        const Assign * assign = cast<Assign>(node);
278        PHINode * phi = mBuilder->CreatePHI(mBitBlockType, 2, assign->getName()->value());
279        auto f = mMarkerMap.find(assign);
280        assert (f != mMarkerMap.end());
281        phi->addIncoming(iBuilder.allZeroes(), ifEntryBlock);
282        phi->addIncoming(f->second, ifBodyFinalBlock);
283        mMarkerMap[assign] = phi;
284    }
285    // Create the phi Node for the summary variable, if needed.
286    mCarryManager->buildCarryDataPhisAfterIfBody(ifEntryBlock, ifBodyFinalBlock);
287    mCarryManager->leaveScope();
288}
289
290void PabloCompiler::compileWhile(const While * whileStatement) {
291
292    PabloBlock & whileBody = whileStatement -> getBody();
293   
294    BasicBlock * whileEntryBlock = mBuilder->GetInsertBlock();
295    BasicBlock * whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunction, 0);
296    BasicBlock * whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunction, 0);
297
298    mCarryManager->enterScope(&whileBody);
299    mCarryManager->ensureCarriesLoadedRecursive();
300
301    const auto & nextNodes = whileStatement->getVariants();
302    std::vector<PHINode *> nextPhis;
303    nextPhis.reserve(nextNodes.size());
304
305    // On entry to the while structure, proceed to execute the first iteration
306    // of the loop body unconditionally.   The while condition is tested at the end of
307    // the loop.
308
309    mBuilder->CreateBr(whileBodyBlock);
310    mBuilder->SetInsertPoint(whileBodyBlock);
311
312    //
313    // There are 3 sets of Phi nodes for the while loop.
314    // (1) Carry-ins: (a) incoming carry data first iterations, (b) zero thereafter
315    // (2) Carry-out accumulators: (a) zero first iteration, (b) |= carry-out of each iteration
316    // (3) Next nodes: (a) values set up before loop, (b) modified values calculated in loop.
317
318    mCarryManager->initializeCarryDataPhisAtWhileEntry(whileEntryBlock);
319
320    // for any Next nodes in the loop body, initialize to (a) pre-loop value.
321    for (const Next * n : nextNodes) {
322        PHINode * phi = mBuilder->CreatePHI(mBitBlockType, 2, n->getName()->value());
323        auto f = mMarkerMap.find(n->getInitial());
324        assert (f != mMarkerMap.end());
325        phi->addIncoming(f->second, whileEntryBlock);
326        mMarkerMap[n->getInitial()] = phi;
327        nextPhis.push_back(phi);
328    }
329
330    //
331    // Now compile the loop body proper.  Carry-out accumulated values
332    // and iterated values of Next nodes will be computed.
333    ++mWhileDepth;
334    compileBlock(whileBody);
335
336    BasicBlock * whileBodyFinalBlock = mBuilder->GetInsertBlock();
337
338    if (mCarryManager->blockHasCarries()) {
339        mCarryManager->generateCarryOutSummaryCodeIfNeeded();
340    }
341    mCarryManager->extendCarryDataPhisAtWhileBodyFinalBlock(whileBodyFinalBlock);
342
343    // Terminate the while loop body with a conditional branch back.
344    mBuilder->CreateCondBr(iBuilder.bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
345
346    // and for any Next nodes in the loop body
347    for (unsigned i = 0; i < nextNodes.size(); i++) {
348        const Next * n = nextNodes[i];
349        auto f = mMarkerMap.find(n->getExpr());
350        if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
351            throw std::runtime_error("Next node expression was not compiled!");
352        }
353        nextPhis[i]->addIncoming(f->second, whileBodyFinalBlock);
354    }
355
356    mBuilder->SetInsertPoint(whileEndBlock);
357    --mWhileDepth;
358
359    mCarryManager->ensureCarriesStoredRecursive();
360    mCarryManager->leaveScope();
361}
362
363
364void PabloCompiler::compileStatement(const Statement * stmt) {
365    Value * expr = nullptr;
366    if (const Assign * assign = dyn_cast<const Assign>(stmt)) {
367        expr = compileExpression(assign->getExpression());
368    }
369    else if (const Next * next = dyn_cast<const Next>(stmt)) {
370        expr = compileExpression(next->getExpr());
371    }
372    else if (const If * ifStatement = dyn_cast<const If>(stmt)) {
373        compileIf(ifStatement);
374        return;
375    }
376    else if (const While * whileStatement = dyn_cast<const While>(stmt)) {
377        compileWhile(whileStatement);
378        return;
379    }
380    else if (const Call* call = dyn_cast<Call>(stmt)) {
381        //Call the callee once and store the result in the marker map.
382        if (mMarkerMap.count(call) != 0) {
383            return;
384        }
385
386        const Prototype * proto = call->getPrototype();
387        const String * callee = proto->getName();
388
389        Type * inputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfParameters(), mBitBlockType});
390        Type * outputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfResults(), mBitBlockType});
391        FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{PointerType::get(inputType, 0), PointerType::get(outputType, 0)}, false);
392
393        //Starts on process_block
394        SmallVector<AttributeSet, 3> Attrs;
395        Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, std::vector<Attribute::AttrKind>({ Attribute::ReadOnly, Attribute::NoCapture })));
396        Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, std::vector<Attribute::AttrKind>({ Attribute::ReadNone, Attribute::NoCapture })));
397        AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
398
399        Function * externalFunction = cast<Function>(mMod->getOrInsertFunction(callee->value(), functionType, AttrSet));
400        if (LLVM_UNLIKELY(externalFunction == nullptr)) {
401            throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
402        }
403        externalFunction->setCallingConv(llvm::CallingConv::C);
404
405
406        AllocaInst * outputStruct = mBuilder->CreateAlloca(outputType);
407        mBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
408        Value * outputPtr = mBuilder->CreateGEP(outputStruct, std::vector<Value *>({ mBuilder->getInt32(0), mBuilder->getInt32(0) }));
409        expr = mBuilder->CreateAlignedLoad(outputPtr, iBuilder.getBitBlockWidth() / 8, false);
410    }
411    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
412        expr = iBuilder.simd_and(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()));
413    }
414    else if (const Or * pablo_or = dyn_cast<Or>(stmt)) {
415        expr = iBuilder.simd_or(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()));
416    }
417    else if (const Xor * pablo_xor = dyn_cast<Xor>(stmt)) {
418        expr = iBuilder.simd_xor(compileExpression(pablo_xor->getExpr1()), compileExpression(pablo_xor->getExpr2()));
419    }
420    else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
421        Value* ifMask = compileExpression(sel->getCondition());
422        Value* ifTrue = iBuilder.simd_and(ifMask, compileExpression(sel->getTrueExpr()));
423        Value* ifFalse = iBuilder.simd_and(iBuilder.simd_not(ifMask), compileExpression(sel->getFalseExpr()));
424        expr = iBuilder.simd_or(ifTrue, ifFalse);
425    }
426    else if (const Not * pablo_not = dyn_cast<Not>(stmt)) {
427        expr = iBuilder.simd_not(compileExpression(pablo_not->getExpr()));
428    }
429    else if (const Advance * adv = dyn_cast<Advance>(stmt)) {
430        Value* strm_value = compileExpression(adv->getExpr());
431        int shift = adv->getAdvanceAmount();
432        unsigned advance_index = adv->getLocalAdvanceIndex();
433        expr = mCarryManager->advanceCarryInCarryOut(advance_index, shift, strm_value);
434    }
435    else if (const Mod64Advance * adv = dyn_cast<Mod64Advance>(stmt)) {
436        Value* strm_value = compileExpression(adv->getExpr());
437        int shift = adv->getAdvanceAmount();
438        expr = iBuilder.simd_slli(64, strm_value, shift);
439    }
440    else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
441        Value * marker = compileExpression(mstar->getMarker());
442        Value * cc = compileExpression(mstar->getCharClass());
443        Value * marker_and_cc = iBuilder.simd_and(marker, cc);
444        unsigned carry_index = mstar->getLocalCarryIndex();
445        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_and_cc, cc);
446        expr = iBuilder.simd_or(iBuilder.simd_xor(sum, cc), marker);
447    }
448    else if (const Mod64MatchStar * mstar = dyn_cast<Mod64MatchStar>(stmt)) {
449        Value * marker = compileExpression(mstar->getMarker());
450        Value * cc = compileExpression(mstar->getCharClass());
451        Value * marker_and_cc = iBuilder.simd_and(marker, cc);
452        Value * sum = iBuilder.simd_add(64, marker_and_cc, cc);
453        expr = iBuilder.simd_or(iBuilder.simd_xor(sum, cc), marker);
454    }
455    else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
456        Value * marker_expr = compileExpression(sthru->getScanFrom());
457        Value * cc_expr = compileExpression(sthru->getScanThru());
458        unsigned carry_index = sthru->getLocalCarryIndex();
459        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_expr, cc_expr);
460        expr = iBuilder.simd_and(sum, iBuilder.simd_not(cc_expr));
461    }
462    else if (const Mod64ScanThru * sthru = dyn_cast<Mod64ScanThru>(stmt)) {
463        Value * marker_expr = compileExpression(sthru->getScanFrom());
464        Value * cc_expr = compileExpression(sthru->getScanThru());
465        Value * sum = iBuilder.simd_add(64, marker_expr, cc_expr);
466        expr = iBuilder.simd_and(sum, iBuilder.simd_not(cc_expr));
467    }
468    else if (const Count * c = dyn_cast<Count>(stmt)) {
469        unsigned count_index = c->getGlobalCountIndex();
470        Value * to_count = compileExpression(c->getExpr());
471        expr = mCarryManager->popCount(to_count, count_index);
472    }
473    else {
474        llvm::raw_os_ostream cerr(std::cerr);
475        PabloPrinter::print(stmt, cerr);
476        throw std::runtime_error("Unrecognized Pablo Statement! can't compile.");
477    }
478    mMarkerMap[stmt] = expr;
479    if (DumpTrace) {
480        genPrintRegister(stmt->getName()->to_string(), expr);
481    }
482   
483}
484
485Value * PabloCompiler::compileExpression(const PabloAST * expr) {
486    if (isa<Ones>(expr)) {
487        return iBuilder.allOnes();
488    }
489    else if (isa<Zeroes>(expr)) {
490        return iBuilder.allZeroes();
491    }
492    auto f = mMarkerMap.find(expr);
493    if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
494        std::string o;
495        llvm::raw_string_ostream str(o);
496        str << "\"";
497        PabloPrinter::print(expr, str);
498        str << "\" was used before definition!";
499        throw std::runtime_error(str.str());
500    }
501    return f->second;
502}
503
504void PabloCompiler::SetOutputValue(Value * marker, const unsigned index) {
505    if (LLVM_UNLIKELY(marker == nullptr)) {
506        throw std::runtime_error("Cannot set result " + std::to_string(index) + " to Null");
507    }
508    if (LLVM_UNLIKELY(marker->getType()->isPointerTy())) {
509        marker = mBuilder->CreateAlignedLoad(marker, iBuilder.getBitBlockWidth()/8, false);
510    }
511    Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(index)};
512    Value* gep = mBuilder->CreateGEP(mOutputAddressPtr, indices);
513    if (marker->getType() != mBitBlockType) {
514        marker = mBuilder->CreateBitCast(marker, mBitBlockType);
515    }
516    mBuilder->CreateAlignedStore(marker, gep, iBuilder.getBitBlockWidth()/8, false);
517}
518
519}
Note: See TracBrowser for help on using the repository browser.