Fix breakage of LLVM 3.1.
Add LLVM version number in llvmpy.
This commit is contained in:
parent
dd32ce56b1
commit
5b6a1d75f8
7 changed files with 50 additions and 8 deletions
|
|
@ -8,7 +8,19 @@ __version__ = '0.9.1'
|
||||||
from weakref import WeakValueDictionary
|
from weakref import WeakValueDictionary
|
||||||
from llvm._utils.finalizer import track as track_resource
|
from llvm._utils.finalizer import track as track_resource
|
||||||
from llvm._utils.finalizer import OwnerMixin as _OwnerMixin
|
from llvm._utils.finalizer import OwnerMixin as _OwnerMixin
|
||||||
|
from llvm import _core
|
||||||
|
|
||||||
|
#===----------------------------------------------------------------------===
|
||||||
|
# LLVM Version
|
||||||
|
#===----------------------------------------------------------------------===
|
||||||
|
|
||||||
|
version = _core.LLVMGetVersion()
|
||||||
|
|
||||||
|
def require_version_at_least(major, minor):
|
||||||
|
'''Sentry to guard version requirement
|
||||||
|
'''
|
||||||
|
if version < (major, minor):
|
||||||
|
raise Exception(major, minor)
|
||||||
|
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
# Exceptions
|
# Exceptions
|
||||||
|
|
|
||||||
|
|
@ -1065,7 +1065,10 @@ _wrap_obj2str(LLVMGetPassName, LLVMPassRef)
|
||||||
_wrap_obj2none(LLVMPassDump, LLVMPassRef)
|
_wrap_obj2none(LLVMPassDump, LLVMPassRef)
|
||||||
|
|
||||||
_wrap_str2obj(LLVMCreateTargetLibraryInfo, LLVMPassRef)
|
_wrap_str2obj(LLVMCreateTargetLibraryInfo, LLVMPassRef)
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 2
|
||||||
_wrap_obj2obj(LLVMCreateTargetTransformInfo, LLVMTargetMachineRef, LLVMPassRef)
|
_wrap_obj2obj(LLVMCreateTargetTransformInfo, LLVMTargetMachineRef, LLVMPassRef)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*===----------------------------------------------------------------------===*/
|
/*===----------------------------------------------------------------------===*/
|
||||||
|
|
@ -1510,6 +1513,14 @@ _wrap_obj2none(LLVMDisposeGenericValue, LLVMGenericValueRef)
|
||||||
/* Misc */
|
/* Misc */
|
||||||
/*===----------------------------------------------------------------------===*/
|
/*===----------------------------------------------------------------------===*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_wLLVMGetVersion(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
int major = LLVM_VERSION_MAJOR;
|
||||||
|
int minor = LLVM_VERSION_MINOR;
|
||||||
|
return Py_BuildValue("(i,i)", major, minor);
|
||||||
|
}
|
||||||
|
|
||||||
_wrap_objintlist2obj(LLVMGetIntrinsic, LLVMModuleRef, LLVMTypeRef,
|
_wrap_objintlist2obj(LLVMGetIntrinsic, LLVMModuleRef, LLVMTypeRef,
|
||||||
LLVMValueRef)
|
LLVMValueRef)
|
||||||
|
|
||||||
|
|
@ -2108,9 +2119,13 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMPassDump )
|
_method( LLVMPassDump )
|
||||||
|
|
||||||
_method( LLVMCreateTargetLibraryInfo )
|
_method( LLVMCreateTargetLibraryInfo )
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 2
|
||||||
_method( LLVMCreateTargetTransformInfo )
|
_method( LLVMCreateTargetTransformInfo )
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
|
_method( LLVMGetVersion )
|
||||||
_method( LLVMGetIntrinsic )
|
_method( LLVMGetIntrinsic )
|
||||||
_method( LLVMLoadLibraryPermanently )
|
_method( LLVMLoadLibraryPermanently )
|
||||||
_method( LLVMParseEnvOpts )
|
_method( LLVMParseEnvOpts )
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,7 @@ const CodeModel::Model CodeModelMap[] = {
|
||||||
|
|
||||||
} // end anony namespace
|
} // end anony namespace
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 2
|
||||||
LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref){
|
LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref){
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
TargetMachine * tm = unwrap(tmref);
|
TargetMachine * tm = unwrap(tmref);
|
||||||
|
|
@ -162,6 +163,7 @@ LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref){
|
||||||
tm->getVectorTargetTransformInfo());
|
tm->getVectorTargetTransformInfo());
|
||||||
return wrap(tti);
|
return wrap(tti);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
LLVMPassRef LLVMCreateTargetLibraryInfo(const char * triple){
|
LLVMPassRef LLVMCreateTargetLibraryInfo(const char * triple){
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
|
||||||
|
|
@ -54,12 +54,15 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 2
|
||||||
/*
|
/*
|
||||||
* Wraps new TargetTransformInfo(
|
* Wraps new TargetTransformInfo(
|
||||||
* TargetMachine::getScalarTargetTransformInfo,
|
* TargetMachine::getScalarTargetTransformInfo,
|
||||||
* TargetMachine::getVectorTargetTransformInfo)
|
* TargetMachine::getVectorTargetTransformInfo)
|
||||||
*/
|
*/
|
||||||
LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref);
|
LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wraps new TargetLibraryInfo
|
* Wraps new TargetLibraryInfo
|
||||||
|
|
|
||||||
|
|
@ -89,10 +89,10 @@ class PassManagerBuilder(llvm.Handle):
|
||||||
vectorize = property(_get_vectorize, _set_vectorize)
|
vectorize = property(_get_vectorize, _set_vectorize)
|
||||||
|
|
||||||
def _set_loop_vectorize(self, enable):
|
def _set_loop_vectorize(self, enable):
|
||||||
try:
|
if llvm.version >= (3, 2):
|
||||||
_core.LLVMPassManagerBuilderSetLoopVectorize(self.ptr,
|
_core.LLVMPassManagerBuilderSetLoopVectorize(self.ptr,
|
||||||
int(bool(enable)))
|
int(bool(enable)))
|
||||||
except AttributeError:
|
else:
|
||||||
warnings.warn("Ignored. LLVM-3.1 & prior do not support loop vectorizer.")
|
warnings.warn("Ignored. LLVM-3.1 & prior do not support loop vectorizer.")
|
||||||
|
|
||||||
def _get_loop_vectorize(self):
|
def _get_loop_vectorize(self):
|
||||||
|
|
@ -326,9 +326,11 @@ class TargetLibraryInfo(Pass):
|
||||||
class TargetTransformInfo(Pass):
|
class TargetTransformInfo(Pass):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new(targetmachine):
|
def new(targetmachine):
|
||||||
|
llvm.require_version_at_least(3, 2)
|
||||||
ptr = _core.LLVMCreateTargetTransformInfo(targetmachine.ptr)
|
ptr = _core.LLVMCreateTargetTransformInfo(targetmachine.ptr)
|
||||||
return TargetTransformInfo(ptr)
|
return TargetTransformInfo(ptr)
|
||||||
|
|
||||||
|
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
# Helpers
|
# Helpers
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
|
|
@ -365,13 +367,15 @@ def build_pass_managers(tm, opt=2, loop_vectorize=False, vectorize=False,
|
||||||
if pm:
|
if pm:
|
||||||
pm.add(tm.target_data)
|
pm.add(tm.target_data)
|
||||||
pm.add(TargetLibraryInfo.new(tm.triple))
|
pm.add(TargetLibraryInfo.new(tm.triple))
|
||||||
pm.add(TargetTransformInfo.new(tm))
|
if llvm.version >= (3, 2):
|
||||||
|
pm.add(TargetTransformInfo.new(tm))
|
||||||
pmb.populate(pm)
|
pmb.populate(pm)
|
||||||
|
|
||||||
if fpm:
|
if fpm:
|
||||||
fpm.add(tm.target_data)
|
fpm.add(tm.target_data)
|
||||||
fpm.add(TargetLibraryInfo.new(tm.triple))
|
fpm.add(TargetLibraryInfo.new(tm.triple))
|
||||||
fpm.add(TargetTransformInfo.new(tm))
|
if llvm.version >= (3, 2):
|
||||||
|
fpm.add(TargetTransformInfo.new(tm))
|
||||||
pmb.populate(fpm)
|
pmb.populate(fpm)
|
||||||
fpm.initialize()
|
fpm.initialize()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
from llvm.core import *
|
from llvm.core import *
|
||||||
from llvm.passes import *
|
from llvm.passes import *
|
||||||
from llvm.ee import *
|
from llvm.ee import *
|
||||||
|
import llvm
|
||||||
from os.path import dirname, join as join_path
|
from os.path import dirname, join as join_path
|
||||||
|
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class TestLoopVectorizer(unittest.TestCase):
|
class TestLoopVectorizer(unittest.TestCase):
|
||||||
def test_loop_vectorizer(self):
|
def test_loop_vectorizer(self):
|
||||||
|
if llvm.version <= (3, 1):
|
||||||
|
return # SKIP
|
||||||
|
|
||||||
re_vector = re.compile("<\d+ x \w+>")
|
re_vector = re.compile("<\d+ x \w+>")
|
||||||
|
|
||||||
|
|
|
||||||
10
test/pass.py
10
test/pass.py
|
|
@ -1,6 +1,7 @@
|
||||||
from llvm.core import *
|
from llvm.core import *
|
||||||
from llvm.passes import *
|
from llvm.passes import *
|
||||||
from llvm.ee import *
|
from llvm.ee import *
|
||||||
|
import llvm
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestPass(unittest.TestCase):
|
class TestPass(unittest.TestCase):
|
||||||
|
|
@ -26,11 +27,12 @@ class TestPass(unittest.TestCase):
|
||||||
self.assertTrue(tli.description)
|
self.assertTrue(tli.description)
|
||||||
pm.add(tli)
|
pm.add(tli)
|
||||||
|
|
||||||
tti = TargetTransformInfo.new(tm)
|
if llvm.version >= (3, 2):
|
||||||
self.assertFalse(tti.name)
|
tti = TargetTransformInfo.new(tm)
|
||||||
self.assertTrue(tti.description)
|
self.assertFalse(tti.name)
|
||||||
|
self.assertTrue(tti.description)
|
||||||
|
|
||||||
pm.add(tti)
|
pm.add(tti)
|
||||||
|
|
||||||
pmb = PassManagerBuilder.new()
|
pmb = PassManagerBuilder.new()
|
||||||
pmb.opt_level = 3
|
pmb.opt_level = 3
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue