@@ -94,21 +94,11 @@ void IR2Vec_FA::collectWriteDefsMap(Module &M) {
94
94
}
95
95
}
96
96
97
- // Vector IR2Vec_FA::getValue(std::string key) {
98
- // Vector vec(DIM, 0);
99
- // if (opcMap.find(key) == opcMap.end()) {
100
- // IR2VEC_DEBUG(errs() << "cannot find key in map : " << key << "\n");
101
- // dataMissCounter++;
102
- // } else
103
- // vec = opcMap[key];
104
- // return vec;
105
- // }
106
-
107
97
inline void IR2Vec_FA::getValue (IR2Vec::Vector &vec, std::string key) {
108
98
auto it = opcMap.find (key);
109
99
if (it == opcMap.end ()) {
110
- dataMissCounter++;
111
100
IR2VEC_DEBUG (errs () << " cannot find key in map : " << key << " \n " );
101
+ dataMissCounter++;
112
102
} else
113
103
vec = it->second ;
114
104
return ;
@@ -139,7 +129,7 @@ void IR2Vec_FA::generateFlowAwareEncodings(std::ostream *o,
139
129
std::ostream *cyclicCount) {
140
130
141
131
int noOfFunc = 0 ;
142
- #pragma omp for
132
+ #pragma omp parallel for
143
133
for (auto &f : M) {
144
134
if (!f.isDeclaration ()) {
145
135
SmallVector<Function *, 15 > funcStack;
@@ -150,7 +140,7 @@ void IR2Vec_FA::generateFlowAwareEncodings(std::ostream *o,
150
140
}
151
141
}
152
142
153
- #pragma omp for
143
+ #pragma omp parallel for
154
144
for (auto funcit : funcVecMap) {
155
145
updateFuncVecMapWithCallee (funcit.first );
156
146
}
@@ -237,7 +227,7 @@ void IR2Vec_FA::generateFlowAwareEncodingsForFunction(
237
227
}
238
228
// iterating over all functions in module instead of funcVecMap to preserve
239
229
// order
240
- #pragma omp for
230
+ #pragma omp parallel for
241
231
for (auto &f : M) {
242
232
if (funcVecMap.find (&f) != funcVecMap.end ()) {
243
233
auto *function = const_cast <const Function *>(&f);
@@ -288,17 +278,16 @@ void IR2Vec_FA::topoDFS(int vertex, std::vector<bool> &Visited,
288
278
visitStack.push_back (vertex);
289
279
}
290
280
291
- std::vector<int > IR2Vec_FA::topoOrder ( int size) {
281
+ void IR2Vec_FA::topoOrder ( std::vector<int > &visitStack, int size) {
292
282
std::vector<bool > Visited (size, false );
293
- std::vector<int > visitStack;
294
283
295
284
for (auto &nodes : SCCAdjList) {
296
285
if (Visited[nodes.first ] == false ) {
297
286
topoDFS (nodes.first , Visited, visitStack);
298
287
}
299
288
}
300
289
301
- return visitStack ;
290
+ return ;
302
291
}
303
292
304
293
void IR2Vec_FA::TransitiveReads (SmallVector<Instruction *, 16 > &Killlist,
@@ -317,10 +306,9 @@ void IR2Vec_FA::TransitiveReads(SmallVector<Instruction *, 16> &Killlist,
317
306
TransitiveReads (Killlist, parentI, ParentBB);
318
307
}
319
308
320
- SmallVector<Instruction *, 16 >
321
- IR2Vec_FA::createKilllist ( Instruction *Arg, Instruction *writeInst) {
309
+ void IR2Vec_FA::createKilllist ( SmallVector<Instruction *, 16 > &KillList,
310
+ Instruction *Arg, Instruction *writeInst) {
322
311
323
- SmallVector<Instruction *, 16 > KillList;
324
312
SmallVector<Instruction *, 16 > tempList;
325
313
BasicBlock *ParentBB = writeInst->getParent ();
326
314
@@ -343,7 +331,7 @@ IR2Vec_FA::createKilllist(Instruction *Arg, Instruction *writeInst) {
343
331
KillList.push_back (*I);
344
332
}
345
333
346
- return KillList ;
334
+ return ;
347
335
}
348
336
349
337
Vector IR2Vec_FA::func2Vec (Function &F,
@@ -364,20 +352,20 @@ Vector IR2Vec_FA::func2Vec(Function &F,
364
352
365
353
ReversePostOrderTraversal<Function *> RPOT (&F);
366
354
367
- #pragma omp for
355
+ #pragma omp parallel for
368
356
for (auto *b : RPOT) {
369
357
for (auto &I : *b) {
370
358
unsigned opnum;
371
359
SmallVector<Instruction *, 16 > lists;
372
360
if (isMemOp (I.getOpcodeName (), opnum, memWriteOps) &&
373
361
dyn_cast<Instruction>(I.getOperand (opnum))) {
374
362
Instruction *argI = cast<Instruction>(I.getOperand (opnum));
375
- lists = createKilllist (argI, &I);
363
+ createKilllist (lists, argI, &I);
376
364
TransitiveReads (lists, argI, I.getParent ());
377
365
if (argI->getParent () == I.getParent ())
378
366
lists.push_back (argI);
379
367
380
- #pragma openmp critical
368
+ #pragma omp critical
381
369
{ killMap[&I] = lists; }
382
370
}
383
371
}
@@ -387,7 +375,8 @@ Vector IR2Vec_FA::func2Vec(Function &F,
387
375
for (auto &I : *b) {
388
376
for (int i = 0 ; i < I.getNumOperands (); i++) {
389
377
if (isa<Instruction>(I.getOperand (i))) {
390
- auto RD = getReachingDefs (&I, i);
378
+ SmallVector<const Instruction *, 10 > RD;
379
+ getReachingDefs (RD, &I, i);
391
380
if (instReachingDefsMap.find (&I) == instReachingDefsMap.end ()) {
392
381
instReachingDefsMap[&I] = RD;
393
382
} else {
@@ -488,7 +477,7 @@ Vector IR2Vec_FA::func2Vec(Function &F,
488
477
489
478
std::vector<int > stack;
490
479
491
- stack = topoOrder (allSCCs.size ());
480
+ topoOrder (stack, allSCCs.size ());
492
481
493
482
for (int i = 0 ; i < allSCCs.size (); i++) {
494
483
if (std::find (stack.begin (), stack.end (), i) == stack.end ()) {
@@ -714,24 +703,23 @@ bool isPotentiallyReachable(
714
703
Worklist, const_cast <BasicBlock *>(B->getParent ()), ExclusionSet, DT, LI);
715
704
}
716
705
717
- SmallVector<const Instruction *, 10 >
718
- IR2Vec_FA::getReachingDefs ( const Instruction *I, unsigned loc) {
706
+ void IR2Vec_FA::getReachingDefs (llvm:: SmallVector<const Instruction *, 10 > &RD,
707
+ const Instruction *I, unsigned loc) {
719
708
IR2VEC_DEBUG (
720
709
outs ()
721
710
<< " Call to getReachingDefs Started****************************\n " );
722
711
723
712
auto parent = dyn_cast<Instruction>(I->getOperand (loc));
724
713
if (!parent)
725
- return {} ;
714
+ return ;
726
715
727
- SmallVector<const Instruction *, 10 > RD;
728
716
SmallVector<const Instruction *, 10 > probableRD;
729
717
IR2VEC_DEBUG (outs () << " Inside RD for : " );
730
718
IR2VEC_DEBUG (I->print (outs ()); outs () << " \n " );
731
719
732
720
if (writeDefsMap[parent].empty ()) {
733
721
RD.push_back (parent);
734
- return RD ;
722
+ return ;
735
723
} else if (writeDefsMap[parent].size () >= 1 ) {
736
724
SmallMapVector<const BasicBlock *, SmallVector<const Instruction *, 10 >, 16 >
737
725
bbInstMap;
@@ -779,25 +767,16 @@ IR2Vec_FA::getReachingDefs(const Instruction *I, unsigned loc) {
779
767
IR2VEC_DEBUG (outs () << " Returning: " );
780
768
IR2VEC_DEBUG (probableRD->print (outs ()); outs () << " \n " );
781
769
RD.push_back (probableRD);
782
- return RD ;
770
+ return ;
783
771
}
784
772
}
785
773
786
- IR2VEC_DEBUG (outs () << " --------Across BB--------\n " );
787
774
SmallVector<const Instruction *, 10 > toDelete;
788
- for (auto it : bbInstMap) {
789
- IR2VEC_DEBUG (outs () << " --------INSTMAP BEGIN--------\n " ;
790
- it.first ->print (outs ()); outs () << " \n " );
791
- bool first = true ;
792
- for (auto it1 : bbInstMap[it.first ]) {
793
- if (first) {
794
- first = false ;
795
- continue ;
796
- }
797
- toDelete.push_back (it1);
798
- IR2VEC_DEBUG (it1->print (outs ()); outs () << " \n " );
775
+ for (auto &it : bbInstMap) {
776
+ auto &vec = it.second ;
777
+ if (vec.size () > 1 ) { // Skip empty or single-element vectors
778
+ toDelete.insert (toDelete.end (), vec.begin () + 1 , vec.end ());
799
779
}
800
- IR2VEC_DEBUG (outs () << " --------INSTMAP END--------\n " );
801
780
}
802
781
auto tmp = probableRD;
803
782
probableRD = {};
@@ -838,11 +817,11 @@ IR2Vec_FA::getReachingDefs(const Instruction *I, unsigned loc) {
838
817
outs () << " \n " ;
839
818
outs ()
840
819
<< " Call to getReachingDefs Ended****************************\n " );
841
- return RD ;
820
+ return ;
842
821
}
843
822
844
823
llvm_unreachable (" unreachable" );
845
- return {} ;
824
+ return ;
846
825
}
847
826
848
827
bool IR2Vec_FA::isMemOp (StringRef opcode, unsigned &operand,
@@ -870,7 +849,7 @@ void IR2Vec_FA::getPartialVec(
870
849
}
871
850
872
851
Vector instVector (DIM, 0 );
873
- Vector vec;
852
+ Vector vec (DIM, 0 ) ;
874
853
StringRef opcodeName = I.getOpcodeName ();
875
854
getValue (vec, opcodeName.str ());
876
855
IR2VEC_DEBUG (I.print (outs ()); outs () << " \n " );
@@ -927,9 +906,9 @@ void IR2Vec_FA::getPartialVec(
927
906
void IR2Vec_FA::solveInsts (
928
907
llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 16 >
929
908
&partialInstValMap) {
930
- std::map <unsigned , const Instruction *> xI;
931
- std::map <const Instruction *, unsigned > Ix;
932
- std::vector<std::vector<double >> A, B;
909
+ std::unordered_map <unsigned , const Instruction *> xI;
910
+ std::unordered_map <const Instruction *, unsigned > Ix;
911
+ std::vector<std::vector<double >> B;
933
912
SmallMapVector<const Instruction *,
934
913
SmallMapVector<const Instruction *, double , 16 >, 16 >
935
914
RDValMap;
@@ -946,7 +925,7 @@ void IR2Vec_FA::solveInsts(
946
925
B.push_back (tmp);
947
926
for (unsigned i = 0 ; i < inst->getNumOperands (); i++) {
948
927
if (isa<Function>(inst->getOperand (i))) {
949
- Vector f;
928
+ Vector f (DIM, 0 ) ;
950
929
getValue (f, " function" );
951
930
if (isa<CallInst>(inst)) {
952
931
auto ci = dyn_cast<CallInst>(inst);
@@ -972,7 +951,7 @@ void IR2Vec_FA::solveInsts(
972
951
B.push_back (vec);
973
952
} else if (isa<Constant>(inst->getOperand (i)) &&
974
953
!isa<PointerType>(inst->getOperand (i)->getType ())) {
975
- Vector c;
954
+ Vector c (DIM, 0 ) ;
976
955
getValue (c, " constant" );
977
956
auto svtmp = c;
978
957
scaleVector (svtmp, WA);
@@ -986,7 +965,7 @@ void IR2Vec_FA::solveInsts(
986
965
IR2VEC_DEBUG (outs () << vec.back () << " \n " );
987
966
B.push_back (vec);
988
967
} else if (isa<BasicBlock>(inst->getOperand (i))) {
989
- Vector l;
968
+ Vector l (DIM, 0 ) ;
990
969
getValue (l, " label" );
991
970
auto svtmp = l;
992
971
scaleVector (svtmp, WA);
@@ -1001,7 +980,8 @@ void IR2Vec_FA::solveInsts(
1001
980
B.push_back (vec);
1002
981
} else {
1003
982
if (isa<Instruction>(inst->getOperand (i))) {
1004
- auto RD = getReachingDefs (inst, i);
983
+ SmallVector<const Instruction *, 10 > RD;
984
+ getReachingDefs (RD, inst, i);
1005
985
for (auto i : RD) {
1006
986
// Check if value of RD is precomputed
1007
987
if (instVecMap.find (i) == instVecMap.end ()) {
@@ -1031,7 +1011,7 @@ void IR2Vec_FA::solveInsts(
1031
1011
}
1032
1012
}
1033
1013
} else if (isa<PointerType>(inst->getOperand (i)->getType ())) {
1034
- Vector l;
1014
+ Vector l (DIM, 0 ) ;
1035
1015
getValue (l, " pointer" );
1036
1016
auto svtmp = l;
1037
1017
scaleVector (svtmp, WA);
@@ -1045,7 +1025,7 @@ void IR2Vec_FA::solveInsts(
1045
1025
IR2VEC_DEBUG (outs () << vec.back () << " \n " );
1046
1026
B.push_back (vec);
1047
1027
} else {
1048
- Vector l;
1028
+ Vector l (DIM, 0 ) ;
1049
1029
getValue (l, " variable" );
1050
1030
auto svtmp = l;
1051
1031
scaleVector (svtmp, WA);
@@ -1064,11 +1044,10 @@ void IR2Vec_FA::solveInsts(
1064
1044
}
1065
1045
}
1066
1046
1067
- for (unsigned i = 0 ; i < xI.size (); i++) {
1068
- std::vector<double > tmp (xI.size (), 0 );
1069
- A.push_back (tmp);
1070
- }
1047
+ std::vector<std::vector<double >> A (xI.size (),
1048
+ std::vector<double >(xI.size (), 0 ));
1071
1049
1050
+ #pragma omp parallel for
1072
1051
for (unsigned i = 0 ; i < xI.size (); i++) {
1073
1052
A[i][i] = 1 ;
1074
1053
auto tmp = A[i];
@@ -1078,6 +1057,7 @@ void IR2Vec_FA::solveInsts(
1078
1057
}
1079
1058
}
1080
1059
1060
+ #pragma omp parallel for collapse(2)
1081
1061
for (unsigned i = 0 ; i < B.size (); i++) {
1082
1062
for (unsigned j = 0 ; j < B[i].size (); j++) {
1083
1063
B[i][j] = (int )(B[i][j] * 10 ) / 10.0 ;
@@ -1171,7 +1151,8 @@ void IR2Vec_FA::solveSingleComponent(
1171
1151
getValue (vecOp, " label" );
1172
1152
} else {
1173
1153
if (isa<Instruction>(I.getOperand (i))) {
1174
- auto RD = getReachingDefs (&I, i);
1154
+ SmallVector<const Instruction *, 10 > RD;
1155
+ getReachingDefs (RD, &I, i);
1175
1156
RDList.insert (RDList.end (), RD.begin (), RD.end ());
1176
1157
} else if (isa<PointerType>(I.getOperand (i)->getType ())) {
1177
1158
getValue (vecOp, " pointer" );
@@ -1248,7 +1229,7 @@ void IR2Vec_FA::inst2Vec(
1248
1229
}
1249
1230
1250
1231
Vector instVector (DIM, 0 );
1251
- Vector vec;
1232
+ Vector vec (DIM, 0 ) ;
1252
1233
StringRef opcodeName = I.getOpcodeName ();
1253
1234
getValue (vec, opcodeName.str ());
1254
1235
IR2VEC_DEBUG (I.print (outs ()); outs () << " \n " );
@@ -1330,7 +1311,8 @@ void IR2Vec_FA::inst2Vec(
1330
1311
getValue (vecOp, " label" );
1331
1312
} else {
1332
1313
if (isa<Instruction>(I.getOperand (i))) {
1333
- auto RD = getReachingDefs (&I, i);
1314
+ SmallVector<const Instruction *, 10 > RD;
1315
+ getReachingDefs (RD, &I, i);
1334
1316
RDList.insert (RDList.end (), RD.begin (), RD.end ());
1335
1317
} else if (isa<PointerType>(I.getOperand (i)->getType ()))
1336
1318
getValue (vecOp, " pointer" );
0 commit comments