static bool FreeUselessIns( block *tail, bool just_the_loop, bool in_regalloc ) /*********************************************************************** Free any instructions which have not been marked with the INS_VISITED bit. See below for the setting of this bit. */ { block *blk; instruction *ins; instruction *prev; bool change; change = FALSE; for( blk = tail; blk != NULL; blk = blk->prev_block ) { if( just_the_loop && !( blk->class & IN_LOOP ) ) { for( ins = blk->ins.hd.prev; ins->head.opcode != OP_BLOCK; ins = ins->head.prev ) { ins->ins_flags &= ~INS_VISITED; } } else { for( ins = blk->ins.hd.prev; ins->head.opcode != OP_BLOCK; ins = prev ) { prev = ins->head.prev; if( ( ins->ins_flags & INS_VISITED ) == 0 ) { change = TRUE; if( in_regalloc ) { DoNothing( ins ); } else { FreeIns( ins ); } } else { ins->ins_flags &= ~INS_VISITED; } } } }
bool ScConvert( instruction *ins ) /******************************************** Get rid of instructions like CBW if the high part is not used in the next instruction. */ { hw_reg_set tmp; if( G( ins ) == G_SIGNEX ) { tmp = HighReg( ins->result->r.reg ); if( !HW_Ovlap( ins->head.next->head.live.regs, tmp ) ) { FreeIns( ins ); /* get rid of the pesky cwd or cbw instruction!*/ return( true ); } } return( false ); }
void FreeJunk( block *blk ) /************************************* Free instructions which aren't going to be generated. */ { instruction *ins; instruction *next; for( ins = blk->ins.hd.next; ins->head.opcode != OP_BLOCK; ins = next ) { next = ins->head.next; if( !DoesSomething( ins ) && !SideEffect( ins ) && ins->head.opcode < FIRST_OP_WITH_LABEL && ins->head.opcode != OP_NOP ) { /*% there for zap info*/ FreeIns( ins ); } } }
void RemoveBlock( block *blk ) /*******************************/ { block_num i; unsigned last_line; block *chk; block *next; instruction *next_ins; if( blk->prev_block != NULL ) { blk->prev_block->next_block = blk->next_block; } if( blk->next_block != NULL ) { blk->next_block->prev_block = blk->prev_block; } for( i = 0; i < blk->targets; ++i ) { /* block may have already been removed by dead code removal*/ if( FindBlock( blk->edge[i].destination.u.blk ) ) { RemoveInputEdge( & blk->edge[i] ); } } last_line = blk->ins.hd.line_num; for( ;; ) { next_ins = blk->ins.hd.next; if( next_ins == (instruction *)&blk->ins ) break; if( next_ins->head.line_num != 0 ) { last_line = next_ins->head.line_num; } FreeIns( next_ins ); } /* Move the last line number from the block being deleted to the head of the next block in source order, if that block doesn't already have a line number on it. */ if( blk->next_block != NULL && blk->next_block->gen_id == (blk->gen_id + 1) ) { /* quick check to see if following block is next one in src order */ next = blk->next_block; } else { next = NULL; for( chk = HeadBlock; chk != NULL; chk = chk->next_block ) { if( (chk != blk) && (chk->gen_id > blk->gen_id) && (next == NULL || next->gen_id > chk->gen_id) ) { next = chk; } } } if( next != NULL && next->ins.hd.line_num == 0 ) { next->ins.hd.line_num = last_line; } if( HeadBlock == blk ) { HeadBlock = blk->next_block; } if( BlockList == blk ) { BlockList = blk->prev_block; if( BlockList == NULL ) { BlockList = HeadBlock; } } TellScrapLabel( blk->label ); if( blk->dataflow != NULL ) { CGFree( blk->dataflow ); } FreeABlock( blk ); }