Commit f1b828b2 authored by guruhegde's avatar guruhegde

Implement findEarliestMemoryDeferInst() fn

parent b5cb31c9
......@@ -66,6 +66,8 @@ void LoopSplitter::addAdapterBasicBlocks(Instruction * SP, Value * Idx) {
}
}
bool LoopSplitter::prepareForLoopSplit(Function *F, Loop * L0, Stats & stat) {
auto Idx = getLoopIndexVar(L0);
auto AnnotatedVars = detectExpPtrVars(F);
......
......@@ -91,17 +91,33 @@ SmallVector<Value *, 4> detectExpPtrVars(Function * F) {
return ExpensivePointers;
}
const LoadInst * findEarliestPointerDerefInstruction(Value * V) {
const LoadInst * LU = nullptr;
auto matchLoadPattern = [&] (const auto * U)
{
if (llvm::isa<LoadInst>(U)) {
auto NextI = cast<LoadInst>(U)->getNextNode();
if (isa<llvm::GetElementPtrInst>(NextI) && NextI->getOperand(0) == U) {
LU = cast<LoadInst>(U);
} else if (isa<LoadInst>(NextI) && NextI->getOperand(0) == U) {
LU = cast<LoadInst>(U);
}
}
};
for_each(V->users(), matchLoadPattern);
return LU;
}
SmallVector<LoadInst *, 4> detectExpPtrUses(SmallVectorImpl<Value *> & AnnotatedVars) {
SmallVector<LoadInst *, 4> VarUsePoints;
for_each(AnnotatedVars, [&]
(const auto & Var) {
auto FU = findFirstUseOfValueInInstType<LoadInst>(Var);
auto FU = findEarliestPointerDerefInstruction(Var);
errs() << *FU << "\n";
if (!FU) return;
// TODO Assume Load instruction immeditately follows.
if (auto * Ptr = dyn_cast<LoadInst>(FU->getNextNode())) {
if (Ptr->getOperand(0) == FU)
VarUsePoints.push_back(const_cast<LoadInst *>(FU));
}
VarUsePoints.push_back(const_cast<LoadInst *>(FU));
});
return VarUsePoints;
}
......
......@@ -105,8 +105,13 @@ auto findFirstUseOfValueInInstType(llvm::Value * V) {
return LU;
}
llvm::AllocaInst * getLoopIndexVar(llvm::Loop * L);
const llvm::LoadInst * findEarliestPointerDerefInstruction(llvm::Value * V);
} // namespace tas
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment