Add GEP inbounds

This commit is contained in:
Siu Kwan Lam 2013-01-14 10:30:46 -06:00
commit 8b58488bbd
3 changed files with 14 additions and 8 deletions

View file

@ -878,6 +878,9 @@ _wrap_objobj2obj(LLVMBuildFree, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
_wrap_objobjstr2obj(LLVMBuildLoad, LLVMBuilderRef, LLVMValueRef, LLVMValueRef) _wrap_objobjstr2obj(LLVMBuildLoad, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
_wrap_objobjobj2obj(LLVMBuildStore, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef) _wrap_objobjobj2obj(LLVMBuildStore, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objobjliststr2obj(LLVMBuildGEP, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef) _wrap_objobjliststr2obj(LLVMBuildGEP, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objobjliststr2obj(LLVMBuildInBoundsGEP, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objint2none(LLVMLdSetAlignment, LLVMValueRef) _wrap_objint2none(LLVMLdSetAlignment, LLVMValueRef)
_wrap_objint2none(LLVMStSetAlignment, LLVMValueRef) _wrap_objint2none(LLVMStSetAlignment, LLVMValueRef)
@ -1959,6 +1962,7 @@ static PyMethodDef core_methods[] = {
_method( LLVMBuildLoad ) _method( LLVMBuildLoad )
_method( LLVMBuildStore ) _method( LLVMBuildStore )
_method( LLVMBuildGEP ) _method( LLVMBuildGEP )
_method( LLVMBuildInBoundsGEP )
_method( LLVMLdSetAlignment ) _method( LLVMLdSetAlignment )
_method( LLVMStSetAlignment ) _method( LLVMStSetAlignment )

View file

@ -2066,11 +2066,14 @@ class Builder(object):
inst.set_volatile(volatile) inst.set_volatile(volatile)
return inst return inst
def gep(self, ptr, indices, name=""): def gep(self, ptr, indices, name="", inbounds=False):
check_is_value(ptr) check_is_value(ptr)
index_ptrs = unpack_values(indices) index_ptrs = unpack_values(indices)
return _make_value( if inbounds:
_core.LLVMBuildGEP(self.ptr, ptr.ptr, index_ptrs, name)) ret = _core.LLVMBuildInBoundsGEP(self.ptr, ptr.ptr, index_ptrs, name)
else:
ret = _core.LLVMBuildGEP(self.ptr, ptr.ptr, index_ptrs, name)
return _make_value(ret)
# casts and extensions # casts and extensions

View file

@ -818,8 +818,7 @@ class CDefinition(object):
if optimize: if optimize:
fpm = lp.FunctionPassManager.new(module) fpm = lp.FunctionPassManager.new(module)
pmb = lp.PassManagerBuilder.new() pmb = lp.PassManagerBuilder.new()
pmb.opt_level = 3 pmb.opt_level = 2
pmb.vectorize = True
pmb.populate(fpm) pmb.populate(fpm)
fpm.run(func) fpm.run(func)
@ -1135,11 +1134,11 @@ class PointerIndexing(OperatorMixin):
# Case #1: A[idx:] get pointer offset by idx # Case #1: A[idx:] get pointer offset by idx
if not idx.step and not idx.stop: if not idx.step and not idx.stop:
idx = _auto_coerce_index(self.parent, idx.start) idx = _auto_coerce_index(self.parent, idx.start)
ptr = bldr.gep(self.value, [idx.value]) ptr = bldr.gep(self.value, [idx.value], inbounds=True)
return CArray(self.parent, ptr) return CArray(self.parent, ptr)
else: # return an variable at idx else: # return an variable at idx
idx = _auto_coerce_index(self.parent, idx) idx = _auto_coerce_index(self.parent, idx)
ptr = bldr.gep(self.value, [idx.value]) ptr = bldr.gep(self.value, [idx.value], inbounds=True)
return CVar(self.parent, ptr) return CVar(self.parent, ptr)
def __setitem__(self, idx, val): def __setitem__(self, idx, val):
@ -1184,7 +1183,7 @@ class PointerValue(PointerIndexing, PointerCasting):
inst = self.parent.builder.store(val.value, self.value, **kws) inst = self.parent.builder.store(val.value, self.value, **kws)
if nontemporal: if nontemporal:
self.parent.set_memop_non_temporal(inst) self.parent.set_memop_non_temporal(inst)
return inst
def atomic_load(self, ordering, align=None, crossthread=True): def atomic_load(self, ordering, align=None, crossthread=True):
'''atomic load memory for pointer types '''atomic load memory for pointer types