// Within sc, is the variable toCheck modified between the declaration of // lifetime and its last use? This is used to determine whether, whenever // toCheck and lifetime are equal, one can be used as a substitute for the // other. bool isPotentiallyModifiedDuringLifeOf(SgBasicBlock* sc, SgInitializedName* toCheck, SgInitializedName* lifetime) { SgStatementPtrList& stmts = sc->get_statements(); bool inLiveRange = false; for (SgStatementPtrList::reverse_iterator i = stmts.rbegin(); i != stmts.rend(); ++i) { if (containsVariableReference(*i, lifetime)) inLiveRange = true; SgVariableSymbol* toCheckSym = new SgVariableSymbol(toCheck); SgVarRefExp* toCheckVr = new SgVarRefExp(SgNULL_FILE, toCheckSym); bool result = false; if (inLiveRange && isPotentiallyModified(toCheckVr, *i)) { result = true; } delete toCheckSym; toCheckSym = NULL; toCheckVr->set_symbol(NULL); delete toCheckVr; toCheckVr = NULL; if (result) return true; if (isSgVariableDeclaration(*i) && isDeclarationOf(isSgVariableDeclaration(*i), lifetime)) return false; // This must be last } return false; }
virtual void visit(SgNode* n) { SgVarRefExp* vr = isSgVarRefExp(n); if (!vr) return; SgInitializedName* in = vr->get_symbol()->get_declaration(); paramMapType::const_iterator iter = paramMap.find(in); if (iter == paramMap.end()) return; // This is not a parameter use vr->set_symbol(iter->second); }
// Same as doSubexpressionExpansion, but requires exactly one use of // initname, and this use must be in a simple context void doSubexpressionExpansionSmart(SgInitializedName* initname) { SgNode* root = initname->get_parent()->get_parent(); assert (root); int count = countVariableReferences(root, initname); // cout << "Initname " << initname->get_name().str() << " was used " << count << " time(s)" << endl; if (count != 1) return; bool doExpansion = true; SgVariableSymbol* initnameSym = new SgVariableSymbol(initname); SgVarRefExp* initnameVr = new SgVarRefExp(SgNULL_FILE, initnameSym); if (isPotentiallyModified(initnameVr, root)) { doExpansion = false; } delete initnameSym; initnameSym = NULL; initnameVr->set_symbol(NULL); delete initnameVr; initnameVr = NULL; if (doExpansion) { doSubexpressionExpansion(initname, true); } }
ClastToSage::ClastToSage(SgScopeStatement* scopScope, clast_stmt* root, scoplib_scop_p scoplibScop, PolyRoseOptions& options) { //SgScopeStatement* scope = isSgScopeStatement((SgNode*) scoplibScop->usr); _polyoptions = options; SgScopeStatement* scope = scopScope; ROSE_ASSERT(scope); m_scopRoot = NULL; /// OLD: m_scope = scope; m_scoplib_scop = scoplibScop; m_verbose = _polyoptions.isVerbose(); // 0- Retrive meta information stored as an annotation of the // SageAST root. SgStatement* scopRoot = isSgStatement((SgNode*)(scoplibScop->usr)); ScopRootAnnotation* annot = (ScopRootAnnotation*)(scopRoot->getAttribute("ScopRoot")); ROSE_ASSERT(annot); _fakeSymbolMap = annot->fakeSymbolMap; // 1- Collect all iterators in the clast. They are of the from 'cXX' // where XX is an integer. _scoplibIterators = collectAllIterators(root); // 2- Map clast iterator to new variables that does not conflict // with existing names, and register the symbols in the symbol // table. _sageIterators = createNewIterators(_scoplibIterators, scope); // 3- Create the basic block containing the transformed scop. SgBasicBlock* bb = buildBasicBlock(root); // 4- Update the variable scope with the new bb, and insert the // declaration statement in the AST. std::map<const char*, SgVariableDeclaration*>::iterator iter; Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(bb,V_SgVarRefExp); for(iter = _sageIterators.begin(); iter != _sageIterators.end(); ++iter) { // Deal with the symbol tables. SgInitializedNamePtrList& l = iter->second->get_variables(); for (SgInitializedNamePtrList::iterator i = l.begin(); i != l.end(); i++) { (*i)->set_scope(bb); SgVariableSymbol* sym = new SgVariableSymbol(*i); bb->insert_symbol((*i)->get_name(), sym); // Ugly hack: replace the old symbol with the new entry in // the symbol table. for (Rose_STL_Container<SgNode *>::iterator j = varRefs.begin(); j != varRefs.end(); j++) { SgVarRefExp *vRef = isSgVarRefExp((*j)); if (vRef->get_symbol()->get_name() == (*i)->get_name()) vRef->set_symbol(sym); } } // Insert the declaration statement in the BB. bb->prepend_statement(iter->second); } // Post-process for pragma insertion. if (options.getGeneratePragmas()) insertPragmas(bb); m_scopRoot = bb; }