<s> if ( secondReg ) { cmpOp2 = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; MachineRegisterInfo & MRI = MF . getRegInfo ( ) ; if ( secondReg && ! TargetRegisterInfo :: isPhysicalRegister ( cmpOp2 ) ) { MachineInstr * def = MRI . getVRegDef ( cmpOp2 ) ; if ( def -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; } } ++ II ; for ( MachineBasicBlock :: iterator localII = II ; localII != end ; ++ localII ) { if ( ! commonChecksToProhibitNewValueJump ( optLocation , localII ) ) return false ; if ( localII -> modifiesRegister ( pReg , TRI ) || localII -> readsRegister ( pReg , TRI ) ) return false ; if ( localII -> modifiesRegister ( cmpReg1 , TRI ) || ( secondReg && localII -> modifiesRegister ( cmpOp2 , TRI ) ) ) return false ; } return true


<s> if ( MII -> getOpcode ( ) == TargetOpcode :: KILL || MII -> getOpcode ( ) == TargetOpcode ::

PHI || MII -> getOpcode ( ) == TargetOpcode :: COPY ) return false ;


<s> FunctionPass * llvm :: create<ISA_LIT>NewValueJump ( ) { return new <ISA_LIT>NewValueJump


<s> void getAnalysisUsage ( AnalysisUsage & AU ) const override { AU . addRequired <


<s> <ISA_LIT>NewValueJump ( ) : MachineFunctionPass ( ID ) { initialize<ISA_LIT>NewValueJumpPass ( * PassRegistry ::


<s> if ( II -> getOperand ( i ) . isReg ( ) && ( II -> getOperand ( i ) . isUse ( ) || II -> getOperand ( i ) . isDef ( ) ) ) { MachineBasicBlock :: iterator localII = II ; ++ localII ; unsigned Reg = II -> getOperand ( i ) . getReg ( ) ; for ( MachineBasicBlock :: iterator localBegin = localII ; localBegin != end ; ++ localBegin ) { if ( localBegin == skip ) continue ; if ( localBegin -> modifiesRegister ( Reg , TRI ) || localBegin -> readsRegister ( Reg , TRI


<s> if ( MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> ) return false ; } return true


<s> if ( MII -> getOpcode ( ) == <STR_LIT> ) return false ; if ( ! afterRA ) { if ( MII -> getOpcode ( ) == TargetOpcode :: KILL || MII -> getOpcode ( ) == TargetOpcode :: PHI || MII -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; if ( MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode (


<s> const BranchProbability Prediction = MBPI -> getEdgeProbability ( Src , jmpTarget ) ; if ( Prediction >= BranchProbability ( <NUM_LIT> , <NUM_LIT> ) ) taken = true ; switch ( MI -> getOpcode ( ) ) { case <STR_LIT> : return taken ? <STR_LIT> : <STR_LIT> ; case <STR_LIT> : { if ( reg >= <NUM_LIT> ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT> : { if ( secondRegNewified ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT> : { if ( reg >= <NUM_LIT> ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT> : { if ( secondRegNewified ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT> : return taken ? <STR_LIT> : <STR_LIT> ; default : llvm_unreachable (


<s> AU . addRequired < MachineBranchProbabilityInfo >


<s> } assert ( HadDef ) ; for ( unsigned i = <NUM_LIT> ; i < II -> getNumOperands ( ) ; ++ i ) { if ( II -> getOperand ( i ) . isReg ( ) && ( II -> getOperand ( i ) . isUse ( ) || II -> getOperand ( i ) . isDef ( ) ) ) { MachineBasicBlock :: iterator localII = II ; ++ localII ; Register Reg = II -> getOperand ( i ) . getReg ( ) ; for ( MachineBasicBlock :: iterator localBegin = localII ; localBegin != end ; ++ localBegin )


<s> int64_t v = Op2 . getImm ( ) ; bool Valid = false ; switch ( MI . getOpcode ( ) ) { case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : Valid = ( isUInt < <NUM_LIT> > ( v ) || v == - <NUM_LIT> ) ; break ; case <STR_LIT> : case <STR_LIT> : Valid = isUInt < <NUM_LIT> > ( v ) ; break ; case <STR_LIT> : case <STR_LIT> : Valid = ( v == <NUM_LIT> ) ; break ; } if ( ! Valid ) return false ; } unsigned cmpReg1 , cmpOp2 = <NUM_LIT> ; cmpReg1 = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( secondReg ) { cmpOp2 = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( cmpReg1 == cmpOp2 ) return false ; MachineRegisterInfo & MRI = MF . getRegInfo ( ) ; if ( ! Register :: isPhysicalRegister ( cmpOp2 ) ) { MachineInstr * def = MRI . getVRegDef ( cmpOp2 ) ; if ( def -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; } } ++ II ; for ( MachineBasicBlock :: iterator localII = II ; localII != end ; ++ localII ) { if ( localII -> isDebugInstr ( ) ) continue ; if ( ! commonChecksToProhibitNewValueJump ( optLocation , localII ) ) return false ; if ( localII -> modifiesRegister ( pReg , TRI ) || localII -> readsRegister ( pReg , TRI ) ) return false ; if ( localII -> modifiesRegister ( cmpReg1 , TRI ) || ( secondReg && localII -> modifiesRegister ( cmpOp2 , TRI ) ) ) return false ; } return


<s> bool taken = false ; MachineBasicBlock * Src = MI -> getParent ( ) ; const BranchProbability Prediction = MBPI -> getEdgeProbability ( Src , jmpTarget ) ; if ( Prediction >= BranchProbability ( <NUM_LIT> , <NUM_LIT> ) ) taken = true ; switch ( MI -> getOpcode ( ) ) { case <STR_LIT> : return taken ? <STR_LIT> : <STR_LIT> ; case <STR_LIT> : { if ( reg >= <NUM_LIT> ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT> : { if ( secondRegNewified ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT>


<s> if ( II -> getOperand ( i ) . isReg ( ) && ( II -> getOperand ( i ) . isUse ( ) || II -> getOperand ( i ) . isDef ( ) ) ) { MachineBasicBlock :: iterator localII = II ; ++ localII ; unsigned Reg = II -> getOperand ( i ) . getReg ( ) ; for ( MachineBasicBlock :: iterator localBegin = localII ; localBegin != end ; ++ localBegin ) { if ( localBegin == skip ) continue ; if ( localBegin -> modifiesRegister ( Reg , TRI ) || localBegin -> readsRegister ( Reg , TRI ) ) return false ; } } } return


<s> MachineRegisterInfo & MRI = MF . getRegInfo ( ) ; if ( secondReg && ! TargetRegisterInfo :: isPhysicalRegister ( cmpOp2 ) ) { MachineInstr * def = MRI . getVRegDef ( cmpOp2 ) ; if ( def -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; } } ++ II ; for ( MachineBasicBlock :: iterator localII = II ; localII != end ; ++ localII ) { if ( ! commonChecksToProhibitNewValueJump ( optLocation , localII ) ) return false ; if ( localII -> modifiesRegister ( pReg , TRI ) || localII -> readsRegister ( pReg , TRI ) ) return false ; if ( localII -> modifiesRegister ( cmpReg1 , TRI ) || ( secondReg && localII -> modifiesRegister ( cmpOp2 , TRI ) ) ) return false ; } return


<s> case <STR_LIT> : case <STR_LIT> : Valid = ( isUInt < <NUM_LIT> > ( v ) || v == - <NUM_LIT> ) ; break ; case <STR_LIT> : case <STR_LIT> : Valid = isUInt < <NUM_LIT> > ( v ) ; break ; case <STR_LIT> : case <STR_LIT> : Valid = ( v == <NUM_LIT> ) ; break ; } if ( ! Valid ) return false ; } unsigned cmpReg1 , cmpOp2 = <NUM_LIT> ; cmpReg1 = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( secondReg ) { cmpOp2 = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( cmpReg1 == cmpOp2 ) return false ; MachineRegisterInfo & MRI = MF . getRegInfo ( ) ; if ( secondReg && ! Register :: isPhysicalRegister ( cmpOp2 ) ) { MachineInstr * def = MRI . getVRegDef ( cmpOp2


<s> if ( II -> getOperand ( i ) . isReg ( ) && ( II -> getOperand ( i ) . isUse ( ) || II -> getOperand ( i ) . isDef ( ) ) ) { MachineBasicBlock :: iterator localII = II ; ++ localII ; unsigned Reg = II -> getOperand ( i ) . getReg ( ) ; for ( MachineBasicBlock :: iterator localBegin = localII ; localBegin != end ; ++ localBegin


<s> if ( predLive ) break ; jmpTarget = MI -> getOperand ( <NUM_LIT> ) . getMBB ( ) ; foundJump = true ; if ( MI -> getOpcode ( ) == <STR_LIT> || MI -> getOpcode ( ) == <STR_LIT> || MI -> getOpcode ( ) == <STR_LIT> ) { invertPredicate = true ; } continue ; } if ( foundJump && MI -> getNumOperands ( ) == <NUM_LIT> ) break ; if ( foundJump && ! foundCompare && MI -> getOperand ( <NUM_LIT> ) . isReg ( ) && MI -> getOperand ( <NUM_LIT> ) . getReg ( ) == predReg ) { if ( QII -> isNewValueJumpCandidate ( MI ) ) { assert ( ( MI -> getDesc ( ) . isCompare ( ) ) && <STR_LIT> ) ; isSecondOpReg = MI -> getOperand ( <NUM_LIT> ) . isReg ( ) ; if ( ! canCompareBeNewValueJump ( QII , QRI , MII , predReg , isSecondOpReg , afterRA , jmpPos , MF ) ) break ; cmpInstr = MI ; cmpPos = MII ; foundCompare = true ; cmpReg1 = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( MI -> getOperand ( <NUM_LIT> ) . isKill ( ) ) MO1IsKill = true ; if ( isSecondOpReg ) { cmpOp2 = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( MI -> getOperand ( <NUM_LIT> ) . isKill ( ) ) MO2IsKill = true ; } else cmpOp2 = MI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; continue ; } } if ( foundCompare && foundJump ) { if ( ! commonChecksToProhibitNewValueJump ( afterRA , MII ) ) break ; bool foundFeeder = false ; MachineBasicBlock :: iterator feederPos = MII ; if ( MI -> getOperand ( <NUM_LIT> ) . isReg ( ) && MI -> getOperand ( <NUM_LIT> ) . isDef ( ) && ( MI -> getOperand ( <NUM_LIT> ) . getReg ( ) == cmpReg1 || ( isSecondOpReg && MI -> getOperand ( <NUM_LIT> ) . getReg ( ) == ( unsigned ) cmpOp2 ) ) ) { unsigned feederReg = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( feederReg == cmpReg1 ) { if ( ! canBeFeederToNewValueJump ( QII , QRI , MII , jmpPos , cmpPos , MF ) ) { if ( ! isSecondOpReg ) break ; else continue ; } else foundFeeder = true ; } if ( ! foundFeeder && isSecondOpReg && feederReg == ( unsigned ) cmpOp2 ) if ( ! canBeFeederToNewValueJump ( QII , QRI , MII , jmpPos , cmpPos , MF ) ) break ; if ( isSecondOpReg ) { if ( cmpInstr -> getOpcode ( ) == <STR_LIT> && feederReg == ( unsigned ) cmpOp2 ) { unsigned tmp = cmpReg1 ; bool tmpIsKill = MO1IsKill ; cmpReg1 = cmpOp2 ; MO1IsKill = MO2IsKill ; cmpOp2 = tmp ; MO2IsKill = tmpIsKill ; } if ( feederReg == ( unsigned ) cmpOp2 ) isSecondOpNewified


<s> if ( ! Valid ) return false ; } unsigned cmpReg1 , cmpOp2 = <NUM_LIT> ; cmpReg1 = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( secondReg ) { cmpOp2 = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( cmpReg1 == cmpOp2 ) return false ; MachineRegisterInfo & MRI = MF . getRegInfo ( ) ; if ( secondReg && ! TargetRegisterInfo :: isPhysicalRegister ( cmpOp2 ) ) { MachineInstr * def = MRI . getVRegDef ( cmpOp2 ) ; if ( def -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; } } ++ II ; for ( MachineBasicBlock :: iterator localII = II ; localII != end ; ++ localII ) { if ( localII -> isDebugValue ( ) ) continue ; if ( ! commonChecksToProhibitNewValueJump ( optLocation , localII ) ) return false ; if ( localII -> modifiesRegister ( pReg , TRI ) || localII -> readsRegister ( pReg


<s> if ( secondReg ) { cmpOp2 = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( cmpReg1 == cmpOp2 ) return false ; MachineRegisterInfo & MRI = MF . getRegInfo ( ) ; if ( secondReg && ! TargetRegisterInfo :: isPhysicalRegister ( cmpOp2 ) ) { MachineInstr * def = MRI . getVRegDef ( cmpOp2 ) ; if ( def -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; } } ++ II ; for ( MachineBasicBlock :: iterator localII = II ; localII != end ; ++ localII ) { if ( localII -> isDebugValue ( ) ) continue ; if ( ! commonChecksToProhibitNewValueJump ( optLocation , localII


<s> if ( MII -> isCall ( ) ) return false ; if ( ! afterRA ) { if ( MII -> getOpcode ( ) == TargetOpcode :: KILL || MII -> getOpcode ( ) == TargetOpcode :: PHI || MII -> getOpcode (

) == TargetOpcode :: COPY ) return false ;


<s> cmpReg1 = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( secondReg ) { cmpOp2 = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; MachineRegisterInfo & MRI = MF . getRegInfo ( ) ; if ( secondReg && ! TargetRegisterInfo :: isPhysicalRegister ( cmpOp2 ) ) { MachineInstr * def = MRI . getVRegDef ( cmpOp2 ) ; if ( def -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; } } ++ II ; for ( MachineBasicBlock :: iterator localII = II ; localII != end ; ++ localII ) { if ( ! commonChecksToProhibitNewValueJump ( optLocation , localII ) ) return false ; if ( localII -> modifiesRegister ( pReg , TRI ) || localII -> readsRegister ( pReg , TRI ) ) return false ; if ( localII -> modifiesRegister ( cmpReg1 , TRI ) || ( secondReg && localII ->

modifiesRegister ( cmpOp2 , TRI ) ) ) return false ;


<s> if ( MII -> getDesc ( ) . mayStore ( ) ) return false ; if ( MII -> getOpcode ( ) == <STR_LIT> ) return false ; if ( ! afterRA ) { if ( MII -> getOpcode ( ) == TargetOpcode :: KILL || MII -> getOpcode ( ) == TargetOpcode :: PHI || MII -> getOpcode ( ) == TargetOpcode :: COPY ) return false ; if ( MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> || MII -> getOpcode ( ) == <STR_LIT> ) return false ; } return true


<s> if ( Prediction >= BranchProbability ( <NUM_LIT> , <NUM_LIT> ) ) taken = true ; switch ( MI -> getOpcode ( ) ) { case <STR_LIT> : return taken ? <STR_LIT> : <STR_LIT> ; case <STR_LIT> : { if ( reg >= <NUM_LIT> ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT> : { if ( secondRegNewified ) return taken ? <STR_LIT> : <STR_LIT> ; else return taken ? <STR_LIT> : <STR_LIT> ; } case <STR_LIT>


<s> RegisterRef UR = UN . Addr -> getRegRef ( * DFG ) ; NodeSet Visited , Defs ; const auto & P = LV -> getAllReachingDefsRec ( UR , UN , Visited , Defs ) ; if ( ! P . second ) { LLVM_DEBUG ( { dbgs ( ) << <STR_LIT> << PrintNode < UseNode * > ( UN , * DFG ) << '\n' << <STR_LIT> ; } ) ; return false ; } const auto & ReachingDefs = P . first ; if ( ReachingDefs . size ( ) > <NUM_LIT> ) { LLVM_DEBUG ( { dbgs ( ) << <STR_LIT> ; for ( auto DI : ReachingDefs ) { NodeAddr < UseNode * > DA = DFG -> addr < UseNode * > ( DI ) ; NodeAddr < StmtNode * > TempIA = DA . Addr -> getOwner ( * DFG ) ; dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( TempIA , * DFG ) << <STR_LIT> ; } }


<s> LLVM_DEBUG ( { dbgs ( ) << <STR_LIT> ; for ( auto DI : ReachingDefs ) { NodeAddr < UseNode * > DA = DFG -> addr < UseNode * > ( DI ) ; NodeAddr < StmtNode * > TempIA = DA . Addr -> getOwner ( * DFG ) ; dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( TempIA


<s> bool KeepTfr = false ; bool HasRepInstr = false ; InstrEvalResult . clear ( ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { bool CanBeReplaced = false ; NodeAddr < UseNode * > UN = * I ; NodeAddr < StmtNode * > SN = UN . Addr -> getOwner ( * DFG ) ; MachineInstr & MI = * SN . Addr -> getCode ( ) ; const MCInstrDesc & MID = MI . getDesc ( ) ; if ( ( MID . mayLoad ( ) || MID . mayStore ( )


<s> if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) return false ; NodeAddr < RefNode * > AA = LV -> getNearestAliasedRef ( OffsetRR , IA ) ; if ( ( DFG -> IsDef ( AA ) && AA . Id != OffsetRegRD ) || AA . Addr -> getReachingDef ( ) != OffsetRegRD ) return false ; MachineInstr & UseMI = * NodeAddr < StmtNode * > ( IA ) . Addr -> getCode ( ) ; NodeAddr < DefNode * > OffsetRegDN = DFG -> addr < DefNode * > ( OffsetRegRD ) ; if ( ( OffsetRegDN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && MI . getParent ( ) != UseMI . getParent ( ) ) return false ; const MCInstrDesc & UseMID = UseMI


<s> assert ( ! ( UseUN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > UseIA = UseUN . Addr -> getOwner ( * DFG ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( UseIA , * DFG ) << <STR_LIT> ) ; MachineInstr * UseMI = UseIA . Addr -> getCode ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << printMBBReference ( * UseMI -> getParent ( ) ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; const MCInstrDesc & UseMID = UseMI -> getDesc ( ) ; assert ( HII -> getAddrMode ( * UseMI ) == <STR_LIT> ) ; auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; short NewOpCode = getBaseWithLongOffset ( * UseMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; unsigned OpStart ; unsigned OpEnd = UseMI -> getNumOperands ( ) ; MachineBasicBlock * BB = UseMI -> getParent ( ) ; MachineInstrBuilder MIB = BuildMI ( * BB , InsertPt , UseMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; if ( UseMID . mayLoad ( ) ) { MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand


<s> if ( UseMID . mayLoad ( ) ) { MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; } else if ( UseMID . mayStore ( ) ) { MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else llvm_unreachable ( <STR_LIT> ) ; for ( unsigned i = OpStart ; i < OpEnd ; ++ i ) MIB . add ( UseMI -> getOperand ( i ) ) ; Deleted . insert (


<s> MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . isImm ( ) ) { short NewOpCode = HII -> changeAddrMode_io_abs ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else Changed


<s> MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> changeAddrMode_io_abs ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } Changed = true ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> changeAddrMode_rr_io ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed =


<s> FunctionPass * llvm :: create<ISA_LIT>OptAddrMode ( ) { return new <ISA_LIT>OptAddrMode


<s> FunctionPass * llvm :: create<ISA_LIT>OptAddrMode (


<s> AU . addRequired < MachineDominanceFrontier > ( ) ; AU . setPreservesAll


<s> return HII -> changeAddrMode_rr_ur ( TempOpCode ) ; } return HII -> changeAddrMode_rr_ur ( MI


<s> if ( MID . mayStore ( ) ) { MachineOperand StOp = MI . getOperand ( MI . getNumOperands ( ) - <NUM_LIT> ) ; if ( StOp . isReg ( ) && StOp . getReg ( ) == TfrDefR ) return false ; } if ( HII -> getAddrMode ( MI ) == <STR_LIT> ) return ( HII -> changeAddrMode_rr_ur ( MI ) >= <NUM_LIT> ) ; else if ( HII -> getAddrMode ( MI ) == <STR_LIT> ) return ( HII -> changeAddrMode_io_abs ( MI ) >= <NUM_LIT> ) ; return false


<s> for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UA = * I ; NodeAddr < InstrNode * > IA = UA . Addr -> getOwner ( * DFG ) ; if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) return false ; NodeAddr < RefNode * > AA = LV -> getNearestAliasedRef ( LRExtRR , IA ) ; if ( ( DFG -> IsDef ( AA ) && AA . Id != LRExtRegRD ) || AA . Addr -> getReachingDef ( ) != LRExtRegRD ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; return false ; } MachineInstr * UseMI = NodeAddr < StmtNode * > ( IA )


<s> AlignMask = <NUM_LIT> ; break ; case <STR_LIT> :: ByteAccess : AlignMask = <NUM_LIT> ; break ; default : return false ; } if ( ( AlignMask & Offset ) != <NUM_LIT> ) return false ; return HII -> isValidOffset ( MI -> getOpcode ( )


<s> default : return false ; } if ( ( AlignMask & Offset ) != <NUM_LIT> ) return false ; return HII -> isValidOffset ( MI -> getOpcode ( ) , Offset , HRI ,


<s> if ( ( MI -> getOpcode ( ) != <STR_LIT> || ! MI -> getOperand ( <NUM_LIT> ) . isGlobal ( ) ) && ( MI -> getOpcode ( ) != <STR_LIT> || ! MI -> getOperand ( <NUM_LIT> ) . isImm ( ) || HII -> isConstExtended ( * MI ) ) ) continue ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << HII -> getName ( MI -> getOpcode ( ) ) << <STR_LIT> << * MI << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( IA , * DFG ) << '\n' ) ; NodeList UNodeList ; getAllRealUses ( SA , UNodeList ) ; if ( ! allValidCandidates ( SA , UNodeList ) ) continue ; if ( MI -> getOpcode ( ) == <STR_LIT> ) { Changed |= processAddUses ( SA , MI , UNodeList ) ; continue ; } short SizeInc = <NUM_LIT> ; unsigned DefR = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; InstrEvalMap InstrEvalResult ; if ( ! analyzeUses ( DefR , UNodeList , InstrEvalResult , SizeInc ) ) continue ; if ( SizeInc > CodeGrowthLimit ) continue ; bool KeepTfr = false ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << UNodeList . size ( ) << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << printMBBReference ( * UseMI -> getParent ( ) ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; int UseMOnum =


<s> if ( skipFunction ( MF . getFunction ( ) ) ) return false ; bool Changed = false ; auto & HST = MF . getSubtarget < <ISA_LIT>Subtarget > ( ) ; MRI = & MF . getRegInfo ( ) ; HII = HST . getInstrInfo ( ) ; HRI = HST . getRegisterInfo ( ) ; const auto & MDF = getAnalysis < MachineDominanceFrontier > ( ) ; MDT = & getAnalysis < MachineDominatorTree > ( ) ; const TargetOperandInfo TOI ( * HII ) ; DataFlowGraph G ( MF , * HII , * HRI , * MDT , MDF , TOI ) ; G . build ( BuildOptions :: KeepDeadPhis ) ; DFG = & G ; Liveness L ( * MRI , * DFG ) ; L . computePhiInfo ( ) ; LV = & L ; Deleted . clear ( ) ; NodeAddr < FuncNode * > FA = DFG -> getFunc ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < FuncNode * >> ( FA , * DFG ) << <STR_LIT> ) ; for ( NodeAddr < BlockNode * > BA : FA . Addr -> members ( * DFG ) ) Changed |= processBlock ( BA ) ; for ( auto MI : Deleted


<s> const MachineOperand ImmOp = AddMI -> getOperand ( <NUM_LIT> ) ; const MachineOperand AddRegOp = AddMI -> getOperand ( <NUM_LIT> ) ; unsigned newReg = AddRegOp . getReg ( ) ; const MCInstrDesc & MID = UseMI -> getDesc ( ) ; MachineOperand & BaseOp = MID . mayLoad ( ) ? UseMI -> getOperand ( <NUM_LIT> ) : UseMI -> getOperand ( <NUM_LIT> ) ; MachineOperand & OffsetOp = MID . mayLoad ( ) ? UseMI -> getOperand ( <NUM_LIT> ) : UseMI -> getOperand ( <NUM_LIT> ) ; BaseOp . setReg ( newReg ) ; BaseOp . setIsUndef ( AddRegOp . isUndef


<s> bool <ISA_LIT>OptAddrMode :: xformUseMI ( MachineInstr * TfrMI , MachineInstr * UseMI , NodeAddr < UseNode * > UseN , unsigned UseMOnum ) { const MachineOperand ImmOp = TfrMI -> getOperand ( <NUM_LIT> ) ; const MCInstrDesc & MID = UseMI -> getDesc ( ) ; unsigned Changed = false ; if ( MID . mayLoad ( ) ) Changed = changeLoad ( UseMI , ImmOp , UseMOnum ) ; else if ( MID . mayStore ( ) ) Changed = changeStore ( UseMI , ImmOp , UseMOnum ) ; else if ( UseMI -> getOpcode ( ) == <STR_LIT> ) Changed = changeAddAsl ( UseN , UseMI , ImmOp


<s> MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> changeAddrMode_io_abs ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset


<s> Register AddDefR = AddMI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UN = * I ; NodeAddr < StmtNode * > SN = UN . Addr -> getOwner ( * DFG ) ; MachineInstr * MI = SN . Addr -> getCode ( ) ; const MCInstrDesc & MID = MI -> getDesc ( ) ; if ( ( ! MID . mayLoad ( ) && ! MID . mayStore ( ) ) || HII -> getAddrMode ( * MI ) != <STR_LIT> || HII -> isHVXVec ( * MI ) ) return false ; MachineOperand BaseOp = MID . mayLoad ( ) ? MI -> getOperand ( <NUM_LIT> ) : MI -> getOperand ( <NUM_LIT> ) ; if ( ! BaseOp . isReg ( ) || BaseOp . getReg ( ) != AddDefR ) return false ; MachineOperand OffsetOp = MID . mayLoad ( ) ? MI -> getOperand ( <NUM_LIT> ) : MI -> getOperand ( <NUM_LIT> ) ; if ( ! OffsetOp . isImm ( ) ) return false ; int64_t newOffset = OffsetOp . getImm ( ) + AddMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; if ( ! isValidOffset ( MI , newOffset ) ) return false ; Register BaseReg = AddMI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( ! isSafeToExtLR ( AddSN , AddMI , BaseReg , UNodeList ) ) return false ; } bool Changed = false ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( )


<s> if ( ! BaseOp . isReg ( ) || BaseOp . getReg ( ) != AddDefR ) return false ; MachineOperand OffsetOp = MID . mayLoad ( ) ? MI -> getOperand ( <NUM_LIT> ) : MI -> getOperand ( <NUM_LIT> ) ; if ( ! OffsetOp . isImm ( ) ) return false ; int64_t newOffset = OffsetOp . getImm ( ) + AddMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; if ( ! isValidOffset ( MI , newOffset ) ) return false ; Register BaseReg = AddMI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; if ( ! isSafeToExtLR ( AddSN , AddMI , BaseReg , UNodeList ) ) return false ; } bool Changed = false ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; Changed |= updateAddUses ( AddMI , UseMI


<s> if ( ! analyzeUses ( DefR , UNodeList , InstrEvalResult , SizeInc ) ) continue ; if ( SizeInc > CodeGrowthLimit ) continue ; bool KeepTfr = false ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << UNodeList . size ( ) << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << printMBBReference ( * UseMI -> getParent ( ) ) << <STR_LIT> <<


<s> MachineOperand & OffsetOp = MID . mayLoad ( ) ? UseMI -> getOperand ( <NUM_LIT> ) : UseMI -> getOperand ( <NUM_LIT> ) ; BaseOp . setReg ( newReg ) ; BaseOp . setIsUndef ( AddRegOp . isUndef ( ) ) ; BaseOp . setImplicit ( AddRegOp . isImplicit ( ) ) ; OffsetOp . setImm ( ImmOp . getImm ( ) + OffsetOp . getImm ( ) ) ; MRI -> clearKillFlags (


<s> const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } Changed = true ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> changeAddrMode_rr_io ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; OpStart = <NUM_LIT>


<s> auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; short NewOpCode = getBaseWithLongOffset ( * UseMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; unsigned OpStart ; unsigned OpEnd = UseMI -> getNumOperands ( ) ; MachineBasicBlock * BB = UseMI -> getParent ( ) ; MachineInstrBuilder MIB = BuildMI ( * BB , InsertPt , UseMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; if ( UseMID . mayLoad ( ) ) { MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; } else if ( UseMID . mayStore ( ) ) { MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else llvm_unreachable ( <STR_LIT> ) ; for ( unsigned i = OpStart ; i < OpEnd ; ++ i ) MIB . add ( UseMI -> getOperand ( i ) ) ; Deleted . insert ( UseMI


<s> NodeList UNodeList ; getAllRealUses ( SA , UNodeList ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseUN = * I ; assert ( ! ( UseUN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > UseIA = UseUN . Addr -> getOwner ( * DFG ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( UseIA , * DFG ) << <STR_LIT> ) ; MachineInstr * UseMI = UseIA . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; const MCInstrDesc & UseMID = UseMI -> getDesc ( ) ; assert ( HII -> getAddrMode ( * UseMI ) == <STR_LIT> ) ; auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator


<s> assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else Changed = false ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << * MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> changeAddrMode_rr_io ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand


<s> RegisterRef DR = DFG -> getPRI ( ) . normalize ( DA . Addr -> getRegRef ( * DFG ) ) ; auto UseSet = LV -> getAllReachedUses ( DR , DA ) ; for ( auto UI : UseSet ) { NodeAddr < UseNode * > UA = DFG -> addr < UseNode * > ( UI ) ; DEBUG ( { NodeAddr < StmtNode * > TempIA = UA . Addr -> getOwner ( * DFG ) ; dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( TempIA , * DFG ) << <STR_LIT> ; } ) ; if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) { NodeAddr < PhiNode * > PA = UA . Addr -> getOwner ( * DFG ) ; NodeId id = PA . Id ; const Liveness :: RefMap & phiUse = LV -> getRealUses ( id ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < Liveness :: RefMap > ( phiUse , * DFG ) << <STR_LIT> ) ; if ( ! phiUse . empty ( ) ) { for ( auto I : phiUse ) { if ( ! DFG -> getPRI ( ) . alias ( RegisterRef ( I . first ) , DR ) ) continue ; auto phiUseSet = I


<s> DEBUG ( dbgs ( ) << <STR_LIT> << UNodeList . size ( ) << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; int UseMOnum = - <NUM_LIT> ; unsigned NumOperands = UseMI -> getNumOperands ( ) ; for ( unsigned j = <NUM_LIT> ; j < NumOperands - <NUM_LIT> ; ++ j ) { const MachineOperand & op = UseMI


<s> bool <ISA_LIT>OptAddrMode :: runOnMachineFunction ( MachineFunction & MF ) { if ( skipFunction ( * MF . getFunction ( ) ) ) return false ; bool Changed = false ; auto & HST = MF . getSubtarget < <ISA_LIT>Subtarget > ( ) ; auto & MRI = MF . getRegInfo ( ) ; HII = HST . getInstrInfo ( ) ; const auto & MDF = getAnalysis < MachineDominanceFrontier > ( ) ; MDT = & getAnalysis < MachineDominatorTree > ( ) ; const auto & TRI = * MF . getSubtarget ( ) . getRegisterInfo ( ) ; const TargetOperandInfo TOI ( * HII ) ; DataFlowGraph G ( MF , * HII , TRI , * MDT , MDF , TOI ) ; G . build ( BuildOptions :: KeepDeadPhis ) ; DFG = & G ; Liveness L ( MRI , * DFG ) ; L . computePhiInfo ( ) ; LV = & L ; Deleted . clear ( ) ; NodeAddr < FuncNode * > FA = DFG -> getFunc ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < FuncNode * >> ( FA , * DFG ) << <STR_LIT> ) ; for ( NodeAddr < BlockNode * > BA : FA . Addr -> members ( * DFG ) ) Changed |= processBlock ( BA ) ; for ( auto MI : Deleted ) MI -> eraseFromParent ( ) ; if ( Changed ) { G . build (


<s> DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB


<s> unsigned OpEnd = OldMI -> getNumOperands ( ) ; MachineBasicBlock * BB = OldMI -> getParent ( ) ; auto UsePos = MachineBasicBlock :: iterator ( OldMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; ++ InsertPt ; MachineInstrBuilder MIB ; if ( ImmOpNum == <NUM_LIT> ) { if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> getBaseWithLongOffset ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> getAbsoluteForm ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; Changed =


<s> MIB . add ( ImmOp ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> getAbsoluteForm ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI


<s> bool <ISA_LIT>OptAddrMode :: canRemoveAddasl ( NodeAddr < StmtNode * > AddAslSN , MachineInstr & MI , const NodeList & UNodeList ) { const MachineOperand & OffsetOp = MI . getOperand ( <NUM_LIT> ) ; if ( ! OffsetOp . isImm ( ) || OffsetOp . getImm ( ) > <NUM_LIT> ) return false ; unsigned OffsetReg = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; RegisterRef OffsetRR ; NodeId OffsetRegRD = <NUM_LIT> ; for ( NodeAddr < UseNode * > UA : AddAslSN . Addr -> members_if ( DFG -> IsUse , * DFG ) ) { RegisterRef RR = UA . Addr -> getRegRef ( * DFG ) ; if ( OffsetReg == RR . Reg ) { OffsetRR = RR ; OffsetRegRD = UA . Addr -> getReachingDef ( ) ; } } for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UA = * I ; NodeAddr < InstrNode * > IA = UA . Addr -> getOwner ( *


<s> } } for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UA = * I ; NodeAddr < InstrNode * > IA = UA . Addr -> getOwner ( * DFG ) ; if ( ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) || RDefMap [ OffsetRR ] [ IA . Id ] != OffsetRegRD ) return false ; MachineInstr & UseMI = * NodeAddr < StmtNode * > ( IA ) . Addr -> getCode ( ) ; NodeAddr < DefNode * > OffsetRegDN = DFG -> addr < DefNode * > ( OffsetRegRD ) ; if ( ( OffsetRegDN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && MI . getParent ( ) != UseMI . getParent ( ) ) return false ; const MCInstrDesc & UseMID = UseMI . getDesc ( ) ; if ( ( ! UseMID . mayLoad ( ) && ! UseMID . mayStore ( ) ) || HII -> getAddrMode ( UseMI ) != <STR_LIT> || getBaseWithLongOffset ( UseMI ) < <NUM_LIT> ) return false ; if ( UseMID . mayStore ( ) && UseMI . getOperand ( <NUM_LIT> ) . isReg ( ) && UseMI . getOperand ( <NUM_LIT> ) . getReg ( ) == MI . getOperand ( <NUM_LIT> ) . getReg ( ) ) return false ; for ( auto & Mo : UseMI . operands ( ) ) if ( Mo . isFI ( ) ) return false ; } return true


<s> DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < DefNode * >> ( DA , * DFG ) << <STR_LIT> ) ; RegisterRef DR = DFG -> normalizeRef ( DA . Addr -> getRegRef ( * DFG ) ) ; auto UseSet = LV -> getAllReachedUses ( DR , DA ) ; for ( auto UI : UseSet ) { NodeAddr < UseNode * > UA = DFG -> addr < UseNode * > ( UI ) ; DEBUG ( { NodeAddr < StmtNode * > TempIA = UA . Addr -> getOwner ( * DFG ) ; dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( TempIA , * DFG ) << <STR_LIT> ; } ) ; if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) { NodeAddr < PhiNode * > PA = UA . Addr -> getOwner ( * DFG ) ; NodeId id = PA . Id ; const Liveness :: RefMap & phiUse = LV


<s> <ISA_LIT>OptAddrMode ( ) : MachineFunctionPass ( ID ) , HII ( nullptr ) , MDT ( nullptr ) , DFG ( nullptr


<s> <ISA_LIT>OptAddrMode ( ) : MachineFunctionPass ( ID ) , HII ( nullptr ) , MDT ( nullptr ) , DFG (


<s> HII = HST . getInstrInfo ( ) ; const auto & MDF = getAnalysis < MachineDominanceFrontier > ( ) ; MDT = & getAnalysis < MachineDominatorTree > ( ) ; const auto & TRI = * MF . getSubtarget ( ) . getRegisterInfo ( ) ; const TargetOperandInfo TOI ( * HII ) ; DataFlowGraph G ( MF , * HII , TRI , * MDT , MDF , TOI ) ; G . build ( ) ; DFG = & G ; Liveness L ( MRI , * DFG ) ; L . computePhiInfo


<s> void <ISA_LIT>OptAddrMode :: updateMap ( NodeAddr < InstrNode * > IA ) { RegisterSet RRs ; for ( NodeAddr < RefNode * > RA : IA . Addr -> members ( * DFG )

) RRs . insert ( RA . Addr -> getRegRef ( * DFG ) ) ;


<s> Deleted . clear ( ) ; NodeAddr < FuncNode * > FA = DFG -> getFunc ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < FuncNode * >> ( FA , * DFG ) << <STR_LIT> ) ; for ( NodeAddr < BlockNode * > BA : FA . Addr -> members ( * DFG ) ) Changed |= processBlock ( BA ) ; for ( auto MI : Deleted ) MI -> eraseFromParent ( ) ; if ( Changed )


<s> DataFlowGraph G ( MF , * HII , TRI , * MDT , MDF , TOI ) ; G . build ( ) ; DFG = & G ; Liveness L ( MRI , * DFG ) ; L . computePhiInfo ( ) ; LV = & L ; Deleted . clear ( ) ; NodeAddr < FuncNode * > FA = DFG -> getFunc ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < FuncNode * >> ( FA , * DFG ) << <STR_LIT> ) ; for ( NodeAddr < BlockNode * > BA : FA . Addr -> members ( * DFG ) ) Changed |= processBlock ( BA ) ; for ( auto MI : Deleted ) MI -> eraseFromParent ( ) ; if ( Changed ) { G . build ( ) ; L . computeLiveIns ( ) ; L . resetLiveIns (


<s> MIB . add ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> changeAddrMode_io_abs ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else Changed = false ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> changeAddrMode_rr_io (


<s> MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> changeAddrMode_io_abs ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else Changed = false ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> changeAddrMode_rr_io ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * MIB << <STR_LIT> ) ; } if ( Changed ) for ( unsigned i = OpStart ; i < OpEnd ; ++ i ) MIB . add ( OldMI -> getOperand (


<s> const MCInstrDesc & MID = MI -> getDesc ( ) ; switch ( MI -> getOpcode ( ) ) { case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case


<s> RegisterRef LRExtRR ; NodeId LRExtRegRD = <NUM_LIT> ; for ( NodeAddr < UseNode * > UA : SN . Addr -> members_if ( DFG -> IsUse , * DFG ) ) { RegisterRef RR = UA . Addr -> getRegRef ( * DFG ) ; if ( LRExtReg == RR . Reg ) { LRExtRR = RR ; LRExtRegRD = UA . Addr -> getReachingDef ( ) ; } } for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UA = * I ; NodeAddr < InstrNode * > IA = UA . Addr -> getOwner ( * DFG ) ; if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) return false ; NodeAddr < RefNode * > AA = LV -> getNearestAliasedRef ( LRExtRR , IA ) ; if ( ( DFG -> IsDef ( AA ) && AA . Id != LRExtRegRD ) || AA . Addr -> getReachingDef ( ) != LRExtRegRD ) { LLVM_DEBUG ( dbgs (


<s> if ( ! isSafeToExtLR ( AddSN , AddMI , BaseReg , UNodeList ) ) return false ; } NodeId LRExtRegRD = <NUM_LIT> ; for ( NodeAddr < UseNode * > UA : AddSN . Addr -> members_if ( DFG -> IsUse , * DFG ) ) { RegisterRef RR = UA . Addr -> getRegRef ( * DFG ) ; if ( BaseReg == RR . Reg ) LRExtRegRD = UA . Addr -> getReachingDef ( ) ; } bool Changed = false ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << *


<s> const MachineOperand ImmOp = AddMI -> getOperand ( <NUM_LIT> ) ; const MachineOperand AddRegOp = AddMI -> getOperand ( <NUM_LIT> ) ; Register NewReg = AddRegOp . getReg ( ) ; MachineOperand & BaseOp = UseMI -> getOperand ( getBaseOpPosition ( UseMI ) ) ; MachineOperand & OffsetOp = UseMI -> getOperand


<s> MachineOperand & BaseOp = UseMI -> getOperand ( getBaseOpPosition ( UseMI ) ) ; MachineOperand & OffsetOp = UseMI -> getOperand ( getOffsetOpPosition ( UseMI ) ) ; BaseOp . setReg ( NewReg ) ; BaseOp . setIsUndef ( AddRegOp . isUndef ( ) ) ; BaseOp . setImplicit ( AddRegOp . isImplicit ( ) ) ; OffsetOp . setImm ( ImmOp . getImm ( ) + OffsetOp .


<s> NodeList UNodeList ; getAllRealUses ( SA , UNodeList ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseUN = * I ; assert ( ! ( UseUN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > UseIA = UseUN . Addr -> getOwner ( * DFG ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( UseIA , * DFG ) << <STR_LIT> ) ; MachineInstr * UseMI = UseIA . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; const MCInstrDesc & UseMID = UseMI -> getDesc ( ) ; assert ( HII -> getAddrMode ( * UseMI ) == <STR_LIT> ) ; auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; short NewOpCode = getBaseWithLongOffset ( * UseMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; unsigned OpStart ; unsigned OpEnd = UseMI -> getNumOperands ( ) ; MachineBasicBlock * BB = UseMI -> getParent ( ) ; MachineInstrBuilder MIB = BuildMI ( * BB , InsertPt , UseMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; if ( UseMID . mayLoad ( ) ) { MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT>


<s> DFG -> markBlock ( BA . Id , DefM ) ; for ( NodeAddr < InstrNode * > IA : BA . Addr -> members ( * DFG ) ) { updateMap ( IA ) ; DFG -> pushAllDefs ( IA , DefM ) ; } MachineDomTreeNode * N = MDT -> getNode ( B ) ; for ( auto I : * N ) Changed |= constructDefMap (


<s> if ( MI -> getOpcode ( ) != <STR_LIT> || ! MI -> getOperand ( <NUM_LIT> ) . isGlobal ( ) ) continue ; DEBUG ( dbgs ( ) << <STR_LIT> << HII -> getName ( MI -> getOpcode ( ) ) << <STR_LIT> << * MI << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( IA , * DFG ) << '\n' ) ; NodeList UNodeList ; getAllRealUses ( SA , UNodeList ) ; if ( ! allValidCandidates ( SA , UNodeList ) ) continue ; short SizeInc = <NUM_LIT> ; unsigned DefR = MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ; InstrEvalMap InstrEvalResult ; if ( ! analyzeUses ( DefR , UNodeList , InstrEvalResult , SizeInc ) ) continue ; if ( SizeInc > CodeGrowthLimit ) continue ; bool KeepTfr = false ; DEBUG ( dbgs ( ) << <STR_LIT> << UNodeList . size ( ) << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << printMBBReference ( * UseMI -> getParent ( ) ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; int UseMOnum = - <NUM_LIT> ; unsigned NumOperands = UseMI -> getNumOperands ( ) ; for ( unsigned j = <NUM_LIT> ; j < NumOperands - <NUM_LIT> ; ++ j ) { const MachineOperand & op = UseMI -> getOperand


<s> NodeAddr < UseNode * > UN = * I ; NodeAddr < StmtNode * > SN = UN . Addr -> getOwner ( * DFG ) ; MachineInstr * MI = SN . Addr -> getCode ( ) ; const MCInstrDesc & MID = MI -> getDesc ( ) ; if ( ( MID . mayLoad ( ) || MID . mayStore ( ) ) ) { if ( ! hasRepForm ( MI , tfrDefR ) ) { KeepTfr = true ; continue ; } SizeInc ++ ; CanBeReplaced = true ; } else if ( MI -> getOpcode ( ) == <STR_LIT> ) { NodeList AddaslUseList ; DEBUG ( dbgs ( ) << <STR_LIT> << * MI << <STR_LIT> ) ; getAllRealUses ( SN , AddaslUseList ) ; if ( allValidCandidates ( SN , AddaslUseList ) && canRemoveAddasl ( SN , MI , AddaslUseList ) ) { SizeInc += AddaslUseList . size ( ) ; SizeInc -= <NUM_LIT> ; CanBeReplaced =


<s> NodeAddr < UseNode * > UseUN = * I ; assert ( ! ( UseUN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > UseIA = UseUN . Addr -> getOwner ( * DFG ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( UseIA , * DFG ) << <STR_LIT> ) ; MachineInstr * UseMI = UseIA . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; const MCInstrDesc & UseMID = UseMI -> getDesc ( ) ; assert ( HII -> getAddrMode ( UseMI ) == <STR_LIT> ) ; auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; short NewOpCode = getBaseWithLongOffset ( UseMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT>


<s> MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; } else if ( HII -> getAddrMode ( OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> getAbsoluteForm ( OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else Changed = false ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } if ( Changed ) for ( unsigned i = OpStart ; i < OpEnd ; ++ i

) MIB . addOperand ( OldMI -> getOperand ( i ) ) ;


<s> unsigned OpEnd = OldMI -> getNumOperands ( ) ; MachineInstrBuilder MIB ; if ( ImmOpNum == <NUM_LIT> ) { if ( HII -> getAddrMode ( OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> getBaseWithLongOffset ( OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; } else if ( HII -> getAddrMode ( OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> getAbsoluteForm ( OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else Changed = false ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( ImmOp ) ; OpStart = <NUM_LIT> ; Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } if ( Changed ) for ( unsigned i = OpStart ; i < OpEnd ; ++ i ) MIB . addOperand ( OldMI -> getOperand ( i ) ) ; return Changed


<s> short NewOpCode = HII -> getAbsoluteForm ( OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . addOperand ( OldMI ->


<s> short TempOpCode = HII -> getBaseWithRegOffset ( MI ) ; return HII -> getBaseWithLongOffset ( TempOpCode ) ; } else return HII ->


<s> DEBUG ( { NodeAddr < StmtNode * > ReachingIA = RDN . Addr -> getOwner ( * DFG ) ; dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( ReachingIA , * DFG ) << <STR_LIT> ; } ) ; NodeId ReachedID = RDN . Addr -> getReachedDef ( ) ; if ( ! ReachedID ) return ReachedDefMI ; NodeAddr < DefNode * > ReachedDN = DFG -> addr < DefNode * > ( ReachedID ) ; NodeAddr < StmtNode * > ReachedIA = ReachedDN . Addr ->


<s> if ( HasReachingDef ) { NodeAddr < DefNode * > RDN = DFG -> addr < DefNode * > ( RD ) ; DEBUG ( { NodeAddr < StmtNode * > ReachingIA = RDN . Addr -> getOwner ( * DFG ) ; dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( ReachingIA , * DFG ) << <STR_LIT> ; } ) ; NodeId ReachedID = RDN . Addr -> getReachedDef ( ) ; if ( ! ReachedID ) return ReachedDefMI ; NodeAddr < DefNode * > ReachedDN = DFG -> addr < DefNode * > ( ReachedID ) ; NodeAddr < StmtNode * > ReachedIA = ReachedDN . Addr -> getOwner ( * DFG ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( ReachedIA , * DFG ) << <STR_LIT> ) ; ReachedDefMI = ReachedIA . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> <<


<s> MachineOperand StOp = MI -> getOperand ( MI -> getNumOperands ( ) - <NUM_LIT> ) ; if ( StOp . isReg ( ) && StOp . getReg ( ) == TfrDefR ) return false ; } if ( HII -> getAddrMode ( MI ) == <STR_LIT> ) return ( HII -> getBaseWithLongOffset (


<s> assert ( ! ( UseUN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > UseIA = UseUN . Addr -> getOwner ( * DFG ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( UseIA , * DFG ) << <STR_LIT> ) ; MachineInstr * UseMI = UseIA . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << printMBBReference ( * UseMI -> getParent ( ) ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; const MCInstrDesc & UseMID = UseMI -> getDesc ( ) ; assert ( HII -> getAddrMode ( * UseMI ) == <STR_LIT> ) ; auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; short NewOpCode = getBaseWithLongOffset ( * UseMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; unsigned OpStart ; unsigned OpEnd = UseMI -> getNumOperands ( ) ; MachineBasicBlock * BB = UseMI -> getParent ( ) ; MachineInstrBuilder MIB = BuildMI ( * BB , InsertPt , UseMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; if ( UseMID . mayLoad ( ) ) { MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; } else if ( UseMID . mayStore ( ) ) { MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else llvm_unreachable ( <STR_LIT> ) ; for ( unsigned i = OpStart ; i < OpEnd ; ++ i ) MIB . add ( UseMI -> getOperand ( i ) ) ; Deleted . insert (


<s> NodeAddr < StmtNode * > SA = AddAslUN . Addr -> getOwner ( * DFG ) ; DEBUG ( dbgs ( ) << <STR_LIT> << * AddAslMI << <STR_LIT> ) ; NodeList UNodeList ; getAllRealUses ( SA , UNodeList ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseUN = * I ; assert ( ! ( UseUN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > UseIA = UseUN . Addr -> getOwner ( * DFG ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( UseIA , * DFG ) << <STR_LIT> ) ; MachineInstr * UseMI = UseIA . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << printMBBReference ( * UseMI -> getParent ( ) ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; const MCInstrDesc & UseMID = UseMI -> getDesc ( ) ; assert ( HII -> getAddrMode ( * UseMI ) == <STR_LIT> ) ; auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; short NewOpCode = getBaseWithLongOffset ( * UseMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; unsigned OpStart ; unsigned OpEnd = UseMI -> getNumOperands ( ) ; MachineBasicBlock * BB = UseMI -> getParent ( ) ; MachineInstrBuilder MIB = BuildMI ( * BB , InsertPt , UseMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; if ( UseMID . mayLoad ( ) ) { MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; } else if ( UseMID . mayStore ( ) ) { MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . add ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) + ImmOp . getOffset ( ) , ImmOp . getTargetFlags ( ) ) ; MIB . add ( UseMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else llvm_unreachable ( <STR_LIT> ) ; for ( unsigned i = OpStart ; i < OpEnd ; ++ i ) MIB . add ( UseMI -> getOperand ( i ) ) ; Deleted . insert ( UseMI


<s> for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UA = * I ; NodeAddr < InstrNode * > IA = UA . Addr -> getOwner ( * DFG ) ; if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) return false ; NodeAddr < RefNode * > AA = LV -> getNearestAliasedRef ( LRExtRR , IA ) ; if ( ( DFG -> IsDef ( AA ) && AA . Id != LRExtRegRD ) || AA . Addr -> getReachingDef ( ) != LRExtRegRD ) { DEBUG ( dbgs (


<s> NodeAddr < StmtNode * > SN = UN . Addr -> getOwner ( * DFG ) ; MachineInstr * MI = SN . Addr -> getCode ( ) ; const MCInstrDesc & MID = MI -> getDesc ( ) ; if ( ( ! MID . mayLoad ( ) && ! MID . mayStore ( ) ) || HII -> getAddrMode ( * MI ) != <STR_LIT> || HII -> isHVXVec ( * MI ) ) return false ; MachineOperand BaseOp = MID . mayLoad ( ) ? MI -> getOperand ( <NUM_LIT> ) : MI -> getOperand ( <NUM_LIT> ) ; if ( ! BaseOp . isReg ( ) || BaseOp . getReg ( ) != AddDefR ) return false ; MachineOperand OffsetOp = MID . mayLoad ( ) ? MI -> getOperand ( <NUM_LIT> ) : MI -> getOperand ( <NUM_LIT> ) ; if ( ! OffsetOp . isImm ( ) ) return false ; int64_t newOffset = OffsetOp . getImm ( ) + AddMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; if ( ! isValidOffset ( MI , newOffset ) ) return false ; unsigned BaseReg = AddMI -> getOperand ( <NUM_LIT>


<s> DFG = & G ; Liveness L ( * MRI , * DFG ) ; L . computePhiInfo ( ) ; LV = & L ; Deleted . clear ( ) ; NodeAddr < FuncNode * > FA = DFG -> getFunc ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < NodeAddr < FuncNode * >> ( FA , * DFG ) << <STR_LIT> ) ; for ( NodeAddr < BlockNode * > BA : FA . Addr -> members ( * DFG ) ) Changed |= processBlock ( BA ) ; for ( auto MI : Deleted ) MI -> eraseFromParent ( ) ; if (


<s> for ( auto DI : ReachingDefs ) { NodeAddr < UseNode * > DA = DFG -> addr < UseNode * > ( DI ) ; NodeAddr < StmtNode * > TempIA = DA . Addr -> getOwner ( * DFG ) ; dbgs ( ) << <STR_LIT> << Print < NodeAddr < InstrNode * >> ( TempIA , * DFG ) << <STR_LIT> ; } } ) ; return false


<s> NodeAddr < UseNode * > UA = * I ; NodeAddr < InstrNode * > IA = UA . Addr -> getOwner ( * DFG ) ; if ( ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) || RDefMap [ OffsetRR ] [ IA . Id ] != OffsetRegRD ) return false ; MachineInstr & UseMI = * NodeAddr < StmtNode * > ( IA ) . Addr -> getCode ( ) ; NodeAddr < DefNode * > OffsetRegDN = DFG -> addr < DefNode * > ( OffsetRegRD ) ; if ( ( OffsetRegDN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && MI . getParent ( ) != UseMI . getParent ( ) ) return false ; const MCInstrDesc & UseMID = UseMI . getDesc ( ) ; if ( ( ! UseMID . mayLoad ( ) && ! UseMID . mayStore ( ) ) || HII -> getAddrMode ( UseMI ) != <STR_LIT> || getBaseWithLongOffset ( UseMI ) < <NUM_LIT> ) return false ; if ( UseMID . mayStore ( ) && UseMI . getOperand ( <NUM_LIT> ) . isReg ( ) && UseMI . getOperand ( <NUM_LIT> ) . getReg ( ) == MI . getOperand ( <NUM_LIT> ) . getReg ( ) ) return false ; for ( auto & Mo : UseMI . operands ( ) )


<s> const MCInstrDesc & UseMID = UseMI -> getDesc ( ) ; assert ( HII -> getAddrMode ( * UseMI ) == <STR_LIT> ) ; auto UsePos = MachineBasicBlock :: iterator ( UseMI ) ; MachineBasicBlock :: instr_iterator InsertPt = UsePos . getInstrIterator ( ) ; short NewOpCode = getBaseWithLongOffset ( * UseMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; unsigned OpStart ; unsigned OpEnd = UseMI -> getNumOperands ( ) ; MachineBasicBlock * BB = UseMI -> getParent ( ) ; MachineInstrBuilder MIB = BuildMI ( * BB , InsertPt , UseMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; if ( UseMID . mayLoad ( ) ) { MIB . addOperand ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; } else if ( UseMID . mayStore ( ) ) { MIB . addOperand ( AddAslMI -> getOperand


<s> unsigned OpStart ; unsigned OpEnd = UseMI -> getNumOperands ( ) ; MachineBasicBlock * BB = UseMI -> getParent ( ) ; MachineInstrBuilder MIB = BuildMI ( * BB , InsertPt , UseMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; if ( UseMID . mayLoad ( ) ) { MIB . addOperand ( UseMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; MIB . addGlobalAddress ( GV , UseMI -> getOperand ( <NUM_LIT> ) . getImm ( ) , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; } else if ( UseMID . mayStore ( ) ) { MIB . addOperand ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( AddAslMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal


<s> short NewOpCode = HII -> getAbsoluteForm ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; OpStart = <NUM_LIT> ; Changed = true ; } else Changed = false ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( ImmOp ) ; OpStart = <NUM_LIT>


<s> MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; MIB . addOperand ( ImmOp ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } if ( Changed ) for ( unsigned i = OpStart ; i < OpEnd ; ++ i )

MIB . addOperand ( OldMI -> getOperand ( i ) ) ;


<s> MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } else if ( HII -> getAddrMode ( * OldMI ) == <STR_LIT> ) { short NewOpCode = HII -> getAbsoluteForm ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII -> get ( NewOpCode ) ) ; const GlobalValue * GV = ImmOp . getGlobal ( ) ; int64_t Offset = ImmOp . getOffset ( ) + OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) ; MIB . addGlobalAddress ( GV , Offset , ImmOp . getTargetFlags ( ) ) ; MIB . addOperand ( OldMI -> getOperand ( <NUM_LIT> ) ) ; OpStart = <NUM_LIT> ; } Changed = true ; DEBUG ( dbgs ( ) << <STR_LIT> << * OldMI << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> << MIB << <STR_LIT> ) ; } else if ( ImmOpNum == <NUM_LIT> && OldMI -> getOperand ( <NUM_LIT> ) . getImm ( ) == <NUM_LIT> ) { short NewOpCode = HII -> xformRegToImmOffset ( * OldMI ) ; assert ( NewOpCode >= <NUM_LIT> && <STR_LIT> ) ; MIB = BuildMI ( * BB , InsertPt , OldMI -> getDebugLoc ( ) , HII ->


<s> for ( NodeAddr < InstrNode * > IA : BA . Addr -> members ( * DFG ) ) { updateMap ( IA ) ; DFG -> pushDefs ( IA , DefM ) ; } MachineDomTreeNode * N = MDT -> getNode ( B ) ; for ( auto I : * N ) Changed |= constructDefMap ( I -> getBlock ( ) ) ; DFG -> releaseBlock ( BA . Id , DefM ) ; return Changed


<s> } ) ; if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) { NodeAddr < PhiNode * > PA = UA . Addr -> getOwner ( * DFG ) ; NodeId id = PA . Id ; const Liveness :: RefMap & phiUse = LV -> getRealUses ( id ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < Liveness :: RefMap > ( phiUse , * DFG ) << <STR_LIT> ) ; if ( phiUse . size ( ) > <NUM_LIT> ) { for ( auto I : phiUse ) { if ( DR != I . first ) continue ; auto phiUseSet = I . second ; for ( auto phiUI : phiUseSet ) { NodeAddr < UseNode * > phiUA = DFG -> addr < UseNode * > ( phiUI ) ; UNodeList . push_back ( phiUA ) ; } } } } else UNodeList . push_back (


<s> if ( UA . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) { NodeAddr < PhiNode * > PA = UA . Addr -> getOwner ( * DFG ) ; NodeId id = PA . Id ; const Liveness :: RefMap & phiUse = LV -> getRealUses ( id ) ; DEBUG ( dbgs ( ) << <STR_LIT> << Print < Liveness :: RefMap > ( phiUse , * DFG ) << <STR_LIT> ) ; if ( phiUse . size ( ) > <NUM_LIT> ) { for ( auto I : phiUse ) { if ( DR != I . first ) continue ; auto phiUseSet = I . second ; for ( auto phiUI : phiUseSet ) { NodeAddr < UseNode * > phiUA = DFG -> addr <


<s> short <ISA_LIT>OptAddrMode :: getBaseWithLongOffset ( const MachineInstr & MI ) const { if ( HII -> getAddrMode ( MI ) == <STR_LIT> ) { short TempOpCode = HII -> getBaseWithRegOffset ( MI ) ; return HII -> getBaseWithLongOffset ( TempOpCode ) ; } else return HII ->


<s> if ( HII -> getAddrMode ( MI ) == <STR_LIT> ) { short TempOpCode = HII -> getBaseWithRegOffset (


<s> <ISA_LIT>OptAddrMode ( ) : MachineFunctionPass ( ID ) , HII ( <NUM_LIT> ) , MDT ( <NUM_LIT> ) , DFG ( <NUM_LIT> ) , LV ( <NUM_LIT> ) { PassRegistry & R = * PassRegistry :: getPassRegistry ( ) ; initialize<ISA_LIT>OptAddrModePass ( R


<s> for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; int UseMOnum = - <NUM_LIT> ; unsigned NumOperands = UseMI -> getNumOperands ( ) ; for ( unsigned j = <NUM_LIT> ; j < NumOperands - <NUM_LIT> ; ++ j ) { const MachineOperand & op = UseMI -> getOperand ( j ) ; if ( op . isReg ( ) && op . isUse ( ) && DefR == op . getReg ( ) ) UseMOnum = j ; } assert ( UseMOnum >= <NUM_LIT> && <STR_LIT> ) ; if ( InstrEvalResult [ UseMI ] ) Changed |= xformUseMI (


<s> DEBUG ( dbgs ( ) << <STR_LIT> << UNodeList . size ( ) << <STR_LIT> ) ; DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto I = UNodeList . rbegin ( ) , E = UNodeList . rend ( ) ; I != E ; ++ I ) { NodeAddr < UseNode * > UseN = * I ; assert ( ! ( UseN . Addr -> getFlags ( ) & NodeAttrs :: PhiRef ) && <STR_LIT> ) ; NodeAddr < StmtNode * > OwnerN = UseN . Addr -> getOwner ( * DFG ) ; MachineInstr * UseMI = OwnerN . Addr -> getCode ( ) ; DEBUG ( dbgs ( ) << <STR_LIT> << UseMI -> getParent ( ) -> getNumber ( ) << <STR_LIT> << * UseMI << <STR_LIT> ) ; int UseMOnum = - <NUM_LIT> ; unsigned NumOperands = UseMI -> getNumOperands ( ) ; for ( unsigned j = <NUM_LIT> ; j < NumOperands - <NUM_LIT> ; ++ j ) { const MachineOperand & op = UseMI -> getOperand ( j ) ; if ( op . isReg ( ) && op . isUse ( ) && DefR == op . getReg ( ) ) UseMOnum = j ; } assert ( UseMOnum >=


<s> break ; } if ( ! Common ) return ; for ( auto & R : RDefMap ) { auto F = DefM . find ( R . first ) ; if ( F == DefM . end ( ) || F -> second . empty ( ) ) continue ; R . second [ IA . Id ] = F -> second


<s> } if ( ! Common ) return ; for ( auto & R : RDefMap ) { auto F = DefM . find ( R . first ) ; if ( F == DefM . end ( ) || F -> second . empty ( ) ) continue ; R . second [ IA . Id ] = F


<s> FunctionPass * llvm :: create<ISA_LIT>OptimizeSZextends ( ) { return new <ISA_LIT>OptimizeSZextends (


<s> bool <ISA_LIT>OptimizeSZextends :: runOnFunction ( Function & F ) { if ( skipFunction ( F ) ) return false ; unsigned Idx = <NUM_LIT> ; for ( auto & Arg : F . args ( ) ) { if ( F . getAttributes ( ) . hasAttribute ( Idx , Attribute :: SExt ) ) { if ( ! isa < PointerType > ( Arg . getType ( ) ) ) { for ( auto UI = Arg . use_begin ( ) ; UI != Arg . use_end ( ) ; ) { if ( isa < SExtInst > ( * UI ) ) { Instruction * Use = cast < Instruction > ( * UI ) ; SExtInst * SI = new SExtInst ( & Arg , Use -> getType ( ) ) ; assert ( EVT :: getEVT ( SI -> getType ( ) ) == ( EVT :: getEVT ( Use -> getType ( ) ) ) ) ; ++ UI ; Use -> replaceAllUsesWith ( SI ) ; Instruction * First = & F . getEntryBlock ( ) . front ( ) ; SI -> insertBefore ( First ) ; Use -> eraseFromParent ( ) ; } else { ++ UI ; } } } } ++ Idx ; } for ( auto & B : F ) { for ( auto & I : B ) { BinaryOperator * Ashr = dyn_cast < BinaryOperator > ( & I ) ; if ( ! ( Ashr && Ashr -> getOpcode ( ) == Instruction :: AShr


<s> } } ++ Idx ; } for ( auto & B : F ) { for ( auto & I : B ) { BinaryOperator * Ashr = dyn_cast < BinaryOperator > ( & I ) ; if ( ! ( Ashr && Ashr -> getOpcode ( ) == Instruction :: AShr ) ) continue ; Value * AshrOp1 = Ashr -> getOperand ( <NUM_LIT> ) ; ConstantInt * C = dyn_cast < ConstantInt > ( AshrOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; Instruction * Shl = dyn_cast < Instruction > ( Ashr -> getOperand ( <NUM_LIT> ) ) ; if ( ! ( Shl && Shl -> getOpcode ( ) == Instruction :: Shl ) ) continue ; Value * Intr = Shl -> getOperand ( <NUM_LIT> ) ; Value * ShlOp1 = Shl -> getOperand ( <NUM_LIT> ) ; C = dyn_cast < ConstantInt > ( ShlOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; if ( IntrinsicInst * I = dyn_cast < IntrinsicInst > ( Intr ) ) { if ( ! intrinsicAlreadySextended ( I -> getIntrinsicID ( ) ) ) continue ; for ( auto UI = Ashr -> user_begin ( ) , UE = Ashr


<s> Instruction * First = & F . getEntryBlock ( ) . front ( ) ; SI -> insertBefore ( First ) ; Use -> eraseFromParent ( ) ; } } } } ++ Idx ; } for ( auto & B : F ) { for ( auto & I : B ) { BinaryOperator * Ashr = dyn_cast < BinaryOperator > ( & I ) ; if ( ! ( Ashr && Ashr -> getOpcode ( ) == Instruction :: AShr ) ) continue ; Value * AshrOp1 = Ashr -> getOperand ( <NUM_LIT> ) ; ConstantInt * C = dyn_cast < ConstantInt > ( AshrOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; Instruction * Shl = dyn_cast < Instruction > ( Ashr -> getOperand ( <NUM_LIT> ) ) ; if ( ! ( Shl && Shl -> getOpcode ( ) == Instruction :: Shl ) ) continue ; Value * Intr = Shl -> getOperand ( <NUM_LIT> ) ; Value * ShlOp1 = Shl -> getOperand ( <NUM_LIT> ) ; C = dyn_cast < ConstantInt > ( ShlOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; if ( IntrinsicInst * I = dyn_cast < IntrinsicInst > ( Intr ) ) { if ( ! intrinsicAlreadySextended ( I -> getIntrinsicID ( ) ) ) continue ; for ( auto UI = Ashr -> user_begin ( )


<s> void getAnalysisUsage ( AnalysisUsage & AU ) const override { AU . addRequired < MachineFunctionAnalysis > (


<s> AU . addPreserved < MachineFunctionAnalysis > ( ) ; AU . addPreserved < StackProtector > ( ) ; FunctionPass :: getAnalysisUsage ( AU


<s> const char * getPassName ( ) const override { return


<s> Instruction * Use = cast < Instruction > ( * UI ) ; SExtInst * SI = new SExtInst ( & Arg , Use -> getType ( ) ) ; assert ( EVT :: getEVT ( SI -> getType ( ) ) == ( EVT :: getEVT ( Use -> getType ( ) ) ) ) ; ++ UI ; Use -> replaceAllUsesWith ( SI ) ; Instruction * First = & F . getEntryBlock ( ) . front ( ) ; SI -> insertBefore ( First ) ; Use -> eraseFromParent ( ) ; } else { ++ UI ; } } } } ++ Idx ; } for ( auto & B : F ) { for ( auto & I : B ) { BinaryOperator * Ashr = dyn_cast < BinaryOperator > ( & I ) ; if ( ! ( Ashr && Ashr -> getOpcode ( ) == Instruction :: AShr ) ) continue ; Value * AshrOp1 = Ashr -> getOperand ( <NUM_LIT> ) ; ConstantInt * C = dyn_cast < ConstantInt > ( AshrOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; Instruction * Shl = dyn_cast < Instruction > ( Ashr -> getOperand ( <NUM_LIT> ) ) ; if ( ! ( Shl && Shl -> getOpcode ( ) == Instruction :: Shl ) ) continue ; Value * Intr = Shl -> getOperand ( <NUM_LIT> ) ; Value * ShlOp1 = Shl -> getOperand ( <NUM_LIT> ) ; C = dyn_cast < ConstantInt > ( ShlOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; if ( IntrinsicInst * I = dyn_cast < IntrinsicInst > ( Intr ) ) { if ( ! intrinsicAlreadySextended ( I -> getIntrinsicID ( ) ) ) continue ; for ( auto UI = Ashr -> user_begin ( ) , UE = Ashr -> user_end ( ) ; UI != UE ; ++ UI ) { const Use & TheUse = UI


<s> ++ UI ; Use -> replaceAllUsesWith ( SI ) ; Instruction * First = & F . getEntryBlock ( ) . front ( ) ; SI -> insertBefore ( First ) ; Use -> eraseFromParent ( ) ; } else { ++ UI ; } } } } ++ Idx ; } for ( auto & B : F ) { for ( auto & I : B ) { BinaryOperator * Ashr = dyn_cast < BinaryOperator > ( & I ) ; if ( ! ( Ashr && Ashr -> getOpcode ( ) == Instruction :: AShr ) ) continue ; Value * AshrOp1 = Ashr -> getOperand ( <NUM_LIT> ) ; ConstantInt * C = dyn_cast < ConstantInt > ( AshrOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; Instruction * Shl = dyn_cast < Instruction > ( Ashr -> getOperand ( <NUM_LIT> ) ) ; if ( ! ( Shl && Shl -> getOpcode ( ) == Instruction :: Shl ) ) continue ; Value * Intr = Shl -> getOperand ( <NUM_LIT> ) ; Value * ShlOp1 = Shl -> getOperand ( <NUM_LIT> ) ; C = dyn_cast < ConstantInt > ( ShlOp1 ) ; if ( ! ( C && C -> getSExtValue ( ) == <NUM_LIT> ) ) continue ; if ( IntrinsicInst * I = dyn_cast < IntrinsicInst > ( Intr ) ) { if ( ! intrinsicAlreadySextended ( I -> getIntrinsicID ( ) ) ) continue ; for ( auto UI = Ashr -> user_begin ( ) , UE = Ashr -> user_end ( ) ; UI != UE ; ++ UI ) { const Use & TheUse = UI . getUse (


<s> FunctionPass * llvm :: create<ISA_LIT>OptimizeSZExtends (


<s> AU . addRequired < MachineFunctionAnalysis > ( ) ; AU . addPreserved < MachineFunctionAnalysis > ( ) ; MachineFunctionPass :: getAnalysisUsage ( AU


<s> StringRef getPassName ( ) const override { return <STR_LIT>


<s> } if ( ! DisableOptSZExt && MI . isCopy ( ) ) { assert ( MI . getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI . getOperand ( <NUM_LIT> ) ; if ( Src . getSubReg ( ) != <STR_LIT> ) continue ; Register DstReg = Dst . getReg ( ) ; Register SrcReg = Src . getReg ( ) ; if ( Register :: isVirtualRegister ( DstReg ) && Register :: isVirtualRegister ( SrcReg ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( SrcReg ) ) { MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc , false ) ) ; } else { DenseMap < unsigned , std :: pair < unsigned , unsigned > > :: iterator DI = PeepholeDoubleRegsMap . find ( SrcReg ) ; if ( DI != PeepholeDoubleRegsMap . end ( ) ) { std :: pair < unsigned , unsigned > PeepholeSrc = DI -> second ; MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc . first , false , false , false , false , false , false , PeepholeSrc . second ) ) ; } } } } if ( ! DisablePNotP ) { bool Done = false ; if ( QII -> isPredicated ( MI ) ) { MachineOperand & Op0 = MI . getOperand ( <NUM_LIT> ) ; Register Reg0 = Op0 . getReg ( ) ; const TargetRegisterClass * RC0 = MRI -> getRegClass ( Reg0 ) ; if ( RC0 -> getID ( ) == <STR_LIT> ) { if ( Register :: isVirtualRegister ( Reg0 ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( Reg0 ) ) { MI . getOperand ( <NUM_LIT> ) . setReg ( PeepholeSrc ) ; MRI -> clearKillFlags ( PeepholeSrc ) ; int NewOp = QII -> getInvertedPredicatedOpcode ( MI . getOpcode ( ) ) ; MI . setDesc ( QII -> get ( NewOp ) ) ; Done = true ; } } } } if ( ! Done ) { unsigned Op = MI . getOpcode ( ) ; unsigned NewOp = <NUM_LIT> ; unsigned PR = <NUM_LIT> , S1 = <NUM_LIT> , S2 = <NUM_LIT> ; switch ( Op


<s> case MachineOperand :: MO_Immediate : if ( Src . isImm ( ) ) { Dst . setImm ( Src . getImm ( ) ) ; } else if ( Src . isReg ( ) ) { Dst . ChangeToRegister ( Src . getReg ( ) , Src . isDef ( ) , Src . isImplicit ( ) , Src . isKill ( ) , Src . isDead ( ) , Src . isUndef ( ) , Src . isDebug ( ) ) ; }


<s> FunctionPass * llvm :: create<ISA_LIT>Peephole (


<s> <ISA_LIT>Peephole ( ) : MachineFunctionPass ( ID ) { initialize<ISA_LIT>PeepholePass ( * PassRegistry :: getPassRegistry (


<s> MBBb != MBBe ; ++ MBBb ) { MachineBasicBlock * MBB = MBBb ; PeepholeMap . clear ( ) ; PeepholeDoubleRegsMap . clear ( ) ; for ( MachineBasicBlock :: iterator MII = MBB -> begin ( ) ; MII != MBB -> end ( ) ; ++ MII ) { MachineInstr * MI = MII ; if ( ! DisableOptSZExt && MI -> getOpcode ( ) == <STR_LIT> ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI -> getOperand ( <NUM_LIT> ) ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { PeepholeMap [ DstReg ] = SrcReg ; } } if ( ! DisableOptExtTo64 && MI -> getOpcode ( ) == <STR_LIT> ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src1 = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src2 = MI -> getOperand ( <NUM_LIT> ) ; if ( Src1 . getImm ( ) != <NUM_LIT> ) continue ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src2 . getReg ( ) ; PeepholeMap [ DstReg ] = SrcReg ; } if ( MI -> getOpcode ( ) == <STR_LIT> ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src1 = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src2 = MI -> getOperand ( <NUM_LIT> ) ; if ( Src2 . getImm ( ) != <NUM_LIT> ) continue ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src1 . getReg ( ) ; PeepholeDoubleRegsMap [ DstReg ] = std :: make_pair ( * & SrcReg , <NUM_LIT> ) ; } if ( ! DisablePNotP && ( MI -> getOpcode ( ) == <STR_LIT> ) ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI -> getOperand ( <NUM_LIT> ) ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { PeepholeMap [ DstReg ] = SrcReg ; } } if ( ! DisableOptSZExt && MI -> isCopy ( ) ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI -> getOperand ( <NUM_LIT> ) ; if ( Src . getSubReg ( ) != <STR_LIT> ) continue ; unsigned DstReg = Dst


<s> void getAnalysisUsage ( AnalysisUsage & AU ) const { MachineFunctionPass :: getAnalysisUsage ( AU


<s> void getAnalysisUsage ( AnalysisUsage & AU )


<s> unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src1 . getReg ( ) ; PeepholeDoubleRegsMap [ DstReg ] = std :: make_pair ( * & SrcReg , <NUM_LIT> ) ; } if ( ! DisablePNotP && ( MI -> getOpcode ( ) == <STR_LIT> ) ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI -> getOperand ( <NUM_LIT> ) ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { PeepholeMap [ DstReg ] = SrcReg ; } } if ( ! DisableOptSZExt && MI -> isCopy ( ) ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI -> getOperand ( <NUM_LIT> ) ; if ( Src . getSubReg ( ) != <STR_LIT> ) continue ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( SrcReg ) ) { MI -> RemoveOperand ( <NUM_LIT> ) ; MI -> addOperand ( MachineOperand :: CreateReg ( PeepholeSrc , false ) ) ; } else { DenseMap < unsigned , std :: pair < unsigned , unsigned > > :: iterator DI = PeepholeDoubleRegsMap . find ( SrcReg ) ; if ( DI != PeepholeDoubleRegsMap . end ( ) ) { std :: pair < unsigned , unsigned > PeepholeSrc = DI -> second ; MI -> RemoveOperand ( <NUM_LIT> ) ; MI -> addOperand ( MachineOperand :: CreateReg ( PeepholeSrc . first , false , false , false , false , false , false , PeepholeSrc . second ) ) ; } } } } if ( ! DisablePNotP ) { bool Done = false ; if ( QII -> isPredicated ( MI ) ) { MachineOperand & Op0 = MI -> getOperand ( <NUM_LIT> ) ; unsigned Reg0 = Op0 . getReg ( ) ; const TargetRegisterClass * RC0 = MRI -> getRegClass ( Reg0 ) ; if ( RC0 -> getID ( ) == <STR_LIT> ) { if ( TargetRegisterInfo :: isVirtualRegister ( Reg0 ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( Reg0 ) ) { MI -> getOperand ( <NUM_LIT> ) . setReg ( PeepholeSrc ) ; int NewOp = QII -> getInvertedPredicatedOpcode ( MI -> getOpcode ( ) ) ; MI -> setDesc ( QII -> get ( NewOp ) ) ; Done = true ; } } } } if ( ! Done ) { unsigned Op = MI -> getOpcode ( ) ; unsigned NewOp = <NUM_LIT> ; unsigned PR = <NUM_LIT> , S1 = <NUM_LIT> ,


<s> DenseMap < unsigned , unsigned > PeepholeMap ; DenseMap < unsigned , std :: pair < unsigned , unsigned > > PeepholeDoubleRegsMap ; if ( Disable<ISA_LIT>Peephole ) return false ; for ( MachineBasicBlock & MBB : MF ) { PeepholeMap . clear ( ) ; PeepholeDoubleRegsMap . clear ( ) ; for ( MachineInstr & MI : llvm :: make_early_inc_range ( MBB ) ) { if ( ! DisableOptSZExt && MI . getOpcode ( ) == <STR_LIT> ) { assert ( MI . getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI . getOperand ( <NUM_LIT> ) ; Register DstReg = Dst . getReg ( ) ; Register SrcReg = Src . getReg ( ) ; if ( DstReg . isVirtual ( ) && SrcReg . isVirtual ( ) ) { PeepholeMap [ DstReg ] = SrcReg ; } } if ( ! DisableOptExtTo64 && MI . getOpcode ( ) == <STR_LIT> ) { assert ( MI . getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src1 = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src2 = MI . getOperand ( <NUM_LIT> ) ; if ( Src1 . getImm ( ) != <NUM_LIT> ) continue ; Register DstReg = Dst . getReg ( ) ; Register SrcReg = Src2 . getReg ( ) ; PeepholeMap [ DstReg ] = SrcReg ; } if ( MI . getOpcode ( ) == <STR_LIT> ) { assert ( MI . getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src1 = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src2 = MI . getOperand ( <NUM_LIT> ) ; if ( Src2 . getImm ( ) != <NUM_LIT> ) continue ; Register DstReg = Dst . getReg


<s> unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { PeepholeMap [ DstReg ] = SrcReg ; } } if ( ! DisableOptSZExt && MI . isCopy ( ) ) { assert ( MI . getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI . getOperand ( <NUM_LIT> ) ; if ( Src . getSubReg ( ) != <STR_LIT> ) continue ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( SrcReg ) ) { MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc , false ) ) ; } else { DenseMap < unsigned , std :: pair < unsigned , unsigned > > :: iterator DI = PeepholeDoubleRegsMap . find ( SrcReg ) ; if ( DI != PeepholeDoubleRegsMap . end ( ) ) { std :: pair < unsigned , unsigned > PeepholeSrc = DI -> second ; MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc . first , false , false , false , false , false , false , PeepholeSrc . second ) ) ; } } } } if ( ! DisablePNotP ) { bool Done = false ; if ( QII -> isPredicated ( MI ) ) { MachineOperand & Op0 = MI . getOperand ( <NUM_LIT> ) ; unsigned Reg0 = Op0 . getReg ( ) ; const TargetRegisterClass * RC0 = MRI -> getRegClass ( Reg0 ) ; if ( RC0 -> getID ( ) == <STR_LIT> ) { if ( TargetRegisterInfo :: isVirtualRegister ( Reg0 ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( Reg0 ) ) { MI . getOperand ( <NUM_LIT> ) . setReg ( PeepholeSrc ) ; MRI -> clearKillFlags ( PeepholeSrc ) ; int NewOp = QII -> getInvertedPredicatedOpcode ( MI . getOpcode ( ) ) ; MI . setDesc ( QII -> get ( NewOp ) ) ; Done = true ; } } } } if ( ! Done


<s> case MachineOperand :: MO_Immediate : if ( Src . isImm ( ) ) { Dst . setImm ( Src . getImm ( ) ) ; } else if ( Src . isReg ( ) ) { Dst . ChangeToRegister ( Src . getReg ( ) , Src . isDef ( ) , Src . isImplicit ( ) , Src . isKill ( ) , Src . isDead

( ) , Src . isUndef ( ) , Src . isDebug ( ) ) ;


<s> PeepholeMap [ DstReg ] = SrcReg ; } } if ( ! DisableOptSZExt && MI . isCopy ( ) ) { assert ( MI . getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI . getOperand ( <NUM_LIT> ) ; if ( Src . getSubReg ( ) != <STR_LIT> ) continue ; Register DstReg = Dst . getReg ( ) ; Register SrcReg = Src . getReg ( ) ; if ( DstReg . isVirtual ( ) && SrcReg . isVirtual ( ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( SrcReg ) ) { MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc , false ) ) ; } else { DenseMap < unsigned , std :: pair < unsigned , unsigned > > :: iterator DI = PeepholeDoubleRegsMap . find ( SrcReg ) ; if ( DI != PeepholeDoubleRegsMap . end ( ) ) { std :: pair < unsigned , unsigned > PeepholeSrc = DI -> second ; MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc . first , false , false , false , false , false , false , PeepholeSrc . second ) ) ; } } } } if ( ! DisablePNotP ) { bool Done = false ; if ( QII -> isPredicated ( MI ) ) { MachineOperand & Op0 = MI . getOperand ( <NUM_LIT> ) ; Register Reg0 = Op0 . getReg ( ) ; const TargetRegisterClass * RC0 = MRI -> getRegClass ( Reg0 ) ; if ( RC0 -> getID ( ) == <STR_LIT> ) { if ( Reg0 . isVirtual ( ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( Reg0 ) ) { MI . getOperand ( <NUM_LIT> ) . setReg ( PeepholeSrc ) ; MRI -> clearKillFlags ( PeepholeSrc ) ; int NewOp = QII -> getInvertedPredicatedOpcode ( MI . getOpcode ( ) ) ; MI . setDesc ( QII -> get ( NewOp ) ) ; Done = true ; } } } } if ( ! Done ) { unsigned Op = MI . getOpcode ( ) ; unsigned NewOp = <NUM_LIT> ; unsigned PR = <NUM_LIT> , S1 = <NUM_LIT>


<s> switch ( Dst . getType ( ) ) { case MachineOperand :: MO_Register : if ( Src . isReg ( ) ) { Dst . setReg ( Src . getReg ( ) ) ; Dst . setSubReg ( Src . getSubReg ( ) ) ; MRI -> clearKillFlags ( Src . getReg ( ) ) ; } else if ( Src . isImm ( ) ) { Dst . ChangeToImmediate ( Src . getImm ( ) ) ; } else { llvm_unreachable ( <STR_LIT> ) ; } break ; case MachineOperand :: MO_Immediate : if ( Src . isImm


<s> if ( ! DisableOptSZExt && MI . isCopy ( ) ) { assert ( MI . getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI . getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI . getOperand ( <NUM_LIT> ) ; if ( Src . getSubReg ( ) != <STR_LIT> ) continue ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( SrcReg ) ) { MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc , false ) ) ; } else { DenseMap < unsigned , std :: pair < unsigned , unsigned > > :: iterator DI = PeepholeDoubleRegsMap . find ( SrcReg ) ; if ( DI != PeepholeDoubleRegsMap . end ( ) ) { std :: pair < unsigned , unsigned > PeepholeSrc = DI -> second ; MI . RemoveOperand ( <NUM_LIT> ) ; MI . addOperand ( MachineOperand :: CreateReg ( PeepholeSrc . first , false , false , false , false , false , false , PeepholeSrc . second ) ) ; } } } } if ( ! DisablePNotP ) { bool Done = false ; if ( QII -> isPredicated ( MI ) ) { MachineOperand & Op0 = MI . getOperand ( <NUM_LIT> ) ; unsigned Reg0 = Op0 . getReg ( ) ; const TargetRegisterClass * RC0 = MRI -> getRegClass ( Reg0 ) ; if ( RC0 -> getID ( ) == <STR_LIT> ) { if ( TargetRegisterInfo :: isVirtualRegister ( Reg0 ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( Reg0 ) ) { MI . getOperand ( <NUM_LIT> ) . setReg ( PeepholeSrc ) ; MRI -> clearKillFlags ( PeepholeSrc ) ; int NewOp = QII -> getInvertedPredicatedOpcode ( MI . getOpcode ( ) ) ; MI . setDesc ( QII -> get ( NewOp ) ) ; Done = true ; } } } } if ( ! Done ) { unsigned Op = MI . getOpcode ( ) ; unsigned NewOp = <NUM_LIT> ; unsigned PR = <NUM_LIT> , S1 = <NUM_LIT> , S2 = <NUM_LIT> ; switch ( Op ) { case <STR_LIT> : case <STR_LIT> : NewOp = Op ; break ; case <STR_LIT>


<s> unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src1 . getReg ( ) ; PeepholeDoubleRegsMap [ DstReg ] = std :: make_pair ( * & SrcReg , <STR_LIT> ) ; } if ( ! DisablePNotP && ( MI -> getOpcode ( ) == <STR_LIT> ) ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI -> getOperand ( <NUM_LIT> ) ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { PeepholeMap [ DstReg ] = SrcReg ; } } if ( ! DisableOptSZExt && MI -> isCopy ( ) ) { assert ( MI -> getNumOperands ( ) == <NUM_LIT> ) ; MachineOperand & Dst = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand & Src = MI -> getOperand ( <NUM_LIT> ) ; if ( Src . getSubReg ( ) != <STR_LIT> ) continue ; unsigned DstReg = Dst . getReg ( ) ; unsigned SrcReg = Src . getReg ( ) ; if ( TargetRegisterInfo :: isVirtualRegister ( DstReg ) && TargetRegisterInfo :: isVirtualRegister ( SrcReg ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( SrcReg ) ) { MI -> RemoveOperand ( <NUM_LIT> ) ; MI -> addOperand ( MachineOperand :: CreateReg ( PeepholeSrc , false ) ) ; } else { DenseMap < unsigned , std :: pair < unsigned , unsigned > > :: iterator DI = PeepholeDoubleRegsMap . find ( SrcReg ) ; if ( DI != PeepholeDoubleRegsMap . end ( ) ) { std :: pair < unsigned , unsigned > PeepholeSrc = DI -> second ; MI -> RemoveOperand ( <NUM_LIT> ) ; MI -> addOperand ( MachineOperand :: CreateReg ( PeepholeSrc . first , false , false , false , false , false , false , PeepholeSrc . second ) ) ; } } } } if ( ! DisablePNotP ) { bool Done = false ; if ( QII -> isPredicated ( * MI ) ) { MachineOperand & Op0 = MI -> getOperand ( <NUM_LIT> ) ; unsigned Reg0 = Op0 . getReg ( ) ; const TargetRegisterClass * RC0 = MRI -> getRegClass ( Reg0 ) ; if ( RC0 -> getID ( ) == <STR_LIT> ) { if ( TargetRegisterInfo :: isVirtualRegister ( Reg0 ) ) { if ( unsigned PeepholeSrc = PeepholeMap . lookup ( Reg0 ) ) { MI -> getOperand ( <NUM_LIT> ) . setReg ( PeepholeSrc ) ; int NewOp = QII -> getInvertedPredicatedOpcode ( MI -> getOpcode ( ) ) ; MI -> setDesc ( QII -> get ( NewOp ) ) ; Done = true ; } } } } if ( ! Done