Exemple #1
0
extern  ins_entry       *IsolatedCode( ins_entry *instr )
/*******************************************************/
{
    ins_entry   *next;

    optbegin
    next = NextIns( instr );
    for( ;; ) {
        if( next == NULL )
            optreturn( next );
        if( _Class( next ) == OC_LABEL )
            break;
        _Savings( OPT_ISOLATED, _ObjLen( next ) );
        if( _Class( next ) == OC_INFO ) {
            next = next->ins.next;
        } else {
            next = DelInstr( next );
        }
        if( _Class( instr ) == OC_DEAD ) {
            break;
        }
    }
    next = Untangle( next );
    optreturn( next );
}
Exemple #2
0
extern  void    CloneCode( label_handle lbl )
/*****************************************
    consider:

        JMP L1
            ....
  L1:   POP   AX
        RET

    we want to clone the code at L1 at the point of the jump,
    since it will be faster (and smaller since POP AX/RET is only 2 bytes
    while the JMP might be 3/5).
*/
{
    ins_entry   *next;
    ins_entry   *lbl_ins;
    ins_entry   *hoist;
    ins_entry   *jmp;
    unsigned    size;
    unsigned    max_size;

    lbl_ins = lbl->ins;
    if( lbl_ins == NULL )
        return;
    size = 0;
    hoist = NextIns( lbl_ins );
    for( next = hoist; ; next = NextIns( next ) ) {
        if( next == NULL )
            return;
        if( _Class( next ) == OC_CODE && CodeHasAbsPatch( &next->oc.oc_entry ) )
            return;
        if( _Class( next ) != OC_LABEL ) {
            size += _ObjLen( next );
            if( size > MAX_CLONE_SIZE )
                return;
            if( _TransferClass( _Class( next ) ) ) {
                break;
            }
        }
    }
    if( _Class( next ) == OC_JMP && _Label( next ) == lbl )
        return;
    for( jmp = lbl->refs; jmp != NULL; jmp = _LblRef( jmp ) ) {
        if( next == jmp )
            continue;
        if( !_TransferClass( _Class( jmp ) ) )
            continue;
        max_size = _ObjLen( jmp );
        if( size > max_size && FindShort( jmp, NULL ) )
            continue;
        if( OptForSize < 50 ) {
            max_size *= (100-OptForSize) / 25;
        }
        if( size > max_size )
            continue;
        DoCloneCode( jmp, hoist );
        DelInstr( jmp );
    }
}
Exemple #3
0
void    DumpOc( ins_entry *ins )
/******************************/
{
    DumpPtr( ins );
    DumpChar( ' ' );
    DumpString(  CNames[_Class( ins )] );
    DumpChar( ' ' );
    if( _Class( ins ) != OC_INFO ) {
        CheckAttr( ins->oc.oc_header.class );
    }
Exemple #4
0
extern  void    DumpOc( ins_entry *ins ) {
/****************************************/

    DumpPtr( ins );
    DumpLiteral( " " );
    DumpString(  CNames[ _Class( ins ) ] );
    DumpLiteral( " " );
    if( _Class( ins ) != OC_INFO ) {
        CheckAttr( ins->oc.oc_header.class );
    }
Exemple #5
0
static  void    DoCloneCode( ins_entry *jmp, ins_entry *hoist )
/*************************************************************/
{
    ins_entry   *clone_point;
    ins_entry   *clone;
    oc_class    cl;

    clone_point = PrevIns( jmp );
    for( ;; ) {
        cl = _Class( hoist );
        switch( cl ) {
        case OC_LABEL:
        case OC_INFO:
        case OC_LREF:
            break;
        default:
            clone = NewInstr( &hoist->oc );
            AddInstr( clone, clone_point );
            if( _TransferClass( cl ) )
                return;
            clone_point = clone;
            break;
        }
        hoist = NextIns( hoist );
    }
}
Exemple #6
0
static  void    TransformJumps( ins_entry *ins, ins_entry *first )
/****************************************************************/
{
    ins_entry           *add;
    ins_entry           *next;
    ins_entry           *lbl;
    oc_class            cl;

  optbegin
    if( _Class( ins ) == OC_RET )
        optreturnvoid;
    lbl = _Label( ins )->ins;
    if( lbl == NULL )
        optreturnvoid;
    add = lbl;
    for( ;; ) {
        if( add == NULL )
            optreturnvoid;
        cl = _Class( add );
        if( _TransferClass( cl ) )
            break;
        if( cl == OC_LABEL ) {
            if( _Attr( add ) & ATTR_SHORT )
                optreturnvoid;
            _ClrStatus( _Label( add ), SHORTREACH );
        }
        add = NextIns( add );
    }
    if( add == first || add == ins )
        optreturnvoid;
    if( FindShort( first, lbl ) )
        optreturnvoid;
    for( ;; ) {
        next = PrevIns( add );
        DeleteQueue( add );
        InsertQueue( add, first );
        if( add == lbl )
            break;
        add = next;
    }
    DeleteQueue( first );
    InsertQueue( first, next );
    Untangle( NextIns( first ) );
  optend
}
Exemple #7
0
extern  bool    FindShort( ins_entry *ins, ins_entry *end )
/*********************************************************/
{
    for( ; ins != NULL && ins != end; ins = NextIns( ins ) ) {
        if( _Class( ins ) == OC_LABEL ) {
            if( _Attr( ins ) & ATTR_SHORT )
                return( true );
            _ClrStatus( _Label( ins ), SHORTREACH );
        }
    }
    return( false );
}
Exemple #8
0
extern  void    JmpRet( ins_entry *instr )
/****************************************/
{
    ins_entry   *ret;

    optbegin
    if( InsDelete )
        optreturnvoid;
    ret = _Label( instr )->ins;
    if( ret == NULL )
        optreturnvoid;
    ret = NextIns( ret );
    if( ret == NULL )
        optreturnvoid;
    if( _Class( ret ) != OC_RET )
        optreturnvoid;
    JmpToRet( instr, ret );
    optend
}
Exemple #9
0
extern  void    CheckStraightenCode( ins_entry  *lbl_ins )
/********************************************************/
{
    label_handle    lbl;
    ins_entry       *jmp;

    optbegin
    if( lbl_ins != NULL ) {
        lbl = _Label( lbl_ins );
        for( jmp = lbl->refs; jmp != NULL; jmp = _LblRef( jmp ) ) {
            if( !_TransferClass( _Class( jmp ) ) )
                continue;
            if( StraightenCode( jmp ) ) {
                break;
            }
        }
    }
    optend
}
Exemple #10
0
char  *FindLabel( uint_32 ref, uint_32 addr, segment *seg )
/*********************************************************/
{
    char                *name;
    fixup               *fix;

    switch( _Class( seg ) ) {
    case TYPE_IMPORT:               /* fall through */
    case TYPE_COMDEF:
        name = FormSym( _Name( seg ) );
        break;
    case TYPE_GROUP:
        name = _Name( seg );
        break;
    default:
        if( ref == BAD_OFFSET ) {
            fix = NULL;
        } else {
            fix = FindFixup( ref, seg );
        }
        if( fix == NULL ) {
            name = FindExpName( addr, seg );
            if( name == NULL ) {
                AddLabel( addr, NULL, seg, false, false );
            }
        } else {
            name = GetFixName( fix );
            if( name == NULL ) {
                AddLabel( fix->imp_address, NULL, seg, false, false );
                name = FindExpName( fix->imp_address, seg );
            }
        }
        break;
    }
    return( name );
}
Exemple #11
0
extern  bool    StraightenCode( ins_entry *jump )
/***********************************************/
{
    ins_entry   *next;
    ins_entry   *insert;
    ins_entry   *hoist;
    ins_entry   *end_hoist;
    oc_class    cl;
    obj_length  align;

    optbegin
    hoist = _Label( jump )->ins;
    if( hoist == NULL )
        optreturn( false );
    if( hoist == LastIns )
        optreturn( false );
    cl = PrevClass( hoist );
    if( !_TransferClass( cl ) )
        optreturn( false );

    end_hoist = NULL;
    for( next = hoist; ; next = NextIns( next ) ) {
        if( next == jump ) { // pushing code down to jump
            if( end_hoist == NULL )
                optreturn( false );
            if( FindShort( hoist, end_hoist ) )
                optreturn( false );
            break;
        }
        if( next == NULL ) { // hauling code up to jump
            if( FindShort( jump, hoist ) )
                optreturn( false );
            break;
        }
        cl = _Class( next );
        if( end_hoist == NULL && _TransferClass( cl ) ) {
            end_hoist = next;
        }
    }

    align = _ObjLen( hoist );
    insert = jump;
    for( ;; ) {
        if( hoist == NULL ) {
            ChgLblRef( jump, AddNewLabel( LastIns, align ) );
            next = LastIns;
            break;
        }
        next = NextIns( hoist );
        DeleteQueue( hoist );
        InsertQueue( hoist, insert );
        if( hoist == jump )
            optreturn( false );
        insert = hoist;
        cl = _Class( hoist );
        if( _TransferClass( cl ) ) {
            IsolatedCode( insert );
            break;
        }
        hoist = next;
    }
    InsDelete = true;
    Untangle( next );
    if( _Class( jump ) != OC_DEAD ) {
        Untangle( _Label( jump )->ins );
    }
    optreturn( true );
}