Commit 0560fb47 authored by Anirudh's avatar Anirudh
Browse files

Code for scheduling

parent 8f63b468
...@@ -18,7 +18,9 @@ add_library (libsystemc-clang ...@@ -18,7 +18,9 @@ add_library (libsystemc-clang
FindNetlist.cpp FindNetlist.cpp
FindArgument.cpp FindArgument.cpp
Automata.cpp Automata.cpp
SuspensionAutomata.cpp SuspensionAutomata.cpp
SCuitable/GlobalSuspensionAutomata.cpp
SCuitable/FindGPUMacro.cpp
#################################### ####################################
#From here the files are for the reflection database #From here the files are for the reflection database
#################################### ####################################
......
#ifndef _FIND_ARGUMENT_ #ifndef _FIND_ARGUMENT_
#define _FIND_ARGUEMNT_ #define _FIND_ARGUMENT_
#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclCXX.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
......
...@@ -360,11 +360,11 @@ void SuspensionAutomata::genSusCFG() ...@@ -360,11 +360,11 @@ void SuspensionAutomata::genSusCFG()
bool foundWait = false; bool foundWait = false;
vector < CFGBlock * >splitBlocksVector; vector < CFGBlock * >splitBlocksVector;
/* /*
_os << "==========================================================\n"; _os << "==========================================================\n";
_os << "Dump CFG Block\n"; _os << "Dump CFG Block\n";
b->dump(_cfg, LO, false); b->dump(_cfg, LO, false);
*/ */
unsigned int prevCFGBlockID; unsigned int prevCFGBlockID;
for (CFGBlock::const_iterator bit = b->begin(), bite = b->end(); for (CFGBlock::const_iterator bit = b->begin(), bite = b->end();
...@@ -546,22 +546,30 @@ void SuspensionAutomata::genSusCFG() ...@@ -546,22 +546,30 @@ void SuspensionAutomata::genSusCFG()
} }
void SuspensionAutomata::addRemainingBlocks(State *initialState, vector<SusCFG*>& transitionBlocks){
bool duplicate = false;
if (_stateCommonCodeBlockMap.find(initialState) != _stateCommonCodeBlockMap.end()) {
stateCommonCodeBlockMapType::iterator stateFound = _stateCommonCodeBlockMap.find(initialState);
checkInsert(stateFound->second, transitionBlocks);
}
}
vector<SusCFG*> SuspensionAutomata::modifDFS(SusCFG * block, State *initialState) vector<SusCFG*> SuspensionAutomata::modifDFS(SusCFG * block, State *initialState)
{ {
deque < SusCFG * >traversedBlocks; deque < SusCFG * >traversedBlocks;
vector < SusCFG * >visitedBlocks; vector < SusCFG * >visitedBlocks;
traversedBlocks.push_front(block); traversedBlocks.push_front(block);
bool isWaitEncounter = false;
vector < SusCFG * >transitionBlocks; vector < SusCFG * >transitionBlocks;
while (traversedBlocks.size() != 0) { while (traversedBlocks.size() != 0) {
SusCFG *currentBlock = traversedBlocks.front(); SusCFG *currentBlock = traversedBlocks.front();
//_os <<"\n ModifDFS current block : " <<currentBlock->getBlockID();
traversedBlocks.pop_front(); traversedBlocks.pop_front();
if (currentBlock->isWaitBlock()) { if (currentBlock->isWaitBlock()) {
float timeInNs; float timeInNs;
string eventName; string eventName;
isWaitEncounter = true;
susCFGStateMapType::iterator stateFound = susCFGStateMapType::iterator stateFound =
susCFGStateMap.find(currentBlock); susCFGStateMap.find(currentBlock);
State *finalState = stateFound->second; State *finalState = stateFound->second;
...@@ -584,7 +592,9 @@ vector<SusCFG*> SuspensionAutomata::modifDFS(SusCFG * block, State *initialState ...@@ -584,7 +592,9 @@ vector<SusCFG*> SuspensionAutomata::modifDFS(SusCFG * block, State *initialState
finalState->addSimTime(timeInNs); finalState->addSimTime(timeInNs);
t->addInitialState(initialState); t->addInitialState(initialState);
t->addFinalState(finalState); t->addFinalState(finalState);
addRemainingBlocks(initialState, transitionBlocks);
t->addCodeBlocks(transitionBlocks); t->addCodeBlocks(transitionBlocks);
_transitionVector.push_back(t); _transitionVector.push_back(t);
return transitionBlocks; return transitionBlocks;
...@@ -636,13 +646,41 @@ vector<SusCFG*> SuspensionAutomata::modifDFS(SusCFG * block, State *initialState ...@@ -636,13 +646,41 @@ vector<SusCFG*> SuspensionAutomata::modifDFS(SusCFG * block, State *initialState
transitionBlocks.push_back(currentBlock); transitionBlocks.push_back(currentBlock);
} }
} }
return transitionBlocks; if (isWaitEncounter == false) {
// we found a path that does not end in a wait block. So,
// it will be in all paths from this initial state to all final wait states
if(_stateCommonCodeBlockMap.find(initialState) == _stateCommonCodeBlockMap.end()) {
_stateCommonCodeBlockMap.insert(stateCommonCodeBlockPairType(initialState, transitionBlocks));
}
else {
stateCommonCodeBlockMapType::iterator stateFound = _stateCommonCodeBlockMap.find(initialState);
vector<SusCFG*> remainingCodeBlocks = stateFound->second;
checkInsert(transitionBlocks, remainingCodeBlocks);
}
}
return transitionBlocks;
} }
void SuspensionAutomata::checkInsert(vector<SusCFG*> source, vector<SusCFG*>& target) {
bool duplicate;
for (int i = 0; i<source.size(); i++) {
duplicate = false;
for (int j = 0; j<target.size(); j++) {
if (source.at(i) == target.at(j)) {
duplicate = true;
break;
}
}
if (duplicate == false) {
target.push_back(source.at(i));
}
}
}
void SuspensionAutomata::genSauto() void SuspensionAutomata::genSauto()
{ {
susCFGVectorType susCFGVector = _susCFGVector; susCFGVectorType susCFGVector = _susCFGVector;
susCFGVectorType waitBlocks; susCFGVectorType waitBlocks;
for (int i = 0; i < susCFGVector.size(); i++) { for (int i = 0; i < susCFGVector.size(); i++) {
...@@ -651,8 +689,8 @@ void SuspensionAutomata::genSauto() ...@@ -651,8 +689,8 @@ void SuspensionAutomata::genSauto()
State *state = new State(susCFGVector.at(i), false, false, false, false); State *state = new State(susCFGVector.at(i), false, false, false, false);
if (i == 0) { if (i == 0) {
state->setInitial(); state->setInitial();
_os <<"\n State susblock set to initial : " <<state->returnSusCFGBlock()->getBlockID(); //_os <<"\n State susblock set to initial : " <<state->returnSusCFGBlock()->getBlockID();
_os <<"\n State : " <<state->isTimed()<<" " <<state->isInitial()<<" " <<state->isDelta(); //_os <<"\n State : " <<state->isTimed()<<" " <<state->isInitial()<<" " <<state->isDelta();
} }
susCFGStateMap.insert(susCFGStatePairType(susCFGVector.at(i), state)); susCFGStateMap.insert(susCFGStatePairType(susCFGVector.at(i), state));
} }
...@@ -681,6 +719,7 @@ void SuspensionAutomata::genSauto() ...@@ -681,6 +719,7 @@ void SuspensionAutomata::genSauto()
initialInsertBlock = waitBlock->getSuccBlocks().at(0); initialInsertBlock = waitBlock->getSuccBlocks().at(0);
} }
vector<SusCFG*> transitionCodeBlocks = modifDFS(initialInsertBlock, initialState); vector<SusCFG*> transitionCodeBlocks = modifDFS(initialInsertBlock, initialState);
//_os <<"\n Transition Blocks : "; //_os <<"\n Transition Blocks : ";
backTrackCodeBlocks.clear(); backTrackCodeBlocks.clear();
for (int j = 0; j<transitionCodeBlocks.size(); j++) { for (int j = 0; j<transitionCodeBlocks.size(); j++) {
...@@ -693,7 +732,8 @@ void SuspensionAutomata::genSauto() ...@@ -693,7 +732,8 @@ void SuspensionAutomata::genSauto()
//_os <<"\n Block : " <<backTrackCodeBlocks.at(j)->getBlockID()<<" has more than one successor"; //_os <<"\n Block : " <<backTrackCodeBlocks.at(j)->getBlockID()<<" has more than one successor";
SusCFG* backBlock = backTrackCodeBlocks.at(j); SusCFG* backBlock = backTrackCodeBlocks.at(j);
if (backBlock->getSuccBlocks().at(0)->isParentBlock()) { if (backBlock->getSuccBlocks().at(0)->isParentBlock()) {
if (backBlock->getSuccBlocks().at(0)->getChildBlockList().at(0) == backTrackCodeBlocks.at(j+1)) {
if (backBlock->getSuccBlocks().at(0)->getChildBlockList().at(0) == backTrackCodeBlocks.at(j+1)) {
//_os <<"\n Block : " <<backBlock->getBlockID()<<" used the first successor"; //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the first successor";
susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 0)); susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 0));
//_os <<"\n Map value : " <<susCFGSuccIDMap[backBlock]; //_os <<"\n Map value : " <<susCFGSuccIDMap[backBlock];
...@@ -701,6 +741,7 @@ void SuspensionAutomata::genSauto() ...@@ -701,6 +741,7 @@ void SuspensionAutomata::genSauto()
} }
} }
else if (backBlock->getSuccBlocks().at(1)->isParentBlock()) { else if (backBlock->getSuccBlocks().at(1)->isParentBlock()) {
if (backBlock->getSuccBlocks().at(1)->getChildBlockList().at(0) == backTrackCodeBlocks.at(j+1)) { if (backBlock->getSuccBlocks().at(1)->getChildBlockList().at(0) == backTrackCodeBlocks.at(j+1)) {
//_os <<"\n Block : " <<backBlock->getBlockID()<<" used the second successor"; //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the second successor";
susCFGSuccIDMap.erase(backBlock); susCFGSuccIDMap.erase(backBlock);
...@@ -709,13 +750,15 @@ void SuspensionAutomata::genSauto() ...@@ -709,13 +750,15 @@ void SuspensionAutomata::genSauto()
} }
} }
else if (backBlock->getSuccBlocks().at(0) == backTrackCodeBlocks.at(j+1)) { else if (backBlock->getSuccBlocks().at(0) == backTrackCodeBlocks.at(j+1)) {
//_os <<"\n Block : " <<backBlock->getBlockID()<<" used the first successor"; //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the first successor";
susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 0)); susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 0));
break; break;
} }
else if (backBlock->getSuccBlocks().at(1) == backTrackCodeBlocks.at(j+1)){ else if (backBlock->getSuccBlocks().at(1) == backTrackCodeBlocks.at(j+1)){
//_os <<"\n Block : " <<backBlock->getBlockID()<<" used the second successor"; //_os <<"\n Block : " <<backBlock->getBlockID()<<" used the second successor";
susCFGSuccIDMap.erase(backBlock); susCFGSuccIDMap.erase(backBlock);
susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 1)); susCFGSuccIDMap.insert(susCFGSuccIDPairType(backBlock, 1));
break; break;
...@@ -916,7 +959,6 @@ void SuspensionAutomata::dumpSauto() ...@@ -916,7 +959,6 @@ void SuspensionAutomata::dumpSauto()
_os << "\n Size of transitionVector : " << transitionVector.size(); _os << "\n Size of transitionVector : " << transitionVector.size();
for (unsigned int i = 0; i < transitionVector.size(); i++) { for (unsigned int i = 0; i < transitionVector.size(); i++) {
Transition *t = transitionVector.at(i); Transition *t = transitionVector.at(i);
t->dump(_os); t->dump(_os);
} }
} }
......
...@@ -118,11 +118,15 @@ namespace scpar { ...@@ -118,11 +118,15 @@ namespace scpar {
typedef pair < SusCFG *, State * >susCFGStatePairType; typedef pair < SusCFG *, State * >susCFGStatePairType;
typedef map < SusCFG *, State * >susCFGStateMapType; typedef map < SusCFG *, State * >susCFGStateMapType;
typedef pair<State*, vector<SusCFG*> > stateCommonCodeBlockPairType;
typedef map<State *, vector<SusCFG*> > stateCommonCodeBlockMapType;
SuspensionAutomata(FindWait::waitListType, CXXMethodDecl *, ASTContext *, SuspensionAutomata(FindWait::waitListType, CXXMethodDecl *, ASTContext *,
raw_ostream &); raw_ostream &);
~SuspensionAutomata(); ~SuspensionAutomata();
void addRemainingBlocks(State*, vector<SusCFG*>&);
void checkInsert(vector<SusCFG*>, vector<SusCFG*>&);
bool isFound(vector < SusCFG * >, SusCFG *); bool isFound(vector < SusCFG * >, SusCFG *);
bool isFound(vector < Transition * >, Transition *); bool isFound(vector < Transition * >, Transition *);
bool initialize(); bool initialize();
...@@ -153,6 +157,7 @@ namespace scpar { ...@@ -153,6 +157,7 @@ namespace scpar {
raw_ostream & _os; raw_ostream & _os;
susCFGVectorType _susCFGVector; susCFGVectorType _susCFGVector;
transitionVectorType _transitionVector; transitionVectorType _transitionVector;
stateCommonCodeBlockMapType _stateCommonCodeBlockMap;
}; // End class SplitWaitBlocks }; // End class SplitWaitBlocks
} // End namespace scpar } // End namespace scpar
#endif #endif
...@@ -107,8 +107,12 @@ bool SystemCConsumer::fire() ...@@ -107,8 +107,12 @@ bool SystemCConsumer::fire()
_systemcModel->addSimulationTime(scstart.returnSimTime()); _systemcModel->addSimulationTime(scstart.returnSimTime());
} }
else {
_os <<"\n Could not find SCMain";
}
FindNetlist findNetlist(scmain.getSCMainFunctionDecl()); FindNetlist findNetlist(scmain.getSCMainFunctionDecl());
_systemcModel->addNetlist(findNetlist); findNetlist.dump();
_systemcModel->addNetlist(findNetlist);
_os <<"\n SystemC model dump\n"; _os <<"\n SystemC model dump\n";
_systemcModel->dump(_os); _systemcModel->dump(_os);
......
...@@ -49,7 +49,8 @@ using namespace clang::tooling; ...@@ -49,7 +49,8 @@ using namespace clang::tooling;
#include "FindArgument.h" #include "FindArgument.h"
#include "Utility.h" #include "Utility.h"
#include "SuspensionAutomata.h" #include "SuspensionAutomata.h"
#include "SCuitable/GlobalSuspensionAutomata.h"
#include "SCuitable/FindGPUMacro.h"
using namespace clang; using namespace clang;
namespace scpar namespace scpar
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment