<s> Value * MemIntrinsicsHandler :: CreateCompositeElemAccessGEP ( IRBuilder < > & IRB , Value * Mem , Type * CompType , Value * * Offset ) { SmallVector < Value * , <NUM_LIT> > Indices ; Indices . push_back ( ConstantInt :: get ( TargetIdxTy , <NUM_LIT> ) ) ;

GetIndicesForCompositeElemAccess ( IRB , Indices , CompType , Offset ) ;


<s> Value * MemIntrinsicsHandler :: CreateGEP ( IRBuilder < > & IRB , Value * I , unsigned i ) { assert ( isa < GetElementPtrInst > ( I ) ) ; GetElementPtrInst * GEP = cast < GetElementPtrInst > ( I ) ; Value * LastIndex = nullptr ; SmallVector < Value * , <NUM_LIT> > Indices ; unsigned IdxCnt = <NUM_LIT> ; for ( auto & Index : GEP -> indices ( ) ) { if ( IdxCnt ++ == ( GEP -> getNumIndices ( ) - <NUM_LIT> ) ) { LastIndex = Index ; break ; } Indices . push_back ( Index ) ; } Value * NewIndex = IRB . CreateAdd ( LastIndex , ConstantInt :: get ( TargetIdxTy , i ) ) ; Indices . push_back ( NewIndex ) ; return IRB . CreateGEP ( GEP -> getPointerOperand ( ) , Indices ) ;


<s> Value * MemIntrinsicsHandler :: GenMask ( IRBuilder < > & IRB , Type * SrcTy , Type * DestTy , Value * Offset , bool IsLoad ) { const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; unsigned SrcSz = DL . getTypeSizeInBits ( SrcTy ) ; unsigned DestSz = DL . getTypeSizeInBits ( DestTy ) ;

return GenMask ( IRB , SrcSz , DestSz , Offset , IsLoad ) ;


<s> Value * MemIntrinsicsHandler :: GenMask ( IRBuilder < > & IRB , Type * SrcTy , Type * DestTy , Value * Offset , bool IsLoad ) { const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ;

unsigned SrcSz = DL . getTypeSizeInBits ( SrcTy ) ;


<s> if ( isa < StructType > ( CompType ) ) { assert ( isa < ConstantInt > ( * Offset ) && <STR_LIT> ) ; unsigned PadOffset = <NUM_LIT> ; unsigned ConstOffset = cast < ConstantInt > ( * Offset ) -> getZExtValue ( ) ; StructType * STy = cast < StructType > ( CompType ) ; const StructLayout * SL = DL . getStructLayout ( STy ) ; int i = GetStructElmIndexAtOffset ( STy , ConstOffset , PadOffset ) ; Indices . push_back ( ConstantInt :: get ( TargetIdxTy , i ) ) ; unsigned ElmOffset = SL -> getElementOffset ( i ) ; Value * ElmOffsetVal = ConstantInt :: get ( TargetIdxTy , ElmOffset ) ; * Offset = IRB . CreateBinOp ( Instruction :: Sub , * Offset , ElmOffsetVal ) ; if ( isa < CompositeType > ( STy -> getTypeAtIndex ( i ) ) ) GetIndicesForCompositeElemAccess ( IRB , Indices , STy -> getTypeAtIndex ( i ) , Offset ) ; } else if ( isa < ArrayType > ( CompType ) ) { Type * ElmTy = cast < ArrayType > ( CompType ) -> getElementType ( ) ; Value * ElmSz = ConstantInt :: get ( TargetIdxTy , DL . getTypeSizeInBits ( ElmTy ) / <NUM_LIT> ) ; Value * Index = IRB . CreateBinOp ( Instruction :: UDiv , * Offset , ElmSz ) ; Indices . push_back ( Index ) ; * Offset = IRB . CreateBinOp ( Instruction :: URem , * Offset , ElmSz ) ; if ( isa < CompositeType > ( ElmTy ) ) GetIndicesForCompositeElemAccess ( IRB , Indices , ElmTy , Offset ) ; } else { Value * CompTypeSz = ConstantInt :: get ( TargetIdxTy , DL . getTypeSizeInBits ( CompType ) / <NUM_LIT> ) ; Value * Index = IRB . CreateBinOp ( Instruction :: UDiv , * Offset , CompTypeSz ) ; Indices . push_back ( Index ) ; * Offset = IRB . CreateBinOp ( Instruction :: Sub , * Offset , CompTypeSz ) ; }


<s> } unsigned ElmSz = DL . getTypeSizeInBits ( STy -> getTypeAtIndex ( ElmIdx ) ) / <NUM_LIT> ; if ( SL -> hasPadding ( ) && ( Offset - SL -> getElementOffset ( ElmIdx ) ) > ElmSz ) { unsigned Alignment = SL -> getAlignment ( ) ; PadOffset = Alignment - ( ( Offset - SL -> getElementOffset ( ElmIdx ) ) ) ; }


<s> unsigned i = <NUM_LIT> ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; const StructLayout * SL = DL . getStructLayout ( STy ) ; unsigned ElmIdx = <NUM_LIT> ; for ( ; i < STy -> getNumElements ( ) ; i ++ ) { ElmIdx = i ; unsigned ElmOffset = SL -> getElementOffset ( i ) ; if ( ElmOffset >= Offset ) { ElmIdx = ElmOffset > Offset ? i - <NUM_LIT> : i ; break ; } } unsigned ElmSz = DL . getTypeSizeInBits ( STy -> getTypeAtIndex ( ElmIdx ) ) / <NUM_LIT> ; if ( SL -> hasPadding ( ) && ( Offset - SL -> getElementOffset ( ElmIdx ) ) > ElmSz ) { unsigned Alignment = SL -> getAlignment ( ) ; PadOffset = Alignment - ( ( Offset - SL -> getElementOffset ( ElmIdx ) ) ) ; } return ElmIdx ;


<s> MemIntrinsicsHandler ( Function & F ) : Func ( & F ) {


<s> for ( auto * User : I -> users ( ) ) {

if ( User -> getNumUses ( ) ) PopulateEraseUsers ( User , Users ) ;


<s> if ( User -> getNumUses ( ) ) PopulateEraseUsers ( User , Users ) ;


<s> for ( auto * User : I . users ( ) ) ProcessUser ( MemOpOffsetMap , * User , Offset , false ) ; ProcessMemOpWRTCompositeSource ( SrcMem , MemOpOffsetMap , DestTy ) ;


<s> LLVMContext & Cxt = Func -> getContext ( ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ;

TargetIdxTy = GetTargetIndexType ( DL , Cxt ) ;


for ( auto * User : I . users ( ) ) RetVal &= ProcessUser ( MemOpOffsetMap , * User , Offset , isStruct ) ;


<s> for ( auto * Val : DeletionSet ) { SmallVector < User * , <NUM_LIT> > Users ; PopulateEraseUsers ( Val , Users ) ;


<s> if ( Val != I && DeletionSet . find ( I ) != DeletionSet . end ( ) ) DeletionSet . erase ( I ) ; } }


<s> void MemIntrinsicsHandler :: ProcessMemOpWRTCompositeSource ( Value * SrcMem , SrcMemOpOffset & MemOpOffsetMap , Type * DestTy ) { Type * SrcTy = GetRootType ( SrcMem -> getType ( ) ) ; assert ( isa < ArrayType > ( SrcTy ) || isa < StructType > ( SrcTy ) ) ;

for ( auto & MemOpOffsetPair : MemOpOffsetMap ) {


<s> for ( auto & MemOpOffsetPair : MemOpOffsetMap ) {

IRBuilder < > IRB ( cast < Instruction > ( MemOpOffsetPair . first ) ) ;


<s> void MemIntrinsicsHandler :: ProcessPrimitive ( Type * SrcTy , Type * DestTy , Value * Offset , Value * SrcMem , BitCastInst & I ) { assert ( SrcTy -> isIntegerTy ( ) ) ; SrcMemOpOffset MemOpOffsetMap ;

for ( auto * User : I . users ( ) ) ProcessUser ( MemOpOffsetMap , * User , Offset , false ) ;


<s> SrcMemOpOffset MemOpOffsetMap ; for ( auto * User : I . users ( ) ) ProcessUser ( MemOpOffsetMap , * User , Offset , false ) ;

ProcessMemOpWRTSourcePrimitive ( SrcMem , MemOpOffsetMap , DestTy ) ;


<s> void MemIntrinsicsHandler :: ProcessStructures ( Type * SrcTy , Type * DestTy , Value * Offset , Value * SrcMem , BitCastInst & I ) { SrcMemOpOffset MemOpOffsetMap ; for ( auto * User : I . users ( ) ) ProcessUser ( MemOpOffsetMap , * User , Offset , false ) ; ProcessMemOpWRTCompositeSource ( SrcMem , MemOpOffsetMap , DestTy ) ;


<s> else if ( isa < LoadInst > ( & I ) || isa < StoreInst > ( & I ) ) MemOpOffsetMap [ & I ] = Offset ; else if ( isa < BitCastInst > ( & I ) ) {


<s> else if ( isa < BitCastInst > ( & I ) ) { AddToLazyDeletionSet ( & I ) ;

for ( auto * BCUser : cast < BitCastInst > ( & I ) -> users ( ) ) RetVal &= ProcessUser ( MemOpOffsetMap , * BCUser , Offset , isStruct ) ;


<s> bool HasBitCastInChain = false ; Value * Offset = ConstantInt :: get ( TargetIdxTy , <NUM_LIT> ) ; Value * Root = GetRootObject ( & I , & Offset , HasBitCastInChain ) ; assert ( Root && isa < PointerType > ( Root -> getType ( ) ) && <STR_LIT> ) ; if ( HasBitCastInChain ) return ; Type * RootTy = GetRootType ( Root -> getType ( ) ) ;

Type * DestTy = GetRootType ( I . getDestTy ( ) ) ;


<s> assert ( MO . isReg ( ) && TargetRegisterInfo :: isVirtualRegister ( MO . getReg ( ) ) && <STR_LIT> ) ; if ( ! MRI -> hasOneDef ( MO . getReg ( ) ) ) return false ;

MachineInstr * Driver = MRI -> getVRegDef ( MO . getReg ( ) ) ;


<s> return false ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : { isInt = true ; return true ; } case <STR_LIT> :


<s> FunctionPass * create<ISA_LIT>OffsetAllocator ( ) {

return new <ISA_LIT>OffsetAllocator ( ) ;


<s> void <ISA_LIT>OffsetAllocator :: EnterScope ( MachineBasicBlock * MBB ) {

LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << MBB -> getName ( ) << '\n' ) ;


<s> void <ISA_LIT>OffsetAllocator :: ExitScopeIfDone ( MachineDomTreeNode * Node , DenseMap < MachineDomTreeNode * , unsigned > & OpenChildren ) { if ( OpenChildren [ Node ] ) return ; ExitScope ( Node -> getBlock ( ) ) ; while ( MachineDomTreeNode * Parent = Node -> getIDom ( ) ) { unsigned Left = -- OpenChildren [ Parent ] ; if ( Left != <NUM_LIT> ) break ; ExitScope ( Parent -> getBlock ( ) ) ;


<s> static bool isAllocationCandidate ( const <ISA_LIT>InstrInfo * TII , MachineInstr * MI ) { if ( MI -> isReturn ( ) ) return false ; if ( MI -> skipAllocation ( ) ) return false ; return true ;


<s> if ( MI -> isReturn ( ) ) return false ; if ( MI -> skipAllocation ( ) ) return false ;


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


<s> static bool isArgument ( MachineInstr * MI ) { unsigned Opcode = MI -> getOpcode ( ) ; switch ( Opcode ) { default : return false ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> :


<s> assert ( MBB -> getNumber ( ) == <NUM_LIT> && <STR_LIT> ) ; return true ; } else return false ;


<s> const std :: vector < MachineDomTreeNode * > & Children = Node -> getChildren ( ) ; OpenChildren [ Node ] = Children . size ( ) ; for ( MachineDomTreeNode * Child : Children ) WorkList . push_back ( Child ) ;


<s> const MachineOperand & Imm2 = I2 -> getOperand ( <NUM_LIT> ) ; return Imm1 . getImm ( ) < Imm2 . getImm ( ) ; } ; for ( MachineBasicBlock :: iterator I = MBB -> begin ( ) , E = MBB -> end ( ) ; I != E ; I ++ ) { MachineInstr * MI = & * I ; if ( isArgument ( MI ) ) Arguments . push_back ( MI ) ; } std :: sort ( Arguments . begin ( ) , Arguments . end ( ) , SortArguments ) ; for ( auto * Arg : Arguments ) {

MachineOperand & MO = Arg -> getOperand ( <NUM_LIT> ) ;


<s> if ( isEntryBlock ( MBB ) ) { PerformArgumentAllocation ( MBB ) ; PerformAllocationForScratchSet ( ) ; } for ( MachineBasicBlock :: iterator I = MBB -> begin ( ) , E = MBB -> end ( ) ; I != E ; ) { MachineInstr * MI = & * I ; ++ I ; if ( ! isAllocationCandidate ( TII , MI ) || isArgument ( MI ) ) continue ; unsigned NumDefs = MI -> getDesc ( ) . getNumDefs ( ) ; for ( unsigned i = <NUM_LIT> ; i < NumDefs ; ++ i ) { MachineOperand & MO = MI -> getOperand ( i ) ; if ( ! MO . isReg ( ) || MO . isImplicit ( ) ) continue ; assert ( TargetRegisterInfo :: isVirtualRegister ( MO . getReg ( ) ) && <STR_LIT> ) ; if ( MI -> isMoveImmediate ( ) ) { FuncInfo -> setRegisterOffset ( MO . getReg ( ) , - <NUM_LIT> ) ; } else if ( MI -> mayLoad ( ) || MI -> getDesc ( ) . isRegCConv ( ) ) { unsigned UseOffset ; MachineOperand LoadSrc = MI -> getOperand ( <NUM_LIT> ) ;

if ( LoadSrc . isReg ( ) ) UseOffset = FuncInfo -> getRegisterOffset ( MI -> getOperand ( <NUM_LIT> ) . getReg ( ) ) ;


<s> bool <ISA_LIT>OffsetAllocator :: runOnMachineFunction ( MachineFunction & MFN ) { MF = & MFN ; TII = static_cast < const <ISA_LIT>InstrInfo * > ( MF -> getSubtarget ( ) . getInstrInfo ( ) ) ; TRI = static_cast < const <ISA_LIT>RegisterInfo * > ( MF -> getSubtarget ( ) . getRegisterInfo ( ) ) ; MRI = & MF -> getRegInfo ( ) ; DT = & getAnalysis < MachineDominatorTree > ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ;

PerformAllocation ( DT -> getRootNode ( ) ) ;


<s> return new <ISA_LIT>PostAllocationFixups ( ) ;


<s> void <ISA_LIT>PostAllocationFixups :: EnterScope ( MachineBasicBlock * MBB ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << MBB -> getName ( ) << '\n' ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << MBB -> getName ( ) << '\n' ) ;


<s> void <ISA_LIT>PostAllocationFixups :: ExitScope ( MachineBasicBlock * MBB ) {


<s> if ( OpenChildren [ Node ] ) return ; ExitScope ( Node -> getBlock ( ) ) ;

while ( MachineDomTreeNode * Parent = Node -> getIDom ( ) ) {


<s> if ( MI . isReturn ( ) && MI . getNumOperands ( ) ) {

MachineInstr * RetOpDef = MRI . getVRegDef ( MI . getOperand ( <NUM_LIT> ) . getReg ( ) ) ;


<s> if ( MI . mayStore ( ) || MI . mayLoad ( ) || MI . isReturn ( ) || MI . isCompare ( ) || MI . hasUnmodeledSideEffects ( ) || MI . isRematerializable ( ) ) return false ; else return true ;


<s> bool isStoreCandidate ( const MachineInstr & MI ) { if ( MI . skipAllocation ( ) ) return false ; if ( MI . mayStore ( ) || MI . mayLoad ( ) || MI . isReturn ( ) || MI . isCompare ( ) || MI . hasUnmodeledSideEffects ( ) || MI . isRematerializable ( ) ) return false ;


<s> DenseMap < MachineDomTreeNode * , unsigned > OpenChildren ; WorkList . push_back ( Node ) ; do { Node = WorkList . pop_back_val ( ) ; Scopes . push_back ( Node ) ; const std :: vector < MachineDomTreeNode * > & Children = Node -> getChildren ( ) ; OpenChildren [ Node ] = Children . size ( ) ; for ( MachineDomTreeNode * Child : Children ) WorkList . push_back ( Child ) ; } while ( ! WorkList . empty ( ) ) ; for ( MachineDomTreeNode * Node : Scopes ) { MachineBasicBlock * MBB = Node -> getBlock ( ) ; EnterScope ( MBB ) ; ProcessReturnFixup ( MBB ) ; ExitScopeIfDone ( Node , OpenChildren ) ;


<s> DenseMap < MachineDomTreeNode * , unsigned > OpenChildren ; WorkList . push_back ( Node ) ; do { Node = WorkList . pop_back_val ( ) ; Scopes . push_back ( Node ) ;

const std :: vector < MachineDomTreeNode * > & Children = Node -> getChildren ( ) ;


<s> MachineInstr * ConstDriver = nullptr ; MachineInstr * MI = & * I ; ++ I ; if ( ! isReturnFixupCandidate ( MRI , * MI ) ) continue ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * MI ) ; MachineOperand & RetVal = MI -> getOperand ( <NUM_LIT> ) ; assert ( RetVal . isReg ( ) && <STR_LIT> ) ; unsigned RetReg = RetVal . getReg ( ) ; const TargetRegisterClass * RC = MRI . getRegClass ( RetReg ) ; unsigned NewReg = MRI . createVirtualRegister ( RC ) ; if ( HasConstantDriver ( & MRI , RetVal , isInt , & ConstDriver ) ) { unsigned LDCOpcode = isInt ? <STR_LIT> : <STR_LIT> ; NewMI = BuildMI ( * MBB , MI , MI -> getDebugLoc ( ) , TII -> get ( LDCOpcode ) ) . addDef ( NewReg ) . addImm ( ConstDriver -> getOperand ( <NUM_LIT> ) . getImm ( ) ) ; ConstDriver -> eraseFromParent ( ) ; } else { unsigned LoadOpcode = <STR_LIT> ( RC ) ; NewMI = BuildMI ( * MBB , MI , MI -> getDebugLoc ( ) , TII -> get ( LoadOpcode ) ) . addDef ( NewReg ) . addImm ( FuncInfo -> getRegisterOffset ( RetReg ) ) ; } FuncInfo -> setRegisterOffset ( NewReg , FuncInfo -> getRegisterOffset ( RetVal . getReg ( ) ) ) ; MachineOperand NewRetVal = MachineOperand :: CreateReg ( NewReg , false ) ; MI -> RemoveOperand ( <NUM_LIT> ) ; MI -> addOperand ( * MF , NewRetVal ) ; MRI . addRegOperandToUseList ( & NewRetVal ) ; NumFixups ++ ; if ( NewMI != nullptr ) Change = true ; } return Change ;


<s> TRI = static_cast < const <ISA_LIT>RegisterInfo * > ( MF -> getSubtarget ( ) . getRegisterInfo ( ) ) ; MRI = & MF -> getRegInfo ( ) ; DT = & getAnalysis < MachineDominatorTree > ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; PerformStoreInsertion ( DT -> getRootNode ( ) ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; PerformReturnFixup ( DT -> getRootNode ( ) ) ; return true ;


<s> DT = & getAnalysis < MachineDominatorTree > ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; PerformStoreInsertion ( DT -> getRootNode ( ) ) ;


<s> if ( EraseSet . find ( MI ) == EraseSet . end ( ) ) EraseSet . insert ( MI ) ;


<s> for ( DeferredEraseSetIter I = EraseSet . begin ( ) , E = EraseSet . end ( ) ; I != E ; I ++ ) { ( * I ) -> eraseFromParent ( ) ;


<s> return new <ISA_LIT>PreAllocationFixups ( ) ;


<s> FunctionPass * create<ISA_LIT>PreAllocationFixups ( ) {

return new <ISA_LIT>PreAllocationFixups ( ) ;


<s> void <ISA_LIT>PreAllocationFixups :: EnterScope ( MachineBasicBlock * MBB ) {


<s> void <ISA_LIT>PreAllocationFixups :: ExitScope ( MachineBasicBlock * MBB ) {


<s> void <ISA_LIT>PreAllocationFixups :: ExitScope ( MachineBasicBlock * MBB ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << MBB -> getName ( ) << '\n' ) ;


<s> ExitScope ( Node -> getBlock ( ) ) ; while ( MachineDomTreeNode * Parent = Node -> getIDom ( ) ) { unsigned Left = -- OpenChildren [ Parent ] ; if ( Left != <NUM_LIT> ) break ;


<s> bool IsExtendFixupCandidate ( MachineRegisterInfo * MRI , MachineInstr * MI ) { unsigned Opcode = MI -> getOpcode ( ) ; switch ( Opcode ) { default : return false ; case <STR_LIT> : case <STR_LIT> :


<s> unsigned Opcode = MI -> getOpcode ( ) ; switch ( Opcode ) { default : return false ; case <STR_LIT> : case <STR_LIT> :


<s> for ( MachineDomTreeNode * Child : Children ) WorkList . push_back ( Child ) ; } while ( ! WorkList . empty ( ) ) ; for ( MachineDomTreeNode * Node : Scopes ) { MachineBasicBlock * MBB = Node -> getBlock ( ) ; EnterScope ( MBB ) ; ProcessExtendFixupsBlock ( MBB ) ; ExitScopeIfDone ( Node , OpenChildren ) ; }


<s> unsigned StoreOpcode = <STR_LIT> ( MRI -> getRegClass ( MOLHS . getReg ( ) ) ) ; BuildMI ( * MBB , MI , MI -> getDebugLoc ( ) , TII -> get ( StoreOpcode ) ) . addDef ( NewReg ) . addUse ( MORHS . getReg ( ) ) ; MachineOperand RetVal = MachineOperand :: CreateReg ( NewReg , false ) ; MI -> RemoveOperand ( <NUM_LIT> ) ; MI -> addOperand ( * MF , RetVal ) ; MRI -> addRegOperandToUseList ( & RetVal ) ; }


<s> NumFixupsInstrs ++ ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << MBB -> getName ( ) << '\n' ) ; MachineOperand MORHS = MI -> getOperand ( <NUM_LIT> ) ; MachineOperand MOLHS = MI -> getOperand ( <NUM_LIT> ) ; unsigned NewReg = MRI -> createVirtualRegister ( MRI -> getRegClass ( MOLHS . getReg ( ) ) ) ; unsigned StoreOpcode = <STR_LIT> ( MRI -> getRegClass ( MOLHS . getReg ( ) ) ) ; BuildMI ( * MBB , MI , MI -> getDebugLoc ( ) , TII -> get ( StoreOpcode ) ) . addDef ( NewReg ) . addUse ( MORHS . getReg ( ) ) ; MachineOperand RetVal = MachineOperand :: CreateReg ( NewReg , false ) ; MI -> RemoveOperand ( <NUM_LIT> ) ; MI -> addOperand ( * MF , RetVal ) ; MRI -> addRegOperandToUseList ( & RetVal ) ; }


<s> MRI = & MF -> getRegInfo ( ) ; DT = & getAnalysis < MachineDominatorTree > ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; PerformExtendFixups ( DT -> getRootNode ( ) ) ;


<s> TII = static_cast < const <ISA_LIT>InstrInfo * > ( MF -> getSubtarget ( ) . getInstrInfo ( ) ) ; TRI = static_cast < const <ISA_LIT>RegisterInfo * > ( MF -> getSubtarget ( ) . getRegisterInfo ( ) ) ; MRI = & MF -> getRegInfo ( ) ; DT = & getAnalysis < MachineDominatorTree > ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ;

PerformExtendFixups ( DT -> getRootNode ( ) ) ;


<s> void <ISA_LIT>RegisterInfo :: eliminateFrameIndex ( MachineBasicBlock :: iterator II , int SPAdj , unsigned FIOperandNum , RegScavenger * ) const {


<s> const MCPhysReg * <ISA_LIT>RegisterInfo :: getCalleeSavedRegs ( const MachineFunction * ) const {

static const MCPhysReg CalleeSavedRegs [ ] = { <NUM_LIT> } ;


<s> unsigned <ISA_LIT>RegisterInfo :: getFrameRegister ( const MachineFunction & MF ) const { return <NUM_LIT> ;


<s> const TargetRegisterClass * <ISA_LIT>RegisterInfo :: getPointerRegClass ( const MachineFunction & MF , unsigned Kind ) const { assert ( Kind == <NUM_LIT> && <STR_LIT> ) ; if ( MF . getSubtarget < <ISA_LIT>Subtarget > ( ) . hasAddr64 ( ) ) return & <STR_LIT> ;


<s> BitVector <ISA_LIT>RegisterInfo :: getReservedRegs ( const MachineFunction & MF ) const { BitVector resRegs ( getNumRegs ( ) ) ; return resRegs . set ( ) ;


<s> <ISA_LIT>RegisterInfo :: <ISA_LIT>RegisterInfo ( const Triple & TT ) : <ISA_LIT>GenRegisterInfo ( <NUM_LIT> ) , TT ( TT ) {


<s> <ISA_LIT>SelectionDAGInfo :: ~ <ISA_LIT>SelectionDAGInfo ( ) {


<s> bool <ISA_LIT>Subtarget :: enableMachineScheduler ( ) const { return false ;


<s> const <ISA_LIT>FrameLowering * getFrameLowering ( ) const override {


<s> return & getInstrInfo ( ) -> getRegisterInfo ( ) ;


<s> const <ISA_LIT>SelectionDAGInfo * getSelectionDAGInfo ( ) const override { return & TSInfo ;


<s> const <ISA_LIT>TargetLowering * getTargetLowering ( ) const override {


<s> <ISA_LIT>Subtarget :: <ISA_LIT>Subtarget ( const Triple & TT , const std :: string & CPU , const std :: string & FS , const TargetMachine & TM ) : <ISA_LIT>GenSubtargetInfo ( TT , CPU , FS ) , CPUString ( CPU ) , TargetTriple ( TT ) , FrameLowering ( ) , InstrInfo ( initializeSubtargetDependencies ( FS ) ) , TSInfo ( ) , TLInfo ( TM , * this ) {


<s> bool <ISA_LIT>Subtarget :: useAA ( ) const {


<s> static Target The<ISA_LIT>Target32 ; return The<ISA_LIT>Target32 ;


<s> RegisterTarget < Triple :: jvm64 > Y ( getThe<ISA_LIT>Target64 ( ) , <STR_LIT> , <STR_LIT> , <STR_LIT> ) ;


<s> void <ISA_LIT>PassConfig :: addCodeGenPrepare ( ) {


<s> addPass ( create<ISA_LIT>ISelDag ( get<ISA_LIT>TargetMachine ( ) , getOptLevel ( ) ) ) ;


<s> if ( JvmAggOpt ) addPass ( createInstructionCombiningPass ( ) ) ; addPass ( create<ISA_LIT>IRDecorator ( ) ) ; addPass ( createAggressiveDCEPass ( ) ) ;


<s> addPass ( create<ISA_LIT>CopyElision ( ) ) ; addPreEmitPass ( ) ;


<s> void <ISA_LIT>PassConfig :: addOptimizedRegAlloc ( FunctionPass * RegAllocPass ) { disablePass ( & RegisterCoalescerID ) ;

TargetPassConfig :: addOptimizedRegAlloc ( RegAllocPass ) ;


<s> disablePass ( & PatchableFunctionID ) ; disablePass ( & PrologEpilogCodeInserterID ) ; TargetPassConfig :: addPostRegAlloc ( ) ;


<s> TargetPassConfig :: addPreEmitPass ( ) ; if ( JvmLSOpt ) addPass ( create<ISA_LIT>LoadStoreEliminationOpt ( ) ) ; addPass ( create<ISA_LIT>OffsetAllocator ( ) ) ; addPass ( create<ISA_LIT>PostAllocationFixups ( ) ) ;


<s> FunctionPass * <ISA_LIT>PassConfig :: createTargetRegisterAllocator ( bool ) { return nullptr ;


<s> bool dumpclassfile ; cl :: GetCommandLineOption < bool > ( <STR_LIT> , dumpclassfile ) ; bool enablejvmassembler ; cl :: GetCommandLineOption < bool > ( <STR_LIT> , enablejvmassembler ) ;

if ( dumpclassfile && ! enablejvmassembler ) llvm :: errs ( ) << <STR_LIT> <STR_LIT> ;


<s> if ( dumpclassfile && ! enablejvmassembler ) llvm :: errs ( ) << <STR_LIT> <STR_LIT> ;


<s> if ( ! RM . hasValue ( ) ) return Reloc :: PIC_ ;


<s> return getTM < <ISA_LIT>TargetMachine > ( ) ;


<s> TargetLoweringObjectFile * getObjFileLowering ( ) const override { return TLOF . get ( ) ;


<s> TargetLoweringObjectFile * getObjFileLowering ( ) const override {


<s> <ISA_LIT>PassConfig ( <ISA_LIT>TargetMachine & TM , PassManagerBase & PM ) : TargetPassConfig ( TM , PM ) {


<s> RegisterTargetMachine < <ISA_LIT>TargetMachine > X ( getThe<ISA_LIT>Target32 ( ) ) ; RegisterTargetMachine < <ISA_LIT>TargetMachine > Y ( getThe<ISA_LIT>Target64 ( ) ) ;


<s> RegisterTargetMachine < <ISA_LIT>TargetMachine > Y ( getThe<ISA_LIT>Target64 ( ) ) ;


<s> <ISA_LIT>TargetMachine :: ~ <ISA_LIT>TargetMachine ( ) {


<s> void changeSection ( const MCSection * CurSection , MCSection * Section , const MCExpr * SubSection , raw_ostream & OS ) override {


<s> void <ISA_LIT>TargetAsmStreamer :: emitString ( const Twine & Str ) {


<s> <ISA_LIT>TargetAsmStreamer :: <ISA_LIT>TargetAsmStreamer ( MCStreamer & S , formatted_raw_ostream & OS ) : <ISA_LIT>TargetStreamer ( S ) , OS ( OS ) {


<s> <ISA_LIT>TargetStreamer :: <ISA_LIT>TargetStreamer ( MCStreamer & S ) : MCTargetStreamer ( S ) {


<s> BlockPredication ( Function & Func ) : F ( & Func ) {


<s> BlockRevPostOrderTraversal :: BlockRevPostOrderTraversal ( Function * F ) {

visitBlocks ( & F -> getEntryBlock ( ) ) ;


<s> visitBlocks ( & F -> getEntryBlock ( ) ) ;


if ( Block -> hasOneUse ( ) && IsRPOTPredecessor ( Itr , cast < BasicBlock > ( cast < Instruction > ( * ( Block -> user_begin ( ) ) ) -> getParent ( ) ) ) ) return true ;


<s> FunctionPass * createX2JavaPass ( ) {


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << i ++ << <STR_LIT> << PV . getPointer ( ) -> getName ( ) << ( PV . getInt ( ) ? <STR_LIT> : <STR_LIT> ) ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << Blk -> getName ( ) ) ; for ( auto PV : PredCondMap [ Blk ] ) {

LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << i ++ << <STR_LIT> << PV . getPointer ( ) -> getName ( ) << ( PV . getInt ( ) ? <STR_LIT> : <STR_LIT> ) ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ;


<s> void XToJavaPass :: EmitArgumentInitializationWrappers ( ) { LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ;


<s> int PhiRemoved = PhiEliminator . ProcessFunction ( ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << PhiRemoved << <STR_LIT> ) ; Predicator . ProcessFunction ( ) ;

for ( auto * Blk : Predicator . getOrderedList ( ) ) {


<s> void XToJavaPass :: EmitEpilogue ( raw_ostream & OS ) {


<s> for ( BasicBlock * BB : RPOT ) LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << BB -> getName ( ) << <STR_LIT> ) ;


<s> EmitEpilogue ( OS ) ; XToJavaCounter ++ ;


<s> char ctrStr [ <NUM_LIT> ] = { '\0' } ; std :: string Name = <STR_LIT> ; Name += Prefix ; sprintf ( ctrStr , <STR_LIT> , ctr ++ ) ;


<s> Name += Prefix ; sprintf ( ctrStr , <STR_LIT> , ctr ++ ) ;


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


<s> BlockOrderList & getOrderedList ( ) { return blockList ;


<s> void BlockPredication :: InsertPredicate ( BasicBlock * Blk , Value * Pred , int TrueCondF ) {

if ( PredCondMap . find ( Blk ) == PredCondMap . end ( ) ) PredCondMap [ Blk ] = { PredicateVar ( Pred , TrueCondF ) } ;


<s> if ( PredCondMap . find ( Blk ) == PredCondMap . end ( ) ) PredCondMap [ Blk ] = { PredicateVar ( Pred , TrueCondF ) } ;

else PredCondMap [ Blk ] . push_back ( PredicateVar ( Pred , TrueCondF ) ) ;


<s> PHIElimination ( Function & Func ) : F ( & Func ) {


<s> int PhiCnt = <NUM_LIT> ; BasicBlock & entry = F -> getEntryBlock ( ) ; for ( auto & Inst : B ) { if ( isa < PHINode > ( Inst ) ) { PHINode & I = cast < PHINode > ( Inst ) ; IRBuilder < > IRB ( & entry , entry . begin ( ) ) ; AllocaInst * NewVar = IRB . CreateAlloca ( I . getType ( ) , nullptr , genTempName ( ++ newInstrCtr , <STR_LIT> ) ) ;

LoadInst * NewLI = IRB . CreateLoad ( I . getType ( ) , NewVar , genTempName ( ++ newInstrCtr , <STR_LIT> ) ) ;


<s> } else { assert ( BI -> isConditional ( ) && BI -> getNumSuccessors ( ) == <NUM_LIT> && <STR_LIT> ) ; Value * Cond = BI -> getCondition ( ) ; BasicBlock * TrueBlk = BI -> getSuccessor ( <NUM_LIT> ) ; BasicBlock * FalseBlk = BI -> getSuccessor ( <NUM_LIT> ) ; InsertPredicate ( TrueBlk , Cond ) ; InsertPredicate ( FalseBlk , Cond , <NUM_LIT> ) ; }


<s> raw_string_ostream OS ( Code ) ; Func = & F ;


<s> void setFunction ( Function & Func ) { F = & Func ;


<s> void BlockRevPostOrderTraversal :: visitBlocks ( BasicBlock * Blk ) { if ( OrderedMap . find ( Blk ) != OrderedMap . end ( ) && ( OrderedMap [ Blk ] == GRAY || OrderedMap [ Blk ] == BLACK ) ) return ; OrderedMap [ Blk ] = GRAY ; Instruction * TI = Blk -> getTerminator ( ) ; if ( isa < BranchInst > ( TI ) && cast < BranchInst > ( TI ) -> isConditional ( ) ) { BasicBlock * FalseBlock = cast < BasicBlock > ( TI -> getSuccessor ( <NUM_LIT> ) ) ; visitBlocks ( FalseBlock ) ; BasicBlock * TrueBlock = cast < BasicBlock > ( TI -> getSuccessor ( <NUM_LIT> ) ) ; visitBlocks ( TrueBlock ) ; } else { for ( unsigned i = <NUM_LIT> ; i < TI -> getNumSuccessors ( ) ; i ++ ) { visitBlocks ( TI -> getSuccessor ( i ) ) ; } } OrderedMap [ Blk ] = BLACK ;


<s> void BlockRevPostOrderTraversal :: visitBlocks ( BasicBlock * Blk ) { if ( OrderedMap . find ( Blk ) != OrderedMap . end ( ) && ( OrderedMap [ Blk ] == GRAY || OrderedMap [ Blk ] == BLACK ) ) return ; OrderedMap [ Blk ] = GRAY ;

Instruction * TI = Blk -> getTerminator ( ) ;


<s> XToJavaPass ( ) : FunctionPass ( ID ) {


<s> jclass cls ; jmethodID mid ; JavaVMInitArgs vm_args ; JavaVMOption options [ <NUM_LIT> ] ; options [ <NUM_LIT> ] . optionString = <STR_LIT> ; options [ <NUM_LIT> ] . optionString = <STR_LIT> ; options [ <NUM_LIT> ] . optionString = <STR_LIT> ; options [ <NUM_LIT> ] . optionString = <STR_LIT> ; vm_args . version = <NUM_LIT> ; vm_args . options = options ; vm_args . nOptions = <NUM_LIT> ; vm_args . ignoreUnrecognized = JNI_TRUE ; fprintf ( stdout , <STR_LIT> , className , methodName ) ;

res = JNI_CreateJavaVM ( & jvm , ( void * * ) & env , & vm_args ) ;


<s> if ( mid == NULL ) { goto destroy ; } jbyteArray jBArr = ( * env ) -> NewByteArray ( env , <NUM_LIT> ) ; if ( jBArr != NULL ) { ( * env ) -> SetByteArrayRegion ( env , jBArr , <NUM_LIT> , <NUM_LIT> , ( jbyte * ) byteArray ) ; } ( * env ) -> CallStaticVoidMethod ( env , cls , mid , jBArr ) ; ( * env ) -> GetByteArrayRegion ( env , jBArr , <NUM_LIT> , <NUM_LIT> , ( jbyte * ) byteArray ) ; ( * env ) -> DeleteLocalRef ( env , jBArr ) ; destroy : if ( ( * env ) -> ExceptionOccurred ( env ) ) { ( * env ) -> ExceptionDescribe ( env ) ; }


<s> fprintf ( stdout , <STR_LIT> , className , methodName ) ; res = JNI_CreateJavaVM ( & jvm , ( void * * ) & env , & vm_args ) ; if ( res < <NUM_LIT> ) { fprintf ( stderr , <STR_LIT> ) ; exit ( <NUM_LIT> ) ; } sleep ( <NUM_LIT> ) ; cls = ( * env ) -> FindClass ( env , className ) ; if ( cls == NULL ) { goto destroy ; } fprintf ( stdout , <STR_LIT> ) ; mid = ( * env ) -> GetStaticMethodID ( env , cls , methodName , <STR_LIT> ) ; if ( mid == NULL ) { goto destroy ; } jbyteArray jBArr = ( * env ) -> NewByteArray ( env , <NUM_LIT> ) ; if ( jBArr != NULL ) { ( * env ) -> SetByteArrayRegion ( env , jBArr , <NUM_LIT> , <NUM_LIT> , ( jbyte * ) byteArray ) ; } ( * env ) -> CallStaticVoidMethod ( env , cls , mid , jBArr ) ; ( * env ) -> GetByteArrayRegion ( env , jBArr , <NUM_LIT> , <NUM_LIT> , ( jbyte * ) byteArray ) ; ( * env ) -> DeleteLocalRef ( env , jBArr ) ; destroy : if ( ( * env ) -> ExceptionOccurred ( env ) ) { ( * env ) -> ExceptionDescribe ( env ) ; } ( * jvm ) -> DestroyJavaVM ( jvm ) ; return ;