7 : _systemcModel(systemCmodel), _os(os), _a(a) {}
24 if (aTransition != bTransition) {
25 transitionTimeMapType::iterator aTransitionFound =
27 transitionTimeMapType::iterator bTransitionFound =
32 if (aTimePair.first == bTimePair.first &&
33 aTimePair.second == bTimePair.second) {
37 vector<SusCFG *> susCFGBlockList;
41 timePairType timePair = make_pair(aTimePair.first, aTimePair.second);
43 for (
int k = 0; k < aCodeBlocks.size(); k++) {
48 susCFGBlockList.push_back(aCodeBlocks.at(k));
52 for (
int k = 0; k < bCodeBlocks.size(); k++) {
57 susCFGBlockList.push_back(bCodeBlocks.at(k));
64 commonTimeDPMapType::iterator commonTimeFound =
66 vector<SusCFG *> tmpVec = commonTimeFound->second;
67 for (
int k = 0; k < bCodeBlocks.size(); k++) {
72 susCFGBlockList.push_back(bCodeBlocks.at(k));
76 tmpVec.insert(tmpVec.end(), susCFGBlockList.begin(),
77 susCFGBlockList.end());
100 cit != cite; cit++) {
104 vector<SusCFG *> susCFGBlockList = cit->second;
112 for (
int i = 0; i < susCFGBlockList.size(); i++) {
116 susCFGBlockGPUMacroMapType::iterator gpuMacroFound =
119 GPUMacro *gpuMacro = gpuMacroFound->second;
126 c_ideal = (u + l) / 2;
128 if (
GPUMap(c_ideal, susCFGBlockList, c_actual)) {
140 vector<SusCFG *> susCFGBlockList,
142 vector<SusCFG *> gpuFitSusCFGVector;
143 vector<SusCFG *> gpuUnfitSusCFGVector;
144 for (
int i = 0; i < susCFGBlockList.size(); i++) {
147 susCFGBlockGPUMacroMapType::iterator gpuMacroFound =
149 GPUMacro *gpuMacro = gpuMacroFound->second;
158 gpuFitSusCFGVector.push_back(susCFGBlockList.at(i));
162 gpuUnfitSusCFGVector.push_back(susCFGBlockList.at(i));
167 vector<SusCFG *> orderedSusCFGList =
178 for (
int i = 0; i < orderedSusCFGList.size(); i++) {
183 if (gpuTime <= c_ideal) {
184 c_ideal = c_ideal - gpuTime;
187 gpuUnfitSusCFGVector.push_back(gpuFitSusCFGVector.at(i));
188 gpuFitSusCFGVector.erase(gpuFitSusCFGVector.begin() + i - 1);
191 float newGPUTime = 0;
192 float newCPUTime = 0;
210 for (
int i = 0; i < gpuFitSusCFGVector.size(); i++) {
214 for (
int i = 0; i < gpuUnfitSusCFGVector.size(); i++) {
216 if (newCPUTime < gpuMacro->getCPUTime()) {
222 if (c_actual >
max(newGPUTime, newCPUTime)) {
223 c_actual =
max(newGPUTime, newCPUTime);
224 for (
int i = 0; i < gpuFitSusCFGVector.size(); i++) {
225 gpuFitSusCFGVector.at(i)->addGPUFit();
228 for (
int i = 0; i < gpuUnfitSusCFGVector.size(); i++) {
229 gpuUnfitSusCFGVector.at(i)->denyGPUFit();
238 vector<SusCFG *> gpuFitSusCFGVector) {
239 vector<SusCFG *> leftList;
240 vector<SusCFG *> rightList;
242 if (gpuFitSusCFGVector.size() <= 1) {
243 return gpuFitSusCFGVector;
245 middle = gpuFitSusCFGVector.size() / 2;
246 for (
int i = 0; i < middle; i++) {
247 leftList.push_back(gpuFitSusCFGVector.at(i));
249 for (
int i = middle; i < gpuFitSusCFGVector.size(); i++) {
250 rightList.push_back(gpuFitSusCFGVector.at(i));
262 vector<SusCFG *> rightList) {
263 vector<SusCFG *> orderedList;
264 while (leftList.size() > 0 || rightList.size() > 0) {
265 if (leftList.size() > 0 && rightList.size() > 0) {
270 int rightGPUTime = rightGPUMacro->
getCPUTime();
271 int rightCPUTime = rightGPUMacro->
getCPUTime();
272 int leftAccFactor = leftCPUTime / leftGPUTime;
273 int rightAccFactor = rightCPUTime / rightGPUTime;
274 if (leftAccFactor >= rightAccFactor) {
275 orderedList.push_back(leftList.back());
278 orderedList.push_back(rightList.back());
279 rightList.pop_back();
281 }
else if (leftList.size() > 0) {
282 orderedList.push_back(leftList.back());
284 }
else if (rightList.size() > 0) {
285 orderedList.push_back(rightList.back());
286 rightList.pop_back();
306 for (
int i = 0; i < codeBlockVector.size(); i++) {
308 SusCFG *susCFGBlock = codeBlockVector.at(i);
309 CFGBlock *cfgBlock = susCFGBlock->
getBlock();
310 if (cfgBlock->getLoopTarget()) {
311 if (
const ForStmt *cfs = dyn_cast<ForStmt>(cfgBlock->getLoopTarget())) {
312 ForStmt *fs =
const_cast<ForStmt *
>(cfs);
313 for (entryFunctionMacroMapType::iterator
319 for (FindGPUMacro::forStmtGPUMacroMapType::iterator
320 fit = gpuMacroMap.begin(),
321 fite = gpuMacroMap.end();
322 fit != fite; fit++) {
326 if (forStmtInstanceIdPair.first == instanceId &&
327 forStmtInstanceIdPair.second == fs) {
347 vector<ModuleDecl *> mdVec = it->second;
349 for (
int i = 0; i < mdVec.size(); i++) {
350 ModuleDecl *md = mdVec.at(i);
351 vector<EntryFunctionContainer *> vef = md->getEntryFunctionContainer();
353 for (
int j = 0; j < vef.size(); j++) {
355 vef.at(j)->getSusAuto();
358 make_pair(vef.at(j), i);
363 for (
int j = 0; j < vef.size(); j++) {
364 CXXMethodDecl *entryFunctionDecl = vef.at(j)->getEntryMethod();
375 vector<Transition *> transitionVec = it->second;
377 for (
int i = 0; i < transitionVec.size(); i++) {
381 initialState = state;
386 for (instanceFunctionSautoMapType::iterator
391 vector<Transition *> sauto = it->second;
393 for (
int i = 0; i < sauto.size(); i++) {
410 vector<Transition *> incomingTransitions;
411 vector<Transition *> outgoingTransitions;
415 outgoingTransitions.push_back(t);
418 incomingTransitions.push_back(t);
431 stateTransitionsMapType::iterator stateFound =
433 return stateFound->second;
435 llvm::errs() <<
"\n ERROR : Could not find state in map";
456 vector<Transition *> transitionVec;
461 if (timePair.first == tp.first && timePair.second == tp.second) {
462 transitionVec.push_back(it->first);
465 return transitionVec;
478 _os <<
"\n Cannot find time of transition : " << t;
479 return make_pair(0, 0);
487 stateTransitionsMapType::iterator stateFound =
489 return stateFound->second;
491 llvm::errs() <<
"\n ERROR : Could not find state in map";
498 Stmt *s =
const_cast<Stmt *
>(cs->getStmt());
499 CXXMemberCallExpr *m = dyn_cast<CXXMemberCallExpr>(s);
506 if (m->getDirectCallee()->getNameInfo().getAsString() ==
string(
"notify")) {
515 LangOptions LangOpts;
516 LangOpts.CPlusPlus =
true;
517 PrintingPolicy Policy(LangOpts);
520 llvm::raw_string_ostream s(TypeS);
522 arg->printPretty(s, 0, Policy);
528 Stmt *s =
const_cast<Stmt *
>(cs->getStmt());
530 CXXMemberCallExpr *ce = dyn_cast<CXXMemberCallExpr>(s);
532 MemberExpr *m = dyn_cast<MemberExpr>(ce->getCallee());
541 for (
int i = 0; i < codeBlocks.size(); i++) {
542 SusCFG *susCFGBlock = codeBlocks.at(i);
543 CFGBlock *cfgBlock = susCFGBlock->
getBlock();
544 for (CFGBlock::iterator it = cfgBlock->begin(), eit = cfgBlock->end();
546 if (Optional<CFGStmt> cs = it->getAs<CFGStmt>()) {
547 const CFGStmt *s = (CFGStmt
const *)&cs;
552 float simCycles = 0.0;
553 float deltaTime = 0.0;
556 transitionTimeMapType::iterator transitionTimeFound =
559 eventName, transitionTimeFound->second));
561 llvm::errs() <<
"\n ERROR : Cannot find transition time";
581 for (
int i = 0; i < transitionVec.size(); i++) {
584 transitionTimeMapType::iterator transitionFound =
586 if (simTime < transitionFound->second.first) {
587 simTime = transitionFound->second.first;
588 deltaTime = transitionFound->second.second + 1;
602 for (
int i = 0; i < transitionVec.size(); i++) {
605 transitionTimeMapType::iterator transitionFound =
607 if (simTime <= transitionFound->second.first) {
608 simTime = transitionFound->second.first + state->
getSimTime();
609 deltaTime = transitionFound->second.second;
623 eventNotificationTimeMapType::iterator eventFound =
629 llvm::errs() <<
"\n ERROR : Unknown state type";
645 deque<Transition *> transitionQueue;
655 vector<Transition *> initialTransitions =
658 for (
int i = 0; i < initialTransitions.size(); i++) {
659 transitionQueue.push_back(initialTransitions.at(i));
662 while (transitionQueue.size() != 0) {
667 transitionQueue.pop_front();
671 transitionQueue.pop_front();
672 transitionQueue.push_back(tr);
676 vector<Transition *> outgoingTransitions =
679 for (
int i = 0; i < outgoingTransitions.size(); i++) {
681 transitionQueue.push_back(outgoingTransitions.at(i));
688 for (instanceFunctionSautoMapType::iterator
692 _os <<
"\n ############################################\n";
693 _os <<
"\n Instance Name : " << it->first.first;
694 _os <<
"\n Function Name : " << it->first.first->getName();
696 vector<Transition *> sauto = it->second;
697 for (
int i = 0; i < sauto.size(); i++) {
698 _os <<
"\n Transition : " << sauto.at(i);
699 sauto.at(i)->dump(
_os);
702 transitionTimeMapType::iterator transitionTimeFound =
704 _os <<
"\n Sim Cycles : " << transitionTimeFound->second.first
705 <<
" Delta cycles : " << transitionTimeFound->second.second;
711 cit != cite; cit++) {
713 vector<SusCFG *> susCFGList = cit->second;
714 _os <<
"\n Time Pair : " << timePair.first <<
" " << timePair.second;
715 _os <<
"\n SusCFG* DP : \n";
716 for (
int j = 0; j < susCFGList.size(); j++) {
720 _os <<
" " << susCFGList.at(j)->getBlockID();
721 susCFGBlockGPUMacroMapType::iterator DPCodeBlockFound =
723 GPUMacro *gpuMacro = DPCodeBlockFound->second;
726 if (susCFGList.at(j)->isGPUFit()) {
727 _os <<
"\n SusCFG Block : " << susCFGList.at(j)->getBlockID()
728 <<
" is marked for GPU execution\n";
forStmtGPUMacroMapType getForStmtGPUMacroMap()
map< forStmtInstanceIdPairType, GPUMacro * > forStmtGPUMacroMapType
pair< int, ForStmt * > forStmtInstanceIdPairType
map< EntryFunctionContainer *, FindGPUMacro::forStmtGPUMacroMapType > entryFunctionMacroMapType
Model::moduleInstanceMapType _moduleInstanceMap
pair< Transition *, timePairType > transitionTimePairType
transitionVectorType getIncomingTransitions(State *)
pair< entryFunctionInstanceIdPairType, transitionVectorType > instanceFunctionSautoPairType
stateTransitionsMapType _incomingTransitionsMap
void annotateTransitionsDPSeg(Transition *, int)
pair< SusCFG *, GPUMacro * > susCFGBlockGPUMacroPairType
vector< SusCFG * > merge_sort(vector< SusCFG * >, vector< SusCFG * >)
entryFunctionMacroMapType getEntryFunctionMacroMap()
map< Transition *, timePairType > transitionTimeMapType
transitionVectorType getOutgoingTransitions(State *)
transitionTimeMapType getTransitionTimeMap()
pair< Transition *, bool > visitTransitionPairType
bool GPUMap(float, vector< SusCFG * >, float &)
~GlobalSuspensionAutomata()
string getArgumentName(Expr *)
transitionTimeMapType _transitionTimeMap
string getNotifyEventName(const CFGStmt *)
map< SusCFG *, GPUMacro * > susCFGBlockGPUMacroMapType
pair< State *, vector< Transition * > > stateTransitionsPairType
timePairType getTimeForTransition(Transition *)
transitionVectorType getTransitionsAtTime(timePairType)
susCFGBlockGPUMacroMapType getSusCFGBlockGPUMacroMap()
instanceFunctionSautoMapType _instanceFunctionSautoMap
stateTransitionsMapType _outgoingTransitionsMap
GlobalSuspensionAutomata(Model *, raw_ostream &, ASTContext *)
bool isNotifyCall(const CFGStmt *)
vector< SusCFG * > arrangeGPUSusCFGBlocks(vector< SusCFG * >)
pair< float, int > timePairType
pair< string, timePairType > eventNotificationTimePairType
void updateEventNotificationTime(Transition *)
pair< timePairType, vector< SusCFG * > > commonTimeDPPairType
transitionVectorType _globalSauto
visitTransitionMapType _visitTransitionMap
eventNotificationTimeMapType _eventNotificationTimeMap
entryFunctionMacroMapType _entryFunctionGPUMacroMap
commonTimeDPMapType _commonTimeDPMap
transitionVectorType getGlobalSauto()
pair< EntryFunctionContainer *, int > entryFunctionInstanceIdPairType
bool updateTransitionTime(Transition *)
pair< EntryFunctionContainer *, FindGPUMacro::forStmtGPUMacroMapType > entryFunctionMacroPairType
susCFGBlockGPUMacroMapType _susCFGBlockGPUMacroMap
vector< Transition * > transitionVectorType
vector< SusCFG * > returnCodeBlocks()
void addInitialState(State *)
State * returnInitialState()
State * returnFinalState()
bool isElementPresent(vec vecInput, element elemInput)