Skip to content

Commit

Permalink
Merge pull request #15 from MeowMJ/master
Browse files Browse the repository at this point in the history
isMAC() fixed
  • Loading branch information
tancheng authored Mar 7, 2024
2 parents 9cd5280 + 0b198c5 commit ff5a806
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
45 changes: 43 additions & 2 deletions src/DFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ void DFG::combineMulAdd() {
DFGNode* addNode = NULL;
bool found = false;
for (DFGNode* dfgNode: nodes) {
if (dfgNode->isMul() and dfgNode->isCritical() and !dfgNode->hasCombined()) {
if (dfgNode->isMul() and !dfgNode->hasCombined()) {
for (DFGNode* succNode: *(dfgNode->getSuccNodes())) {
if (succNode->isAdd() and succNode->isCritical() and !succNode->hasCombined()) {
if (succNode->isAdd() and !succNode->hasCombined()) {
mulNode = dfgNode;
mulNode->setCombine();
addNode = succNode;
Expand Down Expand Up @@ -175,6 +175,47 @@ 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<string>* t_targetPattern){
int patternSize = t_targetPattern->size();
string headOpt = string(t_targetPattern->front());
list<string>::iterator currentFunc = t_targetPattern->begin();
currentFunc++;
// toBeMatchedDFGNodes is to store the DFG nodes that match the pattern
list<DFGNode*>* toBeMatchedDFGNodes = new list<DFGNode*>[patternSize];
for (DFGNode* dfgNode: nodes) {
if (dfgNode->isOpt(headOpt) and !dfgNode->hasCombined()) {
toBeMatchedDFGNodes->push_back(dfgNode);
// the for loop below is to find the target pattern under specific dfgNode
for (int i = 1; i < patternSize; i++, currentFunc++){
string t_opt = *currentFunc;
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)){
toBeMatchedDFGNodes->push_back(succNode);
for(DFGNode* optNode: *toBeMatchedDFGNodes){
if(optNode != dfgNode){
dfgNode ->addPatternPartner(optNode);
}
optNode->setCombine();
}
break;
} else if(i == (patternSize-1) and !succNode->isSuccessorOf(dfgNode)){
continue;
} else{
toBeMatchedDFGNodes->push_back(succNode);
break;
}
}
}
}
toBeMatchedDFGNodes->clear();
}
}
}

bool DFG::shouldIgnore(Instruction* t_inst) {
if (m_targetFunction) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/DFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class DFG {
void combineMulAdd();
void combinePhiAdd();
void combine(string, string);
void combineForIter(list<string>*);
void trimForStandalone();
void detectMemDataDependency();
void eliminateOpcode(string);
Expand Down
17 changes: 10 additions & 7 deletions src/DFGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,16 @@ bool DFGNode::isSel() {
}

bool DFGNode::isMAC() {
if ((m_opcodeName.compare("getelementptr") == 0 or
m_opcodeName.compare("add") == 0 or
m_opcodeName.compare("fadd") == 0 or
m_opcodeName.compare("sub") == 0 or
m_opcodeName.compare("fsub") == 0) &&
(m_opcodeName.compare("fmul") == 0 or
m_opcodeName.compare("mul") == 0))
if (m_opcodeName.compare("mulgetelementptr") == 0 or
m_opcodeName.compare("muladd") == 0 or
m_opcodeName.compare("mulfadd") == 0 or
m_opcodeName.compare("mulsub") == 0 or
m_opcodeName.compare("mulfsub") == 0 or
m_opcodeName.compare("fmulgetelementptr") == 0 or
m_opcodeName.compare("fmuladd") == 0 or
m_opcodeName.compare("fmulfadd") == 0 or
m_opcodeName.compare("fmulsub") == 0 or
m_opcodeName.compare("fmulfsub") == 0)
return true;
return false;
}
Expand Down

0 comments on commit ff5a806

Please sign in to comment.