From fa86e875b33eccba742e06d74ff6ee36498d3963 Mon Sep 17 00:00:00 2001 From: nishant-sachdeva Date: Thu, 18 Jul 2024 15:21:32 +0530 Subject: [PATCH] Pruning omp usage. Adding omp usage to flowaware pipeline --- src/FlowAware.cpp | 51 +++++++++++++++++++++---------------- src/Symbolic.cpp | 64 +++++++++++++++++------------------------------ 2 files changed, 52 insertions(+), 63 deletions(-) diff --git a/src/FlowAware.cpp b/src/FlowAware.cpp index bbf4664f..82eb2150 100644 --- a/src/FlowAware.cpp +++ b/src/FlowAware.cpp @@ -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 funcStack; - auto tmp = func2Vec(f, funcStack); - funcVecMap[&f] = tmp; +#pragma omp parallel + { +#pragma omp for + for (auto &f : M) { + if (!f.isDeclaration()) { + SmallVector funcStack; + auto tmp = func2Vec(f, funcStack); + +#pragma omp critical + { funcVecMap[&f] = tmp; } + } } } @@ -145,7 +150,6 @@ void IR2Vec_FA::generateFlowAwareEncodings(std::ostream *o, for (auto &f : M) { if (!f.isDeclaration()) { Vector tmp; - SmallVector funcStack; tmp = funcVecMap[&f]; if (level == 'f') { @@ -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()); - // } } } @@ -356,19 +358,24 @@ Vector IR2Vec_FA::func2Vec(Function &F, ReversePostOrderTraversal RPOT(&F); - for (auto *b : RPOT) { - unsigned opnum; - SmallVector lists; - for (auto &I : *b) { - lists.clear(); - if (isMemOp(I.getOpcodeName(), opnum, memWriteOps) && - dyn_cast(I.getOperand(opnum))) { - Instruction *argI = cast(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 lists; + if (isMemOp(I.getOpcodeName(), opnum, memWriteOps) && + dyn_cast(I.getOperand(opnum))) { + Instruction *argI = cast(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; } + } } } } diff --git a/src/Symbolic.cpp b/src/Symbolic.cpp index 4a01855c..4f3924dc 100644 --- a/src/Symbolic.cpp +++ b/src/Symbolic.cpp @@ -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()); - - // } } } @@ -111,16 +108,11 @@ Vector IR2Vec_Symbolic::func2Vec(Function &F, ReversePostOrderTraversal RPOT(&F); MapVector cumulativeScore; -#pragma omp parallel - { - std::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()); @@ -135,6 +127,7 @@ Vector IR2Vec_Symbolic::bb2Vec(BasicBlock &B, SmallVector &funcStack) { Vector bbVector(DIM, 0); +#pragma omp parallel for for (auto &I : B) { Vector instVector(DIM, 0); Vector getValueVec; @@ -180,38 +173,27 @@ Vector IR2Vec_Symbolic::bb2Vec(BasicBlock &B, std::transform(instVector.begin(), instVector.end(), getValueVec.begin(), instVector.begin(), std::plus()); -// 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 localVec; - for (unsigned i = 0; i < I.getNumOperands(); i++) { - Vector localValueVector; - if (isa(I.getOperand(i))) { - getValue(localValueVector, "function"); - } else if (isa(I.getOperand(i)->getType())) { - getValue(localValueVector, "pointer"); - } else if (isa(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(I.getOperand(i))) { + getValue(localValueVector, "function"); + } else if (isa(I.getOperand(i)->getType())) { + getValue(localValueVector, "pointer"); + } else if (isa(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()); + } #pragma omp critical - for (auto localValueVector : localVec) { - std::transform(instVector.begin(), instVector.end(), - localValueVector.begin(), instVector.begin(), - std::plus()); - instVecMap[&I] = instVector; - } + { + std::transform(bbVector.begin(), bbVector.end(), instVector.begin(), + bbVector.begin(), std::plus()); } - std::transform(bbVector.begin(), bbVector.end(), instVector.begin(), - bbVector.begin(), std::plus()); } return bbVector; }