Ignore:
Timestamp:
Jan 3, 2017, 3:59:33 PM (3 years ago)
Author:
nmedfort
Message:

Work on bracket matching problem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5233 r5245  
    107107    if (LLVM_UNLIKELY(mCarryInfo->variableLength)) {
    108108        // Check whether we need to resize the carry state
    109         PHINode * index = iBuilder->CreatePHI(iBuilder->getInt32Ty(), 2);
     109        PHINode * index = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2);
    110110        mLoopIndicies.push_back(index);
    111         index->addIncoming(iBuilder->getInt32(0), entryBlock);
     111        index->addIncoming(iBuilder->getSize(0), entryBlock);
    112112        Value * capacityPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    113         Value * capacity = iBuilder->CreateLoad(capacityPtr, false, "carryCapacity");
     113        Value * capacity = iBuilder->CreateLoad(capacityPtr, false, "capacity");
    114114        Value * arrayPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    115 
    116         BasicBlock * resizeBlock = BasicBlock::Create(iBuilder->getContext(), "", mFunction);
    117         BasicBlock * codeBlock = BasicBlock::Create(iBuilder->getContext(), "", mFunction);
     115        Value * array = iBuilder->CreateLoad(arrayPtr, false, "array");
     116
     117        LLVMContext & C = iBuilder->getContext();
     118
     119        BasicBlock * resizeBlock = BasicBlock::Create(C, "", mFunction);
     120        BasicBlock * cleanUpBlock = BasicBlock::Create(C, "", mFunction);
     121        BasicBlock * zeroBlock = BasicBlock::Create(C, "", mFunction);
     122        BasicBlock * codeBlock = BasicBlock::Create(C, "", mFunction);
    118123
    119124        Value * cond = iBuilder->CreateICmpULT(index, capacity);
     
    121126        iBuilder->SetInsertPoint(resizeBlock);
    122127
    123         Type * const carryStateType = arrayPtr->getType()->getPointerElementType()->getPointerElementType();
    124         Value * newCapacity = iBuilder->CreateMul(iBuilder->CreateAdd(index, iBuilder->getInt32(1)), iBuilder->getInt32(2));
    125         Value * newArrayPtr = iBuilder->CreateAlignedMalloc(carryStateType, newCapacity, iBuilder->getCacheAlignment());
    126         iBuilder->CreateMemCpy(newArrayPtr, arrayPtr, capacity, iBuilder->getCacheAlignment());
    127         iBuilder->CreateMemZero(iBuilder->CreateGEP(newArrayPtr, capacity), iBuilder->CreateSub(newCapacity, capacity), iBuilder->getCacheAlignment());
    128         iBuilder->CreateAlignedFree(arrayPtr);
     128        Type * const carryStateType = array->getType()->getPointerElementType();
     129        Value * newCapacity = iBuilder->CreateMul(iBuilder->CreateAdd(index, iBuilder->getSize(1)), iBuilder->getSize(2));
     130        Value * newArray = iBuilder->CreateAlignedMalloc(carryStateType, newCapacity, iBuilder->getCacheAlignment());
     131
     132        assert (newCapacity->getType() == capacity->getType());
     133        assert (newArray->getType() == array->getType());
     134
     135        Value * isNullCarryState = iBuilder->CreateICmpEQ(array, ConstantPointerNull::get(cast<PointerType>(array->getType())));
     136
     137        iBuilder->CreateCondBr(isNullCarryState, zeroBlock, cleanUpBlock);
     138        iBuilder->SetInsertPoint(cleanUpBlock);
     139
     140        iBuilder->CreateMemCpy(newArray, array, capacity, iBuilder->getCacheAlignment());
     141        iBuilder->CreateAlignedFree(array);
     142        iBuilder->CreateBr(zeroBlock);
     143
     144        iBuilder->SetInsertPoint(zeroBlock);
     145
     146        iBuilder->CreateMemZero(iBuilder->CreateGEP(newArray, capacity), iBuilder->CreateSub(newCapacity, capacity), iBuilder->getCacheAlignment());
    129147        iBuilder->CreateStore(newCapacity, capacityPtr);
    130         iBuilder->CreateStore(newArrayPtr, arrayPtr);
     148        iBuilder->CreateStore(newArray, arrayPtr);
     149
    131150        iBuilder->CreateBr(codeBlock);
    132151
     
    151170        assert (mLoopIndicies.size() > 0);
    152171        PHINode * index = mLoopIndicies.back();
    153         index->addIncoming(iBuilder->CreateAdd(index, iBuilder->getInt32(1)), exitBlock);
     172        index->addIncoming(iBuilder->CreateAdd(index, iBuilder->getSize(1)), exitBlock);
    154173        mLoopIndicies.pop_back();
    155174    }
Note: See TracChangeset for help on using the changeset viewer.