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
12
llvm/_core.c
12
llvm/_core.c
|
|
@ -286,6 +286,8 @@ _wrap_objobj2obj(LLVMConstXor, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
|||
|
||||
_wrap_intobjobj2obj(LLVMConstICmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_intobjobj2obj(LLVMConstFCmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_intobjobj2obj(LLVMConstVICmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_intobjobj2obj(LLVMConstVFCmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
|
||||
_wrap_objobj2obj(LLVMConstShl, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objobj2obj(LLVMConstLShr, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
|
|
@ -435,6 +437,7 @@ _wrap_obj2none(LLVMDisposeBuilder, LLVMBuilderRef)
|
|||
|
||||
_wrap_obj2obj(LLVMBuildRetVoid, LLVMBuilderRef, LLVMValueRef)
|
||||
_wrap_objobj2obj(LLVMBuildRet, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objlist2obj(LLVMBuildRetMultiple, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objobj2obj(LLVMBuildBr, LLVMBuilderRef, LLVMBasicBlockRef, LLVMValueRef)
|
||||
_wrap_objobjobjobj2obj(LLVMBuildCondBr, LLVMBuilderRef, LLVMValueRef, LLVMBasicBlockRef, LLVMBasicBlockRef, LLVMValueRef)
|
||||
_wrap_objobjobjint2obj(LLVMBuildSwitch, LLVMBuilderRef, LLVMValueRef, LLVMBasicBlockRef, LLVMValueRef)
|
||||
|
|
@ -527,9 +530,12 @@ _wrap_objobjobjstr2obj(LLVMBuildBitCast, LLVMBuilderRef, LLVMValueRef, LLVMTypeR
|
|||
|
||||
_wrap_objintobjobjstr2obj(LLVMBuildICmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objintobjobjstr2obj(LLVMBuildFCmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objintobjobjstr2obj(LLVMBuildVICmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objintobjobjstr2obj(LLVMBuildVFCmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
|
||||
/* Miscellaneous instructions */
|
||||
|
||||
_wrap_objobjintstr2obj(LLVMBuildGetResult, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objobjstr2obj(LLVMBuildPhi, LLVMBuilderRef, LLVMTypeRef, LLVMValueRef)
|
||||
_wrap_objobjliststr2obj(LLVMBuildCall, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_objobjobjobjstr2obj(LLVMBuildSelect, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
|
||||
|
|
@ -837,6 +843,8 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMConstXor )
|
||||
_method( LLVMConstICmp )
|
||||
_method( LLVMConstFCmp )
|
||||
_method( LLVMConstVICmp )
|
||||
_method( LLVMConstVFCmp )
|
||||
_method( LLVMConstShl )
|
||||
_method( LLVMConstLShr )
|
||||
_method( LLVMConstAShr )
|
||||
|
|
@ -947,6 +955,7 @@ static PyMethodDef core_methods[] = {
|
|||
/* Terminators */
|
||||
_method( LLVMBuildRetVoid )
|
||||
_method( LLVMBuildRet )
|
||||
_method( LLVMBuildRetMultiple )
|
||||
_method( LLVMBuildBr )
|
||||
_method( LLVMBuildCondBr )
|
||||
_method( LLVMBuildSwitch )
|
||||
|
|
@ -1003,8 +1012,11 @@ static PyMethodDef core_methods[] = {
|
|||
/* Comparisons */
|
||||
_method( LLVMBuildICmp )
|
||||
_method( LLVMBuildFCmp )
|
||||
_method( LLVMBuildVICmp )
|
||||
_method( LLVMBuildVFCmp )
|
||||
|
||||
/* Miscellaneous instructions */
|
||||
_method( LLVMBuildGetResult )
|
||||
_method( LLVMBuildPhi )
|
||||
_method( LLVMBuildCall )
|
||||
_method( LLVMBuildSelect )
|
||||
|
|
|
|||
44
llvm/core.py
44
llvm/core.py
|
|
@ -660,6 +660,10 @@ class Constant(Value):
|
|||
check_is_constant(rhs)
|
||||
return Constant(_core.LLVMConstSRem(self.ptr, rhs.ptr))
|
||||
|
||||
def frem(self, rhs):
|
||||
check_is_constant(rhs)
|
||||
return Constant(_core.LLVMConstFRem(self.ptr, rhs.ptr))
|
||||
|
||||
def and_(self, rhs):
|
||||
check_is_constant(rhs)
|
||||
return Constant(_core.LLVMConstAnd(self.ptr, rhs.ptr))
|
||||
|
|
@ -674,11 +678,19 @@ class Constant(Value):
|
|||
|
||||
def icmp(self, int_pred, rhs):
|
||||
check_is_constant(rhs)
|
||||
return Constant(_core.LLVMConstICmp(self.ptr, int_pred, rhs.ptr))
|
||||
return Constant(_core.LLVMConstICmp(int_pred, self.ptr, rhs.ptr))
|
||||
|
||||
def fcmp(self, real_pred, rhs):
|
||||
check_is_constant(rhs)
|
||||
return Constant(_core.LLVMConstFCmp(self.ptr, real_pred, rhs.ptr))
|
||||
return Constant(_core.LLVMConstFCmp(real_pred, self.ptr, rhs.ptr))
|
||||
|
||||
def vicmp(self, int_pred, rhs):
|
||||
check_is_constant(rhs)
|
||||
return Constant(_core.LLVMConstVICmp(int_pred, self.ptr, rhs.ptr))
|
||||
|
||||
def vfcmp(self, real_pred, rhs):
|
||||
check_is_constant(rhs)
|
||||
return Constant(_core.LLVMConstVFCmp(real_pred, self.ptr, rhs.ptr))
|
||||
|
||||
def shl(self, rhs):
|
||||
check_is_constant(rhs)
|
||||
|
|
@ -749,16 +761,16 @@ class Constant(Value):
|
|||
check_is_constant(false_const)
|
||||
return Constant(_core.LLVMConstSelect(self.ptr, true_const.ptr, false_const.ptr))
|
||||
|
||||
def extract(self, index): # note: self must be a _vector_ constant
|
||||
def extract_element(self, index): # note: self must be a _vector_ constant
|
||||
check_is_constant(index)
|
||||
return Constant(_core.LLVMConstExtractElement(self.ptr, index.ptr))
|
||||
|
||||
def insert(self, value, index): # note: self must be a _vector_ constant
|
||||
def insert_element(self, value, index): # note: self must be a _vector_ constant
|
||||
check_is_constant(value)
|
||||
check_is_constant(index)
|
||||
return Constant(_core.LLVMConstInsertElement(self.ptr, value.ptr, index.ptr))
|
||||
|
||||
def shuffle(self, vector_b, mask): # note: self must be a _vector_ constant
|
||||
def shuffle_element(self, vector_b, mask): # note: self must be a _vector_ constant
|
||||
check_is_constant(vector_b) # note: vector_b must be a _vector_ constant
|
||||
check_is_constant(mask)
|
||||
return Constant(_core.LLVMConstShuffleVector(self.ptr, vector_b.ptr, mask.ptr))
|
||||
|
|
@ -1035,11 +1047,15 @@ class Builder(object):
|
|||
|
||||
def ret_void(self):
|
||||
return Instruction(_core.LLVMBuildRetVoid(self.ptr))
|
||||
|
||||
|
||||
def ret(self, value):
|
||||
check_is_value(value)
|
||||
return Instruction(_core.LLVMBuildRet(self.ptr, value.ptr))
|
||||
|
||||
|
||||
def ret_many(self, values):
|
||||
vs = unpack_values(values)
|
||||
return Instruction(_core.LLVMBuildRetMultiple(self.ptr, vs))
|
||||
|
||||
def branch(self, bblk):
|
||||
check_is_basic_block(bblk)
|
||||
return Instruction(_core.LLVMBuildBr(self.ptr, bblk.ptr))
|
||||
|
|
@ -1265,8 +1281,22 @@ class Builder(object):
|
|||
check_is_value(rhs)
|
||||
return Value(_core.LLVMBuildFCmp(self.ptr, rpred, lhs.ptr, rhs.ptr, name))
|
||||
|
||||
def vicmp(self, ipred, lhs, rhs, name=""):
|
||||
check_is_value(lhs)
|
||||
check_is_value(rhs)
|
||||
return Value(_core.LLVMBuildVICmp(self.ptr, ipred, lhs.ptr, rhs.ptr, name))
|
||||
|
||||
def vfcmp(self, rpred, lhs, rhs, name=""):
|
||||
check_is_value(lhs)
|
||||
check_is_value(rhs)
|
||||
return Value(_core.LLVMBuildVFCmp(self.ptr, rpred, lhs.ptr, rhs.ptr, name))
|
||||
|
||||
# misc
|
||||
|
||||
def getresult(self, retval, idx, name=""):
|
||||
check_is_value(retval)
|
||||
return PHINode(_core.LLVMBuildGetResult(self.ptr, retval.ptr, idx, name))
|
||||
|
||||
def phi(self, ty, name=""):
|
||||
check_is_type(ty)
|
||||
return PHINode(_core.LLVMBuildPhi(self.ptr, ty.ptr, name))
|
||||
|
|
|
|||
|
|
@ -41,3 +41,45 @@ char *LLVMDumpValueToString(LLVMValueRef Val) {
|
|||
return strdup(buf.str().c_str());
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMConstVICmp(LLVMIntPredicate Predicate,
|
||||
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||
return wrap(ConstantExpr::getVICmp(Predicate,
|
||||
unwrap<Constant>(LHSConstant),
|
||||
unwrap<Constant>(RHSConstant)));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate Predicate,
|
||||
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||
return wrap(ConstantExpr::getVFCmp(Predicate,
|
||||
unwrap<Constant>(LHSConstant),
|
||||
unwrap<Constant>(RHSConstant)));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef B, LLVMValueRef *Values,
|
||||
unsigned NumValues) {
|
||||
std::vector<Value *> Vs;
|
||||
for (LLVMValueRef *I = Values, *E = Values + NumValues; I != E; ++I)
|
||||
Vs.push_back(unwrap(*I));
|
||||
|
||||
return wrap(unwrap(B)->CreateRet(&Vs[0], NumValues));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
|
||||
LLVMValueRef LHS, LLVMValueRef RHS,
|
||||
const char *Name) {
|
||||
return wrap(unwrap(B)->CreateVICmp(static_cast<ICmpInst::Predicate>(Op),
|
||||
unwrap(LHS), unwrap(RHS), Name));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
|
||||
LLVMValueRef LHS, LLVMValueRef RHS,
|
||||
const char *Name) {
|
||||
return wrap(unwrap(B)->CreateVFCmp(static_cast<FCmpInst::Predicate>(Op),
|
||||
unwrap(LHS), unwrap(RHS), Name));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef B, LLVMValueRef V,
|
||||
unsigned Index, const char *Name) {
|
||||
return wrap(unwrap(B)->CreateGetResult(unwrap(V), Index, Name));
|
||||
}
|
||||
|
||||
|
|
|
|||
20
llvm/extra.h
20
llvm/extra.h
|
|
@ -23,6 +23,26 @@ char *LLVMDumpTypeToString(LLVMTypeRef Ty);
|
|||
LLVMDisposeMessage, after use. */
|
||||
char *LLVMDumpValueToString(LLVMValueRef Val);
|
||||
|
||||
/* missing constant expressions */
|
||||
|
||||
LLVMValueRef LLVMConstVICmp(LLVMIntPredicate Predicate,
|
||||
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate Predicate,
|
||||
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||
|
||||
/* missing instructions */
|
||||
|
||||
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef, LLVMValueRef *Values,
|
||||
unsigned NumValues);
|
||||
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef, LLVMIntPredicate Op,
|
||||
LLVMValueRef LHS, LLVMValueRef RHS,
|
||||
const char *Name);
|
||||
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
|
||||
LLVMValueRef LHS, LLVMValueRef RHS,
|
||||
const char *Name);
|
||||
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef, LLVMValueRef V,
|
||||
unsigned Index, const char *Name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
23
llvm/wrap.h
23
llvm/wrap.h
|
|
@ -464,6 +464,29 @@ _w ## func (PyObject *self, PyObject *args) \
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrap LLVM functions of the type
|
||||
* outtype func(intype1 arg1, intype2 arg2, int arg3, const char *arg4)
|
||||
*/
|
||||
#define _wrap_objobjintstr2obj(func, intype1, intype2, outtype) \
|
||||
static PyObject * \
|
||||
_w ## func (PyObject *self, PyObject *args) \
|
||||
{ \
|
||||
PyObject *obj1, *obj2; \
|
||||
intype1 arg1; \
|
||||
intype2 arg2; \
|
||||
int arg3; \
|
||||
const char *arg4; \
|
||||
\
|
||||
if (!PyArg_ParseTuple(args, "OOis", &obj1, &obj2, &arg3, &arg4)) \
|
||||
return NULL; \
|
||||
\
|
||||
arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \
|
||||
arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \
|
||||
\
|
||||
return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)) ;\
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap LLVM functions of the type
|
||||
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -38,19 +38,27 @@
|
|||
<p>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).</p>
|
||||
<p>Many thanks to the guys over at LLVM for all the nifty software, and a
|
||||
helpful mailing list.</p>
|
||||
<p>Many thanks to the guys over at LLVM for all the nifty software.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 10-Jun-2008.
|
||||
Last updated 11-Jun-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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>
|
||||
|
|
|
|||
|
|
@ -91,5 +91,14 @@ Last updated 10-Jun-2008.
|
|||
</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>
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ package.</p>
|
|||
<div class="sectionbody">
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>0.2, ongoing:
|
||||
<pre><tt>0.2, xx-Jun-2008:
|
||||
|
||||
* Independent package, need not be unpacked into llvm/bindings
|
||||
* Fixed ownership issues with Module/ModuleProvider
|
||||
|
|
@ -126,7 +126,6 @@ package.</p>
|
|||
|
||||
* Initial release.
|
||||
|
||||
|
||||
</tt></pre>
|
||||
</div></div>
|
||||
</div>
|
||||
|
|
@ -140,5 +139,14 @@ Last updated 10-Jun-2008.
|
|||
</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>
|
||||
|
|
|
|||
|
|
@ -110,5 +110,14 @@ Last updated 10-Jun-2008.
|
|||
</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>
|
||||
|
|
|
|||
|
|
@ -67,5 +67,14 @@ Last updated 10-Jun-2008.
|
|||
</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>
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@
|
|||
</div>
|
||||
<div id="preamble">
|
||||
<div class="sectionbody">
|
||||
<p><em>llvm-py</em> is distributed under the
|
||||
<p>llvm-py is distributed under the
|
||||
<a href="http://www.opensource.org/licenses/bsd-license.php">new BSD license</a>.
|
||||
This is similar to LLVM's license. You should be able to use <em>llvm-py</em>
|
||||
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.</p>
|
||||
<p>The license text is present in the
|
||||
<a href="http://code.google.com/p/llvm-py/source/browse/trunk/LICENSE">LICENSE</a>
|
||||
|
|
@ -76,12 +76,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</tt></pre>
|
|||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 10-Jun-2008.
|
||||
Last updated 11-Jun-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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>
|
||||
|
|
|
|||
|
|
@ -224,8 +224,6 @@ 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.</p>
|
||||
<p>The full set of instructions are:</p>
|
||||
<p>TODO</p>
|
||||
<h3>SSA Form and PHI Nodes</h3>
|
||||
<p>All LLVM instructions are represented in the <em>Static Single Assignment</em>
|
||||
(SSA) form. Essentially, this means that any variable can be assigned to
|
||||
|
|
@ -261,7 +259,7 @@ LLVM instruction set has an instruction called <tt>phi</tt>.</p>
|
|||
<h3>LLVM Assembly Language</h3>
|
||||
<p>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 <em>same</em> information. Each format can be
|
||||
|
|
@ -269,26 +267,215 @@ converted into the other two formats (using LLVM APIs).</p>
|
|||
<p>The <a href="http://www.llvm.org/demo/">LLVM demo page</a> lets you type in C or C++
|
||||
code, converts it into LLVM IR and outputs the IR as LLVM assembly
|
||||
language code.</p>
|
||||
<p>Here's a function in C, that calculates the sum of the first <em>n</em>
|
||||
fibonacci numbers:</p>
|
||||
<p>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):</p>
|
||||
<div class="listingblock">
|
||||
<div class="content"><!-- Generator: GNU source-highlight 2.4
|
||||
by Lorenzo Bettini
|
||||
http://www.lorenzobettini.it
|
||||
http://www.gnu.org/software/src-highlite -->
|
||||
<pre><tt><span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">fibsum</span></span><span style="color: #990000">(</span><span style="color: #009900">int</span> n<span style="color: #990000">)</span>
|
||||
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">/* compute sum of 1..n */</span></span>
|
||||
<span style="color: #009900">unsigned</span> <span style="font-weight: bold"><span style="color: #000000">sum</span></span><span style="color: #990000">(</span><span style="color: #009900">unsigned</span> n<span style="color: #990000">)</span>
|
||||
<span style="color: #FF0000">{</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>n <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">return</span></span> n <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #000000">sum</span></span><span style="color: #990000">(</span>n<span style="color: #990000">-</span><span style="color: #993399">1</span><span style="color: #990000">);</span>
|
||||
<span style="color: #FF0000">}</span>
|
||||
</tt></pre></div></div>
|
||||
<p>And here's the corresponding LLVM assembly listing, as provided by the
|
||||
demo page:</p>
|
||||
<p>The corresponding LLVM assembly:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt></tt></pre>
|
||||
<pre><tt>; 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"
|
||||
|
||||
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
|
||||
}</tt></pre>
|
||||
</div></div>
|
||||
<p>Note the … TODO …</p>
|
||||
<p>Note the usage of SSA form and the total absence of any loop or
|
||||
recursion at all!</p>
|
||||
<p>The <a href="http://www.llvm.org/docs/LangRef.html">LLVM Language Reference</a>
|
||||
defines the LLVM assembly language including the entire instruction set.</p>
|
||||
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.</p>
|
||||
<div class="tableblock">
|
||||
<table rules="all"
|
||||
frame="border"
|
||||
cellspacing="0" cellpadding="4">
|
||||
<caption class="title">Table: LLVM Instruction Set</caption>
|
||||
<col width="240" />
|
||||
<col width="560" />
|
||||
<thead>
|
||||
<tr>
|
||||
<th align="left">
|
||||
Category
|
||||
</th>
|
||||
<th align="left">
|
||||
Instructions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr>
|
||||
<td align="left">
|
||||
Terminator instructions
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_ret">ret</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_br">br</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_switch">switch</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_invoke">invoke</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_unwind">unwind</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_unreachable">unreachable</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Binary operations
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_add">add</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_sub">sub</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_mul">mul</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_udiv">udiv</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_sdiv">sdiv</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_fdiv">fdiv</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_urem">urem</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_srem">srem</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_frem">frem</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Bitwise binary operations
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_shl">shl</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_lshr">lshr</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_ashr">ashr</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_and">and</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_or">or</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_xor">xor</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Vector operations
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_extractelement">extractelement</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_insertelement">insertelement</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_shufflevector">shufflevector</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Aggregate operations
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_extractvalue">extractvalue</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_insertvalue">insertvalue</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Memory access and addressing operations
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_malloc">malloc</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_free">free</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_alloca">alloca</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_load">load</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_store">store</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_getelementptr">getelementptr</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Conversion operations
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_trunc">trunc</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_zext">zext</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_sext">sext</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_fptrunc">fptrunc</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_fpext">fpext</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_fptoui">fptoui</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_fptosi">fptosi</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_uitofp">uitofp</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_sitofp">sitofp</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_ptrtoint">ptrtoint</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_inttoptr">inttoptr</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_bitcast">bitcast</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Other operations
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#i_icmp">icmp</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_fcmp">fcmp</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_vicmp">vicmp</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_vfcmp">vfcmp</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_phi">phi</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_select">select</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_call">call</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_va_arg">va_arg</a>, <a href="http://www.llvm.org/docs/LangRef.html#i_getresult">getresult</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Variable argument handling intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#int_va_start">llvm.va_start</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_va_end">llvm.va_end</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_va_copy">llvm.va_copy</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Accurate garbage collection intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#int_returnaddress">llvm.returnaddress</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_frameaddress">llvm.frameaddress</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_stacksave">llvm.stacksave</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_stackrestore">llvm.stackrestore</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_prefetch">llvm.prefetch</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_pcmarker">llvm.pcmarker</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_readcyclecounter">llvm.readcyclecounter</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Standard C library intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#int_memcpy">llvm.memcpy.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_memmove">llvm.memmove.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_memset">llvm.memset.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_sqrt">llvm.sqrt.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_powi">llvm.powi.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_sin">llvm.sin.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_cos">llvm.cos.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_pow">llvm.pow.*</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Bit manipulation intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#int_bswap">llvm.bswap.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_ctpop">llvm.ctpop.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_ctlz">llvm.ctlz.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_cttz">llvm.cttz.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_part_select">llvm.part.select.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_part_set">llvm.part.set.*</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Debugger intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_stoppoint">llvm.dbg.stoppoint</a>, <a href="http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_func_start">llvm.dbg.func.start</a>, <a href="http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_region_start">llvm.dbg.region.start</a>, <a href="http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_region_end">llvm.dbg.region.end</a>, <a href="http://www.llvm.org/docs/SourceLevelDebugging.html#format_common_declare">llvm.dbg.declare</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Exception handling intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/ExceptionHandling.html#llvm_eh_exception">llvm.eh_exception</a>, <a href="http://www.llvm.org/docs/ExceptionHandling.html#llvm_eh_selector">llvm.eh_selector</a>, <a href="http://www.llvm.org/docs/ExceptionHandling.html#llvm_eh_typeid_for">llvm.eh_typeid_for</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Trampoline intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#int_it">llvm.init.trampoline</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
Atomic intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#int_memory_barrier">llvm.memory.barrier</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_atomic_lcs">llvm.atomic.lcs</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_atomic_las">llvm.atomic.las</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_atomic_swap">llvm.atomic.swap</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">
|
||||
General intrinsics
|
||||
</td>
|
||||
<td align="left">
|
||||
<a href="http://www.llvm.org/docs/LangRef.html#int_var_annotation">llvm.var.annotation</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_annotation">llvm.annotation.*</a>, <a href="http://www.llvm.org/docs/LangRef.html#int_trap">llvm.trap</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p>Intrinsics (instructions that start with <tt>llvm.</tt>) are not yet available
|
||||
in llvm-py.</p>
|
||||
<h3>Modules</h3>
|
||||
<p>Modules, in the LLVM IR, are similar to a single <em>C</em> language source
|
||||
file (.c file). A module contains:</p>
|
||||
|
|
@ -330,8 +517,7 @@ 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>
|
||||
<p>Passes are run using a <em>pass manager</em>. For our purposes, there are two
|
||||
pass managers TODO</p>
|
||||
<p>Passes are run using a <em>pass manager</em>. TODO</p>
|
||||
<h3>Execution Engine</h3>
|
||||
<p>TODO</p>
|
||||
<h3>BitCode</h3>
|
||||
|
|
@ -374,9 +560,10 @@ public modules. These are:</p>
|
|||
Python constructs are used (deliberately) —
|
||||
<a href="http://docs.python.org/lib/built-in-funcs.html">property()</a> and
|
||||
<a href="http://wiki.python.org/moin/PythonDecoratorLibrary">property
|
||||
decorators</a> 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.</p>
|
||||
decorators</a> 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.</p>
|
||||
<p>Here is a quick overview of the contents of each package:</p>
|
||||
<div class="title">llvm</div><ul>
|
||||
<li>
|
||||
|
|
@ -559,7 +746,112 @@ corresponding classes. Constructors <em>should not</em> be used.</p>
|
|||
</td>
|
||||
</tr></table>
|
||||
</div>
|
||||
<p>The argument <em>my_module</em> is a module identifier (a plain string).</p>
|
||||
<p>The argument <tt>my_module</tt> is a module identifier (a plain string). The
|
||||
attributes of the <tt>Module</tt> class is:</p>
|
||||
<div class="exampleblock">
|
||||
<div class="title">llvm.core.Module</div>
|
||||
<div class="exampleblock-content">
|
||||
<div class="title">Static Constructors</div><dl>
|
||||
<dt>
|
||||
<tt>new(module_id)</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
create a new <tt>Module</tt> instance with given <tt>module_id</tt>. The <tt>module_id</tt>
|
||||
should be a string.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="title">Properties</div><dl>
|
||||
<dt>
|
||||
<tt>data_layout</tt> (r/w)
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
a string representing the ABI of the platform
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>target</tt> (r/w)
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
a string like <tt>i386-pc-linux-gnu</tt> or <tt>i386-pc-solaris2.8</tt>
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>global_variables</tt> (r)
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>functions</tt> (r)
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="title">Methods</div><dl>
|
||||
<dt>
|
||||
<tt>add_type_name</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>delete_type_name</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>add_global_variable</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>get_global_variable_named</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="title">Special Methods</div><dl>
|
||||
<dt>
|
||||
<tt>__str__</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Module objects can be stringified into it's LLVM assembly language
|
||||
representation.
|
||||
</p>
|
||||
</dd>
|
||||
<dt>
|
||||
<tt>__eq__</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
Module objects can be compared for equality. Internally, this
|
||||
converts both into their LLVM assembly representations and compares
|
||||
them.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div></div>
|
||||
<h3>Types (llvm.core)</h3>
|
||||
<p>Types are what you think they are. A instance of <tt>llvm.core.Type</tt>, or
|
||||
one of its derived classes, represent a type. llvm-py does not use as
|
||||
|
|
@ -761,6 +1053,17 @@ cellspacing="0" cellpadding="4">
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p>The class hierarchy is:</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>Type
|
||||
IntegerType
|
||||
FunctionType
|
||||
StructType
|
||||
ArrayType
|
||||
PointerType
|
||||
VectorType</tt></pre>
|
||||
</div></div>
|
||||
<h3>Values (llvm.core)</h3>
|
||||
<p>TODO</p>
|
||||
<h3>Instructions (llvm.core)</h3>
|
||||
|
|
@ -806,12 +1109,21 @@ reached at <em>mdevan.foobar@gmail.com</em>.</p>
|
|||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Web pages © Mahadevan R. Generated with <a href="http://www.methods.co.nz/asciidoc/">asciidoc</a>.
|
||||
Last updated 10-Jun-2008.
|
||||
Last updated 11-Jun-2008.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue