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

Last change on this file since 4922 was 4922, checked in by nmedfort, 3 years ago

Incorporated a few common case boolean optimizations in the Simplifier.

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