Migrated to LLVM 2.4.
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@50 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
09e1748a19
commit
95cef74480
9 changed files with 699 additions and 634 deletions
|
|
@ -1,4 +1,9 @@
|
|||
|
||||
0,5, in progress:
|
||||
|
||||
* Migrate to LLVM 2.4.
|
||||
|
||||
|
||||
0.4, 21-Nov-2008:
|
||||
|
||||
* Code cleanup, added license headers.
|
||||
|
|
|
|||
12
README
12
README
|
|
@ -12,21 +12,19 @@ Home page:
|
|||
|
||||
Versions:
|
||||
---------
|
||||
|
||||
This package will work only with LLVM 2.3 release version. If you need llvm-py
|
||||
for the in-progress LLVM version (2.4), you've to get llvm-py from the SVN
|
||||
repository -- see the website for more details.
|
||||
This package will work only with LLVM 2.4 release version. If you need
|
||||
llvm-py for LLVM 2.3, use the 0.4 version of llvm-py.
|
||||
|
||||
|
||||
Quickstart:
|
||||
-----------
|
||||
1. Get 2.3 version of LLVM, build it. Make sure '--enable-pic' is passed to
|
||||
1. Get 2.4 version of LLVM, build it. Make sure '--enable-pic' is passed to
|
||||
LLVM's 'configure'.
|
||||
|
||||
2. Unpack llvm-py, build and install:
|
||||
|
||||
$ tar jxvf llvm-py-0.4.tar.bz2
|
||||
$ cd llvm-py-0.4
|
||||
$ tar jxvf llvm-py-0.5.tar.bz2
|
||||
$ cd llvm-py-0.5
|
||||
# Locate llvm-config, usually under <llvm>/Release/bin
|
||||
$ sudo python setup.py install --llvm-config=/path/to/llvm-config
|
||||
|
||||
|
|
|
|||
32
llvm/_core.c
32
llvm/_core.c
|
|
@ -453,8 +453,8 @@ _wrap_obj2none(LLVMDeleteFunction, LLVMValueRef)
|
|||
_wrap_obj2obj(LLVMGetIntrinsicID, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMGetFunctionCallConv, LLVMValueRef, int)
|
||||
_wrap_objint2none(LLVMSetFunctionCallConv, LLVMValueRef)
|
||||
_wrap_obj2str(LLVMGetCollector, LLVMValueRef)
|
||||
_wrap_objstr2none(LLVMSetCollector, LLVMValueRef)
|
||||
_wrap_obj2str(LLVMGetGC, LLVMValueRef)
|
||||
_wrap_objstr2none(LLVMSetGC, LLVMValueRef)
|
||||
_wrap_obj2none(LLVMViewFunctionCFG, LLVMValueRef)
|
||||
_wrap_obj2none(LLVMViewFunctionCFGOnly, LLVMValueRef)
|
||||
|
||||
|
|
@ -476,8 +476,8 @@ _wrap_obj2obj(LLVMCountParams, LLVMValueRef, int)
|
|||
_wrap_obj2obj(LLVMGetFirstParam, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_obj2obj(LLVMGetNextParam, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_obj2obj(LLVMGetParamParent, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objint2none(LLVMAddParamAttr, LLVMValueRef)
|
||||
_wrap_objint2none(LLVMRemoveParamAttr, LLVMValueRef)
|
||||
_wrap_objint2none(LLVMAddAttribute, LLVMValueRef)
|
||||
_wrap_objint2none(LLVMRemoveAttribute, LLVMValueRef)
|
||||
_wrap_objint2none(LLVMSetParamAlignment, LLVMValueRef)
|
||||
|
||||
/*===-- Basic Blocks -----------------------------------------------------===*/
|
||||
|
|
@ -513,8 +513,8 @@ _wrap_obj2str(LLVMInstGetOpcodeName, LLVMValueRef)
|
|||
|
||||
_wrap_objint2none(LLVMSetInstructionCallConv, LLVMValueRef)
|
||||
_wrap_obj2obj(LLVMGetInstructionCallConv, LLVMValueRef, int)
|
||||
_wrap_objintint2none(LLVMAddInstrParamAttr, LLVMValueRef)
|
||||
_wrap_objintint2none(LLVMRemoveInstrParamAttr, LLVMValueRef)
|
||||
_wrap_objintint2none(LLVMAddInstrAttribute, LLVMValueRef)
|
||||
_wrap_objintint2none(LLVMRemoveInstrAttribute, LLVMValueRef)
|
||||
_wrap_objintint2none(LLVMSetInstrParamAlignment, LLVMValueRef)
|
||||
|
||||
/*===-- PHI Nodes --------------------------------------------------------===*/
|
||||
|
|
@ -737,7 +737,7 @@ _wrap_pass( DeadArgElimination )
|
|||
_wrap_pass( DeadTypeElimination )
|
||||
_wrap_pass( DeadInstElimination )
|
||||
_wrap_pass( DeadStoreElimination )
|
||||
_wrap_pass( GCSE )
|
||||
/* _wrap_pass( GCSE ): removed in LLVM 2.4. */
|
||||
_wrap_pass( GlobalDCE )
|
||||
_wrap_pass( GlobalOptimizer )
|
||||
_wrap_pass( GVN )
|
||||
|
|
@ -837,7 +837,7 @@ _wLLVMCreateExecutionEngine(PyObject *self, PyObject *args)
|
|||
if (force_interpreter)
|
||||
error = LLVMCreateInterpreter(&ee, mp, &outmsg);
|
||||
else
|
||||
error = LLVMCreateJITCompiler(&ee, mp, &outmsg);
|
||||
error = LLVMCreateJITCompiler(&ee, mp, 1 /*fast*/, &outmsg);
|
||||
|
||||
if (error) {
|
||||
ret = PyString_FromString(outmsg);
|
||||
|
|
@ -1174,9 +1174,9 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMDeleteFunction )
|
||||
_method( LLVMGetIntrinsicID )
|
||||
_method( LLVMGetFunctionCallConv )
|
||||
_method( LLVMSetFunctionCallConv )
|
||||
_method( LLVMGetCollector )
|
||||
_method( LLVMSetCollector )
|
||||
_method( LLVMSetFunctionCallConv )
|
||||
_method( LLVMGetGC )
|
||||
_method( LLVMSetGC )
|
||||
_method( LLVMVerifyFunction )
|
||||
_method( LLVMViewFunctionCFG )
|
||||
_method( LLVMViewFunctionCFGOnly )
|
||||
|
|
@ -1186,8 +1186,8 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMGetFirstParam )
|
||||
_method( LLVMGetNextParam )
|
||||
_method( LLVMGetParamParent )
|
||||
_method( LLVMAddParamAttr )
|
||||
_method( LLVMRemoveParamAttr )
|
||||
_method( LLVMAddAttribute )
|
||||
_method( LLVMRemoveAttribute )
|
||||
_method( LLVMSetParamAlignment )
|
||||
|
||||
/* Basic Blocks */
|
||||
|
|
@ -1219,8 +1219,8 @@ static PyMethodDef core_methods[] = {
|
|||
/* Call Sites (Call or Invoke) */
|
||||
_method( LLVMSetInstructionCallConv )
|
||||
_method( LLVMGetInstructionCallConv )
|
||||
_method( LLVMAddInstrParamAttr )
|
||||
_method( LLVMRemoveInstrParamAttr )
|
||||
_method( LLVMAddInstrAttribute )
|
||||
_method( LLVMRemoveInstrAttribute )
|
||||
_method( LLVMSetInstrParamAlignment )
|
||||
|
||||
/* PHI Nodes */
|
||||
|
|
@ -1343,7 +1343,7 @@ static PyMethodDef core_methods[] = {
|
|||
_pass( DeadTypeElimination )
|
||||
_pass( DeadInstElimination )
|
||||
_pass( DeadStoreElimination )
|
||||
_pass( GCSE )
|
||||
/* _pass( GCSE ): removed in LLVM 2.4. */
|
||||
_pass( GlobalDCE )
|
||||
_pass( GlobalOptimizer )
|
||||
_pass( GVN )
|
||||
|
|
|
|||
1204
llvm/core.py
1204
llvm/core.py
File diff suppressed because it is too large
Load diff
|
|
@ -82,7 +82,11 @@ char *do_print(W obj)
|
|||
|
||||
char *LLVMDumpModuleToString(LLVMModuleRef module)
|
||||
{
|
||||
return do_print<LLVMModuleRef, llvm::Module>(module);
|
||||
std::ostringstream buf;
|
||||
llvm::Module *p = llvm::unwrap(module);
|
||||
assert(p);
|
||||
p->print(buf, NULL);
|
||||
return strdup(buf.str().c_str());
|
||||
}
|
||||
|
||||
char *LLVMDumpTypeToString(LLVMTypeRef type)
|
||||
|
|
@ -123,6 +127,14 @@ LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef module,
|
|||
return wrap(f);
|
||||
}
|
||||
|
||||
int LLVMHasInitializer(LLVMValueRef global_var)
|
||||
{
|
||||
llvm::GlobalVariable *gvp = llvm::unwrap<llvm::GlobalVariable>(global_var);
|
||||
assert(gvp);
|
||||
|
||||
return gvp->hasInitializer();
|
||||
}
|
||||
|
||||
#define inst_checkfn(ourfn, llvmfn) \
|
||||
unsigned ourfn (LLVMValueRef v) { \
|
||||
llvm::Instruction *ip = llvm::unwrap<llvm::Instruction>(v); \
|
||||
|
|
@ -191,10 +203,10 @@ LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef builder,
|
|||
std::vector<llvm::Value *> values_vec;
|
||||
unwrap_vec(values, n_values, values_vec);
|
||||
|
||||
llvm::IRBuilder *builderp = llvm::unwrap(builder);
|
||||
llvm::IRBuilder<> *builderp = llvm::unwrap(builder);
|
||||
assert(builderp);
|
||||
|
||||
return wrap(builderp->CreateRet(&values_vec[0], values_vec.size()));
|
||||
return llvm::wrap(builderp->CreateAggregateRet(&values_vec[0], values_vec.size()));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder,
|
||||
|
|
@ -202,10 +214,10 @@ LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder,
|
|||
{
|
||||
assert(name);
|
||||
|
||||
llvm::IRBuilder *builderp = llvm::unwrap(builder);
|
||||
llvm::IRBuilder<> *builderp = llvm::unwrap(builder);
|
||||
assert(builderp);
|
||||
|
||||
return wrap(builderp->CreateGetResult(llvm::unwrap(value), index, name));
|
||||
return llvm::wrap(builderp->CreateExtractValue(llvm::unwrap(value), index, name));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef module, int id,
|
||||
|
|
@ -333,7 +345,7 @@ define_pass( DeadArgElimination )
|
|||
define_pass( DeadTypeElimination )
|
||||
define_pass( DeadInstElimination )
|
||||
define_pass( DeadStoreElimination )
|
||||
define_pass( GCSE )
|
||||
/* define_pass( GCSE ): removed in LLVM 2.4 */
|
||||
define_pass( GlobalDCE )
|
||||
define_pass( GlobalOptimizer )
|
||||
define_pass( GVNPRE )
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@ unsigned LLVMModuleGetPointerSize(LLVMModuleRef module);
|
|||
LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef module,
|
||||
const char *name, LLVMTypeRef function_type);
|
||||
|
||||
/* Wraps llvm::GlobalVariable::hasInitializer(). */
|
||||
int LLVMHasInitializer(LLVMValueRef global_var);
|
||||
|
||||
/* The following functions wrap various llvm::Instruction::isXXX() functions.
|
||||
* All of them take an instruction and return 0 (isXXX returned false) or 1
|
||||
* (isXXX returned false). */
|
||||
|
|
@ -143,7 +146,7 @@ declare_pass( DeadArgElimination )
|
|||
declare_pass( DeadTypeElimination )
|
||||
declare_pass( DeadInstElimination )
|
||||
declare_pass( DeadStoreElimination )
|
||||
declare_pass( GCSE )
|
||||
/* declare_pass( GCSE ): removed in LLVM 2.4. */
|
||||
declare_pass( GlobalDCE )
|
||||
declare_pass( GlobalOptimizer )
|
||||
declare_pass( GVNPRE )
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ PASS_DEAD_ARG_ELIMINATION = 10
|
|||
PASS_DEAD_TYPE_ELIMINATION = 11
|
||||
PASS_DEAD_INST_ELIMINATION = 12
|
||||
PASS_DEAD_STORE_ELIMINATION = 13
|
||||
PASS_GCSE = 14
|
||||
# PASS_GCSE = 14: removed in LLVM 2.4
|
||||
PASS_GLOBAL_DCE = 15
|
||||
PASS_GLOBAL_OPTIMIZER = 16
|
||||
PASS_GVN = 17
|
||||
|
|
@ -127,7 +127,7 @@ _pass_creator = {
|
|||
PASS_DEAD_TYPE_ELIMINATION : _core.LLVMAddDeadTypeEliminationPass,
|
||||
PASS_DEAD_INST_ELIMINATION : _core.LLVMAddDeadInstEliminationPass,
|
||||
PASS_DEAD_STORE_ELIMINATION : _core.LLVMAddDeadStoreEliminationPass,
|
||||
PASS_GCSE : _core.LLVMAddGCSEPass,
|
||||
# PASS_GCSE : _core.LLVMAddGCSEPass,: removed in LLVM 2.4.
|
||||
PASS_GLOBAL_DCE : _core.LLVMAddGlobalDCEPass,
|
||||
PASS_GLOBAL_OPTIMIZER : _core.LLVMAddGlobalOptimizerPass,
|
||||
PASS_GVN : _core.LLVMAddGVNPass,
|
||||
|
|
|
|||
31
setup.py
31
setup.py
|
|
@ -1,9 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2008, Mahadevan R All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of this software, nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
import sys, os
|
||||
from distutils.core import setup, Extension
|
||||
|
||||
LLVM_PY_VERSION = '0.4'
|
||||
LLVM_PY_VERSION = '0.5'
|
||||
|
||||
|
||||
def _run(cmd):
|
||||
|
|
|
|||
|
|
@ -351,6 +351,19 @@ def do_basicblock():
|
|||
# ^ not working yet!
|
||||
|
||||
|
||||
def _do_builder_mrv():
|
||||
m = Module.new('mrv')
|
||||
ft = Type.function(Type.array(ti, 2), [ti])
|
||||
f = Function.new(m, ft, 'divrem')
|
||||
blk = f.append_basic_block('b')
|
||||
b = Builder.new(blk)
|
||||
v = b.call(f, [Constant.int(ti, 1)])
|
||||
v1 = b.getresult(v, 0)
|
||||
v2 = b.getresult(v, 1)
|
||||
b.ret_many([v1, v2])
|
||||
#print f
|
||||
|
||||
|
||||
def do_builder():
|
||||
print " Testing class Builder"
|
||||
m = Module.new('a')
|
||||
|
|
@ -365,7 +378,8 @@ def do_builder():
|
|||
blk2 = b.block
|
||||
b.ret_void()
|
||||
b.ret(Constant.int(ti, 10))
|
||||
b.ret_many([Constant.int(ti, 10)]*10)
|
||||
_do_builder_mrv()
|
||||
#b.ret_many([Constant.int(ti, 10)]*10)
|
||||
b.branch(blk)
|
||||
b.cbranch(Constant.int(Type.int(1), 1), blk, blk)
|
||||
b.switch(f.args[0], blk)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue