Add detection of whether LLVM has PTX in the windows build

This commit is contained in:
Mark Wiebe 2012-08-29 13:51:07 -07:00
commit 01b55b48f7
3 changed files with 22 additions and 11 deletions

View file

@ -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:

View file

@ -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

View file

@ -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,