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

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

Add IRBuilder functionality to IDISA_Builder; eliminate separate mBuilder

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/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, mCarryManager(nullptr)
61, mBitBlockType(bitBlockType)
62, iBuilder(nullptr)
63, mInputType(nullptr)
64, mWhileDepth(0)
65, mIfDepth(0)
66, mFunction(nullptr)
67, mInputAddressPtr(nullptr)
68, mOutputAddressPtr(nullptr)
69, mMaxWhileDepth(0) {
70   
71   
72
73}
74
75PabloCompiler::~PabloCompiler() {
76}
77   
78
79llvm::Function * PabloCompiler::compile(PabloFunction * function) {
80    Module * module = new Module("", getGlobalContext());
81   
82    auto func = compile(function, module);
83   
84    //Display the IR that has been generated by this module.
85    if (LLVM_UNLIKELY(DumpGeneratedIR)) {
86        module->dump();
87    }
88    //Create a verifier.  The verifier will print an error message if our module is malformed in any way.
89    verifyModule(*module, &dbgs());
90
91    return func;
92}
93
94// Dynamic AVX2 confirmation
95#if (BLOCK_SIZE == 256)
96#define ISPC_LLVM_VERSION ISPC_LLVM_3_6
97#include <ispc.cpp>
98#endif
99   
100llvm::Function * PabloCompiler::compile(PabloFunction * function, Module * module) {
101
102 
103    PabloBlock * const mainScope = function->getEntryBlock();
104
105    mainScope->enumerateScopes(0);
106   
107    Examine(*function);
108
109    mMod = module;
110
111#if (BLOCK_SIZE == 256)
112    if ((strncmp(lGetSystemISA(), "avx2", 4) == 0)) {
113        iBuilder = new IDISA::IDISA_AVX2_Builder(mMod, mBitBlockType);
114        //std::cerr << "IDISA_AVX2_Builder selected\n";
115    }
116    else{
117        iBuilder = new IDISA::IDISA_Builder(mMod, mBitBlockType);
118        //std::cerr << "Generic IDISA_Builder selected\n";
119    }
120#else   
121    iBuilder = new IDISA::IDISA_Builder(mMod, mBitBlockType);
122#endif
123
124    mCarryManager = new CarryManager(iBuilder);
125   
126    GenerateFunction(*function);
127   
128    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
129
130    //The basis bits structure
131    for (unsigned i = 0; i != function->getNumOfParameters(); ++i) {
132        Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(i)};
133        Value * gep = iBuilder->CreateGEP(mInputAddressPtr, indices);
134        LoadInst * basisBit = iBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
135        mMarkerMap[function->getParameter(i)] = basisBit;
136        if (DumpTrace) {
137            iBuilder->genPrintRegister(function->getParameter(i)->getName()->to_string(), basisBit);
138        }
139    }
140     
141    //Generate the IR instructions for the function.
142   
143    mCarryManager->initialize(mMod, mainScope);
144   
145    compileBlock(mainScope);
146   
147    mCarryManager->ensureCarriesStoredLocal();
148    mCarryManager->leaveScope();
149   
150   
151    mCarryManager->generateBlockNoIncrement();
152
153    if (DumpTrace) {
154        iBuilder->genPrintRegister("mBlockNo", iBuilder->CreateAlignedLoad(iBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
155    }
156   
157    // Write the output values out
158    for (unsigned i = 0; i != function->getNumOfResults(); ++i) {
159        assert (function->getResult(i));
160        SetOutputValue(mMarkerMap[function->getResult(i)], i);
161    }
162
163    //Terminate the block
164    ReturnInst::Create(mMod->getContext(), iBuilder->GetInsertBlock());
165   
166    // Clean up
167    delete mCarryManager; mCarryManager = nullptr;
168    delete iBuilder; iBuilder = nullptr;
169    delete iBuilder; iBuilder = nullptr;
170    mMod = nullptr; // don't delete this. It's either owned by the ExecutionEngine or the calling function.
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    if (mCarryManager->blockHasCarries()) {
268        mCarryManager->generateCarryOutSummaryCodeIfNeeded();
269    }
270    BasicBlock * ifBodyFinalBlock = iBuilder->GetInsertBlock();
271    mCarryManager->ensureCarriesStoredLocal();
272    iBuilder->CreateBr(ifEndBlock);
273    //End Block
274    iBuilder->SetInsertPoint(ifEndBlock);
275    for (const PabloAST * node : ifStatement->getDefined()) {
276        const Assign * assign = cast<Assign>(node);
277        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, assign->getName()->value());
278        auto f = mMarkerMap.find(assign);
279        assert (f != mMarkerMap.end());
280        phi->addIncoming(iBuilder->allZeroes(), ifEntryBlock);
281        phi->addIncoming(f->second, ifBodyFinalBlock);
282        mMarkerMap[assign] = phi;
283    }
284    // Create the phi Node for the summary variable, if needed.
285    mCarryManager->buildCarryDataPhisAfterIfBody(ifEntryBlock, ifBodyFinalBlock);
286    mCarryManager->leaveScope();
287}
288
289void PabloCompiler::compileWhile(const While * whileStatement) {
290
291    PabloBlock * const whileBody = whileStatement->getBody();
292   
293    BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
294    BasicBlock * whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunction, 0);
295    BasicBlock * whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunction, 0);
296
297    mCarryManager->enterScope(whileBody);
298    mCarryManager->ensureCarriesLoadedRecursive();
299
300    const auto & nextNodes = whileStatement->getVariants();
301    std::vector<PHINode *> nextPhis;
302    nextPhis.reserve(nextNodes.size());
303
304    // On entry to the while structure, proceed to execute the first iteration
305    // of the loop body unconditionally.   The while condition is tested at the end of
306    // the loop.
307
308    iBuilder->CreateBr(whileBodyBlock);
309    iBuilder->SetInsertPoint(whileBodyBlock);
310
311    //
312    // There are 3 sets of Phi nodes for the while loop.
313    // (1) Carry-ins: (a) incoming carry data first iterations, (b) zero thereafter
314    // (2) Carry-out accumulators: (a) zero first iteration, (b) |= carry-out of each iteration
315    // (3) Next nodes: (a) values set up before loop, (b) modified values calculated in loop.
316
317    mCarryManager->initializeCarryDataPhisAtWhileEntry(whileEntryBlock);
318
319    // for any Next nodes in the loop body, initialize to (a) pre-loop value.
320    for (const Next * n : nextNodes) {
321        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, n->getName()->value());
322        auto f = mMarkerMap.find(n->getInitial());
323        assert (f != mMarkerMap.end());
324        phi->addIncoming(f->second, whileEntryBlock);
325        mMarkerMap[n->getInitial()] = phi;
326        nextPhis.push_back(phi);
327    }
328
329    //
330    // Now compile the loop body proper.  Carry-out accumulated values
331    // and iterated values of Next nodes will be computed.
332    ++mWhileDepth;
333    compileBlock(whileBody);
334
335    BasicBlock * whileBodyFinalBlock = iBuilder->GetInsertBlock();
336
337    if (mCarryManager->blockHasCarries()) {
338        mCarryManager->generateCarryOutSummaryCodeIfNeeded();
339    }
340    mCarryManager->extendCarryDataPhisAtWhileBodyFinalBlock(whileBodyFinalBlock);
341
342    // Terminate the while loop body with a conditional branch back.
343    iBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
344
345    // and for any Next nodes in the loop body
346    for (unsigned i = 0; i < nextNodes.size(); i++) {
347        const Next * n = nextNodes[i];
348        auto f = mMarkerMap.find(n->getExpr());
349        if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
350            throw std::runtime_error("Next node expression was not compiled!");
351        }
352        nextPhis[i]->addIncoming(f->second, whileBodyFinalBlock);
353    }
354
355    iBuilder->SetInsertPoint(whileEndBlock);
356    --mWhileDepth;
357
358    mCarryManager->ensureCarriesStoredRecursive();
359    mCarryManager->leaveScope();
360}
361
362
363void PabloCompiler::compileStatement(const Statement * stmt) {
364    Value * expr = nullptr;
365    if (const Assign * assign = dyn_cast<const Assign>(stmt)) {
366        expr = compileExpression(assign->getExpression());
367    }
368    else if (const Next * next = dyn_cast<const Next>(stmt)) {
369        expr = compileExpression(next->getExpr());
370    }
371    else if (const If * ifStatement = dyn_cast<const If>(stmt)) {
372        compileIf(ifStatement);
373        return;
374    }
375    else if (const While * whileStatement = dyn_cast<const While>(stmt)) {
376        compileWhile(whileStatement);
377        return;
378    }
379    else if (const Call* call = dyn_cast<Call>(stmt)) {
380        //Call the callee once and store the result in the marker map.
381        if (mMarkerMap.count(call) != 0) {
382            return;
383        }
384
385        const Prototype * proto = call->getPrototype();
386        const String * callee = proto->getName();
387
388        Type * inputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfParameters(), mBitBlockType});
389        Type * outputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfResults(), mBitBlockType});
390        FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{PointerType::get(inputType, 0), PointerType::get(outputType, 0)}, false);
391
392        //Starts on process_block
393        SmallVector<AttributeSet, 3> Attrs;
394        Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, std::vector<Attribute::AttrKind>({ Attribute::ReadOnly, Attribute::NoCapture })));
395        Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, std::vector<Attribute::AttrKind>({ Attribute::ReadNone, Attribute::NoCapture })));
396        AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
397
398        Function * externalFunction = cast<Function>(mMod->getOrInsertFunction(callee->value(), functionType, AttrSet));
399        if (LLVM_UNLIKELY(externalFunction == nullptr)) {
400            throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
401        }
402        externalFunction->setCallingConv(llvm::CallingConv::C);
403
404
405        AllocaInst * outputStruct = iBuilder->CreateAlloca(outputType);
406        iBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
407        Value * outputPtr = iBuilder->CreateGEP(outputStruct, std::vector<Value *>({ iBuilder->getInt32(0), iBuilder->getInt32(0) }));
408        expr = iBuilder->CreateAlignedLoad(outputPtr, iBuilder->getBitBlockWidth() / 8, false);
409    }
410    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
411        expr = iBuilder->simd_and(compileExpression(pablo_and->getOperand(0)), compileExpression(pablo_and->getOperand(1)));
412    }
413    else if (const Or * pablo_or = dyn_cast<Or>(stmt)) {
414        expr = iBuilder->simd_or(compileExpression(pablo_or->getOperand(0)), compileExpression(pablo_or->getOperand(1)));
415    }
416    else if (const Xor * pablo_xor = dyn_cast<Xor>(stmt)) {
417        expr = iBuilder->simd_xor(compileExpression(pablo_xor->getOperand(0)), compileExpression(pablo_xor->getOperand(1)));
418    }
419    else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
420        Value* ifMask = compileExpression(sel->getCondition());
421        Value* ifTrue = iBuilder->simd_and(ifMask, compileExpression(sel->getTrueExpr()));
422        Value* ifFalse = iBuilder->simd_and(iBuilder->simd_not(ifMask), compileExpression(sel->getFalseExpr()));
423        expr = iBuilder->simd_or(ifTrue, ifFalse);
424    }
425    else if (const Not * pablo_not = dyn_cast<Not>(stmt)) {
426        expr = iBuilder->simd_not(compileExpression(pablo_not->getExpr()));
427    }
428    else if (const Advance * adv = dyn_cast<Advance>(stmt)) {
429        Value* strm_value = compileExpression(adv->getExpr());
430        int shift = adv->getAdvanceAmount();
431        unsigned advance_index = adv->getLocalAdvanceIndex();
432        expr = mCarryManager->advanceCarryInCarryOut(advance_index, shift, strm_value);
433    }
434    else if (const Mod64Advance * adv = dyn_cast<Mod64Advance>(stmt)) {
435        Value* strm_value = compileExpression(adv->getExpr());
436        int shift = adv->getAdvanceAmount();
437        expr = iBuilder->simd_slli(64, strm_value, shift);
438    }
439    else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
440        Value * marker = compileExpression(mstar->getMarker());
441        Value * cc = compileExpression(mstar->getCharClass());
442        Value * marker_and_cc = iBuilder->simd_and(marker, cc);
443        unsigned carry_index = mstar->getLocalCarryIndex();
444        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_and_cc, cc);
445        expr = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
446    }
447    else if (const Mod64MatchStar * mstar = dyn_cast<Mod64MatchStar>(stmt)) {
448        Value * marker = compileExpression(mstar->getMarker());
449        Value * cc = compileExpression(mstar->getCharClass());
450        Value * marker_and_cc = iBuilder->simd_and(marker, cc);
451        Value * sum = iBuilder->simd_add(64, marker_and_cc, cc);
452        expr = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
453    }
454    else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
455        Value * marker_expr = compileExpression(sthru->getScanFrom());
456        Value * cc_expr = compileExpression(sthru->getScanThru());
457        unsigned carry_index = sthru->getLocalCarryIndex();
458        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_expr, cc_expr);
459        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
460    }
461    else if (const Mod64ScanThru * sthru = dyn_cast<Mod64ScanThru>(stmt)) {
462        Value * marker_expr = compileExpression(sthru->getScanFrom());
463        Value * cc_expr = compileExpression(sthru->getScanThru());
464        Value * sum = iBuilder->simd_add(64, marker_expr, cc_expr);
465        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
466    }
467    else if (const Count * c = dyn_cast<Count>(stmt)) {
468        unsigned count_index = c->getGlobalCountIndex();
469        Value * to_count = compileExpression(c->getExpr());
470        expr = mCarryManager->popCount(to_count, count_index);
471    }
472    else {
473        llvm::raw_os_ostream cerr(std::cerr);
474        PabloPrinter::print(stmt, cerr);
475        throw std::runtime_error("Unrecognized Pablo Statement! can't compile.");
476    }
477    mMarkerMap[stmt] = expr;
478    if (DumpTrace) {
479        iBuilder->genPrintRegister(stmt->getName()->to_string(), expr);
480    }
481   
482}
483
484Value * PabloCompiler::compileExpression(const PabloAST * expr) {
485    if (isa<Ones>(expr)) {
486        return iBuilder->allOnes();
487    }
488    else if (isa<Zeroes>(expr)) {
489        return iBuilder->allZeroes();
490    }
491    auto f = mMarkerMap.find(expr);
492    if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
493        std::string o;
494        llvm::raw_string_ostream str(o);
495        str << "\"";
496        PabloPrinter::print(expr, str);
497        str << "\" was used before definition!";
498        throw std::runtime_error(str.str());
499    }
500    return f->second;
501}
502
503void PabloCompiler::SetOutputValue(Value * marker, const unsigned index) {
504    if (LLVM_UNLIKELY(marker == nullptr)) {
505        throw std::runtime_error("Cannot set result " + std::to_string(index) + " to Null");
506    }
507    if (LLVM_UNLIKELY(marker->getType()->isPointerTy())) {
508        marker = iBuilder->CreateAlignedLoad(marker, iBuilder->getBitBlockWidth()/8, false);
509    }
510    Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(index)};
511    Value* gep = iBuilder->CreateGEP(mOutputAddressPtr, indices);
512    if (marker->getType() != mBitBlockType) {
513        marker = iBuilder->CreateBitCast(marker, mBitBlockType);
514    }
515    iBuilder->CreateAlignedStore(marker, gep, iBuilder->getBitBlockWidth()/8, false);
516}
517
518}
Note: See TracBrowser for help on using the repository browser.