Commit 41b3e747 authored by guruhegde's avatar guruhegde

[LoopSplitter] step1: detect Annotated variable

parent a0371643
......@@ -3,9 +3,7 @@
#include "Util.h"
#include <llvm/ADT/SmallVector.h>
#include <llvm/ADT/Statistic.h>
#include <llvm/ADT/STLExtras.h>
#include <llvm/IR/CFG.h>
#include <llvm/IR/IRBuilder.h>
#include <iostream>
......@@ -18,6 +16,11 @@ using namespace llvm;
namespace tas {
bool LoopSplitter::run() {
SmallVector<Value *, 4> AnnotatedVars;
detectExpPtrVars(F, AnnotatedVars);
errs() << "No of annotated variables = " << AnnotatedVars.size() << "\n";
auto FU = findFirstUseOfValueInInstType<LoadInst>(AnnotatedVars.front());
return true;
}
......
......@@ -421,21 +421,6 @@ pair<BasicBlock *, BasicBlock *> unifyFunctionExitNodes(Function &F) {
return make_pair(NewRetBlock, UnreachableBlock);
}
template <typename InstType>
auto findFirstUseOfValueInInstType(Value * V) {
auto FU = find_if(V->users(),
[&] (const auto * U) { return isa<InstType>(U)?true:false; });
return cast<InstType>(FU);
}
template <typename InstType>
auto findLastUseOfValueInInstType(Value * V) {
InstType * LU = nullptr;
for_each(V->users(),
[&] (const auto * U) { if (isa<InstType>(U)) LU = cast<InstType>(U); });
return LU;
}
AllocaInst * getLoopIndexVar(Loop * L) {
AllocaInst * Index = nullptr;
auto LatchBB = L->getLoopLatch();
......
......@@ -77,13 +77,27 @@ llvm::Value * addIncrementIndexOp(llvm::AllocaInst * IdxPtr,
void printRegeionInfo(llvm::Function * F);
std::pair<llvm::BasicBlock *, llvm::BasicBlock *> unifyFunctionExitNodes(llvm::Function & F);
std::pair<llvm::BasicBlock *, llvm::BasicBlock *>
unifyFunctionExitNodes(llvm::Function & F);
template <typename InstType>
auto findFirstUseOfValueInInstType(llvm::Value * V);
auto findLastUseOfValueInInstType(llvm::Value * V) {
auto FU = find_if(V->users(),
[&] (const auto * U) {
return llvm::isa<InstType>(U)?true:false;
});
return llvm::cast<InstType>(*FU);
}
template <typename InstType>
auto findLastUseOfValueInInstType(llvm::Value * V);
auto findFirstUseOfValueInInstType(llvm::Value * V) {
const InstType * LU = nullptr;
for_each(V->users(),
[&] (const auto * U) {
if (llvm::isa<InstType>(U)) LU = llvm::cast<InstType>(U);
});
return LU;
}
llvm::AllocaInst * getLoopIndexVar(llvm::Loop * L);
......
......@@ -58,18 +58,9 @@ TEST_CASE("fn with single loop") {
DominatorTree DT(*F);
LoopInfo LI(DT);
auto * L = *LI.begin();
auto PreH = L->getLoopPreheader();
assert (L->isLoopSimplifyForm() && "No loop simplify form!");
assert (PreH && "No Preheader!");
auto Ind = getLoopIndexVar(L);
errs() << "Loop details\n";
LI.print(errs());
errs() << *Ind;
LoopSplitter LS(F, &LI);
LS.run();
REQUIRE(LS.getAnnotatedVarCount() == 1);
}
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