source: icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp @ 4687

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

Carry Manager restructuring and bug fixes

File size: 19.7 KB
Line 
1/*
2 *  Copyright (c) 2015 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
8#include <include/simd-lib/bitblock.hpp>
9#include <stdexcept>
10#include <pablo/carry_data.h>
11#include <pablo/codegenstate.h>
12#include <pablo/carry_manager.h>
13#include <pablo/pabloAST.h>
14#include <iostream>
15
16namespace pablo {
17 
18    unsigned doScopeCount(PabloBlock * pb) {
19        unsigned count = 1;
20       
21        for (Statement * stmt : *pb) {
22            if (If * ifStatement = dyn_cast<If>(stmt)) {
23                count += doScopeCount(&ifStatement->getBody());
24            }
25            else if (While * whileStatement = dyn_cast<While>(stmt)) {
26                count += doScopeCount(&whileStatement->getBody());
27            }
28        }
29        return count;
30       
31    }
32
33unsigned CarryManager::initialize(PabloBlock * pb, Value * carryPtr) {
34    mPabloRoot = pb;
35    mCurrentScope = pb;
36    mCurrentScopeIndex = 0;
37   
38    mCarryDataPtr = carryPtr;
39    unsigned scopeCount = doScopeCount(pb);
40    mCarryInfoVector.resize(scopeCount);
41   
42    unsigned totalCarryDataBits = enumerate(pb, 0, 0, 0);
43   
44    mTotalCarryDataBitBlocks = (totalCarryDataBits + BLOCK_SIZE - 1)/BLOCK_SIZE + 1; // One extra element for the block no.
45    mBlockNoPtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks - 1)), Type::getInt64PtrTy(mBuilder->getContext()));
46    mBlockNo = mBuilder->CreateLoad(mBlockNoPtr);
47    mCarryInVector.resize(mTotalCarryDataBitBlocks);
48    mCarryInPhis.resize(mTotalCarryDataBitBlocks);
49    mCarryOutAccumPhis.resize(mTotalCarryDataBitBlocks);
50    mCarryOutVector.resize(mTotalCarryDataBitBlocks);
51   
52    return mTotalCarryDataBitBlocks;
53}
54   
55void CarryManager::generateBlockNoIncrement() {
56    mBuilder->CreateStore(mBuilder->CreateAdd(mBlockNo, mBuilder->getInt64(1)), mBlockNoPtr);
57}
58
59Value * CarryManager::getBlockNoPtr() {
60    return mBlockNoPtr;
61}
62
63unsigned CarryManager::enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth, unsigned nestedframePosition) {
64    llvm::raw_os_ostream cerr(std::cerr);
65    unsigned idx = blk->getScopeIndex();
66    PabloBlockCarryData * cd = new PabloBlockCarryData(blk);
67    mCarryInfoVector[idx] = cd;
68
69    cd->setIfDepth(ifDepth);
70    cd->setWhileDepth(whileDepth);
71    cd->setFramePosition(nestedframePosition);
72    unsigned nestedOffset = cd->nested.frameOffsetinBits;
73 
74    for (Statement * stmt : *blk) {
75        if (If * ifStatement = dyn_cast<If>(stmt)) {
76            const unsigned ifCarryDataBits = enumerate(&ifStatement->getBody(), ifDepth+1, whileDepth, nestedOffset);
77            PabloBlockCarryData * nestedBlockData = mCarryInfoVector[ifStatement->getBody().getScopeIndex()];
78#ifdef PACKING
79            EnsurePackHasSpace(nestedOffset, ifCarryDataBits);
80#endif
81            nestedOffset += ifCarryDataBits;
82            if (cd->maxNestingDepth <= nestedBlockData->maxNestingDepth) cd->maxNestingDepth = nestedBlockData->maxNestingDepth + 1;
83            cd->nested.entries++;
84        }
85        else if (While * whileStatement = dyn_cast<While>(stmt)) {
86            const unsigned whileCarryDataBits = enumerate(&whileStatement->getBody(), ifDepth, whileDepth+1, nestedOffset);
87            PabloBlockCarryData * nestedBlockData = mCarryInfoVector[whileStatement->getBody().getScopeIndex()];
88            //if (whileStatement->isMultiCarry()) whileCarryDataBits *= whileStatement->getMaxIterations();
89#ifdef PACKING
90            EnsurePackHasSpace(nestedOffset, whileCarryDataBits);
91#endif
92            nestedOffset += whileCarryDataBits;
93            if (cd->maxNestingDepth <= nestedBlockData->maxNestingDepth) cd->maxNestingDepth = nestedBlockData->maxNestingDepth + 1;
94            cd->nested.entries++;
95        }
96    }
97   
98    cd->scopeCarryDataBits = nestedOffset;
99   
100    if (cd->explicitSummaryRequired()) {
101        // Need extra space for the summary variable, always the last
102        // entry within an if block.
103        cd->scopeCarryDataBits = alignCeiling(cd->scopeCarryDataBits, PACK_SIZE);
104        cd->summary.frameOffsetinBits = cd->scopeCarryDataBits;
105        cd->summary.allocatedBits = PACK_SIZE;
106        cd->scopeCarryDataBits += PACK_SIZE;
107    }
108    else {
109        cd->summary.frameOffsetinBits = 0;
110        cd->summary.allocatedBits = cd->scopeCarryDataBits;
111    }
112#ifndef NDEBUG
113    cd->dumpCarryData(cerr);
114#endif
115    return cd->scopeCarryDataBits;
116}
117
118
119/* Entering and leaving blocks. */
120
121void CarryManager::enterScope(PabloBlock * blk) {
122   
123    mCurrentScope = blk;
124    mCarryInfo = mCarryInfoVector[blk->getScopeIndex()];
125    mCurrentScopeIndex += mCarryInfo->getBlockCarryDataIndex();
126    //std::cerr << "enterScope:  mCurrentScopeIndex = " << mCurrentScopeIndex << std::endl;
127}
128
129void CarryManager::leaveScope() {
130    mCurrentScopeIndex -= mCarryInfo->getBlockCarryDataIndex();
131    mCurrentScope = mCurrentScope->getParent();
132    mCarryInfo = mCarryInfoVector[mCurrentScope->getScopeIndex()];
133    //std::cerr << "leaveScope:  mCurrentScopeIndex = " << mCurrentScopeIndex << std::endl;
134}
135
136    /* Methods for getting and setting individual carry values. */
137   
138//#define LOAD_STORE_ON_BLOCK_ENTRY_EXIT   
139Value * CarryManager::getCarryOpCarryIn(int localIndex) {
140    unsigned cd_index = mCurrentScopeIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
141#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
142    if (mCarryInfo->getWhileDepth() == 0) {
143       Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd_index));
144       mCarryInVector[cd_index] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
145    }
146#endif
147    return mCarryInVector[cd_index];
148}
149
150void CarryManager::setCarryOpCarryOut(unsigned localIndex, Value * carry_out) {
151    unsigned cd_index = mCurrentScopeIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
152    mCarryOutVector[cd_index] = carry_out;
153#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
154    if (mCarryInfo->getWhileDepth() == 0) {
155       Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd_index));
156       mBuilder->CreateAlignedStore(carry_out, packPtr, BLOCK_SIZE/8);
157    }
158#endif
159}
160
161   
162Value * CarryManager::advanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm) {
163    if (shift_amount == 1) {
164        return unitAdvanceCarryInCarryOut(localIndex, strm);
165    }
166    else if (shift_amount < LongAdvanceBase) {
167        return shortAdvanceCarryInCarryOut(localIndex, shift_amount, strm);
168    }
169    else {
170        return longAdvanceCarryInCarryOut(localIndex, shift_amount, strm);
171    }
172}
173
174Value * CarryManager::unitAdvanceCarryInCarryOut(int localIndex, Value * strm) {
175    unsigned carryDataIndex = mCurrentScopeIndex + mCarryInfo->unitAdvanceCarryDataOffset(localIndex);
176    mCarryOutVector[carryDataIndex] = strm; 
177#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
178    if (mCarryInfo->getWhileDepth() == 0) {
179        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
180        mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
181        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
182    }
183#endif
184    Value * carry_in = mCarryInVector[carryDataIndex];
185    Value* result_value;
186   
187#if (BLOCK_SIZE == 128) && !defined(USE_LONG_INTEGER_SHIFT)
188    Value * ahead64 = iBuilder->mvmd_dslli(64, carry_in, strm, 1);
189    result_value = mBuilder->CreateOr(iBuilder->simd_srli(64, ahead64, 63), iBuilder->simd_slli(64, strm, 1));
190#else
191    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
192    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
193    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - 1), "advance");
194    result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
195   
196#endif
197    return result_value;
198}
199
200Value * CarryManager::shortAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm) {
201    unsigned carryDataIndex = mCurrentScopeIndex + mCarryInfo->shortAdvanceCarryDataOffset(localIndex);
202    mCarryOutVector[carryDataIndex] = strm; 
203#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
204    if (mCarryInfo->getWhileDepth() == 0) {
205        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
206        mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
207        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
208    }
209#endif
210    Value * carry_in = mCarryInVector[carryDataIndex];
211    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
212    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
213    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - shift_amount), "advance");
214    return mBuilder->CreateBitCast(adv_longint, mBitBlockType);
215}
216   
217
218/*  currently defined in carry_data.h
219 
220 static unsigned power2ceil (unsigned v) {
221 unsigned ceil = 1;
222 while (ceil < v) ceil *= 2;
223 return ceil;
224 }
225 
226 unsigned longAdvanceEntries(unsigned shift_amount) const {
227 return (shift_amount + BLOCK_SIZE - 1)/BLOCK_SIZE;
228 }
229 
230 unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
231 return power2ceil(longAdvanceEntries(shift_amount));
232 }
233 */
234
235   
236Value * CarryManager::longAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * carry_out) {
237    unsigned carryDataIndex = mCurrentScopeIndex + mCarryInfo->longAdvanceCarryDataOffset(localIndex);
238    Value * advBaseIndex = mBuilder->getInt64(carryDataIndex);
239    if (shift_amount <= BLOCK_SIZE) {
240        // special case using a single buffer entry and the carry_out value.
241        Value * advanceDataPtr = mBuilder->CreateGEP(mCarryDataPtr, advBaseIndex);
242        Value * carry_block0 = mBuilder->CreateAlignedLoad(advanceDataPtr, BLOCK_SIZE/8);
243        mBuilder->CreateAlignedStore(carry_out, advanceDataPtr, BLOCK_SIZE/8);
244        /* Very special case - no combine */
245        if (shift_amount == BLOCK_SIZE) return carry_block0;
246        Value* block0_shr = mBuilder->CreateLShr(mBuilder->CreateBitCast(carry_block0, mBuilder->getIntNTy(BLOCK_SIZE)), BLOCK_SIZE - shift_amount);
247        Value* block1_shl = mBuilder->CreateShl(mBuilder->CreateBitCast(carry_out, mBuilder->getIntNTy(BLOCK_SIZE)), shift_amount);
248        return mBuilder->CreateBitCast(mBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
249    }
250    // We need a buffer of at least two elements for storing the advance data.
251    const unsigned block_shift = shift_amount % BLOCK_SIZE;
252    const unsigned advanceEntries = mCarryInfo->longAdvanceEntries(shift_amount);
253    const unsigned bufsize = mCarryInfo->longAdvanceBufferSize(shift_amount);
254    Value * indexMask = mBuilder->getInt64(bufsize - 1);  // A mask to implement circular buffer indexing
255    Value * loadIndex0 = mBuilder->CreateAdd(mBuilder->CreateAnd(mBuilder->CreateSub(mBlockNo, mBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
256    Value * storeIndex = mBuilder->CreateAdd(mBuilder->CreateAnd(mBlockNo, indexMask), advBaseIndex);
257    Value * carry_block0 = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, loadIndex0), BLOCK_SIZE/8);
258    // If the long advance is an exact multiple of BLOCK_SIZE, we simply return the oldest
259    // block in the long advance carry data area. 
260    if (block_shift == 0) {
261        mBuilder->CreateAlignedStore(carry_out, mBuilder->CreateGEP(mCarryDataPtr, storeIndex), BLOCK_SIZE/8);
262        return carry_block0;
263    }
264    // Otherwise we need to combine data from the two oldest blocks.
265    Value * loadIndex1 = mBuilder->CreateAdd(mBuilder->CreateAnd(mBuilder->CreateSub(mBlockNo, mBuilder->getInt64(advanceEntries-1)), indexMask), advBaseIndex);
266    Value * carry_block1 = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, loadIndex1), BLOCK_SIZE/8);
267    Value* block0_shr = mBuilder->CreateLShr(mBuilder->CreateBitCast(carry_block0, mBuilder->getIntNTy(BLOCK_SIZE)), BLOCK_SIZE - block_shift);
268    Value* block1_shl = mBuilder->CreateShl(mBuilder->CreateBitCast(carry_block1, mBuilder->getIntNTy(BLOCK_SIZE)), block_shift);
269    mBuilder->CreateAlignedStore(carry_out, mBuilder->CreateGEP(mCarryDataPtr, storeIndex), BLOCK_SIZE/8);
270    return mBuilder->CreateBitCast(mBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
271}
272   
273
274/* Methods for getting and setting carry summary values */
275   
276bool CarryManager::blockHasCarries(){
277    return mCarryInfo->blockHasCarries();
278} 
279
280
281Value * CarryManager::getCarrySummaryExpr() {
282    unsigned summary_idx = mCurrentScopeIndex + mCarryInfo->summaryCarryDataIndex();
283    Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(summary_idx));
284    Value * summary_expr = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
285    // If the scopeCarryDataSize is 1, then the carry summary is also the pack expr.
286    mCarryInVector[summary_idx] = summary_expr;
287    return summary_expr;
288}
289
290void CarryManager::addSummaryPhiIfNeeded(BasicBlock * ifEntryBlock, BasicBlock * ifBodyFinalBlock) {
291    if ((mCarryInfo->getIfDepth() <= 1) || !mCarryInfo->blockHasCarries()){
292        // For ifDepth == 1, the parent does not need a summary as it is not itself within an if.
293        // Therefore, it doesn't need access to this block's summary in building its own.
294        return;
295    }
296    const unsigned carrySummaryIndex = mCurrentScopeIndex + mCarryInfo->summaryCarryDataIndex();
297    PHINode * summary_phi = mBuilder->CreatePHI(mBitBlockType, 2, "summary");
298    summary_phi->addIncoming(mZeroInitializer, ifEntryBlock);
299    summary_phi->addIncoming(mCarryOutVector[carrySummaryIndex], ifBodyFinalBlock);
300    mCarryOutVector[carrySummaryIndex] = summary_phi;
301}
302
303void CarryManager::generateCarryOutSummaryCodeIfNeeded() {
304   
305    if (!mCarryInfo->explicitSummaryRequired()) {
306        // An explicit summary may not be required, if there is a single carry
307        // operation within the block, or the carries are packed and all carry
308        // bits fit within a single pack.
309        return;
310    }
311   
312    const unsigned carrySummaryIndex = mCurrentScopeIndex + mCarryInfo->summaryCarryDataIndex();
313   
314    Value * carry_summary = mZeroInitializer;
315   
316    if (mCarryInfo->blockHasLongAdvances()) { // Force if entry
317        carry_summary = mOneInitializer;
318    }
319    else {
320        auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryPackIndex();
321        auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
322        if (localCarryPacks > 0) {
323            carry_summary = mCarryOutVector[localCarryIndex];
324            for (auto i = 1; i < localCarryPacks; i++) {
325                //carry_summary = mBuilder->CreateOr(carry_summary, mPabloBlock->mCarryOutPack[i]);           
326                carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[localCarryIndex+i]);
327            }
328        }
329        for (Statement * stmt : *mCurrentScope) {
330            if (If * innerIf = dyn_cast<If>(stmt)) {
331                PabloBlock * inner_blk = & innerIf->getBody();
332                enterScope(inner_blk);
333                if (blockHasCarries()) {
334                  carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[mCurrentScopeIndex + mCarryInfo->summaryCarryDataIndex()]);
335                }
336                leaveScope();
337            }
338            else if (While * innerWhile = dyn_cast<While>(stmt)) {
339                PabloBlock * inner_blk = & innerWhile->getBody();
340                enterScope(inner_blk);
341                if (blockHasCarries()) {
342                    carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[mCurrentScopeIndex + mCarryInfo->summaryCarryDataIndex()]);
343                }
344                leaveScope();
345            }
346        }
347    }
348    // Calculation of the carry out summary is complete.   Store it and make it
349    // available in case it must included by parent blocks.
350    mCarryOutVector[carrySummaryIndex] = carry_summary;
351    Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carrySummaryIndex));
352    mBuilder->CreateAlignedStore(carry_summary, packPtr, BLOCK_SIZE/8);
353}
354
355
356void CarryManager::ensureCarriesLoadedLocal() {
357#ifdef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
358    if ((mCarryInfo->getScopeCarryDataSize() == 0 ) || (mCarryInfo->getWhileDepth() > 0)) return;
359    if ((mCarryInfo->getIfDepth() == 0) || mCarryInfo->explicitSummaryRequired()) {
360        auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryPackIndex();
361        auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
362        //std::cerr << "ensureCarriesLoadedLocal: localCarryIndex =  " << localCarryIndex << "localCarryPacks =  " << localCarryPacks << std::endl;
363        for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {       
364            mCarryInVector[i] = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i)), BLOCK_SIZE/8, false);
365        }
366    }
367#endif
368}
369
370void CarryManager::ensureCarriesStoredLocal() {
371#ifdef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
372    if ((mCarryInfo->getScopeCarryDataSize() == 0 ) || (mCarryInfo->getWhileDepth() > 0)) return;
373    auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryPackIndex();
374    auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
375    //std::cerr << "ensureCarriesStoredLocal: localCarryIndex =  " << localCarryIndex << "localCarryPacks =  " << localCarryPacks << std::endl;
376    for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {       
377        Value * storePtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i));
378        mBuilder->CreateAlignedStore(mCarryOutVector[i], storePtr, BLOCK_SIZE/8, false);
379    }
380#endif
381}
382
383
384
385void CarryManager::ensureCarriesLoadedRecursive() {
386    const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
387    if (mCarryInfo->getWhileDepth() == 1) {
388        for (auto i = mCurrentScopeIndex; i < mCurrentScopeIndex + scopeCarryDataSize; ++i) {
389            mCarryInVector[i] = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i)), BLOCK_SIZE/8, false);
390        }
391    }
392}
393
394
395void CarryManager::initializeCarryDataPhisAtWhileEntry(BasicBlock * whileEntryBlock) {
396    const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
397    for (unsigned index = mCurrentScopeIndex; index < mCurrentScopeIndex + scopeCarryDataSize; ++index) {
398#ifdef SET_WHILE_CARRY_IN_TO_ZERO_AFTER_FIRST_ITERATION
399        PHINode * phi_in = mBuilder->CreatePHI(mBitBlockType, 2);
400        phi_in->addIncoming(mCarryInVector[index], whileEntryBlock);
401        mCarryInPhis[index] = phi_in;
402#endif
403        PHINode * phi_out = mBuilder->CreatePHI(mBitBlockType, 2);
404        phi_out->addIncoming(mZeroInitializer, whileEntryBlock);
405        mCarryOutAccumPhis[index] = phi_out;
406    }
407}
408
409
410void CarryManager::extendCarryDataPhisAtWhileBodyFinalBlock(BasicBlock * whileBodyFinalBlock) {
411    const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
412    for (unsigned index = mCurrentScopeIndex; index < mCurrentScopeIndex + scopeCarryDataSize; ++index) {
413#ifdef SET_WHILE_CARRY_IN_TO_ZERO_AFTER_FIRST_ITERATION
414        mCarryInPhis[index]->addIncoming(mZeroInitializer, whileBodyFinalBlock);
415#endif
416        PHINode * phi = mCarryOutAccumPhis[index];
417        Value * carryOut = mBuilder->CreateOr(phi, mCarryOutVector[index]);
418        phi->addIncoming(carryOut, whileBodyFinalBlock);
419        mCarryOutVector[index] = carryOut;
420    }
421}
422
423void CarryManager::ensureCarriesStoredRecursive() {
424    const unsigned scopeCarryDataSize = mCarryInfo->getScopeCarryDataSize();
425    if (mCarryInfo->getWhileDepth() == 1) {
426        for (auto i = mCurrentScopeIndex; i < mCurrentScopeIndex + scopeCarryDataSize; ++i) {
427            Value * storePtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i));
428            mBuilder->CreateAlignedStore(mCarryOutVector[i], storePtr, BLOCK_SIZE/8, false);
429        }
430    }
431}
432
433}
434
Note: See TracBrowser for help on using the repository browser.