Skip to content

Commit

Permalink
Transition to opaque pointers (GPUOpen-Drivers#1873)
Browse files Browse the repository at this point in the history
Changes in tryToCoalesceChain
  • Loading branch information
mariusz-sikora-at-amd authored Jul 14, 2022
1 parent da9b5f2 commit 0115f36
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions llpc/lower/llpcSpirvLowerAccessChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ GetElementPtrInst *SpirvLowerAccessChain::tryToCoalesceChain(GetElementPtrInst *
std::vector<Value *> idxs;
unsigned startOperand = 1;
Value *blockPtr = nullptr;
Type *coalescedType = nullptr;

do {
ptrVal = chainedInsts.top();
chainedInsts.pop();
if (!blockPtr)
blockPtr = ptrVal->getOperand(0);

for (unsigned i = startOperand; i != ptrVal->getNumOperands(); ++i)
idxs.push_back(ptrVal->getOperand(i));
// NOTE: For subsequent "getelementptr" instructions/constants, we skip the first two operands. The first
Expand All @@ -157,13 +157,21 @@ GetElementPtrInst *SpirvLowerAccessChain::tryToCoalesceChain(GetElementPtrInst *
startOperand = 2;

auto inst = dyn_cast<GetElementPtrInst>(ptrVal);

if (!blockPtr && inst) {
blockPtr = ptrVal->getOperand(0);
coalescedType = inst->getSourceElementType();
}

if (inst)
removedInsts.push(inst);
} while (!chainedInsts.empty());

// TODO: Remove this when LLPC will switch fully to opaque pointers.
assert(cast<PointerType>(blockPtr->getType())->isOpaqueOrPointeeTypeMatches(coalescedType));

// Create the coalesced "getelementptr" instruction (do combining)
auto blockType = blockPtr->getType()->getPointerElementType();
coalescedGetElemPtr = GetElementPtrInst::Create(blockType, blockPtr, idxs, "", getElemPtr);
coalescedGetElemPtr = GetElementPtrInst::Create(coalescedType, blockPtr, idxs, "", getElemPtr);
getElemPtr->replaceAllUsesWith(coalescedGetElemPtr);

// Remove dead "getelementptr" instructions where possible.
Expand Down

0 comments on commit 0115f36

Please sign in to comment.