Added vicmp, vfmp. Updated docs. Support FreeBSD.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@51 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-11-22 16:46:32 +00:00
commit 3bbc5685a8
11 changed files with 747 additions and 729 deletions

View file

@ -1,6 +1,9 @@
0,5, in progress:
0.5, 22-Nov-2008:
* Added vicmp, vfcmp instructions and constant expressions.
* Builds on FreeBSD.
* Updated documentation.
* Migrate to LLVM 2.4.

View file

@ -384,10 +384,8 @@ _wrap_objobj2obj(LLVMConstXor, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_intobjobj2obj(LLVMConstICmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_intobjobj2obj(LLVMConstFCmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
/* after LLVM 2.3!
_wrap_intobjobj2obj(LLVMConstVICmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_intobjobj2obj(LLVMConstVFCmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
*/
_wrap_objobj2obj(LLVMConstShl, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objobj2obj(LLVMConstLShr, LLVMValueRef, LLVMValueRef, LLVMValueRef)
@ -634,10 +632,8 @@ _wrap_objobjobjstr2obj(LLVMBuildBitCast, LLVMBuilderRef, LLVMValueRef, LLVMTypeR
_wrap_objintobjobjstr2obj(LLVMBuildICmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objintobjobjstr2obj(LLVMBuildFCmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
/* after LLVM 2.3!
_wrap_objintobjobjstr2obj(LLVMBuildVICmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objintobjobjstr2obj(LLVMBuildVFCmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
*/
/* Miscellaneous instructions */
@ -1113,10 +1109,8 @@ static PyMethodDef core_methods[] = {
_method( LLVMConstXor )
_method( LLVMConstICmp )
_method( LLVMConstFCmp )
/* after LLVM 2.3!
_method( LLVMConstVICmp )
_method( LLVMConstVFCmp )
*/
_method( LLVMConstShl )
_method( LLVMConstLShr )
_method( LLVMConstAShr )
@ -1296,10 +1290,8 @@ static PyMethodDef core_methods[] = {
/* Comparisons */
_method( LLVMBuildICmp )
_method( LLVMBuildFCmp )
/* after LLVM 2.3!
_method( LLVMBuildVICmp )
_method( LLVMBuildVFCmp )
*/
/* Miscellaneous instructions */
_method( LLVMBuildGetResult )

View file

@ -1481,14 +1481,13 @@ class Constant(Value):
check_is_constant(rhs)
return Constant(_core.LLVMConstFCmp(real_pred, self.ptr, rhs.ptr))
# after LLVM 2.3!
# def vicmp(self, int_pred, rhs):
# check_is_constant(rhs)
# return Constant(_core.LLVMConstVICmp(int_pred, self.ptr, rhs.ptr))
#
# def vfcmp(self, real_pred, rhs):
# check_is_constant(rhs)
# return Constant(_core.LLVMConstVFCmp(real_pred, self.ptr, rhs.ptr))
def vicmp(self, int_pred, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstVICmp(int_pred, self.ptr, rhs.ptr))
def vfcmp(self, real_pred, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstVFCmp(real_pred, self.ptr, rhs.ptr))
def shl(self, rhs):
check_is_constant(rhs)
@ -2168,16 +2167,15 @@ class Builder(object):
check_is_value(rhs)
return Value(_core.LLVMBuildFCmp(self.ptr, rpred, lhs.ptr, rhs.ptr, name))
# after LLVM 2.3!
# def vicmp(self, ipred, lhs, rhs, name=""):
# check_is_value(lhs)
# check_is_value(rhs)
# return Value(_core.LLVMBuildVICmp(self.ptr, ipred, lhs.ptr, rhs.ptr, name))
#
# def vfcmp(self, rpred, lhs, rhs, name=""):
# check_is_value(lhs)
# check_is_value(rhs)
# return Value(_core.LLVMBuildVFCmp(self.ptr, rpred, lhs.ptr, rhs.ptr, name))
def vicmp(self, ipred, lhs, rhs, name=""):
check_is_value(lhs)
check_is_value(rhs)
return Value(_core.LLVMBuildVICmp(self.ptr, ipred, lhs.ptr, rhs.ptr, name))
def vfcmp(self, rpred, lhs, rhs, name=""):
check_is_value(lhs)
check_is_value(rhs)
return Value(_core.LLVMBuildVFCmp(self.ptr, rpred, lhs.ptr, rhs.ptr, name))
# misc

View file

@ -99,6 +99,66 @@ char *LLVMDumpValueToString(LLVMValueRef value)
return do_print<LLVMValueRef, llvm::Value>(value);
}
LLVMValueRef LLVMConstVICmp(LLVMIntPredicate predicate, LLVMValueRef lhs,
LLVMValueRef rhs)
{
llvm::Constant *lhsp = llvm::unwrap<llvm::Constant>(lhs);
assert(lhsp);
llvm::Constant *rhsp = llvm::unwrap<llvm::Constant>(rhs);
assert(rhsp);
llvm::Constant *vicmp =
llvm::ConstantExpr::getVICmp(predicate, lhsp, rhsp);
return llvm::wrap(vicmp);
}
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate predicate, LLVMValueRef lhs,
LLVMValueRef rhs)
{
llvm::Constant *lhsp = llvm::unwrap<llvm::Constant>(lhs);
assert(lhsp);
llvm::Constant *rhsp = llvm::unwrap<llvm::Constant>(rhs);
assert(rhsp);
llvm::Constant *vfcmp =
llvm::ConstantExpr::getVFCmp(predicate, lhsp, rhsp);
return llvm::wrap(vfcmp);
}
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef builder, LLVMIntPredicate predicate,
LLVMValueRef lhs, LLVMValueRef rhs, const char *name)
{
llvm::IRBuilder<> *builderp = llvm::unwrap(builder);
assert(builderp);
llvm::Value *lhsp = llvm::unwrap(lhs);
assert(lhsp);
llvm::Value *rhsp = llvm::unwrap(rhs);
assert(rhsp);
llvm::Value *inst = builderp->CreateVICmp(
static_cast<llvm::CmpInst::Predicate>(predicate),
lhsp, rhsp, name);
return llvm::wrap(inst);
}
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef builder, LLVMRealPredicate predicate,
LLVMValueRef lhs, LLVMValueRef rhs, const char *name)
{
llvm::IRBuilder<> *builderp = llvm::unwrap(builder);
assert(builderp);
llvm::Value *lhsp = llvm::unwrap(lhs);
assert(lhsp);
llvm::Value *rhsp = llvm::unwrap(rhs);
assert(rhsp);
llvm::Value *inst = builderp->CreateVFCmp(
static_cast<llvm::CmpInst::Predicate>(predicate),
lhsp, rhsp, name);
return llvm::wrap(inst);
}
unsigned LLVMModuleGetPointerSize(LLVMModuleRef module)
{
llvm::Module *modulep = llvm::unwrap(module);

View file

@ -66,6 +66,22 @@ LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef bulder, LLVMValueRef *values,
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder, LLVMValueRef value,
unsigned index, const char *name);
/* Wraps llvm::ConstantExpr::getVICmp(). */
LLVMValueRef LLVMConstVICmp(LLVMIntPredicate predicate, LLVMValueRef lhs,
LLVMValueRef rhs);
/* Wraps llvm::ConstantExpr::getVFCmp(). */
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate predicate, LLVMValueRef lhs,
LLVMValueRef rhs);
/* Wraps llvm::IRBuilder::CreateVICmp(). */
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef builder, LLVMIntPredicate predicate,
LLVMValueRef lhs, LLVMValueRef rhs, const char *name);
/* Wraps llvm::IRBuilder::CreateVFCmp(). */
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef builder, LLVMRealPredicate predicate,
LLVMValueRef lhs, LLVMValueRef rhs, const char *name);
/* Wraps llvm::Intrinsic::getDeclaration(). */
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef builder, int id,
LLVMTypeRef *types, unsigned n_types);

View file

@ -86,7 +86,7 @@ def call_setup(llvm_config):
'asmparser' ])
std_libs = [ 'pthread', 'm' ]
if not sys.platform.startswith("openbsd"):
if not ("openbsd" in sys.platform or "freebsd" in sys.platform):
std_libs.append("dl")
ext_core = Extension(

View file

@ -187,9 +187,8 @@ def do_constant():
f.fdiv(f).frem(f).fcmp(RPRED_ULT, f)
vi = Constant.vector([Constant.int(ti,42)]*10)
vf = Constant.vector([Constant.real(Type.float(), 3.14)]*10)
# after LLVM 2.3!
#vi.vicmp(IPRED_ULT, vi)
#vf.vfcmp(RPRED_ULT, vf)
vi.vicmp(IPRED_ULT, vi)
vf.vfcmp(RPRED_ULT, vf)
k.shl(k).lshr(k).ashr(k)
# TODO gep
k.trunc(Type.int(1))
@ -430,9 +429,8 @@ def do_builder():
b.fcmp(RPRED_ULT, fv, fv)
vi = Constant.vector([Constant.int(ti,42)]*10)
vf = Constant.vector([Constant.real(Type.float(), 3.14)]*10)
# after LLVM 2.3!
# b.vicmp(IPRED_ULT, vi, vi)
# b.vfcmp(RPRED_ULT, vf, vf)
b.vicmp(IPRED_ULT, vi, vi)
b.vfcmp(RPRED_ULT, vf, vf)
# TODO b.getresult(v, 0)
b.call(f, [v])
b.select(Constant.int(Type.int(1), 1), blk, blk)

View file

@ -12,18 +12,16 @@ llvm-py is just hatching. It should be stable enough to start hacking
away, though. Be sure to send in a patch if you miss any specific LLVM
API.
_Availability_: llvm-py is available (as a source package) for LLVM 2.3
and Python 2.5. It has been built and tested on Linux (x86, amd64) and
is reported to work with OpenBSD. It is expected to be usable on
various unices, as well as with Python 2.4.
_LLVM 2.4_: Read link:userguide.html#llvm24[this] if you're using LLVM
2.4!
_Availability_: llvm-py is available (as a source package) for LLVM 2.4
and Python 2.5. It has been built and tested on Linux and FreeBSD
(x86 and amd64).
News
----
22-Nov-2008::
0.5 released. For LLVM 2.4.
21-Nov-2008::
0.4 released. Bug fixes, few additional APIs, code cleanup.

View file

@ -31,8 +31,8 @@ and OpenBSD (i386, amd64). However, it should be trivial to build it on
other unices. Windows is not supported, for a variety of reasons.
.Versions
llvm-py requires verion 2.3 of LLVM. It will not work with previous
versions. If you're using LLVM 2.4, see link:#llvm24[below].
llvm-py 0.5 requires verion 2.4 of LLVM. It will not work with previous
versions.
llvm-py has been built and tested with Python 2.5. It should work with
Python 2.4, with minimal changes, if any.
@ -60,8 +60,6 @@ It does not matter which compiler LLVM itself was built with (g\+\+,
llvm-g\+\+ or any other); llvm-py can be built with any compiler. It has
been tried only with gcc/g\+\+ though.
Tip: If LLVM 2.3 does not install cleanly, try installing ``ocamldoc''
first.
LLVM and `--enable-pic`
~~~~~~~~~~~~~~~~~~~~~~~
@ -75,7 +73,7 @@ independent code). Be sure to use the `--enable-pic` option while
configuring LLVM (default is no PIC), like this:
----
~/llvm-2.3$ ./configure --enable-pic --enable-optimized
~/llvm-2.4$ ./configure --enable-pic --enable-optimized
----
@ -106,8 +104,8 @@ If you have +llvm-config+ in your path, you can build and install
llvm-py this way:
-----------------------------------------------------------------------
$ tar jxvf llvm-py-0.3.tar.bz2
$ cd llvm-py-0.3
$ tar jxvf llvm-py-0.5.tar.bz2
$ cd llvm-py-0.5
$ sudo python setup.py install
-----------------------------------------------------------------------
@ -115,8 +113,8 @@ If you need to tell the build script where +llvm-config+ is, do it this
way:
-----------------------------------------------------------------------
$ tar jxvf llvm-py-0.3.tar.bz2
$ cd llvm-py-0.3
$ tar jxvf llvm-py-0.5.tar.bz2
$ cd llvm-py-0.5
$ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Release/bin/llvm-config
-----------------------------------------------------------------------
@ -124,8 +122,8 @@ To build a debug version of llvm-py, that links against the debug
libraries of LLVM, use this:
-----------------------------------------------------------------------
$ tar jxvf llvm-py-0.3.tar.bz2
$ cd llvm-py-0.3
$ tar jxvf llvm-py-0.5.tar.bz2
$ cd llvm-py-0.5
$ python setup.py build -g --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config
$ sudo python setup.py install --llvm-config=/home/mdevan/llvm/Debug/bin/llvm-config
-----------------------------------------------------------------------
@ -139,35 +137,6 @@ Python Modules] and http://docs.python.org/dist/dist.html[Distributing
Python Modules] for more information on such scripts.
[[llvm24]]
LLVM 2.4
~~~~~~~~
LLVM 2.4 is currently in progress. There are incompatible API changes
from LLVM 2.3. The latest release of llvm-py will _not_ compile against
it.
The llvm-py SVN has a branch called
http://code.google.com/p/llvm-py/source/browse/#svn/branches/llvm2.4[llvm2.4],
which attempts to track the changes happening in LLVM 2.4. There are
however, some caveats:
- There are no releases from this branch.
- When LLVM 2.4 is released, then these changes will be merged to main.
From then on llvm-py will support LLVM 2.4 and no longer LLVM 2.3.
- This branch is not religiously kept up-to-date with the changes
happening in LLVM SVN. Therefore, it may not work for you, but might
still be worth a try.
llvm-py can be checked out from this branch like this:
-----------------------------------------------------------------------
$ svn co http://llvm-py.googlecode.com/svn/branches/llvm2.4 llvm-py-2.4
-----------------------------------------------------------------------
The rest of the steps (build, install) remain the same as before.
[[uninstall]]
Uninstall
~~~~~~~~~
@ -1378,28 +1347,30 @@ in `llvm.core`. These are:
[frame="all",grid="all"]
`33`33`33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INTR_ANNOTATION,INTR_DBG_STOPPOINT,INTR_MEMSET_I64
INTR_ARM_THREAD_POINTER,INTR_EH_DWARF_CFA,INTR_PART_SELECT
INTR_ATOMIC_LAS,INTR_EH_EXCEPTION,INTR_PART_SET
INTR_ATOMIC_LCS,INTR_EH_RETURN,INTR_PCMARKER
INTR_ATOMIC_LOAD_AND,INTR_EH_SELECTOR_I32,INTR_POW
INTR_ATOMIC_LOAD_MAX,INTR_EH_SELECTOR_I64,INTR_POWI
INTR_ATOMIC_LOAD_MIN,INTR_EH_TYPEID_FOR_I32,INTR_PREFETCH
INTR_ATOMIC_LOAD_OR,INTR_EH_TYPEID_FOR_I64,INTR_READCYCLECOUNTER
INTR_ATOMIC_LOAD_UMAX,INTR_EH_UNWIND_INIT,INTR_RETURNADDRESS
INTR_ATOMIC_LOAD_UMIN,INTR_FLT_ROUNDS,INTR_SETJMP
INTR_ATOMIC_LOAD_XOR,INTR_FRAMEADDRESS,INTR_SIGLONGJMP
INTR_ATOMIC_LSS,INTR_GCREAD,INTR_SIGSETJMP
INTR_ATOMIC_SWAP,INTR_GCROOT,INTR_SIN
INTR_BSWAP,INTR_GCWRITE,INTR_SQRT
INTR_COS,INTR_INIT_TRAMPOLINE,INTR_STACKRESTORE
INTR_CTLZ,INTR_LONGJMP,INTR_STACKSAVE
INTR_CTPOP,INTR_MEMCPY_I32,INTR_TRAP
INTR_CTTZ,INTR_MEMCPY_I64,INTR_VACOPY
INTR_DBG_DECLARE,INTR_MEMMOVE_I32,INTR_VAEND
INTR_DBG_FUNC_START,INTR_MEMMOVE_I64,INTR_VAR_ANNOTATION
INTR_DBG_REGION_END,INTR_MEMORY_BARRIER,INTR_VASTART
INTR_DBG_REGION_START,INTR_MEMSET_I32,
INTR_ANNOTATION,INTR_ATOMIC_CMP_SWAP,INTR_ATOMIC_LOAD_ADD
INTR_ATOMIC_LOAD_AND,INTR_ATOMIC_LOAD_MAX,INTR_ATOMIC_LOAD_MIN
INTR_ATOMIC_LOAD_NAND,INTR_ATOMIC_LOAD_OR,INTR_ATOMIC_LOAD_SUB
INTR_ATOMIC_LOAD_UMAX,INTR_ATOMIC_LOAD_UMIN,INTR_ATOMIC_LOAD_XOR
INTR_ATOMIC_SWAP,INTR_BSWAP,INTR_COS
INTR_CTLZ,INTR_CTPOP,INTR_CTTZ
INTR_DBG_DECLARE,INTR_DBG_FUNC_START,INTR_DBG_REGION_END
INTR_DBG_REGION_START,INTR_DBG_STOPPOINT,INTR_EH_DWARF_CFA
INTR_EH_EXCEPTION,INTR_EH_RETURN_I32,INTR_EH_RETURN_I64
INTR_EH_SELECTOR_I32,INTR_EH_SELECTOR_I64,INTR_EH_TYPEID_FOR_I32
INTR_EH_TYPEID_FOR_I64,INTR_EH_UNWIND_INIT,INTR_EXP
INTR_EXP2,INTR_FLT_ROUNDS,INTR_FRAMEADDRESS
INTR_GCREAD,INTR_GCROOT,INTR_GCWRITE
INTR_INIT_TRAMPOLINE,INTR_LOG,INTR_LOG10
INTR_LOG2,INTR_LONGJMP,INTR_MEMCPY_I32
INTR_MEMCPY_I64,INTR_MEMMOVE_I32,INTR_MEMMOVE_I64
INTR_MEMORY_BARRIER,INTR_MEMSET_I32,INTR_MEMSET_I64
INTR_PART_SELECT,INTR_PART_SET,INTR_PCMARKER
INTR_POW,INTR_POWI,INTR_PREFETCH
INTR_READCYCLECOUNTER,INTR_RETURNADDRESS,INTR_SETJMP
INTR_SIGLONGJMP,INTR_SIGSETJMP,INTR_SIN
INTR_SQRT,INTR_STACKRESTORE,INTR_STACKSAVE
INTR_TRAP,INTR_VACOPY,INTR_VAEND
INTR_VAR_ANNOTATION,INTR_VASTART,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are also target-specific intrinsics (which correspond to that

View file

@ -42,18 +42,23 @@ Boost.Python, swig etc.</p></div>
<div class="para"><p>llvm-py is just hatching. It should be stable enough to start hacking
away, though. Be sure to send in a patch if you miss any specific LLVM
API.</p></div>
<div class="para"><p><em>Availability</em>: llvm-py is available (as a source package) for LLVM 2.3
and Python 2.5. It has been built and tested on Linux (x86, amd64) and
is reported to work with OpenBSD. It is expected to be usable on
various unices, as well as with Python 2.4.</p></div>
<div class="para"><p><em>LLVM 2.4</em>: Read <a href="userguide.html#llvm24">this</a> if you're using LLVM
2.4!</p></div>
<div class="para"><p><em>Availability</em>: llvm-py is available (as a source package) for LLVM 2.4
and Python 2.5. It has been built and tested on Linux and FreeBSD
(x86 and amd64).</p></div>
</div>
</div>
<h2 id="_news">News</h2>
<div class="sectionbody">
<div class="vlist"><dl>
<dt>
22-Nov-2008
</dt>
<dd>
<p>
0.5 released. For LLVM 2.4.
</p>
</dd>
<dt>
21-Nov-2008
</dt>
<dd>
@ -98,7 +103,7 @@ various unices, as well as with Python 2.4.</p></div>
<div id="footer">
<div id="footer-text">
Web pages &copy; Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
Last updated 2008-11-21.
Last updated 2008-11-22.
</div>
</div>
</div>

File diff suppressed because it is too large Load diff