Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/jit/jit-cfg.c  view on Meta::CPAN

			}
		}
	}

	return 1;
}

static int
compute_local_live_sets(_jit_cfg_t cfg)
{
	int index;
	_jit_node_t node;
	jit_insn_iter_t iter;
	jit_insn_t insn;
	jit_value_t dest;
	jit_value_t value1;
	jit_value_t value2;

	for(index = 0; index < cfg->num_nodes; index++)
	{
		node = &cfg->nodes[index];
		jit_insn_iter_init(&iter, node->block);
		while((insn = jit_insn_iter_next(&iter)) != 0)
		{
			dest = get_dest(insn);
			value1 = get_value1(insn);
			value2 = get_value2(insn);

			if(value1 && !use_value(cfg, node, value1))
			{
				return 0;
			}
			if(value2 && !use_value(cfg, node, value2))
			{
				return 0;
			}
			if(dest)
			{
				if((insn->flags & JIT_INSN_DEST_IS_VALUE) != 0)
				{
					if(!use_value(cfg, node, dest))
					{
						return 0;
					}
				}
				else
				{
					if(!def_value(cfg, node, dest))
					{
						return 0;
					}
				}
			}
		}
	}

	return 1;
}

static int
compute_global_live_sets(_jit_cfg_t cfg)
{
	int change;
	int index, succ_index;
	_jit_node_t node;
	_jit_node_t succ;
	_jit_bitset_t bitset;

	if(!_jit_bitset_allocate(&bitset, cfg->num_values))
	{
		return 0;
	}

	do
	{
		change = 0;
		for(index = 0; index < cfg->num_nodes; index++)
		{
			node = cfg->post_order[index];
			if(!node)
			{
				continue;
			}

			_jit_bitset_clear(&bitset);
			for(succ_index = 0; succ_index < node->num_succs; succ_index++)
			{
				succ = node->succs[succ_index]->dst;
				if(_jit_bitset_is_allocated(&succ->live_in))
				{
					_jit_bitset_add(&bitset, &succ->live_in);
				}
			}
			if(!_jit_bitset_is_allocated(&node->live_out)
			   && !_jit_bitset_allocate(&node->live_out, cfg->num_values))
			{
				_jit_bitset_free(&bitset);
				return 0;
			}
			if(_jit_bitset_copy(&node->live_out, &bitset))
			{
				change = 1;
			}

			_jit_bitset_sub(&bitset, &node->live_def);
			_jit_bitset_add(&bitset, &node->live_use);
			if(!_jit_bitset_is_allocated(&node->live_in)
			   && !_jit_bitset_allocate(&node->live_in, cfg->num_values))
			{
				_jit_bitset_free(&bitset);
				return 0;
			}
			if(_jit_bitset_copy(&node->live_in, &bitset))
			{
				change = 1;
			}
		}
	}
	while(change);

	_jit_bitset_free(&bitset);

libjit/jit/jit-cfg.c  view on Meta::CPAN

	{
		for(index = 0; index < cfg->num_nodes; index++)
		{
			if(cfg->nodes[index].succs)
			{
				jit_free(cfg->nodes[index].succs);
			}
			if(cfg->nodes[index].preds)
			{
				jit_free(cfg->nodes[index].preds);
			}
		}
		jit_free(cfg->nodes);
	}
	if(cfg->edges)
	{
		jit_free(cfg->edges);
	}
	if(cfg->post_order)
	{
		jit_free(cfg->post_order);
	}
	if(cfg->values)
	{
		jit_free(cfg->values);
	}
	jit_free(cfg->entry);
	jit_free(cfg->exit);
	jit_free(cfg);
}

_jit_cfg_t
_jit_cfg_build(jit_function_t func)
{
	_jit_cfg_t cfg;

	cfg = create_cfg(func);
	if(!cfg)
	{
		return 0;
	}
	if(!build_nodes(cfg, func) || !build_edges(cfg, func))
	{
		_jit_cfg_free(cfg);
		return 0;
	}
	if(!compute_depth_first_order(cfg))
	{
		_jit_cfg_free(cfg);
		return 0;
	}

	return cfg;
}

int
_jit_cfg_compute_liveness(_jit_cfg_t cfg)
{
	return (create_value_entries(cfg)
		&& compute_local_live_sets(cfg)
		&& compute_global_live_sets(cfg));
}



( run in 0.319 second using v1.01-cache-2.11-cpan-1edf4fed603 )