instruction *rFIXSHIFT( instruction *ins ) /*********************************************/ { instruction *new_ins; #ifndef NDEBUG signed_32 shift_count; #endif /* Fix up shift instructions that try to shift by too large amounts. This * can happen when optimizer merges adjacent shift instructions. Arithmetic * rights shifts must never exceed (REGISTER_BITS - 1), logical shifts can * be replaced with loads of zero constant. */ #ifndef NDEBUG assert( ins->operands[1]->n.class == N_CONSTANT ); shift_count = ins->operands[1]->c.lo.int_value; assert( shift_count >= REG_SIZE * 8 ); #endif if( ins->head.opcode == OP_RSHIFT && Signed[ins->type_class] == ins->type_class ) { ins->operands[1] = AllocS32Const( REG_SIZE * 8 - 1 ); return( ins ); } else { new_ins = MoveConst( 0, ins->result, ins->type_class ); DupSeg( ins, new_ins ); ReplIns( ins, new_ins ); return( new_ins ); } }
static instruction *KillCompare( instruction *ins, name *result ) { /******************************************************************/ instruction *new_ins; if( ins->result != NULL ) { new_ins = MakeMove( result, ins->result, ins->result->n.type_class ); DupSeg( ins, new_ins ); SetCSEBits( ins, new_ins ); ReplIns( ins, new_ins ); } else { new_ins = ins; DoNothing( ins ); } return( new_ins ); }
static void MoveSeg( instruction *ins, instruction *new_ins, name *op, bool save_old ) { /**************************************************/ int i; if( ins->head.opcode == OP_BLOCK ) return; if( ins->num_operands <= NumOperands( ins ) ) return; if( !SegMemLoc( op ) ) return; DupSeg( ins, new_ins ); if( save_old ) return; i = ins->num_operands; while( --i >= 0 ) { if( op == ins->operands[ i ] ) return; } if( op == ins->result ) return; DelSeg( ins ); }
extern instruction *rSPLITMOVE( instruction *ins ) { /******************************************************/ instruction *new_ins; instruction *ins2; name *temp; CnvOpToInt( ins, 0 ); if( IndexOverlaps( ins, 0 ) ) { temp = AllocTemp( LONG_WORD ); new_ins = MakeMove( LowPart( ins->operands[ 0 ], WORD ), LowPart( temp, WORD ), WORD ); ins2 = MakeMove( HighPart( ins->operands[ 0 ], WORD ), HighPart( temp, WORD ), WORD ); DupSegOp( ins, new_ins, 0 ); DupSegOp( ins, ins2, 0 ); ins->operands[ 0 ] = temp; PrefixIns( ins, new_ins ); PrefixIns( ins, ins2 ); ins2 = MakeMove( LowPart( temp, WORD ), LowPart( ins->result, WORD ), WORD ); DupSegRes( ins, ins2 ); PrefixIns( ins, ins2 ); ins2 = MakeMove( HighPart( temp, WORD ), HighPart( ins->result, WORD ), WORD ); ReplIns( ins, ins2 ); } else { HalfType( ins ); new_ins = MakeMove( LowPart( ins->operands[ 0 ], ins->type_class ), LowPart( ins->result, ins->type_class ), ins->type_class ); DupSeg( ins, new_ins ); ins->operands[ 0 ] = HighPart( ins->operands[ 0 ], ins->type_class ); ins->result = HighPart( ins->result, ins->type_class ); if( new_ins->result->n.class == N_REGISTER && ins->operands[ 0 ]->n.class == N_REGISTER && HW_Ovlap( new_ins->result->r.reg, ins->operands[ 0 ]->r.reg ) ) { SuffixIns( ins, new_ins ); new_ins = ins; } else { PrefixIns( ins, new_ins ); } }
extern instruction *rSPLITOP( instruction *ins ) { /****************************************************/ instruction *new_ins; instruction *ins2; name *temp; if( IndexOverlaps( ins, 0 ) || IndexOverlaps( ins, 1 ) ) { temp = AllocTemp( LONG_WORD ); HalfType( ins ); new_ins = MakeBinary( ins->head.opcode, LowPart( ins->operands[ 0 ], WORD ), LowPart( ins->operands[ 1 ], WORD ), LowPart( temp, WORD ), WORD ); ins2 = MakeBinary( ins->head.opcode, HighPart( ins->operands[ 0 ], WORD ), HighPart( ins->operands[ 1 ], WORD ), HighPart( temp, WORD ), WORD ); if( ins->head.opcode == OP_ADD ) { ins2->head.opcode = OP_EXT_ADD; } else if( ins->head.opcode == OP_SUB ) { ins2->head.opcode = OP_EXT_SUB; } ins2->table = CodeTable( ins2 ); new_ins->table = ins2->table; DupSegOp( ins, new_ins, 0 ); DupSegOp( ins, ins2, 0 ); DupSegOp( ins, new_ins, 1 ); DupSegOp( ins, ins2, 1 ); ins->operands[ 0 ] = temp; ins->operands[ 1 ] = temp; PrefixIns( ins, new_ins ); PrefixIns( ins, ins2 ); ins2 = MakeMove( LowPart( temp, WORD ), LowPart( ins->result, WORD ), WORD ); DupSegRes( ins, ins2 ); PrefixIns( ins, ins2 ); ins2 = MakeMove( HighPart( temp, WORD ), HighPart( ins->result, WORD ), WORD ); DupSegRes( ins, ins2 ); ReplIns( ins, ins2 ); } else { HalfType( ins ); new_ins = MakeBinary( ins->head.opcode, LowPart( ins->operands[ 0 ], ins->type_class ), LowPart( ins->operands[ 1 ], ins->type_class ), LowPart( ins->result, ins->type_class ), ins->type_class ); DupSeg( ins, new_ins ); ins->operands[ 0 ] = HighPart( ins->operands[ 0 ], ins->type_class ); ins->operands[ 1 ] = HighPart( ins->operands[ 1 ], ins->type_class ); ins->result = HighPart( ins->result, ins->type_class ); if( ins->head.opcode == OP_ADD ) { ins->head.opcode = OP_EXT_ADD; } else if( ins->head.opcode == OP_SUB ) { ins->head.opcode = OP_EXT_SUB; } /* Assign fake reduce table (from OP_EXT) to new_ins; default reduce table can generate INC and DEC which'll not set condition codes */ ins->table = CodeTable( ins ); new_ins->table = ins->table; PrefixIns( ins, new_ins ); } new_ins->ins_flags |= INS_CC_USED; return( new_ins ); }
static instruction *FoldAbsolute( instruction *ins ) { /********************************************************* See below. */ instruction *new_ins; opcnt num_operands; name *result; tn fold; type_def *tipe; type_def *left_tipe; type_def *rite_tipe; type_def *fold_tipe; pointer left; pointer rite; name *tmp; name *new_const; float_handle value; tipe = ClassType( ins->type_class ); left_tipe = ClassType( _OpClass( ins ) ); num_operands = OpcodeNumOperands( ins ); left = NULL; rite = NULL; if( num_operands != 0 ) { left = TName( ins->operands[0], left_tipe ); if( num_operands > 1 ) { if( ins->operands[1]->n.type_class == XX ) { rite_tipe = tipe; } else { rite_tipe = ClassType( ins->operands[1]->n.type_class ); } rite = TName( ins->operands[1], rite_tipe ); } } fold = NULL; switch( ins->head.opcode ) { case OP_ADD: fold = FoldPlus( left, rite, tipe ); break; case OP_SUB: fold = FoldMinus( left, rite, tipe ); break; case OP_MUL: fold = FoldTimes( left, rite, tipe ); break; case OP_DIV: fold = FoldDiv( left, rite, tipe ); break; case OP_MOD: fold = FoldMod( left, rite, tipe ); break; case OP_AND: fold = FoldAnd( left, rite, tipe ); break; case OP_OR: fold = FoldOr( left, rite, tipe ); break; case OP_XOR: fold = FoldXor( left, rite, tipe ); break; case OP_RSHIFT: fold = FoldRShift( left, rite, tipe ); break; case OP_LSHIFT: fold = FoldLShift( left, rite, tipe ); break; case OP_NEGATE: fold = FoldUMinus( left, tipe ); break; case OP_COMPLEMENT: fold = Fold1sComp( left, tipe ); break; case OP_CONVERT: // look out for CNV PT U2 t1 type instructions; if sizeof( PT ) is greater // than sizeof( U2 ), we don't want to fold or we'll screw up based pointers if( IsTrickyPointerConv( ins ) ) return( NULL ); // fall through! case OP_ROUND: fold = FoldCnvRnd( (cg_op)ins->head.opcode, left, tipe ); break; case OP_CMP_EQUAL: case OP_CMP_NOT_EQUAL: case OP_CMP_GREATER: case OP_CMP_LESS_EQUAL: case OP_CMP_LESS: case OP_CMP_GREATER_EQUAL: if( ActiveCompare( ins ) ) { fold = FoldCompare( (cg_op)ins->head.opcode, left, rite, tipe ); if( fold != NULL ) { return( StraightLine( ins, fold, true ) ); } } break; case OP_BIT_TEST_TRUE: if( ActiveCompare( ins ) ) { fold = FoldAnd( left, rite, tipe ); if( fold != NULL ) { return( StraightLine( ins, fold, true ) ); } } break; case OP_BIT_TEST_FALSE: if( ActiveCompare( ins ) ) { fold = FoldAnd( left, rite, tipe ); if( fold != NULL ) { return( StraightLine( ins, fold, false ) ); } } break; default: fold = NULL; break; } if( fold != NULL ) { fold_tipe = fold->tipe; result = TGetName( fold ); if( result != NULL && !NeedConvert( fold_tipe, tipe ) ) { ins->table = NULL; // look out for scary DIV U4 EDX:EAX, c1 -> t1 type instructions if( result->n.class != N_CONSTANT && result->n.size != TypeClassSize[ins->type_class] ) return( NULL ); // look out for scary MUL U4 EDX:EAX, c1 -> t1 type instructions if( result->n.class != N_CONSTANT && ins->result->n.size != TypeClassSize[ins->type_class] ) return( NULL ); new_ins = MakeMove( result, ins->result, ins->type_class ); SetCSEBits( ins, new_ins ); DupSeg( ins, new_ins ); ReplIns( ins, new_ins ); return( new_ins ); }