add exact flag to IRBuilder
This commit is contained in:
parent
1e9d37a64e
commit
cfe5e9ea92
2 changed files with 43 additions and 8 deletions
20
llvm/core.py
20
llvm/core.py
|
|
@ -2145,11 +2145,13 @@ class Builder(llvm.Wrapper):
|
|||
def fmul(self, lhs, rhs, name=""):
|
||||
return _make_value(self._ptr.CreateFMul(lhs._ptr, rhs._ptr, name))
|
||||
|
||||
def udiv(self, lhs, rhs, name=""):
|
||||
return _make_value(self._ptr.CreateUDiv(lhs._ptr, rhs._ptr, name))
|
||||
def udiv(self, lhs, rhs, name="", exact=False):
|
||||
return _make_value(self._ptr.CreateUDiv(lhs._ptr, rhs._ptr, name,
|
||||
exact))
|
||||
|
||||
def sdiv(self, lhs, rhs, name=""):
|
||||
return _make_value(self._ptr.CreateSDiv(lhs._ptr, rhs._ptr, name))
|
||||
def sdiv(self, lhs, rhs, name="", exact=False):
|
||||
return _make_value(self._ptr.CreateSDiv(lhs._ptr, rhs._ptr, name,
|
||||
exact))
|
||||
|
||||
def fdiv(self, lhs, rhs, name=""):
|
||||
return _make_value(self._ptr.CreateFDiv(lhs._ptr, rhs._ptr, name))
|
||||
|
|
@ -2167,11 +2169,13 @@ class Builder(llvm.Wrapper):
|
|||
return _make_value(self._ptr.CreateShl(lhs._ptr, rhs._ptr, name,
|
||||
nuw, nsw))
|
||||
|
||||
def lshr(self, lhs, rhs, name=""):
|
||||
return _make_value(self._ptr.CreateLShr(lhs._ptr, rhs._ptr, name))
|
||||
def lshr(self, lhs, rhs, name="", exact=False):
|
||||
return _make_value(self._ptr.CreateLShr(lhs._ptr, rhs._ptr, name,
|
||||
exact))
|
||||
|
||||
def ashr(self, lhs, rhs, name=""):
|
||||
return _make_value(self._ptr.CreateAShr(lhs._ptr, rhs._ptr, name))
|
||||
def ashr(self, lhs, rhs, name="", exact=False):
|
||||
return _make_value(self._ptr.CreateAShr(lhs._ptr, rhs._ptr, name,
|
||||
exact))
|
||||
|
||||
def and_(self, lhs, rhs, name=""):
|
||||
return _make_value(self._ptr.CreateAnd(lhs._ptr, rhs._ptr, name))
|
||||
|
|
|
|||
|
|
@ -1511,6 +1511,37 @@ class TestNUWNSW(TestCase):
|
|||
|
||||
tests.append(TestNUWNSW)
|
||||
|
||||
|
||||
class TestExact(TestCase):
|
||||
def make_module(self):
|
||||
mod = Module.new('asdfa')
|
||||
fnty = Type.function(Type.void(), [Type.int()] * 2)
|
||||
func = mod.add_function(fnty, 'foo')
|
||||
bldr = Builder.new(func.append_basic_block(''))
|
||||
return mod, func, bldr
|
||||
|
||||
def has_exact(self, inst, op):
|
||||
self.assertTrue(('%s exact' % op) in str(inst), "exact flag does not work")
|
||||
|
||||
def _test_template(self, opf, opname):
|
||||
mod, func, bldr = self.make_module()
|
||||
a, b = func.args
|
||||
self.has_exact(opf(bldr, a, b, exact=True), opname)
|
||||
|
||||
def test_udiv_exact(self):
|
||||
self._test_template(Builder.udiv, 'udiv')
|
||||
|
||||
def test_sdiv_exact(self):
|
||||
self._test_template(Builder.sdiv, 'sdiv')
|
||||
|
||||
def test_lshr_exact(self):
|
||||
self._test_template(Builder.lshr, 'lshr')
|
||||
|
||||
def test_ashr_exact(self):
|
||||
self._test_template(Builder.ashr, 'ashr')
|
||||
|
||||
tests.append(TestExact)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def run(verbosity=1):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue