Example #1
0
std::set<unsigned int> FunctionBehavior::get_local_variables(const application_managerConstRef AppM) const
{
   std::set<unsigned int> vars;
   //I simply have to go over all the vertices and get the used variables;
   //the variables which have to be declared are all those variables but
   //the globals ones
   VertexIterator v, vEnd;
   for (boost::tie(v, vEnd) = boost::vertices(*cfg); v != vEnd; v++)
   {
      CustomSet<unsigned int> varsTemp = cfg->CGetOpNodeInfo(*v)->cited_variables;
      vars.insert(varsTemp.begin(), varsTemp.end());
   }
   const std::list<unsigned int>& funParams = helper->get_parameters();
   for (std::list<unsigned int>::const_iterator i = funParams.begin(); i != funParams.end(); i++)
   {
      if (vars.find(*i) != vars.end())
         vars.erase(*i);
   }

   const CustomSet<unsigned int>& gblVariables = AppM->get_global_variables();
   for (CustomSet<unsigned int>::const_iterator i = gblVariables.begin(); i != gblVariables.end(); i++)
   {
      if (vars.find(*i) != vars.end())
         vars.erase(*i);
   }
   return vars;
}
    std::vector<int> TogersonMetricLearner::getDRowIdxs(arma::vec x) {

        CustomSet foundXs;
        vector<int> idxs;

        for(int i = 0; i < expandedX1s.size(); ++i) {

            if(compareArmadilloVec(expandedX1s.at(i), x)) {

                if(foundXs.insert(expandedX2s.at(i)).second)
                    idxs.push_back(i);

            }
        }

        return idxs;
    }
Example #3
0
CustomSet<std::string> language_writer::GetHDLReservedNames() const
{
   CustomSet<std::string> ret;
   ret.insert(RESET_PORT_NAME);
   ret.insert(CLOCK_PORT_NAME);
   ret.insert(DONE_PORT_NAME);
   ret.insert(START_PORT_NAME);
   ret.insert(WENABLE_PORT_NAME);
   ret.insert(RETURN_PORT_NAME);
   return ret;
}
Example #4
0
void FPGA_device::load_devices(const target_deviceRef device)
{
   ///map between the default device string and the corresponding configuration stream
   std::map<std::string, std::string> default_device_data;
   /// Load default device options
   default_device_data["xc4vlx100-10ff1513"] =
      #include "xc4vlx100-10ff1513.data"
         ;
   default_device_data["xc5vlx50-3ff1153"] =
      #include "xc5vlx50-3ff1153.data"
         ;
   default_device_data["xc5vlx110t-1ff1136"] =
      #include "xc5vlx110t-1ff1136.data"
         ;
   default_device_data["xc5vlx330t-2ff1738"] =
      #include "xc5vlx330t-2ff1738.data"
         ;
   default_device_data["xc6vlx240t-1ff1156"] =
      #include "xc6vlx240t-1ff1156.data"
         ;
   default_device_data["xc7z020-1clg484"] =
      #include "xc7z020-1clg484.data"
         ;
   default_device_data["xc7z020-1clg484-VVD"] =
      #include "xc7z020-1clg484-VVD.data"
         ;
   default_device_data["xc7z020-1clg484-YOSYS-VVD"] =
      #include "xc7z020-1clg484-YOSYS-VVD.data"
         ;
   default_device_data["xc7vx485t-2ffg1761-VVD"] =
      #include "xc7vx485t-2ffg1761-VVD.data"
         ;
   default_device_data["xc7vx690t-3ffg1930-VVD"] =
      #include "xc7vx690t-3ffg1930-VVD.data"
         ;
   default_device_data["xc7vx330t-1ffg1157"] =
      #include "xc7vx330t-1ffg1157.data"
         ;
   default_device_data["xc7a100t-1csg324-VVD"] =
      #include "xc7a100t-1csg324-VVD.data"
         ;

#if (0 && HAVE_EXPERIMENTAL)
   default_device_data["xc3s1500l-4fg676"] =
      #include "Spartan-3-xc3s1500l-4fg676.data"
         ;
#endif


   default_device_data["EP2C70F896C6"] =
      #include "EP2C70F896C6.data"
         ;
   default_device_data["EP2C70F896C6-R"] =
      #include "EP2C70F896C6-R.data"
         ;
   default_device_data["5CSEMA5F31C6"] =
      #include "5CSEMA5F31C6.data"
         ;
   default_device_data["EP4SGX530KH40C2"] =
        #include "EP4SGX530KH40C2.data"
         ;
   default_device_data["5SGXEA7N2F45C1"] =
      #include "5SGXEA7N2F45C1.data"
         ;
   default_device_data["LFE335EA8FN484C"] =
      #include "LFE335EA8FN484C.data"
         ;

   unsigned int output_level = Param->getOption<unsigned int>(OPT_output_level);

   try
   {
      PRINT_OUT_MEX(OUTPUT_LEVEL_VERBOSE, output_level, "Available devices:");
      for (std::map<std::string, std::string>::const_iterator d = default_device_data.begin(); d != default_device_data.end(); d++)
      {
         PRINT_OUT_MEX(OUTPUT_LEVEL_VERBOSE, output_level, " - " + d->first);
      }


      const CustomSet<XMLDomParserRef> parsers = [&] () -> CustomSet<XMLDomParserRef>
      {
         CustomSet<XMLDomParserRef> ret;
         if (Param->isOption(OPT_target_device_file))
         {
            const auto file_devices = Param->getOption<const std::list<std::string> >(OPT_target_device_file);
            for(const auto file_device : file_devices)
            {
               PRINT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "Imported user data from file " + file_device);
               ret.insert(XMLDomParserRef(new XMLDomParser(file_device)));
            }
         }
         else
         {
            std::string device_string = Param->getOption<std::string>(OPT_device_string);

            if (default_device_data.find(device_string) != default_device_data.end())
            {
               INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Loading " + device_string);
               ret.insert(XMLDomParserRef(new XMLDomParser(device_string, default_device_data[device_string])));
            }
            else
               THROW_ERROR("Target device not supported: " + device_string);
         }
         return ret;
      }();

      for(const auto parser : parsers)
      {
         parser->Exec();
         if (parser and *parser)
         {
            const xml_element* node = parser->get_document()->get_root_node(); //deleted by DomParser.
            xload(device, node);
         }
      }

      return;
   }
   catch (const char * msg)
   {
      std::cerr << msg << std::endl;
   }
   catch (const std::string & msg)
   {
      std::cerr << msg << std::endl;
   }
   catch (const std::exception& ex)
   {
      std::cout << "Exception caught: " << ex.what() << std::endl;
   }
   catch ( ... )
   {
      std::cerr << "unknown exception" << std::endl;
   }
   THROW_ERROR("Error during XML parsing of device files");

}
void FunctionFrontendFlowStep::WriteBBGraphDot(const std::string filename) const
{
   auto bb_graph_info = BBGraphInfoRef(new BBGraphInfo(AppM, function_id));
   BBGraphsCollectionRef GCC_bb_graphs_collection(new BBGraphsCollection(bb_graph_info, parameters));
   BBGraphRef GCC_bb_graph(new BBGraph(GCC_bb_graphs_collection, CFG_SELECTOR));
   std::unordered_map<vertex, unsigned int> direct_vertex_map;
   std::unordered_map<unsigned int, vertex> inverse_vertex_map;
   const tree_nodeConstRef function_tree_node = AppM->get_tree_manager()->CGetTreeNode(function_id);
   const auto fd = GetPointer<const function_decl>(function_tree_node);
   const auto sl = GetPointer<const statement_list>(GET_CONST_NODE(fd->body));
   /// add vertices
   for(auto block : sl->list_of_bloc)
   {
      inverse_vertex_map[block.first] = GCC_bb_graphs_collection->AddVertex(BBNodeInfoRef(new BBNodeInfo(block.second)));
      direct_vertex_map[inverse_vertex_map[block.first]]=block.first;
   }
   ///Set entry and exit
   if(inverse_vertex_map.find(bloc::ENTRY_BLOCK_ID) == inverse_vertex_map.end())
   {
      inverse_vertex_map[bloc::ENTRY_BLOCK_ID] = GCC_bb_graphs_collection->AddVertex(BBNodeInfoRef(new BBNodeInfo()));
      direct_vertex_map[inverse_vertex_map[bloc::ENTRY_BLOCK_ID]]=bloc::ENTRY_BLOCK_ID;
   }
   bb_graph_info->entry_vertex = inverse_vertex_map[bloc::ENTRY_BLOCK_ID];
   if(inverse_vertex_map.find(bloc::EXIT_BLOCK_ID) == inverse_vertex_map.end())
   {
      inverse_vertex_map[bloc::EXIT_BLOCK_ID] = GCC_bb_graphs_collection->AddVertex(BBNodeInfoRef(new BBNodeInfo()));
      direct_vertex_map[inverse_vertex_map[bloc::EXIT_BLOCK_ID]]=bloc::EXIT_BLOCK_ID;
   }
   bb_graph_info->exit_vertex = inverse_vertex_map[bloc::EXIT_BLOCK_ID];

   /// add edges
   for(const auto block : sl->list_of_bloc)
   {
      for(const auto pred : block.second->list_of_pred)
      {
         if(pred == bloc::ENTRY_BLOCK_ID)
         {
            GCC_bb_graphs_collection->AddEdge(inverse_vertex_map[pred], inverse_vertex_map[block.first], CFG_SELECTOR);
         }
      }
      for(const auto succ : block.second->list_of_succ)
      {
         THROW_ASSERT(inverse_vertex_map.find(block.first) != inverse_vertex_map.end(), "BB" + STR(block.first) + " does not exist");
         THROW_ASSERT(inverse_vertex_map.find(succ) != inverse_vertex_map.end(), "BB" + STR(succ) + " does not exist");
         if(block.second->CGetStmtList().size() and GET_NODE(block.second->CGetStmtList().back())->get_kind() == gimple_multi_way_if_K)
         {
            const auto gmwi = GetPointer<const gimple_multi_way_if>(GET_NODE(block.second->CGetStmtList().back()));
            CustomSet<unsigned int> conds;
            for(auto gmwi_cond : gmwi->list_of_cond)
            {
               if(gmwi_cond.second == succ)
               {
                  if(gmwi_cond.first)
                  {
                     conds.insert(gmwi_cond.first->index);
                  }
                  else
                  {
                     conds.insert(default_COND);
                  }
               }
            }
            THROW_ASSERT(conds.size(), "Inconsistency between cfg and output of gimple_multi_way_if " + gmwi->ToString() + "- condition for BB" + STR(succ) + " not found");
            const EdgeInfoRef edge_info(new BBEdgeInfo());
            for(auto cond : conds)
            {
               GetPointer<BBEdgeInfo>(edge_info)->add_nodeID(cond, CFG_SELECTOR);
            }
            GCC_bb_graphs_collection->InternalAddEdge(inverse_vertex_map[block.first], inverse_vertex_map[succ], CFG_SELECTOR, edge_info);
         }
         else
         {
            GCC_bb_graphs_collection->AddEdge(inverse_vertex_map[block.first], inverse_vertex_map[succ], CFG_SELECTOR);
         }
      }
      if(block.second->list_of_succ.empty())
      {
         GCC_bb_graphs_collection->AddEdge(inverse_vertex_map[block.first], inverse_vertex_map[bloc::EXIT_BLOCK_ID], CFG_SELECTOR);
      }
   }

   /// add a connection between entry and exit thus avoiding problems with non terminating code
   GCC_bb_graphs_collection->AddEdge(inverse_vertex_map[bloc::ENTRY_BLOCK_ID], inverse_vertex_map[bloc::EXIT_BLOCK_ID], CFG_SELECTOR);
   BBGraph(GCC_bb_graphs_collection, CFG_SELECTOR).WriteDot(filename);
   INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Written " + filename);
   /// add edges
   for(const auto block : sl->list_of_bloc)
   {
#ifndef NDEBUG
      for(const auto phi : block.second->CGetPhiList())
      {
         const auto gp = GetPointer<const gimple_phi>(GET_CONST_NODE(phi));
         THROW_ASSERT(gp->CGetDefEdgesList().size() == block.second->list_of_pred.size(), "BB" + STR(block.second->number) + " has " + STR(block.second->list_of_pred.size()) + " incoming edges but contains " + STR(phi));
      }
#endif
   }
}