@@ -295,95 +295,6 @@ void DFG::tuneForPattern() {
295
295
}
296
296
}
297
297
298
- void DFG::tuneForDualIssueAfter () {
299
- // tuneForDualIssueAfter reconstruct the edge for dual issue after tuneForPattern().
300
- // the edges between the dualIssue-combined DFGNodes and its parents/children must be combined into one edge only.
301
- std::cout<<" [MMJ] tuneForDualIssueAfter is running " <<std::endl;
302
- for (DFGNode* dfgNode: nodes) {
303
- if (dfgNode->hasMerged () and !dfgNode->hasCombined ()){
304
- std::cout<<" [MMJ] dfgNode is " << dfgNode->getID () <<std::endl;
305
- for (DFGNode* predNode: *(dfgNode->getPredNodes ())) {
306
- // delete all edges between predNode and merged dfgNode
307
- DFGEdge* firstEdge = NULL ;
308
- while (hasDFGEdge (predNode, dfgNode)){
309
- if (firstEdge == NULL ) {
310
- firstEdge = getDFGEdge (predNode, dfgNode);
311
- }
312
- deleteDFGEdge (predNode, dfgNode);
313
- }
314
- // add the first edge back
315
- if (firstEdge){
316
- m_DFGEdges.push_back (firstEdge);
317
- }
318
- }
319
- }
320
- }
321
- }
322
-
323
- void DFG::tuneForDualIssue () {
324
- // tuneForDualIssue reconstruct the edge for dual issue without tuneForPattern()
325
- // the edges between the merged DFGNodes and its parents/children must be combined into one edge only.
326
- // reconstruct connected DFG by modifying m_DFGEdge
327
- std::cout<<" [MMJ] tuneForDualIssue is running " <<std::endl;
328
- list<DFGNode*>* removeNodes = new list<DFGNode*>();
329
- for (DFGNode* dfgNode: nodes) {
330
- if (dfgNode->hasMerged () and !dfgNode->hasCombined ()) {
331
- if (dfgNode->isPatternRoot ()) {
332
- std::cout<<" [MMJ] dfgNode is " << dfgNode->getID () <<std::endl;
333
- for (DFGNode* patternNode: *(dfgNode->getPatternNodes ())) {
334
- std::cout<<" [MMJ] patternNode is " << patternNode->getID () <<std::endl;
335
- if (hasDFGEdge (dfgNode, patternNode))
336
- m_DFGEdges.remove (getDFGEdge (dfgNode, patternNode));
337
-
338
- for (DFGNode* predNode: *(patternNode->getPredNodes ())) {
339
- // we only keep one edge between dfgNode and predNode
340
- if (predNode == dfgNode or
341
- predNode->isOneOfThem (dfgNode->getPatternNodes ())) {
342
- deleteDFGEdge (predNode, patternNode);
343
- continue ;
344
- }
345
- DFGNode* newPredNode = NULL ;
346
- if (predNode->hasMerged () or predNode->hasCombined ())
347
- newPredNode = predNode->getPatternRoot ();
348
- else
349
- newPredNode = predNode;
350
- replaceDFGEdge (predNode, patternNode, newPredNode, dfgNode);
351
- }
352
-
353
- for (DFGNode* succNode: *(patternNode->getSuccNodes ())) {
354
- std::cout<<" [MMJ] succNode is " << succNode->getID () <<std::endl;
355
- if (succNode == dfgNode or
356
- succNode->isOneOfThem (dfgNode->getPatternNodes ())) {
357
- deleteDFGEdge (patternNode, succNode);
358
- continue ;
359
- }
360
- DFGNode* newSuccNode = NULL ;
361
- if (succNode->hasMerged () or succNode->hasCombined ())
362
- newSuccNode = succNode->getPatternRoot ();
363
- else
364
- newSuccNode = succNode;
365
- replaceDFGEdge (patternNode, succNode, dfgNode, newSuccNode);
366
- }
367
- }
368
- } else {
369
- removeNodes->push_back (dfgNode);
370
- }
371
- }
372
- }
373
- for (DFGNode* dfgNode: *removeNodes) {
374
- nodes.remove (dfgNode);
375
- }
376
- }
377
-
378
- void DFG::ESCORT () {
379
- dualIssueNew (2 ,100 );
380
- // If dualIssueNew fails
381
- dualIssue (3 ,100 );
382
- tuneForDualIssue ();
383
- tuneForDualIssueAfter ();
384
- return ;
385
- }
386
-
387
298
void DFG::combineCmpBranch () {
388
299
// detect patterns (e.g., cmp+branch)
389
300
DFGNode* addNode = NULL ;
@@ -645,223 +556,6 @@ void DFG::combineForUnroll(string type) {
645
556
}
646
557
}
647
558
648
- // combineSuccSame combines DFGNodes of same opcodeName with a same parent.
649
- // Note that the edges between the same parent and the input DFGNodes will be combined into one edge.
650
- // Note the pathName of DFGNodes must be different.
651
- void DFG::combineSuccSame (const list<DFGNode*>* t_sameSuccNode, const int t_mergeSize){
652
- std::cout <<" [MMJ] combineSuccSame is running " << std::endl;
653
- // choose DFGNode in t_sameSuccNode with different pathName
654
- list<DFGNode*>* uniqueNodes;
655
- map<string, list<DFGNode*>> pathNameMap;
656
- for (DFGNode* dfgNode: *t_sameSuccNode){
657
- std::cout <<" [MMJ] t_sameSuccNode dfgNode " << dfgNode->getID () << std::endl;
658
- if (!pathNameMap.count (dfgNode->getPathName ())){
659
- pathNameMap[dfgNode->getPathName ()].push_back (dfgNode);
660
- uniqueNodes->push_back (dfgNode);
661
- std::cout <<" [MMJ] uniqueNodes dfgNode " << dfgNode->getID () << std::endl;
662
- }
663
- }
664
-
665
- // merge uniqueNodes (size must > 1)
666
- if (uniqueNodes->size () == 1 ){
667
- std::cout <<" [MMJ] combineSuccSame uniqueNodes.size() == 1 " << std::endl;
668
- return ;
669
- }
670
-
671
- int mergeCount = 0 ;
672
- DFGNode* headNode = uniqueNodes->front ();
673
- std::cout <<" [MMJ] headNode" << headNode->getID () << std::endl;
674
- for (DFGNode* dfgNode: *uniqueNodes){
675
- std::cout <<" [MMJ] uniqueNodes next" << dfgNode->getID () << std::endl;
676
- if (dfgNode != headNode and !dfgNode->hasMerged () and !dfgNode->hasCombined ()){
677
- headNode ->addPatternPartner (dfgNode);
678
- }
679
- dfgNode->setMerge ();
680
- std::cout <<" [MMJ] dual Issue combine " << dfgNode->getID () << std::endl;
681
- mergeCount++;
682
- if (mergeCount == t_mergeSize) {
683
- // combined DFGNode number <= t_mergeSize
684
- break ;
685
- }
686
- }
687
- uniqueNodes->clear ();
688
- // the handling of edges is in tuneForDualIssue()
689
- return ;
690
- }
691
-
692
- // findOpSameSucc finds nodes that are the same after br, t_mergeSize decides the max number of nodes that can be combined
693
- bool DFG::findOpSameSucc (const list<DFGNode*>* t_succList, const int t_mergeSize) {
694
- std::cout <<" [MMJ] findOpSameSucc is running " << std::endl;
695
- bool found = false ;
696
- map<string, list<DFGNode*>> opcodeNameMap;
697
-
698
- // map succeed DFGNode with their operation name
699
- for (DFGNode* succNode: *t_succList) {
700
- opcodeNameMap[succNode->getOpcodeName ()].push_back (succNode);
701
- }
702
- // combine succeed DFGNodes with number <= t_mergeSize
703
- for (auto & pair: opcodeNameMap) {
704
- if (pair.second .size () > 1 ) {
705
- combineSuccSame (&pair.second , t_mergeSize);
706
- found = true ;
707
- }
708
- }
709
- return found;
710
- }
711
-
712
- // findOpSucc finds nodes br which means the nodes are from different paths, t_mergeSize decides the max number of nodes that can be combined
713
- void DFG::findOpSucc (const list<DFGNode*>* t_succList, const int t_mergeSize) {
714
- // std::cout <<"[MMJ] findOpSucc is running "<< std::endl;
715
- // list<DFGNode*>* uniqueNodes;
716
- // list<DFGNode*> succUniqueNodes;
717
- // uniqueNodes = combineSuccSame(t_succList, t_mergeSize);
718
- // // after merge nodes after br, we merge succeed nodes of the merged nodes
719
- // while (true){
720
- // for (DFGNode* dfgNode: *uniqueNodes){
721
- // for (DFGNode* succNode: *(dfgNode->getSuccNodes())){
722
- // if (succNode->getPathName() == dfgNode->getPathName()){
723
- // // find succNodes of uniqueNodes and succNodes must in the same path with uniqueNodes
724
- // succUniqueNodes.push_back(succNode);
725
- // }
726
- // }
727
- // }
728
- // uniqueNodes = combineSuccSame(&succUniqueNodes, t_mergeSize);
729
- // succUniqueNodes.clear();
730
- // if (uniqueNodes == NULL){
731
- // // finish if no uniqueNodes to be combined
732
- // std::cout <<"[MMJ] break the findOpSucc"<< std::endl;
733
- // break;
734
- // }
735
- // }
736
- return ;
737
- }
738
-
739
- // dualIssue is used to identify 'br' with multiple output, it combines the ouput together with the same control edge.
740
- // Note that the control edge is only one bit width since there is noly one 'br' input.
741
- // Note that dualIssue must be done after other combine operation.
742
- void DFG::dualIssue (const int t_mergeSize, const int t_mergeCount){
743
- // testBench: adpcmkernel's 'br-3phi'
744
- // toBeMatchedDFGNodes is to store the DFG nodes after br
745
- std::cout <<" [MMJ] dual Issue is running. " <<std::endl;
746
- list<DFGNode*>* toBeMatchedDFGNodes = new list<DFGNode*>();
747
- int countPartialMerge = 1 ;
748
- for (DFGNode* dfgNode: nodes) {
749
- if (countPartialMerge > t_mergeCount){
750
- return ;
751
- }
752
- // we support both br and switch
753
- if ((dfgNode->isBranch () or dfgNode->isOpt (" switch" )) and !dfgNode->hasMerged ()) {
754
- bool found = false ;
755
- std::cout <<" [MMJ] dual Issue finds the br/switch " << dfgNode->getID () << std::endl;
756
- for (DFGNode* succNode: *(dfgNode->getSuccNodes ())) {
757
- if (!succNode->hasMerged () and !succNode->hasCombined ()){
758
- toBeMatchedDFGNodes->push_back (succNode);
759
- }
760
- }
761
- // find nodes that are the same after br
762
- found = findOpSameSucc (toBeMatchedDFGNodes, t_mergeSize);
763
- countPartialMerge++;
764
- }
765
- // clear toBeMatchedDFGNodes and find the next br/switch
766
- toBeMatchedDFGNodes->clear ();
767
- }
768
- }
769
-
770
-
771
- // findIFELPath finds succeed nodes after br with different path
772
- void DFG::findIFELPath (list<DFGNode*>* t_succList, const int t_mergeSize) {
773
- std::cout <<" [MMJ] findIFELPath is running " << std::endl;
774
- map<string, list<DFGNode*>> pathNameMap;
775
- for (DFGNode* dfgNode: *t_succList){
776
- std::cout <<" [MMJ] t_succList dfgNode " << dfgNode->getID () << std::endl;
777
- if (!dfgNode->hasMerged () and !dfgNode->hasCombined ()){
778
- pathNameMap[dfgNode->getPathName ()].push_back (dfgNode);
779
- }
780
- }
781
-
782
- for (auto & pair: pathNameMap) {
783
- // sort every path by name to make similar names adjacent
784
- pair.second .sort ([](DFGNode* a, DFGNode* b) {
785
- return a->getOpcodeName () < b->getOpcodeName ();
786
- });
787
- }
788
-
789
- list<DFGNode*> diffPathNode;
790
- while (true ){
791
- for (auto & pair: pathNameMap) {
792
- if (pair.second .empty ()){
793
- // if there is no node in this path, pass
794
- continue ;
795
- }
796
- diffPathNode.push_back (pair.second .front ());
797
- pair.second .pop_front ();
798
- }
799
- if (diffPathNode.empty ()){
800
- std::cout <<" [MMJ] findIFELPath is finished " << std::endl;
801
- return ;
802
- }
803
- pathMerge (&diffPathNode, t_mergeSize);
804
- diffPathNode.clear ();
805
- }
806
- }
807
-
808
- // pathMerge is used to merge exclusive pathes
809
- void DFG::pathMerge (list<DFGNode*>* t_diffPathNode, const int t_mergeSize){
810
- std::cout <<" [MMJ] pathMerge is running " << std::endl;
811
- // choose DFGNode in t_sameSuccNode with different pathName
812
- if (t_diffPathNode->size () < 2 ){
813
- // pathMerge is finished.
814
- std::cout <<" [MMJ] pathMerge is finished " << std::endl;
815
- return ;
816
- }
817
- list<DFGNode*> pathSucc;
818
- for (DFGNode* dfgNode: *t_diffPathNode){
819
- for (DFGNode* succNode: *(dfgNode->getSuccNodes ())){
820
- if ((succNode->getPathName () == dfgNode->getPathName ()) and !succNode->hasMerged () and !succNode->hasCombined ()){
821
- // only add one succNode that is along the path of current dfgNode
822
- pathSucc.push_back (succNode);
823
- break ;
824
- }
825
- }
826
- }
827
- int mergeCount = 0 ;
828
- DFGNode* headNode = t_diffPathNode->front ();
829
- for (DFGNode* dfgNode: *t_diffPathNode){
830
- if (dfgNode != headNode and !dfgNode->hasMerged () and !dfgNode->hasCombined ()){
831
- headNode ->addPatternPartner (dfgNode);
832
- }
833
- dfgNode->setMerge ();
834
- std::cout <<" [MMJ] dual Issue combine " << dfgNode->getID () << std::endl;
835
- mergeCount++;
836
- if (mergeCount == t_mergeSize) {
837
- // combined DFGNode number <= t_mergeSize
838
- break ;
839
- }
840
- }
841
- pathMerge (&pathSucc, t_mergeSize);
842
- pathSucc.clear ();
843
- }
844
-
845
- // dualIssueNew is used to identify 'br' with multiple output, it combines the ouput together with the same control edge.
846
- // Note that the control edge is only one bit width since there is noly one 'br' input.
847
- // Note that dualIssue must be done after other combine operation.
848
- void DFG::dualIssueNew (const int t_mergeSize, const int t_mergeCount){
849
- // testBench: nwkernel's 'add-sext-ge'
850
- // toBeMatchedDFGNodes is to store the DFG nodes after br
851
- std::cout <<" [MMJ] dualIssueNew is running. " <<std::endl;
852
- int countPartialMerge = 1 ;
853
- for (DFGNode* dfgNode: nodes) {
854
- if (countPartialMerge > t_mergeCount){
855
- return ;
856
- }
857
- if ((dfgNode->isBranch () or dfgNode->isOpt (" switch" )) and !dfgNode->hasMerged ()) {
858
- findIFELPath (dfgNode->getSuccNodes (), t_mergeSize);
859
- countPartialMerge++;
860
- }
861
- }
862
- }
863
-
864
-
865
559
bool DFG::shouldIgnore (Instruction* t_inst) {
866
560
if (m_targetFunction) {
867
561
return false ;
0 commit comments