Commit 2a6bb79e authored by rmrf's avatar rmrf
Browse files

SAUTO requires a careful inspection and rework.

For the time being, USE_SAUTO is not defined by default. This means that
we do not need to compile the respective files into the libsystemc-clang
library.  The CMakeLists adjust that.

The source code must also use #ifdef and #endif pairs to isolate the
code that generates and dumps the SAUTO.  This has also been added.

The focus as of now is going to be primarily on sc_method processes.
parent 49d75bfe
...@@ -29,12 +29,12 @@ set (LLVM_BUILD_DIR ...@@ -29,12 +29,12 @@ set (LLVM_BUILD_DIR
) )
set (CMAKE_CXX_FLAGS set (CMAKE_CXX_FLAGS
"$ENV{LLVM_CXX_FLAGS} $ENV{CMAKE_CXX_FLAGS} -DUSE_SAUTO=off -Wcovered-switch-default" "$ENV{LLVM_CXX_FLAGS} $ENV{CMAKE_CXX_FLAGS} -Wcovered-switch-default -g"
) )
if (USE_SAUTO) if (USE_SAUTO)
set (CMAKE_CXX_FLAGS set (CMAKE_CXX_FLAGS
"-DUSE_SAUTO=on ${CMAKE_CXX_FLAGS}" "-DUSE_SAUTO ${CMAKE_CXX_FLAGS}"
) )
endif(USE_SAUTO) endif(USE_SAUTO)
......
if (USE_SAUTO)
add_library (libsystemc-clang
Automata.cpp
SuspensionAutomata.cpp
SCuitable/GlobalSuspensionAutomata.cpp
SCuitable/FindGPUMacro.cpp
)
endif (USE_SAUTO)
add_library (libsystemc-clang add_library (libsystemc-clang
ModuleDecl.cpp ModuleDecl.cpp
FindModule.cpp FindModule.cpp
...@@ -19,11 +28,11 @@ add_library (libsystemc-clang ...@@ -19,11 +28,11 @@ add_library (libsystemc-clang
FindNetlist.cpp FindNetlist.cpp
FindArgument.cpp FindArgument.cpp
FindTemplateParameters.cpp FindTemplateParameters.cpp
Automata.cpp # Automata.cpp
SuspensionAutomata.cpp # SuspensionAutomata.cpp
SCuitable/GlobalSuspensionAutomata.cpp # SCuitable/GlobalSuspensionAutomata.cpp
SCuitable/FindGPUMacro.cpp # SCuitable/FindGPUMacro.cpp
#################################### #####################################
#From here the files are for the reflection database #From here the files are for the reflection database
#################################### ####################################
#Utility.cpp #Utility.cpp
......
...@@ -80,6 +80,7 @@ void EntryFunctionContainer::addWaits(FindWait &f) { ...@@ -80,6 +80,7 @@ void EntryFunctionContainer::addWaits(FindWait &f) {
} }
void EntryFunctionContainer::addSusCFGAuto(SuspensionAutomata &s) { void EntryFunctionContainer::addSusCFGAuto(SuspensionAutomata &s) {
#ifdef USE_SAUTO
_susCFG = s.getSusCFG(); _susCFG = s.getSusCFG();
_susAuto = s.getSauto(); _susAuto = s.getSauto();
...@@ -92,6 +93,7 @@ void EntryFunctionContainer::addSusCFGAuto(SuspensionAutomata &s) { ...@@ -92,6 +93,7 @@ void EntryFunctionContainer::addSusCFGAuto(SuspensionAutomata &s) {
s.getSauto())); s.getSauto()));
} }
*/ */
#endif
} }
void EntryFunctionContainer::addNotifys(FindNotify &f) { void EntryFunctionContainer::addNotifys(FindNotify &f) {
...@@ -110,6 +112,7 @@ void EntryFunctionContainer::addNotifys(FindNotify &f) { ...@@ -110,6 +112,7 @@ void EntryFunctionContainer::addNotifys(FindNotify &f) {
void EntryFunctionContainer::dumpSusCFG(raw_ostream &os) { void EntryFunctionContainer::dumpSusCFG(raw_ostream &os) {
os << "\n#############################################"; os << "\n#############################################";
#ifdef USE_SAUTO
SuspensionAutomata::susCFGVectorType susCFGVector = _susCFG; SuspensionAutomata::susCFGVectorType susCFGVector = _susCFG;
for (unsigned int i = 0; i < susCFGVector.size(); i++) { for (unsigned int i = 0; i < susCFGVector.size(); i++) {
...@@ -137,15 +140,18 @@ void EntryFunctionContainer::dumpSusCFG(raw_ostream &os) { ...@@ -137,15 +140,18 @@ void EntryFunctionContainer::dumpSusCFG(raw_ostream &os) {
} }
} }
} }
#endif
} }
void EntryFunctionContainer::dumpSauto(raw_ostream &os) { void EntryFunctionContainer::dumpSauto(raw_ostream &os) {
#ifdef USE_SAUTO
vector<Transition *> transitionVector = _susAuto; vector<Transition *> transitionVector = _susAuto;
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);
} }
#endif
} }
void EntryFunctionContainer::dump(raw_ostream &os, int tabn) { void EntryFunctionContainer::dump(raw_ostream &os, int tabn) {
......
...@@ -156,11 +156,10 @@ SuspensionAutomata::SuspensionAutomata(vector<WaitContainer *> waitCalls, ...@@ -156,11 +156,10 @@ SuspensionAutomata::SuspensionAutomata(vector<WaitContainer *> waitCalls,
raw_ostream &os) raw_ostream &os)
: _d(d), _a(a), _os(os) { : _d(d), _a(a), _os(os) {
for (int i = 0; i < waitCalls.size(); i++) { for (std::size_t i {0}; i < waitCalls.size(); i++) {
WaitContainer *wc = waitCalls.at(i); WaitContainer *wc {waitCalls.at(i)};
_waitCalls.push_back(wc->getASTNode()); _waitCalls.push_back(wc->getASTNode());
} }
//_waitCalls = waitCalls;
} }
SuspensionAutomata::~SuspensionAutomata() {} SuspensionAutomata::~SuspensionAutomata() {}
...@@ -187,8 +186,8 @@ bool SuspensionAutomata::isWaitCall(const CFGStmt *cs) { ...@@ -187,8 +186,8 @@ bool SuspensionAutomata::isWaitCall(const CFGStmt *cs) {
if (!m) { if (!m) {
return f; return f;
} }
for (int i = 0; i < _waitCalls.size(); i++) { for (std::size_t i {0}; i < _waitCalls.size(); i++) {
CallExpr *ce = _waitCalls.at(i); CallExpr *ce {_waitCalls.at(i)};
if (m == ce) { if (m == ce) {
f = true; f = true;
} }
...@@ -291,7 +290,7 @@ void SuspensionAutomata::genSusCFG() { ...@@ -291,7 +290,7 @@ void SuspensionAutomata::genSusCFG() {
CFGBlock *prev = NULL; CFGBlock *prev = NULL;
SusCFG *prevBlock = NULL; SusCFG *prevBlock = NULL;
for (unsigned int i = 0; i < splitBlocksVector.size(); i++) { for (std::size_t i = 0; i < splitBlocksVector.size(); i++) {
CFGBlock *current = splitBlocksVector.at(i); CFGBlock *current = splitBlocksVector.at(i);
SusCFG *splitBlock = SusCFG *splitBlock =
new SusCFG(const_cast<CFGBlock *>(splitBlocksVector.at(i))); new SusCFG(const_cast<CFGBlock *>(splitBlocksVector.at(i)));
...@@ -303,7 +302,7 @@ void SuspensionAutomata::genSusCFG() { ...@@ -303,7 +302,7 @@ void SuspensionAutomata::genSusCFG() {
if (pre.size() != 0) { if (pre.size() != 0) {
// add trailing statements to post block wait stmt // add trailing statements to post block wait stmt
CFGBlock *newCFGBlock = _cfg->createBlock(); CFGBlock *newCFGBlock = _cfg->createBlock();
for (unsigned int j = 0; j < pre.size(); j++) { for (std::size_t j{0}; j < pre.size(); j++) {
newCFGBlock->appendStmt(const_cast<Stmt *>(pre.at(j)->getStmt()), newCFGBlock->appendStmt(const_cast<Stmt *>(pre.at(j)->getStmt()),
_cfg->getBumpVectorContext()); _cfg->getBumpVectorContext());
} }
...@@ -408,7 +407,7 @@ void SuspensionAutomata::genSusCFG() { ...@@ -408,7 +407,7 @@ void SuspensionAutomata::genSusCFG() {
site = b->succ_end(); site = b->succ_end();
sit != site; sit++) { sit != site; sit++) {
const CFGBlock *succBlock = *sit; const CFGBlock *succBlock = *sit;
SusCFG *tmpBlock; SusCFG *tmpBlock{nullptr};
if (succBlock) { if (succBlock) {
if (susCFGBlockMap.find(const_cast<CFGBlock *>(succBlock)) == if (susCFGBlockMap.find(const_cast<CFGBlock *>(succBlock)) ==
...@@ -488,11 +487,16 @@ vector<SusCFG *> SuspensionAutomata::modifDFS(SusCFG *block, ...@@ -488,11 +487,16 @@ vector<SusCFG *> SuspensionAutomata::modifDFS(SusCFG *block,
// When adding blocks to traversed blocks, check if the last node prior to // When adding blocks to traversed blocks, check if the last node prior to
// the wait call has which branch discovered. Also need to check // the wait call has which branch discovered. Also need to check
// terminator block or block 0 // terminator block or block 0
//
if (susCFGSuccIDMap.find(currentBlock) == susCFGSuccIDMap.end()) { if (susCFGSuccIDMap.find(currentBlock) == susCFGSuccIDMap.end()) {
// currentBlock is not our concern yet, so insert the 0th successive // currentBlock is not our concern yet, so insert the 0th successive
// block // block
//_os <<"\n Current Block : " <<currentBlock->getBlockID()<<" not of //_os <<"\n Current Block : " <<currentBlock->getBlockID()<<" not of
//concern"; //concern";
//
// TODO: BUG: There is an issue here.
// There exists a getSuccBlocks(), but it happens to be empty.
// This happens when there is a thread that uses a wait(), but no while loop.
if (currentBlock->getSuccBlocks().at(0)->isParentBlock()) { if (currentBlock->getSuccBlocks().at(0)->isParentBlock()) {
if (!isFound( if (!isFound(
visitedBlocks, visitedBlocks,
...@@ -571,7 +575,7 @@ vector<SusCFG *> SuspensionAutomata::modifDFS(SusCFG *block, ...@@ -571,7 +575,7 @@ vector<SusCFG *> SuspensionAutomata::modifDFS(SusCFG *block,
void SuspensionAutomata::checkInsert(vector<SusCFG *> source, void SuspensionAutomata::checkInsert(vector<SusCFG *> source,
vector<SusCFG *> &target) { vector<SusCFG *> &target) {
bool duplicate; bool duplicate;
for (int i = 0; i < source.size(); i++) { for (std::size_t i {0}; i < source.size(); i++) {
duplicate = false; duplicate = false;
for (int j = 0; j < target.size(); j++) { for (int j = 0; j < target.size(); j++) {
if (source.at(i) == target.at(j)) { if (source.at(i) == target.at(j)) {
...@@ -588,7 +592,7 @@ void SuspensionAutomata::checkInsert(vector<SusCFG *> source, ...@@ -588,7 +592,7 @@ void SuspensionAutomata::checkInsert(vector<SusCFG *> source,
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 (std::size_t i {0}; i < susCFGVector.size(); i++) {
if (susCFGVector.at(i)->isWaitBlock() || i == 0) { if (susCFGVector.at(i)->isWaitBlock() || i == 0) {
waitBlocks.push_back(susCFGVector.at(i)); waitBlocks.push_back(susCFGVector.at(i));
State *state = new State(susCFGVector.at(i), false, false, false, false); State *state = new State(susCFGVector.at(i), false, false, false, false);
...@@ -602,7 +606,7 @@ void SuspensionAutomata::genSauto() { ...@@ -602,7 +606,7 @@ void SuspensionAutomata::genSauto() {
} }
} }
for (int i = 0; i < waitBlocks.size(); i++) { for (std::size_t i {0}; i < waitBlocks.size(); i++) {
SusCFG *waitBlock = waitBlocks.at(i); SusCFG *waitBlock = waitBlocks.at(i);
...@@ -631,11 +635,11 @@ void SuspensionAutomata::genSauto() { ...@@ -631,11 +635,11 @@ void SuspensionAutomata::genSauto() {
//_os <<"\n Transition Blocks : "; //_os <<"\n Transition Blocks : ";
backTrackCodeBlocks.clear(); backTrackCodeBlocks.clear();
for (int j = 0; j < transitionCodeBlocks.size(); j++) { for (std::size_t j {0}; j < transitionCodeBlocks.size(); j++) {
backTrackCodeBlocks.push_back(transitionCodeBlocks.at(j)); backTrackCodeBlocks.push_back(transitionCodeBlocks.at(j));
//_os <<" "<<transitionCodeBlocks.at(j)->getBlockID();; //_os <<" "<<transitionCodeBlocks.at(j)->getBlockID();;
} }
int j; std::size_t j{};
for (j = backTrackCodeBlocks.size() - 2; j >= 0; j--) { for (j = backTrackCodeBlocks.size() - 2; j >= 0; j--) {
if (backTrackCodeBlocks.at(j)->getSuccBlocks().size() > 1) { if (backTrackCodeBlocks.at(j)->getSuccBlocks().size() > 1) {
//_os <<"\n Block : " <<backTrackCodeBlocks.at(j)->getBlockID()<<" has //_os <<"\n Block : " <<backTrackCodeBlocks.at(j)->getBlockID()<<" has
...@@ -765,9 +769,8 @@ bool SuspensionAutomata::isTimedWait(Stmt *stmt) { ...@@ -765,9 +769,8 @@ bool SuspensionAutomata::isTimedWait(Stmt *stmt) {
} }
return false; return false;
} }
/*
string SuspensionAutomata::getArgumentName(Expr * arg) string SuspensionAutomata::getArgumentName(Expr * arg) {
{
if (arg == NULL) if (arg == NULL)
return string("NULL"); return string("NULL");
...@@ -783,7 +786,6 @@ string SuspensionAutomata::getArgumentName(Expr * arg) ...@@ -783,7 +786,6 @@ string SuspensionAutomata::getArgumentName(Expr * arg)
// _os << ", argument: " << s.str() << "\n"; // _os << ", argument: " << s.str() << "\n";
return s.str(); return s.str();
} }
*/
bool SuspensionAutomata::isDeltaWait(Stmt *stmt) { bool SuspensionAutomata::isDeltaWait(Stmt *stmt) {
......
...@@ -148,7 +148,7 @@ public: ...@@ -148,7 +148,7 @@ public:
bool isEventWait(Stmt *stmt); bool isEventWait(Stmt *stmt);
float getTime(Stmt *stmt); float getTime(Stmt *stmt);
string getEvent(Stmt *stmt); string getEvent(Stmt *stmt);
// string getArgumentName(Expr * arg); string getArgumentName(Expr * arg);
void addEvent(string); void addEvent(string);
void addSimTime(float); void addSimTime(float);
susCFGVectorType getSusCFG(); susCFGVectorType getSusCFG();
......
...@@ -120,17 +120,19 @@ bool SystemCConsumer::fire() { ...@@ -120,17 +120,19 @@ bool SystemCConsumer::fire() {
FindNotify findNotify{ef->_entryMethodDecl, os_}; FindNotify findNotify{ef->_entryMethodDecl, os_};
ef->addNotifys(findNotify); ef->addNotifys(findNotify);
#ifdef USE_SAUTO
/// Does not compile /// Does not compile
SuspensionAutomata suspensionAutomata(findWaits.getWaitCalls(), SuspensionAutomata suspensionAutomata(findWaits.getWaitCalls(),
ef->getEntryMethod(), &_context, ef->getEntryMethod(), &_context,
llvm::errs()); llvm::errs());
if (suspensionAutomata.initialize()) { if (suspensionAutomata.initialize()) {
suspensionAutomata.genSusCFG(); suspensionAutomata.genSusCFG();
// suspensionAutomata.dumpSusCFG(); suspensionAutomata.dumpSusCFG();
suspensionAutomata.genSauto(); suspensionAutomata.genSauto();
// suspensionAutomata.dumpSauto(); suspensionAutomata.dumpSauto();
ef->addSusCFGAuto(suspensionAutomata); ef->addSusCFGAuto(suspensionAutomata);
} }
#endif
_entryFunctionContainerVector.push_back(ef); _entryFunctionContainerVector.push_back(ef);
} }
...@@ -159,6 +161,8 @@ findNetlist.dump(); ...@@ -159,6 +161,8 @@ findNetlist.dump();
_systemcModel->addNetlist(findNetlist); _systemcModel->addNetlist(findNetlist);
*/ */
// Only do this if SAUTO flag is set.
#ifdef USE_SAUTO
// Generate SAUTO // Generate SAUTO
// Placing it here so that unique SAUTO for each instance // Placing it here so that unique SAUTO for each instance
// Model::moduleMapType moduleMap = _systemcModel->getModuleDecl(); // Model::moduleMapType moduleMap = _systemcModel->getModuleDecl();
...@@ -189,6 +193,7 @@ _systemcModel->addNetlist(findNetlist); ...@@ -189,6 +193,7 @@ _systemcModel->addNetlist(findNetlist);
} }
} }
} }
#endif
os_ << "\n"; os_ << "\n";
os_ << "\n## SystemC model\n"; os_ << "\n## SystemC model\n";
......
#include "systemc.h"
#include <iostream>
SC_MODULE( test ){
sc_in<int> in;
sc_out<int> out;
sc_signal<int> test_signal;
void hello() {
std::cout << "write 1" << std::endl;
out.write(1);
wait();
/*
std::cout << "write 2" << std::endl;
out.write(2);
wait(sc_time(100, SC_NS));
*/
}
SC_CTOR( test ) {
SC_THREAD(hello);
}
};
int sc_main(int argc, char *argv[]) {
sc_signal<int> sig1;
test test_instance("testing");
test_instance.in(sig1);
test_instance.out(sig1);
sc_start();
return 0;
}
Markdown is supported
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