From 8550d281dc43e8e2988bce4a155bbab22765b2d7 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 8e1e539c..815eadf5 100644 --- a/src/FlowAware.cpp +++ b/src/FlowAware.cpp @@ -131,12 +131,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; } + } } } @@ -147,7 +152,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') { @@ -156,10 +160,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()); - // } } } @@ -358,19 +360,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 d90ac251..617bdcff 100644 --- a/src/Symbolic.cpp +++ b/src/Symbolic.cpp @@ -49,11 +49,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()); - - // } } } @@ -113,16 +110,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()); @@ -137,6 +129,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; @@ -182,38 +175,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; }