Added missing instructions and constant expressions. Updated documentation.
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@9 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
71e1ee072a
commit
a73422f719
17 changed files with 752 additions and 57 deletions
|
|
@ -5,6 +5,5 @@ llvm-py is developed by Mahadevan R, in his spare time, without being
|
|||
paid for it. He can be reached at mdevan.foobar@gmail.com, on the
|
||||
llvm-dev mailing list and irc.oftc.net#llvm (mdevan).
|
||||
|
||||
Many thanks to the guys over at LLVM for all the nifty software, and a
|
||||
helpful mailing list.
|
||||
Many thanks to the guys over at LLVM for all the nifty software.
|
||||
|
||||
|
|
|
|||
118
www/src/instrset.inc
Normal file
118
www/src/instrset.inc
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
.LLVM Instruction Set
|
||||
|
||||
[frame="all",grid="all"]
|
||||
`30`70~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Category, Instructions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Terminator instructions,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_ret[ret], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_br[br], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_switch[switch], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_invoke[invoke], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_unwind[unwind], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_unreachable[unreachable]"
|
||||
Binary operations,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_add[add], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_sub[sub], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_mul[mul], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_udiv[udiv], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_sdiv[sdiv], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_fdiv[fdiv], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_urem[urem], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_srem[srem], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_frem[frem]"
|
||||
Bitwise binary operations,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_shl[shl], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_lshr[lshr], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_ashr[ashr], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_and[and], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_or[or], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_xor[xor]"
|
||||
Vector operations,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_extractelement[extractelement], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_insertelement[insertelement], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_shufflevector[shufflevector]"
|
||||
Aggregate operations,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_extractvalue[extractvalue], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_insertvalue[insertvalue]"
|
||||
Memory access and addressing operations,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_malloc[malloc], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_free[free], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_alloca[alloca], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_load[load], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_store[store], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_getelementptr[getelementptr]"
|
||||
Conversion operations,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_trunc[trunc], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_zext[zext], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_sext[sext], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_fptrunc[fptrunc], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_fpext[fpext], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_fptoui[fptoui], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_fptosi[fptosi], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_uitofp[uitofp], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_sitofp[sitofp], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_ptrtoint[ptrtoint], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_inttoptr[inttoptr], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_bitcast[bitcast]"
|
||||
Other operations,\
|
||||
"http://www.llvm.org/docs/LangRef.html#i_icmp[icmp], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_fcmp[fcmp], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_vicmp[vicmp], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_vfcmp[vfcmp], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_phi[phi], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_select[select], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_call[call], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_va_arg[va_arg], \
|
||||
http://www.llvm.org/docs/LangRef.html#i_getresult[getresult]"
|
||||
Variable argument handling intrinsics,\
|
||||
"http://www.llvm.org/docs/LangRef.html#int_va_start[llvm.va_start], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_va_end[llvm.va_end], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_va_copy[llvm.va_copy]"
|
||||
Accurate garbage collection intrinsics,\
|
||||
"http://www.llvm.org/docs/LangRef.html#int_returnaddress[llvm.returnaddress], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_frameaddress[llvm.frameaddress], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_stacksave[llvm.stacksave], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_stackrestore[llvm.stackrestore], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_prefetch[llvm.prefetch], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_pcmarker[llvm.pcmarker], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_readcyclecounter[llvm.readcyclecounter]"
|
||||
Standard C library intrinsics,\
|
||||
"http://www.llvm.org/docs/LangRef.html#int_memcpy[llvm.memcpy.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_memmove[llvm.memmove.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_memset[llvm.memset.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_sqrt[llvm.sqrt.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_powi[llvm.powi.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_sin[llvm.sin.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_cos[llvm.cos.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_pow[llvm.pow.\*]"
|
||||
Bit manipulation intrinsics,\
|
||||
"http://www.llvm.org/docs/LangRef.html#int_bswap[llvm.bswap.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_ctpop[llvm.ctpop.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_ctlz[llvm.ctlz.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_cttz[llvm.cttz.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_part_select[llvm.part.select.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_part_set[llvm.part.set.\*]"
|
||||
Debugger intrinsics,\
|
||||
"http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_stoppoint[llvm.dbg.stoppoint], \
|
||||
http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_func_start[llvm.dbg.func.start], \
|
||||
http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_region_start[llvm.dbg.region.start], \
|
||||
http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_region_end[llvm.dbg.region.end], \
|
||||
http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_declare[llvm.dbg.declare]"
|
||||
Exception handling intrinsics,\
|
||||
"http://www.llvm.org/docs/ExceptionHandling.html#llvm_eh_exception[llvm.eh_exception], \
|
||||
http://www.llvm.org/docs/ExceptionHandling.html#llvm_eh_selector[llvm.eh_selector], \
|
||||
http://www.llvm.org/docs/ExceptionHandling.html#llvm_eh_typeid_for[llvm.eh_typeid_for]"
|
||||
Trampoline intrinsics,\
|
||||
"http://www.llvm.org/docs/LangRef.html#int_it[llvm.init.trampoline]"
|
||||
Atomic intrinsics,\
|
||||
"http://www.llvm.org/docs/LangRef.html#int_memory_barrier[llvm.memory.barrier], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_atomic_lcs[llvm.atomic.lcs], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_atomic_las[llvm.atomic.las], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_atomic_swap[llvm.atomic.swap]"
|
||||
General intrinsics,\
|
||||
"http://www.llvm.org/docs/LangRef.html#int_var_annotation[llvm.var.annotation], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_annotation[llvm.annotation.\*], \
|
||||
http://www.llvm.org/docs/LangRef.html#int_trap[llvm.trap]"
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
@ -78,5 +78,14 @@ Last updated {localdate}.
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
||||
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var pageTracker = _gat._getTracker("UA-4519056-2");
|
||||
pageTracker._initData();
|
||||
pageTracker._trackPageview();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
License
|
||||
=======
|
||||
|
||||
_llvm-py_ is distributed under the
|
||||
llvm-py is distributed under the
|
||||
http://www.opensource.org/licenses/bsd-license.php[new BSD license].
|
||||
This is similar to LLVM's license. You should be able to use _llvm-py_
|
||||
This is similar to LLVM's license. You should be able to use llvm-py
|
||||
where-ever and how-ever you're able to use LLVM itself.
|
||||
|
||||
The license text is present in the
|
||||
|
|
|
|||
|
|
@ -167,11 +167,6 @@ instructions related to variable argument handling, exception handling,
|
|||
and garbage collection. These allow high-level languages to be
|
||||
represented cleanly in the IR.
|
||||
|
||||
The full set of instructions are:
|
||||
|
||||
TODO
|
||||
|
||||
|
||||
SSA Form and PHI Nodes
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
@ -217,7 +212,7 @@ 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) (XXX ?)
|
||||
the LLVM assembly language (files with .ll extension)
|
||||
- a binary form, called the LLVM bitcode (files with .bc extension)
|
||||
All three formats (the in-memory IR, the LLVM assembly language and the
|
||||
LLVM bitcode) represent the _same_ information. Each format can be
|
||||
|
|
@ -227,27 +222,62 @@ The http://www.llvm.org/demo/[LLVM demo page] lets you type in C or C++
|
|||
code, converts it into LLVM IR and outputs the IR as LLVM assembly
|
||||
language code.
|
||||
|
||||
Here's a function in C, that calculates the sum of the first _n_
|
||||
fibonacci numbers:
|
||||
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):
|
||||
|
||||
[C]
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
int fibsum(int n)
|
||||
/* compute sum of 1..n */
|
||||
unsigned sum(unsigned n)
|
||||
{
|
||||
if (n == 0)
|
||||
return 0;
|
||||
else
|
||||
return n + sum(n-1);
|
||||
}
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
And here's the corresponding LLVM assembly listing, as provided by the
|
||||
demo page:
|
||||
The corresponding LLVM assembly:
|
||||
|
||||
----
|
||||
----
|
||||
-----------------------------------------------------------------------
|
||||
; ModuleID = '/tmp/webcompile/_4940_0.bc'
|
||||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
|
||||
target triple = "i386-pc-linux-gnu"
|
||||
|
||||
Note the ... TODO ...
|
||||
define i32 @sum(i32 %n) nounwind {
|
||||
entry:
|
||||
%tmp215 = icmp eq i32 %n, 0 ; <i1> [#uses=1]
|
||||
br i1 %tmp215, label %bb10, label %tailrecurse.bb10_crit_edge
|
||||
|
||||
tailrecurse.bb10_crit_edge: ; preds = %entry
|
||||
%tmp = add i32 %n, -1 ; <i32> [#uses=3]
|
||||
%tmp17 = mul i32 %tmp, %tmp ; <i32> [#uses=1]
|
||||
%tmp18 = add i32 %tmp17, %n ; <i32> [#uses=1]
|
||||
%tmp. = zext i32 %tmp to i64 ; <i64> [#uses=2]
|
||||
%tmp19 = add i64 %tmp., -1 ; <i64> [#uses=1]
|
||||
%tmp20 = mul i64 %tmp19, %tmp. ; <i64> [#uses=1]
|
||||
%tmp21 = lshr i64 %tmp20, 1 ; <i64> [#uses=1]
|
||||
%tmp.22 = trunc i64 %tmp21 to i32 ; <i32> [#uses=1]
|
||||
%tmp24 = sub i32 %tmp18, %tmp.22 ; <i32> [#uses=1]
|
||||
ret i32 %tmp24
|
||||
|
||||
bb10: ; preds = %entry
|
||||
ret i32 0
|
||||
}
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
Note the usage of SSA form and the total absence of any loop or
|
||||
recursion at all!
|
||||
|
||||
The http://www.llvm.org/docs/LangRef.html[LLVM Language Reference]
|
||||
defines the LLVM assembly language including the entire instruction set.
|
||||
The table below lists all the LLVM instructions. Each instruction links
|
||||
to it's documentation.
|
||||
|
||||
include::instrset.inc[]
|
||||
|
||||
Intrinsics (instructions that start with +llvm.+) are not yet available
|
||||
in llvm-py.
|
||||
|
||||
Modules
|
||||
~~~~~~~
|
||||
|
|
@ -288,8 +318,7 @@ loaded and executed by +opt+. (Although llvm-py does not allow you to
|
|||
write your own passes, it does allow you to navigate the entire IR at
|
||||
any stage, and perform any transforms on it as you like.)
|
||||
|
||||
Passes are run using a _pass manager_. For our purposes, there are two
|
||||
pass managers TODO
|
||||
Passes are run using a _pass manager_. TODO
|
||||
|
||||
|
||||
Execution Engine
|
||||
|
|
@ -331,9 +360,10 @@ The modules contain only classes and (integer) constants. Mostly simple
|
|||
Python constructs are used (deliberately) --
|
||||
http://docs.python.org/lib/built-in-funcs.html[property()] and
|
||||
http://wiki.python.org/moin/PythonDecoratorLibrary[property
|
||||
decorators] are probably the most exotic animals around. The APIs are
|
||||
designed to be navigable (and guessable!) once you know a few
|
||||
conventions. These conventions are highlighted in the sections below.
|
||||
decorators] are probably the most exotic animals around. All classes are
|
||||
the "new style" classes. The APIs are designed to be navigable (and
|
||||
guessable!) once you know a few conventions. These conventions are
|
||||
highlighted in the sections below.
|
||||
|
||||
Here is a quick overview of the contents of each package:
|
||||
|
||||
|
|
@ -426,8 +456,46 @@ a Module object. This is a common feature for all llvm-py classes.
|
|||
corresponding classes. Constructors _should not_ be used.
|
||||
=======================================================================
|
||||
|
||||
The argument 'my_module' is a module identifier (a plain string).
|
||||
The argument `my_module` is a module identifier (a plain string). The
|
||||
attributes of the `Module` class is:
|
||||
|
||||
.llvm.core.Module
|
||||
[caption=""]
|
||||
=======================================================================
|
||||
.Static Constructors
|
||||
`new(module_id)`::
|
||||
create a new `Module` instance with given `module_id`. The `module_id`
|
||||
should be a string.
|
||||
|
||||
.Properties
|
||||
`data_layout` (r/w)::
|
||||
a string representing the ABI of the platform
|
||||
`target` (r/w)::
|
||||
a string like `i386-pc-linux-gnu` or `i386-pc-solaris2.8`
|
||||
`global_variables` (r)::
|
||||
TODO
|
||||
`functions` (r)::
|
||||
TODO
|
||||
|
||||
.Methods
|
||||
`add_type_name`::
|
||||
TODO
|
||||
`delete_type_name`::
|
||||
TODO
|
||||
`add_global_variable`::
|
||||
TODO
|
||||
`get_global_variable_named`::
|
||||
TODO
|
||||
|
||||
.Special Methods
|
||||
`\_\_str\_\_`::
|
||||
Module objects can be stringified into it's LLVM assembly language
|
||||
representation.
|
||||
`\_\_eq\_\_`::
|
||||
Module objects can be compared for equality. Internally, this
|
||||
converts both into their LLVM assembly representations and compares
|
||||
them.
|
||||
=======================================================================
|
||||
|
||||
Types (llvm.core)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -466,6 +534,16 @@ label, +Type.label()+, +Type+
|
|||
opaque, +Type.opaque()+, +Type+
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The class hierarchy is:
|
||||
-----------------------------------------------------------------------
|
||||
Type
|
||||
IntegerType
|
||||
FunctionType
|
||||
StructType
|
||||
ArrayType
|
||||
PointerType
|
||||
VectorType
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
Values (llvm.core)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue