Example #1
0
        /// <summary>
        /// Creates a call instruction to the given method with the given arguments.
        /// </summary>
        /// <param name="block">The current basic block.</param>
        /// <param name="builder">The current builder.</param>
        /// <param name="method">The target method to invoke.</param>
        /// <param name="arguments">The call arguments.</param>
        private void CreateCall(
            Block block,
            IRBuilder builder,
            MethodBase method,
            ImmutableArray <ValueReference> arguments)
        {
            var intrinsicContext = new InvocationContext(this, block, Method, method, arguments);

            // Check for remapping first
            RemappedIntrinsics.RemapIntrinsic(ref intrinsicContext);
            Frontend.RemapIntrinsic(ref intrinsicContext);

            // Early rejection for runtime-dependent methods
            VerifyNotRuntimeMethod(intrinsicContext.Method);

            // Handle device functions
            if (!Intrinsics.HandleIntrinsic(intrinsicContext, out ValueReference result) &&
                !Frontend.HandleIntrinsic(intrinsicContext, out result))
            {
                var targetFunction = DeclareMethod(intrinsicContext.Method);

                result = builder.CreateCall(
                    targetFunction,
                    intrinsicContext.Arguments);
            }

            // Setup result
            if (result.IsValid && !result.Type.IsVoidType)
            {
                block.Push(result);
            }
        }