コード例 #1
0
ファイル: IntervalPropertyState.C プロジェクト: 8l/rose
VariableIdSet SPRAY::IntervalPropertyState::allVariableIds() {
  VariableIdSet set;
  for(IntervalMapType::iterator i=intervals.begin();i!=intervals.end();++i) {
    set.insert((*i).first);
  }
  return set;
}
コード例 #2
0
/*! 
  * \author Markus Schordan
  * \date 2014.
 */
void SPRAY::IntervalTransferFunctions::transferFunctionExit(Label lab, SgFunctionDefinition* funDef, VariableIdSet& localVariablesInFunction, Lattice& element) {
  // remove all declared variables at function exit (including function parameter variables)
  for(VariableIdSet::iterator i=localVariablesInFunction.begin();i!=localVariablesInFunction.end();++i) {
    VariableId varId=*i;
    IntervalPropertyState* ips=dynamic_cast<IntervalPropertyState*>(&element);
    ips->removeVariable(varId);
  }
}
コード例 #3
0
VariableIdSet PState::getVariableIds() const {
  VariableIdSet varIdSet;
  for(PState::const_iterator i=begin();i!=end();++i) {
    VariableId varId=(*i).first;
    varIdSet.insert(varId);
  }
  return varIdSet;
}
コード例 #4
0
/*! 
  * \author Markus Schordan
  * \date 2013.
 */
void RDTransferFunctions::transferFunctionExit(Label lab, SgFunctionDefinition* callExp, VariableIdSet& localVariablesInFunction, Lattice& element0) {
  RDLattice& element=dynamic_cast<RDLattice&>(element0);

  // remove all declared variable at function exit (including function parameter variables)
  for(VariableIdSet::iterator i=localVariablesInFunction.begin();i!=localVariablesInFunction.end();++i) {
    VariableId varId=*i;
    element.removeAllPairsWithVariableId(varId);
  }
}
コード例 #5
0
VariableIdSet 
AnalysisAbstractionLayer::usedVariablesInsideFunctions(SgProject* project, VariableIdMapping* variableIdMapping) {
  list<SgVarRefExp*> varRefExpList=SgNodeHelper::listOfUsedVarsInFunctions(project);
  VariableIdSet setOfUsedVars;
  for(list<SgVarRefExp*>::iterator i=varRefExpList.begin();i!=varRefExpList.end();++i) {
    setOfUsedVars.insert(variableIdMapping->variableId(*i));
  }
  return setOfUsedVars;
}
コード例 #6
0
/*! 
  * \author Markus Schordan
  * \date 2012.
 */
VariableIdMapping::VariableIdSet VariableIdMapping::getVariableIdSet() {
  VariableIdSet set;
  for(map<SgSymbol*,size_t>::iterator i=mappingSymToVarId.begin();i!=mappingSymToVarId.end();++i) {
    size_t t=(*i).second;
    VariableId id;
    id.setIdCode(t);
    set.insert(id);
  }
  return set;
}
コード例 #7
0
VariableIdSet AnalysisAbstractionLayer::defVariables(SgNode* node, VariableIdMapping& vidm) {
  VariableIdSet resultSet;
  VarsInfo defVarsInfo=getDefUseVarsInfo(node, vidm).getDefVarsInfo();
  //cout<<"DEFISEVARSINFO: "<<DefUseVarsInfo::varsInfoPrettyPrint(defVarsInfo,vidm)<<endl;
  //cout<<"VariableIdInfoMap-size:"<<defVarsInfo.first.size()<<endl;
  extractVariableIdSetFromVarsInfo(resultSet,defVarsInfo);
  ROSE_ASSERT(defVarsInfo.first.size()==resultSet.size());
  ROSE_ASSERT(defVarsInfo.first.size()<=1);
  return resultSet;
}
コード例 #8
0
ファイル: VariableIdUtils.C プロジェクト: 8l/rose
std::string SPRAY::VariableIdSetPrettyPrint::str(VariableIdSet& vset, VariableIdMapping& vidm)
{
  std::ostringstream ostr;
  ostr << "[";
  VariableIdSet::iterator it = vset.begin();
  for( ; it != vset.end(); )
  {
    ostr << "<" << (*it).toString() << ", " << vidm.variableName(*it)  << ">";
    it++;
    if(it != vset.end())
      ostr << ", ";
  }
  ostr << "]";
  return ostr.str();
}
コード例 #9
0
ファイル: VariableIdUtils.C プロジェクト: 8l/rose
std::string SPRAY::VariableIdSetPrettyPrint::str(VariableIdSet& vset)
{
  std::ostringstream ostr;
  ostr << "[";
  VariableIdSet::iterator it = vset.begin();
  for( ; it != vset.end(); )
  {
    ostr << (*it).toString();
    it++;
    if(it != vset.end())
      ostr << ", ";
  }
  ostr << "]";
  return ostr.str();
}
コード例 #10
0
ファイル: Threadification.C プロジェクト: 8l/rose
VariableIdSet Threadification::determineVariablesOfInterest(SgNode* root) {
  VariableIdSet varIdSet;
  RoseAst ast(root);
  for(RoseAst::iterator i=ast.begin();i!=ast.end();++i) {
    if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(*i)) {
      VariableId varId=_variableIdMapping->variableId(varDecl);
      // specifically exclude array variable declarations
      if( (_variableIdMapping->hasPointerType(varId)||_variableIdMapping->hasIntegerType(varId)) 
            && _variableIdMapping->variableName(varId) != "stdout" 
            && _variableIdMapping->variableName(varId) != "__PRETTY_FUNCTION__" ) {
        varIdSet.insert(varId);
      }
    }
  }
  return varIdSet;
}
コード例 #11
0
VariableIdMapping::VariableIdSet VariableIdMapping::variableIdsOfAstSubTree(SgNode* node) {
  VariableIdSet vset;
  RoseAst ast(node);
  for(RoseAst::iterator i=ast.begin();i!=ast.end();++i) {
    VariableId vid; // default creates intentionally an invalid id.
    if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(*i)) {
      vid=variableId(varDecl);
    } else if(SgVarRefExp* varRefExp=isSgVarRefExp(*i)) {
      vid=variableId(varRefExp);
    } else if(SgInitializedName* initName=isSgInitializedName(*i)) {
      vid=variableId(initName);
    }
    if(vid.isValid())
      vset.insert(vid);
  }
  return vset;
}
コード例 #12
0
ファイル: FIConstAnalysis.C プロジェクト: alexjohn1362/rose
void FIConstAnalysis::filterVariables(VariableIdSet& variableIdSet) {
    VariableIdSet toBeRemoved;
    for(VarConstSetMap::iterator i=_varConstSetMap.begin(); i!=_varConstSetMap.end(); ++i) {
        VariableId varId=(*i).first;
        if(variableIdSet.find(varId)==variableIdSet.end()) {
            toBeRemoved.insert(varId);
        }
    }
    for(VariableIdSet::iterator i=toBeRemoved.begin(); i!=toBeRemoved.end(); ++i) {
        _varConstSetMap.erase(*i);
    }
}
コード例 #13
0
ファイル: VariableIdUtils.C プロジェクト: 8l/rose
void SPRAY::set_union(const VariableIdSet& set1, const VariableIdSet& set2, VariableIdSet& rset)
{
  VariableIdSet::const_iterator it1 = set1.begin();
  VariableIdSet::const_iterator it2 = set2.begin();
  VariableIdSet::iterator rit = rset.begin();
  
  // // re-implementation of set-union
  while(true)
  {
    if(it1 == set1.end())
    {
      rset.insert(it2, set2.end());
      break;
    }
    if(it2 == set2.end())
    {
      rset.insert(it1, set1.end());
      break;
    }
    
    if(*it1 < *it2)
    {
      rset.insert(rit, *it1); ++it1; ++rit;
    }
    else if(*it2 < *it1)
    {
      rset.insert(rit, *it2); ++it2; ++rit;
    }
    else
    {
      rset.insert(rit, *it1); ++it1; ++it2; ++rit;
    }
  }
}
コード例 #14
0
// returns the number of race conditions detected (0 or 1 as of now)
int Specialization::verifyUpdateSequenceRaceConditions(LoopInfoSet& loopInfoSet, ArrayUpdatesSequence& arrayUpdates, VariableIdMapping* variableIdMapping) {
  int cnt=0;
  stringstream ss;
  cout<<"STATUS: checking race conditions."<<endl;
  cout<<"INFO: number of parallel loops: "<<numParLoops(loopInfoSet,variableIdMapping)<<endl;

  VariableIdSet allIterVars;
  for(LoopInfoSet::iterator lis=loopInfoSet.begin();lis!=loopInfoSet.end();++lis) {
    allIterVars.insert((*lis).iterationVarId);
  }
  for(LoopInfoSet::iterator lis=loopInfoSet.begin();lis!=loopInfoSet.end();++lis) {
    if((*lis).iterationVarType==ITERVAR_PAR) {
      VariableId parVariable;
      parVariable=(*lis).iterationVarId;
      cout<<"INFO: checking parallel loop: "<<variableIdMapping->variableName(parVariable)<<endl;

      // race check
      // intersect w-set_i = empty
      // w-set_i intersect r-set_j = empty, i!=j.

      IndexToReadWriteDataMap indexToReadWriteDataMap;
      for(ArrayUpdatesSequence::iterator i=arrayUpdates.begin();i!=arrayUpdates.end();++i) {
        const EState* estate=(*i).first;
        const PState* pstate=estate->pstate();
        SgExpression* exp=(*i).second;
        IndexVector index;
        // use all vars for indexing or only outer+par loop variables
#ifdef USE_ALL_ITER_VARS
        for(VariableIdSet::iterator ol=allIterVars.begin();ol!=allIterVars.end();++ol) {
          VariableId otherVarId=*ol;
          ROSE_ASSERT(otherVarId.isValid());
          if(!pstate->varValue(otherVarId).isTop()) {
            int otherIntVal=pstate->varValue(otherVarId).getIntValue();
            index.push_back(otherIntVal);
          }
        }
#else
        for(VariableIdSet::iterator ol=(*lis).outerLoopsVarIds.begin();ol!=(*lis).outerLoopsVarIds.end();++ol) {
          VariableId otherVarId=*ol;
          ROSE_ASSERT(otherVarId.isValid());
          if(!pstate->varValue(otherVarId).isTop()&&pstate->varValue(otherVarId).isConstInt()) {
            int otherIntVal=pstate->varValue(otherVarId).getIntValue();
            index.push_back(otherIntVal);
          }
        }
        if(!pstate->varValue(parVariable).isTop()&&pstate->varValue(parVariable).isConstInt()) {
          int parIntVal=pstate->varValue(parVariable).getIntValue();
          index.push_back(parIntVal);
        }
#endif
        if((*lis).isInAssociatedLoop(estate)) {
          SgExpression* lhs=isSgExpression(SgNodeHelper::getLhs(exp));
          SgExpression* rhs=isSgExpression(SgNodeHelper::getRhs(exp));
          ROSE_ASSERT(isSgPntrArrRefExp(lhs)||SgNodeHelper::isFloatingPointAssignment(exp));
        
          //cout<<"EXP: "<<exp->unparseToString()<<", lhs:"<<lhs->unparseToString()<<" :: "<<endl;
          // read-set
          RoseAst rhsast(rhs);
          for(RoseAst::iterator j=rhsast.begin();j!=rhsast.end();++j) {
            if(SgPntrArrRefExp* useRef=isSgPntrArrRefExp(*j)) {
              j.skipChildrenOnForward();
              ArrayElementAccessData access(useRef,variableIdMapping);
              indexToReadWriteDataMap[index].readArrayAccessSet.insert(access);
            } else if(SgVarRefExp* useRef=isSgVarRefExp(*j)) {
              ROSE_ASSERT(useRef);
              j.skipChildrenOnForward();
              VariableId varId=variableIdMapping->variableId(useRef);
              indexToReadWriteDataMap[index].readVarIdSet.insert(varId);
            } else {
              //cout<<"INFO: UpdateExtraction: ignored expression on rhs:"<<(*j)->unparseToString()<<endl;
            }
          }
          if(SgPntrArrRefExp* arr=isSgPntrArrRefExp(lhs)) {
            ArrayElementAccessData access(arr,variableIdMapping);
            indexToReadWriteDataMap[index].writeArrayAccessSet.insert(access);
          } else if(SgVarRefExp* var=isSgVarRefExp(lhs)) {
            VariableId varId=variableIdMapping->variableId(var);
            indexToReadWriteDataMap[index].writeVarIdSet.insert(varId);
          } else {
            cerr<<"Error: SSA Numbering: unknown LHS."<<endl;
            exit(1);
          }
        
          ss<<"UPD"<<cnt<<":"<<pstate->toString(variableIdMapping)<<" : "<<exp->unparseToString()<<endl;
          ++cnt;
        }
      } // array sequence iter

      // to be utilized later for more detailed output
#if 0
      for(IndexToReadWriteDataMap::iterator imap=indexToReadWriteDataMap.begin();
          imap!=indexToReadWriteDataMap.end();
          ++imap) {
        //        cout<<"DEBUG: INDEX: "<<(*imap).first<<" R-SET: ";
        IndexVector index=(*imap).first;

        cout<<"DEBUG: INDEX: ";
        for(IndexVector::iterator iv=index.begin();iv!=index.end();++iv) {
          if(iv!=index.begin())
            cout<<",";
          cout<<*iv;
        }
        cout<<" R-SET: ";
        for(ArrayElementAccessDataSet::const_iterator i=indexToReadWriteDataMap[index].readArrayAccessSet.begin();i!=indexToReadWriteDataMap[index].readArrayAccessSet.end();++i) {
          cout<<(*i).toString(variableIdMapping)<<" ";
        }
        cout<<endl;
        cout<<"DEBUG: INDEX: ";
        for(IndexVector::iterator iv=index.begin();iv!=index.end();++iv) {
          if(iv!=index.begin())
            cout<<",";
          cout<<*iv;
        }
        cout<<" W-SET: ";
        for(ArrayElementAccessDataSet::const_iterator i=indexToReadWriteDataMap[index].writeArrayAccessSet.begin();i!=indexToReadWriteDataMap[index].writeArrayAccessSet.end();++i) {
          cout<<(*i).toString(variableIdMapping)<<" ";
        }
        cout<<endl;
        cout<<"DEBUG: read-array-access:"<<indexToReadWriteDataMap[index].readArrayAccessSet.size()<<" read-var-access:"<<indexToReadWriteDataMap[index].readVarIdSet.size()<<endl;
        cout<<"DEBUG: write-array-access:"<<indexToReadWriteDataMap[index].writeArrayAccessSet.size()<<" write-var-access:"<<indexToReadWriteDataMap[index].writeVarIdSet.size()<<endl;
      } // imap
#endif

      // perform the check now
      // 1) compute vector if index-vectors for each outer-var-vector
      // 2) check each index-vector. For each iteration of each par-loop iteration then.
      
      //typedef set<int> ParVariableValueSet;
      //ParVariableValueSet parVariableValueSet;
      // MAP: par-variable-val -> vector of IndexVectors with this par-variable-val
      typedef vector<IndexVector> ThreadVector;
      typedef map<IndexVector,ThreadVector > CheckMapType;
      CheckMapType checkMap;
      for(IndexToReadWriteDataMap::iterator imap=indexToReadWriteDataMap.begin();
          imap!=indexToReadWriteDataMap.end();
          ++imap) {
        IndexVector index=(*imap).first;
        IndexVector outVarIndex;
        // if index.size()==0, it will analyze the loop independet of outer loops
        if(index.size()>0) {
          ROSE_ASSERT(index.size()>0);
          for(size_t iv1=0;iv1<index.size()-1;iv1++) {
            outVarIndex.push_back(index[iv1]);
          }
          ROSE_ASSERT(outVarIndex.size()<index.size());
        } else {
          // nothing to check
          continue;
        }
        // last index of index of par-variable
        //int parVariableValue=index[index.size()-1];
        checkMap[outVarIndex].push_back(index);
      }
      //cout<<"INFO: race condition check-map size: "<<checkMap.size()<<endl;
      // perform the check now

      for(CheckMapType::iterator miter=checkMap.begin();miter!=checkMap.end();++miter) {
        IndexVector outerVarIndexVector=(*miter).first;
        ThreadVector threadVectorToCheck=(*miter).second;
        //cout<<"DEBUG: to check: "<<threadVectorToCheck.size()<<endl;
        for(ThreadVector::iterator tv1=threadVectorToCheck.begin();tv1!=threadVectorToCheck.end();++tv1) {
          ArrayElementAccessDataSet wset=indexToReadWriteDataMap[*tv1].writeArrayAccessSet;
          for(ThreadVector::iterator tv2=tv1;tv2!=threadVectorToCheck.end();++tv2) {
            ThreadVector::iterator tv2b=tv2;
            ++tv2b;
            if(tv2b!=threadVectorToCheck.end()) {
              ArrayElementAccessDataSet rset2=indexToReadWriteDataMap[*tv2b].readArrayAccessSet;
              ArrayElementAccessDataSet wset2=indexToReadWriteDataMap[*tv2b].writeArrayAccessSet;
              // check intersect(rset,wset)
              if(accessSetIntersect(wset,rset2)) {
                // verification failed
                cout<<"INFO: race condition detected (wset1,rset2)."<<endl;
                return 1;
              } 
              if(accessSetIntersect(wset,wset2)) {
                // verification failed
                cout<<"INFO: race condition detected (wset1,wset2)."<<endl;
                return 1;
              }
            }
          }
        }
      }
    } // if parallel loop
  } // foreach loop
  return 0;
}
コード例 #15
0
ファイル: woodpecker.C プロジェクト: 8l/rose
int main(int argc, char* argv[]) {
  try {
    if(argc==1) {
      cout << "Error: wrong command line options."<<endl;
      exit(1);
    }
#if 0
    if(argc==3) {
      csvAssertFileName=argv[2];
      argc=2; // don't confuse ROSE command line
      cout<< "INIT: CSV-output file: "<<csvAssertFileName<<endl;
    }
#endif
  // Command line option handling.
    namespace po = boost::program_options;
  po::options_description desc
    ("Woodpecker V0.1\n"
     "Written by Markus Schordan\n"
     "Supported options");
  
  desc.add_options()
    ("help,h", "produce this help message.")
    ("rose-help", "show help for compiler frontend options.")
    ("version,v", "display the version.")
    ("stats", "display code statistics.")
    ("normalize", po::value< string >(), "normalize code (eliminate compound assignment operators).")
    ("inline",po::value< string >(), "perform inlining ([yes]|no).")
    ("eliminate-empty-if",po::value< string >(), "eliminate if-statements with empty branches in main function ([yes]/no).")
    ("eliminate-dead-code",po::value< string >(), "eliminate dead code (variables and expressions) ([yes]|no).")
    ("csv-const-result",po::value< string >(), "generate csv-file [arg] with const-analysis data.")
    ("generate-transformed-code",po::value< string >(), "generate transformed code with prefix rose_ ([yes]|no).")
    ("verbose",po::value< string >(), "print detailed output during analysis and transformation (yes|[no]).")
    ("generate-conversion-functions","generate code for conversion functions between variable names and variable addresses.")
    ("csv-assert",po::value< string >(), "name of csv file with reachability assert results'")
    ("enable-multi-const-analysis",po::value< string >(), "enable multi-const analysis.")
    ("transform-thread-variable", "transform code to use additional thread variable.")
    ;
  //    ("int-option",po::value< int >(),"option info")


  po::store(po::command_line_parser(argc, argv).
            options(desc).allow_unregistered().run(), args);
  po::notify(args);

  if (args.count("help")) {
    cout << "woodpecker <filename> [OPTIONS]"<<endl;
    cout << desc << "\n";
    return 0;
  }
  if (args.count("rose-help")) {
    argv[1] = strdup("--help");
  }

  if (args.count("version")) {
    cout << "Woodpecker version 0.1\n";
    cout << "Written by Markus Schordan 2013\n";
    return 0;
  }
  if (args.count("csv-assert")) {
    csvAssertFileName=args["csv-assert"].as<string>().c_str();
  }
  if (args.count("csv-const-result")) {
    csvConstResultFileName=args["csv-const-result"].as<string>().c_str();
  }
  
  boolOptions.init(argc,argv);
  // temporary fake optinos
  boolOptions.registerOption("arith-top",false); // temporary
  boolOptions.registerOption("semantic-fold",false); // temporary
  boolOptions.registerOption("post-semantic-fold",false); // temporary
  // regular options
  boolOptions.registerOption("normalize",false);
  boolOptions.registerOption("inline",true);
  boolOptions.registerOption("eliminate-empty-if",true);
  boolOptions.registerOption("eliminate-dead-code",true);
  boolOptions.registerOption("generate-transformed-code",true);
  boolOptions.registerOption("enable-multi-const-analysis",false);
  boolOptions.registerOption("verbose",false);
  boolOptions.processOptions();

  if(boolOptions["verbose"])
    detailedOutput=1;

  // clean up string-options in argv
  for (int i=1; i<argc; ++i) {
    if (string(argv[i]) == "--csv-assert" 
        || string(argv[i]) == "--csv-const-result"
        ) {
      // do not confuse ROSE frontend
      argv[i] = strdup("");
      assert(i+1<argc);
        argv[i+1] = strdup("");
    }
  }

  global_option_multiconstanalysis=boolOptions["enable-multi-const-analysis"];
#if 0
  if(global_option_multiconstanalysis) {
    cout<<"INFO: Using flow-insensitive multi-const-analysis."<<endl;
  } else {
    cout<<"INFO: Using flow-insensitive unique-const-analysis."<<endl;
  }
#endif

  cout << "INIT: Parsing and creating AST started."<<endl;
  SgProject* root = frontend(argc,argv);
  //  AstTests::runAllTests(root);
  // inline all functions
  cout << "INIT: Parsing and creating AST finished."<<endl;

  if(args.count("stats")) {
    printCodeStatistics(root);
    exit(0);
  }

  VariableIdMapping variableIdMapping;
  variableIdMapping.computeVariableSymbolMapping(root);

  if(args.count("transform-thread-variable")) {
    Threadification* threadTransformation=new Threadification(&variableIdMapping);
    threadTransformation->transform(root);
    root->unparse(0,0);
    delete threadTransformation;
    cout<<"STATUS: generated program with introduced thread-variable."<<endl;
    exit(0);
  }

  SgFunctionDefinition* mainFunctionRoot=0;
  if(boolOptions["inline"]) {
    cout<<"STATUS: eliminating non-called trivial functions."<<endl;
    // inline functions
    TrivialInlining tin;
    tin.setDetailedOutput(detailedOutput);
    tin.inlineFunctions(root);
    DeadCodeElimination dce;
    // eliminate non called functions
    int numEliminatedFunctions=dce.eliminateNonCalledTrivialFunctions(root);
    cout<<"STATUS: eliminated "<<numEliminatedFunctions<<" functions."<<endl;
  } else {
    cout<<"INFO: Inlining: turned off."<<endl;
  }

  if(boolOptions["eliminate-empty-if"]) {
    DeadCodeElimination dce;
    cout<<"STATUS: Eliminating empty if-statements."<<endl;
    size_t num=0;
    size_t numTotal=num;
    do {
      num=dce.eliminateEmptyIfStmts(root);
      cout<<"INFO: Number of if-statements eliminated: "<<num<<endl;
      numTotal+=num;
    } while(num>0);
    cout<<"STATUS: Total number of empty if-statements eliminated: "<<numTotal<<endl;
  }

  if(boolOptions["normalize"]) {
    cout <<"STATUS: Normalization started."<<endl;
    RewriteSystem rewriteSystem;
    rewriteSystem.resetStatistics();
    rewriteSystem.rewriteCompoundAssignmentsInAst(root,&variableIdMapping);
    cout <<"STATUS: Normalization finished."<<endl;

  }
 
  cout<<"STATUS: performing flow-insensitive const analysis."<<endl;
  VarConstSetMap varConstSetMap;
  VariableIdSet variablesOfInterest;
  FIConstAnalysis fiConstAnalysis(&variableIdMapping);
  fiConstAnalysis.setOptionMultiConstAnalysis(global_option_multiconstanalysis);
  fiConstAnalysis.setDetailedOutput(detailedOutput);
  fiConstAnalysis.runAnalysis(root, mainFunctionRoot);
  variablesOfInterest=fiConstAnalysis.determinedConstantVariables();
  cout<<"INFO: variables of interest: "<<variablesOfInterest.size()<<endl;
  if(detailedOutput)
    printResult(variableIdMapping,varConstSetMap);

  if(csvConstResultFileName) {
    VariableIdSet setOfUsedVarsInFunctions=AnalysisAbstractionLayer::usedVariablesInsideFunctions(root,&variableIdMapping);
    VariableIdSet setOfUsedVarsGlobalInit=AnalysisAbstractionLayer::usedVariablesInGlobalVariableInitializers(root,&variableIdMapping);
    VariableIdSet setOfAllUsedVars = setOfUsedVarsInFunctions;
    setOfAllUsedVars.insert(setOfUsedVarsGlobalInit.begin(), setOfUsedVarsGlobalInit.end());
    cout<<"INFO: number of used vars inside functions: "<<setOfUsedVarsInFunctions.size()<<endl;
    cout<<"INFO: number of used vars in global initializations: "<<setOfUsedVarsGlobalInit.size()<<endl;
    cout<<"INFO: number of vars inside functions or in global inititializations: "<<setOfAllUsedVars.size()<<endl;
    fiConstAnalysis.filterVariables(setOfAllUsedVars);
    fiConstAnalysis.writeCvsConstResult(variableIdMapping, string(csvConstResultFileName));
  }

  if(args.count("generate-conversion-functions")) {
    string conversionFunctionsFileName="conversionFunctions.C";
    ConversionFunctionsGenerator gen;
    set<string> varNameSet;
    std::list<SgVariableDeclaration*> globalVarDeclList=SgNodeHelper::listOfGlobalVars(root);
    for(std::list<SgVariableDeclaration*>::iterator i=globalVarDeclList.begin();i!=globalVarDeclList.end();++i) {
      SgInitializedNamePtrList& initNamePtrList=(*i)->get_variables();
      for(SgInitializedNamePtrList::iterator j=initNamePtrList.begin();j!=initNamePtrList.end();++j) {
	      SgInitializedName* initName=*j;
        if ( true || isSgArrayType(initName->get_type()) ) {  // optional filter (array variables only)
	        SgName varName=initName->get_name();
	        string varNameString=varName; // implicit conversion
	        varNameSet.insert(varNameString);
        }
      }
    }
    string code=gen.generateCodeForGlobalVarAdressMaps(varNameSet);
    ofstream myfile;
    myfile.open(conversionFunctionsFileName.c_str());
    myfile<<code;
    myfile.close();
  }

  VariableConstInfo vci=*(fiConstAnalysis.getVariableConstInfo());
  DeadCodeElimination dce;
  if(boolOptions["eliminate-dead-code"]) {
    cout<<"STATUS: performing dead code elimination."<<endl;
    dce.setDetailedOutput(detailedOutput);
    dce.setVariablesOfInterest(variablesOfInterest);
    dce.eliminateDeadCodePhase1(root,&variableIdMapping,vci);
    cout<<"STATUS: Eliminated "<<dce.numElimVars()<<" variable declarations."<<endl;
    cout<<"STATUS: Eliminated "<<dce.numElimAssignments()<<" variable assignments."<<endl;
    cout<<"STATUS: Replaced "<<dce.numElimVarUses()<<" uses of variables with constant."<<endl;
    cout<<"STATUS: Eliminated "<<dce.numElimVars()<<" dead variables."<<endl;
    cout<<"STATUS: Dead code elimination phase 1: finished."<<endl;
    cout<<"STATUS: Performing condition const analysis."<<endl;
  } else {
    cout<<"STATUS: Dead code elimination: turned off."<<endl;
  }
  if(csvAssertFileName) {
    cout<<"STATUS: performing flow-insensensitive condition-const analysis."<<endl;
    Labeler labeler(root);
    fiConstAnalysis.performConditionConstAnalysis(&labeler);
    cout<<"INFO: Number of true-conditions     : "<<fiConstAnalysis.getTrueConditions().size()<<endl;
    cout<<"INFO: Number of false-conditions    : "<<fiConstAnalysis.getFalseConditions().size()<<endl;
    cout<<"INFO: Number of non-const-conditions: "<<fiConstAnalysis.getNonConstConditions().size()<<endl;
    cout<<"STATUS: performing flow-insensensitive reachability analysis."<<endl;
    ReachabilityAnalysis ra;
    PropertyValueTable reachabilityResults=ra.fiReachabilityAnalysis(labeler, fiConstAnalysis);
    cout<<"STATUS: generating file "<<csvAssertFileName<<endl;
    reachabilityResults.writeFile(csvAssertFileName,true);
  }
#if 0
  rdAnalyzer->determineExtremalLabels(startFunRoot);
  rdAnalyzer->run();
#endif
  cout << "INFO: Remaining functions in program: "<<numberOfFunctions(root)<<endl;
  if(boolOptions["generate-transformed-code"]) {
    cout << "STATUS: generating transformed source code."<<endl;
    root->unparse(0,0);
  }

  std::list<int> fakelist;
  fakelist.push_back(1);
  std::list<int>::iterator myit=fakelist.begin();
  fakelist.erase(myit);
  cout<< "STATUS: finished."<<endl;

  // main function try-catch
  } catch(char* str) {
    cerr << "*Exception raised: " << str << endl;
    return 1;
  } catch(const char* str) {
    cerr << "Exception raised: " << str << endl;
    return 1;
  } catch(string str) {
    cerr << "Exception raised: " << str << endl;
    return 1;
  }
  return 0;
}
コード例 #16
0
void runAnalyses(SgProject* root, Labeler* labeler, VariableIdMapping* variableIdMapping) {

  SPRAY::DFAnalysisBase::normalizeProgram(root);

  if(option_fi_constanalysis) {
    VarConstSetMap varConstSetMap;
    FIConstAnalysis fiConstAnalysis(variableIdMapping);
    fiConstAnalysis.runAnalysis(root);
    fiConstAnalysis.attachAstAttributes(labeler,"const-analysis-inout"); // not iolabeler
    if(csvConstResultFileName) {
      cout<<"INFO: generating const CSV file "<<option_prefix+csvConstResultFileName<<endl;
      fiConstAnalysis.writeCvsConstResult(*variableIdMapping, option_prefix+csvConstResultFileName);
    }
    cout << "INFO: annotating analysis results as comments."<<endl;
    AstAnnotator ara(labeler);
    ara.annotateAstAttributesAsCommentsBeforeStatements(root, "const-analysis-inout");
    ara.annotateAstAttributesAsCommentsAfterStatements(root, "const-analysis-inout");
  }

  if(option_at_analysis) {
    cout<<"STATUS: running address taken analysis."<<endl;
    cout << "STATUS: computing variable and function mappings."<<endl;
    // compute variableId mappings
    VariableIdMapping variableIdMapping;
    variableIdMapping.computeVariableSymbolMapping(root);
    // Compute function id mappings:
    FunctionIdMapping functionIdMapping;
    functionIdMapping.computeFunctionSymbolMapping(root);

    if(option_trace) {
      std::cout << std::endl << "TRACE: Variable Id Mapping:" << std::endl;
      variableIdMapping.toStream(std::cout);
      std::cout << std::endl << "TRACE: Function Id Mapping:" << std::endl;
      functionIdMapping.toStream(std::cout);
    }

    cout << "STATUS: computing address taken sets."<<endl;
    SPRAY::FIPointerAnalysis fipa(&variableIdMapping, &functionIdMapping, root);
    fipa.initialize();
    fipa.run();

    //cout << "STATUS: computed address taken sets:"<<endl;
    //fipa.getFIPointerInfo()->printInfoSets();

    bool createCsv = false;
    ofstream addressTakenCsvFile;
    if(csvAddressTakenResultFileName) {
      std::string addressTakenCsvFileName = option_prefix;
      addressTakenCsvFileName += csvAddressTakenResultFileName;
      addressTakenCsvFile.open(addressTakenCsvFileName.c_str());
      createCsv = true;
    }

    cout << "INFO: annotating declarations of address taken variables and functions."<<endl;

    // Annotate declarations/definitions of variables from which the address was taken:
    VariableIdSet addressTakenVariableIds = fipa.getAddressTakenVariables();
    for(VariableIdSet::const_iterator idIter = addressTakenVariableIds.begin(); idIter != addressTakenVariableIds.end(); ++idIter) {
      // Determine the variable declaration/definition:
      SgLocatedNode* decl = variableIdMapping.getVariableDeclaration(*idIter);
      if(!decl) {
        // The current variable is presumably a function parameter: Try to get the initialized name:
        SgVariableSymbol* varSymbol = isSgVariableSymbol(variableIdMapping.getSymbol(*idIter));
        ROSE_ASSERT(varSymbol);
        SgInitializedName* paramDecl = isSgInitializedName(varSymbol->get_declaration());
        // We should not have a real variable declaration for the parameter:
        ROSE_ASSERT(isSgFunctionParameterList(paramDecl->get_declaration()));

        // Use the InitializedName:
        decl = paramDecl;
      }

      if(decl) {
        // Create the comment:
        ostringstream commentStream;
        commentStream << "/* Address of \"" << variableIdMapping.variableName(*idIter) << "\" is "
                      << "presumably taken.*/";

        // Annotate first declaration:
        insertComment(commentStream.str(), PreprocessingInfo::before, decl);
        // TODO: Annotate other declarations too!

        // Annotate definition if available (e.g. not available in case of parameter):
        if(SgDeclarationStatement* variableDeclaration = isSgDeclarationStatement(decl)) {
          if(SgDeclarationStatement* definingDeclaration = variableDeclaration->get_definingDeclaration()) {
            insertComment(commentStream.str(), PreprocessingInfo::before, definingDeclaration);
          }
        }

        if(createCsv) {
          // Write variable info to csv:
          addressTakenCsvFile << VariableId::idKindIndicator << ","
                              // The id of the variable (id codes are influenced by the used system headers
                              //  and are therefore not stable/portable):
                              << (option_csv_stable ? string("<unstable>") : int_to_string((*idIter).getIdCode())) << ","
                              // Name of the variable:
                              << variableIdMapping.variableName(*idIter) << ","

                              // TODO: Mangled scope and type are currently not stable/portable
                              //  (see comments in getScopeAsMangledStableString(...))
                              // Mangled type of the variable (non-mangled type may contain commas (e.g. "A<int,bool>"):
                              << (option_csv_stable ? string("<unstable>") : variableIdMapping.getType(*idIter)->get_mangled().getString()) << ","
                              // Mangled scope of the variable:
                              << (option_csv_stable ? string("<unstable>") : getScopeAsMangledStableString(decl)) << ","

                              // Is the address taken? (currently only address taken variables are output to csv)
                              << "1" << endl;
        }
      }
      else {
        cout << "ERROR: No declaration for " << variableIdMapping.uniqueShortVariableName(*idIter) << " available." << endl;
        ROSE_ASSERT(false);
      }
    }

    // Annotate declarations and definitions of functions from which the address was taken:
    FunctionIdSet addressTakenFunctionIds = fipa.getAddressTakenFunctions();
    for(FunctionIdSet::const_iterator idIter = addressTakenFunctionIds.begin(); idIter != addressTakenFunctionIds.end(); ++idIter) {

      if(SgFunctionDeclaration* decl = functionIdMapping.getFunctionDeclaration(*idIter)) {
        // Create the comment:
        ostringstream commentStream;
        commentStream << "/* Address of \"" << functionIdMapping.getFunctionNameFromFunctionId(*idIter) << "(...)\" is "
                      << "presumably taken.*/";

        // Annotate first declaration:
        insertComment(commentStream.str(), PreprocessingInfo::before, decl);
        // TODO: Annotate other declarations too!

        // Annotate definition if available:
        if(SgDeclarationStatement* definingDeclaration = decl->get_definingDeclaration()) {
          insertComment(commentStream.str(), PreprocessingInfo::before, definingDeclaration);
        }

        if(createCsv) {
          addressTakenCsvFile << FunctionId::idKindIndicator << ","
                              // The id of the function (id codes are influenced by the used system headers
                              //  and are therefore not stable/portable):
                              << (option_csv_stable ? string("<unstable>") : int_to_string((*idIter).getIdCode())) << ","
                              // Name of the function:
                              << functionIdMapping.getFunctionNameFromFunctionId(*idIter) << ","

                              // TODO: Mangled scope and type are currently not stable/portable
                              //  (see comments in getScopeAsMangledStableString(...))
                              // Mangled type of the function (non-mangled type may contain commas (e.g. "void (A<int,bool>)"):
                              << (option_csv_stable ? string("<unstable>") : functionIdMapping.getTypeFromFunctionId(*idIter)->get_mangled().getString()) << ","
                              // Mangled scope of the function:
                              << (option_csv_stable ? string("<unstable>") :getScopeAsMangledStableString(decl)) << ","

                              // Is the address taken? (currently only address taken functions are output to csv)
                              << "1" << endl;
        }
      }
      else {
        cout << "ERROR: No declaration for " << functionIdMapping.getUniqueShortNameFromFunctionId(*idIter) << " available." << endl;
        ROSE_ASSERT(false);
      }
    }

    if(createCsv) {
      addressTakenCsvFile.close();
    }

#if 0
    VariableIdSet vidset=fipa.getModByPointer();
    cout<<"mod-set: "<<SPRAY::VariableIdSetPrettyPrint::str(vidset,variableIdMapping)<<endl;
#endif
  }
  
  if(option_interval_analysis) {
    cout << "STATUS: creating interval analyzer."<<endl;
    SPRAY::IntervalAnalysis* intervalAnalyzer=new SPRAY::IntervalAnalysis();
    cout << "STATUS: initializing interval analyzer."<<endl;
    intervalAnalyzer->setNoTopologicalSort(option_no_topological_sort);
    intervalAnalyzer->initialize(root);
    cout << "STATUS: running pointer analysis."<<endl;
    ROSE_ASSERT(intervalAnalyzer->getVariableIdMapping());
    SPRAY::FIPointerAnalysis* fipa=new FIPointerAnalysis(intervalAnalyzer->getVariableIdMapping(), intervalAnalyzer->getFunctionIdMapping(), root);
    fipa->initialize();
    fipa->run();
    intervalAnalyzer->setPointerAnalysis(fipa);
    cout << "STATUS: initializing interval transfer functions."<<endl;
    intervalAnalyzer->initializeTransferFunctions();
    cout << "STATUS: initializing interval global variables."<<endl;
    intervalAnalyzer->initializeGlobalVariables(root);
      
    intervalAnalyzer->setSolverTrace(option_trace);
    std::string funtofind="main";
    RoseAst completeast(root);
    SgFunctionDefinition* startFunRoot=completeast.findFunctionByName(funtofind);
    intervalAnalyzer->determineExtremalLabels(startFunRoot);
    intervalAnalyzer->run();

#if 0
    intervalAnalyzer->attachInInfoToAst("iv-analysis-in");
    intervalAnalyzer->attachOutInfoToAst("iv-analysis-out");
    AstAnnotator ara(intervalAnalyzer->getLabeler(),intervalAnalyzer->getVariableIdMapping());
    ara.annotateAstAttributesAsCommentsBeforeStatements(root, "iv-analysis-in");
    ara.annotateAstAttributesAsCommentsAfterStatements(root, "iv-analysis-out");
#else
    AnalysisAstAnnotator ara(intervalAnalyzer->getLabeler(),intervalAnalyzer->getVariableIdMapping());
    ara.annotateAnalysisPrePostInfoAsComments(root,"iv-analysis",intervalAnalyzer);
#endif
    if(option_check_static_array_bounds) {
      checkStaticArrayBounds(root,intervalAnalyzer);
    }
    // schroder3 (2016-08-08): Generate csv-file that contains unreachable statements:
    if(csvDeadCodeUnreachableFileName) {
      // Generate file name and open file:
      std::string deadCodeCsvFileName = option_prefix;
      deadCodeCsvFileName += csvDeadCodeUnreachableFileName;
      ofstream deadCodeCsvFile;
      deadCodeCsvFile.open(deadCodeCsvFileName.c_str());
      // Iteratate over all CFG nodes/ labels:
      for(Flow::const_node_iterator i = intervalAnalyzer->getFlow()->nodes_begin(); i != intervalAnalyzer->getFlow()->nodes_end(); ++i) {
        const Label& label = *i;
        // Do not output a function call twice (only the function call label and not the function call return label):
        if(!intervalAnalyzer->getLabeler()->isFunctionCallReturnLabel(label)) {
          /*const*/ IntervalPropertyState& intervalsLattice = *static_cast<IntervalPropertyState*>(intervalAnalyzer->getPreInfo(label.getId()));
          if(intervalsLattice.isBot()) {
            // Unreachable statement found:
            const SgNode* correspondingNode = intervalAnalyzer->getLabeler()->getNode(label);
            ROSE_ASSERT(correspondingNode);
            // Do not output scope statements ({ }, ...)
            if(!isSgScopeStatement(correspondingNode)) {
              deadCodeCsvFile << correspondingNode->get_file_info()->get_line()
                              << "," << SPRAY::replace_string(correspondingNode->unparseToString(), ",", "/*comma*/")
                              << endl;
            }
          }
        }
      }
      deadCodeCsvFile.close();
    }

    delete fipa;
  }

  if(option_lv_analysis) {
    cout << "STATUS: creating LV analysis."<<endl;
    SPRAY::LVAnalysis* lvAnalysis=new SPRAY::LVAnalysis();
    cout << "STATUS: initializing LV analysis."<<endl;
    lvAnalysis->setBackwardAnalysis();
    lvAnalysis->setNoTopologicalSort(option_no_topological_sort);
    lvAnalysis->initialize(root);
    cout << "STATUS: running pointer analysis."<<endl;
    ROSE_ASSERT(lvAnalysis->getVariableIdMapping());
    SPRAY::FIPointerAnalysis* fipa = new FIPointerAnalysis(lvAnalysis->getVariableIdMapping(), lvAnalysis->getFunctionIdMapping(), root);
    fipa->initialize();
    fipa->run();
    lvAnalysis->setPointerAnalysis(fipa);
    cout << "STATUS: initializing LV transfer functions."<<endl;
    lvAnalysis->initializeTransferFunctions();
    cout << "STATUS: initializing LV global variables."<<endl;
    lvAnalysis->initializeGlobalVariables(root);
    std::string funtofind="main";
    RoseAst completeast(root);
    SgFunctionDefinition* startFunRoot=completeast.findFunctionByName(funtofind);
    cout << "generating icfg_backward.dot."<<endl;
    write_file("icfg_backward.dot", lvAnalysis->getFlow()->toDot(lvAnalysis->getLabeler()));

    lvAnalysis->determineExtremalLabels(startFunRoot);
    lvAnalysis->run();
    cout << "INFO: attaching LV-data to AST."<<endl;
#if 0
    lvAnalysis->attachInInfoToAst("lv-analysis-in");
    lvAnalysis->attachOutInfoToAst("lv-analysis-out");
    AstAnnotator ara(lvAnalysis->getLabeler(),lvAnalysis->getVariableIdMapping());
    ara.annotateAstAttributesAsCommentsBeforeStatements(root, "lv-analysis-in");
    ara.annotateAstAttributesAsCommentsAfterStatements(root, "lv-analysis-out");
#else
    AnalysisAstAnnotator ara(lvAnalysis->getLabeler(),lvAnalysis->getVariableIdMapping());
    ara.annotateAnalysisPrePostInfoAsComments(root,"lv-analysis",lvAnalysis);
#endif

    // schroder3 (2016-08-15): Generate csv-file that contains dead assignments/ initializations:
    if(csvDeadCodeDeadStoreFileName) {
      // Generate file name and open file:
      std::string deadCodeCsvFileName = option_prefix;
      deadCodeCsvFileName += csvDeadCodeDeadStoreFileName;
      ofstream deadCodeCsvFile;
      deadCodeCsvFile.open(deadCodeCsvFileName.c_str());
      if(option_trace) {
        cout << "TRACE: checking for dead stores." << endl;
      }
      // Iteratate over all CFG nodes/ labels:
      for(Flow::const_node_iterator labIter = lvAnalysis->getFlow()->nodes_begin(); labIter != lvAnalysis->getFlow()->nodes_end(); ++labIter) {
        const Label& label = *labIter;
        // Do not output a function call twice (only the function call return label and not the function call label):
        if(!lvAnalysis->getLabeler()->isFunctionCallLabel(label)) {
          /*const*/ SgNode* correspondingNode = lvAnalysis->getLabeler()->getNode(label);
          ROSE_ASSERT(correspondingNode);
          if(/*const*/ SgExprStatement* exprStmt = isSgExprStatement(correspondingNode)) {
            correspondingNode = exprStmt->get_expression();
          }
          /*const*/ SgNode* association = 0;
          // Check if the corresponding node is an assignment or an initialization:
          if(isSgAssignOp(correspondingNode)) {
            association = correspondingNode;
          }
          else if(SgVariableDeclaration* varDecl = isSgVariableDeclaration(correspondingNode)) {
            SgInitializedName* initName = SgNodeHelper::getInitializedNameOfVariableDeclaration(varDecl);
            ROSE_ASSERT(initName);
            // Check whether there is an initialization that can be eliminated (reference initialization can not be eliminated).
            if(!SgNodeHelper::isReferenceType(initName->get_type()) && initName->get_initializer()) {
              association = correspondingNode;
            }
          }

          if(association) {
            if(option_trace) {
              cout << endl << "association: " << association->unparseToString() << endl;
            }
            VariableIdSet assignedVars = AnalysisAbstractionLayer::defVariables(association, *lvAnalysis->getVariableIdMapping(), fipa);
            /*const*/ LVLattice& liveVarsLattice = *static_cast<LVLattice*>(lvAnalysis->getPreInfo(label.getId()));
            if(option_trace) {
              cout << "live: " << liveVarsLattice.toString(lvAnalysis->getVariableIdMapping()) << endl;
              cout << "assigned: " << endl;
            }
            bool minOneIsLive = false;
            for(VariableIdSet::const_iterator assignedVarIter = assignedVars.begin(); assignedVarIter != assignedVars.end(); ++assignedVarIter) {
              if(option_trace) {
                cout << (*assignedVarIter).toString(*lvAnalysis->getVariableIdMapping()) << endl;
              }
              if(liveVarsLattice.exists(*assignedVarIter)) {
                minOneIsLive = true;
                break;
              }
            }
            if(!minOneIsLive) {
              if(option_trace) {
                cout << "association is dead." << endl;
              }
              // assignment to only dead variables found:
              deadCodeCsvFile << correspondingNode->get_file_info()->get_line()
                              << "," << SPRAY::replace_string(correspondingNode->unparseToString(), ",", "/*comma*/")
                              << endl;
            }
          }
        }
      }
      deadCodeCsvFile.close();
    }
    delete lvAnalysis;
  }

  if(option_rd_analysis) {
      cout << "STATUS: creating RD analyzer."<<endl;
      SPRAY::RDAnalysis* rdAnalysis=new SPRAY::RDAnalysis();
      cout << "STATUS: initializing RD analyzer."<<endl;
      rdAnalysis->setNoTopologicalSort(option_no_topological_sort);
      rdAnalysis->initialize(root);
      cout << "STATUS: initializing RD transfer functions."<<endl;
      rdAnalysis->initializeTransferFunctions();
      cout << "STATUS: initializing RD global variables."<<endl;
      rdAnalysis->initializeGlobalVariables(root);
      
      cout << "generating icfg_forward.dot."<<endl;
      write_file("icfg_forward.dot", rdAnalysis->getFlow()->toDot(rdAnalysis->getLabeler()));
    
      std::string funtofind="main";
      RoseAst completeast(root);
      SgFunctionDefinition* startFunRoot=completeast.findFunctionByName(funtofind);
      rdAnalysis->determineExtremalLabels(startFunRoot);
      rdAnalysis->run();
    
      cout << "INFO: attaching RD-data to AST."<<endl;
      rdAnalysis->attachInInfoToAst("rd-analysis-in");
      rdAnalysis->attachOutInfoToAst("rd-analysis-out");
      //printAttributes<RDAstAttribute>(rdAnalysis->getLabeler(),rdAnalysis->getVariableIdMapping(),"rd-analysis-in");
      cout << "INFO: annotating analysis results as comments."<<endl;
      ROSE_ASSERT(rdAnalysis->getVariableIdMapping());
#if 0
      AstAnnotator ara(rdAnalysis->getLabeler(),rdAnalysis->getVariableIdMapping());
      ara.annotateAstAttributesAsCommentsBeforeStatements(root, "rd-analysis-in");
      ara.annotateAstAttributesAsCommentsAfterStatements(root, "rd-analysis-out");
#else
      AnalysisAstAnnotator ara(rdAnalysis->getLabeler(),rdAnalysis->getVariableIdMapping());
      ara.annotateAnalysisPrePostInfoAsComments(root,"rd-analysis",rdAnalysis);
#endif

#if 0
      cout << "INFO: substituting uses with rhs of defs."<<endl;
      substituteUsesWithAvailableExpRhsOfDef("ud-analysis", root, rdAnalysis->getLabeler(), rdAnalysis->getVariableIdMapping());
#endif
      if(option_ud_analysis) {
        ROSE_ASSERT(option_rd_analysis);
        cout << "INFO: generating and attaching UD-data to AST."<<endl;
        createUDAstAttributeFromRDAttribute(rdAnalysis->getLabeler(),"rd-analysis-in", "ud-analysis");
        Flow* flow=rdAnalysis->getFlow();
        cout<<"Flow label-set size: "<<flow->nodeLabels().size()<<endl;
        CFAnalysis* cfAnalyzer0=rdAnalysis->getCFAnalyzer();
        int red=cfAnalyzer0->reduceBlockBeginNodes(*flow);
        cout<<"INFO: eliminated "<<red<<" block-begin nodes in ICFG."<<endl;
        
#if 0
        cout << "INFO: computing program statistics."<<endl;
        ProgramStatistics ps(rdAnalysis->getVariableIdMapping(),
                             rdAnalysis->getLabeler(), 
                             rdAnalysis->getFlow(),
                             "ud-analysis");
        ps.computeStatistics();
        //ps.printStatistics();
        cout << "INFO: generating resource usage visualization."<<endl;
        ps.setGenerateWithSource(false);
        ps.generateResourceUsageICFGDotFile("resourceusageicfg.dot");
        flow->resetDotOptions();
#endif
        cout << "INFO: generating visualization data."<<endl;
        // generate ICFG visualization
        cout << "generating icfg.dot."<<endl;
        write_file("icfg.dot", flow->toDot(rdAnalysis->getLabeler()));
        
        //  cout << "INFO: generating control dependence graph."<<endl;
        //Flow cdg=rdAnalysis->getCFAnalyzer()->controlDependenceGraph(*flow);

        cout << "generating datadependencegraph.dot."<<endl;
        DataDependenceVisualizer ddvis0(rdAnalysis->getLabeler(),
                                        rdAnalysis->getVariableIdMapping(),
                                        "ud-analysis");
        //printAttributes<UDAstAttribute>(rdAnalysis->getLabeler(),rdAnalysis->getVariableIdMapping(),"ud-analysis");
        //ddvis._showSourceCode=false; // for large programs
        ddvis0.generateDefUseDotGraph(root,"datadependencegraph.dot");
        flow->resetDotOptions();
        
        cout << "generating icfgdatadependencegraph.dot."<<endl;
        DataDependenceVisualizer ddvis1(rdAnalysis->getLabeler(),
                                        rdAnalysis->getVariableIdMapping(),
                                        "ud-analysis");
        ddvis1.includeFlowGraphEdges(flow);
        ddvis1.generateDefUseDotGraph(root,"icfgdatadependencegraph.dot");
        flow->resetDotOptions();
        
        cout << "generating icfgdatadependencegraph_clustered.dot."<<endl;
        DataDependenceVisualizer ddvis2(rdAnalysis->getLabeler(),
                                        rdAnalysis->getVariableIdMapping(),
                                        "ud-analysis");
        ddvis2.generateDotFunctionClusters(root,rdAnalysis->getCFAnalyzer(),"icfgdatadependencegraph_clustered.dot",true);
        
        cout << "generating icfg_clustered.dot."<<endl;
        DataDependenceVisualizer ddvis3(rdAnalysis->getLabeler(),
                                        rdAnalysis->getVariableIdMapping(),
                                        "ud-analysis");
        ddvis3.generateDotFunctionClusters(root,rdAnalysis->getCFAnalyzer(),"icfg_clustered.dot",false);
        
      }
    }
}
コード例 #17
0
// TODO: this function ignores all reported memory access to unnamed memory cells
void extractVariableIdSetFromVarsInfo(VariableIdSet& varIdSet, VarsInfo& varsInfo) {
    VariableIdInfoMap& vim=varsInfo.first;
    for(VariableIdInfoMap::iterator i=vim.begin();i!=vim.end();++i) {
      varIdSet.insert((*i).first);
    }
}
コード例 #18
0
ファイル: IntervalPropertyState.C プロジェクト: 8l/rose
void SPRAY::IntervalPropertyState::topifyVariableSet(VariableIdSet varIdSet) {
  for(VariableIdSet::iterator i=varIdSet.begin();i!=varIdSet.end();++i) {
    intervals[*i]=SPRAY::NumberIntervalLattice::top();
  }
}