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

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

Move AVX2 specific IDISA function implementations into subclassed builder

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