diff --git a/www/src/userguide.txt b/www/src/userguide.txt index 794c6a2..cf67e1c 100644 --- a/www/src/userguide.txt +++ b/www/src/userguide.txt @@ -53,7 +53,7 @@ llvm-py is distributed as a source tarball. You'll need to build and install it before it can be used. At least the following will be required for this: -- C and C++ compilers (gcc/g++) +- C and C\++ compilers (gcc/g++) - Python itself - Python development files (headers and libraries) - LLVM, either installed or built @@ -62,8 +62,8 @@ On debian-based systems, the first three can be installed with the command `sudo apt-get install gcc g++ python python-dev`. Ensure that your distro's respository has the appropriate version of LLVM! -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 +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. @@ -1043,6 +1043,7 @@ a few subclasses that represent interesting instructions. ======================================================================= +[[user]] User (llvm.core) ~~~~~~~~~~~~~~~~ @@ -1562,6 +1563,7 @@ should be dropped after `delete` has been called. Functions can be verified with the `verify` method. Note that this may not work properly (aborts on errors). +[[fnattr]] Function attributes, as documented http://www.llvm.org/docs/LangRef.html#fnattrs[here], can be set on functions using the methods `add_attribute` and @@ -1684,11 +1686,13 @@ Argument (llvm.core) The `args` property of `llvm.core.Function` objects yields `llvm.core.Argument` objects. This allows for setting attributes for functions arguments. `Argument` objects cannot be constructed from user -code, the only way to get a reference to these are via functions. +code, the only way to get a reference to these are from `Function` +objects. The method `add_attribute` and `remove_attribute` can be used to add or remove the following attributes: +[[argattrs]] [frame="all",grid="all"] `25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Value, Equivalent LLVM Assembly Keyword @@ -1703,13 +1707,205 @@ Value, Equivalent LLVM Assembly Keyword `ATTR_NEST`, `nest` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The corresponding +These method work exactly like the link:#fnattr[corresponding methods] +of the `Function` class above. Refer http://www.llvm.org/docs/LangRef.html#paramattrs[LLVM docs] -provide more information. +for information on what each attribute means. -The alignment of any parameter can be set via the `alignment` +The alignment of any argument can be set via the `alignment` property, to any power of 2. +.llvm.core.Argument +[caption=""] +======================================================================= +.Base Class +- `llvm.core.Value` + +.Properties +`alignment`:: + The alignment of the argument. Must be a power of 2. + +.Methods +`add_attribute(attr)`:: + Add an attribute `attr` to the argument, from the set listed above. +`remove_attribute(attr)`:: + Remove the attribute `attr` of the argument. +======================================================================= + + +Instructions (llvm.core) +~~~~~~~~~~~~~~~~~~~~~~~~ + +An `llvm.core.Instruction` object represents an LLVM instruction. This +class is the root of a small hierarchy: + +----------------------------------------------------------------------- +Instruction + CallOrInvokeInstruction + PHINode + SwitchInstruction + CompareInstruction +----------------------------------------------------------------------- + +Instructions are not created directly, but via a builder. The builder +both creates instructions and adds them to a basic block at the same +time. One way of getting instruction objects are from basic blocks. + +Being derived from link:#user[`llvm.core.User`], the instruction +is-a user, i.e., an instruction in turn uses other values. The values +an instruction uses are its operands. These may be accessed using +`operands` property from the `llvm.core.User` base. + +The name of the instruction (like `add`, `mul` etc) can be got +via the `opcode_name` property. The `basic_block` property gives +the basic block to which the instruction belongs to. Note that +llvm-py does not allow free-standing instruction objects (i.e., +all instructions are created contained within a basic block). + +Classes of instructions can be got via the properties +`is_terminator`, `is_binary_op`, `is_shift` etc. See below for +the full list. + +.llvm.core.Instruction +[caption=""] +======================================================================= +.Base Class +- `llvm.core.User` + +.Properties +`basic_block` [read-only]:: + The basic block to which this instruction belongs to. +`is_terminator` [read-only]:: + True if the instruction is a terminator instruction. +`is_binary_op` [read-only]:: + True if the instruction is a binary operator. +`is_shift` [read-only]:: + True if the instruction is a shift instruction. +`is_cast` [read-only]:: + True if the instruction is a cast instruction. +`is_logical_shift` [read-only]:: + True if the instruction is a logical shift instruction. +`is_arithmetic_shift` [read-only]:: + True if the instruction is an arithmetic shift instruction. +`is_associative` [read-only]:: + True if the instruction is associative. +`is_commutative` [read-only]:: + True if the instruction is commutative. +`is_volatile` [read-only]:: + True if the instruction is a volatile load or store. +`opcode` [read-only]:: + The numeric opcode value of the instruction. Do not rely + on the absolute value of this number, it may change with + LLVM version. +`opcode_name` [read-only]:: + The name of the instruction, like `add`, `sub` etc. +======================================================================= + + +CallOrInvokeInstruction (llvm.core) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The `llvm.core.CallOrInvokeInstruction` is a subclass of +`llvm.core.Instruction`, and represents either a `call` or an +`invoke` instruction. + +.llvm.core.CallOrInvokeInstruction +[caption=""] +======================================================================= +.Base Class +- `llvm.core.Instruction` + +.Properties +`calling_convention`:: + Get or set the calling convention. See the link:#callconv[list above] + for possible values. + +.Methods +`add_parameter_attribute(idx, attr)`:: + Add an attribute `attr` to the `idx`-th argument. See + link:#argattrs[above] for possible values of `attr`. +`remove_parameter_attribute(idx, attr)`:: + Remove an attribute `attr` from the `idx`-th argument. See + link:#argattrs[above] for possible values of `attr`. +`set_parameter_alignment(idx, align)`:: + Set the alignment of the `idx`-th argument to `align`. + `align` should be a power of two. +======================================================================= + + +PHINode (llvm.core) +~~~~~~~~~~~~~~~~~~~ + +The `llvm.core.PHINode` is a subclass of +`llvm.core.Instruction`, and represents the `phi` instruction. When +created (using `Builder.phi`) the phi node contains no incoming +blocks (nor their corresponding values). To add an incoming arc to +the phi node, use the `add_incoming` method, which takes a source +block (`llvm.core.BasicBlock` object) and a value (object of +`llvm.core.Value` or of a class derived from it) that the phi node +will take on if control branches in from that block. + +.llvm.core.PHINode +[caption=""] +======================================================================= +.Base Class +- `llvm.core.Instruction` + +.Properties +`incoming_count` [read-only]:: + The number of incoming arcs for this phi node. + +.Methods +`add_incoming(value, block)`:: + Add an incoming arc, from the `llvm.core.BasicBlock` object + `block`, with the corresponding value `value`. `value` should + be an object of `llvm.core.Value` (or of a descendent class). + See link:#argattrs[above] for possible values of `attr`. +`get_incoming_value(idx)`:: + Returns the `idx`-th incoming arc's value. +`get_incoming_block(idx)`:: + Returns the `idx`-th incoming arc's block. +======================================================================= + + +SwitchInstruction (llvm.core) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(TODO describe) + +.llvm.core.SwitchInstruction +[caption=""] +======================================================================= +.Base Class +- `llvm.core.Instruction` + +.Methods +`add_case(const, block)`:: + Add another case to the switch statement. When the expression + being evaluated equals `const`, then control branches to + `block`. Here `const` must be of type `llvm.core.ConstantInt`. +======================================================================= + + +CompareInstruction (llvm.core) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(TODO describe) + + +.llvm.core.CompareInstruction +[caption=""] +======================================================================= +.Base Class +- `llvm.core.Instruction` + +.Properties +`predicate` [read-only]:: + The predicate of the compare instruction, one of the `ICMP_*` or + `FCMP_*` constants. +======================================================================= + + Basic Block (llvm.core) ~~~~~~~~~~~~~~~~~~~~~~~ @@ -1722,12 +1918,6 @@ Builder (llvm.core) TODO -Instructions (llvm.core) -~~~~~~~~~~~~~~~~~~~~~~~~ - -TODO - - Target Data (llvm.ee) ~~~~~~~~~~~~~~~~~~~~~ diff --git a/www/web/about.html b/www/web/about.html index bf179ec..4019c49 100644 --- a/www/web/about.html +++ b/www/web/about.html @@ -2,7 +2,7 @@ - + @@ -43,7 +43,7 @@ the llvm-py contributors.

diff --git a/www/web/contribute.html b/www/web/contribute.html index e8b1da2..50a0c43 100644 --- a/www/web/contribute.html +++ b/www/web/contribute.html @@ -2,7 +2,7 @@ - + @@ -65,11 +65,6 @@ spreading the word

SVN HEAD can be checked out like so:

@@ -91,7 +91,7 @@ update and merge before sending patches etc.

diff --git a/www/web/download.html b/www/web/download.html index e4d16ba..286592c 100644 --- a/www/web/download.html +++ b/www/web/download.html @@ -2,7 +2,7 @@ - + @@ -35,9 +35,19 @@

The latest release is 0.6, released 31-Aug-2010 (Changelog below). 0.6 works only with LLVM 2.7.

-

Download it here: -* llvm-py-0.6.tar.bz2 (primary) -* llvm-py-0.6.tar.bz2 (mirror)

+

Download it here:

+

Older versions are available here.

The latest code can be checked out from SVN like so:

@@ -48,12 +58,19 @@ below). 0.6 works only with LLVM 2.7.

package.

-

Changelog

-
0.6, 31-Aug-2010:
+
0.7, in progress:
+
+  * Add llvm.core.Argument.alignment property.
+  * Migrate to LLVM 2.8.
+  * Fix ffi link issue on darwin (Albert Mietus) (Issue #29).
+  * LLVM tutorial ported (Max Shawabkeh) (Issue #33).
+
+
+0.6, 31-Aug-2010:
 
   * Add and remove function attributes (Krzysztof Goj) (Issue #21).
   * Wrap fadd,fsub,fmul (Aaron S Lav) (Issue #31).
@@ -130,11 +147,10 @@ package.

* Initial release.
- diff --git a/www/web/examples.html b/www/web/examples.html index bf8d69c..cf4588b 100644 --- a/www/web/examples.html +++ b/www/web/examples.html @@ -2,7 +2,7 @@ - + @@ -31,15 +31,13 @@ -

Examples

-
-

A Simple Function

+

A Simple Function

Let’s create a (LLVM) module containing a single function, corresponding to the C function:

-
@@ -49,7 +47,7 @@ http://www.gnu.org/software/src-highlite --> }

Here’s how it looks like:

-
@@ -108,12 +106,10 @@ entry: ret i32 %tmp }
-
-
-

Adding JIT Compilation

+

Adding JIT Compilation

Let’s compile this function in-memory and run it.

-
@@ -155,9 +151,6 @@ retval = ee.returned 142
-
-
-

LLVM Tutorials

Simple JIT Tutorials

The following JIT tutorials were contributed by Sebastien Binet.

@@ -218,11 +211,10 @@ has been ported to llvm-py by Max Shawabkeh.

- diff --git a/www/web/examples/JITTutorial1.html b/www/web/examples/JITTutorial1.html index b3b2c5b..211526c 100644 --- a/www/web/examples/JITTutorial1.html +++ b/www/web/examples/JITTutorial1.html @@ -1,4 +1,4 @@ - diff --git a/www/web/examples/JITTutorial2.html b/www/web/examples/JITTutorial2.html index bab1b5d..9a167be 100644 --- a/www/web/examples/JITTutorial2.html +++ b/www/web/examples/JITTutorial2.html @@ -1,4 +1,4 @@ - diff --git a/www/web/index.html b/www/web/index.html index ae6f951..40a4928 100644 --- a/www/web/index.html +++ b/www/web/index.html @@ -2,7 +2,7 @@ - + @@ -47,7 +47,6 @@ discover that any of these claims are wrong, feel free to send across a patch.

-

News

@@ -77,11 +76,10 @@ a patch.

- diff --git a/www/web/license.html b/www/web/license.html index 1adf6ca..b972fa6 100644 --- a/www/web/license.html +++ b/www/web/license.html @@ -2,7 +2,7 @@ - + @@ -74,7 +74,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/www/web/userguide.html b/www/web/userguide.html index aa5f568..a1bd012 100644 --- a/www/web/userguide.html +++ b/www/web/userguide.html @@ -2,7 +2,7 @@ - + @@ -48,7 +48,6 @@ you can setup and use it. A working knowledge of Python and a basic idea of LLVM is assumed.

-

Introduction

LLVM (Low-Level Virtual Machine) provides enough @@ -77,8 +76,6 @@ versions.

llvm-py has been built and tested with Python 2.6. It should work with Python 2.4 and 2.5. It has not been tried with Python 3.x (patches welcome).

-
-

Installation

llvm-py is distributed as a source tarball. You’ll need to build and @@ -87,7 +84,7 @@ required for this:

  • -C and C compilers (gcc/g) +C and C++ compilers (gcc/g++)

  • @@ -109,11 +106,10 @@ LLVM, either installed or built

    On debian-based systems, the first three can be installed with the command sudo apt-get install gcc g++ python python-dev. Ensure that your distro’s respository has the appropriate version of LLVM!

    -

    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 +

    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.

    -
    -

    LLVM and --enable-pic

    +

    LLVM and --enable-pic

    The result of an LLVM build is a set of static libraries and object files. The llvm-py contains an extension package that is built into a shared object (_core.so) which links to these static libraries and @@ -125,9 +121,7 @@ configuring LLVM (default is no PIC), like this:

    ~/llvm$ ./configure --enable-pic --enable-optimized
    -
    -
    -

    llvm-config

    +

    llvm-config

    Inorder to build llvm-py, it’s build script needs to know from where it can invoke the llvm helper program, llvm-config. If you’ve installed LLVM, then this will be available in your PATH, and nothing further @@ -137,9 +131,7 @@ of llvm-config to the build script.

    You’ll need to be root to install llvm-py. Remember that your PATH is different from that of root, so even if llvm-config is in your PATH, it may not be available when you do sudo.

    -
    -
    -

    Steps

    +

    Steps

    The commands illustrated below assume that the LLVM source is available under /home/mdevan/llvm. If you’ve a previous version of llvm-py installed, it is recommended to remove it first, as described @@ -175,9 +167,7 @@ only if you need to debug into LLVM also.

    documentation regarding Installing Python Modules and Distributing Python Modules for more information on such scripts.

    -
-
-

Uninstall

+

Uninstall

If you’d installed llvm-py with the --user option, then llvm-py would be present under ~/.local/lib/python2.6/site-packages. Otherwise, it might be under /usr/lib/python2.6/site-packages @@ -192,15 +182,11 @@ the "egg" can be removed like so:

See the Python documentation for more information.

-
-
-

LLVM Concepts

This section explains a few concepts related to LLVM, not specific to llvm-py.

-
-

Intermediate Representation

+

Intermediate Representation

The intermediate representation, or IR for short, is an in-memory data structure that represents executable code. The IR data structures allow for creation of types, constants, functions, function arguments, @@ -256,9 +242,7 @@ level than the usual assembly language; for example there are instructions related to variable argument handling, exception handling, and garbage collection. These allow high-level languages to be represented cleanly in the IR.

-
-
-

SSA Form and PHI Nodes

+

SSA Form and PHI Nodes

All LLVM instructions are represented in the Static Single Assignment (SSA) form. Essentially, this means that any variable can be assigned to only once. Such a representation facilitates better optimization, among @@ -290,9 +274,7 @@ reached the PHI node. The argument a1 of the PHI node is associated with the block "a1 = 1;" and a2 with the block "a2 = 2;".

PHI nodes have to be explicitly created in the LLVM IR. Accordingly the LLVM instruction set has an instruction called phi.

-
-
-

LLVM Assembly Language

+

LLVM Assembly Language

The LLVM IR can be represented offline in two formats - a textual, human-readable form, similar to assembly language, called the LLVM assembly language (files with .ll extension) @@ -306,7 +288,7 @@ language code.

Just to get a feel of the LLVM assembly language, here’s a function in C, and the corresponding LLVM assembly (as generated by the demo page):

-
@@ -355,9 +337,7 @@ specification of the platform ABI (like endianness, sizes of types, alignment etc.).

The LLVM Language Reference defines the LLVM assembly language including the entire instruction set.

-
-
-

Modules

+

Modules

Modules, in the LLVM IR, are similar to a single C language source file (.c file). A module contains:

    @@ -381,9 +361,7 @@ global type aliases (typedef-s) contained within modules. Modules may be combined (linked) together to give a bigger resultant module. During this process LLVM attempts to reconcile the references between the combined modules.

-
-
-

Optimization and Passes

+

Optimization and Passes

LLVM provides quite a few optimization algorithms that work on the IR. These algorithms are organized as passes. Each pass does something specific, like combining redundant instructions. Passes need not always @@ -406,18 +384,11 @@ any stage, and perform any transforms on it as you like.)

correct objects to run them on (for example, a pass may work only on functions, individually) and actually runs them. opt is a command-line wrapper for the pass manager.

-
-
-

Bit code

+

Bit code

+

TODO

+

Execution Engine, JIT and Interpreter

TODO

-
-

Execution Engine, JIT and Interpreter

-

TODO

-
-
-
-

The llvm-py Package

The llvm-py is a Python package, consisting of 6 modules, that wrap @@ -584,7 +555,7 @@ constants PASS_* that represent various passes llvm.core". However, you might find it more convenient to import llvm-py modules thus:

-
@@ -604,13 +575,12 @@ interpreter or the object? of to get online help. (Note: not complete yet!)
-
-

Module (llvm.core)

+

Module (llvm.core)

Modules are top-level container objects. You need to create a module object first, before you can add global variables, aliases or functions. Modules are created using the static method Module.new:

-
@@ -642,7 +612,7 @@ object as argument, i.e., it should have a read() method that returns the entire data in a single call, as is the case with the builtin file object. Here is an example:

-
@@ -651,7 +621,7 @@ bcfile = = Module.from_bitcode(bcfile)

There is corresponding serialization method also, called to_bitcode:

-
@@ -663,7 +633,7 @@ The static method from_assembly can be used for this. Similar to the from_bitcode method, this one also takes a file-like object as argument:

-
@@ -674,7 +644,7 @@ my_module = Module
llvm.core.Module
-
+
Static Constructors
new(module_id) @@ -887,9 +857,7 @@ string representations.

-
-
-

Types (llvm.core)

+

Types (llvm.core)

Types are what you think they are. A instance of llvm.core.Type, or one of its derived classes, represent a type. llvm-py does not use as many classes to represent types as does LLVM itself. Some types are @@ -1009,7 +977,7 @@ cellspacing="0" cellpadding="4">

The class-level documentation follows:

llvm.core.Type
-
+
Static Constructors
int(n) @@ -1142,7 +1110,7 @@ cellspacing="0" cellpadding="4"> one of the following constants defined in llvm.core:

-
@@ -1165,7 +1133,7 @@ TYPE_METADATA = = 15

Example:

-
@@ -1208,7 +1176,7 @@ http://www.gnu.org/software/src-highlite -->
llvm.core.IntegerType
-
+
Base Class
  • @@ -1229,7 +1197,7 @@ http://www.gnu.org/software/src-highlite -->

llvm.core.FunctionType
-
+
Base Class
  • @@ -1264,7 +1232,7 @@ http://www.gnu.org/software/src-highlite --> function. Used like this:

    -
    @@ -1286,7 +1254,7 @@ http://www.gnu.org/software/src-highlite -->
    llvm.core.StructType
    -
    +
    Base Class
    • @@ -1313,7 +1281,7 @@ http://www.gnu.org/software/src-highlite --> Used like this:

      -
      @@ -1335,7 +1303,7 @@ http://www.gnu.org/software/src-highlite -->
      llvm.core.ArrayType
      -
      +
      Base Class
      • @@ -1364,7 +1332,7 @@ http://www.gnu.org/software/src-highlite -->

      llvm.core.PointerType
      -
      +
      Base Class
      • @@ -1393,7 +1361,7 @@ http://www.gnu.org/software/src-highlite -->

      llvm.core.VectorType
      -
      +
      Base Class
      • @@ -1422,7 +1390,7 @@ http://www.gnu.org/software/src-highlite -->

      Here is an example that demonstrates the creation of types:

      -
      @@ -1462,13 +1430,11 @@ f3 = Type.= [ Type.pointer( Type.int(8) ) ] printf = Type.function( Type.int(), fnargs, True ) # variadic function
      -
      -
      -

      TypeHandle (llvm.core)

      +

      TypeHandle (llvm.core)

      TypeHandle objects are used to create recursive types, like this linked list node structure in C:

      -
      @@ -1517,7 +1483,7 @@ in C++. The above example is available as in the source distribution.

      llvm.core.TypeHandle
      -
      +
      Static Constructors
      new(abstract_ty) @@ -1542,9 +1508,7 @@ in the source distribution.

-
-
-

Values (llvm.core)

+

Values (llvm.core)

llvm.core.Value is the base class of all values computed by a program that may be used as operands to other values. A value has a type associated with it (an object of llvm.core.Type).

@@ -1593,7 +1557,7 @@ a few subclasses that represent interesting instructions.

Value objects have a type (read-only), and a name (read-write).

llvm.core.Value
-
+
Properties
name @@ -1660,16 +1624,14 @@ a few subclasses that represent interesting instructions.

-
-
-

User (llvm.core)

+

User (llvm.core)

User-s are values that refer to other values. The values so refered can be retrived by the properties of User. This is the reverse of the Value.uses. Together these can be used to traverse the use-def chains of the SSA.

llvm.core.User
-
+
Base Class
  • @@ -1698,16 +1660,14 @@ chains of the SSA.

-
-
-

Constants (llvm.core)

+

Constants (llvm.core)

Constant-s represents constants that appear within the code. The values of such objects are known at creation time. Constants can be created from Python constants. A constant expression is also a constant — given a Constant object, an operation (like addition, subtraction etc) can be specified, to yield a new Constant object. Let’s see some examples:

-
@@ -2114,7 +2074,7 @@ cellspacing="0" cellpadding="4">
llvm.core.Constant
-
+
Base Class
  • @@ -2126,9 +2086,7 @@ cellspacing="0" cellpadding="4">

    Methods

    See table of operations above for full list. There are no other methods.

-
-
-

Other Constant* Classes (llvm.core)

+

Other Constant* Classes (llvm.core)

The following subclasses of Constant do not provide additional methods, they serve only to provide richer type information.

@@ -2197,7 +2155,7 @@ cellspacing="0" cellpadding="4">

These types are helpful in isinstance checks, like so:

-
@@ -2207,9 +2165,7 @@ k2 = Constant.< assert isinstance(k1, ConstantInt) assert isinstance(k2, ConstantArray)
-
-
-

Global Value (llvm.core)

+

Global Value (llvm.core)

The class llvm.core.GlobalValue represents module-scope aliases, variables and functions. Global variables are represented by the sub-class llvm.core.GlobalVariable and functions by llvm.core.Function.

@@ -2334,7 +2290,7 @@ global is a declaration or not. The module to which the global belongs to can be retrieved using the module property (read-only).

llvm.core.GlobalValue
-
+
Base Class
  • @@ -2396,9 +2352,7 @@ to can be retrieved using the module property (read-only).

-
-
-

Global Variable (llvm.core)

+

Global Variable (llvm.core)

Global variables (llvm.core.GlobalVariable) are subclasses of llvm.core.GlobalValue and represent module-level variables. These can have optional initializers and can be marked as constants. Global @@ -2406,7 +2360,7 @@ variables can be created either by using the add_global_variable method of the Module class (see above), or by using the static method GlobalVariable.new.

-
@@ -2420,7 +2374,7 @@ gv2 = GlobalVariable -
@@ -2440,7 +2394,7 @@ can be used to indicate that the variable is a global constant.

Global variables can be delete using the delete method. Do not use the object after calling delete on it.

-
@@ -2453,7 +2407,7 @@ gv.= None
llvm.core.GlobalVariable
-
+
Base Class
  • @@ -2513,9 +2467,7 @@ gv = None

-
-
-

Function (llvm.core)

+

Function (llvm.core)

Functions are represented by llvm.core.Function objects. They are contained within modules, and can be created either with the method module_obj.add_function or the static constructor Function.new. @@ -2524,7 +2476,7 @@ References to functions already present in a module can be retrieved via Function.get. All functions in a module can be enumerated by iterating over module_obj.functions.

-
@@ -2554,7 +2506,7 @@ called with a module object, an instrinic ID (which is a numeric constant) and a list of the types of arguments (which LLVM uses to resolve overloaded intrinsic functions).

-
@@ -2795,7 +2747,7 @@ set or got with the property collector.

got using the read-only property args. These can be iterated over, and also be indexed via integers. An example:

-
@@ -2816,7 +2768,7 @@ can be got via basic_block_count method. Note that get_entry_basic_block is slightly faster than basic_blocks[0] and so is basic_block_count, over len(f.basic_blocks).

-
@@ -2839,7 +2791,7 @@ from their containing module. All references to the function object should be dropped after delete has been called.

Functions can be verified with the verify method. Note that this may not work properly (aborts on errors).

-

Function attributes, as documented +

Here is how attributes can be set and removed:

-
@@ -2987,7 +2939,7 @@ f.# declare i32 @sum(i32, i32) nounwind readonly
llvm.core.Function
-
+
Base Class
  • @@ -3175,16 +3127,15 @@ f.

-
-
-

Argument (llvm.core)

+

Argument (llvm.core)

The args property of llvm.core.Function objects yields llvm.core.Argument objects. This allows for setting attributes for functions arguments. Argument objects cannot be constructed from user -code, the only way to get a reference to these are via functions.

+code, the only way to get a reference to these are from Function +objects.

The method add_attribute and remove_attribute can be used to add or remove the following attributes:

-
+
@@ -3268,39 +3219,362 @@ cellspacing="0" cellpadding="4">
-

The corresponding +

These method work exactly like the corresponding methods +of the Function class above. Refer LLVM docs -provide more information.

-

The alignment of any parameter can be set via the alignment +for information on what each attribute means.

+

The alignment of any argument can be set via the alignment property, to any power of 2.

-
-
-

Basic Block (llvm.core)

+
+
llvm.core.Argument
+
+
Base Class
    +
  • +

    +llvm.core.Value +

    +
  • +
+
Properties
+
+alignment +
+
+

+ The alignment of the argument. Must be a power of 2. +

+
+
+
Methods
+
+add_attribute(attr) +
+
+

+ Add an attribute attr to the argument, from the set listed above. +

+
+
+remove_attribute(attr) +
+
+

+ Remove the attribute attr of the argument. +

+
+
+
+

Instructions (llvm.core)

+

An llvm.core.Instruction object represents an LLVM instruction. This +class is the root of a small hierarchy:

+
+
+
Instruction
+  CallOrInvokeInstruction
+  PHINode
+  SwitchInstruction
+  CompareInstruction
+
+

Instructions are not created directly, but via a builder. The builder +both creates instructions and adds them to a basic block at the same +time. One way of getting instruction objects are from basic blocks.

+

Being derived from llvm.core.User, the instruction +is-a user, i.e., an instruction in turn uses other values. The values +an instruction uses are its operands. These may be accessed using +operands property from the llvm.core.User base.

+

The name of the instruction (like add, mul etc) can be got +via the opcode_name property. The basic_block property gives +the basic block to which the instruction belongs to. Note that +llvm-py does not allow free-standing instruction objects (i.e., +all instructions are created contained within a basic block).

+

Classes of instructions can be got via the properties +is_terminator, is_binary_op, is_shift etc. See below for +the full list.

+
+
llvm.core.Instruction
+
+
Base Class
    +
  • +

    +llvm.core.User +

    +
  • +
+
Properties
+
+basic_block [read-only] +
+
+

+ The basic block to which this instruction belongs to. +

+
+
+is_terminator [read-only] +
+
+

+ True if the instruction is a terminator instruction. +

+
+
+is_binary_op [read-only] +
+
+

+ True if the instruction is a binary operator. +

+
+
+is_shift [read-only] +
+
+

+ True if the instruction is a shift instruction. +

+
+
+is_cast [read-only] +
+
+

+ True if the instruction is a cast instruction. +

+
+
+is_logical_shift [read-only] +
+
+

+ True if the instruction is a logical shift instruction. +

+
+
+is_arithmetic_shift [read-only] +
+
+

+ True if the instruction is an arithmetic shift instruction. +

+
+
+is_associative [read-only] +
+
+

+ True if the instruction is associative. +

+
+
+is_commutative [read-only] +
+
+

+ True if the instruction is commutative. +

+
+
+is_volatile [read-only] +
+
+

+ True if the instruction is a volatile load or store. +

+
+
+opcode [read-only] +
+
+

+ The numeric opcode value of the instruction. Do not rely + on the absolute value of this number, it may change with + LLVM version. +

+
+
+opcode_name [read-only] +
+
+

+ The name of the instruction, like add, sub etc. +

+
+
+
+

CallOrInvokeInstruction (llvm.core)

+

The llvm.core.CallOrInvokeInstruction is a subclass of +llvm.core.Instruction, and represents either a call or an +invoke instruction.

+
+
llvm.core.CallOrInvokeInstruction
+
+
Base Class
    +
  • +

    +llvm.core.Instruction +

    +
  • +
+
Properties
+
+calling_convention +
+
+

+ Get or set the calling convention. See the list above + for possible values. +

+
+
+
Methods
+
+add_parameter_attribute(idx, attr) +
+
+

+ Add an attribute attr to the idx-th argument. See + above for possible values of attr. +

+
+
+remove_parameter_attribute(idx, attr) +
+
+

+ Remove an attribute attr from the idx-th argument. See + above for possible values of attr. +

+
+
+set_parameter_alignment(idx, align) +
+
+

+ Set the alignment of the idx-th argument to align. + align should be a power of two. +

+
+
+
+

PHINode (llvm.core)

+

The llvm.core.PHINode is a subclass of +llvm.core.Instruction, and represents the phi instruction. When +created (using Builder.phi) the phi node contains no incoming +blocks (nor their corresponding values). To add an incoming arc to +the phi node, use the add_incoming method, which takes a source +block (llvm.core.BasicBlock object) and a value (object of +llvm.core.Value or of a class derived from it) that the phi node +will take on if control branches in from that block.

+
+
llvm.core.PHINode
+
+
Base Class
    +
  • +

    +llvm.core.Instruction +

    +
  • +
+
Properties
+
+incoming_count [read-only] +
+
+

+ The number of incoming arcs for this phi node. +

+
+
+
Methods
+
+add_incoming(value, block) +
+
+

+ Add an incoming arc, from the llvm.core.BasicBlock object + block, with the corresponding value value. value should + be an object of llvm.core.Value (or of a descendent class). + See above for possible values of attr. +

+
+
+get_incoming_value(idx) +
+
+

+ Returns the idx-th incoming arc’s value. +

+
+
+get_incoming_block(idx) +
+
+

+ Returns the idx-th incoming arc’s block. +

+
+
+
+

SwitchInstruction (llvm.core)

+

(TODO describe)

+
+
llvm.core.SwitchInstruction
+
+
Base Class
    +
  • +

    +llvm.core.Instruction +

    +
  • +
+
Methods
+
+add_case(const, block) +
+
+

+ Add another case to the switch statement. When the expression + being evaluated equals const, then control branches to + block. Here const must be of type llvm.core.ConstantInt. +

+
+
+
+

CompareInstruction (llvm.core)

+

(TODO describe)

+
+
llvm.core.CompareInstruction
+
+
Base Class
    +
  • +

    +llvm.core.Instruction +

    +
  • +
+
Properties
+
+predicate [read-only] +
+
+

+ The predicate of the compare instruction, one of the ICMP_* or + FCMP_* constants. +

+
+
+
+

Basic Block (llvm.core)

TODO

-
-
-

Builder (llvm.core)

+

Builder (llvm.core)

TODO

-
-
-

Instructions (llvm.core)

+

Target Data (llvm.ee)

TODO

-
-
-

Target Data (llvm.ee)

-

TODO

-
-
-

Execution Engine (llvm.ee)

+

Execution Engine (llvm.ee)

TODO. For now, see test/example-jit.py.

-
-
-

Pass Manager and Passes (llvm.passes)

+

Pass Manager and Passes (llvm.passes)

TODO. For now, see test/passes.py.

-
-
-

About the llvm-py Project

llvm-py lives at @@ -3324,11 +3598,10 @@ are most welcome. You can checkout the latest SVN HEAD from

Mahadevan R wrote llvm-py and works on it in his spare time. He can be reached at mdevan@mdevan.org.

-