DesignFlowStep_Status dom_post_dom_computation::InternalExec()
{
   const auto bb_cfg_computation_signature = FunctionFrontendFlowStep::ComputeSignature(FrontendFlowStepType::BASIC_BLOCKS_CFG_COMPUTATION, function_id);
   const auto bb_cfg_computation_vertex = design_flow_manager.lock()->GetDesignFlowStep(bb_cfg_computation_signature);
   const auto design_flow_graph = design_flow_manager.lock()->CGetDesignFlowGraph();
   const auto bb_cfg_computation_step = design_flow_graph->CGetDesignFlowStepInfo(bb_cfg_computation_vertex)->design_flow_step;
   THROW_ASSERT(bb_cfg_computation_step, bb_cfg_computation_signature);
   bb_cfg_computation_bb_version = GetPointer<const FunctionFrontendFlowStep>(bb_cfg_computation_step)->CGetBBVersion();

   const BBGraphConstRef fbb = function_behavior->CGetBBGraph(FunctionBehavior::FBB);

   const BehavioralHelperConstRef  helper = function_behavior->CGetBehavioralHelper();
   ///dominators computation
   THROW_ASSERT(!function_behavior->dominators, "Dominators already built");
   const vertex bbentry = fbb->CGetBBGraphInfo()->entry_vertex;
   const vertex bbexit = fbb->CGetBBGraphInfo()->exit_vertex;
   function_behavior->dominators = new dominance<BBGraph>(*fbb, bbentry, bbexit, parameters);
   function_behavior->dominators->calculate_dominance_info(dominance<BBGraph>::CDI_DOMINATORS);
   std::unordered_map<vertex, vertex> dominator_map = function_behavior->dominators->get_dominator_map();
   for(std::unordered_map<vertex, vertex>::iterator it = dominator_map.begin(); it != dominator_map.end(); it++)
   {
      if(it->first != bbentry)
      {
         function_behavior->bbgc->AddEdge(it->second, it->first, D_SELECTOR);
      }
   }
   PRINT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Built dominators tree of " + helper->get_function_name());
   if(parameters->getOption<bool>(OPT_print_dot))
   {
      function_behavior->GetBBGraph(FunctionBehavior::DOM_TREE)->WriteDot("BB_dom_tree.dot");
   }
   ///post-dominators computation
   THROW_ASSERT(!function_behavior->post_dominators, "Post dominators yet built");
   function_behavior->post_dominators = new dominance<BBGraph>(*fbb, bbentry, bbexit, parameters);
   function_behavior->post_dominators->calculate_dominance_info(dominance<BBGraph>::CDI_POST_DOMINATORS);
   std::unordered_map<vertex, vertex> post_dominator_map = function_behavior->post_dominators->get_dominator_map();
   for(std::unordered_map<vertex, vertex>::iterator it = post_dominator_map.begin(); it != post_dominator_map.end(); it++)
   {
      if(it->first != bbexit)
      {
         function_behavior->bbgc->AddEdge(it->second, it->first, PD_SELECTOR);
      }
   }
   PRINT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Built post-dominators tree of " + helper->get_function_name());

   if(parameters->getOption<bool>(OPT_print_dot))
   {
      function_behavior->GetBBGraph(FunctionBehavior::POST_DOM_TREE)->WriteDot("BB_post_dom_tree.dot");
   }
   return DesignFlowStep_Status::SUCCESS;
}
Esempio n. 2
0
std::deque<bit_lattice> BitLatticeManipulator::sign_extend_bitstring(
      const std::deque<bit_lattice> & bitstring,
      bool bitstring_is_signed,
      size_t final_size) const
{
   THROW_ASSERT(final_size, "cannot sign extend a bitstring to final_size 0");
   THROW_ASSERT(final_size > bitstring.size(), "useless sign extension");
   std::deque<bit_lattice> res = bitstring;
   if (res.empty())
      res.push_front(bit_lattice::X);
   const auto sign_bit = (bitstring_is_signed or res.front() == bit_lattice::X) ? res.front() : bit_lattice::ZERO;
   while (res.size() < final_size)
      res.push_front(sign_bit);
   return res;
}
Esempio n. 3
0
void memory::set_internal_base_address_alignment(unsigned int _internal_base_address_alignment)
{
   THROW_ASSERT(_internal_base_address_alignment && !(_internal_base_address_alignment & (_internal_base_address_alignment-1)), "alignment must be a power of two");
   internal_base_address_alignment = _internal_base_address_alignment;
   align(internal_base_address_start, internal_base_address_alignment);
   next_base_address = internal_base_address_start;
}
Esempio n. 4
0
void AlteraBackendFlow::CheckSynthesisResults()
{
   PRINT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "Analyzing Altera synthesis results");
   std::string report_filename = actual_parameters->parameter_values[PARAM_quartus_report];
   xparse_utilization(report_filename);

   THROW_ASSERT(design_values.find(ALTERA_LE) != design_values.end(), "Missing logic elements");
   area_m = area_model::create_model(TargetDevice_Type::FPGA, Param);
   if(design_values[ALTERA_LE] != 0.0)
      area_m->set_area_value(design_values[ALTERA_LE]);
   else
      area_m->set_area_value(design_values[ALTERA_ALM]);
   clb_model* area_clb_model = GetPointer<clb_model>(area_m);
   if(design_values[ALTERA_LE] != 0.0)
      area_clb_model->set_resource_value(clb_model::LOGIC_ELEMENTS, design_values[ALTERA_LE]);
   else
      area_clb_model->set_resource_value(clb_model::ALMS, design_values[ALTERA_ALM]);

   area_clb_model->set_resource_value(clb_model::REGISTERS, design_values[ALTERA_REGISTERS]);
   area_clb_model->set_resource_value(clb_model::DSP, design_values[ALTERA_DSP]);
   area_clb_model->set_resource_value(clb_model::BRAM, design_values[ALTERA_MEM]);

   time_m = time_model::create_model(TargetDevice_Type::FPGA, Param);
   LUT_model* lut_m = GetPointer<LUT_model>(time_m);
   if(design_values[ALTERA_FMAX] != 0.0)
      lut_m->set_timing_value(LUT_model::COMBINATIONAL_DELAY, 1000/design_values[ALTERA_FMAX]);
   else if(design_values.find("SLACK") != design_values.end())
      lut_m->set_timing_value(LUT_model::COMBINATIONAL_DELAY, design_values.find("SLACK")->second);
   else
      lut_m->set_timing_value(LUT_model::COMBINATIONAL_DELAY, 0);
}
Esempio n. 5
0
language_writerRef language_writer::create_writer(const HDLWriter_Language language, const technology_managerConstRef _TM, const ParameterConstRef _parameters)
{
   THROW_ASSERT(_parameters, "");
   switch (language)
   {
      case HDLWriter_Language::VERILOG:
         return language_writerRef(new verilog_writer(_parameters));
         break;
      case HDLWriter_Language::SYSTEM_VERILOG:
         return language_writerRef(new system_verilog_writer(_parameters));
         break;
      case HDLWriter_Language::VHDL:
         return language_writerRef(new VHDL_writer(_TM, _parameters));
         break;
#if HAVE_EXPERIMENTAL
      case HDLWriter_Language::SYSTEMC:
         return language_writerRef(new SystemC_writer(_parameters));
         break;
      case HDLWriter_Language::BLIF:
         return language_writerRef(new blif_writer(_parameters));
         break;
      case HDLWriter_Language::EDIF:
         return language_writerRef(new edif_writer(_parameters));
         break;
#endif
      default:
         THROW_ERROR("HDL backend language not supported");
   }
   return language_writerRef();
}
Esempio n. 6
0
void memory::add_internal_symbol(unsigned int funID_scope, unsigned int var, const memory_symbolRef m_sym)
{
   if (external.find(var) != external.end())
      THROW_WARNING("The variable " + STR(var) + " has been already allocated out of the module");
   if (parameter.find(var) != parameter.end())
      THROW_WARNING("The variable " + STR(var) + " has been already set as a parameter");
   THROW_ASSERT(in_vars.find(var) == in_vars.end() || is_private_memory(var), "variable already allocated inside this module");

   internal[funID_scope][var] = m_sym;
   if (GetPointer<gimple_call>(TreeM->get_tree_node_const(var)))
      callSites[var] = m_sym;
   else
      in_vars[var] = m_sym;

   if(is_private_memory(var))
   {
      unsigned int allocated_memory =compute_n_bytes(tree_helper::size(TreeM, var));
      rangesize[var] = allocated_memory;
      align(rangesize[var], internal_base_address_alignment);
      total_amount_of_private_memory += allocated_memory;
      maximum_private_memory_size = std::max(maximum_private_memory_size, allocated_memory);
   }
   else
   {
      unsigned int address = m_sym->get_address();
      unsigned int address_orig = address;
      compute_next_base_address(address, var, internal_base_address_alignment);
      next_base_address = std::max(next_base_address, address);
      rangesize[var] = next_base_address-address_orig;
   }
}
Esempio n. 7
0
bool PragmaParser::recognize_call_point_hw_pragma(std::string & line) const
{
   const std::string old_line = line;
   line = std::string(STR_CST_pragma_function_single_line_two_arguments) + "(";
   line += "\"" + std::string(STR_CST_pragma_keyword_map) + "\"";
   line += ", ";
   std::vector<std::string> splitted;
   boost::algorithm::split(splitted, old_line, boost::algorithm::is_any_of(" "));
   THROW_ASSERT(splitted.size() == 4 or splitted.size() == 5, "Error in syntax of mapping pragma: " + old_line);
   THROW_ASSERT(splitted[2] == std::string(STR_CST_pragma_keyword_call_point_hw), "Expecting " + std::string(STR_CST_pragma_keyword_call_point_hw) + " - Found : " + splitted[2]);
   line += "\"" + std::string(STR_CST_pragma_keyword_call_point_hw) + "\"";
   line += ", \"" + splitted[3] + "\"";
   if(splitted.size() == 5)
      line += ", \"" + splitted[4] + "\"";
   line += ");";
   return true;
}
Esempio n. 8
0
// constructor
PragmaParser::PragmaParser(const pragma_managerRef _PM, const ParameterConstRef _Param) :
   PM(_PM),
   debug_level(_Param->get_class_debug_level(GET_CLASS(*this))),
   Param(_Param),
   search_function(false)
{
   THROW_ASSERT(PM, "Pragma manager not initialized");
}
Esempio n. 9
0
unsigned int memory::get_base_address(unsigned int var, unsigned int funId) const
{
   THROW_ASSERT(has_base_address(var), "Variable not yet allocated: @" + STR(var));
   if (has_callSite_base_address(var)) return get_callSite_base_address(var);
   if (has_internal_base_address(var)) return get_internal_base_address(var);
   if (funId && has_parameter_base_address(var, funId)) return get_parameter_base_address(var, funId);
   return get_external_base_address(var);
}
Esempio n. 10
0
NP_functionality::NP_functionaly_type NP_functionality::to_NP_functionaly_type(std::string val)
{
  unsigned int i;
  for(i = 0; i < UNKNOWN; i++)
    if(val == NP_functionaly_typeNames[i])
      break;
  THROW_ASSERT(i < UNKNOWN, "Wrong NP_functionaly_typeNames specified: |" + val + "|");
  return NP_functionaly_type(i);
}
Esempio n. 11
0
std::deque<bit_lattice> BitLatticeManipulator::constructor_bitstring(
      const tree_nodeRef ctor_tn,
      unsigned int ssa_node_id) const
{
   const bool ssa_is_signed = tree_helper::is_int(TM, ssa_node_id);
   THROW_ASSERT(ctor_tn->get_kind() == constructor_K, "ctor_tn is not constructor node");
   constructor * c = GetPointer<constructor>(ctor_tn);
   std::vector<unsigned int> array_dims;
   unsigned int elements_bitsize;
   tree_helper::get_array_dim_and_bitsize(TM, GET_INDEX_CONST_NODE(c->type), array_dims, elements_bitsize);
   unsigned int initialized_elements = 0;
   std::deque<bit_lattice> current_inf;
   current_inf.push_back(bit_lattice::X);
   std::deque<bit_lattice> cur_bitstring;
   for (const auto & i : c->list_of_idx_valu)
   {
      tree_nodeRef el = GET_NODE(i.second);
      THROW_ASSERT(el, "unexpected condition");

      if(el->get_kind() == integer_cst_K)
      {
         cur_bitstring = create_bitstring_from_constant(GetPointer<integer_cst>(el)->value, elements_bitsize, ssa_is_signed);
      }
      else if(el->get_kind() == constructor_K && GetPointer<array_type>(GET_CONST_NODE(GetPointer<constructor>(el)->type)))
      {
         THROW_ASSERT(array_dims.size() > 1, "invalid nested constructors:" + ctor_tn->ToString() + " " +STR(array_dims.size()));
         cur_bitstring = constructor_bitstring(el, ssa_node_id);
      }
      else
      {
         cur_bitstring = create_u_bitstring(elements_bitsize);
      }

      current_inf = inf(current_inf, cur_bitstring, ssa_node_id);
      initialized_elements++;
   }
   if (initialized_elements < array_dims.front())
   {
      current_inf = inf(current_inf, create_bitstring_from_constant(0, elements_bitsize, ssa_is_signed), ssa_node_id);
   }
   return current_inf;
}
DesignFlowStep_Status GenerateSynthesisScripts::Exec()
{
   const auto top_function_ids = HLSMgr->CGetCallGraphManager()->GetRootFunctions();
   THROW_ASSERT(top_function_ids.size() == 1, "Multiple top functions");
   const auto top_fun_id = *(top_function_ids.begin());

   const hlsRef top_hls = HLSMgr->get_HLS(top_fun_id);
   const FunctionBehaviorConstRef FB = HLSMgr->CGetFunctionBehavior(top_fun_id);
   HLSMgr->get_backend_flow()->GenerateSynthesisScripts(FB->CGetBehavioralHelper()->get_function_name(), top_hls->top, HLSMgr->hdl_files, HLSMgr->aux_files);
   return DesignFlowStep_Status::SUCCESS;
}
Esempio n. 13
0
memory_symbolRef memory::get_symbol(unsigned int var, unsigned int funId) const
{
   THROW_ASSERT(has_base_address(var), "Variable not yet allocated: @" + STR(var));
   if (has_callSite_base_address(var)) return callSites.find(var)->second;
   if (has_internal_base_address(var)) return in_vars.find(var)->second;
   if (funId && has_parameter_base_address(var, funId)){
     std::map<unsigned int, std::map<unsigned int, memory_symbolRef> >::const_iterator itr =
         parameter.find(funId);
     return itr->second.find(var)->second;
   }
   return external.find(var)->second;
}
Esempio n. 14
0
bool FunctionBehavior::CheckReachability(const vertex first_operation, const vertex second_operation) const
{
   const std::unordered_map<unsigned int, vertex> & bb_index_map = bb->CGetBBGraphInfo()->bb_index_map;
   const unsigned int first_bb_index = cfg->CGetOpNodeInfo(first_operation)->bb_index;
   const unsigned int second_bb_index = cfg->CGetOpNodeInfo(second_operation)->bb_index;
   const vertex first_bb_vertex = bb_index_map.find(first_bb_index)->second;
   const vertex second_bb_vertex = bb_index_map.find(second_bb_index)->second;
   if(CheckBBReachability(first_bb_vertex, second_bb_vertex))
   {
      return true;
   }
   if(first_bb_vertex == second_bb_vertex)
   {
      THROW_ASSERT(map_levels.size(), "");
      THROW_ASSERT(map_levels.find(first_operation) != map_levels.end(), "Level of " + GET_NAME(cfg, first_operation) + " not found");
      THROW_ASSERT(map_levels.find(second_operation) != map_levels.end(), "Level of " + GET_NAME(cfg, second_operation) + " not found");
      if(map_levels.find(first_operation)->second < map_levels.find(second_operation)->second)
      {
         return true;
      }
   }
   return false;
}
Esempio n. 15
0
void FPGA_device::xwrite(xml_element* nodeRoot)
{
   xml_element* tmRoot = nodeRoot->add_child_element("device");

   THROW_ASSERT(has_parameter("vendor"), "vendor value is missing");
   xml_element* vendor_el = tmRoot->add_child_element("vendor");
   std::string vendor = get_parameter<std::string>("vendor");
   WRITE_XNVM2("value", vendor, vendor_el);

   THROW_ASSERT(has_parameter("family"), "family value is missing");
   xml_element* family_el = tmRoot->add_child_element("family");
   std::string family = get_parameter<std::string>("family");
   WRITE_XNVM2("value", family, family_el);

   THROW_ASSERT(has_parameter("model"), "model value is missing");
   xml_element* model_el = tmRoot->add_child_element("model");
   std::string model = get_parameter<std::string>("model");
   WRITE_XNVM2("value", model, model_el);

   THROW_ASSERT(has_parameter("package"), "package value is missing");
   xml_element* package_el = tmRoot->add_child_element("package");
   std::string package = get_parameter<std::string>("package");
   WRITE_XNVM2("value", package, package_el);

   THROW_ASSERT(has_parameter("speed_grade"), "speed_grade value is missing");
   xml_element* speed_grade_el = tmRoot->add_child_element("speed_grade");
   std::string speed_grade = get_parameter<std::string>("speed_grade");
   WRITE_XNVM2("value", speed_grade, speed_grade_el);

   for(std::map<std::string, std::string>::iterator p = parameters.begin(); p != parameters.end(); p++)
   {
      if(p->first == "vendor" || p->first == "family"  || p->first == "model"  || p->first == "package" || p->first == "speed_grade" || p->first == "clock_period") continue;
      xml_element* elRoot = tmRoot->add_child_element(p->first);
      WRITE_XNVM2("value", p->second, elRoot);
   }

}
Esempio n. 16
0
std::deque<bit_lattice> BitLatticeManipulator::string_cst_bitstring(
      const tree_nodeRef strcst_tn,
      unsigned int ssa_node_id) const
{
   THROW_ASSERT(strcst_tn->get_kind() == string_cst_K, "strcst_tn is not a string_cst node");
   string_cst * sc = GetPointer<string_cst>(strcst_tn);
   const std::string str = sc->strg;
   const bool node_is_signed = tree_helper::is_int(TM, ssa_node_id);
   auto current_inf = create_bitstring_from_constant(0, 8, node_is_signed);
   for (const auto c : str)
   {
      auto current_el = create_bitstring_from_constant(static_cast<long long int>(c), 8, node_is_signed);
      current_inf = inf(current_inf, current_el, ssa_node_id);
   }
   return current_inf;
}
Esempio n. 17
0
std::string DesignCompilerWrapper::write_timing_paths(const std::string& design_name, const std::vector<std::string>& timing_path)
{
   try
   {
      THROW_ASSERT(design_name.size(), "Module name not specified");
      std::string timing_path_xml_file = "timing_path.xml";
      xml_document document;
      xml_element* nodeRoot = document.create_root_node("synthesis");

      xml_element* designRoot = nodeRoot->add_child_element("design");
      WRITE_XNVM(design_name, design_name, designRoot);

      xml_element* timingRoot = designRoot->add_child_element("timing_path");
      std::string number_of_elements = boost::lexical_cast<std::string>(timing_path.size());
      WRITE_XNVM(number_of_elements, number_of_elements, timingRoot);
      std::string type = "POST_SYNTHESIS";
      WRITE_XNVM(type, type, timingRoot);
      for (unsigned int l = 0; l < timing_path.size(); l++)
      {
         xml_element* Enode = timingRoot->add_child_element("path_element");
         std::string path = timing_path[l];
         WRITE_XNVM(path, path, Enode);
         std::string element = boost::lexical_cast<std::string>(l);
         WRITE_XNVM(element, element, Enode);
      }

      document.write_to_file_formatted(timing_path_xml_file);
      return timing_path_xml_file;
   }
   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;
   }
   return "";
}
bool dom_post_dom_computation::HasToBeExecuted() const
{
   const auto bb_cfg_computation_signature = FunctionFrontendFlowStep::ComputeSignature(FrontendFlowStepType::BASIC_BLOCKS_CFG_COMPUTATION, function_id);
   const auto bb_cfg_computation_vertex = design_flow_manager.lock()->GetDesignFlowStep(bb_cfg_computation_signature);
   const auto design_flow_graph = design_flow_manager.lock()->CGetDesignFlowGraph();
   const auto bb_cfg_computation_step = design_flow_graph->CGetDesignFlowStepInfo(bb_cfg_computation_vertex)->design_flow_step;
   THROW_ASSERT(bb_cfg_computation_step, bb_cfg_computation_signature);
   if(GetPointer<const FunctionFrontendFlowStep>(bb_cfg_computation_step)->CGetBBVersion() != bb_cfg_computation_bb_version)
   {
      return true;
   }
   else
   {
      return FunctionFrontendFlowStep::HasToBeExecuted();
   }

}
Esempio n. 19
0
void NP_functionality::get_port_list(std::map<unsigned int, std::map<std::string, std::string> >&InPortMap, std::map<unsigned int, std::map<std::string, std::string> >&OutPortMap) const
{
  std::string port_list = get_NP_functionality(NP_functionality::PORT_LIST);
  if(port_list == "") return ;
  std::vector<std::string> splitted;
  boost::algorithm::split(splitted, port_list , boost::algorithm::is_any_of(";"));
  for (unsigned int i = 0; i < splitted.size(); i++)
  {
    std::string port_description = splitted[i];
    if (port_description == "") continue;
    std::vector<std::string> ports;
    boost::algorithm::split(ports, port_description, boost::algorithm::is_any_of(":"));
    THROW_ASSERT(ports.size() == 4, "Wrong format for NP_functionality::PORT_LIST functionality");
    if (ports[0] == "I")
       InPortMap[boost::lexical_cast<unsigned int>(ports[1])][ports[2]] = ports[3];
    if (ports[0] == "O")
       OutPortMap[boost::lexical_cast<unsigned int>(ports[1])][ports[2]] = ports[3];
  }
}
Esempio n. 20
0
void memory::add_memory_parameter(const structural_managerRef SM, const std::string& name, const std::string& value)
{
   std::string memory_parameters;
   if (SM->get_circ()->is_parameter(MEMORY_PARAMETER))
   {
      memory_parameters = SM->get_circ()->get_parameter(MEMORY_PARAMETER) + ";";
   }
   std::vector<std::string> current_parameters = convert_string_to_vector<std::string>(memory_parameters, ";");
   for(unsigned int l = 0; l < current_parameters.size(); l++)
   {
      std::vector<std::string> current_parameter = convert_string_to_vector<std::string>(current_parameters[l], "=");
      THROW_ASSERT(current_parameter.size() == 2, "expected two elements");
      if (current_parameter[0] == name)
      {
         if (value == current_parameter[1])
            return;
         THROW_ERROR("The parameter \"" + name + "\" has been set with (at least) two different values: " + value + " != " + current_parameter[1]);
      }
   }
   memory_parameters += name + "=" + value;
   SM->get_circ()->set_parameter(MEMORY_PARAMETER, memory_parameters);
}
Esempio n. 21
0
void IC_device::set_dimension(double area)
{
   THROW_ASSERT(GetPointer<CMOS_technology>(target), "The target device is not compatible with the target technology");
   const CMOS_technology* tech = GetPointer<CMOS_technology>(target);
   if (core_height == 0 or core_width == 0)
   {
      std::cerr << "module area: " << area << std::endl;

      area /= get_parameter<double>("utilization_factor");
      if (core_height == 0 and core_width == 0)
      {
         double float_height = sqrt(area*get_parameter<double>("aspect_ratio") / pow(tech->get_parameter<double>("cell_height"), 2.0));
         std::cerr << "float height = " << float_height << std::endl;

         unsigned int rows = 1;
         if ((float_height - floor(float_height)) < 0.5 and floor(float_height) > 0)
            rows = static_cast<unsigned int>(floor(float_height));
         else
            rows = static_cast<unsigned int>(ceil(float_height));

         std::cerr << "number of rows = " << rows << std::endl;
         core_height = (static_cast<double>(rows) * tech->get_parameter<double>("cell_height"));
         core_width = area / core_height;
      }
      else if (core_width == 0)
      {
         core_width = area / core_height;
      }
      else if (core_height == 0)
      {
         core_height = area / core_width;
      }

   }

   std::cerr << "die area = " << core_height*core_width << " [" << core_width << "," << core_height << "]" << std::endl;
}
Esempio n. 22
0
DesignFlowStep_Status values_scheme::InternalExec()
{
   long step_time;
   START_TIME(step_time);
   THROW_ASSERT(HLS->Rliv, "Liveness analysis not yet computed");
   unsigned int i = 0;
   const std::list<vertex> & support = HLS->Rliv->get_support();

   const std::list<vertex>::const_iterator vEnd = support.end();
   for(std::list<vertex>::const_iterator vIt = support.begin(); vIt != vEnd; vIt++)
   {
      //std::cerr << "current state for sv " << HLS->Rliv->get_name(*vIt) << std::endl;
      const std::set<unsigned int>& live = HLS->Rliv->get_live_in(*vIt);
      const std::set<unsigned int>::const_iterator k_end = live.end();
      for(std::set<unsigned int>::const_iterator k = live.begin(); k != k_end; k++)
      {
         if(HLS->storage_value_information->storage_index_map.find(*k) == HLS->storage_value_information->storage_index_map.end())
         {
            HLS->storage_value_information->storage_index_map[*k] = i;
            HLS->storage_value_information->variable_index_vect.push_back(*k);
            i++;
         }
      }
   }
   HLS->storage_value_information->number_of_storage_values = i;
   if(output_level <= OUTPUT_LEVEL_PEDANTIC)
      INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "");
   INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "-->Storage Value Information of function " + HLSMgr->CGetFunctionBehavior(funId)->CGetBehavioralHelper()->get_function_name() + ":");
   INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Number of storage values inserted: "+boost::lexical_cast<std::string>(i));
   STOP_TIME(step_time);
   if(output_level >= OUTPUT_LEVEL_MINIMUM and output_level <= OUTPUT_LEVEL_PEDANTIC)
      INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "Time to compute storage value information: " + print_cpu_time(step_time) + " seconds");
   INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "<--");
   if(output_level <= OUTPUT_LEVEL_PEDANTIC)
      INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "");
   return DesignFlowStep_Status::SUCCESS;
}
Esempio n. 23
0
void BitLatticeManipulator::sign_reduce_bitstring(
      std::deque<bit_lattice> & bitstring,
      bool bitstring_is_signed) const
{
   THROW_ASSERT(not bitstring.empty(), "");
   while (bitstring.size() > 1)
   {
      if (bitstring_is_signed)
      {
         if (bitstring.at(0) != bit_lattice::U and bitstring.at(0) == bitstring.at(1))
            bitstring.pop_front();
         else
            break;
      }
      else
      {
         if ((bitstring.at(0) == bit_lattice::X and bitstring.at(1) == bit_lattice::X) or
               (bitstring.at(0) == bit_lattice::ZERO and bitstring.at(1) != bit_lattice::X))
            bitstring.pop_front();
         else
            break;
      }
   }
}
Esempio n. 24
0
const std::unordered_set<std::tuple<HLSFlowStep_Type, HLSFlowStepSpecializationConstRef, HLSFlowStep_Relationship> > TestbenchGeneration::ComputeHLSRelationships(const DesignFlowStep::RelationshipType relationship_type) const
{
   std::unordered_set<std::tuple<HLSFlowStep_Type, HLSFlowStepSpecializationConstRef, HLSFlowStep_Relationship> > ret;
   switch(relationship_type)
   {
      case DEPENDENCE_RELATIONSHIP:
         {
            const HLSFlowStep_Type interface_type = parameters->getOption<HLSFlowStep_Type>(OPT_interface_type);
#ifndef NDEBUG
            bool interface = interface_type == HLSFlowStep_Type::MINIMAL_INTERFACE_GENERATION or
#if HAVE_TASTE
               interface_type == HLSFlowStep_Type::TASTE_INTERFACE_GENERATION or
#endif
               interface_type == HLSFlowStep_Type::WB4_INTERFACE_GENERATION;
            THROW_ASSERT(interface, "Unexpected interface type");
#endif
            ret.insert(std::make_tuple(interface_type == HLSFlowStep_Type::MINIMAL_INTERFACE_GENERATION ?
                     HLSFlowStep_Type::MINIMAL_TESTBENCH_GENERATION :
                     HLSFlowStep_Type::WB4_TESTBENCH_GENERATION,
                  HLSFlowStepSpecializationConstRef(),
                  HLSFlowStep_Relationship::TOP_FUNCTION));
            break;
         }
      case INVALIDATION_RELATIONSHIP:
         {
            break;
         }
      case PRECEDENCE_RELATIONSHIP:
         {
            break;
         }
      default:
         THROW_UNREACHABLE("");
   }
   return ret;
}
Esempio n. 25
0
bool op_vertex_order_by_map::operator()(const vertex x, const vertex y) const
{
   THROW_ASSERT(ref.find(x) != ref.end(), "Vertex " + GET_NAME(g,x) + " is not in topological_sort");
   THROW_ASSERT(ref.find(y) != ref.end(), "Second " + GET_NAME(g,y) + " vertex is not in topological_sort");
   return ref.find(x)->second < ref.find(y)->second;
}
Esempio n. 26
0
void SlGeneratorInstance::RegisterNode(Node* node)
{
	// if registration of node already began
	if(registeredNodes.find(node) != registeredNodes.end())
	{
		// if node is not registered yet
		if(nodeInitIndices.find(node) == nodeInitIndices.end())
			// than it's a loop
			THROW("Node cyclic dependency");
		// else it's ok, it's just another use of node
		return;
	}
	// register node
	registeredNodes.insert(node);

	switch(node->GetType())
	{
	case Node::typeFloatConst:
	case Node::typeIntConst:
		break;
	case Node::typeAttribute:
		{
			if(shaderType != ShaderTypes::vertex)
				THROW("Only vertex shader can have attribute nodes");

			attributes.push_back(fast_cast<AttributeNode*>(node));
		}
		break;
	case Node::typeUniform:
		{
			UniformNode* uniformNode = fast_cast<UniformNode*>(node);
			uniforms.push_back(std::make_pair(uniformNode->GetGroup(), uniformNode));
		}
		break;
	case Node::typeSampler:
		samplers.push_back(fast_cast<SamplerNode*>(node));
		break;
	case Node::typeReadUniform:
		RegisterNode(fast_cast<ReadUniformNode*>(node)->GetUniformNode());
		break;
	case Node::typeIndexUniformArray:
		{
			IndexUniformArrayNode* indexUniformArrayNode = fast_cast<IndexUniformArrayNode*>(node);
			RegisterNode(indexUniformArrayNode->GetUniformNode());
			RegisterNode(indexUniformArrayNode->GetIndexNode());
		}
		break;
	case Node::typeTransformed:
		transformedNodes.push_back(fast_cast<TransformedNode*>(node));
		break;
	case Node::typeInterpolate:
		{
			InterpolateNode* interpolateNode = fast_cast<InterpolateNode*>(node);
			interpolateNodes.push_back(interpolateNode);
			RegisterNode(interpolateNode->GetNode());
		}
		break;
	case Node::typeSequence:
		{
			SequenceNode* sequenceNode = fast_cast<SequenceNode*>(node);
			RegisterNode(sequenceNode->GetA());
			RegisterNode(sequenceNode->GetB());
		}
		break;
	case Node::typeSwizzle:
		RegisterNode(fast_cast<SwizzleNode*>(node)->GetA());
		break;
	case Node::typeOperation:
		{
			OperationNode* operationNode = fast_cast<OperationNode*>(node);
			int argumentsCount = operationNode->GetArgumentsCount();
			for(int i = 0; i < argumentsCount; ++i)
				RegisterNode(operationNode->GetArgument(i));
		}
		break;
	case Node::typeAction:
		{
			ActionNode* actionNode = fast_cast<ActionNode*>(node);
			int argumentsCount = actionNode->GetArgumentsCount();
			for(int i = 0; i < argumentsCount; ++i)
				RegisterNode(actionNode->GetArgument(i));
		}
		break;
	case Node::typeSample:
		{
			SampleNode* sampleNode = fast_cast<SampleNode*>(node);

			RegisterNode(sampleNode->GetSamplerNode());
			RegisterNode(sampleNode->GetCoordsNode());

			ValueNode* lodNode = sampleNode->GetLodNode();
			if(lodNode)
				RegisterNode(lodNode);

			ValueNode* biasNode = sampleNode->GetBiasNode();
			if(biasNode)
				RegisterNode(biasNode);

			ValueNode* gradXNode = sampleNode->GetGradXNode();
			if(gradXNode)
				RegisterNode(gradXNode);
			ValueNode* gradYNode = sampleNode->GetGradYNode();
			if(gradYNode)
				RegisterNode(gradYNode);

			ValueNode* offsetNode = sampleNode->GetOffsetNode();
			if(offsetNode)
				RegisterNode(offsetNode);
		}
		break;
	case Node::typeFragment:
		{
			if(shaderType != ShaderTypes::pixel)
				THROW("Only pixel shader can do fragment output");
			FragmentNode* fragmentNode = fast_cast<FragmentNode*>(node);

			// register maximum number of fragment outputs
			fragmentTargetsCount = std::max(fragmentTargetsCount, fragmentNode->GetTarget() + 1);
			RegisterNode(fragmentNode->GetNode());
		}
		break;
	case Node::typeDualFragment:
		{
			if(shaderType != ShaderTypes::pixel)
				THROW("Only pixel shader can do dual fragment output");
			DualFragmentNode* dualFragmentNode = fast_cast<DualFragmentNode*>(node);

			dualFragmentTarget = true;

			// register maximum number of fragment outputs
			fragmentTargetsCount = std::max(fragmentTargetsCount, 2);
			RegisterNode(dualFragmentNode->GetNode0());
			RegisterNode(dualFragmentNode->GetNode1());
		}
		break;
	case Node::typeCast:
		RegisterNode(fast_cast<CastNode*>(node)->GetA());
		break;
	default:
		THROW("Unknown node type");
	}

	// add initialization of node
	THROW_ASSERT(nodeInitIndices.find(node) == nodeInitIndices.end());
	nodeInitIndices[node] = (int)nodeInits.size();
	nodeInits.push_back(node);
}
Esempio n. 27
0
std::string DesignCompilerWrapper::get_report_file(unsigned int report_type) const
{
   THROW_ASSERT(report_files.find(report_type) != report_files.end(), "Missing report file");
   return report_files.find(report_type)->second;
}
Esempio n. 28
0
void AlteraBackendFlow::xparse_utilization(const std::string& fn)
{
   try
   {
      XMLDomParser parser(fn);
      parser.Exec();
      if (parser)
      {
         //Walk the tree:
         const xml_element* node = parser.get_document()->get_root_node(); //deleted by DomParser.
         THROW_ASSERT(node->get_name() == "document", "Wrong root name: " + node->get_name());

         const xml_node::node_list list_int = node->get_children();
         for (xml_node::node_list::const_iterator iter_int = list_int.begin(); iter_int != list_int.end(); ++iter_int)
         {
            const xml_element* EnodeC = GetPointer<const xml_element>(*iter_int);
            if(!EnodeC) continue;

            if (EnodeC->get_name() == "application")
            {
               const xml_node::node_list list_sec = EnodeC->get_children();
               for (xml_node::node_list::const_iterator iter_sec = list_sec.begin(); iter_sec != list_sec.end(); ++iter_sec)
               {
                  const xml_element* nodeS = GetPointer<const xml_element>(*iter_sec);
                  if(!nodeS) continue;

                  if (nodeS->get_name() == "section")
                  {
                     std::string stringID;
                     if(CE_XVM(stringID, nodeS)) LOAD_XVM(stringID, nodeS);
                     if (stringID == "QUARTUS_SYNTHESIS_SUMMARY")
                     {
                        const xml_node::node_list list_item = nodeS->get_children();
                        for (xml_node::node_list::const_iterator it_item = list_item.begin(); it_item != list_item.end(); ++it_item)
                        {
                           const xml_element* nodeIt = GetPointer<const xml_element>(*it_item);
                           if(!nodeIt or nodeIt->get_name() != "item") continue;

                           if(CE_XVM(stringID, nodeIt)) LOAD_XVM(stringID, nodeIt);

                           std::string value;
                           if(CE_XVM(value, nodeIt))
                           {
                              LOAD_XVM(value, nodeIt);
                              boost::replace_all(value, ",", "");
                              design_values[stringID] = boost::lexical_cast<double>(value);
                           }
                        }
                     }
                  }
               }
            }
         }
         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 QUARTUS_SH report parsing: " + fn);
}
Esempio n. 29
0
std::string PragmaParser::substitutePragmas(const std::string& OldFile)
{
   INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Substituting pragma in " + OldFile);
   THROW_ASSERT(boost::filesystem::exists(boost::filesystem::path(OldFile)), "Input file \"" + OldFile + "\" does not exist");

   boost::filesystem::path old_path(OldFile);
   std::string FileName = Param->getOption<std::string>(OPT_output_temporary_directory) + STR_CST_pragma_prefix + boost::lexical_cast<std::string>(file_counter) + "_" + GetLeafFileName(old_path);
   boost::filesystem::ofstream fileOutput(FileName.c_str(), std::ios::out);

   file_counter++;
   level = 0;
   unsigned line_number = 0;

   // Get a stream from the input file
   std::ifstream instream(OldFile.c_str());
   // Test if the file has been correctly opened
   THROW_ASSERT(instream.is_open(), "INPUT FILE ERROR: Could not open input file: " + OldFile);
   while (!instream.eof())
   {
      std::string input_line;
      getline (instream,input_line);
      INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Read line <" + input_line + ">");
      std::string output_line = input_line;

      /// search for function name
      if (search_function)
      {
         std::string::size_type notwhite = output_line.find_first_of("(");
         if (notwhite != std::string::npos)
         {
            std::string Token = input_line;
            Token.erase(notwhite);
            name_function += Token;

            notwhite = name_function.find_last_not_of(" \t\r\n");
            name_function.erase(notwhite+1);
            notwhite = name_function.find_last_of(" \t\n*>");
            name_function.erase(0, notwhite+1);
            INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found function " + name_function);

            ///Pragma associated with called are added by pragma_analysis
            if (level == 0)
              PM->AddFunctionDefinitionPragmas(name_function, FunctionPragmas);

            name_function.clear();
            search_function = false;
            FunctionPragmas.clear();
         }
         else
            name_function += input_line + " ";
      }
      if (input_line.find("#pragma") != std::string::npos)
      {
         INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found a pragma");
         output_line = input_line;
         char const* delims = " \t\r\n";
         // trim leading whitespace
         std::string::size_type notwhite = output_line.find_first_not_of(delims);
         output_line.erase(0,notwhite);
         // trim trailing whitespace
         notwhite = output_line.find_last_not_of(delims);
         output_line.erase(notwhite+1);

         analyze_pragma(output_line);
      }

      /// print out the new pragma line
      fileOutput << output_line << std::endl;

      /// manage nesting levels
      bool found = false;
      for(unsigned int i = 0; i < input_line.size(); i++)
      {
         if (input_line[i] == '{')
         {
            level++;
            INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found {: Current level " + boost::lexical_cast<std::string>(level));
            if (!found)
            {
               for(std::list<std::string>::iterator it = FloatingPragmas.begin(); it != FloatingPragmas.end(); it++)
                  OpenPragmas[level].push_back(*it);
               FloatingPragmas.clear();
            }
            found = true;
         }
         if (input_line[i] == '}')
         {
            if (OpenPragmas.count(level))
            {
               for(std::list<std::string>::iterator open_pragma = OpenPragmas[level].begin(); open_pragma != OpenPragmas[level].end(); open_pragma++)
                  fileOutput << std::string(STR_CST_pragma_function_end) + "(\"" << *open_pragma << "\");" << std::endl;
               OpenPragmas[level].clear();
            }
            level--;
            INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found }: Current level " + boost::lexical_cast<std::string>(level));
         }
      }

      /// increment line number
      line_number++;
   }

   fileOutput.close();
   INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Substituted pragma in " + OldFile);
   return FileName;
}
Esempio n. 30
0
void SlGeneratorInstance::PrintNode(ValueNode* node)
{
	THROW_ASSERT(nodeInitIndices.count(node) > 0);
	text << '_' << nodeInitIndices[node];
}