ravicomp/src/opt_unusedcode.c
static int process_block(LinearizerState *linearizer, Proc *proc, BasicBlock *bb)
{
	GraphNode *node = raviX_graph_node(proc->cfg, bb->index);
	GraphNodeList *predecessors = raviX_predecessors(node);
	if (raviX_node_list_size(predecessors) != 0) {
		// Has predecessors so nothing to do
		return 0;
	}
	// No predecessor blocks, so we can remove this block
	GraphNodeList *successors = raviX_successors(node);
	uint32_t count = raviX_node_list_size(successors);
	if (count == 0) {
		// Nothing to do, but odd?
		// FIXME maybe assert?
		return 0;
	}
	// Make a copy of the successor node list as we need to change the CFG
	nodeId_t *nodes = (nodeId_t *) raviX_realloc_array(NULL, sizeof(nodeId_t), 0, count);
	for (uint32_t i = 0; i < count; i++) {
		nodes[i] = raviX_node_list_at(successors, i);
	}
	for (uint32_t i = 0; i < count; i++) {
		// Remove edge from bb to the successor node
		raviX_delete_edge(proc->cfg, bb->index, nodes[i]);
	}
	raviX_free(nodes);
	assert(raviX_node_list_size(successors) == 0); // All should be gone
	// Now clear out this bb
	// FIXME deallocate instructions
	raviX_ptrlist_remove_all((PtrList **)&bb->insns);
	// FIXME do we deallocate bb?
	return 1; // We changed something
}
/**
 * Check if a basic block has 0 predecessors. If so we can remove it from the CFG.
 * We also remove all the instructions in the basic block
 */
Check if a basic block has 0 predecessors. If so we can remove it from the CFG.
We also remove all the instructions in the basic block
Check if a basic block has 0 predecessors . If so we can remove it from the CFG . We also remove all the instructions in the basic block
static int process_block(LinearizerState *linearizer, Proc *proc, BasicBlock *bb)
{
	GraphNode *node = raviX_graph_node(proc->cfg, bb->index);
	GraphNodeList *predecessors = raviX_predecessors(node);
	if (raviX_node_list_size(predecessors) != 0) {
		return 0;
	}
	GraphNodeList *successors = raviX_successors(node);
	uint32_t count = raviX_node_list_size(successors);
	if (count == 0) {
		return 0;
	}
	nodeId_t *nodes = (nodeId_t *) raviX_realloc_array(NULL, sizeof(nodeId_t), 0, count);
	for (uint32_t i = 0; i < count; i++) {
		nodes[i] = raviX_node_list_at(successors, i);
	}
	for (uint32_t i = 0; i < count; i++) {
		raviX_delete_edge(proc->cfg, bb->index, nodes[i]);
	}
	raviX_free(nodes);
	assert(raviX_node_list_size(successors) == 0); 
	raviX_ptrlist_remove_all((PtrList **)&bb->insns);
	return 1; 
}
static int process_block ( LinearizerState * linearizer , Proc * proc , BasicBlock * bb ) { GraphNode * node = raviX_graph_node ( proc -> cfg , bb -> index ) ; GraphNodeList * predecessors = raviX_predecessors ( node ) ; if ( raviX_node_list_size ( predecessors ) != 0 ) { return 0 ; } GraphNodeList * successors = raviX_successors ( node ) ; uint32_t count = raviX_node_list_size ( successors ) ; if ( count == 0 ) { return 0 ; } nodeId_t * nodes = ( nodeId_t * ) raviX_realloc_array ( NULL , sizeof ( nodeId_t ) , 0 , count ) ; for ( uint32_t i = 0 ; i < count ; i ++ ) { nodes [ i ] = raviX_node_list_at ( successors , i ) ; } for ( uint32_t i = 0 ; i < count ; i ++ ) { raviX_delete_edge ( proc -> cfg , bb -> index , nodes [ i ] ) ; } raviX_free ( nodes ) ; assert ( raviX_node_list_size ( successors ) == 0 ) ; raviX_ptrlist_remove_all ( ( PtrList * * ) & bb -> insns ) ; return 1 ; }
Check if a basic block has 0 predecessors.
Check if a basic block has 0 predecessors .
// Has predecessors so nothing to do // No predecessor blocks, so we can remove this block // Nothing to do, but odd? // FIXME maybe assert? // Make a copy of the successor node list as we need to change the CFG // Remove edge from bb to the successor node // All should be gone // Now clear out this bb // FIXME deallocate instructions // FIXME do we deallocate bb? // We changed something