Commit 386d3782 authored by guruhegde's avatar guruhegde

Handle double pointer annotated as batch arg

parent a274c8fb
......@@ -81,17 +81,19 @@ void BatchMaker::replaceOldArgUsesWithBatchArgs(vector<TASArgAttr> & BatchFuncAr
AllocaInst * IdxPtr) {
auto EntryBB = &BatchFunc->front();
SmallVector<Value *, 4> BatchArgs;
SmallVector<std::pair<Value *, bool>, 4> BatchArgs;
for_each(BatchFuncArgList.begin(), BatchFuncArgList.end(),
[&] (TASArgAttr & Attr) {
if (Attr.IsBatch) BatchArgs.push_back(Attr.Val); });
if (Attr.IsBatch) BatchArgs.push_back(make_pair(Attr.Val, Attr.IsDoublePtr)); });
Builder.SetInsertPoint(&EntryBB->front());
BatchSizeAlloca = Builder.CreateAlloca(BatchFuncArgList[BatchSizeArgPos].Ty);
Builder.CreateStore(BatchFuncArgList[BatchSizeArgPos].Val, BatchSizeAlloca);
for (auto & BatchArg : BatchArgs) {
for (auto & BatchArgPair : BatchArgs) {
Builder.SetInsertPoint(&EntryBB->front());
auto & BatchArg = BatchArgPair.first;
auto IsDoublePtr = BatchArgPair.second;
auto BatchArgAlloca = Builder.CreateAlloca(BatchArg->getType());
auto StoreI = findFirstUseInStoreInst(BatchArg);
......@@ -112,10 +114,22 @@ void BatchMaker::replaceOldArgUsesWithBatchArgs(vector<TASArgAttr> & BatchFuncAr
auto NumUses = OldAlloca->getNumUses();
while (NumUses > 0) {
User * U = OldAlloca->user_back();
Builder.SetInsertPoint(cast<Instruction>(U));
auto ElemPtr = Builder.CreateGEP(Builder.CreateLoad(BatchArgAlloca),
Builder.CreateLoad(IdxPtr));
U->replaceUsesOfWith(OldAlloca, ElemPtr);
if (IsDoublePtr) {
U->replaceUsesOfWith(OldAlloca, BatchArgAlloca);
auto Next = cast<Instruction>(U)->getNextNode();
if (isa<GetElementPtrInst>(Next)) {
Builder.SetInsertPoint(Next);
auto NewGEP = Builder.CreateGEP(cast<GetElementPtrInst>(Next)->getPointerOperand(),
Builder.CreateLoad(IdxPtr));
Next->replaceAllUsesWith(NewGEP);
Next->eraseFromParent();
}
} else {
Builder.SetInsertPoint(cast<Instruction>(U));
auto ElemPtr = Builder.CreateGEP(Builder.CreateLoad(BatchArgAlloca),
Builder.CreateLoad(IdxPtr));
U->replaceUsesOfWith(OldAlloca, ElemPtr);
}
NumUses--;
}
}
......
......@@ -21,10 +21,23 @@ struct TASArgAttr {
llvm::Type * Ty;
llvm::Argument * Val;
std::string Name;
bool IsDoublePtr; // Only true when batched double pointer.
private:
llvm::Type * setArgType(bool isBatch, llvm::Type * In) {
if (isBatch) {
IsDoublePtr = In->isPointerTy() && In->getContainedType(0)->isPointerTy();
if (IsDoublePtr) return In;
return llvm::PointerType::get(In, 0);
}
IsDoublePtr = false;
return In;
}
public:
TASArgAttr(bool b, int p, llvm::Type * t, llvm::Argument * v, std::string n) :
Prefix("batch_"), IsBatch(b), PosIdx(p),
Ty(IsBatch ? llvm::PointerType::get(t, 0) : t),
Ty(setArgType(IsBatch, t)),
Val(v),
Name(IsBatch ? Prefix + std::to_string(p) : n) {}
};
......
......@@ -2,7 +2,9 @@
#include "Util.h"
#include <llvm/ADT/PostOrderIterator.h>
#include <llvm/IR/Dominators.h>
#include <llvm/IR/Instructions.h>
#include <llvm/Analysis/LoopInfo.h>
#include <algorithm>
#include <sstream>
......
......@@ -86,7 +86,7 @@ int main(int argc, char * argv[]) {
errs() << "number of annotated functions = " << FnLists.size() << "\n";
for (auto & FnStr : FnLists) {
if (FnStr.second.compare("tas_block_predicate") != 0) continue;
if (FnStr.second.compare("tas_block_predicate") == 0) {
// Block Predication
tas::BlockPredication BP(FnStr.first);
auto res = BP.run();
......@@ -95,11 +95,16 @@ int main(int argc, char * argv[]) {
Err.print(argv[0], errs());
return -1;
}
}
if (FnStr.second.compare("tas_batch_maker") == 0) {
// Make Batch version
tas::BatchMaker BM(FnStr.first);
auto BatchFunc = BM.run();
errs() << BatchFunc->getName() << "\n";
}
/*
// Make Batch version
tas::BatchMaker BM(FnStr.first);
auto BatchFunc = BM.run();
writeToAsmFile(*M);
// Loop Splitting
......
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