Updated documentation.
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@91 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
1c04eb1c87
commit
f0d6877650
2 changed files with 646 additions and 63 deletions
|
|
@ -164,10 +164,11 @@ See the http://docs.python.org/install/index.html[Python
|
|||
documentation] for more information.
|
||||
|
||||
|
||||
The Concepts
|
||||
------------
|
||||
LLVM Concepts
|
||||
-------------
|
||||
|
||||
This section explains a few concepts related to LLVM.
|
||||
This section explains a few concepts related to LLVM, not specific
|
||||
to llvm-py.
|
||||
|
||||
|
||||
Intermediate Representation
|
||||
|
|
@ -322,7 +323,9 @@ file (.c file). A module contains:
|
|||
- global type aliases (typedef-s)
|
||||
|
||||
Modules are top-level containers; all executable code representation is
|
||||
contained within modules.
|
||||
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
|
||||
|
|
@ -350,7 +353,20 @@ 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.)
|
||||
|
||||
TODO: pass manager, execution engine, bit code
|
||||
A "pass manager" is responsible for loading passes, selecting the
|
||||
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
|
||||
~~~~~~~~
|
||||
|
||||
TODO
|
||||
|
||||
Execution Engine, JIT and Interpreter
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
TODO
|
||||
|
||||
|
||||
The llvm-py Package
|
||||
|
|
@ -954,28 +970,48 @@ associated with it (an object of `llvm.core.Type`).
|
|||
The class hierarchy is:
|
||||
-----------------------------------------------------------------------
|
||||
Value
|
||||
Constant
|
||||
GlobalValue
|
||||
GlobalVariable
|
||||
Function
|
||||
User
|
||||
Constant
|
||||
ConstantExpr
|
||||
ConstantAggregateZero
|
||||
ConstantInt
|
||||
ConstantFP
|
||||
ConstantArray
|
||||
ConstantStruct
|
||||
ConstantVector
|
||||
ConstantPointerNull
|
||||
UndefValue
|
||||
GlobalValue
|
||||
GlobalVariable
|
||||
Function
|
||||
Instruction
|
||||
CallOrInvokeInstruction
|
||||
PHINode
|
||||
SwitchInstruction
|
||||
CompareInstruction
|
||||
Argument
|
||||
Instruction
|
||||
CallOrInvokeInstruction
|
||||
PHINode
|
||||
SwitchInstruction
|
||||
BasicBlock
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
The `Value` class is abstract, it's not meant to be instantiated.
|
||||
The `Value` class is abstract, it's not meant to be instantiated. `User`
|
||||
is a `Value` that in turn uses (i.e., can refer to) other values (for
|
||||
e.g., a constant expression 1+2 refers to two constant values 1 and 2).
|
||||
|
||||
`Constant`-s represent constants that appear within code or as
|
||||
initializers of globals. They are constructed using static methods of
|
||||
`Constant`. The `Constant` class is covered in a separate section below.
|
||||
The `Function` object represents an instance of a function type. Such
|
||||
objects contain `Argument` objects, which represent the actual,
|
||||
`Constant`. Various types of constants are represented by various
|
||||
subclasses of `Constant`. However, most of them are empty and do
|
||||
not provide any additional attributes or methods over `Constant`.
|
||||
|
||||
The `Function` object represents an instance of a function type.
|
||||
Such objects contain `Argument` objects, which represent the actual,
|
||||
local-variable-like arguments of the function (not to be confused with
|
||||
the arguments returned by a function _type_ object -- these represent
|
||||
the _type_ of the arguments). The various `Instruction`-s are created by
|
||||
the `Builder` class. These are also covered separately.
|
||||
the _type_ of the arguments).
|
||||
|
||||
The various `Instruction`-s are created by the `Builder` class. Most
|
||||
instructions are represented by `Instruction` itself, but there are
|
||||
a few subclasses that represent interesting instructions.
|
||||
|
||||
`Value` objects have a type (read-only), and a name (read-write).
|
||||
|
||||
|
|
@ -987,6 +1023,14 @@ the `Builder` class. These are also covered separately.
|
|||
The name of the value.
|
||||
`type` [read-only]::
|
||||
An `llvm.core.Type` object representing the type of the value.
|
||||
`uses` [read-only]::
|
||||
The list of values (`llvm.core.Value`) that use this value.
|
||||
`use_count` [read-only]::
|
||||
The number of values that use (refer) this value. Same as
|
||||
`len(val.uses)` but faster if you just want the count.
|
||||
`value_id` [read-only]::
|
||||
Returns `llvm::Value::getValueID()`. Refer LLVM documentation
|
||||
for more info.
|
||||
|
||||
.Special Methods
|
||||
`__str__`::
|
||||
|
|
@ -999,6 +1043,30 @@ the `Builder` class. These are also covered separately.
|
|||
=======================================================================
|
||||
|
||||
|
||||
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
|
||||
[caption=""]
|
||||
=======================================================================
|
||||
.Base Class
|
||||
- `llvm.core.Value`
|
||||
|
||||
.Properties
|
||||
`operands` [read-only]::
|
||||
The list of operands (values, of type `llvm.core.Value`) that this
|
||||
value refers to.
|
||||
`operand_count` [read-only]::
|
||||
The number of operands that this value referes to. Same as
|
||||
`len(uses.operands)` but faster if you just want the count.
|
||||
=======================================================================
|
||||
|
||||
|
||||
Constants (llvm.core)
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
@ -1057,9 +1125,12 @@ section of the LLVM Language Reference.
|
|||
Method, Operation
|
||||
`k.neg()`, "negation, same as `0 - k`"
|
||||
`k.not_()`, "1's complement of `k`. Note trailing underscore."
|
||||
`k.add(k2)`, "`k + k2`"
|
||||
`k.sub(k2)`, "`k - k2`"
|
||||
`k.mul(k2)`, "`k * k2`"
|
||||
`k.add(k2)`, "`k + k2`, where `k` and `k2` are integers."
|
||||
`k.fadd(k2)`, "`k + k2`, where `k` and `k2` are floating-point."
|
||||
`k.sub(k2)`, "`k - k2`, where `k` and `k2` are integers."
|
||||
`k.fsub(k2)`, "`k - k2`, where `k` and `k2` are floating-point."
|
||||
`k.mul(k2)`, "`k * k2`, where `k` and `k2` are integers."
|
||||
`k.fmul(k2)`, "`k * k2`, where `k` and `k2` are floating-point."
|
||||
`k.udiv(k2)`, "Quotient of unsigned division of `k` with `k2`"
|
||||
`k.sdiv(k2)`, "Quotient of signed division of `k` with `k2`"
|
||||
`k.fdiv(k2)`, "Quotient of floating point division of `k` with `k2`"
|
||||
|
|
@ -1074,7 +1145,7 @@ Method, Operation
|
|||
`k.shl(k2)`, "Shift `k` left by `k2` bits."
|
||||
`k.lshr(k2)`, "Shift `k` logically right by `k2` bits (new bits are 0s)."
|
||||
`k.ashr(k2)`, "Shift `k` arithmetically right by `k2` bits (new bits are same as previous sign bit)."
|
||||
`k.gep(indices)`, "TODO"
|
||||
`k.gep(indices)`, "GEP, see http://www.llvm.org/docs/GetElementPtr.html[LLVM docs]."
|
||||
`k.trunc(ty)`, "Truncate `k` to a type `ty` of lower bitwidth."
|
||||
`k.sext(ty)`, "Sign extend `k` to a type `ty` of higher bitwidth, while extending the sign bit."
|
||||
`k.zext(ty)`, "Sign extend `k` to a type `ty` of higher bitwidth, all new bits are 0s."
|
||||
|
|
@ -1151,6 +1222,37 @@ See table of operations link:#constops[above] for full list. There are no other
|
|||
methods.
|
||||
=======================================================================
|
||||
|
||||
Other Constant* Classes (llvm.core)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The following subclasses of `Constant` do not provide additional
|
||||
methods, they serve only to provide richer type information.
|
||||
|
||||
[frame="all",grid="all",format="csv",cols="3",options="header"]
|
||||
|======================================================================
|
||||
Subclass, LLVM C++ Class, Remarks
|
||||
`ConstantExpr`, `llvm::ConstantExpr`, A constant expression
|
||||
`ConstantAggregateZero`, `llvm::ConstantAggregateZero`, All-zero constant
|
||||
`ConstantInt`, `llvm::ConstantInt`, An integer constant
|
||||
`ConstantFP`, `llvm::ConstantFP`, A floating-point constant
|
||||
`ConstantArray`, `llvm::ConstantArray`, An array constant
|
||||
`ConstantStruct`, `llvm::ConstantStruct`, A structure constant
|
||||
`ConstantVector`, `llvm::ConstantVector`, A vector constant
|
||||
`ConstantPointerNull`, `llvm::ConstantPointerNull`, All-zero pointer constant
|
||||
`UndefValue`, `llvm::UndefValue`, corresponds to `undef` of LLVM IR
|
||||
|======================================================================
|
||||
|
||||
These types are helpful in `isinstance` checks, like so:
|
||||
[python]
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
ti = Type.int(32)
|
||||
k1 = Constant.int(ti, 42) # int32_t k1 = 42;
|
||||
k2 = Constant.array(ti, [k1, k1]) # int32_t k2[] = { k1, k1 };
|
||||
|
||||
assert isinstance(k1, ConstantInt)
|
||||
assert isinstance(k2, ConstantArray)
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Global Value (llvm.core)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -1347,6 +1449,7 @@ for f in module_obj.functions:
|
|||
print f.name
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
[[intrinsic]]
|
||||
References to intrinsic functions can be got via the static constructor
|
||||
`intrinsic`. This returns a `Function` object, calling which is
|
||||
equivalent to invoking the intrinsic. The `intrinsic` method has to be
|
||||
|
|
@ -1370,12 +1473,11 @@ http://www.llvm.org/docs/LangRef.html#int_bswap[llvm.bswap]. The
|
|||
integer argument. The list of intrinsic IDs defined as integer constants
|
||||
in `llvm.core`. These are:
|
||||
|
||||
[format="csv",cols="4"]
|
||||
[format="csv",cols="4",grid="none"]
|
||||
|======================================================================
|
||||
include::intrinsics.csv[]
|
||||
|======================================================================
|
||||
|
||||
`ATTR_ZEXT`, `zeroext`
|
||||
There are also target-specific intrinsics (which correspond to that
|
||||
target's CPU instructions) available, but are omitted here for brevity.
|
||||
Full list can be seen from
|
||||
|
|
@ -1387,6 +1489,7 @@ directory in the source distribution for more examples. The intrinsic ID
|
|||
can be retrieved from a function object with the read-only property
|
||||
`intrinsic_id`.
|
||||
|
||||
[[callconv]]
|
||||
The function's calling convention can be set using the
|
||||
`calling_convention` property. The following (integer) constants defined
|
||||
in `llvm.core` can be used as values:
|
||||
|
|
@ -1459,12 +1562,15 @@ 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).
|
||||
|
||||
TODO function attributes
|
||||
Function attributes, as documented
|
||||
http://www.llvm.org/docs/LangRef.html#fnattrs[here], can be
|
||||
set on functions using the methods `add_attribute` and
|
||||
`remove_attribute`. The following values may be used to refer to the
|
||||
LLVM attributes:
|
||||
|
||||
[frame="all",grid="all"]
|
||||
`25`75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Value, Equivalent LLVM Assembly Keyword
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~a
|
||||
`ATTR_ALWAYS_INLINE`,`alwaysinline`
|
||||
`ATTR_INLINE_HINT`,`inlinehint`
|
||||
`ATTR_NO_INLINE`,`noinline`
|
||||
|
|
@ -1480,6 +1586,98 @@ Value, Equivalent LLVM Assembly Keyword
|
|||
`ATTR_NAKED`,`naked`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Here is how attributes can be set and removed:
|
||||
|
||||
[python]
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# create a function
|
||||
ti = Type.int(32)
|
||||
tf = Type.function(ti, [ti, ti])
|
||||
m = Module.new('mod')
|
||||
f = m.add_function(tf, 'sum')
|
||||
print f
|
||||
# declare i32 @sum(i32, i32)
|
||||
|
||||
# add a couple of attributes
|
||||
f.add_attribute(ATTR_NO_UNWIND)
|
||||
f.add_attribute(ATTR_READONLY)
|
||||
print f
|
||||
# declare i32 @sum(i32, i32) nounwind readonly
|
||||
source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.llvm.core.Function
|
||||
[caption=""]
|
||||
=======================================================================
|
||||
.Base Class
|
||||
- `llvm.core.GlobalValue`
|
||||
|
||||
.Static Constructors
|
||||
`new(module_obj, func_ty, name)`::
|
||||
Create a function named `name` of type `func_ty` in the module
|
||||
`module_obj` and return a `Function` object that represents it.
|
||||
`get(module_obj, name)`::
|
||||
Return a `Function` object to represent the function
|
||||
named `name` in the module `module_obj` or raise `LLVMException` if
|
||||
such a function does not exist.
|
||||
`get_or_insert(module_obj, func_ty, name)`::
|
||||
Similar to `get`, except that if the function does not exist it
|
||||
is added first, as though with `new`.
|
||||
`intrinsic(module_obj, intrinsic_id, types)`::
|
||||
Create and return a `Function` object that refers to an intrinsic
|
||||
function, as described link:#intrinsic[above].
|
||||
|
||||
.Properties
|
||||
`calling_convention`::
|
||||
The calling convention for the function, as listed
|
||||
link:#callconv[above].
|
||||
`collector`::
|
||||
A string holding the name of the garbage collection algorithm.
|
||||
See http://www.llvm.org/docs/LangRef.html#gc[LLVM docs].
|
||||
`does_not_throw`::
|
||||
Setting to True sets the `ATTR_NO_UNWIND` attribute, False
|
||||
removes it. Shortcut to using `f.add_attribute(ATTR_NO_UNWIND)`
|
||||
and `f.remove_attribute(ATTR_NO_UNWIND)`.
|
||||
`args` [read-only]::
|
||||
List of `llvm.core.Argument` objects representing the formal
|
||||
arguments of the function.
|
||||
`basic_block_count` [read-only]::
|
||||
Number of basic blocks belonging to this function. Same as
|
||||
`len(f.basic_blocks)` but faster if you just want the count.
|
||||
`entry_basic_block` [read-only]::
|
||||
The `llvm.core.BasicBlock` object representing the entry
|
||||
basic block for this function, or `None` if there are no
|
||||
basic blocks.
|
||||
`basic_blocks` [read-only]::
|
||||
List of `llvm.core.BasicBlock` objects representing the
|
||||
basic blocks belonging to this function.
|
||||
`intrinsic_id` [read-only]::
|
||||
Returns the ID of the intrinsic if this object represents an
|
||||
intrinsic instruction. Otherwise 0.
|
||||
|
||||
.Methods
|
||||
`delete()`::
|
||||
Deletes the function from it's module. _Do not hold any
|
||||
references to this object after calling `delete` on it.
|
||||
`append_basic_block(name)`::
|
||||
Add a new basic block named `name`, and return a corresponding
|
||||
`llvm.core.BasicBlock` object. Note that if this is not the
|
||||
entry basic block, you'll have to add appropriate branch
|
||||
instructions from other basic blocks yourself.
|
||||
`add_attribute(attr)`::
|
||||
Add an attribute `attr` to the function, from the set listed above.
|
||||
`remove_attribute(attr)`::
|
||||
Remove the attribute `attr` of the function.
|
||||
`viewCFG()`::
|
||||
Displays the control flow graph using the GraphViz tool.
|
||||
`viewCFGOnly()`::
|
||||
Displays the control flow graph using the GraphViz tool, but
|
||||
omitting function bodies.
|
||||
`verify()`::
|
||||
Verifies the function. See
|
||||
http://llvm.org/docs/Passes.html#verify[LLVM docs].
|
||||
=======================================================================
|
||||
|
||||
|
||||
Argument (llvm.core)
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
|||
|
|
@ -182,9 +182,10 @@ the "egg" can be removed like so:</p></div>
|
|||
<div class="paragraph"><p>See the <a href="http://docs.python.org/install/index.html">Python
|
||||
documentation</a> for more information.</p></div>
|
||||
</div>
|
||||
<h2 id="_the_concepts">The Concepts</h2>
|
||||
<h2 id="_llvm_concepts">LLVM Concepts</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="paragraph"><p>This section explains a few concepts related to LLVM.</p></div>
|
||||
<div class="paragraph"><p>This section explains a few concepts related to LLVM, not specific
|
||||
to llvm-py.</p></div>
|
||||
<h3 id="_intermediate_representation">Intermediate Representation</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p>The intermediate representation, or IR for short, is an in-memory data
|
||||
structure that represents executable code. The IR data structures allow
|
||||
|
|
@ -357,7 +358,9 @@ global type aliases (typedef-s)
|
|||
</li>
|
||||
</ul></div>
|
||||
<div class="paragraph"><p>Modules are top-level containers; all executable code representation is
|
||||
contained within modules.</p></div>
|
||||
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.</p></div>
|
||||
<h3 id="_optimization_and_passes">Optimization and Passes</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p>LLVM provides quite a few optimization algorithms that work on the IR.
|
||||
These algorithms are organized as <em>passes</em>. Each pass does something
|
||||
|
|
@ -377,7 +380,14 @@ can write your own passes (in C/C++, as a shared library). This can be
|
|||
loaded and executed by <tt>opt</tt>. (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.)</p></div>
|
||||
<div class="paragraph"><p>TODO: pass manager, execution engine, bit code</p></div>
|
||||
<div class="paragraph"><p>A "pass manager" is responsible for loading passes, selecting the
|
||||
correct objects to run them on (for example, a pass may work only
|
||||
on functions, individually) and actually runs them. <tt>opt</tt> is a
|
||||
command-line wrapper for the pass manager.</p></div>
|
||||
<h3 id="_bit_code">Bit code</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p>TODO</p></div>
|
||||
<h3 id="_execution_engine_jit_and_interpreter">Execution Engine, JIT and Interpreter</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p>TODO</p></div>
|
||||
</div>
|
||||
<h2 id="_the_llvm_py_package">The llvm-py Package</h2>
|
||||
<div class="sectionbody">
|
||||
|
|
@ -1506,27 +1516,44 @@ associated with it (an object of <tt>llvm.core.Type</tt>).</p></div>
|
|||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>Value
|
||||
Constant
|
||||
GlobalValue
|
||||
GlobalVariable
|
||||
Function
|
||||
User
|
||||
Constant
|
||||
ConstantExpr
|
||||
ConstantAggregateZero
|
||||
ConstantInt
|
||||
ConstantFP
|
||||
ConstantArray
|
||||
ConstantStruct
|
||||
ConstantVector
|
||||
ConstantPointerNull
|
||||
UndefValue
|
||||
GlobalValue
|
||||
GlobalVariable
|
||||
Function
|
||||
Instruction
|
||||
CallOrInvokeInstruction
|
||||
PHINode
|
||||
SwitchInstruction
|
||||
CompareInstruction
|
||||
Argument
|
||||
Instruction
|
||||
CallOrInvokeInstruction
|
||||
PHINode
|
||||
SwitchInstruction
|
||||
BasicBlock</tt></pre>
|
||||
</div></div>
|
||||
<div class="paragraph"><p>The <tt>Value</tt> class is abstract, it’s not meant to be instantiated.
|
||||
<tt>Constant</tt>-s represent constants that appear within code or as
|
||||
<div class="paragraph"><p>The <tt>Value</tt> class is abstract, it’s not meant to be instantiated. <tt>User</tt>
|
||||
is a <tt>Value</tt> that in turn uses (i.e., can refer to) other values (for
|
||||
e.g., a constant expression 1+2 refers to two constant values 1 and 2).</p></div>
|
||||
<div class="paragraph"><p><tt>Constant</tt>-s represent constants that appear within code or as
|
||||
initializers of globals. They are constructed using static methods of
|
||||
<tt>Constant</tt>. The <tt>Constant</tt> class is covered in a separate section below.
|
||||
The <tt>Function</tt> object represents an instance of a function type. Such
|
||||
objects contain <tt>Argument</tt> objects, which represent the actual,
|
||||
<tt>Constant</tt>. Various types of constants are represented by various
|
||||
subclasses of <tt>Constant</tt>. However, most of them are empty and do
|
||||
not provide any additional attributes or methods over <tt>Constant</tt>.</p></div>
|
||||
<div class="paragraph"><p>The <tt>Function</tt> object represents an instance of a function type.
|
||||
Such objects contain <tt>Argument</tt> objects, which represent the actual,
|
||||
local-variable-like arguments of the function (not to be confused with
|
||||
the arguments returned by a function <em>type</em> object — these represent
|
||||
the <em>type</em> of the arguments). The various <tt>Instruction</tt>-s are created by
|
||||
the <tt>Builder</tt> class. These are also covered separately.</p></div>
|
||||
the <em>type</em> of the arguments).</p></div>
|
||||
<div class="paragraph"><p>The various <tt>Instruction</tt>-s are created by the <tt>Builder</tt> class. Most
|
||||
instructions are represented by <tt>Instruction</tt> itself, but there are
|
||||
a few subclasses that represent interesting instructions.</p></div>
|
||||
<div class="paragraph"><p><tt>Value</tt> objects have a type (read-only), and a name (read-write).</p></div>
|
||||
<div class="exampleblock">
|
||||
<div class="title">llvm.core.Value</div>
|
||||
|
|
@ -1548,6 +1575,32 @@ the <tt>Builder</tt> class. These are also covered separately.</p></div>
|
|||
An <tt>llvm.core.Type</tt> object representing the type of the value.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>uses</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
The list of values (<tt>llvm.core.Value</tt>) that use this value.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>use_count</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
The number of values that use (refer) this value. Same as
|
||||
<tt>len(val.uses)</tt> but faster if you just want the count.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>value_id</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Returns <tt>llvm::Value::getValueID()</tt>. Refer LLVM documentation
|
||||
for more info.
|
||||
</p>
|
||||
</dd>
|
||||
</dl></div>
|
||||
<div class="dlist"><div class="title">Special Methods</div><dl>
|
||||
<dt class="hdlist1">
|
||||
|
|
@ -1571,6 +1624,42 @@ the <tt>Builder</tt> class. These are also covered separately.</p></div>
|
|||
</dd>
|
||||
</dl></div>
|
||||
</div></div>
|
||||
<h3 id="_user_llvm_core">User (llvm.core)</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p><tt>User</tt>-s are values that refer to other values. The values so refered
|
||||
can be retrived by the properties of <tt>User</tt>. This is the reverse of
|
||||
the <tt>Value.uses</tt>. Together these can be used to traverse the use-def
|
||||
chains of the SSA.</p></div>
|
||||
<div class="exampleblock">
|
||||
<div class="title">llvm.core.User</div>
|
||||
<div class="exampleblock-content">
|
||||
<div class="ulist"><div class="title">Base Class</div><ul>
|
||||
<li>
|
||||
<p>
|
||||
<tt>llvm.core.Value</tt>
|
||||
</p>
|
||||
</li>
|
||||
</ul></div>
|
||||
<div class="dlist"><div class="title">Properties</div><dl>
|
||||
<dt class="hdlist1">
|
||||
<tt>operands</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
The list of operands (values, of type <tt>llvm.core.Value</tt>) that this
|
||||
value refers to.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>operand_count</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
The number of operands that this value referes to. Same as
|
||||
<tt>len(uses.operands)</tt> but faster if you just want the count.
|
||||
</p>
|
||||
</dd>
|
||||
</dl></div>
|
||||
</div></div>
|
||||
<h3 id="_constants_llvm_core">Constants (llvm.core)</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p><tt>Constant</tt>-s represents constants that appear within the code. The
|
||||
values of such objects are known at creation time. Constants can be
|
||||
|
|
@ -1692,15 +1781,27 @@ cellspacing="0" cellpadding="4">
|
|||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.add(k2)</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k + k2</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k + k2</tt>, where <tt>k</tt> and <tt>k2</tt> are integers.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.fadd(k2)</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k + k2</tt>, where <tt>k</tt> and <tt>k2</tt> are floating-point.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.sub(k2)</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k - k2</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k - k2</tt>, where <tt>k</tt> and <tt>k2</tt> are integers.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.fsub(k2)</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k - k2</tt>, where <tt>k</tt> and <tt>k2</tt> are floating-point.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.mul(k2)</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k * k2</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k * k2</tt>, where <tt>k</tt> and <tt>k2</tt> are integers.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.fmul(k2)</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>k * k2</tt>, where <tt>k</tt> and <tt>k2</tt> are floating-point.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.udiv(k2)</tt></p></td>
|
||||
|
|
@ -1760,7 +1861,7 @@ cellspacing="0" cellpadding="4">
|
|||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.gep(indices)</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">TODO</p></td>
|
||||
<td align="left" valign="top"><p class="table">GEP, see <a href="http://www.llvm.org/docs/GetElementPtr.html">LLVM docs</a>.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>k.trunc(ty)</tt></p></td>
|
||||
|
|
@ -1985,6 +2086,85 @@ cellspacing="0" cellpadding="4">
|
|||
<div class="paragraph"><div class="title">Methods</div><p>See table of operations <a href="#constops">above</a> for full list. There are no other
|
||||
methods.</p></div>
|
||||
</div></div>
|
||||
<h3 id="_other_constant_classes_llvm_core">Other Constant* Classes (llvm.core)</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p>The following subclasses of <tt>Constant</tt> do not provide additional
|
||||
methods, they serve only to provide richer type information.</p></div>
|
||||
<div class="tableblock">
|
||||
<table rules="all"
|
||||
width="100%"
|
||||
frame="border"
|
||||
cellspacing="0" cellpadding="4">
|
||||
<col width="33%" />
|
||||
<col width="33%" />
|
||||
<col width="33%" />
|
||||
<thead>
|
||||
<tr>
|
||||
<th align="left" valign="top">Subclass</th>
|
||||
<th align="left" valign="top">LLVM C++ Class</th>
|
||||
<th align="left" valign="top">Remarks</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantExpr</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantExpr</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">A constant expression</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantAggregateZero</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantAggregateZero</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">All-zero constant</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantInt</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantInt</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">An integer constant</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantFP</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantFP</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">A floating-point constant</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantArray</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantArray</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">An array constant</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantStruct</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantStruct</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">A structure constant</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantVector</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantVector</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">A vector constant</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>ConstantPointerNull</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::ConstantPointerNull</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">All-zero pointer constant</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>UndefValue</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>llvm::UndefValue</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">corresponds to <tt>undef</tt> of LLVM IR</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="paragraph"><p>These types are helpful in <tt>isinstance</tt> checks, like so:</p></div>
|
||||
<div class="listingblock">
|
||||
<div class="content"><!-- Generator: GNU source-highlight 3.1.3
|
||||
by Lorenzo Bettini
|
||||
http://www.lorenzobettini.it
|
||||
http://www.gnu.org/software/src-highlite -->
|
||||
<pre><tt>ti <span style="color: #990000">=</span> Type<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">(</span><span style="color: #993399">32</span><span style="color: #990000">)</span>
|
||||
k1 <span style="color: #990000">=</span> Constant<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">(</span>ti<span style="color: #990000">,</span> <span style="color: #993399">42</span><span style="color: #990000">)</span> <span style="font-style: italic"><span style="color: #9A1900"># int32_t k1 = 42;</span></span>
|
||||
k2 <span style="color: #990000">=</span> Constant<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">array</span></span><span style="color: #990000">(</span>ti<span style="color: #990000">,</span> <span style="color: #990000">[</span>k1<span style="color: #990000">,</span> k1<span style="color: #990000">])</span> <span style="font-style: italic"><span style="color: #9A1900"># int32_t k2[] = { k1, k1 };</span></span>
|
||||
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">assert</span></span> <span style="font-weight: bold"><span style="color: #000000">isinstance</span></span><span style="color: #990000">(</span>k1<span style="color: #990000">,</span> ConstantInt<span style="color: #990000">)</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">assert</span></span> <span style="font-weight: bold"><span style="color: #000000">isinstance</span></span><span style="color: #990000">(</span>k2<span style="color: #990000">,</span> ConstantArray<span style="color: #990000">)</span></tt></pre></div></div>
|
||||
<h3 id="_global_value_llvm_core">Global Value (llvm.core)</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p>The class <tt>llvm.core.GlobalValue</tt> represents module-scope aliases, variables
|
||||
and functions. Global variables are represented by the sub-class
|
||||
|
|
@ -2319,7 +2499,7 @@ f4 <span style="color: #990000">=</span> Function<span style="color: #990000">.<
|
|||
<span style="font-style: italic"><span style="color: #9A1900"># list all function names in a module</span></span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">for</span></span> f <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> module_obj<span style="color: #990000">.</span>functions<span style="color: #990000">:</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">print</span></span> f<span style="color: #990000">.</span>name</tt></pre></div></div>
|
||||
<div class="paragraph"><p>References to intrinsic functions can be got via the static constructor
|
||||
<div class="paragraph" id="intrinsic"><p>References to intrinsic functions can be got via the static constructor
|
||||
<tt>intrinsic</tt>. This returns a <tt>Function</tt> object, calling which is
|
||||
equivalent to invoking the intrinsic. The <tt>intrinsic</tt> method has to be
|
||||
called with a module object, an instrinic ID (which is a numeric
|
||||
|
|
@ -2342,7 +2522,7 @@ the LLVM intrinsic
|
|||
integer argument. The list of intrinsic IDs defined as integer constants
|
||||
in <tt>llvm.core</tt>. These are:</p></div>
|
||||
<div class="tableblock">
|
||||
<table rules="all"
|
||||
<table rules="none"
|
||||
width="100%"
|
||||
frame="border"
|
||||
cellspacing="0" cellpadding="4">
|
||||
|
|
@ -2485,8 +2665,7 @@ cellspacing="0" cellpadding="4">
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="paragraph"><p><tt>ATTR_ZEXT</tt>, <tt>zeroext</tt>
|
||||
There are also target-specific intrinsics (which correspond to that
|
||||
<div class="paragraph"><p>There are also target-specific intrinsics (which correspond to that
|
||||
target’s CPU instructions) available, but are omitted here for brevity.
|
||||
Full list can be seen from
|
||||
<a href="http://code.google.com/p/llvm-py/source/browse/trunk/llvm/_intrinsic_ids.py"><tt>_intrinsic_ids.py</tt></a>.
|
||||
|
|
@ -2496,7 +2675,7 @@ for more information on the intrinsics, and the
|
|||
directory in the source distribution for more examples. The intrinsic ID
|
||||
can be retrieved from a function object with the read-only property
|
||||
<tt>intrinsic_id</tt>.</p></div>
|
||||
<div class="paragraph"><p>The function’s calling convention can be set using the
|
||||
<div class="paragraph" id="callconv"><p>The function’s calling convention can be set using the
|
||||
<tt>calling_convention</tt> property. The following (integer) constants defined
|
||||
in <tt>llvm.core</tt> can be used as values:</p></div>
|
||||
<div class="tableblock">
|
||||
|
|
@ -2612,7 +2791,11 @@ from their containing module. All references to the function object
|
|||
should be dropped after <tt>delete</tt> has been called.</p></div>
|
||||
<div class="paragraph"><p>Functions can be verified with the <tt>verify</tt> method. Note that this may
|
||||
not work properly (aborts on errors).</p></div>
|
||||
<div class="paragraph"><p>TODO function attributes</p></div>
|
||||
<div class="paragraph"><p>Function attributes, as documented
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#fnattrs">here</a>, can be
|
||||
set on functions using the methods <tt>add_attribute</tt> and
|
||||
<tt>remove_attribute</tt>. The following values may be used to refer to the
|
||||
LLVM attributes:</p></div>
|
||||
<div class="tableblock">
|
||||
<table rules="all"
|
||||
frame="border"
|
||||
|
|
@ -2628,13 +2811,6 @@ cellspacing="0" cellpadding="4">
|
|||
Equivalent LLVM Assembly Keyword
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>~<sub>~</sub>a
|
||||
</td>
|
||||
<td align="left">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
<tt>ATTR_ALWAYS_INLINE</tt>
|
||||
|
|
@ -2742,6 +2918,215 @@ cellspacing="0" cellpadding="4">
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="paragraph"><p>Here is how attributes can be set and removed:</p></div>
|
||||
<div class="listingblock">
|
||||
<div class="content"><!-- Generator: GNU source-highlight 3.1.3
|
||||
by Lorenzo Bettini
|
||||
http://www.lorenzobettini.it
|
||||
http://www.gnu.org/software/src-highlite -->
|
||||
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># create a function</span></span>
|
||||
ti <span style="color: #990000">=</span> Type<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">int</span></span><span style="color: #990000">(</span><span style="color: #993399">32</span><span style="color: #990000">)</span>
|
||||
tf <span style="color: #990000">=</span> Type<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">function</span></span><span style="color: #990000">(</span>ti<span style="color: #990000">,</span> <span style="color: #990000">[</span>ti<span style="color: #990000">,</span> ti<span style="color: #990000">])</span>
|
||||
m <span style="color: #990000">=</span> Module<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">new</span></span><span style="color: #990000">(</span><span style="color: #FF0000">'mod'</span><span style="color: #990000">)</span>
|
||||
f <span style="color: #990000">=</span> m<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_function</span></span><span style="color: #990000">(</span>tf<span style="color: #990000">,</span> <span style="color: #FF0000">'sum'</span><span style="color: #990000">)</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">print</span></span> f
|
||||
<span style="font-style: italic"><span style="color: #9A1900"># declare i32 @sum(i32, i32)</span></span>
|
||||
|
||||
<span style="font-style: italic"><span style="color: #9A1900"># add a couple of attributes</span></span>
|
||||
f<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_attribute</span></span><span style="color: #990000">(</span>ATTR_NO_UNWIND<span style="color: #990000">)</span>
|
||||
f<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">add_attribute</span></span><span style="color: #990000">(</span>ATTR_READONLY<span style="color: #990000">)</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">print</span></span> f
|
||||
<span style="font-style: italic"><span style="color: #9A1900"># declare i32 @sum(i32, i32) nounwind readonly</span></span></tt></pre></div></div>
|
||||
<div class="exampleblock">
|
||||
<div class="title">llvm.core.Function</div>
|
||||
<div class="exampleblock-content">
|
||||
<div class="ulist"><div class="title">Base Class</div><ul>
|
||||
<li>
|
||||
<p>
|
||||
<tt>llvm.core.GlobalValue</tt>
|
||||
</p>
|
||||
</li>
|
||||
</ul></div>
|
||||
<div class="dlist"><div class="title">Static Constructors</div><dl>
|
||||
<dt class="hdlist1">
|
||||
<tt>new(module_obj, func_ty, name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Create a function named <tt>name</tt> of type <tt>func_ty</tt> in the module
|
||||
<tt>module_obj</tt> and return a <tt>Function</tt> object that represents it.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>get(module_obj, name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Return a <tt>Function</tt> object to represent the function
|
||||
named <tt>name</tt> in the module <tt>module_obj</tt> or raise <tt>LLVMException</tt> if
|
||||
such a function does not exist.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>get_or_insert(module_obj, func_ty, name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Similar to <tt>get</tt>, except that if the function does not exist it
|
||||
is added first, as though with <tt>new</tt>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>intrinsic(module_obj, intrinsic_id, types)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Create and return a <tt>Function</tt> object that refers to an intrinsic
|
||||
function, as described <a href="#intrinsic">above</a>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl></div>
|
||||
<div class="dlist"><div class="title">Properties</div><dl>
|
||||
<dt class="hdlist1">
|
||||
<tt>calling_convention</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
The calling convention for the function, as listed
|
||||
<a href="#callconv">abov</a>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>collector</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
A string holding the name of the garbage collection algorithm.
|
||||
See <a href="http://www.llvm.org/docs/LangRef.html#gc">LLVM docs</a>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>does_not_throw</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Setting to True sets the <tt>ATTR_NO_UNWIND</tt> attribute, False
|
||||
removes it. Shortcut to using <tt>f.add_attribute(ATTR_NO_UNWIND)</tt>
|
||||
and <tt>f.remove_attribute(ATTR_NO_UNWIND)</tt>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>args</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
List of <tt>llvm.core.Argument</tt> objects representing the formal
|
||||
arguments of the function.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>basic_block_count</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Number of basic blocks belonging to this function. Same as
|
||||
<tt>len(f.basic_blocks)</tt> but faster if you just want the count.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>entry_basic_block</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
The <tt>llvm.core.BasicBlock</tt> object representing the entry
|
||||
basic block for this function, or <tt>None</tt> if there are no
|
||||
basic blocks.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>basic_blocks</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
List of <tt>llvm.core.BasicBlock</tt> objects representing the
|
||||
basic blocks belonging to this function.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>intrinsic_id</tt> [read-only]
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Returns the ID of the intrinsic if this object represents an
|
||||
intrinsic instruction. Otherwise 0.
|
||||
</p>
|
||||
</dd>
|
||||
</dl></div>
|
||||
<div class="dlist"><div class="title">Methods</div><dl>
|
||||
<dt class="hdlist1">
|
||||
<tt>delete()</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Deletes the function from it’s module. _Do not hold any
|
||||
references to this object after calling <tt>delete</tt> on it.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>append_basic_block(name)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Add a new basic block named <tt>name</tt>, and return a corresponding
|
||||
<tt>llvm.core.BasicBlock</tt> object. Note that if this is not the
|
||||
entry basic block, you’ll have to add appropriate branch
|
||||
instructions from other basic blocks yourself.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>add_attribute(attr)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Add an attribute <tt>attr</tt> to the function, from the set listed above.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>remove_attribute(attr)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Remove the attribute <tt>attr</tt> of the function.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>viewCFG()</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Displays the control flow graph using the GraphViz tool.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>viewCFGOnly()</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Displays the control flow graph using the GraphViz tool, but
|
||||
omitting function bodies.
|
||||
</p>
|
||||
</dd>
|
||||
<dt class="hdlist1">
|
||||
<tt>verify()</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Verifies the function. See
|
||||
<a href="http://llvm.org/docs/Passes.html#verify">LLVM docs</a>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl></div>
|
||||
</div></div>
|
||||
<h3 id="_argument_llvm_core">Argument (llvm.core)</h3><div style="clear:left"></div>
|
||||
<div class="paragraph"><p>The <tt>args</tt> property of <tt>llvm.core.Function</tt> objects yields
|
||||
<tt>llvm.core.Argument</tt> objects. This allows for setting attributes for
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue