Allow initialization of other targets.
- Remove PTX/NVPTX targets from default built and init
This commit is contained in:
parent
b754e803ec
commit
a357987597
6 changed files with 48 additions and 67 deletions
25
llvm/core.py
25
llvm/core.py
|
|
@ -2305,28 +2305,3 @@ if api.llvm.InitializeNativeTargetAsmPrinter():
|
|||
# should user trigger the initialization?
|
||||
raise llvm.LLVMException("No native asm printer!?")
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# Initialization
|
||||
#===----------------------------------------------------------------------===
|
||||
|
||||
HAS_PTX = HAS_NVPTX = False
|
||||
|
||||
if True: # use PTX?
|
||||
try:
|
||||
api.LLVMInitializePTXTarget()
|
||||
api.LLVMInitializePTXTargetInfo()
|
||||
api.LLVMInitializePTXTargetMC()
|
||||
api.LLVMInitializePTXAsmPrinter()
|
||||
HAS_PTX = True
|
||||
except AttributeError:
|
||||
try:
|
||||
api.LLVMInitializeNVPTXTarget()
|
||||
api.LLVMInitializeNVPTXTargetInfo()
|
||||
api.LLVMInitializeNVPTXTargetMC()
|
||||
api.LLVMInitializeNVPTXAsmPrinter()
|
||||
HAS_NVPTX = True
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
18
llvm/ee.py
18
llvm/ee.py
|
|
@ -222,6 +222,24 @@ class ExecutionEngine(llvm.Wrapper):
|
|||
# Target machine
|
||||
#===----------------------------------------------------------------------===
|
||||
|
||||
def initialize_target(target, noraise=False):
|
||||
"""Initialize target by name.
|
||||
It is safe to initialize the same target multiple times.
|
||||
"""
|
||||
prefix = 'LLVMInitialize'
|
||||
postfixes = ['Target', 'TargetInfo', 'TargetMC', 'AsmPrinter']
|
||||
try:
|
||||
for postfix in postfixes:
|
||||
getattr(api, '%s%s%s' % (prefix, target, postfix))()
|
||||
except AttributeError:
|
||||
if noraise:
|
||||
return False
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def print_registered_targets():
|
||||
'''
|
||||
Note: print directly to stdout
|
||||
|
|
|
|||
|
|
@ -636,12 +636,13 @@ class TestTargetMachines(TestCase):
|
|||
self.assertTrue(le.get_host_cpu_name())
|
||||
|
||||
def test_ptx(self):
|
||||
if lc.HAS_PTX:
|
||||
if le.initialize_target('PTX', noraise=True):
|
||||
arch = 'ptx64'
|
||||
elif lc.HAS_NVPTX:
|
||||
elif le.initialize_target('NVPTX', noraise=True):
|
||||
arch = 'nvptx64'
|
||||
else:
|
||||
return # skip this test
|
||||
|
||||
print(arch)
|
||||
m, func = self._build_module()
|
||||
func.calling_convention = lc.CC_PTX_KERNEL # set calling conv
|
||||
|
|
@ -650,7 +651,7 @@ class TestTargetMachines(TestCase):
|
|||
self.assertTrue(ptxtm.cpu)
|
||||
ptxasm = ptxtm.emit_assembly(m)
|
||||
self.assertIn('foo', ptxasm)
|
||||
if lc.HAS_NVPTX:
|
||||
if arch == 'nvptx64':
|
||||
self.assertIn('.address_size 64', ptxasm)
|
||||
self.assertIn('sm_20', ptxasm)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue