Commit e2573aea authored by guruhegde's avatar guruhegde

Add comments

parent 4360f5ee
......@@ -27,8 +27,9 @@ using namespace llvm;
namespace tas {
// TODO Use return val array
/// If function parameter annotated as BATCH_ARG and if it is a double pointer,
/// Then additional pointer indirection not added, but arg itself treated as
/// pointer array.
/// Old Function Prototype:
/// Ret Fn(Type1 A, Type2 B BATCH_ARG, Type3 C BATCH_ARG);
/// BatchForm Fn Prototype:
......
......@@ -53,7 +53,7 @@ void BlockPredication::linearizeControlFlow() {
// For each Action block add a Predicate block.
insertPredicateBlocks();
setBlocksSuccessors(PredicateBlocks);
setActionBlocksSuccessors(PredicateBlocks);
setPredBlockSuccessors(PredicateBlocks, ActionBlocks);
......@@ -64,6 +64,7 @@ void BlockPredication::linearizeControlFlow() {
}
}
// Handling phi nodes. These cases appeared in tas code.
void BlockPredication::movePhiNodeToPredicateBlock(BasicBlock * PredBB,
BasicBlock * ActionBB) {
for (auto I = ActionBB->begin(); isa<PHINode>(I);) {
......@@ -106,7 +107,7 @@ void BlockPredication::setPathIDCondition(BranchInst * BI,
Builder.CreateStore(PathIdVal, MaskIDAlloca);
}
void BlockPredication::setBlocksSuccessors(deque<BasicBlock *> & PredicateBlocks) {
void BlockPredication::setActionBlocksSuccessors(deque<BasicBlock *> & PredicateBlocks) {
BranchInst * BI = cast<BranchInst>(F->getEntryBlock().getTerminator());
BranchInst::Create(PredicateBlocks.front(), BI);
BI->eraseFromParent();
......@@ -122,7 +123,6 @@ void BlockPredication::insertPredicateBlocks() {
for (int i = 0; i < ActionBlocks.size(); ++i) {
auto PB = BasicBlock::Create(F->getContext(),
string("predicate_") + std::to_string(i), F, ActionBlocks[i]);
//ActionBlocks[i]->replaceAllUsesWith(PB);
PredicateBlocks.push_back(PB);
}
}
......
......@@ -11,7 +11,7 @@
namespace tas {
// This class transforms the function in place.
// Linerize the control flow in a function.
class BlockPredication {
using BlockToIntMapType = llvm::DenseMap<llvm::BasicBlock *, unsigned>;
......@@ -26,7 +26,7 @@ class BlockPredication {
void linearizeControlFlow();
void setPathIDCondition(llvm::BranchInst * BI, BlockToIntMapType & MaskIDMap);
void setBlocksSuccessors(std::deque<llvm::BasicBlock *> & PredicateBlocks);
void setActionBlocksSuccessors(std::deque<llvm::BasicBlock *> & PredicateBlocks);
void insertPredicateBlocks();
void movePhiNodeToPredicateBlock(llvm::BasicBlock * PredBB,
llvm::BasicBlock * ActionBB);
......
......@@ -9,6 +9,7 @@
namespace tas {
// TODO Rewrite this class with clean interface.
// use IRLoop class for new for loop usages.
/// For loop construct containing single logical body
class TASForLoop {
llvm::Function * F;
......
#include "LoopSplitter.h"
#include "ForLoop.h"
#include "ForLoopV2.h"
#include "IRLoop.h"
#include "Util.h"
#include <llvm/ADT/SmallVector.h>
......@@ -81,6 +80,7 @@ bool LoopSplitter::run() {
addBatchArrayForIntermediateVars(L0);
// Collect existing loop's ingrediants.
auto BodyBegin = L0->getHeader()->getTerminator()->getSuccessor(0);
BodyEnd = L0->getLoopLatch()->getSinglePredecessor();
EndBlocks.push_back(BodyEnd);
......@@ -90,10 +90,16 @@ bool LoopSplitter::run() {
auto TripCount = getLoopTripCount(L0);
assert (ExitBlock && "Loop must have a single exit block!");
// Parent loop skeleton is extracted and used as a new loop.
auto ParentLoop = IRLoop(F->getContext());
ParentLoop.extractLoopSkeleton(L0);
// Same index is used in all the loops.
// It gets reset to 0 in preheader basic block.
auto Index = getLoopIndexVar(L0);
// Create skeleton loop. Number of loops depend on how many variables
// we need to prefetch.
std::vector<IRLoop> Loops;
for (int i = 0; i < AnnotatedVars.size(); ++i) {
Loops.push_back(IRLoop(F->getContext()));
......@@ -108,6 +114,7 @@ bool LoopSplitter::run() {
}
Loops.back().setExitBlock(ExitBlock);
// Divide original loop body into partitions and assign it to new loop parts.
std::vector<BasicBlock *> Blocks;
traverseLoopBody(Blocks, BodyBegin);
......
......@@ -18,9 +18,6 @@ class AllocaInst;
namespace tas {
class TASForLoop;
llvm::AllocaInst * getLoopIndexVar(llvm::Loop * L);
struct Stats {
unsigned AnnotatedVarsSize;
unsigned VarUsePointsSize;
......@@ -31,6 +28,10 @@ struct Stats {
Stats(const Stats & o) = default;
};
/// This class operates on a function.
/// Preconditions: at least one variable annotated as EXPENSIVE
/// at least one loop.
/// Class updates the function in place. It doesn't create new function.
class LoopSplitter {
using ListOfBlocksType = std::vector<std::vector<llvm::BasicBlock *>>;
llvm::Function * F;
......
#ifndef TAS_LOOPSPLITTERPASS_H
+ TAS_ROOT_INCLUDE + #ifndef TAS_LOOPSPLITTERPASS_H
#define TAS_LOOPSPLITTERPASS_H
#include <llvm/IR/Function.h>
......
......@@ -10,6 +10,8 @@ using namespace std;
namespace tas {
static std::string TAS_ROOT_INCLUDE { "-I/home/gp/mpi-sws/tas/" };
string generateIR(string InFile, string Input_dir, bool isTas = false) {
// Compile source to LLVM IR using clang
string OutFile;
......@@ -17,17 +19,16 @@ string generateIR(string InFile, string Input_dir, bool isTas = false) {
OutFile = InFile.substr(0, InFile.find_last_of(".")) + string(".ll");
string tags ("-O0 -Xclang -disable-O0-optnone -S -emit-llvm ");
if (isTas) {
tags += "-std=gnu99 -Wall -Werror -I. -I/home/gp/mpi-sws/tas/include/ -march=native "
tags += "-std=gnu99 -Wall -Werror -I." + TAS_ROOT_INCLUDE + "include/ -march=native "
"-fno-omit-frame-pointer -Wno-unused-variable -Wno-unused-function "
"-Wno-address-of-packed-member -Wno-sometimes-uninitialized "
"-I/usr/share/dpdk/x86_64-native-linuxapp-gcc/include "
"-I/usr/share/dpdk/x86_64-native-linuxapp-gcc/include/dpdk "
"-I/usr/share/dpdk/x86_64-native-linuxapp-gcc/include/x86_64-linux-gnu/dpdk/ "
"-I/usr/include/dpdk "
"-I/home/gp/mpi-sws/tas -I/home/gp/mpi-sws/tas/lib/tas/include "
"-I/home/gp/mpi-sws/tas/lib/sockets/include "
"-I/home/gp/mpi-sws/tas/tas/include "
"-I/home/gp/mpi-sws/tas/tas/fast ";
"-I/usr/include/dpdk " + TAS_ROOT_INCLUDE + "lib/tas/include "
+ TAS_ROOT_INCLUDE + "lib/sockets/include "
+ TAS_ROOT_INCLUDE + "tas/include "
+ TAS_ROOT_INCLUDE + "tas/fast ";
}
string GenerateIRCmd = string("clang ") + tags + string("-o") +
......
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