Skip to content
Snippets Groups Projects
Commit 9f0c3c74 authored by guruhegde's avatar guruhegde
Browse files

Fix index variable.

* Some positive throughput in tas
parent 743cf699
Branches master
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ void IRLoop::analyze(Loop * L) {
}
}
void IRLoop::constructEmptyLoop(AllocaInst * TripCount, Function * F) {
void IRLoop::constructEmptyLoop(AllocaInst * TripCount, AllocaInst * Idx, Function * F) {
Latch = BasicBlock::Create(Ctx, "latch", F);
Header = BasicBlock::Create(Ctx, "header", F, Latch);
PreHeader = BasicBlock::Create(Ctx, "preheader", F, Header);
......@@ -32,18 +32,18 @@ void IRLoop::constructEmptyLoop(AllocaInst * TripCount, Function * F) {
// Create Loop Index Variable.
IRBuilder<> Builder(Ctx);
Builder.SetInsertPoint(&F->getEntryBlock().front());
IdxAlloca = Builder.CreateAlloca(Builder.getInt32Ty());
//Builder.SetInsertPoint(&F->getEntryBlock().front());
//IdxAlloca = Builder.CreateAlloca(Builder.getInt32Ty());
// Set Index variable to 0 in preheader block.
Builder.SetInsertPoint(PreHeader);
Builder.CreateStore(Builder.getInt32(0), IdxAlloca);
Builder.CreateStore(Builder.getInt32(0), Idx);
Builder.CreateBr(Header);
// Populate latch block
Builder.SetInsertPoint(Latch);
auto BackEdge = Builder.CreateBr(Header);
addIncrementIndexOp(IdxAlloca, BackEdge);
addIncrementIndexOp(Idx, BackEdge);
// Branch Empty block to latch
Builder.SetInsertPoint(EmptyBody);
......@@ -51,7 +51,7 @@ void IRLoop::constructEmptyLoop(AllocaInst * TripCount, Function * F) {
// Populate header block
Builder.SetInsertPoint(Header);
auto IdxVal = Builder.CreateLoad(IdxAlloca);
auto IdxVal = Builder.CreateLoad(Idx);
auto TC = Builder.CreateLoad(TripCount);
auto * Icmp = Builder.CreateICmpSLT(IdxVal, TC, "loop-predicate");
Builder.CreateCondBr(Icmp, EmptyBody, EmptyBody);
......
......@@ -27,7 +27,7 @@ public:
IRLoop(llvm::LLVMContext & C) : Ctx(C) {}
void analyze(llvm::Loop * L);
void constructEmptyLoop(llvm::AllocaInst * TripCount,
void constructEmptyLoop(llvm::AllocaInst * TripCount, llvm::AllocaInst * Idx,
llvm::Function * F);
void extractLoopSkeleton(llvm::Loop * L);
void setLoopBlocks(std::vector<llvm::BasicBlock *> & Blocks);
......
......@@ -86,18 +86,19 @@ bool LoopSplitter::run() {
EndBlocks.push_back(BodyEnd);
auto EntryBlock = getPreLoopBlock(L0);
EntryBlock->printAsOperand(errs()); errs() << " - Entry\n";
ExitBlock = L0->getExitBlock();
auto TripCount = getLoopTripCount(L0);
assert (ExitBlock && "Loop must have a single exit block!");
auto ParentLoop = IRLoop(F->getContext());
ParentLoop.extractLoopSkeleton(L0);
auto Index = getLoopIndexVar(L0);
errs() << *Index;
std::vector<IRLoop> Loops;
for (int i = 0; i < AnnotatedVars.size(); ++i) {
Loops.push_back(IRLoop(F->getContext()));
Loops.back().constructEmptyLoop(TripCount, F);
Loops.back().constructEmptyLoop(TripCount, Index, F);
}
Loops.push_back(ParentLoop);
......@@ -128,7 +129,6 @@ bool LoopSplitter::run() {
Loops[i].setLoopBlocks(LoopBlocks[i]);
}
F->print(errs());
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment