<s> LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTargetMC ( ) {


<s> DirectXSubtarget :: DirectXSubtarget ( const Triple & TT , StringRef CPU , StringRef FS , const DirectXTargetMachine & TM ) : DirectXGenSubtargetInfo ( TT , CPU , CPU , FS ) , TL ( TM , * this ) {


<s> const DirectXTargetLowering * getTargetLowering ( ) const override { return & TL ;


<s> LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTargetInfo ( ) { RegisterTarget < Triple :: dxil , false > X ( getTheDirectXTarget ( ) , <STR_LIT> , <STR_LIT> , <STR_LIT> ) ;


<s> PM . add ( create<ISA_LIT>PrepareModulePass ( ) ) ; switch ( FileType ) { case CGFT_AssemblyFile :

PM . add ( createPrintModulePass ( Out , <STR_LIT> , true ) ) ;


<s> RegisterTargetMachine < DirectXTargetMachine > X ( getTheDirectXTarget ( ) ) ;

auto * PR = PassRegistry :: getPassRegistry ( ) ;


<s> RegisterTargetMachine < DirectXTargetMachine > X ( getTheDirectXTarget ( ) ) ; auto * PR = PassRegistry :: getPassRegistry ( ) ;

initialize<ISA_LIT>PrepareModulePass ( * PR ) ;


<s> PM . add ( create<ISA_LIT>OpLoweringLegacyPass ( ) ) ; PM . add ( create<ISA_LIT>PrepareModulePass ( ) ) ; PM . add ( create<ISA_LIT>TranslateMetadataPass ( ) ) ; switch ( FileType ) { case CGFT_AssemblyFile : PM . add ( createPrintModulePass ( Out , <STR_LIT> , true ) ) ; break ; case CGFT_ObjectFile : PM . add ( create<ISA_LIT>WriterPass ( Out ) ) ; break ; case CGFT_Null : break ; } return false ;


<s> case CGFT_AssemblyFile : PM . add ( createPrintModulePass ( Out , <STR_LIT> , true ) ) ; break ; case CGFT_ObjectFile : PM . add ( create<ISA_LIT>WriterPass ( Out ) ) ; break ; case CGFT_Null : break ;


<s> RegisterTargetMachine < DirectXTargetMachine > X ( getTheDirectXTarget ( ) ) ; auto * PR = PassRegistry :: getPassRegistry ( ) ; initialize<ISA_LIT>PrepareModulePass ( * PR ) ; initialize<ISA_LIT>OpLoweringLegacyPass ( * PR ) ;


<s> TargetPassConfig * DirectXTargetMachine :: createPassConfig ( PassManagerBase & PM ) { return new DirectXPassConfig ( * this , PM ) ;


<s> FunctionPass * createTargetRegisterAllocator ( bool ) override {


<s> DirectXPassConfig ( DirectXTargetMachine & TM , PassManagerBase & PM ) : TargetPassConfig ( TM , PM ) {


<s> DirectXTargetLowering :: DirectXTargetLowering ( const DirectXTargetMachine & TM , const DirectXSubtarget & STI ) : TargetLowering ( TM ) {


<s> DirectXTargetMachine :: DirectXTargetMachine ( const Target & T , const Triple & TT , StringRef CPU , StringRef FS , const TargetOptions & Options , Optional < Reloc :: Model > RM , Optional < CodeModel :: Model > CM , CodeGenOpt :: Level OL , bool JIT ) : LLVMTargetMachine ( T , <STR_LIT> <STR_LIT> , TT , CPU , FS , Options , Reloc :: Static , CodeModel :: Small , OL ) , TLOF ( std :: make_unique < <ISA_LIT>TargetObjectFile > ( ) ) , Subtarget ( std :: make_unique < DirectXSubtarget > ( TT , CPU , FS , * this ) ) {


<s> DirectXTargetMachine & getDirectXTargetMachine ( ) const {

return getTM < DirectXTargetMachine > ( ) ;


<s> MCSection * getExplicitSectionGlobal ( const GlobalObject * GO , SectionKind Kind , const TargetMachine & TM ) const override {


<s> MCSection * getExplicitSectionGlobal ( const GlobalObject * GO , SectionKind Kind , const TargetMachine & TM ) const override { llvm_unreachable ( <STR_LIT> ) ;


<s> TargetLoweringObjectFile * getObjFileLowering ( ) const override {


<s> const DirectXSubtarget * DirectXTargetMachine :: getSubtargetImpl ( const Function & ) const { return Subtarget . get ( ) ;


<s> LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget ( ) { RegisterTargetMachine < DirectXTargetMachine > X ( getTheDirectXTarget ( ) ) ;


<s> MCSection * SelectSectionForGlobal ( const GlobalObject * GO , SectionKind Kind , const TargetMachine & TM ) const override {


<s> DirectXTargetMachine :: ~ DirectXTargetMachine ( ) {


<s> explicit DirectXTTIImpl ( const DirectXTargetMachine * TM , const Function & F ) : BaseT ( TM , F . getParent ( ) -> getDataLayout ( ) ) , ST ( TM -> getSubtargetImpl ( F ) ) , TLI ( ST -> getTargetLowering ( ) ) {


<s> const DirectXSubtarget * getST ( ) const {


<s> void assignValueId ( GlobalValue :: GUID ValGUID ) { GUIDToValueIdMap [ ValGUID ] = ++ GlobalValueId ;


<s> void BitcodeWriter :: copyStrtab ( StringRef Strtab ) { writeBlob ( bitc :: STRTAB_BLOCK_ID , bitc :: STRTAB_BLOB , Strtab ) ;


<s> Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Array ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ;

return Stream . EmitAbbrev ( std :: move ( Abbv ) ) ;


<s> Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Array ) ) ;


<s> auto Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: METADATA_STRING_OLD ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Array ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , <NUM_LIT> ) ) ; return Stream . EmitAbbrev ( std :: move ( Abbv ) ) ;


<s> auto Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: METADATA_STRING_OLD ) ) ;

Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Array ) ) ;


<s> <ISA_LIT>BitcodeWriter ( const Module & M , SmallVectorImpl < char > & Buffer , StringTableBuilder & StrtabBuilder , BitstreamWriter & Stream ) : Stream ( Stream ) , StrtabBuilder ( StrtabBuilder ) , M ( M ) , VE ( M , true ) , Buffer ( Buffer ) , BitcodeStartBit ( Stream . GetCurrentBitNo ( ) ) {

GlobalValueId = VE . getValues ( ) . size ( ) ;


<s> void <ISA_LIT>BitcodeWriter :: emitSignedInt64 ( SmallVectorImpl < uint64_t > & Vals , uint64_t V ) { if ( ( int64_t ) V >= <NUM_LIT> ) Vals . push_back ( V << <NUM_LIT> ) ; else Vals . push_back ( ( - V << <NUM_LIT> ) | <NUM_LIT> ) ;


<s> unsigned NumWords = A . getActiveWords ( ) ; const uint64_t * RawData = A . getRawData ( ) ; for ( unsigned i = <NUM_LIT> ; i < NumWords ; i ++ ) emitSignedInt64 ( Vals , RawData [ i ] ) ;


<s> for ( unsigned i = <NUM_LIT> ; i < NumWords ; i ++ ) emitSignedInt64 ( Vals , RawData [ i ] ) ;


<s> unsigned getEncodedAlign ( MaybeAlign Alignment ) {


<s> return bitc :: BINOP_ADD ; case Instruction :: Sub : case Instruction :: FSub : return bitc :: BINOP_SUB ; case Instruction :: Mul : case Instruction :: FMul : return bitc :: BINOP_MUL ; case Instruction :: UDiv : return bitc :: BINOP_UDIV ; case Instruction :: FDiv : case Instruction :: SDiv :


<s> case Instruction :: Mul : case Instruction :: FMul : return bitc :: BINOP_MUL ; case Instruction :: UDiv : return bitc :: BINOP_UDIV ; case Instruction :: FDiv : case Instruction :: SDiv : return bitc :: BINOP_SDIV ; case Instruction :: URem : return bitc :: BINOP_UREM ; case Instruction :: FRem : case Instruction :: SRem : return bitc :: BINOP_SREM ; case Instruction :: Shl : return bitc :: BINOP_SHL ; case Instruction :: LShr : return bitc :: BINOP_LSHR ; case Instruction :: AShr : return bitc :: BINOP_ASHR ; case Instruction :: And : return bitc :: BINOP_AND ; case Instruction :: Or :


<s> switch ( Opcode ) { default : llvm_unreachable ( <STR_LIT> ) ; case Instruction :: Trunc : return bitc :: CAST_TRUNC ; case Instruction :: ZExt : return bitc :: CAST_ZEXT ; case Instruction :: SExt : return bitc :: CAST_SEXT ; case Instruction :: FPToUI :


<s> unsigned <ISA_LIT>BitcodeWriter :: getEncodedCastOpcode ( unsigned Opcode ) { switch ( Opcode ) { default : llvm_unreachable ( <STR_LIT> ) ; case Instruction :: Trunc : return bitc :: CAST_TRUNC ; case Instruction :: ZExt : return bitc :: CAST_ZEXT ; case Instruction :: SExt : return bitc :: CAST_SEXT ; case Instruction :: FPToUI : return bitc :: CAST_FPTOUI ; case Instruction :: FPToSI : return bitc :: CAST_FPTOSI ; case Instruction :: UIToFP : return bitc :: CAST_UITOFP ; case Instruction :: SIToFP : return bitc :: CAST_SITOFP ; case Instruction :: FPTrunc : return bitc :: CAST_FPTRUNC ;


<s> case Comdat :: Largest : return bitc :: COMDAT_SELECTION_KIND_LARGEST ; case Comdat :: NoDeduplicate : return bitc :: COMDAT_SELECTION_KIND_NO_DUPLICATES ;


<s> unsigned <ISA_LIT>BitcodeWriter :: getEncodedDLLStorageClass ( const GlobalValue & GV ) { switch ( GV . getDLLStorageClass ( ) ) {

case GlobalValue :: DefaultStorageClass :


<s> unsigned <ISA_LIT>BitcodeWriter :: getEncodedLinkage ( const GlobalValue & GV ) { return getEncodedLinkage ( GV . getLinkage ( ) ) ;


<s> case AtomicOrdering :: NotAtomic : return bitc :: ORDERING_NOTATOMIC ; case AtomicOrdering :: Unordered : return bitc :: ORDERING_UNORDERED ; case AtomicOrdering :: Monotonic : return bitc :: ORDERING_MONOTONIC ; case AtomicOrdering :: Acquire : return bitc :: ORDERING_ACQUIRE ; case AtomicOrdering :: Release : return bitc :: ORDERING_RELEASE ; case AtomicOrdering :: AcquireRelease : return bitc :: ORDERING_ACQREL ; case AtomicOrdering :: SequentiallyConsistent :


<s> return bitc :: ORDERING_ACQUIRE ; case AtomicOrdering :: Release : return bitc :: ORDERING_RELEASE ; case AtomicOrdering :: AcquireRelease : return bitc :: ORDERING_ACQREL ; case AtomicOrdering :: SequentiallyConsistent : return bitc :: ORDERING_SEQCST ;


<s> return bitc :: RMW_NAND ; case AtomicRMWInst :: Or : return bitc :: RMW_OR ; case AtomicRMWInst :: Xor : return bitc :: RMW_XOR ; case AtomicRMWInst :: Max : return bitc :: RMW_MAX ; case AtomicRMWInst :: Min : return bitc :: RMW_MIN ; case AtomicRMWInst :: UMax : return bitc :: RMW_UMAX ; case AtomicRMWInst :: UMin :


<s> unsigned getEncodedSyncScopeID ( SyncScope :: ID SSID ) {


<s> case GlobalVariable :: LocalDynamicTLSModel : return <NUM_LIT> ; case GlobalVariable :: InitialExecTLSModel : return <NUM_LIT> ; case GlobalVariable :: LocalExecTLSModel : return <NUM_LIT> ;


<s> unsigned <ISA_LIT>BitcodeWriter :: getEncodedUnaryOpcode ( unsigned Opcode ) { switch ( Opcode ) { default : llvm_unreachable ( <STR_LIT> ) ; case Instruction :: FNeg : return bitc :: UNOP_FNEG ; }


<s> return <NUM_LIT> ; case GlobalValue :: HiddenVisibility : return <NUM_LIT> ; case GlobalValue :: ProtectedVisibility : return <NUM_LIT> ;


<s> void <ISA_LIT>BitcodeWriter :: pushValue ( const Value * V , unsigned InstID , SmallVectorImpl < unsigned > & Vals ) { unsigned ValID = VE . getValueID ( V ) ; Vals . push_back ( InstID - ValID ) ;


<s> unsigned ValID = VE . getValueID ( V ) ;


<s> Vals . push_back ( VE . getTypeID ( V -> getType ( ) ) ) ; return true ; }


<s> void <ISA_LIT>BitcodeWriter :: pushValueSigned ( const Value * V , unsigned InstID , SmallVectorImpl < uint64_t > & Vals ) { unsigned ValID = VE . getValueID ( V ) ; int64_t diff = ( ( int32_t ) InstID - ( int32_t ) ValID ) ; emitSignedInt64 ( Vals , diff ) ;


<s> return rotateSign ( Val . get < ConstantInt * > ( ) -> getValue ( ) ) ;


<s> static uint64_t rotateSign ( DISubrange :: BoundType Val ) {

return rotateSign ( Val . get < ConstantInt * > ( ) -> getValue ( ) ) ;


<s> uint64_t Val = getAttrKindEncoding ( Attr . getKindAsEnum ( ) ) ; assert ( Val <= bitc :: ATTR_KIND_ARGMEMONLY && <STR_LIT> ) ; Record . push_back ( <NUM_LIT> ) ; Record . push_back ( Val ) ; Record . push_back ( Attr . getValueAsInt ( ) ) ; } else { StringRef Kind = Attr . getKindAsString ( ) ; StringRef Val = Attr . getValueAsString ( ) ; Record . push_back ( Val . empty ( ) ? <NUM_LIT> : <NUM_LIT> ) ; Record . append ( Kind . begin ( ) , Kind . end ( ) ) ; Record . push_back ( <NUM_LIT> ) ; if ( ! Val . empty ( ) ) { Record . append ( Val . begin ( ) , Val . end ( ) ) ; Record . push_back ( <NUM_LIT> ) ; } } } Stream . EmitRecord ( bitc :: PARAMATTR_GRP_CODE_ENTRY , Record ) ;


<s> Record . push_back ( VE . getAttributeGroupID ( Pair ) ) ; Record . push_back ( AttrListIndex ) ; for ( Attribute Attr : AS ) { if ( Attr . isEnumAttribute ( ) ) { uint64_t Val = getAttrKindEncoding ( Attr . getKindAsEnum ( ) ) ; assert ( Val <= bitc :: ATTR_KIND_ARGMEMONLY && <STR_LIT> ) ; Record . push_back ( <NUM_LIT> ) ; Record . push_back ( Val ) ; } else if ( Attr . isIntAttribute ( ) ) { uint64_t Val = getAttrKindEncoding ( Attr . getKindAsEnum ( ) ) ; assert ( Val <= bitc :: ATTR_KIND_ARGMEMONLY && <STR_LIT> ) ; Record . push_back ( <NUM_LIT> ) ; Record . push_back ( Val ) ; Record . push_back ( Attr . getValueAsInt ( ) ) ; } else { StringRef Kind = Attr . getKindAsString ( ) ; StringRef Val = Attr . getValueAsString ( ) ;

Record . push_back ( Val . empty ( ) ? <NUM_LIT> : <NUM_LIT> ) ;


<s> const std :: vector < AttributeList > & Attrs = VE . getAttributeLists ( ) ; if ( Attrs . empty ( ) ) return ; Stream . EnterSubblock ( bitc :: PARAMATTR_BLOCK_ID , <NUM_LIT> ) ; SmallVector < uint64_t , <NUM_LIT> > Record ; for ( unsigned i = <NUM_LIT> , e = Attrs . size ( ) ; i != e ; ++ i ) { AttributeList AL = Attrs [ i ] ; for ( unsigned i : AL . indexes ( ) ) { AttributeSet AS = AL . getAttributes ( i ) ; if ( AS . hasAttributes ( ) ) Record . push_back ( VE . getAttributeGroupID ( { i , AS } ) ) ; } Stream . EmitRecord ( bitc :: PARAMATTR_CODE_ENTRY , Record ) ;


<s> Abbv -> Add ( BitCodeAbbrevOp ( Record ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Blob ) ) ;

auto AbbrevNo = Stream -> EmitAbbrev ( std :: move ( Abbv ) ) ;


<s> Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , VE . computeBitsRequiredForTypeIndicies ( ) ) ) ; if ( Stream . EmitBlockInfoAbbrev ( bitc :: CONSTANTS_BLOCK_ID , std :: move ( Abbv ) ) != CONSTANTS_SETTYPE_ABBREV ) assert ( false && <STR_LIT> ) ; } { auto Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: CST_CODE_INTEGER ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; if ( Stream . EmitBlockInfoAbbrev ( bitc :: CONSTANTS_BLOCK_ID , std :: move ( Abbv ) ) != CONSTANTS_INTEGER_ABBREV ) assert ( false && <STR_LIT> ) ; } { auto Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: CST_CODE_CE_CAST ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , VE . computeBitsRequiredForTypeIndicies ( ) ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; if ( Stream . EmitBlockInfoAbbrev ( bitc :: CONSTANTS_BLOCK_ID , std :: move ( Abbv ) ) != CONSTANTS_CE_CAST_Abbrev ) assert ( false && <STR_LIT> ) ; } { auto Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: CST_CODE_NULL ) ) ; if ( Stream . EmitBlockInfoAbbrev ( bitc :: CONSTANTS_BLOCK_ID , std :: move ( Abbv ) ) != CONSTANTS_NULL_Abbrev ) assert ( false && <STR_LIT> ) ; } { auto Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: FUNC_CODE_INST_LOAD ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , VE . computeBitsRequiredForTypeIndicies ( ) ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , <NUM_LIT> ) ) ; if ( Stream . EmitBlockInfoAbbrev ( bitc :: FUNCTION_BLOCK_ID , std :: move ( Abbv ) ) != ( unsigned ) FUNCTION_INST_LOAD_ABBREV ) assert ( false && <STR_LIT> ) ; } { auto Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: FUNC_CODE_INST_BINOP ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , <NUM_LIT> ) ) ; if ( Stream . EmitBlockInfoAbbrev ( bitc :: FUNCTION_BLOCK_ID , std :: move ( Abbv ) ) != ( unsigned ) FUNCTION_INST_BINOP_ABBREV ) assert ( false && <STR_LIT> ) ; }


<s> assert ( isUInt < <NUM_LIT> > ( Size ) ) ; Vals . push_back ( Size ) ; for ( char Chr : C -> getName ( ) ) Vals . push_back ( ( unsigned char ) Chr ) ; Stream . EmitRecord ( bitc :: MODULE_CODE_COMDAT , Vals , <NUM_LIT> ) ; Vals . clear ( ) ;


<s> assert ( isUInt < <NUM_LIT> > ( Size ) ) ; Vals . push_back ( Size ) ; for ( char Chr : C -> getName ( ) ) Vals . push_back ( ( unsigned char ) Chr ) ; Stream . EmitRecord ( bitc :: MODULE_CODE_COMDAT , Vals , <NUM_LIT> ) ;


<s> void writeDIArgList ( const DIArgList * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) {


<s> Record . push_back ( N -> getAlignInBits ( ) ) ; Record . push_back ( N -> getEncoding ( ) ) ; Stream . EmitRecord ( bitc :: METADATA_BASIC_TYPE , Record , Abbrev ) ;


<s> void writeDICommonBlock ( const DICommonBlock * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) {


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getRetainedTypes ( ) . get ( ) ) ) ; Record . push_back ( <NUM_LIT> ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getGlobalVariables ( ) . get ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getImportedEntities ( ) . get ( ) ) ) ;

Record . push_back ( N -> getDWOId ( ) ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getRetainedTypes ( ) . get ( ) ) ) ; Record . push_back ( <NUM_LIT> ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getGlobalVariables ( ) . get ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getImportedEntities ( ) . get ( ) ) ) ; Record . push_back ( N -> getDWOId ( ) ) ; Stream . EmitRecord ( bitc :: METADATA_COMPILE_UNIT , Record , Abbrev ) ; Record . clear ( ) ;


<s> Record . push_back ( N -> getFlags ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getElements ( ) . get ( ) ) ) ; Record . push_back ( N -> getRuntimeLang ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getVTableHolder ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getTemplateParams ( ) . get ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawIdentifier ( ) ) ) ; Stream . EmitRecord ( bitc :: METADATA_COMPOSITE_TYPE , Record , Abbrev ) ; Record . clear ( ) ;


<s> Record . push_back ( N -> getLine ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getScope ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getBaseType ( ) ) ) ; Record . push_back ( N -> getSizeInBits ( ) ) ; Record . push_back ( N -> getAlignInBits ( ) ) ; Record . push_back ( N -> getOffsetInBits ( ) ) ; Record . push_back ( N -> getFlags ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getExtraData ( ) ) ) ; Stream . EmitRecord ( bitc :: METADATA_DERIVED_TYPE , Record , Abbrev ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ; Stream . EmitRecord ( bitc :: METADATA_ENUMERATOR , Record , Abbrev ) ; Record . clear ( ) ;


<s> Record . reserve ( N -> getElements ( ) . size ( ) + <NUM_LIT> ) ;

Record . push_back ( N -> isDistinct ( ) ) ;


<s> Record . reserve ( N -> getElements ( ) . size ( ) + <NUM_LIT> ) ; Record . push_back ( N -> isDistinct ( ) ) ; Record . append ( N -> elements_begin ( ) , N -> elements_end ( ) ) ; Stream . EmitRecord ( bitc :: METADATA_EXPRESSION , Record , Abbrev ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getRawDirectory ( ) ) ) ;

Stream . EmitRecord ( bitc :: METADATA_FILE , Record , Abbrev ) ;


<s> void writeDIGenericSubrange ( const DIGenericSubrange * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) { llvm_unreachable ( <STR_LIT> ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeDIGlobalVariable ( const DIGlobalVariable * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) { Record . push_back ( N -> isDistinct ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getScope ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawLinkageName ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getFile ( ) ) ) ; Record . push_back ( N -> getLine ( ) ) ;

Record . push_back ( VE . getMetadataOrNullID ( N -> getType ( ) ) ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawLinkageName ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getFile ( ) ) ) ; Record . push_back ( N -> getLine ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getType ( ) ) ) ; Record . push_back ( N -> isLocalToUnit ( ) ) ; Record . push_back ( N -> isDefinition ( ) ) ; Record . push_back ( <NUM_LIT> ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getStaticDataMemberDeclaration ( ) ) ) ; Stream . EmitRecord ( bitc :: METADATA_GLOBAL_VAR , Record , Abbrev ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getEntity ( ) ) ) ; Record . push_back ( N -> getLine ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ;

Stream . EmitRecord ( bitc :: METADATA_IMPORTED_ENTITY , Record , Abbrev ) ;


<s> void writeDILabel ( const DILabel * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) {


<s> Record . push_back ( N -> isDistinct ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getScope ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getFile ( ) ) ) ;

Record . push_back ( N -> getLine ( ) ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeDILexicalBlockFile ( const DILexicalBlockFile * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) {


<s> void <ISA_LIT>BitcodeWriter :: writeDILexicalBlockFile ( const DILexicalBlockFile * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) { Record . push_back ( N -> isDistinct ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getScope ( ) ) ) ;

Record . push_back ( VE . getMetadataOrNullID ( N -> getFile ( ) ) ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getFile ( ) ) ) ; Record . push_back ( N -> getLine ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getType ( ) ) ) ; Record . push_back ( N -> getArg ( ) ) ; Record . push_back ( N -> getFlags ( ) ) ; Stream . EmitRecord ( bitc :: METADATA_LOCAL_VAR , Record , Abbrev ) ;


<s> Record . push_back ( VE . getMetadataID ( N -> getScope ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getInlinedAt ( ) ) ) ; Stream . EmitRecord ( bitc :: METADATA_LOCATION , Record , Abbrev ) ;


<s> for ( auto & I : N -> operands ( ) ) Record . push_back ( VE . getMetadataOrNullID ( I ) ) ;

Stream . EmitRecord ( bitc :: METADATA_MODULE , Record , Abbrev ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getScope ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getFile ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ; Record . push_back ( <NUM_LIT> ) ; Stream . EmitRecord ( bitc :: METADATA_NAMESPACE , Record , Abbrev ) ;


<s> void writeDIStringType ( const DIStringType * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) { llvm_unreachable ( <STR_LIT> ) ;


<s> Record . push_back ( N -> getScopeLine ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getContainingType ( ) ) ) ; Record . push_back ( N -> getVirtuality ( ) ) ; Record . push_back ( N -> getVirtualIndex ( ) ) ; Record . push_back ( N -> getFlags ( ) ) ; Record . push_back ( N -> isOptimized ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawUnit ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getTemplateParams ( ) . get ( ) ) ) ;

Record . push_back ( VE . getMetadataOrNullID ( N -> getDeclaration ( ) ) ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeDISubrange ( const DISubrange * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) {


<s> Record . push_back ( rotateSign ( N -> getLowerBound ( ) ) ) ; Stream . EmitRecord ( bitc :: METADATA_SUBRANGE , Record , Abbrev ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeDISubroutineType ( const DISubroutineType * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) {


<s> void <ISA_LIT>BitcodeWriter :: writeDITemplateTypeParameter ( const DITemplateTypeParameter * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) { Record . push_back ( N -> isDistinct ( ) ) ;

Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeDITemplateTypeParameter ( const DITemplateTypeParameter * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) { Record . push_back ( N -> isDistinct ( ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ;


<s> Record . push_back ( VE . getMetadataOrNullID ( N -> getRawName ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getType ( ) ) ) ; Record . push_back ( VE . getMetadataOrNullID ( N -> getValue ( ) ) ) ; Stream . EmitRecord ( bitc :: METADATA_TEMPLATE_VALUE , Record , Abbrev ) ; Record . clear ( ) ;


<s> SmallVector < char , <NUM_LIT> > Buffer ; Buffer . reserve ( <NUM_LIT> * <NUM_LIT> ) ; Triple TT ( M . getTargetTriple ( ) ) ; if ( TT . isOSDarwin ( ) || TT . isOSBinFormatMachO ( ) ) Buffer . insert ( Buffer . begin ( ) , BWH_HeaderSize , <NUM_LIT> ) ; BitcodeWriter Writer ( Buffer , dyn_cast < raw_fd_stream > ( & Out ) ) ; Writer . writeModule ( M ) ; Writer . writeSymtab ( ) ; Writer . writeStrtab ( ) ; if ( ! Buffer . empty ( ) ) Out . write ( ( char * ) & Buffer . front ( ) , Buffer . size ( ) ) ;


<s> writeFunctionMetadata ( F ) ; unsigned InstID = CstEnd ; bool NeedsMetadataAttachment = F . hasMetadata ( ) ; DILocation * LastDL = nullptr ; for ( Function :: const_iterator BB = F . begin ( ) , E = F . end ( ) ; BB != E ; ++ BB ) for ( BasicBlock :: const_iterator I = BB -> begin ( ) , E = BB -> end ( ) ; I != E ; ++ I ) { writeInstruction ( * I , InstID , Vals ) ; if ( ! I -> getType ( ) -> isVoidTy ( ) ) ++ InstID ; NeedsMetadataAttachment |= I -> hasMetadataOtherThanDebugLoc ( ) ; DILocation * DL = I -> getDebugLoc ( ) ; if ( ! DL ) continue ; if ( DL == LastDL ) { Stream . EmitRecord ( bitc :: FUNC_CODE_DEBUG_LOC_AGAIN , Vals ) ; continue ; } Vals . push_back ( DL -> getLine ( ) ) ; Vals . push_back ( DL -> getColumn ( ) ) ; Vals . push_back ( VE . getMetadataOrNullID ( DL -> getScope ( ) ) ) ; Vals . push_back ( VE . getMetadataOrNullID ( DL -> getInlinedAt ( ) ) ) ; Stream . EmitRecord ( bitc :: FUNC_CODE_DEBUG_LOC , Vals ) ; Vals . clear ( ) ; LastDL = DL ; } if ( auto * Symtab = F . getValueSymbolTable ( ) ) writeFunctionLevelValueSymbolTable ( * Symtab ) ; if ( NeedsMetadataAttachment ) writeFunctionMetadataAttachment ( F ) ; if ( VE . shouldPreserveUseListOrder ( ) ) writeUseListBlock ( & F ) ;


<s> if ( isChar6 ) isChar6 = BitCodeAbbrevOp :: isChar6 ( * C ) ; if ( ( unsigned char ) * C & <NUM_LIT> ) { is7Bit = false ; break ; } } unsigned AbbrevToUse = VST_ENTRY_8_ABBREV ; unsigned Code ; if ( isa < BasicBlock > ( SI -> getValue ( ) ) ) { Code = bitc :: VST_CODE_BBENTRY ; if ( isChar6 ) AbbrevToUse = VST_BBENTRY_6_ABBREV ; } else { Code = bitc :: VST_CODE_ENTRY ; if ( isChar6 ) AbbrevToUse = VST_ENTRY_6_ABBREV ; else if ( is7Bit ) AbbrevToUse = VST_ENTRY_7_ABBREV ; } NameVals . push_back ( VE . getValueID ( SI -> getValue ( ) ) ) ;

for ( const char * P = Name . getKeyData ( ) , * E = Name . getKeyData ( ) + Name . getKeyLength ( ) ;


<s> Stream . EnterSubblock ( bitc :: METADATA_BLOCK_ID , <NUM_LIT> ) ; SmallVector < uint64_t , <NUM_LIT> > Record ; writeMetadataStrings ( VE . getMDStrings ( ) , Record ) ; writeMetadataRecords ( VE . getNonMDStrings ( ) , Record ) ; Stream . ExitBlock ( ) ;


<s> writeMetadataStrings ( VE . getMDStrings ( ) , Record ) ;

writeMetadataRecords ( VE . getNonMDStrings ( ) , Record ) ;


<s> } for ( const BasicBlock & BB : F ) for ( const Instruction & I : BB ) { MDs . clear ( ) ; I . getAllMetadataOtherThanDebugLoc ( MDs ) ; if ( MDs . empty ( ) ) continue ; Record . push_back ( VE . getInstructionID ( & I ) ) ; for ( unsigned i = <NUM_LIT> , e = MDs . size ( ) ; i != e ; ++ i ) { Record . push_back ( MDs [ i ] . first ) ; Record . push_back ( VE . getMetadataID ( MDs [ i ] . second ) ) ; } Stream . EmitRecord ( bitc :: METADATA_ATTACHMENT , Record , <NUM_LIT> ) ; Record . clear ( ) ;


<s> void writeGenericDINode ( const GenericDINode * N , SmallVectorImpl < uint64_t > & Record , unsigned & Abbrev ) {


<s> void <ISA_LIT>BitcodeWriter :: writeMDTuple ( const MDTuple * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) { for ( unsigned i = <NUM_LIT> , e = N -> getNumOperands ( ) ; i != e ; ++ i ) { Metadata * MD = N -> getOperand ( i ) ; assert ( ! ( MD && isa < LocalAsMetadata > ( MD ) ) && <STR_LIT> ) ; Record . push_back ( VE . getMetadataOrNullID ( MD ) ) ; } Stream . EmitRecord ( N -> isDistinct ( ) ? bitc :: METADATA_DISTINCT_NODE : bitc :: METADATA_NODE , Record , Abbrev ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeMDTuple ( const MDTuple * N , SmallVectorImpl < uint64_t > & Record , unsigned Abbrev ) {

for ( unsigned i = <NUM_LIT> , e = N -> getNumOperands ( ) ; i != e ; ++ i ) {


<s> if ( MDs . empty ( ) ) return ; for ( const Metadata * MD : MDs ) { if ( IndexPos ) IndexPos -> push_back ( Stream . GetCurrentBitNo ( ) ) ; if ( const MDNode * N = dyn_cast < MDNode > ( MD ) ) { assert ( N -> isResolved ( ) && <STR_LIT> ) ; switch ( N -> getMetadataID ( ) ) { default : llvm_unreachable ( <STR_LIT> ) ; case Metadata :: CLASS ## Kind : \ if ( MDAbbrevs ) \ write ## CLASS ( cast < CLASS > ( N ) , Record , \ ( * MDAbbrevs ) [ MetadataAbbrev :: CLASS ## AbbrevID ] ) ; \ else \ write ## CLASS ( cast < CLASS > ( N ) , Record , CLASS ## Abbrev ) ; \ continue ; } } writeValueAsMetadata ( cast < ValueAsMetadata > ( MD ) , Record ) ; }


<s> if ( const MDNode * N = dyn_cast < MDNode > ( MD ) ) { assert ( N -> isResolved ( ) && <STR_LIT> ) ; switch ( N -> getMetadataID ( ) ) { default : llvm_unreachable ( <STR_LIT> ) ; case Metadata :: CLASS ## Kind : \ if ( MDAbbrevs ) \ write ## CLASS ( cast < CLASS > ( N ) , Record , \ ( * MDAbbrevs ) [ MetadataAbbrev :: CLASS ## AbbrevID ] ) ; \ else \ write ## CLASS ( cast < CLASS > ( N ) , Record , CLASS ## Abbrev ) ; \ continue ; }


<s> void <ISA_LIT>BitcodeWriter :: writeMetadataStrings ( ArrayRef < const Metadata * > Strings , SmallVectorImpl < uint64_t > & Record ) { for ( const Metadata * MD : Strings ) { const MDString * MDS = cast < MDString > ( MD ) ; Record . append ( MDS -> bytes_begin ( ) , MDS -> bytes_end ( ) ) ; Stream . EmitRecord ( bitc :: METADATA_STRING_OLD , Record , createMetadataStringsAbbrev ( ) ) ; Record . clear ( ) ;


<s> <ISA_LIT>BitcodeWriter ModuleWriter ( M , Buffer , StrtabBuilder , * Stream ) ;


<s> <ISA_LIT>BitcodeWriter ModuleWriter ( M , Buffer , StrtabBuilder , * Stream ) ; ModuleWriter . write ( ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeModuleConstants ( ) { const ValueEnumerator :: ValueList & Vals = VE . getValues ( ) ; for ( unsigned i = <NUM_LIT> , e = Vals . size ( ) ; i != e ; ++ i ) { if ( ! isa < GlobalValue > ( Vals [ i ] . first ) ) { writeConstants ( i , Vals . size ( ) , true ) ; return ; }


<s> std :: vector < uint64_t > IndexPos ; IndexPos . reserve ( VE . getNonMDStrings ( ) . size ( ) ) ; writeMetadataRecords ( VE . getNonMDStrings ( ) , Record , & MDAbbrevs , & IndexPos ) ; for ( const NamedMDNode & NMD : M . named_metadata ( ) ) { StringRef Str = NMD . getName ( ) ; Record . append ( Str . bytes_begin ( ) , Str . bytes_end ( ) ) ; Stream . EmitRecord ( bitc :: METADATA_NAME , Record , NameAbbrev ) ;


<s> SmallVector < uint64_t , <NUM_LIT> > Record ; SmallVector < StringRef , <NUM_LIT> > Names ; M . getMDKindNames ( Names ) ; if ( Names . empty ( ) ) return ; Stream . EnterSubblock ( bitc :: METADATA_BLOCK_ID , <NUM_LIT> ) ; for ( unsigned MDKindID = <NUM_LIT> , e = Names . size ( ) ; MDKindID != e ; ++ MDKindID ) { Record . push_back ( MDKindID ) ; StringRef KName = Names [ MDKindID ] ; Record . append ( KName . begin ( ) , KName . end ( ) ) ; Stream . EmitRecord ( bitc :: METADATA_KIND , Record , <NUM_LIT> ) ; Record . clear ( ) ;


<s> SmallVector < uint64_t , <NUM_LIT> > Record ; SmallVector < StringRef , <NUM_LIT> > Names ; M . getMDKindNames ( Names ) ; if ( Names . empty ( ) ) return ; Stream . EnterSubblock ( bitc :: METADATA_BLOCK_ID , <NUM_LIT> ) ; for ( unsigned MDKindID = <NUM_LIT> , e = Names . size ( ) ; MDKindID != e ; ++ MDKindID ) { Record . push_back ( MDKindID ) ; StringRef KName = Names [ MDKindID ] ;

Record . append ( KName . begin ( ) , KName . end ( ) ) ;


<s> Stream . EmitRecord ( bitc :: MODULE_CODE_VERSION , ArrayRef < unsigned > { <NUM_LIT> } ) ;


<s> for ( char C : Str ) { if ( AbbrevToUse && ! BitCodeAbbrevOp :: isChar6 ( C ) ) AbbrevToUse = <NUM_LIT> ; Vals . push_back ( C ) ; } Stream . EmitRecord ( Code , Vals , AbbrevToUse ) ;


<s> assert ( ! WroteStrtab ) ; std :: vector < char > Strtab ; StrtabBuilder . finalizeInOrder ( ) ;

Strtab . resize ( StrtabBuilder . getSize ( ) ) ;


<s> SmallVector < char , <NUM_LIT> > Symtab ; if ( Error E = irsymtab :: build ( Mods , Symtab , StrtabBuilder , Alloc ) ) { consumeError ( std :: move ( E ) ) ; return ;


<s> Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: TYPE_CODE_STRUCT_ANON ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Array ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , NumBits ) ) ; unsigned StructAnonAbbrev = Stream . EmitAbbrev ( std :: move ( Abbv ) ) ; Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: TYPE_CODE_STRUCT_NAME ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Array ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Char6 ) ) ; unsigned StructNameAbbrev = Stream . EmitAbbrev ( std :: move ( Abbv ) ) ; Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: TYPE_CODE_STRUCT_NAMED ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Array ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , NumBits ) ) ; unsigned StructNamedAbbrev = Stream . EmitAbbrev ( std :: move ( Abbv ) ) ; Abbv = std :: make_shared < BitCodeAbbrev > ( ) ; Abbv -> Add ( BitCodeAbbrevOp ( bitc :: TYPE_CODE_ARRAY ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: VBR , <NUM_LIT> ) ) ; Abbv -> Add ( BitCodeAbbrevOp ( BitCodeAbbrevOp :: Fixed , NumBits ) ) ; unsigned ArrayAbbrev = Stream . EmitAbbrev ( std :: move ( Abbv ) ) ; TypeVals . push_back ( TypeList . size ( ) ) ; Stream . EmitRecord ( bitc :: TYPE_CODE_NUMENTRY , TypeVals ) ; TypeVals . clear ( ) ; for ( Type * T : TypeList ) { int AbbrevToUse = <NUM_LIT> ; unsigned Code = <NUM_LIT> ; switch ( T -> getTypeID ( ) ) { case Type :: BFloatTyID : case Type :: X86_AMXTyID : case Type :: TokenTyID : case Type :: <ISA_LIT>PointerTyID : llvm_unreachable ( <STR_LIT> ) ; break ; case Type :: VoidTyID : Code = bitc :: TYPE_CODE_VOID ; break ; case Type :: HalfTyID : Code = bitc :: TYPE_CODE_HALF ;


<s> assert ( Order . Shuffle . size ( ) >= <NUM_LIT> && <STR_LIT> ) ; unsigned Code ; if ( isa < BasicBlock > ( Order . V ) ) Code = bitc :: USELIST_CODE_BB ; else Code = bitc :: USELIST_CODE_DEFAULT ; SmallVector < uint64_t , <NUM_LIT> > Record ( Order . Shuffle . begin ( ) , Order . Shuffle . end ( ) ) ; Record . push_back ( VE . getValueID ( Order . V ) ) ;


<s> if ( isa < BasicBlock > ( Order . V ) ) Code = bitc :: USELIST_CODE_BB ; else Code = bitc :: USELIST_CODE_DEFAULT ; SmallVector < uint64_t , <NUM_LIT> > Record ( Order . Shuffle . begin ( ) , Order . Shuffle . end ( ) ) ;

Record . push_back ( VE . getValueID ( Order . V ) ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeUseListBlock ( const Function * F ) { assert ( VE . shouldPreserveUseListOrder ( ) && <STR_LIT> ) ; auto hasMore = [ & ] ( ) { return ! VE . UseListOrders . empty ( ) && VE . UseListOrders . back ( ) . F == F ; } ; if ( ! hasMore ( ) ) return ; Stream . EnterSubblock ( bitc :: USELIST_BLOCK_ID , <NUM_LIT> ) ; while ( hasMore ( ) ) { writeUseList ( std :: move ( VE . UseListOrders . back ( ) ) ) ; VE . UseListOrders . pop_back ( ) ; }


<s> Record . push_back ( VE . getValueID ( V ) ) ; Stream . EmitRecord ( bitc :: METADATA_VALUE , Record , <NUM_LIT> ) ; Record . clear ( ) ;


<s> void <ISA_LIT>BitcodeWriter :: writeValueSymbolTableForwardDecl ( ) {


<s> static std :: string constructOverloadName ( OverloadKind Kind , Type * Ty , const OpCodeProperty & Prop ) { if ( Kind == OverloadKind :: VOID ) {

return ( Twine ( <ISA_LIT>OpNamePrefix ) + getOpCodeClassName ( Prop ) ) . str ( ) ;


<s> const OpCodeProperty * Prop = getOpCodeProperty ( <ISA_LIT>Op ) ; Type * OverloadTy = F . getReturnType ( ) ; OverloadKind Kind = getOverloadKind ( OverloadTy ) ; if ( ( Prop -> OverloadTys & ( uint16_t ) Kind ) == <NUM_LIT> ) { llvm_unreachable ( <STR_LIT> ) ; } std :: string FnName = constructOverloadName ( Kind , OverloadTy , * Prop ) ;

assert ( ! M . getFunction ( FnName ) && <STR_LIT> ) ;


<s> if ( ( Prop -> OverloadTys & ( uint16_t ) Kind ) == <NUM_LIT> ) { llvm_unreachable ( <STR_LIT> ) ; } std :: string FnName = constructOverloadName ( Kind , OverloadTy , * Prop ) ; assert ( ! M . getFunction ( FnName ) && <STR_LIT> ) ; auto & Ctx = M . getContext ( ) ; Type * OpCodeTy = Type :: getInt32Ty ( Ctx ) ;


<s> <ISA_LIT>OpLoweringLegacy ( ) : ModulePass ( ID ) {


<s> return OverloadKind :: FLOAT ; case Type :: DoubleTyID : return OverloadKind :: DOUBLE ; case Type :: IntegerTyID : { IntegerType * ITy = cast < IntegerType > ( Ty ) ; unsigned Bits = ITy -> getBitWidth ( ) ; switch ( Bits ) { case <NUM_LIT> : return OverloadKind :: I1 ; case <NUM_LIT> : return OverloadKind :: I8 ; case <NUM_LIT> : return OverloadKind :: I16 ; case <NUM_LIT> : return OverloadKind :: I32 ; case <NUM_LIT> : return OverloadKind :: I64 ; default : llvm_unreachable ( <STR_LIT> ) ; return OverloadKind :: VOID ; } } case Type :: PointerTyID :


<s> switch ( T ) { case Type :: VoidTyID : return OverloadKind :: VOID ; case Type :: HalfTyID : return OverloadKind :: HALF ; case Type :: FloatTyID : return OverloadKind :: FLOAT ; case Type :: DoubleTyID : return OverloadKind :: DOUBLE ; case Type :: IntegerTyID : { IntegerType * ITy = cast < IntegerType > ( Ty ) ; unsigned Bits = ITy -> getBitWidth ( ) ; switch ( Bits ) { case <NUM_LIT> : return OverloadKind :: I1 ; case <NUM_LIT> :


<s> static const char * getOverloadTypeName ( OverloadKind Kind ) { switch ( Kind ) { case OverloadKind :: HALF : return <STR_LIT> ; case OverloadKind :: FLOAT :


<s> static std :: string getTypeName ( OverloadKind Kind , Type * Ty ) { if ( Kind < OverloadKind :: UserDefineType ) { return getOverloadTypeName ( Kind ) ; } else if ( Kind == OverloadKind :: UserDefineType ) { StructType * ST = cast < StructType > ( Ty ) ; return ST -> getStructName ( ) . str ( ) ; } else if ( Kind == OverloadKind :: ObjectType ) { StructType * ST = cast < StructType > ( Ty ) ; return ST -> getStructName ( ) . str ( ) ; } else { std :: string Str ; raw_string_ostream OS ( Str ) ; Ty -> print ( OS ) ; return OS . str ( ) ;


<s> auto <ISA_LIT>OpFn = create<ISA_LIT>OpFunction ( <ISA_LIT>Op , F , M ) ; IRBuilder < > B ( M . getContext ( ) ) ; Value * <ISA_LIT>OpArg = B . getInt32 ( static_cast < unsigned > ( <ISA_LIT>Op ) ) ; for ( User * U : make_early_inc_range ( F . users ( ) ) ) { CallInst * CI = dyn_cast < CallInst > ( U ) ; if ( ! CI ) continue ; SmallVector < Value * > Args ; Args . emplace_back ( <ISA_LIT>OpArg ) ; Args . append ( CI -> arg_begin ( ) , CI -> arg_end ( ) ) ; B . SetInsertPoint ( CI ) ; CallInst * <ISA_LIT>CI = B . CreateCall ( <ISA_LIT>OpFn , Args ) ; CI -> replaceAllUsesWith ( <ISA_LIT>CI ) ;


<s> static void lowerIntrinsic ( <STR_LIT> <ISA_LIT>Op , Function & F , Module & M ) { auto <ISA_LIT>OpFn = create<ISA_LIT>OpFunction ( <ISA_LIT>Op , F , M ) ; IRBuilder < > B ( M . getContext ( ) ) ; Value * <ISA_LIT>OpArg = B . getInt32 ( static_cast < unsigned > ( <ISA_LIT>Op ) ) ;

for ( User * U : make_early_inc_range ( F . users ( ) ) ) {


<s> static SmallDenseMap < <STR_LIT> , <STR_LIT> > LowerMap = { { <STR_LIT> , <STR_LIT> :: Sin } } ; for ( Function & F : make_early_inc_range ( M . functions ( ) ) ) { if ( ! F . isDeclaration ( ) ) continue ; <STR_LIT> ID = F . getIntrinsicID ( ) ; auto LowerIt = LowerMap . find ( ID ) ; if ( LowerIt == LowerMap . end ( ) ) continue ; lowerIntrinsic ( LowerIt -> second , F , M ) ;


<s> auto LowerIt = LowerMap . find ( ID ) ; if ( LowerIt == LowerMap . end ( ) ) continue ; lowerIntrinsic ( LowerIt -> second , F , M ) ; Updated = true ; } return Updated ;


<s> if ( lowerIntrinsics ( M ) ) return PreservedAnalyses :: none ( ) ; return PreservedAnalyses :: all ( ) ;


<s> bool runOnModule ( Module & M ) override {


<s> TypedPointerType * TypedPointerType :: get ( Type * EltTy , unsigned AddressSpace ) { assert ( EltTy && <STR_LIT> ) ; assert ( isValidElementType ( EltTy ) && <STR_LIT> ) ; llvm :: Any & TargetData = EltTy -> getContext ( ) . getTargetData ( ) ; if ( ! TargetData . hasValue ( ) ) TargetData = Any { std :: make_shared < TypedPointerTracking > ( ) } ; assert ( any_isa < std :: shared_ptr < TypedPointerTracking >> ( TargetData ) && <STR_LIT> ) ; std :: shared_ptr < TypedPointerTracking > Tracking = any_cast < std :: shared_ptr < TypedPointerTracking >> ( TargetData ) ; std :: unique_ptr < TypedPointerType > & Entry = AddressSpace == <NUM_LIT> ? Tracking -> PointerTypes [ EltTy ] : Tracking -> ASPointerTypes [ std :: make_pair ( EltTy , AddressSpace ) ] ; if ( ! Entry ) Entry = std :: unique_ptr < TypedPointerType > ( new TypedPointerType ( EltTy , AddressSpace ) ) ; return Entry . get ( ) ;


<s> TypedPointerType * TypedPointerType :: get ( Type * EltTy , unsigned AddressSpace ) { assert ( EltTy && <STR_LIT> ) ; assert ( isValidElementType ( EltTy ) && <STR_LIT> ) ; llvm :: Any & TargetData = EltTy -> getContext ( ) . getTargetData ( ) ;

if ( ! TargetData . hasValue ( ) ) TargetData = Any { std :: make_shared < TypedPointerTracking > ( ) } ;


<s> unsigned getAddressSpace ( ) const {


<s> Type * getElementType ( ) const { return PointeeTy ;


<s> return ! ElemTy -> isVoidTy ( ) && ! ElemTy -> isLabelTy ( ) && ! ElemTy -> isMetadataTy ( ) && ! ElemTy -> isTokenTy ( ) && ! ElemTy -> isX86_AMXTy ( ) ;


<s> ContainedTys = & PointeeTy ; NumContainedTys = <NUM_LIT> ; setSubclassData ( AddrSpace ) ;


<s> static Value * maybeGenerateBitcast ( IRBuilder < > & Builder , PointerTypeMap & PointerTypes , Instruction & Inst , Value * Operand , Type * Ty ) { auto It = PointerTypes . find ( Operand ) ; if ( It != PointerTypes . end ( ) ) if ( cast < TypedPointerType > ( It -> second ) -> getElementType ( ) == Ty ) return nullptr ; Builder . SetInsertPoint ( & Inst ) ;

return Builder . Insert ( CastInst :: Create ( Instruction :: BitCast , Operand , Builder . getInt8PtrTy ( ) ) ) ;


<s> auto It = PointerTypes . find ( Operand ) ; if ( It != PointerTypes . end ( ) ) if ( cast < TypedPointerType > ( It -> second ) -> getElementType ( ) == Ty ) return nullptr ;


<s> IRBuilder < > Builder ( & BB ) ; for ( auto & I : make_early_inc_range ( BB ) ) { if ( I . getOpcode ( ) == Instruction :: FNeg ) { Builder . SetInsertPoint ( & I ) ; Value * In = I . getOperand ( <NUM_LIT> ) ; Value * Zero = ConstantFP :: get ( In -> getType ( ) , - <NUM_LIT> ) ; I . replaceAllUsesWith ( Builder . CreateFSub ( Zero , In ) ) ; I . eraseFromParent ( ) ; continue ; } if ( ! M . getContext ( ) . hasSetOpaquePointersValue ( ) ) continue ; if ( auto LI = dyn_cast < LoadInst > ( & I ) ) { if ( Value * NoOpBitcast = maybeGenerateBitcast ( Builder , PointerTypes , I , LI -> getPointerOperand ( ) , LI -> getType ( ) ) ) { LI -> replaceAllUsesWith ( Builder . CreateLoad ( LI -> getType ( ) , NoOpBitcast ) ) ; LI -> eraseFromParent ( ) ; } continue ; } if ( auto SI = dyn_cast < StoreInst > ( & I ) ) { if ( Value * NoOpBitcast = maybeGenerateBitcast ( Builder , PointerTypes , I , SI -> getPointerOperand ( ) , SI -> getValueOperand ( ) -> getType ( ) ) ) { SI -> replaceAllUsesWith ( Builder . CreateStore ( SI -> getValueOperand ( ) , NoOpBitcast ) ) ; SI -> eraseFromParent ( ) ; } continue ;


<s> if ( auto LI = dyn_cast < LoadInst > ( & I ) ) { if ( Value * NoOpBitcast = maybeGenerateBitcast ( Builder , PointerTypes , I , LI -> getPointerOperand ( ) , LI -> getType ( ) ) ) { LI -> replaceAllUsesWith ( Builder . CreateLoad ( LI -> getType ( ) , NoOpBitcast ) ) ; LI -> eraseFromParent ( ) ; } continue ; } if ( auto SI = dyn_cast < StoreInst > ( & I ) ) { if ( Value * NoOpBitcast = maybeGenerateBitcast ( Builder , PointerTypes , I , SI -> getPointerOperand ( ) , SI -> getValueOperand ( ) -> getType ( ) ) ) { SI -> replaceAllUsesWith ( Builder . CreateStore ( SI -> getValueOperand ( ) , NoOpBitcast ) ) ; SI -> eraseFromParent ( ) ; }


<s> <ISA_LIT>PrepareModule ( ) : ModulePass ( ID ) {


<s> constexpr bool isValidFor<ISA_LIT> ( Attribute :: AttrKind Attr ) { return is_contained ( { Attribute :: Alignment , Attribute :: AlwaysInline , Attribute :: Builtin , Attribute :: ByVal , Attribute :: InAlloca , Attribute :: Cold , Attribute :: Convergent , Attribute :: InlineHint , Attribute :: InReg , Attribute :: JumpTable , Attribute :: MinSize , Attribute :: Naked , Attribute :: Nest , Attribute :: NoAlias , Attribute :: NoBuiltin , Attribute :: NoCapture , Attribute :: NoDuplicate , Attribute :: NoImplicitFloat , Attribute :: NoInline , Attribute :: NonLazyBind , Attribute :: NonNull , Attribute :: Dereferenceable , Attribute :: DereferenceableOrNull , Attribute :: NoRedZone , Attribute :: NoReturn , Attribute :: NoUnwind , Attribute :: OptimizeForSize , Attribute :: OptimizeNone , Attribute :: ReadNone , Attribute :: ReadOnly , Attribute :: ArgMemOnly , Attribute :: Returned , Attribute :: ReturnsTwice , Attribute :: SExt , Attribute :: StackAlignment , Attribute :: StackProtect , Attribute :: StackProtectReq , Attribute :: StackProtectStrong , Attribute :: SafeStack , Attribute :: StructRet , Attribute :: SanitizeAddress , Attribute :: SanitizeThread , Attribute :: SanitizeMemory , Attribute :: UWTable , Attribute :: ZExt } , Attr ) ;


<s> F . removeRetAttrs ( AttrMask ) ; for ( size_t Idx = <NUM_LIT> ; Idx < F . arg_size ( ) ; ++ Idx ) F . removeParamAttrs ( Idx , AttrMask ) ; for ( auto & BB : F ) { IRBuilder < > Builder ( & BB ) ; for ( auto & I : make_early_inc_range ( BB ) ) { if ( I . getOpcode ( ) == Instruction :: FNeg ) { Builder . SetInsertPoint ( & I ) ; Value * In = I . getOperand ( <NUM_LIT> ) ; Value * Zero = ConstantFP :: get ( In -> getType ( ) , - <NUM_LIT> ) ; I . replaceAllUsesWith ( Builder . CreateFSub ( Zero , In ) ) ; I . eraseFromParent ( ) ; }


<s> I = Attribute :: AttrKind ( I + <NUM_LIT> ) ) { if ( ! isValidFor<ISA_LIT> ( I ) ) AttrMask . addAttribute ( I ) ; } for ( auto & F : M . functions ( ) ) { F . removeFnAttrs ( AttrMask ) ; F . removeRetAttrs ( AttrMask ) ; for ( size_t Idx = <NUM_LIT> ; Idx < F . arg_size ( ) ; ++ Idx ) F . removeParamAttrs ( Idx , AttrMask ) ; for ( auto & BB : F ) { IRBuilder < > Builder ( & BB ) ; for ( auto & I : make_early_inc_range ( BB ) ) { if ( I . getOpcode ( ) == Instruction :: FNeg ) {


<s> static void cleanModule ( Module & M ) { cleanModuleFlags ( M ) ;


<s> static uint32_t ConstMDToUint32 ( const MDOperand & MDO ) {

ConstantInt * pConst = mdconst :: extract < ConstantInt > ( MDO ) ;


<s> static uint32_t ConstMDToUint32 ( const MDOperand & MDO ) { ConstantInt * pConst = mdconst :: extract < ConstantInt > ( MDO ) ; return ( uint32_t ) pConst -> getZExtValue ( ) ;


<s> explicit <ISA_LIT>TranslateMetadata ( ) : ModulePass ( ID ) , ValidatorVer ( <NUM_LIT> , <NUM_LIT> ) {


<s> static void emit<ISA_LIT>ValidatorVersion ( Module & M , VersionTuple & ValidatorVer ) { NamedMDNode * <ISA_LIT>ValidatorVersionMD = M . getNamedMetadata ( ValVerKey ) ;

if ( <ISA_LIT>ValidatorVersionMD ) M . eraseNamedMetadata ( <ISA_LIT>ValidatorVersionMD ) ;


<s> static VersionTuple load<ISA_LIT>ValidatorVersion ( MDNode * ValVerMD ) { if ( ValVerMD -> getNumOperands ( ) != <ISA_LIT>VersionNumFields ) return VersionTuple ( ) ; unsigned Major = ConstMDToUint32 ( ValVerMD -> getOperand ( <NUM_LIT> ) ) ; unsigned Minor = ConstMDToUint32 ( ValVerMD -> getOperand ( <NUM_LIT> ) ) ; return VersionTuple ( Major , Minor ) ;


<s> bool <ISA_LIT>TranslateMetadata :: runOnModule ( Module & M ) { if ( MDNode * ValVerMD = cast_or_null < MDNode > ( M . getModuleFlag ( ValVerKey ) ) ) { auto ValVer = load<ISA_LIT>ValidatorVersion ( ValVerMD ) ; if ( ! ValVer . empty ( ) ) ValidatorVer = ValVer ;


<s> static ConstantAsMetadata * Uint32ToConstMD ( unsigned v , LLVMContext & Ctx ) { return ConstantAsMetadata :: get ( Constant :: getIntegerValue ( IntegerType :: get ( Ctx , <NUM_LIT> ) , APInt ( <NUM_LIT> , v ) ) ) ;


<s> uint64_t ValueEnumerator :: computeBitsRequiredForTypeIndicies ( ) const { return Log2_32_Ceil ( getTypes ( ) . size ( ) + <NUM_LIT> ) ;


<s> void ValueEnumerator :: dropFunctionFromMetadata ( MetadataMapType :: value_type & FirstMD ) { SmallVector < const MDNode * , <NUM_LIT> > Worklist ; auto push = [ & Worklist ] ( MetadataMapType :: value_type & MD ) { auto & Entry = MD . second ; if ( ! Entry . F ) return ;


<s> if ( ! Entry . F ) return ; Entry . F = <NUM_LIT> ; if ( Entry . ID ) if ( auto * N = dyn_cast < MDNode > ( MD . first ) ) Worklist . push_back ( N ) ; } ; push ( FirstMD ) ; while ( ! Worklist . empty ( ) ) for ( const Metadata * Op : Worklist . pop_back_val ( ) -> operands ( ) ) { if ( ! Op ) continue ; auto MD = MetadataMap . find ( Op ) ; if ( MD != MetadataMap . end ( ) ) push ( * MD ) ;


<s> print ( dbgs ( ) , ValueMap , <STR_LIT> ) ;


<s> print ( dbgs ( ) , ValueMap , <STR_LIT> ) ; dbgs ( ) << '\n' ; print ( dbgs ( ) , MetadataMap , <STR_LIT> ) ;


<s> void ValueEnumerator :: EnumerateAttributes ( AttributeList PAL ) { if ( PAL . isEmpty ( ) ) return ; unsigned & Entry = AttributeListMap [ PAL ] ; if ( Entry == <NUM_LIT> ) { AttributeLists . push_back ( PAL ) ; Entry = AttributeLists . size ( ) ; }

for ( unsigned i : PAL . indexes ( ) ) {


<s> for ( ValueAsMetadata * VAM : ArgList -> getArgs ( ) ) { if ( isa < LocalAsMetadata > ( VAM ) ) { assert ( MetadataMap . count ( VAM ) && <STR_LIT> ) ; assert ( MetadataMap [ VAM ] . F == F && <STR_LIT> ) ; } else { assert ( isa < ConstantAsMetadata > ( VAM ) && <STR_LIT> ) ; assert ( ValueMap . count ( VAM -> getValue ( ) ) && <STR_LIT> ) ; EnumerateMetadata ( F , VAM ) ; } } MDs . push_back ( ArgList ) ; Index . F = F ;


<s> } else { assert ( isa < ConstantAsMetadata > ( VAM ) && <STR_LIT> ) ; assert ( ValueMap . count ( VAM -> getValue ( ) ) && <STR_LIT> ) ; EnumerateMetadata ( F , VAM ) ; } } MDs . push_back ( ArgList ) ; Index . F = F ; Index . ID = MDs . size ( ) ;


<s> assert ( Index . F == F && <STR_LIT> ) ; return ; } MDs . push_back ( Local ) ; Index . F = F ;


<s> if ( Op -> isDistinct ( ) && ! N -> isDistinct ( ) ) DelayedDistinctNodes . push_back ( Op ) ; else Worklist . push_back ( std :: make_pair ( Op , Op -> op_begin ( ) ) ) ; continue ; } Worklist . pop_back ( ) ; MDs . push_back ( N ) ; MetadataMap [ N ] . ID = MDs . size ( ) ; if ( Worklist . empty ( ) || Worklist . back ( ) . first -> isDistinct ( ) ) { for ( const MDNode * N : DelayedDistinctNodes ) Worklist . push_back ( std :: make_pair ( N , N -> op_begin ( ) ) ) ; DelayedDistinctNodes . clear ( ) ;


<s> assert ( ( isa < MDNode > ( MD ) || isa < MDString > ( MD ) || isa < ConstantAsMetadata > ( MD ) ) && <STR_LIT> ) ; auto Insertion = MetadataMap . insert ( std :: make_pair ( MD , MDIndex ( F ) ) ) ; MDIndex & Entry = Insertion . first -> second ; if ( ! Insertion . second ) { if ( Entry . hasDifferentFunction ( F ) ) dropFunctionFromMetadata ( * Insertion . first ) ; return nullptr ; } if ( auto * N = dyn_cast < MDNode > ( MD ) ) return N ; MDs . push_back ( MD ) ; Entry . ID = MDs . size ( ) ;

if ( auto * C = dyn_cast < ConstantAsMetadata > ( MD ) ) EnumerateValue ( C -> getValue ( ) ) ;


<s> void ValueEnumerator :: EnumerateNamedMDNode ( const NamedMDNode * MD ) { for ( unsigned i = <NUM_LIT> , e = MD -> getNumOperands ( ) ; i != e ; ++ i ) EnumerateMetadata ( nullptr , MD -> getOperand ( i ) ) ;


<s> for ( const auto & I : M . named_metadata ( ) ) EnumerateNamedMDNode ( & I ) ;


<s> EnumerateOperandType ( Op ) ; } if ( auto * CE = dyn_cast < ConstantExpr > ( C ) ) { if ( CE -> getOpcode ( ) == Instruction :: ShuffleVector ) EnumerateOperandType ( CE -> getShuffleMaskForBitcode ( ) ) ; if ( CE -> getOpcode ( ) == Instruction :: GetElementPtr ) EnumerateType ( cast < GEPOperator > ( CE ) -> getSourceElementType ( ) ) ;


<s> const Constant * C = dyn_cast < Constant > ( V ) ; if ( ! C ) return ; if ( ValueMap . count ( C ) ) return ; for ( const Value * Op : C -> operands ( ) ) { if ( isa < BasicBlock > ( Op ) ) continue ;


<s> if ( StructType * STy = dyn_cast < StructType > ( Ty ) ) if ( ! STy -> isLiteral ( ) ) * TypeID = ~ <NUM_LIT> ;

for ( Type * SubTy : Ty -> subtypes ( ) ) EnumerateType ( SubTy ) ;


<s> assert ( ! V -> getType ( ) -> isVoidTy ( ) && <STR_LIT> ) ; assert ( ! isa < MetadataAsValue > ( V ) && <STR_LIT> ) ; unsigned & ValueID = ValueMap [ V ] ; if ( ValueID ) { Values [ ValueID - <NUM_LIT> ] . second ++ ; return ; } if ( auto * GO = dyn_cast < GlobalObject > ( V ) ) if ( const Comdat * C = GO -> getComdat ( ) ) Comdats . insert ( C ) ; EnumerateType ( V -> getType ( ) ) ; if ( const Constant * C = dyn_cast < Constant > ( V ) ) {


<s> void ValueEnumerator :: EnumerateValueSymbolTable ( const ValueSymbolTable & VST ) {

for ( ValueSymbolTable :: const_iterator VI = VST . begin ( ) , VE = VST . end ( ) ;


<s> void ValueEnumerator :: EnumerateValueSymbolTable ( const ValueSymbolTable & VST ) { for ( ValueSymbolTable :: const_iterator VI = VST . begin ( ) , VE = VST . end ( ) ; VI != VE ; ++ VI ) EnumerateValue ( VI -> getValue ( ) ) ;


<s> const Metadata * get ( ArrayRef < const Metadata * > MDs ) const {


<s> const Metadata * get ( ArrayRef < const Metadata * > MDs ) const { assert ( ID && <STR_LIT> ) ; assert ( ID <= MDs . size ( ) && <STR_LIT> ) ;


<s> unsigned getAttributeGroupID ( IndexAndAttrSet Group ) const { if ( ! Group . second . hasAttributes ( ) ) return <NUM_LIT> ; AttributeGroupMapType :: const_iterator I = AttributeGroupMap . find ( Group ) ; assert ( I != AttributeGroupMap . end ( ) && <STR_LIT> ) ; return I -> second ;


<s> if ( ! Group . second . hasAttributes ( ) ) return <NUM_LIT> ; AttributeGroupMapType :: const_iterator I = AttributeGroupMap . find ( Group ) ; assert ( I != AttributeGroupMap . end ( ) && <STR_LIT> ) ;


<s> const std :: vector < IndexAndAttrSet > & getAttributeGroups ( ) const {


<s> assert ( I != AttributeListMap . end ( ) && <STR_LIT> ) ; return I -> second ;


<s> AttributeListMapType :: const_iterator I = AttributeListMap . find ( PAL ) ;

assert ( I != AttributeListMap . end ( ) && <STR_LIT> ) ;


<s> const std :: vector < AttributeList > & getAttributeLists ( ) const {


<s> const std :: vector < const BasicBlock * > & getBasicBlocks ( ) const { return BasicBlocks ;


<s> unsigned ValueEnumerator :: getComdatID ( const Comdat * C ) const {

unsigned ComdatID = Comdats . idFor ( C ) ;


<s> const ComdatSetType & getComdats ( ) const { return Comdats ;


<s> void getFunctionConstantRange ( unsigned & Start , unsigned & End ) const { Start = FirstFuncConstantID ; End = FirstInstID ;


<s> Start = FirstFuncConstantID ; End = FirstInstID ;


<s> unsigned ValueEnumerator :: getGlobalBasicBlockID ( const BasicBlock * BB ) const { unsigned & Idx = GlobalBasicBlockIDs [ BB ] ; if ( Idx != <NUM_LIT> ) return Idx - <NUM_LIT> ;

IncorporateFunctionInfoGlobalBBIDs ( BB -> getParent ( ) , GlobalBasicBlockIDs ) ;


<s> unsigned ValueEnumerator :: getGlobalBasicBlockID ( const BasicBlock * BB ) const {

unsigned & Idx = GlobalBasicBlockIDs [ BB ] ;


<s> unsigned ValueEnumerator :: getInstructionID ( const Instruction * Inst ) const { InstructionMapType :: const_iterator I = InstructionMap . find ( Inst ) ; assert ( I != InstructionMap . end ( ) && <STR_LIT> ) ;


<s> return makeArrayRef ( MDs ) . slice ( NumModuleMDs , NumMDStrings ) ;


<s> ArrayRef < const Metadata * > getMDStrings ( ) const {

return makeArrayRef ( MDs ) . slice ( NumModuleMDs , NumMDStrings ) ;


<s> unsigned ValueEnumerator :: getMetadataFunctionID ( const Function * F ) const { return F ? getValueID ( F ) + <NUM_LIT> : <NUM_LIT> ;


<s> unsigned ValueEnumerator :: getMetadataFunctionID ( const Function * F ) const {

return F ? getValueID ( F ) + <NUM_LIT> : <NUM_LIT> ;


<s> unsigned getMetadataID ( const Metadata * MD ) const { auto ID = getMetadataOrNullID ( MD ) ; assert ( ID != <NUM_LIT> && <STR_LIT> ) ;


<s> unsigned getMetadataOrNullID ( const Metadata * MD ) const {

return MetadataMap . lookup ( MD ) . ID ;


<s> if ( isa < MDString > ( MD ) ) return <NUM_LIT> ; auto * N = dyn_cast < MDNode > ( MD ) ; if ( ! N ) return <NUM_LIT> ;

return N -> isDistinct ( ) ? <NUM_LIT> : <NUM_LIT> ;


<s> ArrayRef < const Metadata * > getNonMDStrings ( ) const {

return makeArrayRef ( MDs ) . slice ( NumModuleMDs ) . slice ( NumMDStrings ) ;


<s> assert ( I != TypeMap . end ( ) && <STR_LIT> ) ;


<s> unsigned getTypeID ( Type * T ) const { TypeMapType :: const_iterator I = TypeMap . find ( T ) ; assert ( I != TypeMap . end ( ) && <STR_LIT> ) ; return I -> second - <NUM_LIT> ;


<s> unsigned ValueEnumerator :: getValueID ( const Value * V ) const { if ( auto * MD = dyn_cast < MetadataAsValue > ( V ) ) return getMetadataID ( MD -> getMetadata ( ) ) ;

ValueMapType :: const_iterator I = ValueMap . find ( V ) ;


<s> const ValueList & getValues ( ) const { return Values ;


<s> NumModuleValues = Values . size ( ) ; incorporateFunctionMetadata ( F ) ; for ( const auto & I : F . args ( ) ) { EnumerateValue ( & I ) ; if ( I . hasAttribute ( Attribute :: ByVal ) ) EnumerateType ( I . getParamByValType ( ) ) ; else if ( I . hasAttribute ( Attribute :: StructRet ) ) EnumerateType ( I . getParamStructRetType ( ) ) ; else if ( I . hasAttribute ( Attribute :: ByRef ) ) EnumerateType ( I . getParamByRefType ( ) ) ; } FirstFuncConstantID = Values . size ( ) ; for ( const BasicBlock & BB : F ) { for ( const Instruction & I : BB ) { for ( const Use & OI : I . operands ( ) ) { if ( ( isa < Constant > ( OI ) && ! isa < GlobalValue > ( OI ) ) || isa < InlineAsm > ( OI ) ) EnumerateValue ( OI ) ; } if ( auto * SVI = dyn_cast < ShuffleVectorInst > ( & I ) ) EnumerateValue ( SVI -> getShuffleMaskForBitcode ( ) ) ;


for ( const BasicBlock & BB : * F ) IDMap [ & BB ] = ++ Counter ;


MDs . insert ( MDs . end ( ) , FunctionMDs . begin ( ) + R . First , FunctionMDs . begin ( ) + R . Last ) ;


<s> unsigned ID = IDs . size ( ) + <NUM_LIT> ; IDs [ V ] . first = ID ;


<s> bool isGlobalConstant ( unsigned ID ) const { return ID <= LastGlobalConstantID ;


<s> return ID <= LastGlobalValueID && ! isGlobalConstant ( ID ) ;


<s> static bool isIntOrIntVectorValue ( const std :: pair < const Value * , unsigned > & V ) { return V . first -> getType ( ) -> isIntOrIntVectorTy ( ) ;


<s> return V . first -> getType ( ) -> isIntOrIntVectorTy ( ) ;


<s> explicit MDIndex ( unsigned F ) : F ( F ) {


<s> explicit MDRange ( unsigned First ) : First ( First ) {


<s> if ( ShouldPreserveUseListOrder ) return ; std :: stable_sort ( Values . begin ( ) + CstStart , Values . begin ( ) + CstEnd , [ this ] ( const std :: pair < const Value * , unsigned > & LHS , const std :: pair < const Value * , unsigned > & RHS ) { if ( LHS . first -> getType ( ) != RHS . first -> getType ( ) ) return getTypeID ( LHS . first -> getType ( ) ) < getTypeID ( RHS . first -> getType ( ) ) ; return LHS . second > RHS . second ; } ) ;

std :: stable_partition ( Values . begin ( ) + CstStart , Values . begin ( ) + CstEnd , isIntOrIntVectorValue ) ;


<s> for ( const GlobalAlias & A : M . aliases ( ) ) if ( ! isa < GlobalValue > ( A . getAliasee ( ) ) ) orderValue ( A . getAliasee ( ) , OM ) ; for ( const GlobalIFunc & I : M . ifuncs ( ) ) if ( ! isa < GlobalValue > ( I . getResolver ( ) ) ) orderValue ( I . getResolver ( ) , OM ) ; for ( const Function & F : M ) { for ( const Use & U : F . operands ( ) ) if ( ! isa < GlobalValue > ( U . get ( ) ) ) orderValue ( U . get ( ) , OM ) ; } auto orderConstantValue = [ & OM ] ( const Value * V ) { if ( ( isa < Constant > ( V ) && ! isa < GlobalValue > ( V ) ) || isa < InlineAsm > ( V ) ) orderValue ( V , OM ) ; } ; for ( const Function & F : M ) { if ( F . isDeclaration ( ) ) continue ; for ( const BasicBlock & BB : F ) for ( const Instruction & I : BB ) for ( const Value * V : I . operands ( ) ) { if ( const auto * MAV = dyn_cast < MetadataAsValue > ( V ) ) { if ( const auto * VAM = dyn_cast < ValueAsMetadata > ( MAV -> getMetadata ( ) ) ) { orderConstantValue ( VAM -> getValue ( ) ) ; } else if ( const auto * AL = dyn_cast < DIArgList > ( MAV -> getMetadata ( ) ) ) { for ( const auto * VAM : AL -> getArgs ( ) ) orderConstantValue ( VAM -> getValue ( ) ) ;


<s> for ( const Argument & A : F . args ( ) ) predictValueUseListOrder ( & A , & F , OM , Stack ) ; for ( const BasicBlock & BB : F ) for ( const Instruction & I : BB ) { for ( const Value * Op : I . operands ( ) ) if ( isa < Constant > ( * Op ) || isa < InlineAsm > ( * Op ) ) predictValueUseListOrder ( Op , & F , OM , Stack ) ; if ( auto * SVI = dyn_cast < ShuffleVectorInst > ( & I ) ) predictValueUseListOrder ( SVI -> getShuffleMaskForBitcode ( ) , & F , OM , Stack ) ; } for ( const BasicBlock & BB : F ) for ( const Instruction & I : BB ) predictValueUseListOrder ( & I , & F , OM , Stack ) ; } for ( const GlobalVariable & G : M . globals ( ) ) predictValueUseListOrder ( & G , nullptr , OM , Stack ) ; for ( const Function & F : M ) predictValueUseListOrder ( & F , nullptr , OM , Stack ) ; for ( const GlobalAlias & A : M . aliases ( ) ) predictValueUseListOrder ( & A , nullptr , OM , Stack ) ; for ( const GlobalIFunc & I : M . ifuncs ( ) ) predictValueUseListOrder ( & I , nullptr , OM , Stack ) ; for ( const GlobalVariable & G : M . globals ( ) ) if ( G . hasInitializer ( ) ) predictValueUseListOrder ( G . getInitializer ( ) , nullptr , OM , Stack ) ; for ( const GlobalAlias & A : M . aliases ( ) ) predictValueUseListOrder ( A . getAliasee ( ) , nullptr , OM , Stack ) ; for ( const GlobalIFunc & I : M . ifuncs ( ) ) predictValueUseListOrder ( I . getResolver ( ) , nullptr , OM , Stack ) ; for ( const Function & F : M ) {

for ( const Use & U : F . operands ( ) ) predictValueUseListOrder ( U . get ( ) , nullptr , OM , Stack ) ;


<s> assert ( IDPair . first && <STR_LIT> ) ; if ( IDPair . second ) return ; IDPair . second = true ; if ( ! V -> use_empty ( ) && std :: next ( V -> use_begin ( ) ) != V -> use_end ( ) ) predictValueUseListOrderImpl ( V , F , IDPair . first , OM , Stack ) ; if ( const Constant * C = dyn_cast < Constant > ( V ) ) { if ( C -> getNumOperands ( ) ) { for ( const Value * Op : C -> operands ( ) ) if ( isa < Constant > ( Op ) ) predictValueUseListOrder ( Op , F , OM , Stack ) ; if ( auto * CE = dyn_cast < ConstantExpr > ( C ) ) if ( CE -> getOpcode ( ) == Instruction :: ShuffleVector ) predictValueUseListOrder ( CE -> getShuffleMaskForBitcode ( ) , F , OM , Stack ) ; }


<s> IDPair . second = true ; if ( ! V -> use_empty ( ) && std :: next ( V -> use_begin ( ) ) != V -> use_end ( ) ) predictValueUseListOrderImpl ( V , F , IDPair . first , OM , Stack ) ; if ( const Constant * C = dyn_cast < Constant > ( V ) ) {


<s> for ( const auto & I : Map ) { const Metadata * MD = I . first ;

OS << <STR_LIT> << I . second . ID << <STR_LIT> ;


<s> for ( const BasicBlock * BB : BasicBlocks ) ValueMap . erase ( BB ) ; Values . resize ( NumModuleValues ) ; MDs . resize ( NumModuleMDs ) ; BasicBlocks . clear ( ) ;


<s> bool shouldPreserveUseListOrder ( ) const {


<s> EnumerateValue ( & GV ) ; EnumerateType ( GV . getValueType ( ) ) ; } for ( const Function & F : M ) { EnumerateValue ( & F ) ; EnumerateType ( F . getValueType ( ) ) ; EnumerateAttributes ( F . getAttributes ( ) ) ; } for ( const GlobalAlias & GA : M . aliases ( ) ) { EnumerateValue ( & GA ) ; EnumerateType ( GA . getValueType ( ) ) ; } for ( const GlobalIFunc & GIF : M . ifuncs ( ) ) { EnumerateValue ( & GIF ) ; EnumerateType ( GIF . getValueType ( ) ) ; } unsigned FirstConstant = Values . size ( ) ; for ( const GlobalVariable & GV : M . globals ( ) ) { if ( GV . hasInitializer ( ) ) EnumerateValue ( GV . getInitializer ( ) ) ; if ( GV . hasAttributes ( ) ) EnumerateAttributes ( GV . getAttributesAsList ( AttributeList :: FunctionIndex ) ) ; } for ( const GlobalAlias & GA : M . aliases ( ) ) EnumerateValue ( GA . getAliasee ( ) ) ; for ( const GlobalIFunc & GIF : M . ifuncs ( ) ) EnumerateValue ( GIF . getResolver ( ) ) ; for ( const Function & F : M ) for ( const Use & U : F . operands ( ) ) EnumerateValue ( U . get ( ) ) ; EnumerateType ( Type :: getMetadataTy ( M . getContext ( ) ) ) ;

EnumerateValueSymbolTable ( M . getValueSymbolTable ( ) ) ;


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


<s> StringRef getPassName ( ) const override {


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


<s> bool runOnModule ( Module & M ) override { Write<ISA_LIT>ToFile ( M , OS ) ; return false ;


<s> initializeWrite<ISA_LIT>PassPass ( * PassRegistry :: getPassRegistry ( ) ) ;


<s> explicit Write<ISA_LIT>Pass ( raw_ostream & o ) : ModulePass ( ID ) , OS ( o ) {

initializeWrite<ISA_LIT>PassPass ( * PassRegistry :: getPassRegistry ( ) ) ;


<s> for ( const auto & I : B ) { if ( const auto * RetInst = dyn_cast_or_null < ReturnInst > ( & I ) ) { Type * NewRetTy = classifyPointerType ( RetInst -> getReturnValue ( ) ) ; if ( ! RetTy ) RetTy = NewRetTy ; else if ( RetTy != NewRetTy ) RetTy = TypedPointerType :: get ( Type :: getInt8Ty ( I . getContext ( ) ) , F . getReturnType ( ) -> getPointerAddressSpace ( ) ) ; } } } } for ( auto & A : F . args ( ) ) { Type * ArgTy = A . getType ( ) ; if ( ArgTy -> isOpaquePointerTy ( ) ) { TypedPointerType * NewTy = classifyPointerType ( & A ) ; Map [ & A ] = NewTy ; ArgTy = NewTy ;


<s> NewPointeeTy = Inst -> getValueOperand ( ) -> getType ( ) ; } else if ( const auto * Inst = dyn_cast < GetElementPtrInst > ( User ) ) { NewPointeeTy = Inst -> getSourceElementType ( ) ; } if ( NewPointeeTy ) { if ( NewPointeeTy -> isOpaquePointerTy ( ) ) return TypedPointerType :: get ( classifyPointerType ( User ) , V -> getType ( ) -> getPointerAddressSpace ( ) ) ; if ( ! PointeeTy ) PointeeTy = NewPointeeTy ; else if ( PointeeTy != NewPointeeTy ) PointeeTy = Type :: getInt8Ty ( V -> getContext ( ) ) ;


<s> for ( const auto & I : B ) { if ( I . getType ( ) -> isOpaquePointerTy ( ) ) Map [ & I ] = classifyPointerType ( & I ) ; } }