From 01b55b48f7c121e96b2e0383755089e0795253de Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Wed, 29 Aug 2012 13:51:07 -0700 Subject: [PATCH] Add detection of whether LLVM has PTX in the windows build --- llvm-config-win32.py | 10 ++++++++-- llvm/extra.h | 5 ----- setup.py | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/llvm-config-win32.py b/llvm-config-win32.py index db9de65..0e70231 100644 --- a/llvm-config-win32.py +++ b/llvm-config-win32.py @@ -1,8 +1,8 @@ import sys, os -def find_path_of(filename): +def find_path_of(filename, envvar='PATH'): """Finds the path from $PATH where the file exists, returns None if not found.""" - pathlist = os.getenv('PATH').split(os.pathsep) + pathlist = os.getenv(envvar).split(os.pathsep) for path in pathlist: if os.path.exists(os.path.join(path, filename)): return os.path.abspath(path) @@ -50,6 +50,12 @@ Advapi32 Shell32 """.split(): print('-l%s' % lib) + # Look for the PTX .lib in %LIBPATH% + if find_path_of('LLVMPTXCodeGen.lib', 'LIBPATH') != None: + print('-lLLVMPTXAsmPrinter') + print('-lLLVMPTXCodeGen') + print('-lLLVMPTXDesc') + print('-lLLVMPTXInfo') elif sys.argv[1] == '--includedir': llvmbin = find_path_of('llvm-tblgen.exe') if llvmbin is None: diff --git a/llvm/extra.h b/llvm/extra.h index 7182411..4cc3072 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -45,15 +45,10 @@ #define LLVM_HAS_NVPTX 0 #endif -#if defined(_WIN32) - #define LLVM_DISABLE_PTX -#endif - #include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm_c_extra.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/setup.py b/setup.py index 611472a..219c8da 100644 --- a/setup.py +++ b/setup.py @@ -68,7 +68,10 @@ if dynlink: objs_core = [] else: if sys.platform == 'win32': - print('PTX is disabled on Win32 at the moment') + # XXX: If found, the PTX components are returned by llvm-config-win32.py, + # regardless of whether we ask for them. There should be a better way + # eventually. + print('PTX is included on Win32 at if found by llvm-config-win32.py') ptx_components = [] elif llvm_version <= (3, 1): # select between PTX & NVPTX print('Using PTX') @@ -91,13 +94,20 @@ else: 'asmparser', 'linker', 'support', 'vectorize'] + ptx_components) +macros = [('__STDC_CONSTANT_MACROS', None), + ('__STDC_LIMIT_MACROS', None)] +if sys.platform == 'win32': + # If no PTX lib got added, disable PTX in the build + if 'LLVMPTXCodeGen' not in libs_core: + macros.append(('LLVM_DISABLE_PTX', None)), +else: + macros.append(('_GNU_SOURCE', None)) + extra_link_args = ldflags.split() kwds = dict(ext_modules = [Extension( name='llvm._core', sources=['llvm/_core.cpp', 'llvm/wrap.cpp', 'llvm/extra.cpp'], - define_macros = [('__STDC_CONSTANT_MACROS', None), - ('__STDC_LIMIT_MACROS', None), - ('_GNU_SOURCE', None)], + define_macros = macros, include_dirs = ['/usr/include', incdir], library_dirs = [libdir], libraries = libs_core,