Skip to content

Commit

Permalink
Pruning omp usage. Adding omp usage to flowaware pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant-sachdeva committed Jul 18, 2024
1 parent 8b9a998 commit fa86e87
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 63 deletions.
51 changes: 29 additions & 22 deletions src/FlowAware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,17 @@ void IR2Vec_FA::generateFlowAwareEncodings(std::ostream *o,
std::ostream *cyclicCount) {

int noOfFunc = 0;

for (auto &f : M) {
if (!f.isDeclaration()) {
SmallVector<Function *, 15> funcStack;
auto tmp = func2Vec(f, funcStack);
funcVecMap[&f] = tmp;
#pragma omp parallel
{
#pragma omp for
for (auto &f : M) {
if (!f.isDeclaration()) {
SmallVector<Function *, 15> funcStack;
auto tmp = func2Vec(f, funcStack);

#pragma omp critical
{ funcVecMap[&f] = tmp; }
}
}
}

Expand All @@ -145,7 +150,6 @@ void IR2Vec_FA::generateFlowAwareEncodings(std::ostream *o,
for (auto &f : M) {
if (!f.isDeclaration()) {
Vector tmp;
SmallVector<Function *, 15> funcStack;
tmp = funcVecMap[&f];

if (level == 'f') {
Expand All @@ -154,10 +158,8 @@ void IR2Vec_FA::generateFlowAwareEncodings(std::ostream *o,
noOfFunc++;
}

// else if (level == 'p') {
std::transform(pgmVector.begin(), pgmVector.end(), tmp.begin(),
pgmVector.begin(), std::plus<double>());
// }
}
}

Expand Down Expand Up @@ -356,19 +358,24 @@ Vector IR2Vec_FA::func2Vec(Function &F,

ReversePostOrderTraversal<Function *> RPOT(&F);

for (auto *b : RPOT) {
unsigned opnum;
SmallVector<Instruction *, 16> lists;
for (auto &I : *b) {
lists.clear();
if (isMemOp(I.getOpcodeName(), opnum, memWriteOps) &&
dyn_cast<Instruction>(I.getOperand(opnum))) {
Instruction *argI = cast<Instruction>(I.getOperand(opnum));
lists = createKilllist(argI, &I);
TransitiveReads(lists, argI, I.getParent());
if (argI->getParent() == I.getParent())
lists.push_back(argI);
killMap[&I] = lists;
#pragma omp parallel
{
#pragma omp for
for (auto *b : RPOT) {
for (auto &I : *b) {
unsigned opnum;
SmallVector<Instruction *, 16> lists;
if (isMemOp(I.getOpcodeName(), opnum, memWriteOps) &&
dyn_cast<Instruction>(I.getOperand(opnum))) {
Instruction *argI = cast<Instruction>(I.getOperand(opnum));
lists = createKilllist(argI, &I);
TransitiveReads(lists, argI, I.getParent());
if (argI->getParent() == I.getParent())
lists.push_back(argI);

#pragma openmp critical
{ killMap[&I] = lists; }
}
}
}
}
Expand Down
64 changes: 23 additions & 41 deletions src/Symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ void IR2Vec_Symbolic::generateSymbolicEncodings(std::ostream *o) {
noOfFunc++;
}

// else if (level == 'p') {
std::transform(pgmVector.begin(), pgmVector.end(), tmp.begin(),
pgmVector.begin(), std::plus<double>());

// }
}
}

Expand Down Expand Up @@ -111,16 +108,11 @@ Vector IR2Vec_Symbolic::func2Vec(Function &F,
ReversePostOrderTraversal<Function *> RPOT(&F);
MapVector<const BasicBlock *, double> cumulativeScore;

#pragma omp parallel
{
std::vector<Vector> localVector;
for (auto *b : RPOT) {
Vector weightedBBVector = bb2Vec(*b, funcStack);
localVector.push_back(weightedBBVector);
}

#pragma omp parallel for
for (auto *b : RPOT) {
Vector weightedBBVector = bb2Vec(*b, funcStack);
#pragma omp critical
for (auto weightedBBVector : localVector) {
{
std::transform(funcVector.begin(), funcVector.end(),
weightedBBVector.begin(), funcVector.begin(),
std::plus<double>());
Expand All @@ -135,6 +127,7 @@ Vector IR2Vec_Symbolic::bb2Vec(BasicBlock &B,
SmallVector<Function *, 15> &funcStack) {
Vector bbVector(DIM, 0);

#pragma omp parallel for
for (auto &I : B) {
Vector instVector(DIM, 0);
Vector getValueVec;
Expand Down Expand Up @@ -180,38 +173,27 @@ Vector IR2Vec_Symbolic::bb2Vec(BasicBlock &B,
std::transform(instVector.begin(), instVector.end(), getValueVec.begin(),
instVector.begin(), std::plus<double>());

// Check if this section can be made faster using openMP
// order of vectors is not important since it's all added up using
// std::transform
// So we can parallelize this section
#pragma omp parallel
{
std::vector<Vector> localVec;
for (unsigned i = 0; i < I.getNumOperands(); i++) {
Vector localValueVector;
if (isa<Function>(I.getOperand(i))) {
getValue(localValueVector, "function");
} else if (isa<PointerType>(I.getOperand(i)->getType())) {
getValue(localValueVector, "pointer");
} else if (isa<Constant>(I.getOperand(i))) {
getValue(localValueVector, "constant");
} else {
getValue(localValueVector, "variable");
}
scaleVector(localValueVector, WA);
localVec.push_back(localValueVector);
for (unsigned i = 0; i < I.getNumOperands(); i++) {
Vector localValueVector;
if (isa<Function>(I.getOperand(i))) {
getValue(localValueVector, "function");
} else if (isa<PointerType>(I.getOperand(i)->getType())) {
getValue(localValueVector, "pointer");
} else if (isa<Constant>(I.getOperand(i))) {
getValue(localValueVector, "constant");
} else {
getValue(localValueVector, "variable");
}

scaleVector(localValueVector, WA);
std::transform(instVector.begin(), instVector.end(),
localValueVector.begin(), instVector.begin(),
std::plus<double>());
}
#pragma omp critical
for (auto localValueVector : localVec) {
std::transform(instVector.begin(), instVector.end(),
localValueVector.begin(), instVector.begin(),
std::plus<double>());
instVecMap[&I] = instVector;
}
{
std::transform(bbVector.begin(), bbVector.end(), instVector.begin(),
bbVector.begin(), std::plus<double>());
}
std::transform(bbVector.begin(), bbVector.end(), instVector.begin(),
bbVector.begin(), std::plus<double>());
}
return bbVector;
}

0 comments on commit fa86e87

Please sign in to comment.