Beispiel #1
0
        /// <summary cref="Backend.TargetUnit(CompileUnit)"/>
        internal override void TargetUnit(CompileUnit unit)
        {
            var module       = unit.LLVMModule;
            var dataLayout   = GetLLVMLayout(Platform);
            var targetTriple = GetLLVMTriple(Platform);

            SetDataLayout(module, dataLayout);
            SetTarget(module, targetTriple);

            if (CreateMemoryBufferWithContentsOfFile(LibDevicePath, out LLVMMemoryBufferRef libDeviceBuffer, out IntPtr errorMessage))
            {
                throw new InvalidOperationException(string.Format(
                                                        ErrorMessages.CouldNotReadLibDevice, Marshal.PtrToStringAnsi(errorMessage)));
            }
            if (GetBitcodeModuleInContext(unit.LLVMContext, libDeviceBuffer, out LLVMModuleRef libDeviceModule, out errorMessage))
            {
                throw new InvalidOperationException(string.Format(
                                                        ErrorMessages.CouldNotLoadLibDevice, Marshal.PtrToStringAnsi(errorMessage)));
            }
            SetDataLayout(libDeviceModule, dataLayout);
            SetTarget(libDeviceModule, targetTriple);
            LinkModules2(module, libDeviceModule);

            var functions = new PTXDeviceFunctions(unit);

            ptxDeviceFunctions.Add(unit, functions);
            unit.RegisterDeviceFunctions(functions);
        }