<s> case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitLoadStoreInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitMiscLoadStoreInstruction ( MI , <STR_LIT> ) ; break ; } case <STR_LIT> : emitMOVi2piecesInstruction ( MI ) ; break ; case <STR_LIT> : emitLEApcrelJTInstruction ( MI ) ; break ; case <STR_LIT> :


<s> Binary |= getAddrModeUPBits ( <STR_LIT> ( MO . getImm ( ) ) ) ; if ( <STR_LIT> ( MO . getImm ( ) ) ) Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= encodeVFPRd ( MI , OpIdx + <NUM_LIT> ) ; unsigned NumRegs = <NUM_LIT> ; for ( unsigned i = OpIdx + <NUM_LIT> , e = MI . getNumOperands ( ) ; i != e ; ++ i ) { const MachineOperand & MO = MI . getOperand ( i ) ; if ( ! MO . isReg ( ) || MO . isImplicit ( ) ) break ; ++ NumRegs ; }


<s> errs ( ) << <STR_LIT> << CPI << <STR_LIT> << ( void * ) MCE . getCurrentPCValue ( ) << <STR_LIT> ; if ( const Function * F = dyn_cast < Function > ( C ) ) errs ( ) << F -> getName ( ) ; else errs ( ) << * C ; errs ( ) << '\n' ; } ) ; switch ( C -> getValueID ( ) ) { default : { llvm_unreachable ( <STR_LIT> ) ; break ; } case Value :: GlobalVariableVal : { emitGlobalAddress ( static_cast < const GlobalValue * > ( C ) , <STR_LIT> , isa < Function > ( C ) , false ) ; emitWordLE ( <NUM_LIT> ) ; break ; } case Value :: ConstantIntVal : { const ConstantInt * CI = static_cast < const ConstantInt * > ( C ) ; uint32_t Val = * ( uint32_t * ) CI -> getValue ( ) . getRawData ( ) ;


<s> return ; } Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getAddrModeSBit ( MI , MCID ) ; unsigned NumDefs = MCID . getNumDefs ( ) ; unsigned OpIdx = <NUM_LIT> ; if ( NumDefs ) Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; else if ( ImplicitRd ) Binary |= ( get<ISA_LIT>RegisterNumbering ( ImplicitRd ) << <STR_LIT> ) ; if ( MCID . Opcode == <STR_LIT> ) { unsigned Lo16 = getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) ; Binary |= Lo16 & <NUM_LIT> ; Binary |= ( ( Lo16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( MCID . Opcode == <STR_LIT> ) { unsigned Hi16 = ( getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) >> <NUM_LIT> ) ; Binary |= Hi16 & <NUM_LIT> ; Binary |= ( ( Hi16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) { uint32_t v = ~ MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; int32_t lsb = CountTrailingZeros_32 ( v ) ; int32_t msb = ( <NUM_LIT> - CountLeadingZeros_32 ( v ) ) - <NUM_LIT> ; Binary |= ( msb & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) { Binary |= getMachineOpValue ( MI , OpIdx ++ ) ; uint32_t lsb = MI . getOperand ( OpIdx ++ ) . getImm ( ) ; uint32_t widthm1 = MI . getOperand ( OpIdx ++ ) . getImm ( ) - <NUM_LIT> ; Binary |= ( widthm1 & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; bool isUnary = MCID . TSFlags & <STR_LIT> ; if ( ! isUnary ) { if ( ImplicitRn ) Binary |= ( get<ISA_LIT>RegisterNumbering ( ImplicitRn ) << <STR_LIT> ) ; else { Binary |= getMachineOpValue ( MI , OpIdx ) << <STR_LIT> ; ++ OpIdx ; } }

const MachineOperand & MO = MI . getOperand ( OpIdx ) ;


<s> } else if ( MCID . Opcode == <STR_LIT> ) { unsigned Hi16 = ( getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) >> <NUM_LIT> ) ; Binary |= Hi16 & <NUM_LIT> ; Binary |= ( ( Hi16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) { uint32_t v = ~ MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; int32_t lsb = CountTrailingZeros_32 ( v ) ; int32_t msb = ( <NUM_LIT> - CountLeadingZeros_32 ( v ) ) - <NUM_LIT> ; Binary |= ( msb & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) { Binary |= getMachineOpValue ( MI , OpIdx ++ ) ; uint32_t lsb = MI . getOperand ( OpIdx ++ ) . getImm ( ) ; uint32_t widthm1 = MI . getOperand ( OpIdx ++ ) . getImm ( ) - <NUM_LIT> ; Binary |= ( widthm1 & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; bool isUnary = MCID . TSFlags & <STR_LIT> ; if ( ! isUnary ) { if ( ImplicitRn ) Binary |= ( get<ISA_LIT>RegisterNumbering ( ImplicitRn ) << <STR_LIT> ) ; else { Binary |= getMachineOpValue ( MI , OpIdx ) << <STR_LIT> ; ++ OpIdx ; } } const MachineOperand & MO = MI . getOperand ( OpIdx ) ; if ( ( MCID . TSFlags & <STR_LIT> ) == <STR_LIT> ) { emitWordLE ( Binary | getMachineSoRegOpValue ( MI , MCID , MO , OpIdx ) ) ; return ; } if ( MO . isReg ( ) ) {

emitWordLE ( Binary | get<ISA_LIT>RegisterNumbering ( MO . getReg ( ) ) ) ;


<s> break ; case <STR_LIT> : emitPseudoInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitDataProcessingInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitLoadStoreInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitMiscLoadStoreInstruction ( MI ) ; break ; case <STR_LIT> : emitLoadStoreMultipleInstruction ( MI ) ; break ; case <STR_LIT> : emitMulFrmInstruction ( MI ) ; break ; case <STR_LIT> : emitExtendInstruction ( MI ) ; break ; case <STR_LIT> : emitMiscArithInstruction ( MI ) ; break ; case <STR_LIT> : emitSaturateInstruction ( MI ) ; break ; case <STR_LIT> : emitBranchInstruction ( MI ) ; break ; case <STR_LIT> : emitMiscBranchInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitVFPArithInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : emitVFPConversionInstruction ( MI ) ; break ; case <STR_LIT> : emitVFPLoadStoreInstruction ( MI ) ; break ; case <STR_LIT> : emitVFPLoadStoreMultipleInstruction ( MI ) ; break ; case <STR_LIT> : emitMiscInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitNEONLaneInstruction ( MI ) ; break ; case <STR_LIT> : emitNEONDupInstruction ( MI ) ; break ; case <STR_LIT> : emitNEON1RegModImmInstruction ( MI ) ; break ; case <STR_LIT> : emitNEON2RegInstruction ( MI ) ; break ; case <STR_LIT> : emitNEON3RegInstruction ( MI ) ; break ;


<s> void <ISA_LIT>CodeEmitter :: emitLEApcrelInstruction ( const MachineInstr & MI ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; unsigned Binary = <NUM_LIT> ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ;

Binary |= getAddrModeSBit ( MI , MCID ) ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; unsigned OpIdx = <NUM_LIT> ; bool Skipped = false ; if ( IsPrePost && Form == <STR_LIT> ) { ++ OpIdx ; Skipped = true ; } if ( ImplicitRd ) Binary |= ( get<ISA_LIT>RegisterNumbering ( ImplicitRd ) << <STR_LIT> ) ; else Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; if ( ImplicitRn ) Binary |= ( get<ISA_LIT>RegisterNumbering ( ImplicitRn ) << <STR_LIT> ) ; else Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; if ( ! Skipped && MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; const MachineOperand & MO2 = MI . getOperand ( OpIdx ) ; unsigned AM2Opc = ( ImplicitRn == <STR_LIT> ) ? <NUM_LIT> : MI . getOperand ( OpIdx + <NUM_LIT> ) . getImm ( ) ; Binary |= ( ( <STR_LIT> ( AM2Opc ) == <STR_LIT> ? <NUM_LIT> : <NUM_LIT> ) << <STR_LIT> ) ; if ( ! MO2 . getReg ( ) ) {

if ( <STR_LIT> ( AM2Opc ) ) Binary |= <STR_LIT> ( AM2Opc ) ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; emitWordLE ( Binary ) ; emitMiscBranchInstruction ( MI ) ; break ; } case TargetOpcode :: INLINEASM : { if ( MI . getOperand ( <NUM_LIT> ) . getSymbolName ( ) [ <NUM_LIT> ] ) { report_fatal_error ( <STR_LIT> ) ; } break ; } case TargetOpcode :: PROLOG_LABEL : case TargetOpcode :: EH_LABEL : MCE . emitLabel ( MI . getOperand ( <NUM_LIT> ) . getMCSymbol ( ) ) ; break ; case TargetOpcode :: IMPLICIT_DEF : case TargetOpcode :: KILL : break ; case <STR_LIT> : emitConstPoolInstruction ( MI ) ; break ; case <STR_LIT> : emitLoadStoreMultipleInstruction ( MI ) ; break ; case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitDataProcessingInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitLoadStoreInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitMiscLoadStoreInstruction ( MI , <STR_LIT> ) ;


<s> unsigned RegD = MI . getOperand ( OpIdx ) . getReg ( ) ; unsigned Binary = <NUM_LIT> ; bool isSPVFP = <STR_LIT> -> contains ( RegD ) ; RegD = get<ISA_LIT>RegisterNumbering ( RegD ) ; if ( ! isSPVFP ) { Binary |= ( RegD & <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ( RegD & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; } else { Binary |= ( ( RegD & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ;


<s> static unsigned encodeVFPRm ( const MachineInstr & MI , unsigned OpIdx ) { unsigned RegM = MI . getOperand ( OpIdx ) . getReg ( ) ; unsigned Binary = <NUM_LIT> ; bool isSPVFP = <STR_LIT> -> contains ( RegM ) ; RegM = get<ISA_LIT>RegisterNumbering ( RegM ) ; if ( ! isSPVFP ) { Binary |= ( RegM & <NUM_LIT> ) ;

Binary |= ( ( RegM & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ;


<s> RegN = get<ISA_LIT>RegisterNumbering ( RegN ) ; if ( ! isSPVFP ) { Binary |= ( RegN & <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ( RegN & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; } else { Binary |= ( ( RegN & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; Binary |= ( RegN & <NUM_LIT> ) << <STR_LIT> ;


<s> uint32_t Binary = <NUM_LIT> ; const MachineOperand & MO = MI . getOperand ( Op ) ; uint32_t Reg = getMachineOpValue ( MI , MO ) ; Binary |= ( Reg << <NUM_LIT> ) ; if ( MO . isReg ( ) ) { const MachineOperand & MO1 = MI . getOperand ( Op + <NUM_LIT> ) ; if ( uint32_t ImmOffs = <STR_LIT> ( MO1 . getImm ( ) ) ) { if ( <STR_LIT> ( MO1 . getImm ( ) ) == <STR_LIT> ) Binary |= <NUM_LIT> << <NUM_LIT> ; Binary |= ImmOffs & <NUM_LIT> ;


<s> else if ( MO . isImm ( ) ) return static_cast < unsigned > ( MO . getImm ( ) ) ; else if ( MO . isFPImm ( ) ) return static_cast < unsigned > ( MO . getFPImm ( ) -> getValueAPF ( ) . bitcastToAPInt ( ) . getHiBits ( <NUM_LIT> ) . getLimitedValue ( ) ) ; else if ( MO . isGlobal ( ) ) emitGlobalAddress ( MO . getGlobal ( ) , <STR_LIT> , true , false ) ; else if ( MO . isSymbol ( ) ) emitExternalSymbolAddress ( MO . getSymbolName ( ) , <STR_LIT> ) ; else if ( MO . isCPI ( ) ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; unsigned Reloc = ( ( MCID . TSFlags & <STR_LIT> ) == <STR_LIT> ) ? <STR_LIT> : <STR_LIT> ;

emitConstPoolAddress ( MO . getIndex ( ) , Reloc ) ;


<s> return ; } else if ( MCID . Opcode == <STR_LIT> ) { unsigned Hi16 = ( getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) >> <NUM_LIT> ) ; Binary |= Hi16 & <NUM_LIT> ; Binary |= ( ( Hi16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) { uint32_t v = ~ MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; int32_t lsb = countTrailingZeros ( v ) ; int32_t msb = ( <NUM_LIT> - countLeadingZeros ( v ) ) - <NUM_LIT> ; Binary |= ( msb & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) { Binary |= getMachineOpValue ( MI , OpIdx ++ ) ; uint32_t lsb = MI . getOperand ( OpIdx ++ ) . getImm ( ) ; uint32_t widthm1 = MI . getOperand ( OpIdx ++ ) . getImm ( ) - <NUM_LIT> ; Binary |= ( widthm1 & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ;

bool isUnary = MCID . TSFlags & <STR_LIT> ;


<s> const MCInstrDesc & MCID = MI . getDesc ( ) ; unsigned Binary = getBinaryCodeForInstr ( MI ) ; if ( MCID . Opcode == <STR_LIT> || MCID . Opcode == <STR_LIT> ) { emitWordLE ( Binary ) ; return ; } Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getAddrModeSBit ( MI , MCID ) ; unsigned NumDefs = MCID . getNumDefs ( ) ; unsigned OpIdx = <NUM_LIT> ; if ( NumDefs ) Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; else if ( ImplicitRd ) Binary |= ( II -> getRegisterInfo ( ) . getEncodingValue ( ImplicitRd ) << <STR_LIT> ) ; if ( MCID . Opcode == <STR_LIT> ) { unsigned Lo16 = getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) ; Binary |= Lo16 & <NUM_LIT> ; Binary |= ( ( Lo16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( MCID . Opcode == <STR_LIT> ) { unsigned Hi16 = ( getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) >> <NUM_LIT> ) ; Binary |= Hi16 & <NUM_LIT> ; Binary |= ( ( Hi16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) {

uint32_t v = ~ MI . getOperand ( <NUM_LIT> ) . getImm ( ) ;


<s> const TargetInstrDesc & TID = MI . getDesc ( ) ; unsigned Binary = getBinaryCodeForInstr ( MI ) ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getAddrModeSBit ( MI , TID ) ; unsigned NumDefs = TID . getNumDefs ( ) ; unsigned OpIdx = <NUM_LIT> ; if ( NumDefs ) Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; else if ( ImplicitRd ) Binary |= ( <ISA_LIT>RegisterInfo :: getRegisterNumbering ( ImplicitRd ) << <STR_LIT> ) ; if ( TID . Opcode == <STR_LIT> ) { unsigned Lo16 = getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) ; Binary |= Lo16 & <NUM_LIT> ; Binary |= ( ( Lo16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( TID . Opcode == <STR_LIT> ) { unsigned Hi16 = ( getMovi32Value ( MI , MI . getOperand ( OpIdx ) , <STR_LIT> ) >> <NUM_LIT> ) ; Binary |= Hi16 & <NUM_LIT> ; Binary |= ( ( Hi16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ;


<s> default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : break ; case <STR_LIT> : case <STR_LIT> : { const MachineOperand & MO0 = MI . getOperand ( <NUM_LIT> ) ; Binary |= <ISA_LIT>RegisterInfo :: getRegisterNumbering ( MO0 . getReg ( ) ) << <STR_LIT> ; break ; } case <STR_LIT> : case <STR_LIT> : { Binary |= encodeVFPRd ( MI , <NUM_LIT> ) ; const MachineOperand & MO1 = MI . getOperand ( <NUM_LIT> ) ; unsigned Imm = static_cast < unsigned > ( MO1 . getFPImm ( ) -> getValueAPF ( ) . bitcastToAPInt ( ) . getHiBits ( <NUM_LIT> ) . getLimitedValue ( ) ) ; unsigned ModifiedImm ; if ( Opcode == <STR_LIT> ) ModifiedImm = ( Imm & <NUM_LIT> ) >> <NUM_LIT> | ( Imm & <NUM_LIT> ) >> <NUM_LIT> ; else ModifiedImm = ( Imm & <NUM_LIT> ) >> <NUM_LIT> | ( Imm & <NUM_LIT> ) >> <NUM_LIT> ; Binary |= ( ( ModifiedImm & <NUM_LIT> ) >> <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( ModifiedImm & <NUM_LIT> ) ; break ; } } emitWordLE ( Binary ) ;


<s> void <ISA_LIT>CodeEmitter :: emitNEONDupInstruction ( const MachineInstr & MI ) { unsigned Binary = getBinaryCodeForInstr ( MI ) ; Binary |= ( IsThumb ? <STR_LIT> : II -> getPredicate ( & MI ) ) << <STR_LIT> ; unsigned RegT = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ; RegT = <ISA_LIT>RegisterInfo :: getRegisterNumbering ( RegT ) ;


<s> RegT = <ISA_LIT>RegisterInfo :: getRegisterNumbering ( RegT ) ; Binary |= ( RegT << <STR_LIT> ) ; Binary |= encodeNEONRn ( MI , <NUM_LIT> ) ; emitWordLE ( Binary ) ;


<s> RegTOpIdx = <NUM_LIT> ; RegNOpIdx = <NUM_LIT> ; LnOpIdx = <NUM_LIT> ; } else { RegTOpIdx = <NUM_LIT> ; RegNOpIdx = <NUM_LIT> ; LnOpIdx = <NUM_LIT> ; } Binary |= ( IsThumb ? <STR_LIT> : II -> getPredicate ( & MI ) ) << <STR_LIT> ; unsigned RegT = MI . getOperand ( RegTOpIdx ) . getReg ( ) ; RegT = <ISA_LIT>RegisterInfo :: getRegisterNumbering ( RegT ) ; Binary |= ( RegT << <STR_LIT> ) ; Binary |= encodeNEONRn ( MI , RegNOpIdx ) ; unsigned LaneShift ; if ( ( Binary & ( <NUM_LIT> << <NUM_LIT> ) ) != <NUM_LIT> ) LaneShift = <NUM_LIT> ; else if ( ( Binary & ( <NUM_LIT> << <NUM_LIT> ) ) != <NUM_LIT> ) LaneShift = <NUM_LIT> ; else LaneShift = <NUM_LIT> ; unsigned Lane = MI . getOperand ( LnOpIdx ) . getImm ( ) << LaneShift ; unsigned Opc1 = Lane >> <NUM_LIT> ; unsigned Opc2 = Lane & <NUM_LIT> ; assert ( ( Opc1 & <NUM_LIT> ) == <NUM_LIT> && <STR_LIT> ) ;


<s> RegTOpIdx = <NUM_LIT> ; RegNOpIdx = <NUM_LIT> ; LnOpIdx = <NUM_LIT> ; } Binary |= ( IsThumb ? <STR_LIT> : II -> getPredicate ( & MI ) ) << <STR_LIT> ; unsigned RegT = MI . getOperand ( RegTOpIdx ) . getReg ( ) ; RegT = <ISA_LIT>RegisterInfo :: getRegisterNumbering ( RegT ) ; Binary |= ( RegT << <STR_LIT> ) ; Binary |= encodeNEONRn ( MI , RegNOpIdx ) ; unsigned LaneShift ; if ( ( Binary & ( <NUM_LIT> << <NUM_LIT> ) ) != <NUM_LIT> ) LaneShift = <NUM_LIT> ; else if ( ( Binary & ( <NUM_LIT> << <NUM_LIT> ) ) != <NUM_LIT> ) LaneShift = <NUM_LIT> ; else LaneShift = <NUM_LIT> ; unsigned Lane = MI . getOperand ( LnOpIdx ) . getImm ( ) << LaneShift ; unsigned Opc1 = Lane >> <NUM_LIT> ; unsigned Opc2 = Lane & <NUM_LIT> ;

assert ( ( Opc1 & <NUM_LIT> ) == <NUM_LIT> && <STR_LIT> ) ;


<s> case TargetOpcode :: IMPLICIT_DEF : case TargetOpcode :: KILL : break ; case <STR_LIT> : emitConstPoolInstruction ( MI ) ; break ; case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitDataProcessingInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitLoadStoreInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitMiscLoadStoreInstruction ( MI , <STR_LIT> ) ; break ; } case <STR_LIT> : emitMOVi32immInstruction ( MI ) ; break ; case <STR_LIT> : emitMOVi2piecesInstruction ( MI ) ; break ; case <STR_LIT> : emitLEApcrelJTInstruction ( MI ) ; break ;


<s> unsigned OpIdx = <NUM_LIT> ; if ( IsUpdating ) ++ OpIdx ; Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; const MachineOperand & MO = MI . getOperand ( OpIdx ++ ) ; Binary |= getAddrModeUPBits ( <STR_LIT> ( MO . getImm ( ) ) ) ; if ( IsUpdating ) Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= encodeVFPRd ( MI , OpIdx + <NUM_LIT> ) ; unsigned NumRegs = <NUM_LIT> ; for ( unsigned i = OpIdx + <NUM_LIT> , e = MI . getNumOperands ( ) ; i != e ; ++ i ) { const MachineOperand & MO = MI . getOperand ( i ) ; if ( ! MO . isReg ( ) || MO . isImplicit ( ) ) break ; ++ NumRegs ; } if ( Binary & <NUM_LIT> ) Binary |= NumRegs * <NUM_LIT> ; else Binary |= NumRegs ;


<s> Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; const MachineOperand & MO = MI . getOperand ( OpIdx ++ ) ; Binary |= getAddrModeUPBits ( <STR_LIT> ( MO . getImm ( ) ) ) ; if ( IsUpdating ) Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= encodeVFPRd ( MI , OpIdx + <NUM_LIT> ) ; unsigned NumRegs = <NUM_LIT> ; for ( unsigned i = OpIdx + <NUM_LIT> , e = MI . getNumOperands ( ) ; i != e ; ++ i ) {

const MachineOperand & MO = MI . getOperand ( i ) ;


<s> Binary |= ( RegD & <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ( RegD >> <NUM_LIT> ) & <NUM_LIT> ) << <STR_LIT> ; return Binary ;


<s> unsigned RegN = MI . getOperand ( OpIdx ) . getReg ( ) ; unsigned Binary = <NUM_LIT> ; RegN = <ISA_LIT>RegisterInfo :: getRegisterNumbering ( RegN ) ;

Binary |= ( RegN & <NUM_LIT> ) << <STR_LIT> ;


<s> FunctionPass * create<ISA_LIT>CodeEmitterPass ( <ISA_LIT>TargetMachine & TM , MachineCodeEmitter & MCE ) { return new Emitter < MachineCodeEmitter > ( TM , MCE ) ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) ; emitWordLE ( Binary ) ;


<s> void Emitter < CodeEmitter > :: emitBranchInstruction ( const MachineInstr & MI ) { const TargetInstrDesc & TID = MI . getDesc ( ) ; if ( TID . Opcode == <STR_LIT> ) abort ( ) ;

unsigned Binary = getBinaryCodeForInstr ( MI ) ;


<s> const MachineConstantPoolEntry & MCPE = ( * MCPEs ) [ CPIndex ] ; JTI -> addConstantPoolEntryAddr ( CPI , MCE . getCurrentPCValue ( ) ) ; if ( MCPE . isMachineConstantPoolEntry ( ) ) { <ISA_LIT>ConstantPoolValue * ACPV = static_cast < <ISA_LIT>ConstantPoolValue * > ( MCPE . Val . MachineCPVal ) ; DOUT << <STR_LIT> << CPI << <STR_LIT> << ( void * ) MCE . getCurrentPCValue ( ) << <STR_LIT> << * ACPV << '\n' ; GlobalValue * GV = ACPV -> getGV ( ) ; if ( GV ) { assert ( ! ACPV -> isStub ( ) && <STR_LIT> ) ; if ( ACPV -> isNonLazyPointer ( ) ) MCE . addRelocation ( MachineRelocation :: getIndirectSymbol ( MCE . getCurrentPCOffset ( ) , <STR_LIT> , GV , ( intptr_t ) ACPV , false ) ) ; else emitGlobalAddress ( GV , <STR_LIT> , ACPV -> isStub ( ) || isa < Function > ( GV ) , ( intptr_t ) ACPV ) ; } else { assert ( ! ACPV -> isNonLazyPointer ( ) && <STR_LIT> ) ; emitExternalSymbolAddress ( ACPV -> getSymbol ( ) , <STR_LIT> ) ; } emitWordLE ( <NUM_LIT> ) ; } else { Constant * CV = MCPE . Val . ConstVal ;

DOUT << <STR_LIT> << CPI << <STR_LIT> << ( void * ) MCE . getCurrentPCValue ( ) << <STR_LIT> ;


<s> const MachineOperand & MO = MI . getOperand ( OpIdx ) ; if ( ( TID . TSFlags & <STR_LIT> ) == <STR_LIT> ) { emitWordLE ( Binary | getMachineSoRegOpValue ( MI , TID , MO , OpIdx ) ) ; return ; } if ( MO . isReg ( ) ) { emitWordLE ( Binary | <ISA_LIT>RegisterInfo :: getRegisterNumbering ( MO . getReg ( ) ) ) ; return ; } Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= getMachineSoImmOpValue ( MO . getImm ( ) ) ; emitWordLE ( Binary ) ;


<s> MCE . addRelocation ( MachineRelocation :: getGV ( MCE . getCurrentPCOffset ( ) , Reloc , GV , ACPV , NeedStub ) ) ;


<s> case <STR_LIT> : emitDataProcessingInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitLoadStoreInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitMiscLoadStoreInstruction ( MI ) ; break ; case <STR_LIT> : emitLoadStoreMultipleInstruction ( MI ) ; break ; case <STR_LIT> : emitMulFrmInstruction ( MI ) ; break ; case <STR_LIT> : emitExtendInstruction ( MI ) ; break ; case <STR_LIT> : emitMiscArithInstruction ( MI ) ; break ; case <STR_LIT> : emitBranchInstruction ( MI ) ; break ; case <STR_LIT> : emitMiscBranchInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitVFPArithInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : emitVFPConversionInstruction ( MI ) ; break ; case <STR_LIT> : emitVFPLoadStoreInstruction ( MI ) ; break ;


<s> const MachineOperand & MO2 = MI . getOperand ( OpIdx ) ; unsigned AM3Opc = ( ImplicitRn == <STR_LIT> ) ? <NUM_LIT> : MI . getOperand ( OpIdx + <NUM_LIT> ) . getImm ( ) ; Binary |= ( ( <STR_LIT> ( AM3Opc ) == <STR_LIT> ? <NUM_LIT> : <NUM_LIT> ) << <STR_LIT> ) ; if ( MO2 . getReg ( ) ) { Binary |= <ISA_LIT>RegisterInfo :: getRegisterNumbering ( MO2 . getReg ( ) ) ; emitWordLE ( Binary ) ; return ; } Binary |= <NUM_LIT> << <STR_LIT> ; if ( unsigned ImmOffs = <STR_LIT> ( AM3Opc ) ) {

Binary |= ( ImmOffs >> <NUM_LIT> ) << <STR_LIT> ;


<s> unsigned V2 = <STR_LIT> ( MO1 . getImm ( ) ) ; unsigned Binary = <NUM_LIT> << <NUM_LIT> ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , MO0 ) << <STR_LIT> ; Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= getMachineSoImmOpValue ( <STR_LIT> ( V1 ) ) ; emitWordLE ( Binary ) ; Binary = <NUM_LIT> << <NUM_LIT> ;


<s> MCE . emitLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; break ; case TargetInstrInfo :: IMPLICIT_DEF : case TargetInstrInfo :: DECLARE : case <STR_LIT> : break ; case <STR_LIT> : emitConstPoolInstruction ( MI ) ; break ; case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitDataProcessingInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitLoadStoreInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitMiscLoadStoreInstruction ( MI , <STR_LIT> ) ; break ; } case <STR_LIT> : emitMOVi2piecesInstruction ( MI ) ; break ; case <STR_LIT> : emitLEApcrelJTInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : emitPseudoMoveInstruction ( MI ) ; break ; }


<s> const TargetInstrDesc & TID = MI . getDesc ( ) ; unsigned Reloc = ( ( TID . TSFlags & <STR_LIT> ) == <STR_LIT> ) ? <STR_LIT> : <STR_LIT> ; emitConstPoolAddress ( MO . getIndex ( ) , Reloc ) ; } else if ( MO . isJTI ( ) ) emitJumpTableAddress ( MO . getIndex ( ) , <STR_LIT> ) ; else if ( MO . isMBB ( ) ) emitMachineBasicBlock ( MO . getMBB ( ) , <STR_LIT> ) ; else { cerr << <STR_LIT> << MO << <STR_LIT> ; abort ( ) ; }


<s> else if ( MO . isGlobal ( ) ) emitGlobalAddress ( MO . getGlobal ( ) , <STR_LIT> , true ) ; else if ( MO . isSymbol ( ) ) emitExternalSymbolAddress ( MO . getSymbolName ( ) , <STR_LIT> ) ; else if ( MO . isCPI ( ) ) { const TargetInstrDesc & TID = MI . getDesc ( ) ; unsigned Reloc = ( ( TID . TSFlags & <STR_LIT> ) == <STR_LIT> ) ? <STR_LIT> : <STR_LIT> ; emitConstPoolAddress ( MO . getIndex ( ) , Reloc ) ; } else if ( MO . isJTI ( ) ) emitJumpTableAddress ( MO . getIndex ( ) , <STR_LIT> ) ;

else if ( MO . isMBB ( ) ) emitMachineBasicBlock ( MO . getMBB ( ) , <STR_LIT> ) ;


<s> const MachineOperand & MO2 = MI . getOperand ( OpIdx + <NUM_LIT> ) ; <STR_LIT> SOpc = <STR_LIT> ( MO2 . getImm ( ) ) ; unsigned SBits = <NUM_LIT> ; unsigned Rs = MO1 . getReg ( ) ; if ( Rs ) { switch ( SOpc ) { default : assert ( <NUM_LIT> && <STR_LIT> ) ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; } } else { switch ( SOpc ) { default : assert ( <NUM_LIT> && <STR_LIT> ) ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; } } Binary |= SBits << <NUM_LIT> ;

if ( SOpc == <STR_LIT> ) return Binary ;


<s> switch ( <STR_LIT> ( Imm ) ) { default : assert ( <NUM_LIT> && <STR_LIT> ) ; case <STR_LIT> : return <NUM_LIT> ;


<s> DOUT << <STR_LIT> << MF . getFunction ( ) -> getName ( ) << <STR_LIT> ; MCE . startFunction ( MF ) ; for ( MachineFunction :: iterator MBB = MF . begin ( ) , E = MF . end ( ) ; MBB != E ; ++ MBB ) { MCE . StartMachineBasicBlock ( MBB ) ; for ( MachineBasicBlock :: const_iterator I = MBB -> begin ( ) , E = MBB -> end ( ) ; I != E ; ++ I ) emitInstruction ( * I ) ; } } while ( MCE . finishFunction ( MF ) ) ;


<s> unsigned RegD = MI . getOperand ( OpIdx ) . getReg ( ) ; unsigned Binary = <NUM_LIT> ; bool isSPVFP = <STR_LIT> . contains ( RegD ) ; RegD = get<ISA_LIT>RegisterNumbering ( RegD ) ;

if ( ! isSPVFP ) Binary |= RegD << <STR_LIT> ;


<s> else { Binary |= ( ( RegD & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; Binary |= ( RegD & <NUM_LIT> ) << <STR_LIT> ; } return Binary ;


<s> if ( ! isSPVFP ) Binary |= RegM ; else { Binary |= ( ( RegM & <NUM_LIT> ) >> <NUM_LIT> ) ;

Binary |= ( RegM & <NUM_LIT> ) << <STR_LIT> ;


<s> else { Binary |= ( ( RegM & <NUM_LIT> ) >> <NUM_LIT> ) ; Binary |= ( RegM & <NUM_LIT> ) << <STR_LIT> ; } return Binary ;


<s> bool isSPVFP = <STR_LIT> . contains ( RegN ) ; RegN = get<ISA_LIT>RegisterNumbering ( RegN ) ; if ( ! isSPVFP ) Binary |= RegN << <STR_LIT> ;


<s> static unsigned encodeVFPRn ( const MachineInstr & MI , unsigned OpIdx ) { unsigned RegN = MI . getOperand ( OpIdx ) . getReg ( ) ; unsigned Binary = <NUM_LIT> ; bool isSPVFP = <STR_LIT> . contains ( RegN ) ; RegN = get<ISA_LIT>RegisterNumbering ( RegN ) ; if ( ! isSPVFP ) Binary |= RegN << <STR_LIT> ; else { Binary |= ( ( RegN & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; Binary |= ( RegN & <NUM_LIT> ) << <STR_LIT> ;


<s> void <ISA_LIT>CodeEmitter :: addPCLabel ( unsigned LabelID ) {

DEBUG ( errs ( ) << <STR_LIT> << LabelID << <STR_LIT> << ( void * ) MCE . getCurrentPCValue ( ) << '\n' ) ;


<s> <ISA_LIT>CodeEmitter ( TargetMachine & tm , JITCodeEmitter & mce ) : MachineFunctionPass ( ID ) , JTI ( <NUM_LIT> ) , II ( ( const <ISA_LIT>BaseInstrInfo * ) tm . getInstrInfo ( ) ) , TD ( tm . getDataLayout ( ) ) , TM ( tm ) , MCE ( mce ) , MCPEs ( <NUM_LIT> ) , MJTEs ( <NUM_LIT> ) , IsPIC ( TM . getRelocationModel ( ) == Reloc :: PIC_ ) , IsThumb ( false ) {


<s> assert ( ( Binary & <NUM_LIT> ) == <NUM_LIT> && <STR_LIT> ) ;

unsigned UBit = ( Binary >> <NUM_LIT> ) & <NUM_LIT> ;


<s> assert ( ( Binary & <NUM_LIT> ) == <NUM_LIT> && <STR_LIT> ) ; unsigned UBit = ( Binary >> <NUM_LIT> ) & <NUM_LIT> ; return <NUM_LIT> | ( UBit << <NUM_LIT> ) | ( Binary & <NUM_LIT> ) ;


<s> return new <ISA_LIT>CodeEmitter ( TM , JCE ) ;


<s> void <ISA_LIT>CodeEmitter :: emitBranchInstruction ( const MachineInstr & MI ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; if ( MCID . Opcode == <STR_LIT> ) { llvm_unreachable ( <STR_LIT> ) ; } unsigned Binary = getBinaryCodeForInstr ( MI ) ; if ( MCID . Opcode == <STR_LIT> ) { Binary = <NUM_LIT> ; } Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) ; emitWordLE ( Binary ) ;


<s> } Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) ; emitWordLE ( Binary ) ;


<s> } case Value :: ConstantIntVal : { const ConstantInt * CI = static_cast < const ConstantInt * > ( C ) ; uint32_t Val = * ( uint32_t * ) CI -> getValue ( ) . getRawData ( ) ; emitWordLE ( Val ) ; break ; } case Value :: ConstantFPVal : { const ConstantFP * CFP = static_cast < const ConstantFP * > ( C ) ; if ( CFP -> getType ( ) -> isFloatTy ( ) ) emitWordLE ( CFP -> getValueAPF ( ) . bitcastToAPInt ( ) . getZExtValue ( ) ) ; else if ( CFP -> getType ( ) -> isDoubleTy ( ) ) emitDWordLE ( CFP -> getValueAPF ( ) . bitcastToAPInt ( ) . getZExtValue ( ) ) ; else { llvm_unreachable ( <STR_LIT> ) ; } break ; } case Value :: ConstantArrayVal : { const ConstantArray * CA = static_cast < const ConstantArray * > ( C ) ; for ( unsigned i = <NUM_LIT> , e = CA -> getNumOperands ( ) ; i != e ; ++ i ) emitConstantToMemory ( CPI , CA -> getOperand ( i ) ) ; break ; }


<s> void <ISA_LIT>CodeEmitter :: emitConstPoolAddress ( unsigned CPI , unsigned Reloc ) const { MCE . addRelocation ( MachineRelocation :: getConstPool ( MCE . getCurrentPCOffset ( ) , Reloc , CPI , <NUM_LIT> , true ) ) ;


<s> unsigned CPIndex = MI . getOperand ( <NUM_LIT> ) . getIndex ( ) ; const MachineConstantPoolEntry & MCPE = ( * MCPEs ) [ CPIndex ] ; JTI -> addConstantPoolEntryAddr ( CPI , MCE . getCurrentPCValue ( ) ) ; if ( MCPE . isMachineConstantPoolEntry ( ) ) { <ISA_LIT>ConstantPoolValue * ACPV = static_cast < <ISA_LIT>ConstantPoolValue * > ( MCPE . Val . MachineCPVal ) ; DEBUG ( errs ( ) << <STR_LIT> << CPI << <STR_LIT> << ( void * ) MCE . getCurrentPCValue ( ) << <STR_LIT> << * ACPV << '\n' ) ; assert ( ACPV -> isGlobalValue ( ) && <STR_LIT> ) ;

const GlobalValue * GV = cast < <ISA_LIT>ConstantPoolConstant > ( ACPV ) -> getGV ( ) ;


<s> uint32_t v = ~ MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; int32_t lsb = CountTrailingZeros_32 ( v ) ; int32_t msb = ( <NUM_LIT> - CountLeadingZeros_32 ( v ) ) - <NUM_LIT> ; Binary |= ( msb & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } else if ( ( MCID . Opcode == <STR_LIT> ) || ( MCID . Opcode == <STR_LIT> ) ) { Binary |= getMachineOpValue ( MI , OpIdx ++ ) ; uint32_t lsb = MI . getOperand ( OpIdx ++ ) . getImm ( ) ; uint32_t widthm1 = MI . getOperand ( OpIdx ++ ) . getImm ( ) - <NUM_LIT> ; Binary |= ( widthm1 & <NUM_LIT> ) << <NUM_LIT> ; Binary |= ( lsb & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; return ; } if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; bool isUnary = MCID . TSFlags & <STR_LIT> ; if ( ! isUnary ) { if ( ImplicitRn ) Binary |= ( II -> getRegisterInfo ( ) . getEncodingValue ( ImplicitRn ) << <STR_LIT> ) ;


<s> void <ISA_LIT>CodeEmitter :: emitDWordLE ( uint64_t Binary ) { DEBUG ( errs ( ) << <STR_LIT> ; errs ( ) . write_hex ( Binary ) << <STR_LIT> ) ; MCE . emitDWordLE ( Binary ) ;


<s> } else { Binary |= getMachineOpValue ( MI , MO1 ) ; } if ( MI . getOperand ( OpIdx ) . isImm ( ) && ! MCID . OpInfo [ OpIdx ] . isPredicate ( ) && ! MCID . OpInfo [ OpIdx ] . isOptionalDef ( ) ) Binary |= ( getMachineOpValue ( MI , OpIdx ) / <NUM_LIT> ) << <STR_LIT> ; emitWordLE ( Binary ) ;


<s> emitExternalSymbolAddress ( const char * ES , unsigned Reloc ) const { MCE . addRelocation ( MachineRelocation :: getExtSym ( MCE . getCurrentPCOffset ( ) , Reloc , ES ) ) ;


<s> void <ISA_LIT>CodeEmitter :: emitExternalSymbolAddress ( const char * ES , unsigned Reloc ) const {

MCE . addRelocation ( MachineRelocation :: getExtSym ( MCE . getCurrentPCOffset ( ) , Reloc , ES ) ) ;


<s> const std :: vector < MachineBasicBlock * > & MBBs = ( * MJTEs ) [ JTIndex ] . MBBs ; for ( unsigned i = <NUM_LIT> , e = MBBs . size ( ) ; i != e ; ++ i ) { if ( IsPIC ) emitMachineBasicBlock ( MBBs [ i ] , <STR_LIT> , JTBase ) ; else emitMachineBasicBlock ( MBBs [ i ] , <STR_LIT> ) ; emitWordLE ( <NUM_LIT> ) ;


<s> void <ISA_LIT>CodeEmitter :: emitInlineJumpTable ( unsigned JTIndex ) { uintptr_t JTBase = MCE . getCurrentPCValue ( ) ; JTI -> addJumpTableBaseAddr ( JTIndex , JTBase ) ;

DEBUG ( errs ( ) << <STR_LIT> << JTIndex << <STR_LIT> << ( void * ) JTBase << '\n' ) ;


<s> case <STR_LIT> : emitPseudoInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitDataProcessingInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitLoadStoreInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitMiscLoadStoreInstruction ( MI ) ; break ; case <STR_LIT> : emitLoadStoreMultipleInstruction ( MI ) ; break ; case <STR_LIT> : emitMulFrmInstruction ( MI ) ; break ; case <STR_LIT> : emitExtendInstruction ( MI ) ; break ; case <STR_LIT> : emitMiscArithInstruction ( MI ) ; break ; case <STR_LIT> : emitSaturateInstruction ( MI ) ; break ; case <STR_LIT> : emitBranchInstruction ( MI ) ; break ; case <STR_LIT> : emitMiscBranchInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : emitVFPArithInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> :


<s> MCE . addRelocation ( MachineRelocation :: getJumpTable ( MCE . getCurrentPCOffset ( ) , Reloc , JTIndex , <NUM_LIT> , true ) ) ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getAddrModeSBit ( MI , MCID ) ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) << <STR_LIT> ; Binary |= II -> getRegisterInfo ( ) . getEncodingValue ( <STR_LIT> ) << <STR_LIT> ; Binary |= <NUM_LIT> << <STR_LIT> ;

emitConstPoolAddress ( MI . getOperand ( <NUM_LIT> ) . getIndex ( ) , <STR_LIT> ) ;


<s> unsigned Binary = <NUM_LIT> << <NUM_LIT> ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getAddrModeSBit ( MI , MCID ) ;

Binary |= getMachineOpValue ( MI , <NUM_LIT> ) << <STR_LIT> ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getAddrModeSBit ( MI , MCID ) ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) << <STR_LIT> ; Binary |= II -> getRegisterInfo ( ) . getEncodingValue ( <STR_LIT> ) << <STR_LIT> ;


<s> unsigned Binary = getBinaryCodeForInstr ( MI ) ; if ( MI . getOpcode ( ) == <STR_LIT> || MI . getOpcode ( ) == <STR_LIT> || MI . getOpcode ( ) == <STR_LIT> || MI . getOpcode ( ) == <STR_LIT> || MI . getOpcode ( ) == <STR_LIT> ) { emitWordLE ( Binary ) ; return ; } if ( MI . getOpcode ( ) == <STR_LIT> ) Binary = <NUM_LIT> ; else if ( MI . getOpcode ( ) == <STR_LIT> ) Binary = <NUM_LIT> ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; unsigned OpIdx = <NUM_LIT> ; bool Skipped = false ; if ( IsPrePost && Form == <STR_LIT> ) { ++ OpIdx ; Skipped = true ; }

if ( ImplicitRd ) Binary |= ( II -> getRegisterInfo ( ) . getEncodingValue ( ImplicitRd ) << <STR_LIT> ) ;


<s> unsigned OpIdx = <NUM_LIT> ; bool Skipped = false ; if ( IsPrePost && Form == <STR_LIT> ) { ++ OpIdx ; Skipped = true ; } if ( ImplicitRd ) Binary |= ( II -> getRegisterInfo ( ) . getEncodingValue ( ImplicitRd ) << <STR_LIT> ) ; else Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; if ( ImplicitRn ) Binary |= ( II -> getRegisterInfo ( ) . getEncodingValue ( ImplicitRn ) << <STR_LIT> ) ; else Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; if ( ! Skipped && MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; const MachineOperand & MO2 = MI . getOperand ( OpIdx ) ; unsigned AM2Opc = ( ImplicitRn == <STR_LIT> ) ? <NUM_LIT> : MI . getOperand ( OpIdx + <NUM_LIT> ) . getImm ( ) ; Binary |= ( ( <STR_LIT> ( AM2Opc ) == <STR_LIT> ? <NUM_LIT> : <NUM_LIT> ) << <STR_LIT> ) ; if ( ! MO2 . getReg ( ) ) { if ( <STR_LIT> ( AM2Opc ) ) Binary |= <STR_LIT> ( AM2Opc ) ; emitWordLE ( Binary ) ; return ; } Binary |= <NUM_LIT> << <STR_LIT> ; assert ( TargetRegisterInfo :: isPhysicalRegister ( MO2 . getReg ( ) ) ) ;

Binary |= II -> getRegisterInfo ( ) . getEncodingValue ( MO2 . getReg ( ) ) ;


<s> void <ISA_LIT>CodeEmitter :: emitLoadStoreMultipleInstruction ( const MachineInstr & MI ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; bool IsUpdating = ( MCID . TSFlags & <STR_LIT> ) != <NUM_LIT> ; unsigned Binary = getBinaryCodeForInstr ( MI ) ; if ( MCID . getOpcode ( ) == <STR_LIT> ) { IsUpdating = true ; Binary |= <NUM_LIT> ; } Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; unsigned OpIdx = <NUM_LIT> ; if ( IsUpdating ) ++ OpIdx ; Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; <STR_LIT> Mode = <STR_LIT> ( MI . getOpcode ( ) ) ; Binary |= getAddrModeUPBits ( <STR_LIT> ( Mode ) ) ; if ( IsUpdating ) Binary |= <NUM_LIT> << <STR_LIT> ; for ( unsigned i = OpIdx + <NUM_LIT> , e = MI . getNumOperands ( ) ; i != e ; ++ i ) { const MachineOperand & MO = MI . getOperand ( i ) ; if ( ! MO . isReg ( ) || MO . isImplicit ( ) ) break ; unsigned RegNum = II -> getRegisterInfo ( ) . getEncodingValue ( MO . getReg ( ) ) ;

assert ( TargetRegisterInfo :: isPhysicalRegister ( MO . getReg ( ) ) && RegNum < <NUM_LIT> ) ;


<s> MCE . addRelocation ( MachineRelocation :: getBB ( MCE . getCurrentPCOffset ( ) , Reloc , BB , JTBase ) ) ;


<s> void <ISA_LIT>CodeEmitter :: emitMiscArithInstruction ( const MachineInstr & MI ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; unsigned Binary = getBinaryCodeForInstr ( MI ) ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; if ( MCID . Opcode == <STR_LIT> || MCID . Opcode == <STR_LIT> ) { emitWordLE ( Binary ) ; return ; } unsigned OpIdx = <NUM_LIT> ; Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; const MachineOperand & MO = MI . getOperand ( OpIdx ++ ) ; if ( OpIdx == MCID . getNumOperands ( ) || MCID . OpInfo [ OpIdx ] . isPredicate ( ) || MCID . OpInfo [ OpIdx ] . isOptionalDef ( ) ) { Binary |= getMachineOpValue ( MI , MO ) ; emitWordLE ( Binary ) ; return ; } Binary |= getMachineOpValue ( MI , MO ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , OpIdx ++ ) ; unsigned ShiftAmt = MI . getOperand ( OpIdx ) . getImm ( ) ; if ( MCID . Opcode == <STR_LIT> ) { assert ( ShiftAmt != <NUM_LIT> && <STR_LIT> ) ; if ( ShiftAmt == <NUM_LIT> ) ShiftAmt = <NUM_LIT> ; } assert ( ShiftAmt < <NUM_LIT> && <STR_LIT> ) ; Binary |= ShiftAmt << <STR_LIT> ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; if ( MCID . Opcode == <STR_LIT> || MCID . Opcode == <STR_LIT> ) { emitWordLE ( Binary ) ; return ; } unsigned OpIdx = <NUM_LIT> ; Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; const MachineOperand & MO = MI . getOperand ( OpIdx ++ ) ; if ( OpIdx == MCID . getNumOperands ( ) || MCID . OpInfo [ OpIdx ] . isPredicate ( ) || MCID . OpInfo [ OpIdx ] . isOptionalDef ( ) ) { Binary |= getMachineOpValue ( MI , MO ) ; emitWordLE ( Binary ) ;


<s> emitDataProcessingInstruction ( MI , <STR_LIT> ) ; unsigned JTIndex = ( MCID . Opcode == <STR_LIT> ) ? MI . getOperand ( <NUM_LIT> ) . getIndex ( ) : MI . getOperand ( <NUM_LIT> ) . getIndex ( ) ; emitInlineJumpTable ( JTIndex ) ; return ; } else if ( MCID . Opcode == <STR_LIT> ) { emitLoadStoreInstruction ( MI , <STR_LIT> ) ;

emitInlineJumpTable ( MI . getOperand ( <NUM_LIT> ) . getIndex ( ) ) ;


<s> void <ISA_LIT>CodeEmitter :: emitMiscBranchInstruction ( const MachineInstr & MI ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; if ( MCID . Opcode == <STR_LIT> || MCID . Opcode == <STR_LIT> ) { emitDataProcessingInstruction ( MI , <STR_LIT> ) ; unsigned JTIndex = ( MCID . Opcode == <STR_LIT> ) ? MI . getOperand ( <NUM_LIT> ) . getIndex ( ) : MI . getOperand ( <NUM_LIT> ) . getIndex ( ) ; emitInlineJumpTable ( JTIndex ) ; return ; } else if ( MCID . Opcode == <STR_LIT> ) { emitLoadStoreInstruction ( MI , <STR_LIT> ) ; emitInlineJumpTable ( MI . getOperand ( <NUM_LIT> ) . getIndex ( ) ) ; return ;


<s> void <ISA_LIT>CodeEmitter :: emitMiscInstruction ( const MachineInstr & MI ) { unsigned Opcode = MI . getDesc ( ) . Opcode ; unsigned Binary = getBinaryCodeForInstr ( MI ) ; if ( Opcode == <STR_LIT> ) { unsigned Imm = getMachineOpValue ( MI , <NUM_LIT> ) ; Binary &= ~ ( <NUM_LIT> >> <NUM_LIT> ) ; Binary |= ( Imm & <NUM_LIT> ) >> <NUM_LIT> ; Binary &= ~ ( <NUM_LIT> >> <NUM_LIT> ) ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; unsigned OpIdx = <NUM_LIT> ; bool Skipped = false ; if ( IsPrePost && Form == <STR_LIT> ) { ++ OpIdx ; Skipped = true ; } Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; if ( MCID . Opcode == <STR_LIT> || MCID . Opcode == <STR_LIT> ) ++ OpIdx ; if ( ImplicitRn ) Binary |= ( II -> getRegisterInfo ( ) . getEncodingValue ( ImplicitRn ) << <STR_LIT> ) ; else Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; if ( ! Skipped && MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; const MachineOperand & MO2 = MI . getOperand ( OpIdx ) ; unsigned AM3Opc = ( ImplicitRn == <STR_LIT> ) ? <NUM_LIT> : MI . getOperand ( OpIdx + <NUM_LIT> ) . getImm ( ) ; Binary |= ( ( <STR_LIT> ( AM3Opc ) == <STR_LIT> ? <NUM_LIT> : <NUM_LIT> ) << <STR_LIT> ) ; if ( MO2 . getReg ( ) ) { Binary |= II -> getRegisterInfo ( ) . getEncodingValue ( MO2 . getReg ( ) ) ; emitWordLE ( Binary ) ; return ; } Binary |= <NUM_LIT> << <STR_LIT> ; if ( unsigned ImmOffs = <STR_LIT> ( AM3Opc ) ) { Binary |= ( ImmOffs >> <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ImmOffs & <NUM_LIT> ) ; } emitWordLE ( Binary ) ;


<s> const MachineOperand & MO1 = MI . getOperand ( <NUM_LIT> ) ; assert ( MO1 . isImm ( ) && <STR_LIT> ( MO1 . getImm ( ) ) && <STR_LIT> ) ; unsigned V1 = <STR_LIT> ( MO1 . getImm ( ) ) ; unsigned V2 = <STR_LIT> ( MO1 . getImm ( ) ) ; unsigned Binary = <NUM_LIT> << <NUM_LIT> ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , MO0 ) << <STR_LIT> ; Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= getMachineSoImmOpValue ( V1 ) ; emitWordLE ( Binary ) ; Binary = <NUM_LIT> << <NUM_LIT> ;


<s> assert ( MO1 . isImm ( ) && <STR_LIT> ( MO1 . getImm ( ) ) && <STR_LIT> ) ; unsigned V1 = <STR_LIT> ( MO1 . getImm ( ) ) ; unsigned V2 = <STR_LIT> ( MO1 . getImm ( ) ) ; unsigned Binary = <NUM_LIT> << <NUM_LIT> ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , MO0 ) << <STR_LIT> ; Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= getMachineSoImmOpValue ( V1 ) ;


<s> Binary |= Lo16 & <NUM_LIT> ; Binary |= ( ( Lo16 >> <NUM_LIT> ) & <NUM_LIT> ) << <NUM_LIT> ; emitWordLE ( Binary ) ; unsigned Hi16 = getMovi32Value ( MI , MO1 , <STR_LIT> ) >> <NUM_LIT> ; Binary = <NUM_LIT> << <NUM_LIT> ;


<s> const MCInstrDesc & MCID = MI . getDesc ( ) ; unsigned Binary = getBinaryCodeForInstr ( MI ) ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getAddrModeSBit ( MI , MCID ) ; unsigned OpIdx = <NUM_LIT> ;

if ( MCID . getNumDefs ( ) == <NUM_LIT> ) Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ;


<s> Binary |= encodeNEONRd ( MI , <NUM_LIT> ) ; unsigned Imm = MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; unsigned Op = ( Imm >> <NUM_LIT> ) & <NUM_LIT> ; unsigned Cmode = ( Imm >> <NUM_LIT> ) & <NUM_LIT> ; unsigned I = ( Imm >> <NUM_LIT> ) & <NUM_LIT> ; unsigned Imm3 = ( Imm >> <NUM_LIT> ) & <NUM_LIT> ; unsigned Imm4 = Imm & <NUM_LIT> ; Binary |= ( I << <NUM_LIT> ) | ( Imm3 << <NUM_LIT> ) | ( Cmode << <NUM_LIT> ) | ( Op << <NUM_LIT> ) | Imm4 ;

if ( IsThumb ) Binary = convertNEONDataProcToThumb ( Binary ) ;


<s> unsigned Cmode = ( Imm >> <NUM_LIT> ) & <NUM_LIT> ; unsigned I = ( Imm >> <NUM_LIT> ) & <NUM_LIT> ; unsigned Imm3 = ( Imm >> <NUM_LIT> ) & <NUM_LIT> ; unsigned Imm4 = Imm & <NUM_LIT> ; Binary |= ( I << <NUM_LIT> ) | ( Imm3 << <NUM_LIT> ) | ( Cmode << <NUM_LIT> ) | ( Op << <NUM_LIT> ) | Imm4 ;


<s> if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; Binary |= encodeNEONRm ( MI , OpIdx ) ; if ( IsThumb ) Binary = convertNEONDataProcToThumb ( Binary ) ;


<s> if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; Binary |= encodeNEONRn ( MI , OpIdx ++ ) ; if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; Binary |= encodeNEONRm ( MI , OpIdx ) ; if ( IsThumb ) Binary = convertNEONDataProcToThumb ( Binary ) ;


<s> Binary |= ( IsThumb ? <STR_LIT> : II -> getPredicate ( & MI ) ) << <STR_LIT> ;

unsigned RegT = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ;


<s> Binary |= ( IsThumb ? <STR_LIT> : II -> getPredicate ( & MI ) ) << <STR_LIT> ; unsigned RegT = MI . getOperand ( <NUM_LIT> ) . getReg ( ) ;

RegT = II -> getRegisterInfo ( ) . getEncodingValue ( RegT ) ;


<s> case <STR_LIT> : emitMiscBranchInstruction ( MI ) ; break ; case <STR_LIT> : case <STR_LIT> : { unsigned Binary = <NUM_LIT> ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; emitWordLE ( Binary ) ; emitMiscBranchInstruction ( MI ) ; break ; } case TargetOpcode :: INLINEASM : { if ( MI . getOperand ( <NUM_LIT> ) . getSymbolName ( ) [ <NUM_LIT> ] ) { report_fatal_error ( <STR_LIT> ) ; } break ; } case TargetOpcode :: PROLOG_LABEL : case TargetOpcode :: EH_LABEL : MCE . emitLabel ( MI . getOperand ( <NUM_LIT> ) . getMCSymbol ( ) ) ; break ; case TargetOpcode :: IMPLICIT_DEF : case TargetOpcode :: KILL : break ; case <STR_LIT> : emitConstPoolInstruction ( MI ) ; break ; case <STR_LIT> : emitLoadStoreMultipleInstruction ( MI ) ; break ; case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitDataProcessingInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; }


<s> break ; } case TargetOpcode :: PROLOG_LABEL : case TargetOpcode :: EH_LABEL : MCE . emitLabel ( MI . getOperand ( <NUM_LIT> ) . getMCSymbol ( ) ) ; break ; case TargetOpcode :: IMPLICIT_DEF : case TargetOpcode :: KILL : break ; case <STR_LIT> : emitConstPoolInstruction ( MI ) ; break ; case <STR_LIT> : emitLoadStoreMultipleInstruction ( MI ) ; break ; case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ; emitDataProcessingInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ; break ; } case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { addPCLabel ( MI . getOperand ( <NUM_LIT> ) . getImm ( ) ) ;

emitLoadStoreInstruction ( MI , <NUM_LIT> , <STR_LIT> ) ;


<s> case <STR_LIT> : Binary |= ( <NUM_LIT> << <NUM_LIT> ) | ( <NUM_LIT> << <NUM_LIT> ) ; break ; case <STR_LIT> : Binary |= ( <NUM_LIT> << <NUM_LIT> ) | ( <NUM_LIT> << <NUM_LIT> ) ; break ; }

Binary |= getMachineOpValue ( MI , <NUM_LIT> ) ;


<s> unsigned Binary = getBinaryCodeForInstr ( MI ) ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; if ( Opcode == <STR_LIT> || Opcode == <STR_LIT> ) Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) << <STR_LIT> ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) << <STR_LIT> ; unsigned Pos = MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; if ( MCID . Opcode == <STR_LIT> || MCID . Opcode == <STR_LIT> ) Pos -= <NUM_LIT> ; assert ( ( Pos < <NUM_LIT> || ( Pos < <NUM_LIT> && MCID . Opcode != <STR_LIT> && MCID . Opcode != <STR_LIT> ) ) && <STR_LIT> ) ; Binary |= Pos << <NUM_LIT> ; Binary |= getMachineOpValue ( MI , <NUM_LIT> ) ; if ( MCID . getNumOperands ( ) == <NUM_LIT> ) { unsigned ShiftOp = MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; <STR_LIT> Opc = <STR_LIT> ( ShiftOp ) ; if ( Opc == <STR_LIT> ) Binary |= ( <NUM_LIT> << <NUM_LIT> ) ; unsigned ShiftAmt = MI . getOperand ( <NUM_LIT> ) . getImm ( ) ; if ( ShiftAmt == <NUM_LIT> && Opc == <STR_LIT> ) ShiftAmt = <NUM_LIT> ;

assert ( ShiftAmt < <NUM_LIT> && <STR_LIT> ) ;


<s> Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; unsigned OpIdx = <NUM_LIT> ; Binary |= encodeVFPRd ( MI , OpIdx ++ ) ; if ( MCID . getOperandConstraint ( OpIdx , MCOI :: TIED_TO ) != - <NUM_LIT> ) ++ OpIdx ; if ( ( MCID . TSFlags & <STR_LIT> ) == <STR_LIT> ) Binary |= encodeVFPRn ( MI , OpIdx ++ ) ;

if ( OpIdx == MCID . getNumOperands ( ) || MCID . OpInfo [ OpIdx ] . isPredicate ( ) || MCID . OpInfo [ OpIdx ] . isOptionalDef ( ) ) {


<s> case <STR_LIT> : Binary |= encodeVFPRn ( MI , <NUM_LIT> ) ; break ; case <STR_LIT> : Binary |= encodeVFPRm ( MI , <NUM_LIT> ) ; break ; } switch ( Form ) { default : break ; case <STR_LIT> : Binary |= encodeVFPRm ( MI , <NUM_LIT> ) ; break ; case <STR_LIT> : case <STR_LIT> : Binary |= encodeVFPRn ( MI , <NUM_LIT> ) ; break ; case <STR_LIT> : case <STR_LIT> : Binary |= encodeVFPRd ( MI , <NUM_LIT> ) ;


<s> Binary |= encodeVFPRd ( MI , OpIdx ++ ) ; const MachineOperand & Base = MI . getOperand ( OpIdx ++ ) ; Binary |= getMachineOpValue ( MI , Base ) << <STR_LIT> ; if ( Base . isReg ( ) ) { const MachineOperand & Offset = MI . getOperand ( OpIdx ) ; if ( unsigned ImmOffs = <STR_LIT> ( Offset . getImm ( ) ) ) { if ( <STR_LIT> ( Offset . getImm ( ) ) == <STR_LIT> ) Binary |= <NUM_LIT> << <STR_LIT> ;


<s> return ; } unsigned OpIdx = <NUM_LIT> ; Binary |= encodeVFPRd ( MI , OpIdx ++ ) ; const MachineOperand & Base = MI . getOperand ( OpIdx ++ ) ; Binary |= getMachineOpValue ( MI , Base ) << <STR_LIT> ; if ( Base . isReg ( ) ) { const MachineOperand & Offset = MI . getOperand ( OpIdx ) ; if ( unsigned ImmOffs = <STR_LIT> ( Offset . getImm ( ) ) ) { if ( <STR_LIT> ( Offset . getImm ( ) ) == <STR_LIT> ) Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= ImmOffs ; emitWordLE ( Binary ) ;


<s> <STR_LIT> Mode = <STR_LIT> ( MI . getOpcode ( ) ) ; Binary |= getAddrModeUPBits ( <STR_LIT> ( Mode ) ) ; if ( IsUpdating ) Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= encodeVFPRd ( MI , OpIdx + <NUM_LIT> ) ; unsigned NumRegs = <NUM_LIT> ; for ( unsigned i = OpIdx + <NUM_LIT> , e = MI . getNumOperands ( ) ; i != e ; ++ i ) { const MachineOperand & MO = MI . getOperand ( i ) ; if ( ! MO . isReg ( ) || MO . isImplicit ( ) ) break ; ++ NumRegs ; }

if ( Binary & <NUM_LIT> ) Binary |= NumRegs * <NUM_LIT> ;


<s> void <ISA_LIT>CodeEmitter :: emitVFPLoadStoreMultipleInstruction ( const MachineInstr & MI ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; bool IsUpdating = ( MCID . TSFlags & <STR_LIT> ) != <NUM_LIT> ; unsigned Binary = getBinaryCodeForInstr ( MI ) ; Binary |= II -> getPredicate ( & MI ) << <STR_LIT> ; unsigned OpIdx = <NUM_LIT> ; if ( IsUpdating ) ++ OpIdx ; Binary |= getMachineOpValue ( MI , OpIdx ++ ) << <STR_LIT> ; <STR_LIT> Mode = <STR_LIT> ( MI . getOpcode ( ) ) ; Binary |= getAddrModeUPBits ( <STR_LIT> ( Mode ) ) ; if ( IsUpdating ) Binary |= <NUM_LIT> << <STR_LIT> ; Binary |= encodeVFPRd ( MI , OpIdx + <NUM_LIT> ) ; unsigned NumRegs = <NUM_LIT> ; for ( unsigned i = OpIdx + <NUM_LIT> , e = MI . getNumOperands ( ) ; i != e ; ++ i ) { const MachineOperand & MO = MI . getOperand ( i ) ; if ( ! MO . isReg ( ) || MO . isImplicit ( ) ) break ; ++ NumRegs ; } if ( Binary & <NUM_LIT> ) Binary |= NumRegs * <NUM_LIT> ;


<s> DEBUG ( errs ( ) << <STR_LIT> ; errs ( ) . write_hex ( Binary ) << <STR_LIT> ) ; MCE . emitWordLE ( Binary ) ;


<s> RegD = II -> getRegisterInfo ( ) . getEncodingValue ( RegD ) ; Binary |= ( RegD & <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ( RegD >> <NUM_LIT> ) & <NUM_LIT> ) << <STR_LIT> ;


<s> unsigned <ISA_LIT>CodeEmitter :: encodeNEONRm ( const MachineInstr & MI , unsigned OpIdx ) const { unsigned RegM = MI . getOperand ( OpIdx ) . getReg ( ) ;


<s> unsigned Binary = <NUM_LIT> ; RegM = II -> getRegisterInfo ( ) . getEncodingValue ( RegM ) ; Binary |= ( RegM & <NUM_LIT> ) ; Binary |= ( ( RegM >> <NUM_LIT> ) & <NUM_LIT> ) << <STR_LIT> ;


<s> Binary |= ( RegN & <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ( RegN >> <NUM_LIT> ) & <NUM_LIT> ) << <STR_LIT> ;


<s> unsigned Binary = <NUM_LIT> ; bool isSPVFP = <STR_LIT> . contains ( RegD ) ; RegD = II -> getRegisterInfo ( ) . getEncodingValue ( RegD ) ; if ( ! isSPVFP ) { Binary |= ( RegD & <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ( RegD & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; } else {


<s> bool isSPVFP = <STR_LIT> . contains ( RegM ) ; RegM = II -> getRegisterInfo ( ) . getEncodingValue ( RegM ) ; if ( ! isSPVFP ) { Binary |= ( RegM & <NUM_LIT> ) ; Binary |= ( ( RegM & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; } else { Binary |= ( ( RegM & <NUM_LIT> ) >> <NUM_LIT> ) ;

Binary |= ( RegM & <NUM_LIT> ) << <STR_LIT> ;


<s> unsigned <ISA_LIT>CodeEmitter :: encodeVFPRn ( const MachineInstr & MI , unsigned OpIdx ) const { unsigned RegN = MI . getOperand ( OpIdx ) . getReg ( ) ; unsigned Binary = <NUM_LIT> ; bool isSPVFP = <STR_LIT> . contains ( RegN ) ; RegN = II -> getRegisterInfo ( ) . getEncodingValue ( RegN ) ; if ( ! isSPVFP ) { Binary |= ( RegN & <NUM_LIT> ) << <STR_LIT> ; Binary |= ( ( RegN & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; } else { Binary |= ( ( RegN & <NUM_LIT> ) >> <NUM_LIT> ) << <STR_LIT> ; Binary |= ( RegN & <NUM_LIT> ) << <STR_LIT> ; }


<s> uint32_t getAddrMode2OffsetOpValue ( const MachineInstr & MI , unsigned OpIdx ) const {


<s> uint32_t getAddrMode2OpValue ( const MachineInstr & MI , unsigned OpIdx ) const {


<s> uint32_t getAddrMode3OffsetOpValue ( const MachineInstr & MI , unsigned OpIdx ) const {


<s> uint32_t getAddrMode3OffsetOpValue ( const MachineInstr & MI , unsigned OpIdx ) const { return <NUM_LIT> ;


<s> uint32_t getAddrMode3OpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> uint32_t getAddrMode3OpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> } unsigned Reg = II -> getRegisterInfo ( ) . getEncodingValue ( MO . getReg ( ) ) ; int32_t Imm12 = MO1 . getImm ( ) ; if ( Imm12 == INT32_MIN ) Imm12 = <NUM_LIT> ; bool isAdd = true ; if ( Imm12 < <NUM_LIT> ) { Imm12 = - Imm12 ; isAdd = false ;


<s> return <NUM_LIT> ; } unsigned Reg = II -> getRegisterInfo ( ) . getEncodingValue ( MO . getReg ( ) ) ; int32_t Imm12 = MO1 . getImm ( ) ; if ( Imm12 == INT32_MIN ) Imm12 = <NUM_LIT> ; bool isAdd = true ; if ( Imm12 < <NUM_LIT> ) { Imm12 = - Imm12 ;


<s> unsigned getAddrMode6AddressOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getAddrMode6DupAddressOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getAddrMode6OffsetOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> return <NUM_LIT> ; } unsigned Reg = II -> getRegisterInfo ( ) . getEncodingValue ( MO . getReg ( ) ) ; int32_t Imm12 = MO1 . getImm ( ) ; uint32_t Binary ; Binary = Imm12 & <NUM_LIT> ; if ( Imm12 >= <NUM_LIT> ) Binary |= ( <NUM_LIT> << <NUM_LIT> ) ;


<s> unsigned getAddrModeImm12OpValue ( const MachineInstr & MI , unsigned Op ) const { const MachineOperand & MO = MI . getOperand ( Op ) ; const MachineOperand & MO1 = MI . getOperand ( Op + <NUM_LIT> ) ; if ( ! MO . isReg ( ) ) { emitConstPoolAddress ( MO . getIndex ( ) , <STR_LIT> ) ; return <NUM_LIT> ; } unsigned Reg = II -> getRegisterInfo ( ) . getEncodingValue ( MO . getReg ( ) ) ; int32_t Imm12 = MO1 . getImm ( ) ; uint32_t Binary ;


<s> uint32_t getAddrModeISOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> uint32_t getAddrModePCOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned <ISA_LIT>CodeEmitter :: getAddrModeSBit ( const MachineInstr & MI , const MCInstrDesc & MCID ) const {

for ( unsigned i = MI . getNumOperands ( ) , e = MCID . getNumOperands ( ) ; i >= e ; -- i ) {


<s> unsigned <ISA_LIT>CodeEmitter :: getAddrModeSBit ( const MachineInstr & MI , const MCInstrDesc & MCID ) const { for ( unsigned i = MI . getNumOperands ( ) , e = MCID . getNumOperands ( ) ; i >= e ; -- i ) { const MachineOperand & MO = MI . getOperand ( i - <NUM_LIT> ) ; if ( MO . isReg ( ) && MO . isDef ( ) && MO . getReg ( ) == <STR_LIT> ) return <NUM_LIT> << <STR_LIT> ; } return <NUM_LIT> ;


<s> uint32_t getAddrModeSOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned Binary = <NUM_LIT> ; switch ( Mode ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : break ;

case <STR_LIT> : Binary |= <NUM_LIT> << <STR_LIT> ; break ;


<s> unsigned Binary = <NUM_LIT> ; switch ( Mode ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : break ; case <STR_LIT> : Binary |= <NUM_LIT> << <STR_LIT> ; break ; case <STR_LIT> : Binary |= <NUM_LIT> << <STR_LIT> ; break ;


<s> unsigned getAdrLabelOpValue ( const MachineInstr & MI , unsigned Op ) const {


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

MachineFunctionPass :: getAnalysisUsage ( AU ) ;


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


<s> unsigned get<ISA_LIT>BLTargetOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getBitfieldInvertedMaskOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getBranchTargetOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getCCOutOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> if ( ! MO . isImm ( ) ) { emitGlobalAddress ( MO . getGlobal ( ) , Reloc , true , false ) ; return <NUM_LIT> ; } unsigned Imm16 = static_cast < unsigned > ( MO . getImm ( ) ) ; return Imm16 ;


<s> uint32_t getLdStSORegOpValue ( const MachineInstr & MI , unsigned OpIdx ) const {


<s> uint32_t getLdStSORegOpValue ( const MachineInstr & MI , unsigned OpIdx ) const { return <NUM_LIT> ;


<s> else if ( MO . isFPImm ( ) ) return static_cast < unsigned > ( MO . getFPImm ( ) -> getValueAPF ( ) . bitcastToAPInt ( ) . getHiBits ( <NUM_LIT> ) . getLimitedValue ( ) ) ; else if ( MO . isGlobal ( ) ) emitGlobalAddress ( MO . getGlobal ( ) , <STR_LIT> , true , false ) ; else if ( MO . isSymbol ( ) ) emitExternalSymbolAddress ( MO . getSymbolName ( ) , <STR_LIT> ) ; else if ( MO . isCPI ( ) ) { const MCInstrDesc & MCID = MI . getDesc ( ) ; unsigned Reloc = ( ( MCID . TSFlags & <STR_LIT> ) == <STR_LIT> ) ? <STR_LIT> : <STR_LIT> ; emitConstPoolAddress ( MO . getIndex ( ) , Reloc ) ; } else if ( MO . isJTI ( ) ) emitJumpTableAddress ( MO . getIndex ( ) , <STR_LIT> ) ;

else if ( MO . isMBB ( ) ) emitMachineBasicBlock ( MO . getMBB ( ) , <STR_LIT> ) ;


<s> unsigned Binary = ( <STR_LIT> ( ( unsigned ) SoImmVal ) >> <NUM_LIT> ) << <STR_LIT> ; Binary |= <STR_LIT> ( ( unsigned ) SoImmVal ) ; return Binary ;


<s> unsigned <ISA_LIT>CodeEmitter :: getMachineSoImmOpValue ( unsigned SoImm ) { int SoImmVal = <STR_LIT> ( SoImm ) ; assert ( SoImmVal != - <NUM_LIT> && <STR_LIT> ) ; unsigned Binary = ( <STR_LIT> ( ( unsigned ) SoImmVal ) >> <NUM_LIT> ) << <STR_LIT> ; Binary |= <STR_LIT> ( ( unsigned ) SoImmVal ) ; return Binary ;


<s> unsigned Rs = MO1 . getReg ( ) ; if ( Rs ) { switch ( SOpc ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; } } else { switch ( SOpc ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; }


<s> case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; } } else { switch ( SOpc ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; case <STR_LIT> : SBits = <NUM_LIT> ; break ; } } Binary |= SBits << <NUM_LIT> ; if ( SOpc == <STR_LIT> ) return Binary ; if ( Rs ) {

assert ( <STR_LIT> ( MO2 . getImm ( ) ) == <NUM_LIT> ) ;


<s> unsigned getNEONVcvtImm32OpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getNEONVcvtImm32OpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> uint32_t getPostIdxRegOpValue ( const MachineInstr & MI , unsigned OpIdx ) const { return <NUM_LIT> ;


<s> unsigned getRegisterListOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> case <STR_LIT> : return <NUM_LIT> ; case <STR_LIT> : return <NUM_LIT> ; case <STR_LIT> : return <NUM_LIT> ; case <STR_LIT> : case <STR_LIT> : return <NUM_LIT> ;


<s> unsigned getShiftRight16Imm ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getShiftRight32Imm ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getShiftRight64Imm ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getShiftRight8Imm ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getSOImmOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getSsatBitPosValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getT2AddrModeImm0_1020s4OpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getT2AddrModeImm12OffsetOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getT2AddrModeImm12OffsetOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getT2AddrModeImm12OpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getT2AddrModeImm12OpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getT2AddrModeImm8OffsetOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getT2AddrModeImm8s4OpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getT2AddrModeSORegOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getT2AddrModeSORegOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getT2Imm8s4OpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getT2SOImmOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getT2SORegOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getThumbAddrModeRegRegOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getThumbAdrLabelOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned getThumbBRTargetOpValue ( const MachineInstr & MI , unsigned Op ) const {


<s> unsigned getUnconditionalBranchTargetOpValue ( const MachineInstr & MI , unsigned Op ) const { return <NUM_LIT> ;


<s> unsigned NEONThumb2DataIPostEncoder ( const MachineInstr & MI , unsigned Val ) const { return <NUM_LIT> ;


<s> unsigned NEONThumb2LoadStorePostEncoder ( const MachineInstr & MI , unsigned Val ) const { return <NUM_LIT> ;


<s> TD = Target . getDataLayout ( ) ; Subtarget = & TM . getSubtarget < <ISA_LIT>Subtarget > ( ) ; MCPEs = & MF . getConstantPool ( ) -> getConstants ( ) ; MJTEs = <NUM_LIT> ; if ( MF . getJumpTableInfo ( ) ) MJTEs = & MF . getJumpTableInfo ( ) -> getJumpTables ( ) ; IsPIC = TM . getRelocationModel ( ) == Reloc :: PIC_ ; IsThumb = MF . getInfo < <ISA_LIT>FunctionInfo > ( ) -> isThumbFunction ( ) ; JTI -> Initialize ( MF , IsPIC ) ; MMI = & getAnalysis < MachineModuleInfo > ( ) ; MCE . setModuleInfo ( MMI ) ; do { DEBUG ( errs ( ) << <STR_LIT> << MF . getName ( ) << <STR_LIT> ) ; MCE . startFunction ( MF ) ; for ( MachineFunction :: iterator MBB = MF . begin ( ) , E = MF . end ( ) ; MBB != E ; ++ MBB ) { MCE . StartMachineBasicBlock ( MBB ) ; for ( MachineBasicBlock :: iterator I = MBB -> begin ( ) , E = MBB -> end ( ) ; I != E ; ++ I ) emitInstruction ( * I ) ; } } while ( MCE . finishFunction ( MF ) ) ;


<s> Val &= <NUM_LIT> ; Val |= <NUM_LIT> ; }


<s> auto ZExt = cast < ZExtInst > ( V ) ; if ( ZExt -> getDestTy ( ) != ExtTy ) continue ; Value * Src = ZExt -> getOperand ( <NUM_LIT> ) ; if ( ZExt -> getSrcTy ( ) == ZExt -> getDestTy ( ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * ZExt << <STR_LIT> ) ; ReplaceAllUsersOfWith ( ZExt , Src ) ; continue ; } if ( NewInsts . count ( Src ) && isa < TruncInst > ( Src ) && Src -> getType ( ) == OrigTy ) { auto * Trunc = cast < TruncInst > ( Src ) ; assert ( Trunc -> getOperand ( <NUM_LIT> ) -> getType ( ) == ExtTy && <STR_LIT> ) ; ReplaceAllUsersOfWith ( ZExt , Trunc -> getOperand ( <NUM_LIT> ) ) ; } } for ( auto * I : InstsToRemove ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * I << <STR_LIT> ) ; I -> dropAllReferences ( ) ; I -> eraseFromParent ( ) ; } InstsToRemove . clear ( ) ; NewInsts . clear ( ) ; TruncTysMap . clear ( ) ; Promoted . clear ( ) ;


<s> ConstantInt * Mask = ConstantInt :: get ( SrcTy , APInt :: getMaxValue ( NumBits ) . getZExtValue ( ) ) ; Value * Masked = Builder . CreateAnd ( Trunc -> getOperand ( <NUM_LIT> ) , Mask ) ; if ( auto * I = dyn_cast < Instruction > ( Masked ) ) NewInsts . insert ( I ) ; ReplaceAllUsersOfWith ( Trunc , Masked ) ; }


<s> Builder . SetInsertPoint ( Trunc ) ; IntegerType * SrcTy = cast < IntegerType > ( Trunc -> getOperand ( <NUM_LIT> ) -> getType ( ) ) ; IntegerType * DestTy = cast < IntegerType > ( TruncTysMap [ Trunc ] [ <NUM_LIT> ] ) ; unsigned NumBits = DestTy -> getScalarSizeInBits ( ) ;

ConstantInt * Mask = ConstantInt :: get ( SrcTy , APInt :: getMaxValue ( NumBits ) . getZExtValue ( ) ) ;


<s> static bool EqualTypeSize ( Value * V ) {

return V -> getType ( ) -> getScalarSizeInBits ( ) == <ISA_LIT>CodeGenPrepare :: TypeSize ;


<s> return V -> getType ( ) -> getScalarSizeInBits ( ) == <ISA_LIT>CodeGenPrepare :: TypeSize ;


<s> } ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto V : * Sources ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; if ( auto * I = dyn_cast < Instruction > ( V ) ) InsertZExt ( I , I ) ; else if ( auto * Arg = dyn_cast < Argument > ( V ) ) { BasicBlock & BB = Arg -> getParent ( ) -> front ( ) ; InsertZExt ( Arg , & * BB . getFirstInsertionPt ( ) ) ; } else { llvm_unreachable ( <STR_LIT> ) ; } Promoted . insert ( V ) ; }


<s> void IRPromoter :: ExtendSources ( ) { IRBuilder < > Builder { Ctx } ; auto InsertZExt = [ & ] ( Value * V , Instruction * InsertPt ) { assert ( V -> getType ( ) != ExtTy && <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; Builder . SetInsertPoint ( InsertPt ) ; if ( auto * I = dyn_cast < Instruction > ( V ) ) Builder . SetCurrentDebugLocation ( I -> getDebugLoc ( ) ) ; Value * ZExt = Builder . CreateZExt ( V , ExtTy ) ; if ( auto * I = dyn_cast < Instruction > ( ZExt ) ) { if ( isa < Argument > ( V ) ) I -> moveBefore ( InsertPt ) ; else I -> moveAfter ( InsertPt ) ; NewInsts . insert ( I ) ; } ReplaceAllUsersOfWith ( V , ZExt ) ; } ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto V : * Sources ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; if ( auto * I = dyn_cast < Instruction > ( V ) ) InsertZExt ( I , I ) ; else if ( auto * Arg = dyn_cast < Argument > ( V ) ) { BasicBlock & BB = Arg -> getParent ( ) -> front ( ) ; InsertZExt ( Arg , & * BB . getFirstInsertionPt ( ) ) ; } else { llvm_unreachable ( <STR_LIT> ) ; } Promoted . insert ( V ) ;


<s> unsigned Opc = cast < Instruction > ( V ) -> getOpcode ( ) ;

return Opc == Instruction :: AShr || Opc == Instruction :: SDiv || Opc == Instruction :: SRem || Opc == Instruction :: SExt ;


<s> if ( ! isa < Instruction > ( V ) ) return false ;

unsigned Opc = cast < Instruction > ( V ) -> getOpcode ( ) ;


<s> IRPromoter ( Module * M ) : M ( M ) , Ctx ( M -> getContext ( ) ) , ExtTy ( Type :: getInt32Ty ( Ctx ) ) {


<s> return true ; } if ( I -> getOpcode ( ) != Instruction :: Add && I -> getOpcode ( ) != Instruction :: Sub ) return false ; if ( ! ST -> hasDSP ( ) || ! EnableDSP || ! isSupportedType ( I ) ) return false ; if ( ST -> isThumb ( ) && ! ST -> hasThumb2 ( ) ) return false ; for ( auto & Op : I -> operands ( ) ) { if ( isa < Constant > ( Op ) ) { if ( ! EnableDSPWithImms ) return false ;


<s> if ( GenerateSignBits ( V ) ) return false ;

if ( ! isa < Instruction > ( V ) ) return true ;


<s> ConstantInt * OverflowConst = cast < ConstantInt > ( I -> getOperand ( <NUM_LIT> ) ) ; bool NegImm = OverflowConst -> isNegative ( ) ; bool IsDecreasing = ( ( Opc == Instruction :: Sub ) && ! NegImm ) || ( ( Opc == Instruction :: Add ) && NegImm ) ; if ( ! IsDecreasing ) return false ; auto * CI = cast < ICmpInst > ( * I -> user_begin ( ) ) ; if ( CI -> isSigned ( ) || CI -> isEquality ( ) ) return false ; ConstantInt * ICmpConst = nullptr ; if ( auto * Const = dyn_cast < ConstantInt > ( CI -> getOperand ( <NUM_LIT> ) ) ) ICmpConst = Const ; else if ( auto * Const = dyn_cast < ConstantInt > ( CI -> getOperand ( <NUM_LIT> ) ) ) ICmpConst = Const ; else return false ; APInt Total = ICmpConst -> getValue ( ) . getBitWidth ( ) < <NUM_LIT> ? ICmpConst -> getValue ( ) . zext ( <NUM_LIT> ) : ICmpConst -> getValue ( ) ; Total += OverflowConst -> getValue ( ) . getBitWidth ( ) < <NUM_LIT> ? OverflowConst -> getValue ( ) . abs ( ) . zext ( <NUM_LIT> ) : OverflowConst -> getValue ( ) . abs ( ) ;

APInt Max = APInt :: getAllOnesValue ( <ISA_LIT>CodeGenPrepare :: TypeSize ) ;


<s> if ( auto * Store = dyn_cast < StoreInst > ( V ) ) return LessOrEqualTypeSize ( Store -> getValueOperand ( ) ) ; if ( auto * Return = dyn_cast < ReturnInst > ( V ) ) return LessOrEqualTypeSize ( Return -> getReturnValue ( ) ) ; if ( auto * ZExt = dyn_cast < ZExtInst > ( V ) ) return GreaterThanTypeSize ( ZExt ) ; if ( auto * Switch = dyn_cast < SwitchInst > ( V ) ) return LessThanTypeSize ( Switch -> getCondition ( ) ) ; if ( auto * ICmp = dyn_cast < ICmpInst > ( V ) ) return ICmp -> isSigned ( ) || LessThanTypeSize ( ICmp -> getOperand ( <NUM_LIT> ) ) ; return isa < CallInst > ( V ) ;


<s> if ( auto * Switch = dyn_cast < SwitchInst > ( V ) ) return LessThanTypeSize ( Switch -> getCondition ( ) ) ; if ( auto * ICmp = dyn_cast < ICmpInst > ( V ) ) return ICmp -> isSigned ( ) || LessThanTypeSize ( ICmp -> getOperand ( <NUM_LIT> ) ) ; return isa < CallInst > ( V ) ;


<s> static bool isSource ( Value * V ) { if ( ! isa < IntegerType > ( V -> getType ( ) ) ) return false ; if ( isa < Argument > ( V ) ) return true ; else if ( isa < LoadInst > ( V ) ) return true ;

else if ( isa < BitCastInst > ( V ) ) return true ;


<s> Type * Ty = V -> getType ( ) ; if ( Ty -> isVoidTy ( ) || Ty -> isPointerTy ( ) ) return true ;

if ( auto * Ld = dyn_cast < LoadInst > ( V ) ) Ty = cast < PointerType > ( Ld -> getPointerOperandType ( ) ) -> getElementType ( ) ;


<s> if ( ! isa < IntegerType > ( Ty ) || cast < IntegerType > ( V -> getType ( ) ) -> getBitWidth ( ) == <NUM_LIT> ) return false ; return LessOrEqualTypeSize ( V ) ;


<s> case Instruction :: Load : case Instruction :: Trunc : case Instruction :: BitCast : return isSupportedType ( I ) ; case Instruction :: ZExt : return isSupportedType ( I -> getOperand ( <NUM_LIT> ) ) ; case Instruction :: ICmp : if ( isa < PointerType > ( I -> getOperand ( <NUM_LIT> ) -> getType ( ) ) ) return true ; return EqualTypeSize ( I -> getOperand ( <NUM_LIT> ) ) ; case Instruction :: Call : { auto * Call = cast < CallInst > ( I ) ; return isSupportedType ( Call ) && Call -> hasRetAttr ( Attribute :: AttrKind :: ZExt ) ;


<s> return V -> getType ( ) -> getScalarSizeInBits ( ) <= <ISA_LIT>CodeGenPrepare :: TypeSize ;


<s> if ( auto * Call = dyn_cast < CallInst > ( I ) ) { for ( unsigned i = <NUM_LIT> ; i < Call -> getNumArgOperands ( ) ; ++ i ) { Value * Arg = Call -> getArgOperand ( i ) ; TruncTysMap [ Call ] . push_back ( Arg -> getType ( ) ) ; } } else if ( auto * Switch = dyn_cast < SwitchInst > ( I ) ) TruncTysMap [ I ] . push_back ( Switch -> getCondition ( ) -> getType ( ) ) ; else { for ( unsigned i = <NUM_LIT> ; i < I -> getNumOperands ( ) ; ++ i ) TruncTysMap [ I ] . push_back ( I -> getOperand ( i ) -> getType ( ) ) ; } } for ( auto * V : Visited ) { if ( ! isa < TruncInst > ( V ) || Sources . count ( V ) ) continue ; auto * Trunc = cast < TruncInst > ( V ) ; TruncTysMap [ Trunc ] . push_back ( Trunc -> getDestTy ( ) ) ; } PrepareWrappingAdds ( ) ;


<s> auto Const = cast < ConstantInt > ( I -> getOperand ( <NUM_LIT> ) ) ; auto * NewConst = ConstantInt :: get ( Ctx , Const -> getValue ( ) . abs ( ) ) ; Builder . SetInsertPoint ( I ) ; Value * NewVal = Builder . CreateSub ( I -> getOperand ( <NUM_LIT> ) , NewConst ) ; if ( auto * NewInst = dyn_cast < Instruction > ( NewVal ) ) { NewInst -> copyIRFlags ( I ) ; NewInsts . insert ( NewInst ) ; } InstsToRemove . insert ( I ) ;


<s> if ( shouldPromote ( I ) ) { I -> mutateType ( ExtTy ) ; Promoted . insert ( I ) ; } } for ( auto * V : * Visited ) { auto * I = dyn_cast < Instruction > ( V ) ; if ( ! I ) continue ; if ( Sources -> count ( I ) || Sinks -> count ( I ) ) continue ; if ( ! shouldPromote ( I ) || SafeToPromote -> count ( I ) || NewInsts . count ( I ) ) continue ; assert ( EnableDSP && <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * I << <STR_LIT> ) ; Function * DSPInst = <STR_LIT> ( M , getNarrowIntrinsic ( I ) ) ; Builder . SetInsertPoint ( I ) ; Builder . SetCurrentDebugLocation ( I -> getDebugLoc ( ) ) ;

Value * Args [ ] = { I -> getOperand ( <NUM_LIT> ) , I -> getOperand ( <NUM_LIT> ) } ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * From << <STR_LIT> << * To << <STR_LIT> ) ; for ( Use & U : From -> uses ( ) ) { auto * User = cast < Instruction > ( U . getUser ( ) ) ; if ( InstTo && User -> isIdenticalTo ( InstTo ) ) { ReplacedAll = false ; continue ; }


<s> for ( Use & U : From -> uses ( ) ) { auto * User = cast < Instruction > ( U . getUser ( ) ) ; if ( InstTo && User -> isIdenticalTo ( InstTo ) ) { ReplacedAll = false ; continue ; } Users . push_back ( User ) ; } for ( auto * U : Users ) U -> replaceUsesOfWith ( From , To ) ; if ( ReplacedAll ) if ( auto * I = dyn_cast < Instruction > ( From ) ) InstsToRemove . insert ( I ) ;


<s> if ( AllVisited . count ( & I ) ) continue ; if ( isa < ICmpInst > ( I ) ) { auto & CI = cast < ICmpInst > ( I ) ; if ( CI . isSigned ( ) || ! isa < IntegerType > ( CI . getOperand ( <NUM_LIT> ) -> getType ( ) ) ) continue ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << CI << <STR_LIT> ) ;


<s> bool <ISA_LIT>CodeGenPrepare :: runOnFunction ( Function & F ) { if ( skipFunction ( F ) || DisableCGP ) return false ; auto * TPC = & getAnalysis < TargetPassConfig > ( ) ; if ( ! TPC ) return false ; const TargetMachine & TM = TPC -> getTM < TargetMachine > ( ) ; ST = & TM . getSubtarget < <ISA_LIT>Subtarget > ( F ) ; bool MadeChange = false ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << F . getName ( ) << <STR_LIT> ) ; for ( BasicBlock & BB : F ) { auto & Insts = BB . getInstList ( ) ; for ( auto & I : Insts ) { if ( AllVisited . count ( & I ) ) continue ; if ( isa < ICmpInst > ( I ) ) { auto & CI = cast < ICmpInst > ( I ) ; if ( CI . isSigned ( ) || ! isa < IntegerType > ( CI . getOperand ( <NUM_LIT> ) -> getType ( ) ) ) continue ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << CI << <STR_LIT> ) ; for ( auto & Op : CI . operands ( ) ) {

if ( auto * I = dyn_cast < Instruction > ( Op ) ) MadeChange |= TryToPromote ( I ) ;


<s> if ( isSource ( V ) ) return true ; auto * I = dyn_cast < Instruction > ( V ) ;


<s> auto * Trunc = dyn_cast < Instruction > ( Builder . CreateTrunc ( V , TruncTy ) ) ; if ( Trunc ) NewInsts . insert ( Trunc ) ; return Trunc ; } ; for ( auto I : * Sinks ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * I << <STR_LIT> ) ; if ( auto * Call = dyn_cast < CallInst > ( I ) ) { for ( unsigned i = <NUM_LIT> ; i < Call -> getNumArgOperands ( ) ; ++ i ) { Value * Arg = Call -> getArgOperand ( i ) ; Type * Ty = TruncTysMap [ Call ] [ i ] ; if ( Instruction * Trunc = InsertTrunc ( Arg , Ty ) ) { Trunc -> moveBefore ( Call ) ;


<s> SetVector < Value * > CurrentVisited ; WorkList . insert ( V ) ; auto AddLegalInst = [ & ] ( Value * V ) { if ( CurrentVisited . count ( V ) ) return true ; if ( isa < GetElementPtrInst > ( V ) ) return true ; if ( ! isSupportedValue ( V ) || ( shouldPromote ( V ) && ! isLegalToPromote ( V ) ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; return false ; } WorkList . insert ( V ) ; return true ; } ; while ( ! WorkList . empty ( ) ) { Value * V = WorkList . back ( ) ; WorkList . pop_back ( ) ; if ( CurrentVisited . count ( V ) ) continue ; if ( ! isa < Instruction > ( V ) && ! isSource ( V ) ) continue ; if ( AllVisited . count ( V ) ) return false ; CurrentVisited . insert ( V ) ; AllVisited . insert ( V ) ; if ( isSink ( V ) ) Sinks . insert ( cast < Instruction > ( V ) ) ; if ( isSource ( V ) ) Sources . insert ( V ) ; if ( ! isSink ( V ) && ! isSource ( V ) ) { if ( auto * I = dyn_cast < Instruction > ( V ) ) { for ( auto & U : I -> operands ( ) ) { if ( ! AddLegalInst ( U ) ) return false ; } }


<s> static bool isSafeOverflow ( Instruction * I ) { if ( isa < OverflowingBinaryOperator > ( I ) && I -> hasNoUnsignedWrap ( ) ) return true ; unsigned Opc = I -> getOpcode ( ) ; if ( Opc != Instruction :: Add && Opc != Instruction :: Sub ) return false ; if ( ! I -> hasOneUse ( ) || ! isa < ICmpInst > ( * I -> user_begin ( ) ) || ! isa < ConstantInt > ( I -> getOperand ( <NUM_LIT> ) ) ) return false ; ConstantInt * OverflowConst = cast < ConstantInt > ( I -> getOperand ( <NUM_LIT> ) ) ; bool NegImm = OverflowConst -> isNegative ( ) ; bool IsDecreasing = ( ( Opc == Instruction :: Sub ) && ! NegImm ) || ( ( Opc == Instruction :: Add ) && NegImm ) ; if ( ! IsDecreasing ) return false ; auto * CI = cast < ICmpInst > ( * I -> user_begin ( ) ) ; if ( CI -> isSigned ( ) || CI -> isEquality ( ) ) return false ; ConstantInt * ICmpConst = nullptr ; if ( auto * Const = dyn_cast < ConstantInt > ( CI -> getOperand ( <NUM_LIT> ) ) ) ICmpConst = Const ; else if ( auto * Const = dyn_cast < ConstantInt > ( CI -> getOperand ( <NUM_LIT> ) ) ) ICmpConst = Const ; else return false ; APInt Total = ICmpConst -> getValue ( ) . getBitWidth ( ) < <NUM_LIT> ? ICmpConst -> getValue ( ) . zext ( <NUM_LIT> ) : ICmpConst -> getValue ( ) ; Total += OverflowConst -> getValue ( ) . getBitWidth ( ) < <NUM_LIT> ? OverflowConst -> getValue ( ) . abs ( ) . zext ( <NUM_LIT> ) : OverflowConst -> getValue ( ) . abs ( ) ; APInt Max = APInt :: getAllOnesValue ( <ISA_LIT>CodeGenPrepare :: TypeSize ) ; if ( Total . getBitWidth ( ) > Max . getBitWidth ( ) ) {

if ( Total . ugt ( Max . zext ( Total . getBitWidth ( ) ) ) ) return false ;


<s> static bool isSource ( Value * V ) { if ( ! isa < IntegerType > ( V -> getType ( ) ) ) return false ; if ( isa < Argument > ( V ) ) return true ;

else if ( isa < LoadInst > ( V ) ) return true ;


<s> const IntegerType * IntTy = dyn_cast < IntegerType > ( Ty ) ; if ( ! IntTy ) return false ;

return IntTy -> getBitWidth ( ) == <ISA_LIT>CodeGenPrepare :: TypeSize ;


<s> if ( isa < StoreInst > ( V ) || isa < GetElementPtrInst > ( V ) ) return true ; if ( isa < BranchInst > ( V ) || isa < SwitchInst > ( V ) || isa < BasicBlock > ( V ) ) return true ; if ( ( isa < Constant > ( V ) && ! isa < ConstantExpr > ( V ) ) || isa < Argument > ( V ) ) return isSupportedType ( V ) ; if ( isa < PHINode > ( V ) || isa < SelectInst > ( V ) || isa < ReturnInst > ( V ) || isa < LoadInst > ( V ) ) return isSupportedType ( V ) ; if ( auto * Trunc = dyn_cast < TruncInst > ( V ) ) return isSupportedType ( Trunc ) || isSupportedType ( Trunc -> getOperand ( <NUM_LIT> ) ) ; if ( isa < CastInst > ( V ) && ! isa < SExtInst > ( V ) ) return isSupportedType ( cast < CastInst > ( V ) -> getOperand ( <NUM_LIT> ) ) ; if ( auto * Call = dyn_cast < CallInst > ( V ) ) return isSupportedType ( Call ) && Call -> hasRetAttr ( Attribute :: AttrKind :: ZExt ) ; if ( ! isa < BinaryOperator > ( V ) ) return false ; if ( ! isSupportedType ( V ) ) return false ;


<s> TruncTysMap [ ZExt ] = TruncTysMap [ V ] ; } ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto V : Sources ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; if ( auto * I = dyn_cast < Instruction > ( V ) ) InsertZExt ( I , I ) ; else if ( auto * Arg = dyn_cast < Argument > ( V ) ) { BasicBlock & BB = Arg -> getParent ( ) -> front ( ) ; InsertZExt ( Arg , & * BB . getFirstInsertionPt ( ) ) ; } else { llvm_unreachable ( <STR_LIT> ) ; } Promoted . insert ( V ) ; } LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto * V : Visited ) { if ( Sources . count ( V ) ) continue ; auto * I = cast < Instruction > ( V ) ; if ( Sinks . count ( I ) ) continue ; for ( unsigned i = <NUM_LIT> , e = I -> getNumOperands ( ) ; i < e ; ++ i ) { Value * Op = I -> getOperand ( i ) ; if ( ( Op -> getType ( ) == ExtTy ) || ! isa < IntegerType > ( Op -> getType ( ) ) ) continue ; if ( auto * Const = dyn_cast < ConstantInt > ( Op ) ) FixConst ( Const , I ) ; else if ( isa < UndefValue > ( Op ) ) I -> setOperand ( i , UndefValue :: get ( ExtTy ) ) ; } if ( shouldPromote ( I ) ) { I -> mutateType ( ExtTy ) ; Promoted . insert ( I ) ; } } for ( auto * V : Visited ) { if ( Sources . count ( V ) ) continue ; if ( ! shouldPromote ( V ) || isPromotedResultSafe ( V ) ) continue ; assert ( EnableDSP && <STR_LIT> ) ; InsertDSPIntrinsic ( cast < Instruction > ( V ) ) ; } auto InsertTrunc = [ & ] ( Value * V ) -> Instruction * { if ( ! isa < Instruction > ( V ) || ! isa < IntegerType > ( V -> getType ( ) ) ) return nullptr ; if ( ( ! Promoted . count ( V ) && ! NewInsts . count ( V ) ) || ! TruncTysMap . count ( V ) || Sources . count ( V ) ) return nullptr ; Type * TruncTy = TruncTysMap [ V ] ;

if ( TruncTy == ExtTy ) return nullptr ;


<s> if ( AllVisited . count ( & I ) ) continue ; if ( isa < ICmpInst > ( I ) ) { auto & CI = cast < ICmpInst > ( I ) ; if ( CI . isSigned ( ) || ! isa < IntegerType > ( CI . getOperand ( <NUM_LIT> ) -> getType ( ) ) ) continue ; for ( auto & Op : CI . operands ( ) ) { if ( auto * I = dyn_cast < Instruction > ( Op ) ) MadeChange |= TryToPromote ( I ) ; } } } Promoter -> Cleanup ( ) ; LLVM_DEBUG ( if ( verifyFunction ( F , & dbgs ( ) ) ) { dbgs ( ) ;


<s> for ( auto & I : Insts ) { if ( AllVisited . count ( & I ) ) continue ; if ( isa < ICmpInst > ( I ) ) { auto & CI = cast < ICmpInst > ( I ) ; if ( CI . isSigned ( ) || ! isa < IntegerType > ( CI . getOperand ( <NUM_LIT> ) -> getType ( ) ) ) continue ; for ( auto & Op : CI . operands ( ) ) { if ( auto * I = dyn_cast < Instruction > ( Op ) ) MadeChange |= TryToPromote ( I ) ; }


<s> SmallPtrSet < Instruction * , <NUM_LIT> > Sinks ; WorkList . insert ( V ) ; SmallPtrSet < Value * , <NUM_LIT> > CurrentVisited ; CurrentVisited . clear ( ) ; auto AddLegalInst = [ & ] ( Value * V ) { if ( CurrentVisited . count ( V ) ) return true ; if ( isa < GetElementPtrInst > ( V ) ) return true ; if ( ! isSupportedValue ( V ) || ( shouldPromote ( V ) && ! isLegalToPromote ( V ) ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; return false ; } WorkList . insert ( V ) ; return true ; } ; while ( ! WorkList . empty ( ) ) { Value * V = WorkList . back ( ) ; WorkList . pop_back ( ) ; if ( CurrentVisited . count ( V ) ) continue ; if ( ! isa < Instruction > ( V ) && ! isSource ( V ) ) continue ; if ( AllVisited . count ( V ) ) return false ; CurrentVisited . insert ( V ) ; AllVisited . insert ( V ) ; if ( isSink ( V ) ) Sinks . insert ( cast < Instruction > ( V ) ) ;

if ( isSource ( V ) ) Sources . insert ( V ) ;


<s> if ( CurrentVisited . count ( V ) ) return true ; if ( isa < GetElementPtrInst > ( V ) ) return true ; if ( ! isSupportedValue ( V ) || ( shouldPromote ( V ) && ! isLegalToPromote ( V ) ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; return false ; } WorkList . insert ( V ) ; return true ; } ; while ( ! WorkList . empty ( ) ) { Value * V = WorkList . back ( ) ; WorkList . pop_back ( ) ; if ( CurrentVisited . count ( V ) ) continue ; if ( ! isa < Instruction > ( V ) && ! isSource ( V ) ) continue ; if ( AllVisited . count ( V ) ) return false ; CurrentVisited . insert ( V ) ; AllVisited . insert ( V ) ; if ( isSink ( V ) ) Sinks . insert ( cast < Instruction > ( V ) ) ; if ( isSource ( V ) ) Sources . insert ( V ) ; else if ( auto * I = dyn_cast < Instruction > ( V ) ) { for ( auto & U : I -> operands ( ) ) { if ( ! AddLegalInst ( U ) ) return false ; } } if ( isSource ( V ) || shouldPromote ( V ) ) { for ( Use & U : V -> uses ( ) ) { if ( ! AddLegalInst ( U . getUser ( ) ) ) return false ; } }


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto V : Sources ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; if ( auto * I = dyn_cast < Instruction > ( V ) ) InsertZExt ( I , I ) ; else if ( auto * Arg = dyn_cast < Argument > ( V ) ) { BasicBlock & BB = Arg -> getParent ( ) -> front ( ) ; InsertZExt ( Arg , & * BB . getFirstInsertionPt ( ) ) ;


<s> if ( generateSignBits ( V ) ) return false ; auto * I = cast < Instruction > ( V ) ; if ( I -> hasOneUse ( ) && isSink ( * I -> use_begin ( ) ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ;


<s> if ( generateSignBits ( V ) ) return false ; auto * I = cast < Instruction > ( V ) ; if ( I -> hasOneUse ( ) && isSink ( * I -> use_begin ( ) ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; return true ; }

if ( isa < OverflowingBinaryOperator > ( I ) ) return false ;


<s> bool IsDecreasing = ( ( Opc == Instruction :: Sub ) && ! NegImm ) || ( ( Opc == Instruction :: Add ) && NegImm ) ; if ( ! IsDecreasing ) return false ; auto * CI = cast < ICmpInst > ( * I -> user_begin ( ) ) ; if ( CI -> isSigned ( ) || CI -> isEquality ( ) ) return false ; ConstantInt * ICmpConst = nullptr ; if ( auto * Const = dyn_cast < ConstantInt > ( CI -> getOperand ( <NUM_LIT> ) ) ) ICmpConst = Const ; else if ( auto * Const = dyn_cast < ConstantInt > ( CI -> getOperand ( <NUM_LIT> ) ) ) ICmpConst = Const ; else return false ; APInt Total = ICmpConst -> getValue ( ) . getBitWidth ( ) < <NUM_LIT> ? ICmpConst -> getValue ( ) . zext ( <NUM_LIT> ) : ICmpConst -> getValue ( ) ; Total += OverflowConst -> getValue ( ) . getBitWidth ( ) < <NUM_LIT> ? OverflowConst -> getValue ( ) . abs ( ) . zext ( <NUM_LIT> ) : OverflowConst -> getValue ( ) . abs ( ) ; APInt Max = APInt :: getAllOnesValue ( <ISA_LIT>CodeGenPrepare :: TypeSize ) ; if ( Total . getBitWidth ( ) > Max . getBitWidth ( ) ) { if ( Total . ugt ( Max . zext ( Total . getBitWidth ( ) ) ) ) return false ; } else if ( Max . getBitWidth ( ) > Total . getBitWidth ( ) ) {

if ( Total . zext ( Max . getBitWidth ( ) ) . ugt ( Max ) ) return false ;


<s> PromoteTree ( Visited , Sources , Sinks , SafeToPromote ) ; TruncateSinks ( Sources , Sinks ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) ; for ( auto * V : Sources ) V -> dump ( ) ; for ( auto * I : NewInsts ) I -> dump ( ) ; for ( auto * V : Visited ) { if ( ! Sources . count ( V ) ) V -> dump ( ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) ; for ( auto * V : Sources ) V -> dump ( ) ; for ( auto * I : NewInsts ) I -> dump ( ) ; for ( auto * V : Visited ) { if ( ! Sources . count ( V ) ) V -> dump ( ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * I << <STR_LIT> ) ; auto * NewConst = ConstantInt :: get ( Ctx , Const -> getValue ( ) . abs ( ) ) ; Builder . SetInsertPoint ( I ) ; Value * NewVal = Opc == Instruction :: Sub ? Builder . CreateAdd ( I -> getOperand ( <NUM_LIT> ) , NewConst ) : Builder . CreateSub ( I -> getOperand ( <NUM_LIT> ) , NewConst ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * NewVal << <STR_LIT> ) ; if ( auto * NewInst = dyn_cast < Instruction > ( NewVal ) ) { NewInst -> copyIRFlags ( I ) ; NewInsts . insert ( NewInst ) ; } InstsToRemove . push_back ( I ) ; I -> replaceAllUsesWith ( NewVal ) ; } } } for ( auto * I : NewInsts ) Visited . insert ( I ) ;


<s> Value * Op = I -> getOperand ( i ) ; if ( ( Op -> getType ( ) == ExtTy ) || ! isa < IntegerType > ( Op -> getType ( ) ) ) continue ; if ( auto * Const = dyn_cast < ConstantInt > ( Op ) ) { Constant * NewConst = ConstantExpr :: getZExt ( Const , ExtTy ) ; I -> setOperand ( i , NewConst ) ; } else if ( isa < UndefValue > ( Op ) ) I -> setOperand ( i , UndefValue :: get ( ExtTy ) ) ; } if ( shouldPromote ( I ) ) { I -> mutateType ( ExtTy ) ; Promoted . insert ( I ) ; } } for ( auto * V : Visited ) { auto * I = dyn_cast < Instruction > ( V ) ; if ( ! I ) continue ; if ( Sources . count ( I ) || Sinks . count ( I ) ) continue ;

if ( ! shouldPromote ( I ) || SafeToPromote . count ( I ) || NewInsts . count ( I ) ) continue ;


<s> static void ReplaceAllUsersOfWith ( Value * From , Value * To ) { SmallVector < Instruction * , <NUM_LIT> > Users ; Instruction * InstTo = dyn_cast < Instruction > ( To ) ; for ( Use & U : From -> uses ( ) ) { auto * User = cast < Instruction > ( U . getUser ( ) ) ; if ( InstTo && User -> isIdenticalTo ( InstTo ) ) continue ; Users . push_back ( User ) ; } for ( auto * U : Users ) U -> replaceUsesOfWith ( From , To ) ;


<s> SmallVector < Instruction * , <NUM_LIT> > Users ; Instruction * InstTo = dyn_cast < Instruction > ( To ) ; for ( Use & U : From -> uses ( ) ) {

auto * User = cast < Instruction > ( U . getUser ( ) ) ;


<s> IRBuilder < > Builder { Ctx } ; auto InsertTrunc = [ & ] ( Value * V ) -> Instruction * { if ( ! isa < Instruction > ( V ) || ! isa < IntegerType > ( V -> getType ( ) ) ) return nullptr ; if ( ( ! Promoted . count ( V ) && ! NewInsts . count ( V ) ) || ! TruncTysMap . count ( V ) || Sources . count ( V ) ) return nullptr ; Type * TruncTy = TruncTysMap [ V ] ; if ( TruncTy == ExtTy ) return nullptr ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * TruncTy << <STR_LIT> << * V << <STR_LIT> ) ; Builder . SetInsertPoint ( cast < Instruction > ( V ) ) ; auto * Trunc = dyn_cast < Instruction > ( Builder . CreateTrunc ( V , TruncTy ) ) ; if ( Trunc ) NewInsts . insert ( Trunc ) ; return Trunc ; } ; for ( auto I : Sinks ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * I << <STR_LIT> ) ; if ( auto * Call = dyn_cast < CallInst > ( I ) ) { for ( unsigned i = <NUM_LIT> ; i < Call -> getNumArgOperands ( ) ; ++ i ) { Value * Arg = Call -> getArgOperand ( i ) ; if ( Instruction * Trunc = InsertTrunc ( Arg ) ) { Trunc -> moveBefore ( Call ) ; Call -> setArgOperand ( i , Trunc ) ; } } continue ; } for ( unsigned i = <NUM_LIT> ; i < I -> getNumOperands ( ) ; ++ i ) { if ( Instruction * Trunc = InsertTrunc ( I -> getOperand ( i ) ) ) {


<s> if ( CurrentVisited . count ( V ) ) return true ; if ( isa < GetElementPtrInst > ( V ) ) return true ; if ( ! isSupportedValue ( V ) || ( shouldPromote ( V ) && ! isLegalToPromote ( V ) ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; return false ; } WorkList . insert ( V ) ; return true ; } ; while ( ! WorkList . empty ( ) ) { Value * V = WorkList . back ( ) ; WorkList . pop_back ( ) ; if ( CurrentVisited . count ( V ) ) continue ; if ( ! isa < Instruction > ( V ) && ! isSource ( V ) ) continue ; if ( AllVisited . count ( V ) ) return false ; CurrentVisited . insert ( V ) ; AllVisited . insert ( V ) ; if ( isSink ( V ) ) Sinks . insert ( cast < Instruction > ( V ) ) ; if ( isSource ( V ) ) Sources . insert ( V ) ; else if ( auto * I = dyn_cast < Instruction > ( V ) ) { for ( auto & U : I -> operands ( ) ) { if ( ! AddLegalInst ( U ) ) return false ; } } if ( isSource ( V ) || shouldPromote ( V ) ) { for ( Use & U : V -> uses ( ) ) { if ( ! AddLegalInst ( U . getUser ( ) ) ) return false ; } } } LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ; for ( auto * I : CurrentVisited ) I -> dump ( ) ; ) ; unsigned ToPromote = <NUM_LIT> ; for ( auto * V : CurrentVisited ) { if ( Sources . count ( V ) ) continue ; if ( Sinks . count ( cast < Instruction > ( V ) ) ) continue ; ++ ToPromote ;


<s> case Instruction :: Add : return TypeSize == <NUM_LIT> ? <STR_LIT> : <STR_LIT> ; case Instruction :: Sub : return TypeSize == <NUM_LIT> ? <STR_LIT> : <STR_LIT> ;


<s> unsigned VSize = <NUM_LIT> ; if ( auto * Ld = dyn_cast < LoadInst > ( V ) ) { auto * PtrTy = cast < PointerType > ( Ld -> getPointerOperandType ( ) ) ; VSize = PtrTy -> getElementType ( ) -> getPrimitiveSizeInBits ( ) ; } else if ( auto * ZExt = dyn_cast < ZExtInst > ( V ) ) { VSize = ZExt -> getOperand ( <NUM_LIT> ) -> getType ( ) -> getPrimitiveSizeInBits ( ) ;


<s> bool <ISA_LIT>CodeGenPrepare :: isNarrowInstSupported ( Instruction * I ) { if ( ! ST -> hasDSP ( ) || ! EnableDSP || ! isSupportedType ( I ) ) return false ; if ( ST -> isThumb ( ) && ! ST -> hasThumb2 ( ) ) return false ;

if ( I -> getOpcode ( ) != Instruction :: Add && I -> getOpcode ( ) != Instruction :: Sub ) return false ;


<s> static bool isPromotedResultSafe ( Value * V ) { if ( ! isa < Instruction > ( V ) ) return true ; if ( isSigned ( V ) ) return false ; auto * I = cast < Instruction > ( V ) ; if ( I -> hasOneUse ( ) && isSink ( * I -> use_begin ( ) ) ) return true ; if ( isa < OverflowingBinaryOperator > ( I ) ) return isSafeOverflow ( I ) ; return true ;


<s> unsigned Opc = cast < Instruction > ( V ) -> getOpcode ( ) ;

return Opc == Instruction :: AShr || Opc == Instruction :: SDiv || Opc == Instruction :: SRem ;


<s> if ( ! isa < Instruction > ( V ) ) return false ; unsigned Opc = cast < Instruction > ( V ) -> getOpcode ( ) ; return Opc == Instruction :: AShr || Opc == Instruction :: SDiv || Opc == Instruction :: SRem ;


<s> auto UsesNarrowValue = [ ] ( Value * V ) { return V -> getType ( ) -> getScalarSizeInBits ( ) <= <NUM_LIT> ; } ; if ( auto * Store = dyn_cast < StoreInst > ( V ) ) return UsesNarrowValue ( Store -> getValueOperand ( ) ) ; if ( auto * Return = dyn_cast < ReturnInst > ( V ) ) return UsesNarrowValue ( Return -> getReturnValue ( ) ) ; return isa < CallInst > ( V ) ;


<s> else if ( auto * ZExt = dyn_cast < ZExtInst > ( V ) ) return isa < LoadInst > ( ZExt -> getOperand ( <NUM_LIT> ) ) && ZExt -> getOperand ( <NUM_LIT> ) -> hasOneUse ( ) ;

else if ( auto * Call = dyn_cast < CallInst > ( V ) ) return Call -> hasRetAttr ( Attribute :: AttrKind :: ZExt ) ;


<s> else if ( auto * Load = dyn_cast < LoadInst > ( V ) ) { if ( ! isa < IntegerType > ( Load -> getType ( ) ) ) return false ;

if ( Load -> hasOneUse ( ) && isa < ZExtInst > ( * Load -> use_begin ( ) ) ) return false ;


<s> const IntegerType * IntTy = dyn_cast < IntegerType > ( V -> getType ( ) ) ; if ( ! IntTy ) return false ; if ( IntTy -> getBitWidth ( ) == <NUM_LIT> ) return false ;

if ( auto * ZExt = dyn_cast < ZExtInst > ( V ) ) return isSupportedType ( ZExt -> getOperand ( <NUM_LIT> ) ) ;


<s> if ( isa < BranchInst > ( V ) || isa < SwitchInst > ( V ) || isa < BasicBlock > ( V ) ) return true ; if ( isa < PHINode > ( V ) || isa < SelectInst > ( V ) || isa < ReturnInst > ( V ) ) return true ; if ( auto * Call = dyn_cast < CallInst > ( V ) ) return Call -> hasRetAttr ( Attribute :: AttrKind :: ZExt ) ; else if ( auto * Cast = dyn_cast < CastInst > ( V ) ) { if ( isa < ZExtInst > ( Cast ) ) return Cast -> getDestTy ( ) -> getScalarSizeInBits ( ) <= <NUM_LIT> ; else if ( auto * Trunc = dyn_cast < TruncInst > ( V ) ) return Trunc -> getDestTy ( ) -> getScalarSizeInBits ( ) <= TypeSize ; else { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; return false ; } } else if ( ! isa < BinaryOperator > ( V ) ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ;


<s> if ( isa < ConstantInt > ( V ) || isa < Argument > ( V ) ) return true ; if ( isa < StoreInst > ( V ) || isa < LoadInst > ( V ) || isa < GetElementPtrInst > ( V ) ) return true ; if ( auto * ICmp = dyn_cast < ICmpInst > ( V ) ) return ICmp -> isEquality ( ) || ! ICmp -> isSigned ( ) ; if ( isa < BranchInst > ( V ) || isa < SwitchInst > ( V ) || isa < BasicBlock > ( V ) ) return true ; if ( isa < PHINode > ( V ) || isa < SelectInst > ( V ) || isa < ReturnInst > ( V ) ) return true ; if ( auto * Call = dyn_cast < CallInst > ( V ) ) return Call -> hasRetAttr ( Attribute :: AttrKind :: ZExt ) ; else if ( auto * Cast = dyn_cast < CastInst > ( V ) ) { if ( isa < ZExtInst > ( Cast ) ) return Cast -> getDestTy ( ) -> getScalarSizeInBits ( ) <= <NUM_LIT> ; else if ( auto * Trunc = dyn_cast < TruncInst > ( V ) ) return Trunc -> getDestTy ( ) -> getScalarSizeInBits ( ) <= TypeSize ; else { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ;


<s> NewInsts . insert ( ZExt ) ; } ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto V : Leaves ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * V << <STR_LIT> ) ; if ( auto * ZExt = dyn_cast < ZExtInst > ( V ) ) ZExt -> mutateType ( ExtTy ) ; else if ( auto * I = dyn_cast < Instruction > ( V ) ) InsertZExt ( I , I ) ; else if ( auto * Arg = dyn_cast < Argument > ( V ) ) { BasicBlock & BB = Arg -> getParent ( ) -> front ( ) ; InsertZExt ( Arg , & * BB . getFirstInsertionPt ( ) ) ; } else { llvm_unreachable ( <STR_LIT> ) ; } Promoted . insert ( V ) ; } LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; for ( auto * V : Visited ) { if ( Leaves . count ( V ) ) continue ; if ( ! isa < Instruction > ( V ) ) continue ; auto * I = cast < Instruction > ( V ) ; if ( Roots . count ( I ) ) continue ; for ( auto & U : I -> operands ( ) ) { if ( ( U -> getType ( ) == ExtTy ) || ! isSupportedType ( & * U ) ) continue ; if ( auto * Const = dyn_cast < ConstantInt > ( & * U ) ) FixConst ( Const , I ) ; else if ( isa < UndefValue > ( & * U ) ) U -> mutateType ( ExtTy ) ; } if ( shouldPromote ( I ) ) { I -> mutateType ( ExtTy ) ; Promoted . insert ( I ) ; } } for ( auto * V : Visited ) { if ( Leaves . count ( V ) ) continue ; if ( auto * ZExt = dyn_cast < ZExtInst > ( V ) ) { if ( ZExt -> getDestTy ( ) != ExtTy ) { ZExt -> mutateType ( ExtTy ) ; Promoted . insert ( ZExt ) ; } else if ( ZExt -> getSrcTy ( ) == ExtTy ) { ReplaceAllUsersOfWith ( V , ZExt -> getOperand ( <NUM_LIT> ) ) ; InstsToRemove . push_back ( ZExt ) ; } continue ; } if ( ! shouldPromote ( V ) || isPromotedResultSafe ( V ) ) continue ; InsertDSPIntrinsic ( cast < Instruction > ( V ) ) ;