Added tests for bitcode.

Updated CHANGELOG, inline docs.
Switched to absolute imports.
Added all passes to extra.{cpp,h}\!

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@31 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-08-11 14:21:16 +00:00
commit fc3f11d899
10 changed files with 219 additions and 14 deletions

View file

@ -1,5 +1,7 @@
0.3, in progress: 0.3, in progress:
* Various bug fixes.
* Bitcode support: convert modules to bitcode and vice versa.
* Intrinsics added. * Intrinsics added.
* JIT Tutorials ported (Sebastien Binet). * JIT Tutorials ported (Sebastien Binet).
* GenericValue added. Used by ExecutionEngine.run(). * GenericValue added. Used by ExecutionEngine.run().

13
README
View file

@ -10,9 +10,18 @@ Home page:
http://mdevan.nfshost.com/llvm-py/ http://mdevan.nfshost.com/llvm-py/
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.
Quickstart: Quickstart:
---------- -----------
1. Get 2.3 version of LLVM, build it. 2.2 or earlier will *not* work. 1. Get 2.3 version of LLVM, build it. Make sure '--enable-pic' is passed to
LLVM's 'configure'.
2. Unpack llvm-py, build and install: 2. Unpack llvm-py, build and install:

View file

@ -2,13 +2,15 @@
""" """
VERSION = '0.2' VERSION = '0.3'
#===----------------------------------------------------------------------=== #===----------------------------------------------------------------------===
# Exceptions # Exceptions
#===----------------------------------------------------------------------=== #===----------------------------------------------------------------------===
class LLVMException(Exception): class LLVMException(Exception):
"""Generic LLVM exception."""
def __init__(self, msg=""): def __init__(self, msg=""):
Exception.__init__(self, msg) Exception.__init__(self, msg)
@ -19,6 +21,13 @@ class LLVMException(Exception):
#===----------------------------------------------------------------------=== #===----------------------------------------------------------------------===
class Ownable(object): class Ownable(object):
"""Objects that can be owned.
Modules and Module Providers can be owned, i.e., the responsibility of
destruction of ownable objects can be handed over to other objects. The
llvm.Ownable class represents objects that can be so owned. This class
is NOT intended for public use.
"""
def __init__(self, ptr, del_fn): def __init__(self, ptr, del_fn):
self.ptr = ptr self.ptr = ptr

View file

@ -2,7 +2,7 @@
Used only in other modules, not for public use.""" Used only in other modules, not for public use."""
import core import llvm.core as core
import llvm import llvm

View file

@ -5,8 +5,8 @@ in-memory intermediate representation (IR) data structures."""
import llvm # top-level, for common stuff import llvm # top-level, for common stuff
import _core # C wrappers import llvm._core as _core # C wrappers
from _util import * # utility functions from llvm._util import * # utility functions
#===----------------------------------------------------------------------=== #===----------------------------------------------------------------------===

View file

@ -3,9 +3,9 @@
""" """
import llvm # top-level, for common stuff import llvm # top-level, for common stuff
import core # module provider, function etc. import llvm.core as core # module provider, function etc.
import _core # C wrappers import llvm._core as _core # C wrappers
from _util import * # utility functions from llvm._util import * # utility functions
#===----------------------------------------------------------------------=== #===----------------------------------------------------------------------===

View file

@ -20,6 +20,14 @@
#include "llvm/Support/CallSite.h" #include "llvm/Support/CallSite.h"
#include "llvm/IntrinsicInst.h" #include "llvm/IntrinsicInst.h"
#include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Verifier.h"
// +includes for passes
#include "llvm/PassManager.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
#include "llvm/Transforms/Instrumentation.h"
// -includes for passes
#include "llvm-c/Core.h" #include "llvm-c/Core.h"
@ -131,3 +139,77 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len)
*Len = len; *Len = len;
return bytes; return bytes;
} }
/* passes */
#define define_pass(P) \
void LLVMAdd ## P ## Pass (LLVMPassManagerRef PM) { \
unwrap(PM)->add( create ## P ## Pass ()); \
}
define_pass( AggressiveDCE )
define_pass( ArgumentPromotion )
define_pass( BlockPlacement )
define_pass( BreakCriticalEdges )
define_pass( CodeGenPrepare )
define_pass( CondPropagation )
define_pass( ConstantMerge )
//LLVM-C define_pass( ConstantPropagation )
define_pass( DeadCodeElimination )
define_pass( DeadArgElimination )
define_pass( DeadTypeElimination )
define_pass( DeadInstElimination )
define_pass( DeadStoreElimination )
define_pass( GCSE )
define_pass( GlobalDCE )
define_pass( GlobalOptimizer )
//LLVM-C define_pass( GVN )
define_pass( GVNPRE )
define_pass( IndMemRem )
define_pass( IndVarSimplify )
define_pass( FunctionInlining )
define_pass( BlockProfiler )
define_pass( EdgeProfiler )
define_pass( FunctionProfiler )
define_pass( NullProfilerRS )
define_pass( RSProfiling )
//LLVM-C define_pass( InstructionCombining )
/* we support only internalize(true) */
ModulePass *createInternalizePass() { return llvm::createInternalizePass(true); }
define_pass( Internalize )
define_pass( IPConstantPropagation )
define_pass( IPSCCP )
define_pass( JumpThreading )
define_pass( LCSSA )
define_pass( LICM )
define_pass( LoopDeletion )
define_pass( LoopExtractor )
define_pass( SingleLoopExtractor )
define_pass( LoopIndexSplit )
define_pass( LoopStrengthReduce )
define_pass( LoopRotate )
define_pass( LoopUnroll )
define_pass( LoopUnswitch )
define_pass( LoopSimplify )
define_pass( LowerAllocations )
define_pass( LowerInvoke )
define_pass( LowerSetJmp )
define_pass( LowerSwitch )
//LLVM-C define_pass( PromoteMemoryToRegister )
define_pass( MemCpyOpt )
define_pass( UnifyFunctionExitNodes )
define_pass( PredicateSimplifier )
define_pass( PruneEH )
define_pass( RaiseAllocations )
//LLVM-C define_pass( Reassociate )
define_pass( DemoteRegisterToMemory )
define_pass( ScalarReplAggregates )
define_pass( SCCP )
define_pass( SimplifyLibCalls )
//LLVM-C define_pass( CFGSimplification )
define_pass( StripSymbols )
define_pass( StripDeadPrototypes )
define_pass( StructRetPromotion )
define_pass( TailCallElimination )
define_pass( TailDuplication )

View file

@ -46,13 +46,86 @@ LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef, LLVMValueRef *Values,
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef, LLVMValueRef V, LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef, LLVMValueRef V,
unsigned Index, const char *Name); unsigned Index, const char *Name);
/* intrinsics */
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef B, int ID, LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef B, int ID,
LLVMTypeRef *Types, unsigned Count); LLVMTypeRef *Types, unsigned Count);
/* bitcode related */
LLVMModuleRef LLVMGetModuleFromBitcode(const char *BC, unsigned Len, LLVMModuleRef LLVMGetModuleFromBitcode(const char *BC, unsigned Len,
char **OutMessage); char **OutMessage);
unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len); unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len);
/* passes */
#define declare_pass(P) \
void LLVMAdd ## P ## Pass (LLVMPassManagerRef PM);
declare_pass( AggressiveDCE )
declare_pass( ArgumentPromotion )
declare_pass( BlockPlacement )
declare_pass( BreakCriticalEdges )
declare_pass( CodeGenPrepare )
declare_pass( CondPropagation )
declare_pass( ConstantMerge )
//LLVM-C declare_pass( ConstantPropagation )
declare_pass( DeadCodeElimination )
declare_pass( DeadArgElimination )
declare_pass( DeadTypeElimination )
declare_pass( DeadInstElimination )
declare_pass( DeadStoreElimination )
declare_pass( GCSE )
declare_pass( GlobalDCE )
declare_pass( GlobalOptimizer )
//LLVM-C declare_pass( GVN )
declare_pass( GVNPRE )
declare_pass( IndMemRem )
declare_pass( IndVarSimplify )
declare_pass( FunctionInlining )
declare_pass( BlockProfiler )
declare_pass( EdgeProfiler )
declare_pass( FunctionProfiler )
declare_pass( NullProfilerRS )
declare_pass( RSProfiling )
//LLVM-C declare_pass( InstructionCombining )
declare_pass( Internalize )
declare_pass( IPConstantPropagation )
declare_pass( IPSCCP )
declare_pass( JumpThreading )
declare_pass( LCSSA )
declare_pass( LICM )
declare_pass( LoopDeletion )
declare_pass( LoopExtractor )
declare_pass( SingleLoopExtractor )
declare_pass( LoopIndexSplit )
declare_pass( LoopStrengthReduce )
declare_pass( LoopRotate )
declare_pass( LoopUnroll )
declare_pass( LoopUnswitch )
declare_pass( LoopSimplify )
declare_pass( LowerAllocations )
declare_pass( LowerInvoke )
declare_pass( LowerSetJmp )
declare_pass( LowerSwitch )
//LLVM-C declare_pass( PromoteMemoryToRegister )
declare_pass( MemCpyOpt )
declare_pass( UnifyFunctionExitNodes )
declare_pass( PredicateSimplifier )
declare_pass( PruneEH )
declare_pass( RaiseAllocations )
//LLVM-C declare_pass( Reassociate )
declare_pass( DemoteRegisterToMemory )
declare_pass( ScalarReplAggregates )
declare_pass( SCCP )
declare_pass( SimplifyLibCalls )
//LLVM-C declare_pass( CFGSimplification )
declare_pass( StripSymbols )
declare_pass( StripDeadPrototypes )
declare_pass( StructRetPromotion )
declare_pass( TailCallElimination )
declare_pass( TailDuplication )
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View file

@ -1,10 +1,23 @@
"""Pass managers and passes. """Pass managers and passes.
This module provides the LLVM pass managers and the passes themselves.
Passes that are currently available are:
Simple Constant Propagation
Combine Redundant Instructions
Promote Memory to Register
Demote all values to stack slots
Reassociate expressions
Global Value Numbering
Simplify the CFG
See http://www.llvm.org/docs/Passes.html for the full list of passes
available in LLVM.
""" """
import ee # target data import llvm.ee as ee # target data
import _core # C wrappers import llvm._core as _core # C wrappers
from _util import * # utility functions from llvm._util import * # utility functions
# passes # passes

View file

@ -34,6 +34,23 @@ def do_module():
except LLVMException: except LLVMException:
pass pass
class strstream(object):
def __init__(self):
self.s = ''
def write(self, data):
self.s += data
def read(self):
return self.s
ss = strstream()
m2 = Module.new('test')
m2.add_type_name('myint', ti)
m2.to_bitcode(ss)
m3 = Module.from_bitcode(ss)
t = m2 == m3
def do_type(): def do_type():
print " Testing class Type" print " Testing class Type"