public Resolver(Context context, IRContext irContext) : base(irContext) { MathImplementationResolver resolver; using (var phase = context.BeginCodeGeneration(irContext)) { using (var frontendPhase = phase.BeginFrontendCodeGeneration()) { resolver = new MathImplementationResolver( frontendPhase, mathFunction => mathFunction.GetCustomAttribute <PTXMathIntrinsicAttribute>() == null, typeof(XMath), typeof(Resolver)); // Declare debugging functions var deviceAssertFunction = frontendPhase.DeclareMethod( new MethodDeclaration( DebugAssertFailedName, irContext.VoidType, MethodFlags.External)); using (var failedBuilder = deviceAssertFunction.CreateBuilder()) { failedBuilder.AddParameter(irContext.StringType, "message"); failedBuilder.AddParameter(irContext.StringType, "file"); failedBuilder.AddParameter( irContext.GetPrimitiveType(BasicValueType.Int32), "line"); failedBuilder.AddParameter(irContext.StringType, "function"); failedBuilder.AddParameter( irContext.GetPrimitiveType(BasicValueType.Int32), "charSize"); } debugAssertFunction = frontendPhase.DeclareMethod( new MethodDeclaration( WrapperDebugAssertFailedName, irContext.VoidType, MethodFlags.Inline)); using (var assertBuilder = debugAssertFunction.CreateBuilder()) { var messageParam = assertBuilder.AddParameter(irContext.StringType, "message"); var entryBlock = assertBuilder.CreateEntryBlock(); entryBlock.CreateCall( deviceAssertFunction, ImmutableArray.Create( messageParam, entryBlock.CreatePrimitiveValue("Kernel.cs"), entryBlock.CreatePrimitiveValue(0), entryBlock.CreatePrimitiveValue("Kernel"), entryBlock.CreatePrimitiveValue(1))); entryBlock.CreateReturn(); } } } // Perform an initial pass to resolve all PTX-specific intrinsic functions var transformer = Transformer.Create( new TransformerConfiguration(MethodTransformationFlags.None, false), new IntrinsicSpecializer <PTXIntrinsicConfiguration>(new PTXIntrinsicConfiguration( this))); irContext.Transform(transformer); resolver.ApplyTo(this); // Resolve all previously unresolved intrinsic functions /* This is required since the intrinsic implementation resolver does not perform * time-consuming recursive dependency analyses. This is not an issue since * these analyses and recursive passes are not required for default user kernels. * Unfortunately, we need a second pass at this point to ensure that all intrinsic * function declarations have been properly resolved. */ irContext.Transform(transformer); // Optimize the whole module irContext.Optimize(); }