From 7a97486d61c19d860b707dffff2ddae9c2daabab Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:29:11 +0800 Subject: [PATCH 01/15] Update DFG::combineForIter() --- src/DFG.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/DFG.cpp b/src/DFG.cpp index 0489be5..ec5170b 100644 --- a/src/DFG.cpp +++ b/src/DFG.cpp @@ -176,7 +176,7 @@ void DFG::combine(string t_opt0, string t_opt1) { } // Combines patterns provided by users which should be a cycle, otherwise, the fusion won't be performed. -void DFG::combineForIter(list* t_targetPattern){ +void DFG::combineForIter(list* t_targetPattern){ int patternSize = t_targetPattern->size(); string headOpt = string(t_targetPattern->front()); list::iterator currentFunc = t_targetPattern->begin(); @@ -192,17 +192,18 @@ void DFG::combineForIter(list* t_targetPattern){ DFGNode* tailNode = toBeMatchedDFGNodes->back(); for (DFGNode* succNode: *(tailNode->getSuccNodes())) { if (succNode->isOpt(t_opt) and !succNode->hasCombined()) { - // Indicate the pattern is finally found and matched - if (i == (patternSize-1) and succNode->isSuccessorOf(dfgNode)){ + if (i == (patternSize-1) and dfgNode->isSuccessorOf(succNode)){ toBeMatchedDFGNodes->push_back(succNode); for(DFGNode* optNode: *toBeMatchedDFGNodes){ - if(optNode != dfgNode){ - dfgNode ->addPatternPartner(optNode); + if(optNode == dfgNode){ + optNode->setCombine(); + } else{ + dfgNode->addPatternPartner(optNode); + optNode->setCombine(); } - optNode->setCombine(); } break; - } else if(i == (patternSize-1) and !succNode->isSuccessorOf(dfgNode)){ + } else if(i == (patternSize-1) and !dfgNode->isSuccessorOf(succNode)){ continue; } else{ toBeMatchedDFGNodes->push_back(succNode); @@ -212,6 +213,8 @@ void DFG::combineForIter(list* t_targetPattern){ } } toBeMatchedDFGNodes->clear(); + currentFunc = t_targetPattern->begin(); + currentFunc++; } } } From 4486503df73fba9e4f787adb6263cf795d9dfa0f Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:41:06 +0800 Subject: [PATCH 02/15] Update DFG::combineForIter() --- src/DFG.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/DFG.cpp b/src/DFG.cpp index ec5170b..d4a2aae 100644 --- a/src/DFG.cpp +++ b/src/DFG.cpp @@ -176,7 +176,7 @@ void DFG::combine(string t_opt0, string t_opt1) { } // Combines patterns provided by users which should be a cycle, otherwise, the fusion won't be performed. -void DFG::combineForIter(list* t_targetPattern){ +void DFG::combineForIter(list* t_targetPattern){ int patternSize = t_targetPattern->size(); string headOpt = string(t_targetPattern->front()); list::iterator currentFunc = t_targetPattern->begin(); @@ -192,15 +192,14 @@ void DFG::combineForIter(list* t_targetPattern){ DFGNode* tailNode = toBeMatchedDFGNodes->back(); for (DFGNode* succNode: *(tailNode->getSuccNodes())) { if (succNode->isOpt(t_opt) and !succNode->hasCombined()) { + // Indicate the pattern is finally found and matched if (i == (patternSize-1) and dfgNode->isSuccessorOf(succNode)){ toBeMatchedDFGNodes->push_back(succNode); for(DFGNode* optNode: *toBeMatchedDFGNodes){ - if(optNode == dfgNode){ - optNode->setCombine(); - } else{ - dfgNode->addPatternPartner(optNode); - optNode->setCombine(); + if(optNode != dfgNode){ + dfgNode ->addPatternPartner(optNode); } + optNode->setCombine(); } break; } else if(i == (patternSize-1) and !dfgNode->isSuccessorOf(succNode)){ From 8882f056d0e8fbe4f10148dbfacf0224ef0ad6bd Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:13:21 +0800 Subject: [PATCH 03/15] Update DFGNode::addConst(int) --- src/DFGNode.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DFGNode.h b/src/DFGNode.h index a4d0818..fbfaa74 100644 --- a/src/DFGNode.h +++ b/src/DFGNode.h @@ -101,6 +101,7 @@ class DFGNode { void setInEdge(DFGEdge*); void setOutEdge(DFGEdge*); void cutEdges(); + void addConst(int); // combineForUnroll string getJSONOpt(); string getFuType(); void addConst(); From ad36ab54f30c22370a7fd386f9c0f09447f2b389 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:15:34 +0800 Subject: [PATCH 04/15] Update DFGNode::addConst(int) --- src/DFGNode.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/DFGNode.cpp b/src/DFGNode.cpp index 60fd62a..11eabff 100644 --- a/src/DFGNode.cpp +++ b/src/DFGNode.cpp @@ -31,6 +31,7 @@ DFGNode::DFGNode(int t_id, bool t_precisionAware, Instruction* t_inst, m_execLatency = 1; m_pipelinable = false; m_isPredicatee = false; + m_addConst = 0; // combineForUnroll m_predicatees = NULL; m_isPredicater = false; m_patternNodes = new list(); @@ -527,6 +528,10 @@ void DFGNode::cutEdges() { } } +void DFGNode::addConst(int t_const){ // combineForUnroll + m_addConst = t_const; +} + bool DFGNode::isSuccessorOf(DFGNode* t_dfgNode) { list* succNodes = t_dfgNode->getSuccNodes(); if (find (succNodes->begin(), succNodes->end(), this) != succNodes->end()) From fec0c3887989d97a54f1c6a5603ce06344c31f06 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:16:24 +0800 Subject: [PATCH 05/15] Update DFGNode::m_addConst --- src/DFGNode.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DFGNode.h b/src/DFGNode.h index fbfaa74..343c8af 100644 --- a/src/DFGNode.h +++ b/src/DFGNode.h @@ -57,6 +57,8 @@ class DFGNode { // "m_predicated" indicates whether the execution of the node depends on // predication or not (i.e., the predecessor probably is a "branch"). bool m_isPredicatee; + // combineForUnroll(): "m_addConst" indicates the const in "add+const" node + int m_addConst; list* m_predicatees; bool m_isPredicater; DFGNode* m_patternRoot; From 9e0d259afc47c37d977694f18d745c570166e836 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:18:09 +0800 Subject: [PATCH 06/15] Update DFG::addDFGEdge and DFG::combineForUnroll --- src/DFG.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DFG.h b/src/DFG.h index a4d4435..85a123d 100644 --- a/src/DFG.h +++ b/src/DFG.h @@ -52,6 +52,7 @@ class DFG { DFGEdge* getDFGEdge(DFGNode*, DFGNode*); void deleteDFGEdge(DFGNode*, DFGNode*); void replaceDFGEdge(DFGNode*, DFGNode*, DFGNode*, DFGNode*); + void addDFGEdge(DFGNode*,DFGNode*); // combineForUnroll bool hasDFGEdge(DFGNode*, DFGNode*); DFGEdge* getCtrlEdge(DFGNode*, DFGNode*); bool hasCtrlEdge(DFGNode*, DFGNode*); @@ -65,6 +66,7 @@ class DFG { void combinePhiAdd(); void combine(string, string); void combineForIter(list*); + void combineForUnroll(list*); //combineForUnroll void trimForStandalone(); void detectMemDataDependency(); void eliminateOpcode(string); From 32a60440fa5d855de75e4ebfd9839a535b4005ce Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:19:45 +0800 Subject: [PATCH 07/15] Update DFG::addDFGEdge and DFG::combineForUnroll --- src/DFG.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/DFG.cpp b/src/DFG.cpp index d4a2aae..85da3e9 100644 --- a/src/DFG.cpp +++ b/src/DFG.cpp @@ -218,6 +218,57 @@ void DFG::combineForIter(list* t_targetPattern){ } } +void DFG::combineForUnroll(list* t_targetPattern){ + // combineForUnroll is used to reconstruct "phi-add-add-..." alike patterns provided by users which should be a cycle, otherwise, the fusion won't be performed. + int patternSize = t_targetPattern->size(); + string headOpt = string(t_targetPattern->front()); + list::iterator currentFunc = t_targetPattern->begin(); + currentFunc++; + // toBeMatchedDFGNodes is to store the DFG nodes that match the pattern + list* toBeMatchedDFGNodes = new list[patternSize]; + for (DFGNode* dfgNode: nodes) { + if (dfgNode->isOpt(headOpt) and !dfgNode->hasCombined() and dfgNode->getID() != 1) { + toBeMatchedDFGNodes->push_back(dfgNode); + std::cout<<"\033[32m I find \033[0m" << dfgNode->getID() <back(); + for (DFGNode* succNode: *(tailNode->getSuccNodes())) { + std::cout<<"\033[32m I find \033[0m" << succNode->getID() <isOpt(t_opt) and !succNode->hasCombined()) { + if (i == (patternSize-1) and dfgNode->isSuccessorOf(succNode)){ + toBeMatchedDFGNodes->push_back(succNode); + // find a phi-add-add-... + // new add_const(DFGNode) + std::cout<<"\033[31m I find phi-add-add \033[0m" <getID(); + bool newAddPrecisionAware = 1; // a test + Instruction* newAddInst = succNode->getInst(); + StringRef newAddStrRef = succNode->getStringRef(); + DFGNode* newAddNode = new DFGNode(newAddNodeID++, newAddPrecisionAware, newAddInst, newAddStrRef); // succeed from the last node + newAddNode -> addConst(patternSize-1); + nodes.push_back(newAddNode); + // reconsturct edges + replaceDFGEdge(succNode, dfgNode, newAddNode, dfgNode); + addDFGEdge(dfgNode, newAddNode); + break; + } else if(i == (patternSize-1) and !dfgNode->isSuccessorOf(succNode)){ + continue; + } else{ + toBeMatchedDFGNodes->push_back(succNode); + break; + } + } + } + } + toBeMatchedDFGNodes->clear(); + currentFunc = t_targetPattern->begin(); + currentFunc++; + } + } +} + bool DFG::shouldIgnore(Instruction* t_inst) { if (m_targetFunction) { return false; @@ -1204,6 +1255,12 @@ void DFG::replaceDFGEdge(DFGNode* t_old_src, DFGNode* t_old_dst, m_DFGEdges.push_back(newEdge); } +void DFG::addDFGEdge(DFGNode* t_src, DFGNode* t_dst){ // combineForUnroll + int newEdgeID = (m_DFGEdges.back())->getID(); + DFGEdge* newEdge = new DFGEdge(newEdgeID, t_src, t_dst); + m_DFGEdges.push_back(newEdge); +} + void DFG::deleteDFGEdge(DFGNode* t_src, DFGNode* t_dst) { if (!hasDFGEdge(t_src, t_dst)) return; m_DFGEdges.remove(getDFGEdge(t_src, t_dst)); From 749eb91324a16e4655f6499f984a496522b359b8 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:58:45 -0700 Subject: [PATCH 08/15] Update DFG::CombineForUnroll --- src/DFG.cpp | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/DFG.cpp b/src/DFG.cpp index 85da3e9..9e3c387 100644 --- a/src/DFG.cpp +++ b/src/DFG.cpp @@ -219,8 +219,13 @@ void DFG::combineForIter(list* t_targetPattern){ } void DFG::combineForUnroll(list* t_targetPattern){ - // combineForUnroll is used to reconstruct "phi-add-add-..." alike patterns provided by users which should be a cycle, otherwise, the fusion won't be performed. + // combineForUnroll is used to reconstruct "phi-add-add-..." alike patterns, otherwise, the fusion won't be performed. int patternSize = t_targetPattern->size(); + if (patternSize > 4){ + std::cout<<"\033[32m [Erro] The pattern is too long! \033[0m" <front()); list::iterator currentFunc = t_targetPattern->begin(); currentFunc++; @@ -229,32 +234,21 @@ void DFG::combineForUnroll(list* t_targetPattern){ for (DFGNode* dfgNode: nodes) { if (dfgNode->isOpt(headOpt) and !dfgNode->hasCombined() and dfgNode->getID() != 1) { toBeMatchedDFGNodes->push_back(dfgNode); - std::cout<<"\033[32m I find \033[0m" << dfgNode->getID() <back(); for (DFGNode* succNode: *(tailNode->getSuccNodes())) { - std::cout<<"\033[32m I find \033[0m" << succNode->getID() <isOpt(t_opt) and !succNode->hasCombined()) { - if (i == (patternSize-1) and dfgNode->isSuccessorOf(succNode)){ + if (i == (patternSize-1)){ toBeMatchedDFGNodes->push_back(succNode); - // find a phi-add-add-... - // new add_const(DFGNode) - std::cout<<"\033[31m I find phi-add-add \033[0m" <getID(); - bool newAddPrecisionAware = 1; // a test - Instruction* newAddInst = succNode->getInst(); - StringRef newAddStrRef = succNode->getStringRef(); - DFGNode* newAddNode = new DFGNode(newAddNodeID++, newAddPrecisionAware, newAddInst, newAddStrRef); // succeed from the last node - newAddNode -> addConst(patternSize-1); - nodes.push_back(newAddNode); - // reconsturct edges - replaceDFGEdge(succNode, dfgNode, newAddNode, dfgNode); - addDFGEdge(dfgNode, newAddNode); + for(DFGNode* optNode: *toBeMatchedDFGNodes){ + if(optNode != dfgNode){ + dfgNode ->addPatternPartner(optNode); + } + optNode->setCombine(); + } break; - } else if(i == (patternSize-1) and !dfgNode->isSuccessorOf(succNode)){ - continue; } else{ toBeMatchedDFGNodes->push_back(succNode); break; @@ -1255,12 +1249,6 @@ void DFG::replaceDFGEdge(DFGNode* t_old_src, DFGNode* t_old_dst, m_DFGEdges.push_back(newEdge); } -void DFG::addDFGEdge(DFGNode* t_src, DFGNode* t_dst){ // combineForUnroll - int newEdgeID = (m_DFGEdges.back())->getID(); - DFGEdge* newEdge = new DFGEdge(newEdgeID, t_src, t_dst); - m_DFGEdges.push_back(newEdge); -} - void DFG::deleteDFGEdge(DFGNode* t_src, DFGNode* t_dst) { if (!hasDFGEdge(t_src, t_dst)) return; m_DFGEdges.remove(getDFGEdge(t_src, t_dst)); From 22691eb6c5dab6d98ca5fae17ae5b45d8fa9f626 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:59:06 -0700 Subject: [PATCH 09/15] Update DFG.h --- src/DFG.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DFG.h b/src/DFG.h index 85a123d..6854e27 100644 --- a/src/DFG.h +++ b/src/DFG.h @@ -52,7 +52,6 @@ class DFG { DFGEdge* getDFGEdge(DFGNode*, DFGNode*); void deleteDFGEdge(DFGNode*, DFGNode*); void replaceDFGEdge(DFGNode*, DFGNode*, DFGNode*, DFGNode*); - void addDFGEdge(DFGNode*,DFGNode*); // combineForUnroll bool hasDFGEdge(DFGNode*, DFGNode*); DFGEdge* getCtrlEdge(DFGNode*, DFGNode*); bool hasCtrlEdge(DFGNode*, DFGNode*); From e9087458a61f39f2afd2c6ace71efb57d2d3cac5 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:05:27 -0700 Subject: [PATCH 10/15] Update DFG::CombineForUnroll --- src/DFG.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DFG.cpp b/src/DFG.cpp index 9e3c387..763994e 100644 --- a/src/DFG.cpp +++ b/src/DFG.cpp @@ -218,11 +218,11 @@ void DFG::combineForIter(list* t_targetPattern){ } } +// combineForUnroll is used to reconstruct "phi-add-add-..." alike patterns with a limited length. void DFG::combineForUnroll(list* t_targetPattern){ - // combineForUnroll is used to reconstruct "phi-add-add-..." alike patterns, otherwise, the fusion won't be performed. int patternSize = t_targetPattern->size(); if (patternSize > 4){ - std::cout<<"\033[32m [Erro] The pattern is too long! \033[0m" < Date: Mon, 10 Jun 2024 11:06:18 -0700 Subject: [PATCH 11/15] Delete add_Const and addConst() --- src/DFGNode.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/DFGNode.h b/src/DFGNode.h index 343c8af..a4d0818 100644 --- a/src/DFGNode.h +++ b/src/DFGNode.h @@ -57,8 +57,6 @@ class DFGNode { // "m_predicated" indicates whether the execution of the node depends on // predication or not (i.e., the predecessor probably is a "branch"). bool m_isPredicatee; - // combineForUnroll(): "m_addConst" indicates the const in "add+const" node - int m_addConst; list* m_predicatees; bool m_isPredicater; DFGNode* m_patternRoot; @@ -103,7 +101,6 @@ class DFGNode { void setInEdge(DFGEdge*); void setOutEdge(DFGEdge*); void cutEdges(); - void addConst(int); // combineForUnroll string getJSONOpt(); string getFuType(); void addConst(); From 819e789e41da9f0b904b2343cbcc01d6690d4258 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:07:08 -0700 Subject: [PATCH 12/15] Delete m_addConst and addConst() --- src/DFGNode.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/DFGNode.cpp b/src/DFGNode.cpp index 11eabff..60fd62a 100644 --- a/src/DFGNode.cpp +++ b/src/DFGNode.cpp @@ -31,7 +31,6 @@ DFGNode::DFGNode(int t_id, bool t_precisionAware, Instruction* t_inst, m_execLatency = 1; m_pipelinable = false; m_isPredicatee = false; - m_addConst = 0; // combineForUnroll m_predicatees = NULL; m_isPredicater = false; m_patternNodes = new list(); @@ -528,10 +527,6 @@ void DFGNode::cutEdges() { } } -void DFGNode::addConst(int t_const){ // combineForUnroll - m_addConst = t_const; -} - bool DFGNode::isSuccessorOf(DFGNode* t_dfgNode) { list* succNodes = t_dfgNode->getSuccNodes(); if (find (succNodes->begin(), succNodes->end(), this) != succNodes->end()) From 19201a8ee32087d9344d81e8ee561a56007d53e0 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:09:45 -0700 Subject: [PATCH 13/15] Add comments on combineForUnroll --- src/DFG.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DFG.h b/src/DFG.h index 6854e27..30321d6 100644 --- a/src/DFG.h +++ b/src/DFG.h @@ -65,7 +65,8 @@ class DFG { void combinePhiAdd(); void combine(string, string); void combineForIter(list*); - void combineForUnroll(list*); //combineForUnroll + // combineForUnroll is used to reconstruct "phi-add-add-..." alike patterns with a limited length. + void combineForUnroll(list*); void trimForStandalone(); void detectMemDataDependency(); void eliminateOpcode(string); From 1d864a835ebe037b2566557c87fc0f0f0c141db9 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Wed, 12 Jun 2024 18:29:07 -0700 Subject: [PATCH 14/15] Update DFG::replaceDFGEdge() --- src/DFG.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/DFG.cpp b/src/DFG.cpp index 763994e..8173ca5 100644 --- a/src/DFG.cpp +++ b/src/DFG.cpp @@ -1245,8 +1245,11 @@ void DFG::replaceDFGEdge(DFGNode* t_old_src, DFGNode* t_old_dst, if (target == NULL) assert("ERROR cannot find the corresponding DFG edge."); m_DFGEdges.remove(target); - DFGEdge* newEdge = new DFGEdge(target->getID(), t_new_src, t_new_dst); + DFGEdge* newEdge = new DFGEdge(target->getID(), t_new_src, t_new_dst, target->isCtrlEdge()); m_DFGEdges.push_back(newEdge); + if (newEdge->isCtrlEdge()){ + m_ctrlEdges.push_back(newEdge); + } } void DFG::deleteDFGEdge(DFGNode* t_src, DFGNode* t_dst) { From 9746972241abd145d67ba48887e232645ee1aac9 Mon Sep 17 00:00:00 2001 From: MeowMJ <131838721+MeowMJ@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:47:28 -0700 Subject: [PATCH 15/15] Update DFG::replaceDFGEdge() to keep the ctrl property of the original edge on the newly added edge --- src/DFG.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DFG.cpp b/src/DFG.cpp index 8173ca5..98dd7d1 100644 --- a/src/DFG.cpp +++ b/src/DFG.cpp @@ -1245,6 +1245,7 @@ void DFG::replaceDFGEdge(DFGNode* t_old_src, DFGNode* t_old_dst, if (target == NULL) assert("ERROR cannot find the corresponding DFG edge."); m_DFGEdges.remove(target); + // Keeps the ctrl property of the original edge on the newly added edge. DFGEdge* newEdge = new DFGEdge(target->getID(), t_new_src, t_new_dst, target->isCtrlEdge()); m_DFGEdges.push_back(newEdge); if (newEdge->isCtrlEdge()){