Exemplo n.º 1
0
    void check_block(const Block *b) {
      for (auto input : b->inputs()) {
        check_value(input);
        JIT_ASSERT(input->node()->kind_ == kParam);
      }

      for (auto n : b->nodes()) {
        JIT_ASSERT(n->kind_ != kParam);
        JIT_ASSERT(n->kind_ != kReturn);
        check_node(n);
      }

      JIT_ASSERT(b->output_->kind() == kReturn);
      check_node(b->output_);

      // all_nodes
      // - inputs_, output_ and nodes_ are all included in all_nodes
      // - all_nodes does not contain dead nodes??? (likely to be temporarily
      // suspended).  Weaker: all_nodes contains all inputs and returns
      // - only one return node???

      node_set nodes_set(ALL_OF(b->nodes()));
      node_set inputs_set {b->input_};
      node_set output_set {b->output_};
      // TODO: Make a more type safe std::includes wrapper which disallows use on
      // non-ordered containers
      JIT_ASSERT(std::includes(ALL_OF(all_nodes_set), ALL_OF(nodes_set)));
      JIT_ASSERT(std::includes(ALL_OF(all_nodes_set), ALL_OF(inputs_set)));
      JIT_ASSERT(std::includes(ALL_OF(all_nodes_set), ALL_OF(output_set)));

      sum_set.insert(ALL_OF(nodes_set));
      sum_set.insert(ALL_OF(inputs_set));
      sum_set.insert(ALL_OF(output_set));
    }
Exemplo n.º 2
0
void BranchInfo::_insertVariable(node_type &variable, node_set &variables)
{
	if ((variables.find(variable) != variables.end()) || (_divergGraph.isDivNode(variable))) {
		return;
	}

#ifdef DEBUG
	std::cout << "Variable " << variable << " taints: " << std::endl;
#endif

	node_set newVariables;
	newVariables.insert(variable);

	while (newVariables.size() > 0) {
		node_type newVar = *newVariables.begin();

		variables.insert(newVar);
		newVariables.erase(newVar);
#ifdef DEBUG
		std::cout << newVar << ' ';
#endif

		node_set dependences = _divergGraph.getOutNodesSet(newVar);
		node_set::const_iterator depend = dependences.begin();
		node_set::const_iterator endDepend = dependences.end();

		for (; depend != endDepend; depend++) {
			if ((variables.find(*depend) == variables.end()) && (!_divergGraph.isDivNode(*depend))) {
				newVariables.insert(*depend);
			}
		}
	}
#ifdef DEBUG
	std::cout << std::endl;
#endif

}
Exemplo n.º 3
0
//寻找最短路径,最短路径存储在path中。返回值为路径长度
int Dijkstra(path_vec& path)
{
    //初始化各个变量
    path.clear();
    dist2start.clear();
    open_set.clear();
    close_set.clear();

    close_set.insert(start_node);
    for(int i=0; i<node_count; i++)
    {
        if(i != start_node)
            open_set.insert(i);
        dist2start[i] = std::make_pair(start_node, GetCrtMap(start_node,i) );
    }

    //开始寻路
    while(!open_set.empty())
    {
        path_pair min_cost = std::make_pair(start_node, BIG_NUMBER);
        int min_cost_node = -1;
        for(note_set_iter nodeToDo = open_set.begin();
            nodeToDo != open_set.end();
            nodeToDo++)
        {
            for(note_set_iter nodeDone = close_set.begin();
                nodeDone != close_set.end();
                nodeDone++)
            {
                int tmp_cost = dist2start[*nodeDone].second + GetCrtMap(*nodeDone, *nodeToDo);
                if(min_cost.second >= tmp_cost)
                {
                    min_cost.first = *nodeDone;
                    min_cost.second = tmp_cost;
                    min_cost_node = *nodeToDo;
                }
            } 
        }
        assert(min_cost_node != start_node);
        if(min_cost_node < 0)
            return -1;
        open_set.erase(min_cost_node);
        close_set.insert(min_cost_node);
        dist2start[min_cost_node] = (min_cost);
        
        // update nodes connected with min_cost_node
        for(note_set_iter nodeRel = open_set.begin();
            nodeRel != open_set.end();
            nodeRel++)
        {
            int tmp_dist = GetCrtMap(min_cost_node, *nodeRel);
            if(tmp_dist < BIG_NUMBER && min_cost.second + tmp_dist < dist2start[*nodeRel].second)
            {
                dist2start[*nodeRel].first = min_cost_node;
                dist2start[*nodeRel].second = min_cost.second + tmp_dist < dist2start[*nodeRel].second;
            }
        }
    }

    //输出路径
    int crtNode = end_node;
    do
    {
        path.insert(path.begin(), crtNode);
        crtNode = dist2start[crtNode].first;
    }while( crtNode != start_node );
    path.insert(path.begin(), start_node);

    return dist2start[end_node].second;
}