<s> return new <ISA_LIT>AsmBackend ( TT . isArch64Bit ( ) ) ;


<s> unsigned <ISA_LIT>AsmBackend :: getNumFixupKinds ( ) const {


<s> explicit <ISA_LIT>AsmBackend ( bool Is64Bit ) : MCAsmBackend ( <STR_LIT> ) , Is64Bit ( Is64Bit ) {


<s> bool <ISA_LIT>AsmBackend :: mayNeedRelaxation ( const MCInst & Inst , const MCSubtargetInfo & STI ) const {


<s> ~ <ISA_LIT>AsmBackend ( ) override {


<s> ClassDef += ClassName ; ClassDef += <STR_LIT> ; EmitClassFields ( ClassDef , STy , CompFields ) ; ClassDef += <STR_LIT> ; for ( auto & TyFIDPair : CompFields ) EmitFieldAllocation ( ClassDef , TyFIDPair . first , ClassName , TyFIDPair . second ) ; ClassDef += <STR_LIT> ; return ClassDef ;


<s> ClassDef += <STR_LIT> ; for ( auto & TyFIDPair : CompFields ) EmitFieldAllocation ( ClassDef , TyFIDPair . first , ClassName , TyFIDPair . second ) ; ClassDef += <STR_LIT> ;


<s> std :: string ClassDef = EmitClassDefinition ( TyNmPair . first , ClassName ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << ClassDef ; ) ; std :: error_code EC ; sys :: fs :: OpenFlags OpenFlags = sys :: fs :: F_None ; raw_fd_ostream ClassFile ( ClassName + <STR_LIT> , EC , OpenFlags ) ;


<s> StrBuf += <STR_LIT> ; sprintf ( fieldBuf , <STR_LIT> , i ) ; StrBuf += fieldBuf ; StrBuf += <STR_LIT> ; Type * FieldTy = STy -> getElementType ( i ) ; MFI -> getTypeDescriptor ( FieldTy , StrBuf ) ; if ( isa < CompositeType > ( FieldTy ) ) CompFields . push_back ( std :: make_pair ( FieldTy , i ) ) ;


<s> <ISA_LIT>Assembler obj ; Optional < std :: unique_ptr < <STR_LIT> >> classPkt = obj . AssembleClass ( TM . getMCAsmInfo ( ) -> getAsmMemoryBuffer ( ) ) ; if ( Dump<ISA_LIT>ClassFile && classPkt . hasValue ( ) ) { std :: error_code EC ; sys :: fs :: OpenFlags OpenFlags = sys :: fs :: F_None ; std :: string ModName ( M . getName ( ) . data ( ) ) ; std :: string ClassName = ModName . substr ( <NUM_LIT> , ModName . find ( <STR_LIT> ) ) ; raw_fd_ostream ClassFile ( ClassName + <STR_LIT> , EC , OpenFlags ) ;

ClassFile . write ( classPkt -> get ( ) -> getPayload ( ) , classPkt -> get ( ) -> getSize ( ) ) ;


<s> if ( Dump<ISA_LIT>ClassFile && classPkt . hasValue ( ) ) { std :: error_code EC ; sys :: fs :: OpenFlags OpenFlags = sys :: fs :: F_None ; std :: string ModName ( M . getName ( ) . data ( ) ) ; std :: string ClassName = ModName . substr ( <NUM_LIT> , ModName . find ( <STR_LIT> ) ) ; raw_fd_ostream ClassFile ( ClassName + <STR_LIT> , EC , OpenFlags ) ; ClassFile . write ( classPkt -> get ( ) -> getPayload ( ) , classPkt -> get ( ) -> getSize ( ) ) ; ClassFile . close ( ) ; } else if ( classPkt . hasValue ( ) ) { classPkt -> get ( ) -> dump ( ) ;


<s> if ( isa < ArrayType > ( Ty ) ) { char IDStr [ <NUM_LIT> ] = { '\0' } ; Type * ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; unsigned NumElm = cast < ArrayType > ( Ty ) -> getNumElements ( ) ; std :: string ElmTyStr = EmitTypeString ( ElmTy ) ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; sprintf ( IDStr , <STR_LIT> , NumElm ) ; FieldInit += IDStr ; if ( isa < StructType > ( ElmTy ) ) FieldInit += <STR_LIT> ; else FieldInit += <STR_LIT> ; FieldInit += ElmTyStr ; FieldInit += <STR_LIT> ; FieldInit += ClassName ; FieldInit += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , FieldID ) ; FieldInit += IDStr ; FieldInit += <STR_LIT> ; MFI -> getTypeDescriptor ( Ty , FieldInit ) ; if ( isa < StructType > ( ElmTy ) ) { for ( unsigned i = <NUM_LIT> ; i < NumElm ; i ++ ) { FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += ClassName ; FieldInit += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , FieldID ) ; FieldInit += IDStr ; FieldInit += <STR_LIT> ; MFI -> getTypeDescriptor ( Ty , FieldInit ) ; if ( i < <NUM_LIT> ) FieldInit += <STR_LIT> ; else FieldInit += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , i ) ; FieldInit += IDStr ; FieldInit += <STR_LIT> ; FieldInit += ElmTyStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += ElmTyStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; } } } else if ( isa < StructType > ( Ty ) ) { char IDStr [ <NUM_LIT> ] = { '\0' } ; std :: string TypeStr = EmitTypeString ( Ty ) ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += TypeStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += TypeStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += ClassName ;


<s> FieldInit += IDStr ; if ( isa < StructType > ( ElmTy ) ) FieldInit += <STR_LIT> ; else FieldInit += <STR_LIT> ; FieldInit += ElmTyStr ; FieldInit += <STR_LIT> ; FieldInit += ClassName ; FieldInit += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , FieldID ) ; FieldInit += IDStr ; FieldInit += <STR_LIT> ; MFI -> getTypeDescriptor ( Ty , FieldInit ) ; if ( isa < StructType > ( ElmTy ) ) { for ( unsigned i = <NUM_LIT> ; i < NumElm ; i ++ ) { FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += ClassName ; FieldInit += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , FieldID ) ; FieldInit += IDStr ; FieldInit += <STR_LIT> ; MFI -> getTypeDescriptor ( Ty , FieldInit ) ; if ( i < <NUM_LIT> ) FieldInit += <STR_LIT> ; else FieldInit += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , i ) ; FieldInit += IDStr ; FieldInit += <STR_LIT> ; FieldInit += ElmTyStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += ElmTyStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; } } } else if ( isa < StructType > ( Ty ) ) { char IDStr [ <NUM_LIT> ] = { '\0' } ; std :: string TypeStr = EmitTypeString ( Ty ) ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += TypeStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += TypeStr ; FieldInit += <STR_LIT> ; FieldInit += <STR_LIT> ; FieldInit += ClassName ; FieldInit += <STR_LIT> ;


<s> Type * ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; unsigned NumElems = cast < ArrayType > ( Ty ) -> getNumElements ( ) ; for ( unsigned i = <NUM_LIT> ; i < NumElems ; i ++ ) { if ( i < NumElems - <NUM_LIT> ) AsmBuf += <STR_LIT> ; AsmBuf += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , i ) ; AsmBuf += IDStr ; EmitFieldInitialization ( AsmBuf , Ty , ElmTy , ConstIdx , CVec , FieldID , false ) ; } } else if ( isa < StructType > ( Ty ) ) { char IDStr [ <NUM_LIT> ] = { '\0' } ; AsmBuf += GetLoadString ( PTy ) ; if ( isa < StructType > ( PTy ) ) { AsmBuf += <STR_LIT> ; AsmBuf += MFI -> getFromTypeNameMap ( PTy ) ; AsmBuf += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ;


<s> Type * FldTy = cast < StructType > ( Ty ) -> getTypeAtIndex ( i ) ; if ( i < NumFields - <NUM_LIT> ) AsmBuf += <STR_LIT> ; EmitFieldInitialization ( AsmBuf , FldTy , Ty , ConstIdx , CVec , i , false ) ; } } else { char IDStr [ <NUM_LIT> ] = { '\0' } ; assert ( isa < ConstantInt > ( CVec [ ConstIdx ] ) ) ; unsigned InitVal = cast < ConstantInt > ( CVec [ ConstIdx ++ ] ) -> getZExtValue ( ) ; sprintf ( IDStr , <STR_LIT> , InitVal ) ; AsmBuf += <STR_LIT> ; AsmBuf += IDStr ; AsmBuf += GetStoreString ( PTy ) ; if ( isa < StructType > ( PTy ) ) { AsmBuf += MFI -> getFromTypeNameMap ( PTy ) ; AsmBuf += <STR_LIT> ; IDStr [ <NUM_LIT> ] = '\0' ; sprintf ( IDStr , <STR_LIT> , FieldID ) ; AsmBuf += IDStr ; AsmBuf += <STR_LIT> ;

MFI -> getTypeDescriptor ( Ty , AsmBuf ) ;


<s> <ISA_LIT>TargetStreamer * TS = getTargetStreamer ( ) ;


<s> std :: string ClassName = ModName . substr ( <NUM_LIT> , ModName . find ( <STR_LIT> ) ) ; const GlobalVariable * GCStructObj = Mod -> getNamedGlobal ( <STR_LIT> ) ; Type * GCStructTy = GetRootType ( GCStructObj -> getType ( ) ) ; assert ( isa < StructType > ( GCStructTy ) ) ; StructType * STy = cast < StructType > ( GCStructTy ) ; FieldTypeIndexVec CompFields ; EmitClassFields ( ConstrStr , STy , CompFields ) ; ConstrStr += <STR_LIT> ; for ( auto TyIdx : CompFields ) EmitFieldAllocation ( ConstrStr , TyIdx . first , ClassName , TyIdx . second ) ; PopulateConstValVector ( GCStructObj -> getInitializer ( ) , CVec ) ; for ( auto TyIdx : CompFields ) EmitFieldInitialization ( ConstrStr , STy , TyIdx . first , ConstIdx , CVec , TyIdx . second , true ) ; <ISA_LIT>FunctionInfo :: TypeNameMap * STyName = const_cast < <ISA_LIT>FunctionInfo * > ( MFI ) -> getTypeNameMap ( ) ; STyName -> erase ( STy ) ; } else { ConstrStr += <STR_LIT> ; } ConstrStr += <STR_LIT> ; ConstrPrint = true ; } TS -> emitString ( ConstrStr ) ; std :: string str ( <STR_LIT> ) ; str += F . getName ( ) ; str += <STR_LIT> ; for ( auto & Arg : F . args ( ) ) { Type * T = Arg . getType ( ) ; if ( isa < PointerType > ( T ) ) T = cast < PointerType > ( T ) -> getElementType ( ) ; MFI -> getTypeDescriptor ( T , str ) ; } Type * RetType = F . getReturnType ( ) ; str += <STR_LIT> ; MFI -> getTypeDescriptor ( RetType , str ) ; TS -> emitString ( str ) ; str = <STR_LIT> ; limit [ <NUM_LIT> ] = '\0' ; sprintf ( limit , <STR_LIT> , MFI -> getLocalsLimit ( ) ) ; str += limit ;


<s> void EmitFunctionEntryLabel ( ) override {


<s> void <ISA_LIT>AsmPrinter :: EmitGlobalVariable ( const GlobalVariable * GV ) { assert ( GV -> isConstant ( ) && <STR_LIT> ) ;


<s> void <ISA_LIT>AsmPrinter :: EmitGlobalVariable ( const GlobalVariable * GV ) {

assert ( GV -> isConstant ( ) && <STR_LIT> ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << * MI << '\n' ) ; <ISA_LIT>MCInstLower InstLower ( OutContext , * this ) ; MCInst TmpInst ;


<s> std :: string str ( <STR_LIT> ) ; str += <STR_LIT> ; str += ClassName ; str += <STR_LIT> ;


<s> switch ( VT . getSimpleVT ( ) . SimpleTy ) { default : assert ( <STR_LIT> ) ; case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : return <STR_LIT> ;


<s> if ( isa < StructType > ( Ty ) ) return <STR_LIT> ; else if ( isa < ArrayType > ( Ty ) ) { Type * ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; if ( isa < CompositeType > ( ElmTy ) ) return <STR_LIT> ; return GetLoadString ( ElmTy ) ; } else { const DataLayout & DL = MF -> getDataLayout ( ) ; const <ISA_LIT>TargetLowering & TLI = * MF -> getTarget ( ) . getSubtarget < <ISA_LIT>Subtarget > ( MF -> getFunction ( ) ) . getTargetLowering ( ) ;

EVT VT = TLI . getValueType ( DL , Ty ) ;


<s> Type * ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; if ( isa < CompositeType > ( ElmTy ) ) return <STR_LIT> ; return GetLoadString ( ElmTy ) ; } else { const DataLayout & DL = MF -> getDataLayout ( ) ; const <ISA_LIT>TargetLowering & TLI = * MF -> getTarget ( ) . getSubtarget < <ISA_LIT>Subtarget > ( MF -> getFunction ( ) ) . getTargetLowering ( ) ; EVT VT = TLI . getValueType ( DL , Ty ) ; switch ( VT . getSimpleVT ( ) . SimpleTy ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> :


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


<s> const <ISA_LIT>TargetLowering & TLI = * MF -> getTarget ( ) . getSubtarget < <ISA_LIT>Subtarget > ( MF -> getFunction ( ) ) . getTargetLowering ( ) ; EVT VT = TLI . getValueType ( DL , Ty ) ; switch ( VT . getSimpleVT ( ) . SimpleTy ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> :


<s> <ISA_LIT>TargetStreamer * <ISA_LIT>AsmPrinter :: getTargetStreamer ( ) { MCTargetStreamer * TS = OutStreamer -> getTargetStreamer ( ) ;

return static_cast < <ISA_LIT>TargetStreamer * > ( TS ) ;


<s> <ISA_LIT>TargetStreamer * <ISA_LIT>AsmPrinter :: getTargetStreamer ( ) {

MCTargetStreamer * TS = OutStreamer -> getTargetStreamer ( ) ;


<s> unsigned Opcode = MI . getOpcode ( ) ; if ( MI . getDesc ( ) . isRegCConv ( ) ) return true ; switch ( Opcode ) { default : return false ; case <STR_LIT> : case <STR_LIT> :


<s> explicit <ISA_LIT>AsmPrinter ( TargetMachine & TM , std :: unique_ptr < MCStreamer > Streamer ) : AsmPrinter ( TM , std :: move ( Streamer ) ) , Subtarget ( nullptr ) , MRI ( nullptr ) , MFI ( nullptr ) {


<s> RegisterAsmPrinter < <ISA_LIT>AsmPrinter > X ( getThe<ISA_LIT>Target32 ( ) ) ; RegisterAsmPrinter < <ISA_LIT>AsmPrinter > Y ( getThe<ISA_LIT>Target64 ( ) ) ;


<s> RegisterAsmPrinter < <ISA_LIT>AsmPrinter > X ( getThe<ISA_LIT>Target32 ( ) ) ;

RegisterAsmPrinter < <ISA_LIT>AsmPrinter > Y ( getThe<ISA_LIT>Target64 ( ) ) ;


<s> return AsmPrinter :: lowerConstant ( CV ) ;


<s> Type * Ty = Init -> getType ( ) ; if ( isa < ArrayType > ( Ty ) || isa < StructType > ( Ty ) ) { unsigned NumElems = isa < ArrayType > ( Ty ) ? cast < ArrayType > ( Ty ) -> getNumElements ( ) : cast < StructType > ( Ty ) -> getNumElements ( ) ; for ( unsigned i = <NUM_LIT> ; i < NumElems ; i ++ ) PopulateConstValVector ( Init -> getAggregateElement ( i ) , CVec ) ;


<s> void <ISA_LIT>AsmPrinter :: PopulateConstValVector ( const Constant * Init , ConstantVals & CVec ) { Type * Ty = Init -> getType ( ) ; if ( isa < ArrayType > ( Ty ) || isa < StructType > ( Ty ) ) {

unsigned NumElems = isa < ArrayType > ( Ty ) ? cast < ArrayType > ( Ty ) -> getNumElements ( ) : cast < StructType > ( Ty ) -> getNumElements ( ) ;


<s> if ( ! AsmPrinter :: PrintAsmOperand ( MI , OpNo , AsmVariant , ExtraCode , OS ) ) return false ; if ( ! ExtraCode ) { const MachineOperand & MO = MI -> getOperand ( OpNo ) ; switch ( MO . getType ( ) ) { case MachineOperand :: MO_Immediate : OS << MO . getImm ( ) ; return false ; case MachineOperand :: MO_MachineBasicBlock : case MachineOperand :: MO_Register : case MachineOperand :: MO_GlobalAddress : case MachineOperand :: MO_ExternalSymbol : assert ( <NUM_LIT> && <STR_LIT> ) ; return false ; default : break ; }


<s> bool <ISA_LIT>AsmPrinter :: PrintAsmOperand ( const MachineInstr * MI , unsigned OpNo , unsigned AsmVariant , const char * ExtraCode , raw_ostream & OS ) { if ( AsmVariant != <NUM_LIT> ) report_fatal_error ( <STR_LIT> ) ; if ( ! AsmPrinter :: PrintAsmOperand ( MI , OpNo , AsmVariant , ExtraCode , OS ) ) return false ; if ( ! ExtraCode ) { const MachineOperand & MO = MI -> getOperand ( OpNo ) ; switch ( MO . getType ( ) ) { case MachineOperand :: MO_Immediate : OS << MO . getImm ( ) ; return false ; case MachineOperand :: MO_MachineBasicBlock : case MachineOperand :: MO_Register : case MachineOperand :: MO_GlobalAddress : case MachineOperand :: MO_ExternalSymbol : assert ( <NUM_LIT> && <STR_LIT> ) ; return false ; default :


MFI = MF . getInfo < <ISA_LIT>FunctionInfo > ( ) ;


<s> JNIEXPORT void JNICALL Java_jasmin_Main_llc_1dump_1classObj ( JNIEnv * env , jobject obj , jbyteArray bytes ) { jint len = env -> GetArrayLength ( reinterpret_cast < jarray * > ( & bytes ) [ <NUM_LIT> ] ) ; classObjectBuffer = ( char * ) malloc ( sizeof ( int ) + len + <NUM_LIT> ) ; int * payLoadSize = ( int * ) classObjectBuffer ; char * objectPayLoad = classObjectBuffer + sizeof ( int ) ;

std :: cout << <STR_LIT> << std :: endl ;


<s> jobject jobj = env -> NewObject ( cls , cnstr ) ; if ( NULL == jobj ) return nullptr ; jmethodID mid = env -> GetMethodID ( cls , <STR_LIT> , <STR_LIT> ) ; if ( NULL == mid ) return nullptr ; jstring jstr = env -> NewStringUTF ( asmFile . c_str ( ) ) ; if ( NULL == jstr ) return nullptr ; LLVM_DEBUG ( llvm :: dbgs ( ) << <STR_LIT> << strlen ( asmFile . c_str ( ) ) << <STR_LIT> ) ;

env -> CallVoidMethod ( jobj , mid , jstr ) ;


<s> Optional < std :: unique_ptr < <STR_LIT> >> <STR_LIT> ( std :: string asmFile ) { std :: unique_ptr < <STR_LIT> > Packet ; char * classObject = Impl -> assemble ( asmFile ) ; if ( ! classObject ) return None ; Packet = llvm :: make_unique < <STR_LIT> > ( classObject ) ; Impl -> freeClassObjectBuffer ( ) ; return std :: move ( Packet ) ;


<s> void <ISA_LIT>AssemblerImpl :: freeClassObjectBuffer ( ) {

if ( classObjectBuffer ) free ( classObjectBuffer ) ;


<s> void <ISA_LIT>AssemblerImpl :: freeClassObjectBuffer ( ) { if ( classObjectBuffer ) free ( classObjectBuffer ) ; classObjectBuffer = nullptr ;


<s> inst = new <ISA_LIT>AssemblerImpl ( ) ; }


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


<s> <ISA_LIT>AssemblerImpl :: <ISA_LIT>AssemblerImpl ( ) { JavaVMInitArgs vm_args ; JavaVMOption options [ <NUM_LIT> ] ; std :: string libPath = <STR_LIT> ; std :: string classPath = <STR_LIT> ; if ( ! Process :: GetEnv ( <STR_LIT> ) . hasValue ( ) ) report_fatal_error ( <STR_LIT> ) ; classPath = classPath + Process :: GetEnv ( <STR_LIT> ) . getValue ( ) ; classPath = classPath + <STR_LIT> ; libPath = libPath + Process :: GetEnv ( <STR_LIT> ) . getValue ( ) ; classObjectBuffer = nullptr ;


<s> <ISA_LIT>ExceptionChecker ( JNIEnv * jenv ) : env ( jenv ) {


<s> <STR_LIT> <ISA_LIT>Assembler ( ) { delete Impl ;


<s> ~ <ISA_LIT>ExceptionChecker ( ) { if ( env -> ExceptionOccurred ( ) ) { env -> ExceptionDescribe ( ) ; }


<s> if ( env -> ExceptionOccurred ( ) ) { env -> ExceptionDescribe ( ) ;


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


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

return llvm :: GenMask ( Cxt , DL , IRB , SrcSz , DestSz , Offset , IsLoad ) ;


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


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


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

ProcessMemOpWRTCompositeSource ( SrcMem , MemOpOffsetMap , DestTy , <NUM_LIT> ) ;


<s> void CastHandler :: ProcessFunction ( ) { LLVMContext & Cxt = Func -> getContext ( ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ;

TargetIdxTy = GetTargetIndexType ( DL , Cxt ) ;


<s> bool RetVal = true ; bool AllConstantIndices = I . hasAllConstantIndices ( ) ; if ( isStruct && ! AllConstantIndices ) return false ; Offset = ComputeOffsetForGEP ( IRB , I , Offset ) ; AddToLazyDeletionSet ( & I ) ;

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


<s> bool CastHandler :: ProcessGEPChain ( SrcMemOpOffset & MemOpOffsetMap , GetElementPtrInst & I , Value * Offset , bool isStruct ) { IRBuilder < > IRB ( & I ) ;


for ( auto * I : Users ) cast < Instruction > ( I ) -> eraseFromParent ( ) ;


<s> Users . insert ( Val ) ; } for ( auto * I : Users ) cast < Instruction > ( I ) -> eraseFromParent ( ) ;


<s> const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; assert ( isa < ArrayType > ( SrcTy ) || isa < StructType > ( SrcTy ) ) ; for ( auto & MemOpOffsetPair : MemOpOffsetMap ) { IRBuilder < > IRB ( cast < Instruction > ( MemOpOffsetPair . first ) ) ; Value * Offset = MemOpOffsetPair . second ; Value * SrcElement = llvm :: CreateCompositeElemAccessGEP ( DL , IRB , SrcMem , TargetIdxTy , SrcTy , & Offset ) ; ProcessLoadStorePrimtive ( IRB , SrcElement , MemOpOffsetPair . first , Offset , Align ) ; }


<s> IRBuilder < > IRB ( cast < Instruction > ( MemOpOffsetPair . first ) ) ; ProcessLoadStorePrimtive ( IRB , SrcMem , MemOpOffsetPair . first , MemOpOffsetPair . second , <NUM_LIT> ) ;


<s> assert ( isa < StructType > ( SrcTy ) && <STR_LIT> ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ;

const StructLayout * SL = DL . getStructLayout ( cast < StructType > ( SrcTy ) ) ;


<s> assert ( isa < StructType > ( SrcTy ) && <STR_LIT> ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; const StructLayout * SL = DL . getStructLayout ( cast < StructType > ( SrcTy ) ) ; unsigned Align = SL -> hasPadding ( ) ? SL -> getAlignment ( ) * <NUM_LIT> : <NUM_LIT> ; SrcMemOpOffset MemOpOffsetMap ; for ( auto * User : I . users ( ) ) ProcessUser ( MemOpOffsetMap , * User , Offset , false ) ;

ProcessMemOpWRTCompositeSource ( SrcMem , MemOpOffsetMap , DestTy , Align ) ;


<s> AddToLazyDeletionSet ( & I ) ; for ( auto * BCUser : cast < BitCastInst > ( & I ) -> users ( ) ) RetVal &= ProcessUser ( MemOpOffsetMap , * BCUser , Offset , isStruct ) ; } else llvm_unreachable ( <STR_LIT> ) ;


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


<s> 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> for ( auto & Idx : GI -> indices ( ) ) if ( ! isa < ConstantInt > ( Idx ) ) return false ; } }


<s> bool CompositeHandler :: AreAllUsesConstantIndexedReferences ( Value * I ) { for ( auto * User : I -> users ( ) ) { if ( ! isa < GetElementPtrInst > ( User ) ) return false ;


<s> Argument * NewArguments = std :: allocator < Argument > ( ) . allocate ( ArgsCnt ) ; Func -> setArguments ( NewArguments , ArgsCnt ) ; for ( unsigned i = <NUM_LIT> , e = ArgsCnt ; i != e ; ++ i ) { Type * ArgTy = Func -> getFunctionType ( ) -> getParamType ( i ) ; assert ( ! ArgTy -> isVoidTy ( ) && <STR_LIT> ) ; new ( NewArguments + i ) Argument ( ArgTy , <STR_LIT> , const_cast < Function * > ( Func ) , i ) ; CopyArgumentAttributes ( Arguments + i , Func , i ) ; } }


<s> Argument * NewArguments = std :: allocator < Argument > ( ) . allocate ( ArgsCnt ) ; Func -> setArguments ( NewArguments , ArgsCnt ) ; for ( unsigned i = <NUM_LIT> , e = ArgsCnt ; i != e ; ++ i ) {

Type * ArgTy = Func -> getFunctionType ( ) -> getParamType ( i ) ;


<s> bool CompositeHandler :: canFlattenType ( Type * Ty ) { if ( Ty -> isPointerTy ( ) ) Ty = cast < PointerType > ( Ty ) -> getElementType ( ) ; if ( CompositeType :: classof ( Ty ) && ( dyn_cast < StructType > ( Ty ) || ( dyn_cast < ArrayType > ( Ty ) && ! CheckIfFlattendType ( cast < ArrayType > ( Ty ) -> getElementType ( ) ) ) ) ) return true ; return false ;


<s> for ( StructType :: element_iterator EB = STy -> element_begin ( ) , EI = EB , EE = STy -> element_end ( ) ; EI != EE ; ++ EI ) { if ( isa < StructType > ( * EI ) ) return false ;

else if ( isa < ArrayType > ( * EI ) ) retVal &= CheckIfFlattendType ( * EI ) ;


<s> if ( StructType * STy = dyn_cast < StructType > ( Ty ) ) { for ( StructType :: element_iterator EB = STy -> element_begin ( ) , EI = EB , EE = STy -> element_end ( ) ; EI != EE ; ++ EI ) { CollectPrimitiveTypes ( * EI , TyVec ) ; } } else if ( dyn_cast < PointerType > ( Ty ) ) { CollectPrimitiveTypes ( cast < PointerType > ( Ty ) -> getElementType ( ) , TyVec ) ; } else if ( dyn_cast < ArrayType > ( Ty ) ) { Type * ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; if ( isa < StructType > ( ElmTy ) || ( isa < ArrayType > ( ElmTy ) && ! CheckIfFlattendType ( ElmTy ) ) ) { CompositeHandler :: TypeVec ElmSubTys ; CollectPrimitiveTypes ( ElmTy , ElmSubTys ) ; for ( unsigned i = <NUM_LIT> ; i < cast < ArrayType > ( Ty ) -> getNumElements ( ) ; i ++ ) TyVec . append ( ElmSubTys . begin ( ) , ElmSubTys . end ( ) ) ; } else TyVec . push_back ( Ty ) ; } else TyVec . push_back ( Ty ) ;


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


<s> if ( Old -> hasSwiftSelfAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: SwiftSelf ) ; if ( Old -> hasSwiftErrorAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: SwiftError ) ; if ( Old -> hasInAllocaAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: InAlloca ) ;

if ( Old -> hasNestAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: Nest ) ;


<s> if ( Old -> hasNestAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: Nest ) ; if ( Old -> hasNoAliasAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: NoAlias ) ; if ( Old -> hasNoCaptureAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: NoCapture ) ; if ( Old -> hasStructRetAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: StructRet ) ;

if ( Old -> hasReturnedAttr ( ) ) Func -> addParamAttr ( ArgNo , Attribute :: Returned ) ;


<s> assert ( objFlatObjArr . find ( Src ) != objFlatObjArr . end ( ) && <STR_LIT> ) ; ValueVec IdxVec ; IdxVec . push_back ( ConstantInt :: get ( Type :: getInt32Ty ( Func -> getContext ( ) ) , APInt ( <NUM_LIT> , <NUM_LIT> ) ) ) ; if ( ! isa < ConstantInt > ( Src ) ) { if ( isBlastedType ( Ty ) ) { Type * BlTy = typeDefs [ Ty ] ; assert ( isa < StructType > ( BlTy ) ) ; for ( unsigned i = <NUM_LIT> ; i < cast < StructType > ( BlTy ) -> getNumElements ( ) ; i ++ ) { Type * ElmTy = cast < StructType > ( BlTy ) -> getElementType ( i ) ; Value * SrcObj = objFlatObjArr [ Src ] [ i ] ; Value * DstObj = objFlatObjArr [ Dst ] [ i ] ; if ( isa < SequentialType > ( ElmTy ) ) { int NumElms = cast < SequentialType > ( ElmTy ) -> getNumElements ( ) ; CopyCompositeObj ( DstObj , SrcObj , ElmTy , NumElms , IdxVec , IRB , Func -> getContext ( ) ) ; } else { CopyScalarObj ( DstObj , SrcObj , ElmTy , IRB ) ; } } } else { Value * SrcObj = objFlatObjArr [ Src ] [ <NUM_LIT> ] ; Value * DstObj = objFlatObjArr [ Dst ] [ <NUM_LIT> ] ; Type * SrcObjTy = GetRootType ( SrcObj -> getType ( ) ) ; Type * DstObjTy = GetRootType ( DstObj -> getType ( ) ) ;

assert ( isa < ArrayType > ( SrcObjTy ) && isa < ArrayType > ( DstObjTy ) ) ;


<s> static void CopyScalarObj ( Value * Dst , Value * Src , Type * ElmTy , IRBuilder < > & IRB ) {

Value * SrcLoad = IRB . CreateLoad ( Src ) ;


<s> DenseSet < Argument * > WorkListArgs ; IRBuilder < > IRB ( & Func -> getEntryBlock ( ) . front ( ) ) ; for ( auto & TyValPair : typeValues ) { for ( Value * V : TyValPair . second ) { if ( isa < AllocaInst > ( V ) ) { ValueVec ValArr ; Value * ArraySize = nullptr ; Type * FlatTy = typeDefs [ TyValPair . first ] ; FlatTy = GetRootType ( FlatTy ) ; if ( isBlastedType ( TyValPair . first ) ) { for ( unsigned i = <NUM_LIT> ; i < cast < StructType > ( FlatTy ) -> getNumElements ( ) ; i ++ ) { Type * ElmTy = cast < StructType > ( FlatTy ) -> getStructElementType ( i ) ; if ( isa < ArrayType > ( ElmTy ) ) { uint64_t ElemCount = cast < ArrayType > ( ElmTy ) -> getNumElements ( ) ; ArraySize = Constant :: getIntegerValue ( Type :: getInt32Ty ( Func -> getContext ( ) ) , APInt ( <NUM_LIT> , ElemCount ) ) ; ElmTy = cast < ArrayType > ( ElmTy ) -> getElementType ( ) ; } AllocaInst * AI = IRB . CreateAlloca ( ElmTy , ArraySize ) ; ValArr . push_back ( AI ) ; IRB . SetInsertPoint ( AI ) ; } } else ValArr . push_back ( IRB . CreateAlloca ( FlatTy , ArraySize ) ) ; if ( objFlatObjArr . find ( V ) == objFlatObjArr . end ( ) ) objFlatObjArr [ V ] = ValArr ; } else if ( isa < Argument > ( V ) ) WorkListArgs . insert ( cast < Argument > ( V ) ) ; } } if ( WorkListArgs . size ( ) > <NUM_LIT> ) { Argument * OldArgs = BuildAndSetArgsList ( Func ) ; for ( unsigned i = <NUM_LIT> ; i < Func -> arg_size ( ) ; i ++ ) { Argument * OldArg = OldArgs + i ; Type * ArgTy = OldArg -> getType ( ) ; if ( WorkListArgs . find ( OldArg ) == WorkListArgs . end ( ) ) OldArg -> replaceAllUsesWith ( Func -> arg_begin ( ) + i ) ; else { ValueVec ValArr ; assert ( typeDefs . find ( ArgTy ) != typeDefs . end ( ) && typeDefs [ ArgTy ] ) ; Argument * NewArg = new ( Func -> arg_begin ( ) + i ) Argument ( typeDefs [ ArgTy ] , <STR_LIT> , const_cast < Function * > ( Func ) , i ) ;

CopyArgumentAttributes ( OldArg , Func , i ) ;


<s> } } LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << ArgFixupCount << <STR_LIT> ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << AllocaFixupCount << <STR_LIT> ) ; for ( auto * User : LazyRemovalSet ) cast < Instruction > ( User ) -> removeFromParent ( ) ; if ( ArgFixupCount ) {


<s> void CompositeHandler :: doTypeCollection ( ) { for ( Argument & Arg : Func -> args ( ) ) visitValue ( & Arg , Arg . getType ( ) ) ; visit ( Func ) ;


<s> if ( Ty . second ) Ty . second -> dump ( ) ; else dbgs ( ) << <STR_LIT> ; dbgs ( ) << <STR_LIT> ;


<s> for ( auto Val : typeValues [ Ty . first ] ) Val -> dump ( ) ; dbgs ( ) << <STR_LIT> ; if ( Ty . second ) Ty . second -> dump ( ) ; else dbgs ( ) << <STR_LIT> ;


<s> unsigned NumLeadingNonLeafArrDim = GetNumLeadingNonLeafArrDim ( Elm ) ; IList . append ( Elm -> idx_begin ( ) , Elm -> idx_begin ( ) + NumLeadingNonLeafArrDim + <NUM_LIT> ) ; } else IList . append ( Elm -> idx_begin ( ) , Elm -> idx_end ( ) ) ; User * OnlyUse = * ( Elm -> user_begin ( ) ) ; if ( dyn_cast < GetElementPtrInst > ( OnlyUse ) ) { InsertIntoSet ( LazyRemovalSet , Elm ) ; return extractIndices ( Ty , cast < GetElementPtrInst > ( OnlyUse ) , IList , LazyRemovalSet , AccessMemFormFlatStruct ) ; } return Elm ;


<s> IList . append ( Elm -> idx_begin ( ) , Elm -> idx_begin ( ) + NumLeadingNonLeafArrDim + <NUM_LIT> ) ; } else IList . append ( Elm -> idx_begin ( ) , Elm -> idx_end ( ) ) ; User * OnlyUse = * ( Elm -> user_begin ( ) ) ; if ( dyn_cast < GetElementPtrInst > ( OnlyUse ) ) {

InsertIntoSet ( LazyRemovalSet , Elm ) ;


<s> assert ( typeDefs . find ( TyPair . first ) != typeDefs . end ( ) ) ; if ( typeDefs [ TyPair . first ] == nullptr ) typeDefs [ TyPair . first ] = flattenType_core ( Func -> getContext ( ) , TyPair . first ) ; }


<s> assert ( typeDefs . find ( TyPair . first ) != typeDefs . end ( ) ) ; if ( typeDefs [ TyPair . first ] == nullptr ) typeDefs [ TyPair . first ] = flattenType_core ( Func -> getContext ( ) , TyPair . first ) ;


<s> Type * MPT = GetMostPreferredTypeForStruct ( Func -> getContext ( ) , TyVec , NumElements ) ; NewTy = ArrayType :: get ( MPT , NumElements ) ; typeIsBlasted [ Ty ] = false ; } else { NewTy = StructType :: get ( Cxt , TyVec ) ; typeIsBlasted [ Ty ] = true ; } if ( Ty -> isPointerTy ( ) ) return PointerType :: get ( NewTy , cast < PointerType > ( Ty ) -> getAddressSpace ( ) ) ;


<s> Type * MPT = Type :: getInt32Ty ( Cxt ) ; for ( auto Ty : TyVec ) { int ElmCnt = <NUM_LIT> ; Type * ElmTy = nullptr ; if ( isa < ArrayType > ( Ty ) ) { ElmCnt = cast < ArrayType > ( Ty ) -> getNumElements ( ) ; ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; while ( isa < ArrayType > ( ElmTy ) ) { ElmCnt *= cast < ArrayType > ( ElmTy ) -> getNumElements ( ) ; ElmTy = cast < ArrayType > ( ElmTy ) -> getElementType ( ) ; } } else { ElmTy = Ty ; ElmCnt = <NUM_LIT> ; } if ( ElmTy -> getPrimitiveSizeInBits ( ) > MPT -> getPrimitiveSizeInBits ( ) ) { ElmCnt *= ElmTy -> getPrimitiveSizeInBits ( ) / MPT -> getPrimitiveSizeInBits ( ) ; llvm_unreachable ( <STR_LIT> ) ; }


<s> Type * ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; bool exploreArr = ! CheckIfFlattendType ( ElmTy ) || ! AccessMemFormFlatStruct ; if ( isa < StructType > ( ElmTy ) || ( isa < ArrayType > ( ElmTy ) && exploreArr ) ) { int NumArrElems = cast < ArrayType > ( Ty ) -> getNumElements ( ) ; NumElems += NumArrElems * getNumElements ( ElmTy , AccessMemFormFlatStruct ) ; } else NumElems += exploreArr ? cast < ArrayType > ( Ty ) -> getNumElements ( ) : <NUM_LIT> ;

} else if ( isa < PointerType > ( Ty ) ) {


<s> static unsigned GetNumLeadingNonLeafArrDim ( GetElementPtrInst * GI ) {

if ( GI -> getNumIndices ( ) > <NUM_LIT> ) return ( GI -> getNumIndices ( ) - ( GetNumLeafArrayDimensions ( GI ) + <NUM_LIT> ) ) ;


<s> static unsigned GetNumLeafArrayDimensions ( GetElementPtrInst * V ) { int i = <NUM_LIT> ; SmallVector < Type * , <NUM_LIT> > WorkList ; for ( gep_type_iterator Itr = gep_type_begin ( V ) ; Itr != gep_type_end ( V ) ; Itr ++ ) WorkList . push_back ( Itr . getIndexedType ( ) ) ; WorkList . pop_back ( ) ; while ( WorkList . size ( ) ) {


<s> OTy = GetRootType ( OTy ) ; gep_type_iterator IdxTyItr = gep_type_begin ( GI ) ; assert ( OTy == IdxTyItr . getIndexedType ( ) && <STR_LIT> ) ;

return getTyIndexInFlattenedType_core ( Func , ConstantInt :: get ( Int32Ty , APInt ( <NUM_LIT> , <NUM_LIT> ) ) , GI , AccessMemFormFlatStruct ) ;


<s> assert ( OTy == IdxTyItr . getIndexedType ( ) && <STR_LIT> ) ; return getTyIndexInFlattenedType_core ( Func , ConstantInt :: get ( Int32Ty , APInt ( <NUM_LIT> , <NUM_LIT> ) ) , GI , AccessMemFormFlatStruct ) ;


<s> IdxOffset = ConstantInt :: get ( Int32Ty , CumulativeIndex ) ; } else if ( NextRef == ArrayElemRef ) { IdxOffset = IRB . CreateBinOp ( Instruction :: Mul , ConstantInt :: get ( Int32Ty , APInt ( <NUM_LIT> , getNumElements ( cast < ArrayType > ( PrevTy ) -> getElementType ( ) , AccessMemFormFlatStruct ) ) ) , IdxVal ) ; } else IdxOffset = IdxVal ; if ( isa < ArrayType > ( IdxTy ) ) NextRef = ArrayElemRef ; else if ( isa < StructType > ( IdxTy ) || isa < PointerType > ( IdxTy ) ) NextRef = StructFieldRef ; else NextRef = ScalarRef ; Idx = IRB . CreateBinOp ( Instruction :: Add , Idx , IdxOffset ) ; if ( -- NumLeadingNonLeafArrDim == <NUM_LIT> ) return Idx ; PrevTy = IdxTy ; }

if ( isa < GetElementPtrInst > ( * ( GI -> user_begin ( ) ) ) ) return getTyIndexInFlattenedType_core ( Func , Idx , cast < GetElementPtrInst > ( * ( GI -> user_begin ( ) ) ) , AccessMemFormFlatStruct ) ;


<s> if ( Set . find ( Val ) == Set . end ( ) ) Set . insert ( Val ) ;


<s> void CompositeHandler :: ProcessFunction ( ) { doTypeCollection ( ) ; dump ( ) ; flattenTypes ( ) ; dump ( ) ; doAllocations ( ) ; doReplacements ( ) ;


<s> dump ( ) ; flattenTypes ( ) ; dump ( ) ; doAllocations ( ) ;


<s> void CompositeHandler :: replaceAllUsesWithUnwrapped ( Value * Old , Value * New ) {

assert ( Old -> getType ( ) != New -> getType ( ) && <STR_LIT> ) ;


<s> assert ( Old -> getType ( ) != New -> getType ( ) && <STR_LIT> ) ;

for ( auto * User : Old -> users ( ) ) for ( unsigned i = <NUM_LIT> ; i < User -> getNumOperands ( ) ; i ++ ) if ( User -> getOperand ( i ) == Old ) User -> setOperand ( i , New ) ;


<s> void CompositeHandler :: replaceCastChainAndMemIntrinsics ( Type * Ty , BitCastInst * V , ValueSet & LazyRemovalSet , ValueVec & ValArr ) { if ( ! isa < BitCastInst > ( V ) || ! cast < BitCastInst > ( V ) -> hasOneUse ( ) ) return ; Value * OnlyUser = * ( V -> user_begin ( ) ) ; if ( isa < CallInst > ( OnlyUser ) && cast < CallInst > ( OnlyUser ) -> getCalledFunction ( ) ) { unsigned ID = cast < CallInst > ( OnlyUser ) -> getCalledFunction ( ) -> getIntrinsicID ( ) ;

assert ( ( ID == <STR_LIT> || ID == <STR_LIT> || ID == <STR_LIT> ) && <STR_LIT> ) ;


<s> Value * Base = AIArr [ <NUM_LIT> ] ; Type * Int32Ty = Type :: getInt32Ty ( Func -> getContext ( ) ) ; Mem = IRB . CreateGEP ( Base , { ConstantInt :: get ( Int32Ty , APInt ( <NUM_LIT> , <NUM_LIT> ) ) , AIArrIdx } ) ; } if ( isa < ArrayType > ( IndexType ) ) { int NumLeadingNonLeafArrDim = GetNumLeadingNonLeafArrDim ( lastGEP ) ; bool CreateNewLeafGEP = NumLeadingNonLeafArrDim > <NUM_LIT> ; if ( CreateNewLeafGEP ) { IRB . SetInsertPoint ( lastGEP ) ; SmallVector < Value * , <NUM_LIT> > IdxVec ; IdxVec . append ( lastGEP -> idx_begin ( ) + NumLeadingNonLeafArrDim , lastGEP -> idx_end ( ) ) ; Value * NewGEP = IRB . CreateGEP ( Mem , IdxVec ) ; lastGEP -> replaceAllUsesWith ( NewGEP ) ; InsertIntoSet ( LazyRemovalSet , lastGEP ) ; } else lastGEP -> getOperand ( <NUM_LIT> ) -> replaceAllUsesWith ( Mem ) ; } else if ( isa < StructType > ( IndexType ) ) { replaceAllUsesWithUnwrapped ( lastGEP , Mem ) ; InsertIntoSet ( LazyRemovalSet , lastGEP ) ; } else { lastGEP -> replaceAllUsesWith ( Mem ) ;


<s> unsigned TySize = Func -> getParent ( ) -> getDataLayout ( ) . getTypeSizeInBits ( RootTy ) / <NUM_LIT> ; IRBuilder < > IRB ( CI ) ; if ( isa < ConstantInt > ( Size ) && TySize == cast < ConstantInt > ( Size ) -> getZExtValue ( ) ) { copyMemory ( Dst , Src , Ty , ValArr , IRB ) ; RemoveInstrs . push_back ( CI ) ; for ( auto Val : RemoveInstrs ) InsertIntoSet ( LazyRemovalSet , Val ) ; } else {


<s> ValueVec RemoveInstrs ; auto GetRootValue = [ & ] ( Value * V ) -> Value * { while ( isa < CastInst > ( V ) ) { RemoveInstrs . push_back ( V ) ; V = cast < User > ( V ) -> getOperand ( <NUM_LIT> ) ; } return V ; } ; Value * Dst = CI -> getOperand ( <NUM_LIT> ) ; Value * Src = CI -> getOperand ( <NUM_LIT> ) ; Value * Size = CI -> getOperand ( <NUM_LIT> ) ;


<s> else if ( isa < BitCastInst > ( User ) ) replaceCastChainAndMemIntrinsics ( Ty , cast < BitCastInst > ( User ) , LazyRemovalSet , ValArr ) ; else llvm_unreachable ( <STR_LIT> ) ; } if ( RemoveVal ) InsertIntoSet ( LazyRemovalSet , V ) ;


<s> visitValue ( & I , I . getType ( ) ) ;


<s> void CompositeHandler :: visitCallInst ( CallInst & I ) { for ( Value * Arg : I . arg_operands ( ) ) {

visitValue ( Arg , Arg -> getType ( ) ) ;


<s> if ( canFlattenType ( VT ) ) { if ( typeDefs . find ( VT ) == typeDefs . end ( ) ) typeDefs [ VT ] = nullptr ;


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


<s> for ( DeferredEraseSetIter I = EraseSet . begin ( ) , E = EraseSet . end ( ) ; I != E ;


<s> I ++ ) { ( * I ) -> eraseFromParent ( ) ; }


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


<s> FunctionPass * create<ISA_LIT>CopyElision ( ) { return new <ISA_LIT>CopyElision ( ) ;


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


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


<s> void <ISA_LIT>CopyElision :: 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 ; ExitScope ( Parent -> getBlock ( ) ) ; Node = Parent ;


<s> AU . setPreservesCFG ( ) ; MachineFunctionPass :: getAnalysisUsage ( AU ) ;

AU . addRequired < MachineDominatorTree > ( ) ;


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


<s> MachineOperand RHS = MI -> getOperand ( <NUM_LIT> ) ; const TargetRegisterClass * LHSRC = MRI -> getRegClass ( LHS . getReg ( ) ) ; const TargetRegisterClass * RHSRC = MRI -> getRegClass ( RHS . getReg ( ) ) ;


<s> <ISA_LIT>CopyElision ( ) : MachineFunctionPass ( ID ) { initialize<ISA_LIT>CopyElisionPass ( * PassRegistry :: getPassRegistry ( ) ) ;


<s> initialize<ISA_LIT>CopyElisionPass ( * PassRegistry :: getPassRegistry ( ) ) ;


<s> 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 ) ;


<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 ( ) ;


<s> MachineOperand MORHS = MI -> getOperand ( <NUM_LIT> ) ; unsigned NewReg = MRI -> createVirtualRegister ( MRI -> getRegClass ( MORHS . getReg ( ) ) ) ; if ( HasConstantDriver ( MRI , MORHS , isInt , & ConstNode ) ) { BuildMI ( * MBB , I , MI -> getDebugLoc ( ) , TII -> get ( <STR_LIT> ( MRI -> getRegClass ( MORHS . getReg ( ) ) ) ) ) . addDef ( NewReg ) . addImm ( ConstNode -> getOperand ( <NUM_LIT> ) . getImm ( ) ) ; AddToDeferredEraseSet ( ConstNode ) ; } else { unsigned LoadOpcode = <STR_LIT> ( MRI -> getRegClass ( MORHS . getReg ( ) ) ) ; BuildMI ( * MBB , I , MI -> getDebugLoc ( ) , TII -> get ( LoadOpcode ) ) . addDef ( NewReg ) . addUse ( MORHS . getReg ( ) ) ; } MachineOperand MOLHS = MI -> getOperand ( <NUM_LIT> ) ; unsigned StoreOpcode = <STR_LIT> ( MRI -> getRegClass ( MOLHS . getReg ( ) ) ) ; BuildMI ( * MBB , I , MI -> getDebugLoc ( ) , TII -> get ( StoreOpcode ) ) . addDef ( MOLHS . getReg ( ) ) . addUse ( NewReg ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> << MBB -> getName ( ) << '\n' ) ; bool isInt ; MachineInstr * ConstNode = nullptr ; MachineOperand MORHS = MI -> getOperand ( <NUM_LIT> ) ; unsigned NewReg = MRI -> createVirtualRegister ( MRI -> getRegClass ( MORHS . getReg ( ) ) ) ; if ( HasConstantDriver ( MRI , MORHS , isInt , & ConstNode ) ) { BuildMI ( * MBB , I , MI -> getDebugLoc ( ) , TII -> get ( <STR_LIT> ( MRI -> getRegClass ( MORHS . getReg ( ) ) ) ) ) . addDef ( NewReg ) . addImm ( ConstNode -> getOperand ( <NUM_LIT> ) . getImm ( ) ) ; AddToDeferredEraseSet ( ConstNode ) ; } else { unsigned LoadOpcode = <STR_LIT> ( MRI -> getRegClass ( MORHS . getReg ( ) ) ) ;

BuildMI ( * MBB , I , MI -> getDebugLoc ( ) , TII -> get ( LoadOpcode ) ) . addDef ( NewReg ) . addUse ( MORHS . getReg ( ) ) ;


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


<s> bool <ISA_LIT>CopyElision :: 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> ) ; PerformCopyElision ( DT -> getRootNode ( ) ) ; return true ;


<s> std :: unique_ptr < const MCInstrInfo > MCII ( T . createMCInstrInfo ( ) ) ; return new <ISA_LIT>Disassembler ( STI , Ctx , std :: move ( MCII ) ) ;


<s> return new <ISA_LIT>Disassembler ( STI , Ctx , std :: move ( MCII ) ) ;


<s> <ISA_LIT>Disassembler ( const MCSubtargetInfo & STI , MCContext & Ctx , std :: unique_ptr < const MCInstrInfo > MCII ) : MCDisassembler ( STI , Ctx ) , MCII ( std :: move ( MCII ) ) {


<s> void LLVMInitialize<ISA_LIT>Disassembler ( ) { TargetRegistry :: RegisterMCDisassembler ( getThe<ISA_LIT>Target32 ( ) , create<ISA_LIT>Disassembler ) ;

TargetRegistry :: RegisterMCDisassembler ( getThe<ISA_LIT>Target64 ( ) , create<ISA_LIT>Disassembler ) ;


<s> void <ISA_LIT>FrameLowering :: emitEpilogue ( MachineFunction & MF , MachineBasicBlock & MBB ) const {


<s> void <ISA_LIT>FrameLowering :: emitPrologue ( MachineFunction & MF , MachineBasicBlock & MBB ) const {


<s> bool <ISA_LIT>FrameLowering :: hasFP ( const MachineFunction & MF ) const {


<s> bool <ISA_LIT>FrameLowering :: hasFP ( const MachineFunction & MF ) const { return false ;


<s> <ISA_LIT>FrameLowering ( ) : TargetFrameLowering ( StackGrowsDown , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , true ) {


<s> <ISA_LIT>InstPrinter :: <ISA_LIT>InstPrinter ( const MCAsmInfo & MAI , const MCInstrInfo & MII , const MCRegisterInfo & MRI ) : MCInstPrinter ( MAI , MII , MRI ) {


<s> void <ISA_LIT>InstPrinter :: printInst ( const MCInst * MI , raw_ostream & OS , StringRef Annot , const MCSubtargetInfo & ) { printInstruction ( MI , OS ) ; printAnnotation ( OS , Annot ) ;


StringRef Desc = ( * DescVec ) [ MI -> getOperand ( OpNo ) . getImm ( ) ] ;


<s> if ( Op . isReg ( ) ) { llvm_unreachable ( <STR_LIT> ) ; } else if ( Op . isImm ( ) ) { O << Op . getImm ( ) ; } else if ( Op . isFPImm ( ) ) { assert ( OpNo < Desc . getNumOperands ( ) && <STR_LIT> ) ; assert ( Desc . TSFlags == <NUM_LIT> && <STR_LIT> ) ; if ( Info . OperandType == <STR_LIT> ) { O << Op . getFPImm ( ) ; } else { assert ( Info . OperandType == <STR_LIT> ) ;


<s> } else { assert ( ! CBR && <STR_LIT> ) ; CBR = & MI ; } } if ( nullptr == CBR && nullptr == UBR ) return true ; else if ( UBR && ! CBR ) { TBB = UBR -> getOperand ( <NUM_LIT> ) . getMBB ( ) ; } else if ( CBR ) { TBB = CBR -> getOperand ( CBR -> getNumOperands ( ) - <NUM_LIT> ) . getMBB ( ) ; for ( unsigned i = <NUM_LIT> ; i < CBR -> getNumOperands ( ) - <NUM_LIT> ; i ++ ) Cond . push_back ( CBR -> getOperand ( i ) ) ; FBB = UBR ? UBR -> getOperand ( <NUM_LIT> ) . getMBB ( ) : nullptr ; } else { llvm_unreachable ( <STR_LIT> ) ; }


<s> void <ISA_LIT>InstrInfo :: copyPhysReg ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , const DebugLoc & DL , unsigned DestReg , unsigned SrcReg , bool KillSrc ) const {


<s> else return MI . getOperand ( MI . getNumOperands ( ) - <NUM_LIT> ) . getMBB ( ) ;


<s> else if ( ! IsConditionalBranch ( MI ) ) return MI . getOperand ( <NUM_LIT> ) . getMBB ( ) ;

else return MI . getOperand ( MI . getNumOperands ( ) - <NUM_LIT> ) . getMBB ( ) ;


<s> bool <ISA_LIT>InstrInfo :: IsConditionalBranch ( const MachineInstr & MI ) const { assert ( MI . isBranch ( ) && <STR_LIT> ) ; switch ( MI . getOpcode ( ) ) { default :


<s> <ISA_LIT>InstrInfo :: <ISA_LIT>InstrInfo ( const <ISA_LIT>Subtarget & STI ) : <ISA_LIT>GenInstrInfo ( ) , RI ( STI . getTargetTriple ( ) ) {


<s> if ( ! MI . isBranch ( ) ) break ; MI . eraseFromParent ( ) ; Count ++ ; } return Count ;


<s> MachineInstr & MI = * ritr ; if ( ! MI . isBranch ( ) ) break ; MI . eraseFromParent ( ) ; Count ++ ;


<s> break ; case <STR_LIT> : NewCond = <STR_LIT> ; break ; case <STR_LIT> : NewCond = <STR_LIT> ; break ; case <STR_LIT> : NewCond = <STR_LIT> ; break ; case <STR_LIT> : NewCond = <STR_LIT> ; break ; case <STR_LIT> : NewCond = <STR_LIT> ; break ; case <STR_LIT> : NewCond = <STR_LIT> ; break ; case <STR_LIT> : NewCond = <STR_LIT> ;


<s> SmallVector < Instruction * , <NUM_LIT> > DelList ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; for ( auto & BB : * F ) for ( auto & II : BB ) if ( Value * Const = ConstantFoldInstruction ( & II , DL , nullptr ) ) { II . replaceAllUsesWith ( Const ) ; DelList . push_back ( & II ) ; } for ( auto Inst : DelList ) { DropAllReferences ( Inst ) ; Inst -> removeFromParent ( ) ; }


<s> II . replaceAllUsesWith ( Const ) ; DelList . push_back ( & II ) ; } for ( auto Inst : DelList ) { DropAllReferences ( Inst ) ;


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


<s> for ( Use & U : V -> operands ( ) ) {

if ( isa < ConstantExpr > ( U . get ( ) ) ) DropAllReferences ( cast < User > ( U . get ( ) ) ) ;


<s> void <ISA_LIT>IRDecorator :: DropAllReferences ( User * V ) { for ( Use & U : V -> operands ( ) ) { if ( isa < ConstantExpr > ( U . get ( ) ) ) DropAllReferences ( cast < User > ( U . get ( ) ) ) ;


<s> void <ISA_LIT>IRDecorator :: EmitArgumentInitializationWrappers ( ) {


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


<s> SmallVector < Value * , <NUM_LIT> > WorkList ; using IndexKind = enum { SCALAR_REF , ARRAY_REF , STRUCT_REF } ; LLVMContext & Cxt = Func -> getContext ( ) ; const DataLayout & DL = F -> getParent ( ) -> getDataLayout ( ) ; for ( auto & BB : * F ) { for ( auto & II : BB ) { if ( isa < GetElementPtrInst > ( & II ) ) { bool Change = false ; SmallVector < Value * , <NUM_LIT> > Indices ; IRBuilder < > IRB ( cast < Instruction > ( & II ) ) ; IndexKind NextIndex = SCALAR_REF ; for ( gep_type_iterator GTI = gep_type_begin ( & II ) , E = gep_type_end ( & II ) ; GTI != E ; ++ GTI ) { const Value * Idx = GTI . getOperand ( ) ; Type * IdxTy = GTI . getIndexedType ( ) ; if ( NextIndex == ARRAY_REF ) { Value * NewIdx = GetTypeNormalizedValue ( DL , IRB , const_cast < Value * > ( Idx ) , Type :: getInt32Ty ( Cxt ) ) ; Change = Idx != NewIdx ; Idx = NewIdx ;


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


<s> BitCastXForm . setFunction ( * F ) ; BitCastXForm . ProcessFunction ( ) ;


<s> void <ISA_LIT>IRDecorator :: HandleGlobalConstants ( Function * F ) { Module * M = F -> getParent ( ) ; if ( M -> global_empty ( ) ) return ; unsigned FieldIndex = <NUM_LIT> ; SmallVector < Type * , <NUM_LIT> > TypeList ; SmallVector < Constant * , <NUM_LIT> > InitVals ; GlobFieldOffsetMap GlobOffsetMap ; for ( auto & Glob : M -> globals ( ) ) { TypeList . push_back ( GetRootType ( Glob . getType ( ) ) ) ; InitVals . push_back ( Glob . getInitializer ( ) ) ;

GlobOffsetMap [ & Glob ] = FieldIndex ++ ;


<s> <ISA_LIT>IRDecorator ( ) : FunctionPass ( ID ) {


<s> Indices . pop_back ( ) ; Value * Index = cast < GetElementPtrInst > ( GEP ) -> getOperand ( <NUM_LIT> ) ; Index = GetTypeNormalizedValue ( DL , IRB , Index , LastIndex -> getType ( ) ) ; Value * NextIndex = IRB . CreateAdd ( LastIndex , Index ) ; Indices . push_back ( NextIndex ) ; } else { init = SoC ? <NUM_LIT> : <NUM_LIT> ; for ( i = init ; i < cast < GetElementPtrInst > ( GEP ) -> getNumIndices ( ) ; i ++ ) Indices . push_back ( cast < GetElementPtrInst > ( GEP ) -> getOperand ( i + <NUM_LIT> ) ) ; } SmallVector < std :: pair < Instruction * , Value * > , <NUM_LIT> > UserGEPClonePairVec ; for ( auto * User : GEP -> users ( ) ) { IRB . SetInsertPoint ( cast < Instruction > ( User ) ) ; if ( isa < GetElementPtrInst > ( User ) ) LinearizeGEP ( IRB , Ptr , User , false , Indices ) ; else { Value * NewMergeGEP = IRB . CreateGEP ( Ptr , Indices ) ; UserGEPClonePairVec . push_back ( std :: make_pair ( cast < Instruction > ( User ) , NewMergeGEP ) ) ; } } for ( auto UserClonePair : UserGEPClonePairVec ) UserClonePair . first -> replaceUsesOfWith ( GEP , UserClonePair . second ) ; for ( i = init ; i < cast < GetElementPtrInst > ( GEP ) -> getNumIndices ( ) ; i ++ ) Indices . pop_back ( ) ; if ( LastIndex ) Indices . push_back ( LastIndex ) ;


<s> Value * Ptr = cast < GetElementPtrInst > ( & II ) -> getPointerOperand ( ) ; bool IsInGEPChain = isa < GetElementPtrInst > ( Ptr ) ; for ( auto * User : II . users ( ) ) { if ( ! IsInGEPChain && isa < GetElementPtrInst > ( User ) ) { WorkList . push_back ( & II ) ;


<s> BasicBlock * NewBlk = OldTI -> getParent ( ) ; BasicBlock * TrueBlk = BasicBlock :: Create ( Cxt , NewBlk -> getName ( ) + <STR_LIT> , Func ) ; TrueBlk -> moveAfter ( NewBlk ) ; BasicBlock * FalseBlk = BasicBlock :: Create ( Cxt , NewBlk -> getName ( ) + <STR_LIT> , Func ) ; FalseBlk -> moveAfter ( TrueBlk ) ; IRB . SetInsertPoint ( OldTI ) ; IRB . CreateCondBr ( Cond , TrueBlk , FalseBlk ) ; OldTI -> eraseFromParent ( ) ; IRB . SetInsertPoint ( TrueBlk ) ; IRB . CreateBr ( EndBlk ) ; IRB . SetInsertPoint ( FalseBlk ) ; IRB . CreateBr ( EndBlk ) ; IRB . SetInsertPoint ( EndBlk -> getFirstNonPHI ( ) ) ; PHINode * PHI = IRB . CreatePHI ( Select -> getType ( ) , <NUM_LIT> ) ; PHI -> addIncoming ( TrueVal , TrueBlk ) ; PHI -> addIncoming ( FalseVal , FalseBlk ) ;


<s> Value * FalseVal = Select -> getFalseValue ( ) ; BasicBlock :: iterator SplitIt = Select -> getIterator ( ) ; BasicBlock * EndBlk = SplitBlock ( Select -> getParent ( ) , & * ++ SplitIt , DT ) ; Instruction * OldTI = cast < Instruction > ( * EndBlk -> user_begin ( ) ) ; BasicBlock * NewBlk = OldTI -> getParent ( ) ; BasicBlock * TrueBlk = BasicBlock :: Create ( Cxt , NewBlk -> getName ( ) + <STR_LIT> , Func ) ; TrueBlk -> moveAfter ( NewBlk ) ; BasicBlock * FalseBlk = BasicBlock :: Create ( Cxt , NewBlk -> getName ( ) + <STR_LIT> , Func ) ; FalseBlk -> moveAfter ( TrueBlk ) ; IRB . SetInsertPoint ( OldTI ) ; IRB . CreateCondBr ( Cond , TrueBlk , FalseBlk ) ; OldTI -> eraseFromParent ( ) ; IRB . SetInsertPoint ( TrueBlk ) ; IRB . CreateBr ( EndBlk ) ; IRB . SetInsertPoint ( FalseBlk ) ;


<s> return true ; } } ; for ( auto & BB : * F ) for ( auto & II : BB ) if ( IsFixupCandidate ( II . getOpcode ( ) ) ) WorkList . push_back ( & II ) ; for ( auto Inst : WorkList ) { switch ( Inst -> getOpcode ( ) ) { default : llvm_unreachable ( <STR_LIT> ) ; case Instruction :: ICmp : FixupICmp ( Inst ) ;


<s> LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; Func -> dump ( ) ; FixupCompositeIndexes ( Func ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; Func -> dump ( ) ; LinearizeGEPChains ( Func ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; Func -> dump ( ) ; UniquifyGEPOperands ( Func ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ; Func -> dump ( ) ; PerformIRFixups ( Func ) ; LLVM_DEBUG ( dbgs ( ) << <STR_LIT> ) ;


<s> void <ISA_LIT>IRDecorator :: ReplaceConstantGlobsRefs ( GlobalVariable * GV , GlobalVariable * GCStruct , GlobFieldOffsetMap & GlobOffsetMap ) { LLVMContext & Cxt = Func -> getContext ( ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; Type * TargetIdxTy = GetTargetIndexType ( DL , Cxt ) ; SmallVector < Instruction * , <NUM_LIT> > RemoveList ; SmallVector < std :: pair < Instruction * , Value * > , <NUM_LIT> > UserGEPClonePairVec ; for ( auto Use = GV -> use_begin ( ) ; Use != GV -> use_end ( ) ; Use ++ ) { SmallVector < Value * , <NUM_LIT> > Indices ; unsigned FldIndex = GlobOffsetMap [ GV ] ; Indices . push_back ( ConstantInt :: get ( TargetIdxTy , <NUM_LIT> ) ) ;

Indices . push_back ( ConstantInt :: get ( TargetIdxTy , FldIndex ) ) ;


<s> DT = & getAnalysis < DominatorTreeWrapperPass > ( ) . getDomTree ( ) ;


<s> if ( isa < GetElementPtrInst > ( GEPPtr ) ) { SmallVector < Value * , <NUM_LIT> > Indices ; for ( auto & Index : cast < GetElementPtrInst > ( GEPPtr ) -> indices ( ) ) Indices . push_back ( Index ) ;

IRBuilder < > IRB ( cast < Instruction > ( GEPclone ) ) ;


<s> if ( ! isa < GetElementPtrInst > ( User ) ) { WorkList . push_back ( & II ) ; break ; } } } for ( auto * II : WorkList ) { GetElementPtrInst * GEP = cast < GetElementPtrInst > ( II ) ; if ( GEP -> use_empty ( ) ) continue ; SmallVector < Value * , <NUM_LIT> > Indices ; for ( auto & Index : GEP -> indices ( ) ) Indices . push_back ( Index ) ; Value * GEPclone = nullptr ; SmallVector < std :: pair < Instruction * , Value * > , <NUM_LIT> > UserGEPClonePairVec ; for ( auto & Use : GEP -> uses ( ) ) { Instruction * UI = cast < Instruction > ( Use . getUser ( ) ) ; IRBuilder < > IRB ( UI ) ; GEPclone = IRB . CreateGEP ( GEP -> getPointerOperand ( ) , Indices ) ; UserGEPClonePairVec . push_back ( std :: make_pair ( UI , GEPclone ) ) ; } for ( auto UserClonePair : UserGEPClonePairVec ) { UserClonePair . first -> replaceUsesOfWith ( GEP , UserClonePair . second ) ; UniquifyGEPChain ( GEP , UserClonePair . second ) ; } }


<s> for ( auto & BB : * F ) for ( auto & II : BB ) if ( isa < GetElementPtrInst > ( & II ) ) { for ( auto * User : II . users ( ) ) { if ( ! isa < GetElementPtrInst > ( User ) ) { WorkList . push_back ( & II ) ; break ; } } } for ( auto * II : WorkList ) { GetElementPtrInst * GEP = cast < GetElementPtrInst > ( II ) ; if ( GEP -> use_empty ( ) ) continue ; SmallVector < Value * , <NUM_LIT> > Indices ; for ( auto & Index : GEP -> indices ( ) ) Indices . push_back ( Index ) ; Value * GEPclone = nullptr ;

SmallVector < std :: pair < Instruction * , Value * > , <NUM_LIT> > UserGEPClonePairVec ;


<s> FunctionPass * llvm :: create<ISA_LIT>ISelDag ( <ISA_LIT>TargetMachine & TM , CodeGenOpt :: Level OptLevel ) {

return new <ISA_LIT>DAGToDAGISel ( TM , OptLevel ) ;


<s> StringRef getPassName ( ) const override {


<s> <ISA_LIT>DAGToDAGISel ( <ISA_LIT>TargetMachine & tm , CodeGenOpt :: Level OptLevel ) : SelectionDAGISel ( tm , OptLevel ) , Subtarget ( nullptr ) , ForCodeSize ( false ) {


<s> ForCodeSize = MF . getFunction ( ) . hasFnAttribute ( Attribute :: OptimizeForSize ) || MF . getFunction ( ) . hasFnAttribute ( Attribute :: MinSize ) ; Subtarget = & MF . getSubtarget < <ISA_LIT>Subtarget > ( ) ; <ISA_LIT>FunctionInfo * MFI = MF . getInfo < <ISA_LIT>FunctionInfo > ( ) ; for ( auto & STy : Cxt . getNamedStructTypes ( ) ) MFI -> addToTypeNameMap ( STy . getValue ( ) ) ; const Function & F = MF . getFunction ( ) ; if ( F . hasFnAttribute ( Attribute :: <ISA_LIT>InstMethod ) ) { const Module * Mod = F . getParent ( ) ; StringRef ModName = Mod -> getName ( ) ; const GlobalVariable * GCStructObj = Mod -> getNamedGlobal ( <STR_LIT> ) ; assert ( GCStructObj && <STR_LIT> ) ;

std :: string ClassName = ModName . substr ( <NUM_LIT> , ModName . find ( <STR_LIT> ) ) ;


<s> if ( Node -> isMachineOpcode ( ) ) { LLVM_DEBUG ( errs ( ) << <STR_LIT> ; Node -> dump ( CurDAG ) ; errs ( ) << <STR_LIT> ) ; Node -> setNodeId ( - <NUM_LIT> ) ; return ; } EVT VT = Node -> getValueType ( <NUM_LIT> ) ; switch ( Node -> getOpcode ( ) ) {


<s> if ( RepMap . find ( N ) == RepMap . end ( ) ) { RepMap [ N ] = Replicator - <NUM_LIT> ;


<s> static bool CallingConvSupported ( CallingConv :: ID CallConv ) {


<s> bool <ISA_LIT>TargetLowering :: CanLowerReturn ( CallingConv :: ID , MachineFunction & , bool , const SmallVectorImpl < <STR_LIT> > & Outs , LLVMContext & ) const {


<s> void <ISA_LIT>TargetLowering :: clearAuxiliaryData ( ) { RepMap . clear ( ) ; Replicator = <NUM_LIT> ;


<s> const AllocaInst * AI = cast < const AllocaInst > ( & I ) ; SDValue ArrSz = SDB -> getValue ( AI -> getArraySize ( ) ) ; EVT VTs [ ] = { CompVT , <STR_LIT> } ; SDValue Ops [ ] = { SDB -> getRoot ( ) , ArrSz , DAG . getConstant ( <NUM_LIT> , DL , <STR_LIT> ) } ; SDValue DSA = DAG . getNode ( <STR_LIT> , DL , VTs , Ops ) ; Type * AllocatedTy = AI -> getAllocatedType ( ) ; MFI -> addToNodeTypeMap ( DSA . getNode ( ) , AllocatedTy ) ; if ( isa < StructType > ( AllocatedTy ) ) MFI -> addToTypeNameMap ( AllocatedTy ) ;

DAG . setRoot ( DSA . getValue ( <NUM_LIT> ) ) ;


<s> SDValue <ISA_LIT>TargetLowering :: createAllocationMacros ( SelectionDAGBuilder * SDB , const User & I , const SDLoc & DL ) const { SelectionDAG & DAG = SDB -> DAG ; <ISA_LIT>FunctionInfo * MFI = DAG . getMachineFunction ( ) . getInfo < <ISA_LIT>FunctionInfo > ( ) ; EVT CompVT ( <STR_LIT> ) ; const AllocaInst * AI = cast < const AllocaInst > ( & I ) ; SDValue ArrSz = SDB -> getValue ( AI -> getArraySize ( ) ) ; EVT VTs [ ] = { CompVT , <STR_LIT> } ; SDValue Ops [ ] = { SDB -> getRoot ( ) , ArrSz , DAG . getConstant ( <NUM_LIT> , DL , <STR_LIT> ) } ; SDValue DSA = DAG . getNode ( <STR_LIT> , DL , VTs , Ops ) ; Type * AllocatedTy = AI -> getAllocatedType ( ) ;

MFI -> addToNodeTypeMap ( DSA . getNode ( ) , AllocatedTy ) ;


<s> GTI != E ; ++ GTI ) { NumIndices -- ; const Value * Idx = GTI . getOperand ( ) ; Type * IdxTy = GTI . getIndexedType ( ) ; if ( NextIndex == ARRAY_REF || NextIndex == STRUCT_REF ) { unsigned NodeOpcode = NextIndex == STRUCT_REF ? <STR_LIT> : <STR_LIT> ; IsInChain |= <NUM_LIT> << <NUM_LIT> ; IsInChain |= ( <NUM_LIT> == NumIndices ) << <NUM_LIT> ; SDValue InChainUse = DAG . getConstant ( IsInChain , dl , <STR_LIT> ) ; IsInChain &= ~ <NUM_LIT> ; SDValue Ops [ ] = { SDB -> getRoot ( ) , N , SDB -> getValue ( Idx ) , InChainUse } ; if ( isa < CompositeType > ( IdxTy ) ) { EVT VTs [ ] = { <STR_LIT> , <STR_LIT> } ; N = DAG . getNode ( NodeOpcode , dl , VTs , Ops ) ; SDNodeFlags Flags = N . getNode ( ) -> getFlags ( ) ; Flags . setIsComposite ( true ) ; N . getNode ( ) -> setFlags ( Flags ) ; } else { EVT IdxVT = getValueType ( DL , IdxTy ) ;


<s> <ISA_LIT>FunctionInfo * MFI = DAG . getMachineFunction ( ) . getInfo < <ISA_LIT>FunctionInfo > ( ) ; PointerType * MemPtr = cast < PointerType > ( PtrVal -> getType ( ) ) ; assert ( isa < StructType > ( MemPtr -> getElementType ( ) ) || isa < ArrayType > ( MemPtr -> getElementType ( ) ) ) ; int NumIndices = cast < GetElementPtrInst > ( & I ) -> getNumIndices ( ) ; int IsInChain = ! isa < GetElementPtrInst > ( PtrVal ) ; for ( gep_type_iterator GTI = gep_type_begin ( & I ) , E = gep_type_end ( & I ) ; GTI != E ; ++ GTI ) { NumIndices -- ; const Value * Idx = GTI . getOperand ( ) ; Type * IdxTy = GTI . getIndexedType ( ) ; if ( NextIndex == ARRAY_REF || NextIndex == STRUCT_REF ) { unsigned NodeOpcode = NextIndex == STRUCT_REF ? <STR_LIT> : <STR_LIT> ; IsInChain |= <NUM_LIT> << <NUM_LIT> ; IsInChain |= ( <NUM_LIT> == NumIndices ) << <NUM_LIT> ; SDValue InChainUse = DAG . getConstant ( IsInChain , dl , <STR_LIT> ) ; IsInChain &= ~ <NUM_LIT> ; SDValue Ops [ ] = { SDB -> getRoot ( ) , N , SDB -> getValue ( Idx ) , InChainUse } ; if ( isa < CompositeType > ( IdxTy ) ) { EVT VTs [ ] = { <STR_LIT> , <STR_LIT> } ;

N = DAG . getNode ( NodeOpcode , dl , VTs , Ops ) ;


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


<s> bool doNotPerformImplicitStaticAllocation ( ) const override { return true ;


<s> MachineFunction & MF = DAG . getMachineFunction ( ) ; DAG . getContext ( ) -> diagnose ( DiagnosticInfoUnsupported ( MF . getFunction ( ) , msg , DL . getDebugLoc ( ) ) ) ;


<s> DAG . getContext ( ) -> diagnose ( DiagnosticInfoUnsupported ( MF . getFunction ( ) , msg , DL . getDebugLoc ( ) ) ) ;


<s> SDValue Chain = Alloc . getValue ( <NUM_LIT> ) ; EVT DupVTs [ ] = { Alloc . getValueType ( ) , <STR_LIT> } ; SDValue DupOps [ ] = { Chain , Alloc } ; SDValue Dup = DAG . getNode ( <STR_LIT> , dl , DupVTs , DupOps ) ; Chain = Dup . getValue ( <NUM_LIT> ) ;

std :: string MethodDescStr = MFI -> getFromTypeNameMap ( AllocatedTy ) ;


<s> bool generateAllocationMacros ( ) const { return true ;


<s> bool generateCompositeMacros ( ) const override { return true ;


<s> SDValue Chain = Mem . getValue ( <NUM_LIT> ) ; EVT AllocStoreVTs [ ] = { Mem . getValueType ( ) , <STR_LIT> } ; SDValue AllocStoreOps [ ] = { Chain , Mem } ; SDValue AllocStore = DAG . getNode ( <STR_LIT> , dl , AllocStoreVTs , AllocStoreOps ) ; SDNodeFlags Flags = AllocStore . getNode ( ) -> getFlags ( ) ;

Flags . setIsComposite ( isComposite ) ;


<s> assert ( Mem . getNode ( ) -> getValueType ( Mem . getNode ( ) -> getNumValues ( ) - <NUM_LIT> ) == <STR_LIT> ) ; SDValue Chain = Mem . getValue ( <NUM_LIT> ) ; EVT AllocStoreVTs [ ] = { Mem . getValueType ( ) , <STR_LIT> } ; SDValue AllocStoreOps [ ] = { Chain , Mem } ; SDValue AllocStore = DAG . getNode ( <STR_LIT> , dl , AllocStoreVTs , AllocStoreOps ) ; SDNodeFlags Flags = AllocStore . getNode ( ) -> getFlags ( ) ; Flags . setIsComposite ( isComposite ) ; AllocStore . getNode ( ) -> setFlags ( Flags ) ;


<s> unsigned N = Node -> getNumValues ( ) ;

while ( N && Node -> getValueType ( N - <NUM_LIT> ) == <STR_LIT> ) -- N ;


<s> static SDValue GetFieldSpecDescID ( SDLoc & DL , SelectionDAG & DAG , SDValue & Obj , SDValue & Idx ) { <ISA_LIT>FunctionInfo * MFI = DAG . getMachineFunction ( ) . getInfo < <ISA_LIT>FunctionInfo > ( ) ; Type * ObjTy = MFI -> getFromNodeTypeMap ( Obj . getNode ( ) ) ; assert ( ObjTy && <STR_LIT> ) ; assert ( isa < StructType > ( ObjTy ) && <STR_LIT> ) ; assert ( isa < ConstantSDNode > ( Idx . getNode ( ) ) ) ; uint64_t IdxNum = cast < ConstantSDNode > ( Idx . getNode ( ) ) -> getZExtValue ( ) ; Type * FTy = cast < StructType > ( ObjTy ) -> getElementType ( ( unsigned ) IdxNum ) ; char fbuff [ <NUM_LIT> ] = { '\0' } ; sprintf ( fbuff , <STR_LIT> , IdxNum ) ; std :: string FieldSpec = MFI -> getFromTypeNameMap ( ObjTy ) ; FieldSpec += <STR_LIT> ; FieldSpec += fbuff ; FieldSpec += <STR_LIT> ; MFI -> getTypeDescriptor ( FTy , FieldSpec ) ; unsigned DescID = MFI -> addToDescriptorIDMap ( FieldSpec ) ; return DAG . getConstant ( DescID , DL , <STR_LIT> ) ;


<s> <ISA_LIT>FunctionInfo * MFI = DAG . getMachineFunction ( ) . getInfo < <ISA_LIT>FunctionInfo > ( ) ; Type * ObjTy = MFI -> getFromNodeTypeMap ( Obj . getNode ( ) ) ; assert ( ObjTy && <STR_LIT> ) ; assert ( isa < StructType > ( ObjTy ) && <STR_LIT> ) ; assert ( isa < ConstantSDNode > ( Idx . getNode ( ) ) ) ; uint64_t IdxNum = cast < ConstantSDNode > ( Idx . getNode ( ) ) -> getZExtValue ( ) ;

Type * FTy = cast < StructType > ( ObjTy ) -> getElementType ( ( unsigned ) IdxNum ) ;


<s> if ( VT . isInteger ( ) || VT . isFloatingPoint ( ) ) return withChain ? <STR_LIT> : <STR_LIT> ; else llvm_unreachable ( <STR_LIT> ) ; return <STR_LIT> ;


<s> int <ISA_LIT>TargetLowering :: getNodeReplicatorCounter ( unsigned Opcode , SDNode * N ) { assert ( doNotCSE ( Opcode ) && <STR_LIT> ) ; if ( N && RepMap . find ( N ) != RepMap . end ( ) ) return RepMap [ N ] ; return Replicator ++ ;


<s> SDUse & Use = itr . getUse ( ) ; if ( CompRefNode != Use . getUser ( ) && Use . getValueType ( ) != <STR_LIT> ) {


<s> return Opcode == <STR_LIT> || Opcode == <STR_LIT> || Opcode == <STR_LIT> || Opcode == <STR_LIT> || Opcode == <STR_LIT> ;


<s> default : return false ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : return true ; }


<s> switch ( Opcode ) { default : return false ; case <STR_LIT> : { SDValue Ptr = Opr . getOperand ( <NUM_LIT> ) ; return ! Ptr . getNode ( ) -> getFlags ( ) . hasIsAbsorptionCandidate ( ) ;


<s> SDValue Ptr = Opr . getOperand ( <NUM_LIT> ) ; return ! Ptr . getNode ( ) -> getFlags ( ) . hasIsAbsorptionCandidate ( ) ; }


<s> bool isSuitableForJumpTable ( const SwitchInst * SI , uint64_t NumCases , uint64_t Range ) const override {


<s> setSchedulingPreference ( Sched :: RegPressure ) ; addRegisterClass ( <STR_LIT> , & <STR_LIT> ) ; addRegisterClass ( <STR_LIT> , & <STR_LIT> ) ; addRegisterClass ( <STR_LIT> , & <STR_LIT> ) ; addRegisterClass ( <STR_LIT> , & <STR_LIT> ) ; addRegisterClass ( <STR_LIT> , & <STR_LIT> ) ; addRegisterClass ( <STR_LIT> , & <STR_LIT> ) ; computeRegisterProperties ( Subtarget -> getRegisterInfo ( ) ) ; for ( auto T : { <STR_LIT> , <STR_LIT> } ) for ( unsigned Opc = <NUM_LIT> ; Opc < <STR_LIT> ; ++ Opc ) setOperationAction ( Opc , T , Legal ) ; for ( auto T : { <STR_LIT> , <STR_LIT> , <STR_LIT> , <STR_LIT> , <STR_LIT> , <STR_LIT> } ) { setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ; setOperationAction ( <STR_LIT> , T , Custom ) ;


<s> static SDValue LoadOperand ( SelectionDAG & DAG , const SDLoc & DL , EVT VT , SDValue Val ) { SDNodeFlags Flags = Val . getNode ( ) -> getFlags ( ) ; auto CompatibleLoad = [ = ] ( SDValue Opr , EVT VT ) -> bool { if ( IsLoadOperand ( Opr ) && Opr . getValueType ( ) == VT ) return true ; else return false ; } ;

bool CanSkipF = ( ! Flags . hasIsAbsorptionCandidate ( ) && ( CompatibleLoad ( Val , VT ) || IsLoadLike ( Val . getOpcode ( ) ) ) ) ;


<s> assert ( Vals [ <NUM_LIT> ] . getValueType ( ) == <STR_LIT> && VTs [ <NUM_LIT> ] == <STR_LIT> ) ; SDNode * ValNode = Vals [ <NUM_LIT> ] . getNode ( ) ; SDNodeFlags Flags = ValNode -> getFlags ( ) ; auto CompatibleLoad = [ = ] ( SDValue Opr , EVT VT ) -> bool { if ( Opr . getOpcode ( ) == <STR_LIT> && Opr . getValueType ( ) == VT ) return true ;


<s> LoadInp1 = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Opr1 ) ; LoadInp2 = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Opr2 ) ; if ( isa < ConstantSDNode > ( LoadInp1 . getNode ( ) ) ) LoadInp1 = LoadOperand ( DAG , DL , <STR_LIT> , LoadInp1 ) ; if ( isa < ConstantSDNode > ( LoadInp2 . getNode ( ) ) ) LoadInp2 = LoadOperand ( DAG , DL , <STR_LIT> , LoadInp2 ) ;

BinOp = DAG . getNode ( LowerBinOp , DL , <STR_LIT> , { LoadInp1 , LoadInp2 } ) ;


<s> unsigned LowerBinOp = GetLowerBinaryOp ( Op . getOpcode ( ) ) ; if ( VT == <STR_LIT> || VT == <STR_LIT> ) { LoadInp1 = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Opr1 ) ; LoadInp2 = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Opr2 ) ; if ( isa < ConstantSDNode > ( LoadInp1 . getNode ( ) ) ) LoadInp1 = LoadOperand ( DAG , DL , <STR_LIT> , LoadInp1 ) ; if ( isa < ConstantSDNode > ( LoadInp2 . getNode ( ) ) ) LoadInp2 = LoadOperand ( DAG , DL , <STR_LIT> , LoadInp2 ) ; BinOp = DAG . getNode ( LowerBinOp , DL , <STR_LIT> , { LoadInp1 , LoadInp2 } ) ; } else { LoadInp1 = LoadOperand ( DAG , DL , Opr1 . getValueType ( ) , Opr1 ) ; LoadInp2 = LoadOperand ( DAG , DL , Opr2 . getValueType ( ) , Opr2 ) ; BinOp = DAG . getNode ( LowerBinOp , DL , VT , { LoadInp1 , LoadInp2 } ) ; } TransferNodeFlagsWithGlue ( Op , BinOp ) ; if ( VT == <STR_LIT> || VT == <STR_LIT> ) BinOp = DAG . getNode ( <STR_LIT> , DL , VT , BinOp ) ; return BinOp ;


<s> return <STR_LIT> ; case <STR_LIT> : case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : case <STR_LIT> : return <STR_LIT> ; case <STR_LIT> : case <STR_LIT> : return <STR_LIT> ; } } ; SDValue Chain = Op . getOperand ( <NUM_LIT> ) ; SDValue CondNode = Op . getOperand ( <NUM_LIT> ) ; SDValue Opr1 = Op . getOperand ( <NUM_LIT> ) ; SDValue Opr2 = Op . getOperand ( <NUM_LIT> ) ; SDValue BBlock = Op . getOperand ( <NUM_LIT> ) ; EVT VT = Opr1 . getValueType ( ) ; SDValue LoadInp1 = LoadOperand ( DAG , DL , VT , Opr1 ) ; SDValue LoadInp2 = LoadOperand ( DAG , DL , VT , Opr2 ) ; <STR_LIT> CCode = cast < CondCodeSDNode > ( CondNode . getNode ( ) ) -> get ( ) ; if ( VT == <STR_LIT> ) { SDValue Ops [ ] = { LoadInp2 , LoadInp1 } ; SDValue LCmp = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Ops ) ; LoadInp1 = LCmp ; LoadInp2 = LoadOperand ( DAG , DL , <STR_LIT> , DAG . getConstant ( <NUM_LIT> , DL , <STR_LIT> ) ) ; CCode = GetNewCCode ( CCode ) ; } CondNode = DAG . getConstant ( CCode , DL , <STR_LIT> ) ;

SDValue Ops [ ] = { Chain , CondNode , LoadInp1 , LoadInp2 , BBlock } ;


<s> SelectionDAG & DAG = CLI . DAG ; const SDLoc DL = CLI . DL ; SDValue Chain = CLI . Chain ; SDValue Callee = CLI . Callee ; MachineFunction & MF = DAG . getMachineFunction ( ) ; auto Layout = MF . getDataLayout ( ) ; CallingConv :: ID CallConv = CLI . CallConv ; if ( ! CallingConvSupported ( CallConv ) ) fail ( DL , DAG , <STR_LIT> <STR_LIT> ) ; if ( CLI . IsPatchPoint ) fail ( DL , DAG , <STR_LIT> ) ; SmallVectorImpl < <STR_LIT> > & Ins = CLI . Ins ; if ( Ins . size ( ) > <NUM_LIT> ) fail ( DL , DAG , <STR_LIT> ) ; SmallVectorImpl < <STR_LIT> > & Outs = CLI . Outs ; SmallVectorImpl < SDValue > & OutVals = CLI . OutVals ; for ( unsigned i = <NUM_LIT> ; i < Outs . size ( ) ; ++ i ) { const <STR_LIT> & Out = Outs [ i ] ; SDValue & OutVal = OutVals [ i ] ; EVT VT = OutVal . getValueType ( ) ; if ( Out . Flags . isNest ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isInAlloca ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isInConsecutiveRegs ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isInConsecutiveRegsLast ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isByVal ( ) && Out . Flags . getByValSize ( ) != <NUM_LIT> ) Chain = DAG . getNode ( <STR_LIT> , DL , VT , OutVal ) ; } bool IsVarArg = CLI . IsVarArg ; unsigned NumFixedArgs = CLI . NumFixedArgs ; SmallVector < CCValAssign , <NUM_LIT> > ArgLocs ; CCState CCInfo ( CallConv , IsVarArg , MF , ArgLocs , * DAG . getContext ( ) ) ; if ( IsVarArg ) { for ( SDValue Arg : make_range ( OutVals . begin ( ) + NumFixedArgs , OutVals . end ( ) ) ) { EVT VT = Arg . getValueType ( ) ; assert ( VT != <STR_LIT> && <STR_LIT> ) ; Type * Ty = VT . getTypeForEVT ( * DAG . getContext ( ) ) ; unsigned Offset = CCInfo . AllocateStack ( Layout . getTypeAllocSize ( Ty ) , Layout . getABITypeAlignment ( Ty ) ) ; CCInfo . addLoc ( CCValAssign :: getMem ( ArgLocs . size ( ) , VT . getSimpleVT ( ) , Offset , VT . getSimpleVT ( ) , CCValAssign :: Full ) ) ;


<s> SDValue LoadInp = LoadOperand ( DAG , DL , <STR_LIT> , CondNode ) ; SDValue CondCode = DAG . getConstant ( <STR_LIT> , DL , <STR_LIT> ) ; SDValue Ops [ ] = { Chain , CondCode , LoadInp , BBlock } ; SDValue BrConstcc = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Ops ) ; TransferNodeFlagsWithGlue ( CondNode , BrConstcc ) ;


<s> assert ( CondNode . getOpcode ( ) == <STR_LIT> && <STR_LIT> ) ; SDValue LoadInp = LoadOperand ( DAG , DL , <STR_LIT> , CondNode ) ; SDValue CondCode = DAG . getConstant ( <STR_LIT> , DL , <STR_LIT> ) ; SDValue Ops [ ] = { Chain , CondCode , LoadInp , BBlock } ; SDValue BrConstcc = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Ops ) ; TransferNodeFlagsWithGlue ( CondNode , BrConstcc ) ; return BrConstcc ;


<s> if ( isa < ArrayType > ( AllocatedTy ) ) { int IsClassArr = isa < StructType > ( cast < ArrayType > ( AllocatedTy ) -> getElementType ( ) ) ; int ArrSz = cast < ArrayType > ( AllocatedTy ) -> getNumElements ( ) ; SDValue ArrSzVal = DAG . getConstant ( ArrSz , dl , <STR_LIT> ) ; EVT LoadVTs [ ] = { ArrSzVal . getValueType ( ) , <STR_LIT> } ; SDValue LoadOps [ ] = { Chain , ArrSzVal } ; LoadSz = DAG . getNode ( <STR_LIT> , dl , LoadVTs , LoadOps ) ; Chain = LoadSz . getValue ( <NUM_LIT> ) ; SDValue Ops [ ] = { Chain , LoadSz , TypeStrID , DAG . getConstant ( <NUM_LIT> , dl , <STR_LIT> ) , DAG . getConstant ( IsClassArr , dl , <STR_LIT> ) } ; Alloc = DAG . getNode ( <STR_LIT> , dl , VTs , Ops ) ; } else if ( isa < StructType > ( AllocatedTy ) ) {

SDValue Ops [ ] = { Chain , LoadSz , TypeStrID , DAG . getConstant ( <NUM_LIT> , dl , <STR_LIT> ) , DAG . getConstant ( <NUM_LIT> , dl , <STR_LIT> ) } ;


<s> if ( Op . getOpcode ( ) == <STR_LIT> ) return Op0 ;

Op0 = LoadOperand ( DAG , DL , Op0 . getValueType ( ) , Op0 ) ;


<s> <ISA_LIT>FunctionInfo * MFI = MF . getInfo < <ISA_LIT>FunctionInfo > ( ) ; MF . getRegInfo ( ) . addLiveIn ( <STR_LIT> ) ; for ( const <STR_LIT> & In : Ins ) { if ( In . Flags . isInAlloca ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( In . Flags . isNest ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( In . Flags . isInConsecutiveRegs ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( In . Flags . isInConsecutiveRegsLast ( ) ) fail ( DL , DAG , <STR_LIT> ) ; SDValue Arg ; if ( In . Used ) { bool IsCompositeArg = In . Flags . isByVal ( ) ; EVT ArgTy = IsCompositeArg ? <STR_LIT> : In . VT ; Arg = DAG . getNode ( <STR_LIT> , DL , ArgTy , DAG . getTargetConstant ( InVals . size ( ) , DL , <STR_LIT> ) ) ; SDNodeFlags Flags = Arg . getNode ( ) -> getFlags ( ) ; Flags . setIsComposite ( IsCompositeArg ) ; Arg . getNode ( ) -> setFlags ( Flags ) ; } else { Arg = DAG . getUNDEF ( In . VT ) ; } InVals . push_back ( Arg ) ; MFI -> incrimentArgumentCount ( ) ;


<s> static SDValue LowerGlobalAddress ( SDValue Op , SelectionDAG & DAG , EVT PtrVT ) { SDLoc DL ( Op ) ; const GlobalValue * GV = cast < GlobalAddressSDNode > ( Op ) -> getGlobal ( ) ; return DAG . getTargetGlobalAddress ( GV , DL , PtrVT ) ;


const GlobalValue * GV = cast < GlobalAddressSDNode > ( Op ) -> getGlobal ( ) ;


<s> assert ( Op . getOperand ( <NUM_LIT> ) . isUndef ( ) && <STR_LIT> ) ; EVT VTs [ ] = { Op . getValueType ( ) , <STR_LIT> } ; SDValue Ops [ ] = { Op . getOperand ( <NUM_LIT> ) , Ptr } ;

return DAG . getNode ( <STR_LIT> , DL , VTs , Ops ) ;


<s> case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : return LowerBinaryOp ( Op , DAG ) ; case <STR_LIT> : return LowerLOAD ( Op , DAG ) ; case <STR_LIT> : return LowerSTORE ( Op , DAG ) ; case <STR_LIT> : return LowerGlobalAddress ( Op , DAG , PtrVT ) ; case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : case <STR_LIT> : return LowerEXTEND ( Op , DAG ) ; case <STR_LIT> : return LowerTRUNCATE ( Op , DAG ) ;


<s> else Chain = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Chain ) ; for ( const <STR_LIT> & Out : Outs ) { assert ( ! Out . Flags . isByVal ( ) && <STR_LIT> ) ; assert ( ! Out . Flags . isNest ( ) && <STR_LIT> ) ; assert ( Out . IsFixed && <STR_LIT> ) ; if ( Out . Flags . isInAlloca ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isInConsecutiveRegs ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isInConsecutiveRegsLast ( ) ) fail ( DL , DAG , <STR_LIT> ) ;


<s> for ( const <STR_LIT> & Out : Outs ) { assert ( ! Out . Flags . isByVal ( ) && <STR_LIT> ) ; assert ( ! Out . Flags . isNest ( ) && <STR_LIT> ) ; assert ( Out . IsFixed && <STR_LIT> ) ; if ( Out . Flags . isInAlloca ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isInConsecutiveRegs ( ) ) fail ( DL , DAG , <STR_LIT> ) ; if ( Out . Flags . isInConsecutiveRegsLast ( ) ) fail ( DL , DAG , <STR_LIT> ) ;


<s> } assert ( Op . getOperand ( <NUM_LIT> ) . isUndef ( ) && <STR_LIT> ) ; SDValue LoadVal = LoadOperand ( DAG , DL , Val . getValueType ( ) , Val ) ; SDValue Ops [ ] = { Chain , LoadVal , Ptr } ;

return DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Ops ) ;


<s> assert ( AloadNode -> getValueType ( AloadNode -> getNumValues ( ) - <NUM_LIT> ) == <STR_LIT> && <STR_LIT> ) ; EVT VTs [ ] = { Use . getOperand ( <NUM_LIT> ) . getValueType ( ) , <STR_LIT> } ; SDValue StoreSrc [ ] = { Chain , Use . getOperand ( <NUM_LIT> ) } ; SDValue SrcLoad = LoadOperandWCh ( DAG , DL , VTs , StoreSrc ) ; TransferNodeFlags ( Use . getOperand ( <NUM_LIT> ) , SrcLoad ) ; SDValue Opr [ ] = { SrcLoad . getValue ( <NUM_LIT> ) , Aload , SrcLoad , DescID } ; FieldAcc = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Opr ) ; TransferNodeFlags ( Op , FieldAcc ) ; } else { EVT VTs [ ] = { Op . getValueType ( ) , <STR_LIT> } ; SDValue Opr [ ] = { Chain , Aload , DescID } ; FieldAcc = DAG . getNode ( <STR_LIT> , DL , VTs , Opr ) ; Chain = FieldAcc . getValue ( <NUM_LIT> ) ; TransferNodeFlags ( Op , FieldAcc ) ;

if ( Use . getOpcode ( ) == <STR_LIT> ) {


<s> SDValue Use = GetRefUse ( Op ) ; SDValue Aload = Obj ; if ( IS_START_OF_CHAIN ( InChainUseFlag ) ) { EVT VTs [ ] = { <STR_LIT> , <STR_LIT> } ; SDValue Ops [ ] = { Chain , Obj } ; Aload = DAG . getNode ( <STR_LIT> , DL , VTs , Ops ) ; SDNodeFlags Flags = Aload . getNode ( ) -> getFlags ( ) ; Flags . setIsComposite ( true ) ; Aload . getNode ( ) -> setFlags ( Flags ) ; Chain = Aload . getValue ( <NUM_LIT> ) ; } SDValue DescID = GetFieldSpecDescID ( DL , DAG , Obj , Idx ) ; SDNodeFlags Flags = Op . getNode ( ) -> getFlags ( ) ; Idx . getNode ( ) -> setFlags ( Flags ) ; SDValue FieldAcc ; if ( Use . getOpcode ( ) == <STR_LIT> ) { SDNode * AloadNode = Aload . getNode ( ) ; assert ( AloadNode -> getValueType ( AloadNode -> getNumValues ( ) - <NUM_LIT> ) == <STR_LIT> && <STR_LIT> ) ; EVT VTs [ ] = { Use . getOperand ( <NUM_LIT> ) . getValueType ( ) , <STR_LIT> } ; SDValue StoreSrc [ ] = { Chain , Use . getOperand ( <NUM_LIT> ) } ; SDValue SrcLoad = LoadOperandWCh ( DAG , DL , VTs , StoreSrc ) ; TransferNodeFlags ( Use . getOperand ( <NUM_LIT> ) , SrcLoad ) ; SDValue Opr [ ] = { SrcLoad . getValue ( <NUM_LIT> ) , Aload , SrcLoad , DescID } ; FieldAcc = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Opr ) ; TransferNodeFlags ( Op , FieldAcc ) ; } else { EVT VTs [ ] = { Op . getValueType ( ) , <STR_LIT> } ; SDValue Opr [ ] = { Chain , Aload , DescID } ; FieldAcc = DAG . getNode ( <STR_LIT> , DL , VTs , Opr ) ; Chain = FieldAcc . getValue ( <NUM_LIT> ) ; TransferNodeFlags ( Op , FieldAcc ) ; if ( Use . getOpcode ( ) == <STR_LIT> ) { EVT StoreVTs [ ] = { FieldAcc . getValueType ( ) , <STR_LIT> } ; SDValue StoreOps [ ] = { Chain , FieldAcc } ; FieldAcc = DAG . getNode ( <STR_LIT> , DL , StoreVTs , StoreOps ) ; Chain = FieldAcc . getValue ( <NUM_LIT> ) ; SDNodeFlags Flags ; Flags . setIsComposite ( Op . getNode ( ) -> getFlags ( ) . hasIsComposite ( ) ) ; FieldAcc . getNode ( ) -> setFlags ( Flags ) ; } }

if ( Use . getOpcode ( ) == <STR_LIT> || Use . getOpcode ( ) == <STR_LIT> ) ReplaceAllUsesOfValueAndChain ( false , DAG , Use , FieldAcc ) ;


<s> EVT Op0VT = Op0 . getValueType ( ) ; EVT TruncVT = Op . getValueType ( ) ; if ( TruncVT . bitsLT ( <STR_LIT> ) && Op0VT . bitsGT ( <STR_LIT> ) ) { SDValue Load = DAG . getNode ( <STR_LIT> , DL , Op0VT , Op0 ) ; Op0 = DAG . getNode ( <STR_LIT> , DL , <STR_LIT> , Load ) ; Op0VT = Op0 . getValueType ( ) ;


<s> NewChNum = GetChainOperandNumFromValue ( New ) ; if ( OldChNum >= <NUM_LIT> && NewChNum >= <NUM_LIT> ) DAG . ReplaceAllUsesOfValueWith ( Old . getValue ( OldChNum ) , New . getValue ( NewChNum ) ) ; else if ( OldChNum >= <NUM_LIT> ) { assert ( Old . getOperand ( <NUM_LIT> ) . getValueType ( ) . getSimpleVT ( ) == <STR_LIT> ) ;

SDValue OldParentCh = Old . getOperand ( <NUM_LIT> ) ;


<s> static void ReplaceAllUsesOfValueAndChain ( bool RepOnlyChain , SelectionDAG & DAG , SDValue Old , SDValue New ) { int OldChNum , NewChNum ; if ( false == RepOnlyChain ) DAG . ReplaceAllUsesOfValueWith ( Old , New ) ; OldChNum = GetChainOperandNumFromValue ( Old ) ; NewChNum = GetChainOperandNumFromValue ( New ) ; if ( OldChNum >= <NUM_LIT> && NewChNum >= <NUM_LIT> ) DAG . ReplaceAllUsesOfValueWith ( Old . getValue ( OldChNum ) , New . getValue ( NewChNum ) ) ; else if ( OldChNum >= <NUM_LIT> ) { assert ( Old . getOperand ( <NUM_LIT> ) . getValueType ( ) . getSimpleVT ( ) == <STR_LIT> ) ;


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


New . getNode ( ) -> setFlags ( Flags ) ;


<s> SDNodeFlags Flags = Old . getNode ( ) -> getFlags ( ) ;


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


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

return new <ISA_LIT>LoadStoreEliminationOpt ( ) ;


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


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

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


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


<s> unsigned Left = -- OpenChildren [ Parent ] ; if ( Left != <NUM_LIT> ) break ;


<s> <ISA_LIT>LoadStoreEliminationOpt ( ) : MachineFunctionPass ( ID ) {


<s> DenseMap < MachineDomTreeNode * , unsigned > OpenChildren ; <ISA_LIT>FunctionInfo * FuncInfo = MF -> getInfo < <ISA_LIT>FunctionInfo > ( ) ; FuncInfo -> setLocalsLimit ( <NUM_LIT> ) ; 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 ) ;


<s> 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 ( ) ;


<s> if ( ! llvm :: isStoreCandidate ( * MI ) ) continue ; unsigned NumDefs = MI -> getDesc ( ) . getNumDefs ( ) ; if ( <NUM_LIT> != NumDefs ) continue ; MachineOperand & MO = MI -> getOperand ( <NUM_LIT> ) ; if ( ! MO . isReg ( ) || MO . isImplicit ( ) ) continue ; if ( ! MRI -> hasOneUse ( MO . getReg ( ) ) ) continue ; MachineInstr & UseMI = * MRI -> use_instr_begin ( MO . getReg ( ) ) ;

if ( ! <STR_LIT> ( UseMI . getOpcode ( ) ) || & UseMI != MI -> getNextNode ( ) ) continue ;


<s> bool <ISA_LIT>LoadStoreEliminationOpt :: 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 ( ) ) ;


<s> 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> ) ; PerformOptimization ( DT -> getRootNode ( ) ) ; return true ;


<s> void <ISA_LIT>LowerMemoryIntrinsics :: AddToLazyDeletionSet ( User * Elm ) {

if ( DeletionSet . find ( Elm ) == DeletionSet . end ( ) ) DeletionSet . insert ( Elm ) ;


<s> Offset = Offset % ElmSz ; return CheckForPartialElementAccess ( ElemTy , Offset ) ; } else return <NUM_LIT> != ( Offset % ElmSz ) ; } else if ( isa < StructType > ( Ty ) ) { const StructLayout * SL = DL . getStructLayout ( cast < StructType > ( Ty ) ) ; unsigned FldIdx = SL -> getElementContainingOffset ( Offset ) ; Type * FldTy = cast < StructType > ( Ty ) -> getTypeAtIndex ( FldIdx ) ; if ( isa < CompositeType > ( FldTy ) ) { Offset -= SL -> getElementOffset ( FldIdx ) ; return CheckForPartialElementAccess ( FldTy , Offset ) ;

} else return SL -> getElementOffset ( FldIdx ) == Offset ;


<s> Type * ElemTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; unsigned ElmSz = DL . getTypeSizeInBits ( ElemTy ) / <NUM_LIT> ; if ( isa < CompositeType > ( ElemTy ) ) { Offset = Offset % ElmSz ; return CheckForPartialElementAccess ( ElemTy , Offset ) ; } else return <NUM_LIT> != ( Offset % ElmSz ) ; } else if ( isa < StructType > ( Ty ) ) { const StructLayout * SL = DL . getStructLayout ( cast < StructType > ( Ty ) ) ; unsigned FldIdx = SL -> getElementContainingOffset ( Offset ) ; Type * FldTy = cast < StructType > ( Ty ) -> getTypeAtIndex ( FldIdx ) ; if ( isa < CompositeType > ( FldTy ) ) { Offset -= SL -> getElementOffset ( FldIdx ) ; return CheckForPartialElementAccess ( FldTy , Offset ) ; } else return SL -> getElementOffset ( FldIdx ) == Offset ;


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


<s> Mask . setBits ( CurrDstOffset + WindowSz , DstSz ) ; return ConstantInt :: get ( TargetIdxTy , Mask . getZExtValue ( ) ) ;


<s> const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; Value * NextGep = llvm :: GetNextGEP ( DL , IRB , TargetIdxTy , V , Padding ) ; if ( IsSrcGep ) CurrDstOffset += Padding ;


<s> Value * <ISA_LIT>LowerMemoryIntrinsics :: GetNextGep ( IRBuilder < > & IRB , Value * V , bool IsSrcGep ) { unsigned Padding = <NUM_LIT> ; assert ( isa < GetElementPtrInst > ( V ) && <STR_LIT> ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ;

Value * NextGep = llvm :: GetNextGEP ( DL , IRB , TargetIdxTy , V , Padding ) ;


<s> Value * <ISA_LIT>LowerMemoryIntrinsics :: GetNextSrcGep ( IRBuilder < > & IRB ) { const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; unsigned SrcSz = DL . getTypeSizeInBits ( GetRootType ( CurrSrc -> getType ( ) ) ) ; if ( CurrSrcOffset < SrcSz ) return CurrSrc ; CurrSrcOffset = <NUM_LIT> ;

return GetNextGep ( IRB , CurrSrc , false ) ;


<s> Type * <ISA_LIT>LowerMemoryIntrinsics :: GetTypeAtOffset ( Type * Ty , Value * * Offset ) { if ( ! isa < ConstantInt > ( * Offset ) ) return Ty ; Ty = GetRootType ( Ty ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; uint64_t OffsetVal = cast < ConstantInt > ( * Offset ) -> getZExtValue ( ) ; if ( isa < StructType > ( Ty ) ) { const StructLayout * SL = DL . getStructLayout ( cast < StructType > ( Ty ) ) ; unsigned Field = SL -> getElementContainingOffset ( OffsetVal ) ;

uint64_t RemOffset = OffsetVal - SL -> getElementOffset ( Field ) ;


<s> Type * ElmTy = cast < ArrayType > ( Ty ) -> getElementType ( ) ; uint64_t ElmSz = DL . getTypeSizeInBits ( ElmTy ) / <NUM_LIT> ; unsigned Index = OffsetVal / ElmSz ; uint64_t RemOffset = ( OffsetVal > Index * ElmSz ) ? OffsetVal - ElmSz * Index : <NUM_LIT> ; * Offset = ConstantInt :: get ( TargetIdxTy , RemOffset ) ; return GetTypeAtOffset ( ElmTy , Offset ) ; } else { return Ty ;


<s> while ( isa < CastInst > ( V ) ) V = cast < CastInst > ( V ) -> getOperand ( <NUM_LIT> ) ;


<s> V = GetRootObject ( V , & Offset , HasBitCastInChain ) ; if ( ! isa < ConstantInt > ( Offset ) ) return true ; Type * Ty = GetRootType ( V -> getType ( ) ) ; unsigned OffsetVal = cast < ConstantInt > ( Offset ) -> getZExtValue ( ) ; return CheckForPartialElementAccess ( Ty , OffsetVal ) ;


<s> <ISA_LIT>LowerMemoryIntrinsics ( ) : FunctionPass ( ID ) {


<s> Dst = GetRootObject ( Dst , & InitOffsetDst , HasBitCastInChain ) ; Dst = CreateCompositeElemAccessGEP ( DL , IRB , Dst , TargetIdxTy , GetRootType ( Dst -> getType ( ) ) , & InitOffsetDst ) ; Type * PenultimateDstTy = GetPenultimateGepIndexType ( Dst ) ; if ( isa < ArrayType > ( PenultimateDstTy ) && ( isa < ArrayType > ( PenultimateSrcTy ) || isa < MemSetInst > ( Inst ) ) ) OptMemTransferArray ( IRB , Src , InitOffsetSrc , Dst , InitOffsetDst , Length , Inst ) ;

else OptMemTransferSerial ( IRB , Src , InitOffsetSrc , Dst , InitOffsetDst , Length , Inst ) ;


<s> unsigned <ISA_LIT>LowerMemoryIntrinsics :: OptMemTransferScalar ( IRBuilder < > & IRB , Value * Src , Value * Dst , MemIntrinsic * Inst ) { assert ( ! isa < CompositeType > ( Src -> getType ( ) ) && ! isa < CompositeType > ( Dst -> getType ( ) ) ) ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; Type * SrcTy = GetRootType ( Src -> getType ( ) ) ; Type * DstTy = GetRootType ( Dst -> getType ( ) ) ; uint64_t SrcSz = DL . getTypeSizeInBits ( SrcTy ) ; uint64_t DstSz = DL . getTypeSizeInBits ( DstTy ) ; unsigned MemTransferDst = DstSz - CurrDstOffset ; unsigned MemTransferSrc = isa < MemSetInst > ( Inst ) ? MemTransferDst : SrcSz - CurrSrcOffset ; unsigned MemTransferSz = MemTransferDst < MemTransferSrc ? MemTransferDst : MemTransferSrc ; Value * LoadSrc = nullptr ; if ( MemSetInst * MSI = dyn_cast < MemSetInst > ( Inst ) ) { LoadSrc = PrepareValueForMemSet ( IRB , MSI -> getValue ( ) , DstTy ) ;


<s> while ( MemTransferSz > <NUM_LIT> ) { MemTransferSz -= ( int ) OptMemTransferScalar ( IRB , CurrSrc , CurrDst , Inst ) ; if ( MemTransferSz > <NUM_LIT> ) { CurrSrc = GetNextSrcGep ( IRB ) ; CurrDst = GetNextDstGep ( IRB ) ;


<s> for ( unsigned i = <NUM_LIT> ; i < PackCount ; i ++ ) { Value * Shift = ConstantInt :: get ( Ret -> getType ( ) , DL . getTypeSizeInBits ( Val -> getType ( ) ) * i ) ; Value * ShiftVal = IRB . CreateShl ( Ret , Shift ) ; Ret = IRB . CreateOr ( Ret , ShiftVal ) ;


<s> Value * <ISA_LIT>LowerMemoryIntrinsics :: PrepareValueForMemSet ( IRBuilder < > & IRB , Value * Val , Type * ToType ) { SmallVector < Constant * , <NUM_LIT> > Elems ; if ( StructType * STy = dyn_cast < StructType > ( ToType ) ) { for ( unsigned i = <NUM_LIT> ; i < STy -> getNumElements ( ) ; i ++ ) { Type * Ty = STy -> getTypeAtIndex ( i ) ; Elems . push_back ( cast < Constant > ( PrepareValueForMemSet ( IRB , Val , Ty ) ) ) ;


<s> Type * Ty = STy -> getTypeAtIndex ( i ) ; Elems . push_back ( cast < Constant > ( PrepareValueForMemSet ( IRB , Val , Ty ) ) ) ; } return ConstantStruct :: get ( STy , Elems ) ; } else if ( ArrayType * ATy = dyn_cast < ArrayType > ( ToType ) ) {


<s> bool <ISA_LIT>LowerMemoryIntrinsics :: ProcessFunction ( ) { LLVMContext & Cxt = Func -> getContext ( ) ; SmallVector < MemIntrinsic * , <NUM_LIT> > WorkList ; const DataLayout & DL = Func -> getParent ( ) -> getDataLayout ( ) ; TargetIdxTy = GetTargetIndexType ( DL , Cxt ) ;

for ( auto & BB : * Func ) for ( auto & I : BB ) if ( isa < MemIntrinsic > ( & I ) ) {


<s> auto Item = WorkList . back ( ) ; WorkList . pop_back ( ) ; IRBuilder < > IRB ( Item ) ; if ( isa < ConstantInt > ( Item -> getLength ( ) ) ) OptimizeMemCopy ( IRB , Item ) ; else if ( MemCpyInst * Memcpy = dyn_cast < MemCpyInst > ( Item ) ) expandMemCpyAsLoop ( Memcpy , TTI ) ; else if ( MemSetInst * Memset = dyn_cast < MemSetInst > ( Item ) ) expandMemSetAsLoop ( Memset ) ;


<s> while ( ! WorkList . empty ( ) ) { auto Item = WorkList . back ( ) ; WorkList . pop_back ( ) ; IRBuilder < > IRB ( Item ) ; if ( isa < ConstantInt > ( Item -> getLength ( ) ) ) OptimizeMemCopy ( IRB , Item ) ;

else if ( MemCpyInst * Memcpy = dyn_cast < MemCpyInst > ( Item ) ) expandMemCpyAsLoop ( Memcpy , TTI ) ;


<s> } for ( auto * I : Users ) cast < Instruction > ( I ) -> eraseFromParent ( ) ;


<s> Users . insert ( Val ) ; } for ( auto * I : Users ) cast < Instruction > ( I ) -> eraseFromParent ( ) ; DeletionSet . clear ( ) ;


<s> void <ISA_LIT>LowerMemoryIntrinsics :: ResetOffsets ( ) { CurrDstOffset = <NUM_LIT> ; CurrSrcOffset = <NUM_LIT> ;


<s> CurrSrcOffset = <NUM_LIT> ; CurrSrc = nullptr ;


<s> bool runOnFunction ( Function & F ) override { Func = & F ;


<s> assert ( isa < ConstantInt > ( SrcOffset ) && <STR_LIT> ) ; assert ( isa < ConstantInt > ( DstOffset ) && <STR_LIT> ) ; CurrSrc = Src ; CurrSrcOffset = cast < ConstantInt > ( SrcOffset ) -> getZExtValue ( ) ; CurrDst = Dst ;

CurrDstOffset = cast < ConstantInt > ( DstOffset ) -> getZExtValue ( ) ;


<s> Value * NewI = IRB . CreateMemCpy ( MI -> getRawDest ( ) , MI -> getDestAlignment ( ) , MI -> getRawSource ( ) , MI -> getSourceAlignment ( ) , MI -> getLength ( ) ) ; I -> replaceAllUsesWith ( NewI ) ; cast < Instruction > ( I ) -> dropAllReferences ( ) ;

AddToLazyDeletionSet ( cast < User > ( I ) ) ;


<s> Value * NewI = IRB . CreateMemCpy ( MI -> getRawDest ( ) , MI -> getDestAlignment ( ) , MI -> getRawSource ( ) , MI -> getSourceAlignment ( ) , MI -> getLength ( ) ) ; I -> replaceAllUsesWith ( NewI ) ;

cast < Instruction > ( I ) -> dropAllReferences ( ) ;


<s> std :: string * DescStr = new std :: string ( Desc . data ( ) ) ; StringRef D ( DescStr -> c_str ( ) ) ; DescVec . push_back ( D ) ; DescIDMap [ Desc ] = ID ; } return DescIDMap [ Desc ] ;


<s> void <ISA_LIT>FunctionInfo :: addToScratchAllocationSet ( unsigned Reg ) { if ( scratchAllocations . find ( Reg ) == scratchAllocations . end ( ) ) {

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


<s> assert ( isa < StructType > ( Ty ) ) ; if ( STyName . find ( Ty ) == STyName . end ( ) ) { std :: string * Name = GenClassName ( ) ;


<s> void clearScratchAllocationSet ( ) { scratchAllocations . clear ( ) ;


<s> const DataLayout & DL ( F . getParent ( ) -> getDataLayout ( ) ) ; const <ISA_LIT>TargetLowering & TLI = * TM . getSubtarget < <ISA_LIT>Subtarget > ( F ) . getTargetLowering ( ) ; SmallVector < EVT , <NUM_LIT> > VTs ; ComputeValueVTs ( TLI , DL , Ty , VTs ) ; for ( EVT VT : VTs ) {

unsigned NumRegs = TLI . getNumRegisters ( F . getContext ( ) , VT ) ;


<s> void llvm :: ComputeSigVTs ( const Function & F , const TargetMachine & TM , SmallVectorImpl < MVT > & Params , SmallVectorImpl < MVT > & Results ) { ComputeLegalVTs ( F , TM , F . getReturnType ( ) , Results ) ;


<s> std :: string * Name = new std :: string ( <STR_LIT> ) ; sprintf ( buff , <STR_LIT> , ClassNum ++ ) ; * Name += buff ; return Name ;


<s> DescriptorVec * getDescVector ( ) { return & DescVec ;


<s> assert ( DescIDMap . find ( DescVec [ ID ] ) != DescIDMap . end ( ) ) ;


<s> Type * <ISA_LIT>FunctionInfo :: getFromNodeTypeMap ( SDNode * N ) { if ( NodeTypeMap . find ( N ) != NodeTypeMap . end ( ) ) return NodeTypeMap [ N ] ;


<s> Type * <ISA_LIT>FunctionInfo :: getFromNodeTypeMap ( SDNode * N ) { if ( NodeTypeMap . find ( N ) != NodeTypeMap . end ( ) ) return NodeTypeMap [ N ] ; return nullptr ;


<s> assert ( MOOMap . size ( ) && MOOMap . find ( Reg ) != MOOMap . end ( ) && <STR_LIT> ) ; return MOOMap [ Reg ] ;


<s> void <ISA_LIT>FunctionInfo :: getTypeDescriptor ( Type * Ty , std :: string & Desc ) const { <ISA_LIT>FunctionInfo * MFI = const_cast < <ISA_LIT>FunctionInfo * > ( this ) ; const DataLayout & DL = MF . getDataLayout ( ) ; const <ISA_LIT>TargetLowering & TLI = * MF . getTarget ( ) . getSubtarget < <ISA_LIT>Subtarget > ( MF . getFunction ( ) ) . getTargetLowering ( ) ; if ( isa < ArrayType > ( Ty ) ) { Desc += <STR_LIT> ; getTypeDescriptor ( cast < SequentialType > ( Ty ) -> getElementType ( ) , Desc ) ; } else if ( isa < PointerType > ( Ty ) ) {

getTypeDescriptor ( cast < PointerType > ( Ty ) -> getElementType ( ) , Desc ) ;


<s> return MOOMap . size ( ) && MOOMap . find ( Reg ) != MOOMap . end ( ) ;


<s> explicit <ISA_LIT>FunctionInfo ( MachineFunction & MF ) : MF ( MF ) {


<s> void setEmitGlobConsts ( bool Val = true ) { EmitGlobConsts = Val ;


<s> void setLocalsLimit ( unsigned limit ) {


<s> void setStackLimit ( unsigned limit ) {


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


<s> UseDataRegionDirectives = true ; HasSingleParameterDotFile = false ; HasDotTypeDotSizeDirective = false ; if ( Enable<ISA_LIT>Assembler ) { EnableInMemoryAsmEmit = true ; AsmMemoryBuffer = new std :: string ( <STR_LIT> ) ; } AlignmentIsInBytes = false ; COMMDirectiveAlignmentIsInBytes = false ;

LCOMMDirectiveAlignmentType = LCOMM :: Log2Alignment ;


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


<s> case MachineOperand :: MO_Register : { int LocalOffset ; <ISA_LIT>FunctionInfo * MFI = const_cast < <ISA_LIT>FunctionInfo * > ( MI -> getParent ( ) -> getParent ( ) -> getInfo < <ISA_LIT>FunctionInfo > ( ) ) ; if ( MRI -> hasOneDef ( MO . getReg ( ) ) && MRI -> getVRegDef ( MO . getReg ( ) ) -> skipAllocation ( ) ) LocalOffset = - <NUM_LIT> ; else LocalOffset = MFI -> getRegisterOffset ( MO . getReg ( ) ) ; MCOp = MCOperand :: createImm ( LocalOffset ) ; break ; } case MachineOperand :: MO_Immediate : MCOp = MCOperand :: createImm ( MO . getImm ( ) ) ; break ; case MachineOperand :: MO_FPImmediate : { const ConstantFP * Imm = MO . getFPImm ( ) ;

if ( Imm -> getType ( ) -> isFloatTy ( ) ) MCOp = MCOperand :: createFPImm ( Imm -> getValueAPF ( ) . convertToFloat ( ) ) ;


<s> } void Lower ( const MachineInstr * MI , MCInst & OutMI ) const ; const MCSymbolRefExpr * LowerSymbolOperand ( const MachineOperand & MO ) const ;


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


<s> switch ( Opcode ) { default : llvm_unreachable ( <STR_LIT> ) ; case <STR_LIT> : return & <STR_LIT> ; case <STR_LIT> : return & <STR_LIT> ; case <STR_LIT> : return & <STR_LIT> ; case <STR_LIT> : return & <STR_LIT> ; }


<s> else if ( RC == & <STR_LIT> ) return <STR_LIT> ; else if ( RC == & <STR_LIT> ) return <STR_LIT> ; else llvm_unreachable ( <STR_LIT> ) ;


<s> } else if ( RRC == & <STR_LIT> ) { if ( LRC == & <STR_LIT> ) return <STR_LIT> ; else if ( LRC == & <STR_LIT> ) return <STR_LIT> ; else if ( LRC == & <STR_LIT> ) return <STR_LIT> ; } else if ( RRC == & <STR_LIT> ) { if ( LRC == & <STR_LIT> ) return <STR_LIT> ;


<s> if ( RC == & <STR_LIT> ) return <STR_LIT> ; else if ( RC == & <STR_LIT> ) return <STR_LIT> ; else if ( RC == & <STR_LIT> ) return <STR_LIT> ; else if ( RC == & <STR_LIT> ) return <STR_LIT> ; else llvm_unreachable ( <STR_LIT> ) ; return <STR_LIT> ;


<s> return new <ISA_LIT>TargetAsmStreamer ( S , OS ) ;


<s> static MCAsmInfo * createMCAsmInfo ( const MCRegisterInfo & , const Triple & TT ) { return new <ISA_LIT>MCAsmInfo ( TT ) ;


<s> return new <ISA_LIT>MCAsmInfo ( TT ) ;


<s> static MCInstPrinter * createMCInstPrinter ( const Triple & , unsigned SyntaxVariant , const MCAsmInfo & MAI , const MCInstrInfo & MII , const MCRegisterInfo & MRI ) {

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


<s> static MCInstPrinter * createMCInstPrinter ( const Triple & , unsigned SyntaxVariant , const MCAsmInfo & MAI , const MCInstrInfo & MII , const MCRegisterInfo & MRI ) { assert ( SyntaxVariant == <NUM_LIT> && <STR_LIT> ) ;

return new <ISA_LIT>InstPrinter ( MAI , MII , MRI ) ;


<s> MCInstrInfo * X = new MCInstrInfo ( ) ;


<s> static MCRegisterInfo * createMCRegisterInfo ( const Triple & ) { MCRegisterInfo * X = new MCRegisterInfo ( ) ; Init<ISA_LIT>MCRegisterInfo ( X , <NUM_LIT> ) ;


<s> return create<ISA_LIT>MCSubtargetInfoImpl ( TT , CPU , FS ) ;


<s> static MCSubtargetInfo * createMCSubtargetInfo ( const Triple & TT , StringRef CPU , StringRef FS ) {

return create<ISA_LIT>MCSubtargetInfoImpl ( TT , CPU , FS ) ;


<s> TargetRegistry :: RegisterMCInstrInfo ( * T , createMCInstrInfo ) ; TargetRegistry :: RegisterMCRegInfo ( * T , createMCRegisterInfo ) ; TargetRegistry :: RegisterMCInstPrinter ( * T , createMCInstPrinter ) ; TargetRegistry :: RegisterMCAsmBackend ( * T , createAsmBackend ) ; TargetRegistry :: RegisterMCSubtargetInfo ( * T , createMCSubtargetInfo ) ;

TargetRegistry :: RegisterAsmTargetStreamer ( * T , createAsmTargetStreamer ) ;


<s> void MemIntrinsicsHandler :: AddToLazyDeletionSet ( User * Elm ) {

if ( DeletionSet . find ( Elm ) == DeletionSet . end ( ) ) DeletionSet . insert ( Elm ) ;


<s> if ( DeletionSet . find ( Elm ) == DeletionSet . end ( ) ) DeletionSet . insert ( Elm ) ;