Code cleanup.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@47 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-11-17 16:45:40 +00:00
commit b52355d84e
11 changed files with 588 additions and 212 deletions

View file

@ -1,6 +1,7 @@
0.4, in progress: 0.4, in progress:
* Code cleanup, added license headers.
* Added llvm.core.load_library_permanently() (Issue #12). * Added llvm.core.load_library_permanently() (Issue #12).
* Fix comparison using != (Issue #11). * Fix comparison using != (Issue #11).
* Instruction.is_terminator added. * Instruction.is_terminator added.

View file

@ -1,3 +1,33 @@
#
# Copyright (c) 2008, Mahadevan R All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of this software, nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""Common classes related to LLVM. """Common classes related to LLVM.
""" """

View file

@ -1,3 +1,32 @@
/*
* Copyright (c) 2008, Mahadevan R All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of this software, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* our includes */ /* our includes */
#include "wrap.h" #include "wrap.h"
@ -427,13 +456,11 @@ _wrap_obj2none(LLVMViewFunctionCFGOnly, LLVMValueRef)
static PyObject * static PyObject *
_wLLVMVerifyFunction(PyObject *self, PyObject *args) _wLLVMVerifyFunction(PyObject *self, PyObject *args)
{ {
PyObject *obj;
LLVMValueRef fn; LLVMValueRef fn;
if (!PyArg_ParseTuple(args, "O", &obj)) if (!(fn = (LLVMValueRef)get_object_arg(args)))
return NULL; return NULL;
fn = (LLVMValueRef) PyCObject_AsVoidPtr(obj);
return ctor_int(LLVMVerifyFunction(fn, LLVMReturnStatusAction)); return ctor_int(LLVMVerifyFunction(fn, LLVMReturnStatusAction));
} }
@ -473,8 +500,8 @@ _wrap_obj2obj(LLVMInstIsArithmeticShift, LLVMValueRef, int)
_wrap_obj2obj(LLVMInstIsAssociative, LLVMValueRef, int) _wrap_obj2obj(LLVMInstIsAssociative, LLVMValueRef, int)
_wrap_obj2obj(LLVMInstIsCommutative, LLVMValueRef, int) _wrap_obj2obj(LLVMInstIsCommutative, LLVMValueRef, int)
_wrap_obj2obj(LLVMInstIsTrapping, LLVMValueRef, int) _wrap_obj2obj(LLVMInstIsTrapping, LLVMValueRef, int)
_wrap_obj2obj(LLVMInstGetOpcode, LLVMValueRef, int) _wrap_obj2obj(LLVMInstGetOpcode, LLVMValueRef, int)
_wrap_obj2str(LLVMInstGetOpcodeName, LLVMValueRef) _wrap_obj2str(LLVMInstGetOpcodeName, LLVMValueRef)
/*===-- Call Sites (Call or Invoke) --------------------------------------===*/ /*===-- Call Sites (Call or Invoke) --------------------------------------===*/
@ -493,7 +520,7 @@ static void LLVMAddIncoming1(LLVMValueRef PhiNode, LLVMValueRef IncomingValue, L
} }
_wrap_objobjobj2none(LLVMAddIncoming1, LLVMValueRef, LLVMValueRef, LLVMBasicBlockRef) _wrap_objobjobj2none(LLVMAddIncoming1, LLVMValueRef, LLVMValueRef, LLVMBasicBlockRef)
_wrap_obj2obj(LLVMCountIncoming, LLVMValueRef, int) _wrap_obj2obj(LLVMCountIncoming, LLVMValueRef, int)
_wrap_objint2obj(LLVMGetIncomingValue, LLVMValueRef, LLVMValueRef) _wrap_objint2obj(LLVMGetIncomingValue, LLVMValueRef, LLVMValueRef)
_wrap_objint2obj(LLVMGetIncomingBlock, LLVMValueRef, LLVMBasicBlockRef) _wrap_objint2obj(LLVMGetIncomingBlock, LLVMValueRef, LLVMBasicBlockRef)
@ -766,15 +793,13 @@ _wrap_obj2none(LLVMDisposeTargetData, LLVMTargetDataRef)
static PyObject * static PyObject *
_wLLVMTargetDataAsString(PyObject *self, PyObject *args) _wLLVMTargetDataAsString(PyObject *self, PyObject *args)
{ {
PyObject *obj;
LLVMTargetDataRef td; LLVMTargetDataRef td;
char *tdrep = 0; char *tdrep = 0;
PyObject *ret; PyObject *ret;
if (!PyArg_ParseTuple(args, "O", &obj)) if (!(td = (LLVMTargetDataRef)get_object_arg(args)))
return NULL; return NULL;
td = (LLVMTargetDataRef) PyCObject_AsVoidPtr(obj);
tdrep = LLVMCopyStringRepOfTargetData(td); tdrep = LLVMCopyStringRepOfTargetData(td);
ret = PyString_FromString(tdrep); ret = PyString_FromString(tdrep);
LLVMDisposeMessage(tdrep); LLVMDisposeMessage(tdrep);

View file

@ -1,3 +1,33 @@
#
# Copyright (c) 2008, Mahadevan R All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of this software, nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""Utility functions and classes. """Utility functions and classes.
Used only in other modules, not for public use.""" Used only in other modules, not for public use."""

View file

@ -1,3 +1,33 @@
#
# Copyright (c) 2008, Mahadevan R All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of this software, nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""Core classes of LLVM. """Core classes of LLVM.
The llvm.core module contains classes and constants required to build the The llvm.core module contains classes and constants required to build the
@ -880,6 +910,8 @@ class Module(llvm.Ownable):
return Function.get(self, name) return Function.get(self, name)
def get_or_insert_function(self, ty, name): def get_or_insert_function(self, ty, name):
"""Like get_function_named(), but does add_function() first, if
function is not present."""
return Function.get_or_insert(self, ty, name) return Function.get_or_insert(self, ty, name)
@property @property
@ -1143,6 +1175,7 @@ class FunctionType(Type):
class StructType(Type): class StructType(Type):
"""Represents a structure type."""
def __init__(self, ptr, kind): def __init__(self, ptr, kind):
"""DO NOT CALL DIRECTLY. """DO NOT CALL DIRECTLY.
@ -1152,19 +1185,26 @@ class StructType(Type):
@property @property
def element_count(self): def element_count(self):
"""Number of elements (members) in the structure.
Same as len(obj.elements), but faster."""
return _core.LLVMCountStructElementTypes(self.ptr) return _core.LLVMCountStructElementTypes(self.ptr)
@property @property
def elements(self): def elements(self):
"""An iterable that yieldsd Type objects, representing the types of the
elements (members) of the structure, in order."""
pp = _core.LLVMGetStructElementTypes(self.ptr) pp = _core.LLVMGetStructElementTypes(self.ptr)
return [ _make_type(p, _core.LLVMGetTypeKind(p)) for p in pp ] return [ _make_type(p, _core.LLVMGetTypeKind(p)) for p in pp ]
@property @property
def packed(self): def packed(self):
"""True if the structure is packed, False otherwise."""
return _core.LLVMIsPackedStruct(self.ptr) != 0 return _core.LLVMIsPackedStruct(self.ptr) != 0
class ArrayType(Type): class ArrayType(Type):
"""Represents an array type."""
def __init__(self, ptr, kind): def __init__(self, ptr, kind):
"""DO NOT CALL DIRECTLY. """DO NOT CALL DIRECTLY.

View file

@ -1,3 +1,33 @@
#
# Copyright (c) 2008, Mahadevan R All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of this software, nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""Execution Engine and related classes. """Execution Engine and related classes.
""" """

View file

@ -1,14 +1,46 @@
/*
* Copyright (c) 2008, Mahadevan R All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of this software, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** /**
* These are some "extra" functions not available in the standard LLVM-C * These are some "extra" functions not available in the standard LLVM-C
* bindings, but are required / good-to-have inorder to implement the * bindings, but are required / good-to-have inorder to implement the
* Python bindings. * Python bindings.
*/ */
// standard includes
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
// LLVM includes
#include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
@ -22,202 +54,271 @@
#include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Verifier.h"
#include "llvm/Assembly/Parser.h" #include "llvm/Assembly/Parser.h"
#include "llvm/System/DynamicLibrary.h" #include "llvm/System/DynamicLibrary.h"
// +includes for passes
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/LoopPass.h"
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h" #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
#include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation.h"
// -includes for passes
// LLVM-C includes
#include "llvm-c/Core.h" #include "llvm-c/Core.h"
// our includes
#include "extra.h" #include "extra.h"
using namespace llvm; //using namespace llvm;
char *LLVMDumpModuleToString(LLVMModuleRef M) { /* Helper method for LLVMDumpXXXToString() methods. */
std::ostringstream buf; template <typename W, typename UW>
unwrap(M)->print(buf); char *do_print(W obj)
return strdup(buf.str().c_str());
}
char *LLVMDumpTypeToString(LLVMTypeRef Ty) {
std::ostringstream buf;
unwrap(Ty)->print(buf);
return strdup(buf.str().c_str());
}
char *LLVMDumpValueToString(LLVMValueRef Val) {
std::ostringstream buf;
unwrap(Val)->print(buf);
return strdup(buf.str().c_str());
}
#if 0 /* after LLVM 2.3! */
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 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));
}
#endif
unsigned LLVMModuleGetPointerSize(LLVMModuleRef M)
{ {
Module::PointerSize p = unwrap(M)->getPointerSize(); std::ostringstream buf;
if (p == Module::Pointer32) UW *p = llvm::unwrap(obj);
assert(p);
p->print(buf);
return strdup(buf.str().c_str());
}
char *LLVMDumpModuleToString(LLVMModuleRef module)
{
return do_print<LLVMModuleRef, llvm::Module>(module);
}
char *LLVMDumpTypeToString(LLVMTypeRef type)
{
return do_print<LLVMTypeRef, llvm::Type>(type);
}
char *LLVMDumpValueToString(LLVMValueRef value)
{
return do_print<LLVMValueRef, llvm::Value>(value);
}
unsigned LLVMModuleGetPointerSize(LLVMModuleRef module)
{
llvm::Module *modulep = llvm::unwrap(module);
assert(modulep);
llvm::Module::PointerSize p = modulep->getPointerSize();
if (p == llvm::Module::Pointer32)
return 32; return 32;
else if (p == Module::Pointer64) else if (p == llvm::Module::Pointer64)
return 64; return 64;
return 0; return 0;
} }
LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef M, LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef module,
const char *Name, LLVMTypeRef FunctionTy) const char *name, LLVMTypeRef function_type)
{ {
FunctionType *ft = unwrap<FunctionType>(FunctionTy); assert(name);
Constant *f = unwrap(M)->getOrInsertFunction(Name, ft);
llvm::Module *modulep = llvm::unwrap(module);
assert(modulep);
llvm::FunctionType *ftp = llvm::unwrap<llvm::FunctionType>(function_type);
assert(ftp);
llvm::Constant *f = modulep->getOrInsertFunction(name, ftp);
return wrap(f); return wrap(f);
} }
#define inst_checkfn(ourfn, llvmfn) \ #define inst_checkfn(ourfn, llvmfn) \
unsigned ourfn (LLVMValueRef I) { \ unsigned ourfn (LLVMValueRef v) { \
return unwrap<Instruction>(I)-> llvmfn () ? 1 : 0; \ llvm::Instruction *ip = llvm::unwrap<llvm::Instruction>(v); \
assert(ip); \
return ip-> llvmfn () ? 1 : 0; \
}
inst_checkfn(LLVMInstIsTerminator, isTerminator)
inst_checkfn(LLVMInstIsBinaryOp, isBinaryOp)
inst_checkfn(LLVMInstIsShift, isShift)
inst_checkfn(LLVMInstIsCast, isCast)
inst_checkfn(LLVMInstIsLogicalShift, isLogicalShift)
inst_checkfn(LLVMInstIsArithmeticShift, isArithmeticShift)
inst_checkfn(LLVMInstIsAssociative, isAssociative)
inst_checkfn(LLVMInstIsCommutative, isCommutative)
inst_checkfn(LLVMInstIsTrapping, isTrapping)
const char *LLVMInstGetOpcodeName(LLVMValueRef inst)
{
llvm::Instruction *instp = llvm::unwrap<llvm::Instruction>(inst);
assert(instp);
return instp->getOpcodeName();
}
unsigned LLVMInstGetOpcode(LLVMValueRef inst)
{
llvm::Instruction *instp = llvm::unwrap<llvm::Instruction>(inst);
assert(instp);
return instp->getOpcode();
}
/* llvm::unwrap a set of `n' wrapped objects starting at `values',
* into a vector of pointers to llvm::unwrapped objects `out'. */
template <typename W, typename UW>
void unwrap_vec(W *values, unsigned n, std::vector<UW *>& out)
{
out.clear();
while (n--) {
UW *p = llvm::unwrap(*values);
assert(p);
out.push_back(p);
++values;
} }
}
inst_checkfn(LLVMInstIsTerminator, isTerminator) /* Same as llvm::unwrap_vec, but use a vector of const pointers. */
inst_checkfn(LLVMInstIsBinaryOp, isBinaryOp) template <typename W, typename UW>
inst_checkfn(LLVMInstIsShift, isShift) void unwrap_cvec(W *values, unsigned n, std::vector<const UW *>& out)
inst_checkfn(LLVMInstIsCast, isCast)
inst_checkfn(LLVMInstIsLogicalShift,isLogicalShift)
inst_checkfn(LLVMInstIsArithmeticShift,isArithmeticShift)
inst_checkfn(LLVMInstIsAssociative, isAssociative)
inst_checkfn(LLVMInstIsCommutative, isCommutative)
inst_checkfn(LLVMInstIsTrapping, isTrapping)
const char *LLVMInstGetOpcodeName(LLVMValueRef I)
{ {
return unwrap<Instruction>(I)->getOpcodeName(); out.clear();
while (n--) {
UW *p = llvm::unwrap(*values);
assert(p);
out.push_back(p);
++values;
}
} }
unsigned LLVMInstGetOpcode(LLVMValueRef I) LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef builder,
LLVMValueRef *values, unsigned n_values)
{ {
return unwrap<Instruction>(I)->getOpcode(); assert(values);
std::vector<llvm::Value *> values_vec;
unwrap_vec(values, n_values, values_vec);
llvm::IRBuilder *builderp = llvm::unwrap(builder);
assert(builderp);
return wrap(builderp->CreateRet(&values_vec[0], values_vec.size()));
} }
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef B, LLVMValueRef *Values, LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder,
unsigned NumValues) { LLVMValueRef value, unsigned index, const char *name)
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 LLVMBuildGetResult(LLVMBuilderRef B, LLVMValueRef V,
unsigned Index, const char *Name) {
return wrap(unwrap(B)->CreateGetResult(unwrap(V), Index, Name));
}
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef M, int ID,
LLVMTypeRef *Types, unsigned Count)
{ {
std::vector<const Type*> Tys; assert(name);
for (LLVMTypeRef *I = Types, *E = Types + Count; I != E; ++I)
Tys.push_back(unwrap(*I));
Function *intfunc = Intrinsic::getDeclaration(unwrap(M), llvm::IRBuilder *builderp = llvm::unwrap(builder);
Intrinsic::ID(ID), &Tys[0], Count); assert(builderp);
return wrap(builderp->CreateGetResult(llvm::unwrap(value), index, name));
}
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef module, int id,
LLVMTypeRef *types, unsigned n_types)
{
assert(types);
std::vector<const llvm::Type*> types_vec;
unwrap_cvec(types, n_types, types_vec);
llvm::Module *modulep = llvm::unwrap(module);
assert(modulep);
llvm::Function *intfunc = llvm::Intrinsic::getDeclaration(modulep,
llvm::Intrinsic::ID(id), &types_vec[0], types_vec.size());
return wrap(intfunc); return wrap(intfunc);
} }
LLVMModuleRef LLVMGetModuleFromAssembly(const char *A, unsigned Len, LLVMModuleRef LLVMGetModuleFromAssembly(const char *asmtext, unsigned txtlen,
char **OutMessage) char **out)
{ {
ParseError e; assert(asmtext);
assert(out);
Module *MP = ParseAssemblyString(A, NULL /*unused within!*/, &e); llvm::Module *modulep;
if (!MP) { llvm::ParseError error;
*OutMessage = strdup(e.getMessage().c_str()); if (!(modulep = llvm::ParseAssemblyString(asmtext, NULL /*unused within!*/,
&error))) {
*out = strdup(error.getMessage().c_str());
return NULL; return NULL;
} }
return wrap(MP); return wrap(modulep);
} }
LLVMModuleRef LLVMGetModuleFromBitcode(const char *BC, unsigned Len, LLVMModuleRef LLVMGetModuleFromBitcode(const char *bitcode, unsigned bclen,
char **OutMessage) char **out)
{ {
MemoryBuffer *mb = MemoryBuffer::getMemBufferCopy(BC, BC+Len); assert(bitcode);
if (!mb) assert(out);
llvm::MemoryBuffer *mbp;
if (!(mbp = llvm::MemoryBuffer::getMemBufferCopy(bitcode, bitcode+bclen)))
return NULL; return NULL;
std::string msg; std::string msg;
LLVMModuleRef mr = wrap(ParseBitcodeFile(mb, &msg)); llvm::Module *modulep;
if (!mr) if (!(modulep = llvm::ParseBitcodeFile(mbp, &msg)))
*OutMessage = strdup(msg.c_str()); *out = strdup(msg.c_str());
delete mb; delete mbp;
return mr; return wrap(modulep);
} }
unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len) unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, unsigned *lenp)
{ {
assert(lenp);
llvm::Module *modulep = llvm::unwrap(module);
assert(modulep);
/* get bc into a string */
std::ostringstream buf; std::ostringstream buf;
WriteBitcodeToFile(unwrap(M), buf); llvm::WriteBitcodeToFile(modulep, buf);
const std::string& s = buf.str(); const std::string& bc = buf.str();
size_t len = s.size();
unsigned char *bytes = (unsigned char *)malloc(len); /* and then into a malloc()-ed block */
size_t bclen = bc.size();
unsigned char *bytes = (unsigned char *)malloc(bclen);
if (!bytes) if (!bytes)
return NULL; return NULL;
memcpy(bytes, s.data(), len); memcpy(bytes, bc.data(), bclen);
*Len = len;
/* return */
*lenp = bclen;
return bytes; return bytes;
} }
/* Return 0 on failure (with ErrMsg filled in), 1 on success. */ /* Return 0 on failure (with errmsg filled in), 1 on success. */
unsigned LLVMLoadLibraryPermanently(const char* filename, char **ErrMsg) unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg)
{ {
std::string msg; assert(filename);
assert(errmsg);
/* Note: the LLVM API returns true on failure. Don't ask why. */ /* Note: the LLVM API returns true on failure. Don't ask why. */
if (sys::DynamicLibrary::LoadLibraryPermanently(filename, &msg)) { std::string msg;
*ErrMsg = strdup(msg.c_str()); if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(filename, &msg)) {
*errmsg = strdup(msg.c_str());
return 0; return 0;
} }
return 1; return 1;
} }
/* passes */
#define define_pass(P) \ /* Passes. A few passes (listed below) are used directly from LLVM-C,
void LLVMAdd ## P ## Pass (LLVMPassManagerRef PM) { \ * rest are defined here.
unwrap(PM)->add( create ## P ## Pass ()); \ *
* ConstantPropagation
* GVN
* InstructionCombining
* PromoteMemoryToRegister
* Reassociate
* CFGSimplification
*/
#define define_pass(P) \
void LLVMAdd ## P ## Pass (LLVMPassManagerRef passmgr) { \
using namespace llvm; \
llvm::PassManagerBase *pmp = llvm::unwrap(passmgr); \
assert(pmp); \
pmp->add( create ## P ## Pass ()); \
} }
define_pass( AggressiveDCE ) define_pass( AggressiveDCE )
@ -227,7 +328,6 @@ define_pass( BreakCriticalEdges )
define_pass( CodeGenPrepare ) define_pass( CodeGenPrepare )
define_pass( CondPropagation ) define_pass( CondPropagation )
define_pass( ConstantMerge ) define_pass( ConstantMerge )
//LLVM-C define_pass( ConstantPropagation )
define_pass( DeadCodeElimination ) define_pass( DeadCodeElimination )
define_pass( DeadArgElimination ) define_pass( DeadArgElimination )
define_pass( DeadTypeElimination ) define_pass( DeadTypeElimination )
@ -236,7 +336,6 @@ define_pass( DeadStoreElimination )
define_pass( GCSE ) define_pass( GCSE )
define_pass( GlobalDCE ) define_pass( GlobalDCE )
define_pass( GlobalOptimizer ) define_pass( GlobalOptimizer )
//LLVM-C define_pass( GVN )
define_pass( GVNPRE ) define_pass( GVNPRE )
define_pass( IndMemRem ) define_pass( IndMemRem )
define_pass( IndVarSimplify ) define_pass( IndVarSimplify )
@ -246,9 +345,8 @@ define_pass( EdgeProfiler )
define_pass( FunctionProfiler ) define_pass( FunctionProfiler )
define_pass( NullProfilerRS ) define_pass( NullProfilerRS )
define_pass( RSProfiling ) define_pass( RSProfiling )
//LLVM-C define_pass( InstructionCombining )
/* we support only internalize(true) */ /* we support only internalize(true) */
ModulePass *createInternalizePass() { return llvm::createInternalizePass(true); } llvm::ModulePass *createInternalizePass() { return llvm::createInternalizePass(true); }
define_pass( Internalize ) define_pass( Internalize )
define_pass( IPConstantPropagation ) define_pass( IPConstantPropagation )
define_pass( IPSCCP ) define_pass( IPSCCP )
@ -268,18 +366,15 @@ define_pass( LowerAllocations )
define_pass( LowerInvoke ) define_pass( LowerInvoke )
define_pass( LowerSetJmp ) define_pass( LowerSetJmp )
define_pass( LowerSwitch ) define_pass( LowerSwitch )
//LLVM-C define_pass( PromoteMemoryToRegister )
define_pass( MemCpyOpt ) define_pass( MemCpyOpt )
define_pass( UnifyFunctionExitNodes ) define_pass( UnifyFunctionExitNodes )
define_pass( PredicateSimplifier ) define_pass( PredicateSimplifier )
define_pass( PruneEH ) define_pass( PruneEH )
define_pass( RaiseAllocations ) define_pass( RaiseAllocations )
//LLVM-C define_pass( Reassociate )
define_pass( DemoteRegisterToMemory ) define_pass( DemoteRegisterToMemory )
define_pass( ScalarReplAggregates ) define_pass( ScalarReplAggregates )
define_pass( SCCP ) define_pass( SCCP )
define_pass( SimplifyLibCalls ) define_pass( SimplifyLibCalls )
//LLVM-C define_pass( CFGSimplification )
define_pass( StripSymbols ) define_pass( StripSymbols )
define_pass( StripDeadPrototypes ) define_pass( StripDeadPrototypes )
define_pass( StructRetPromotion ) define_pass( StructRetPromotion )

View file

@ -1,3 +1,33 @@
/*
* Copyright (c) 2008, Mahadevan R All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of this software, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** /**
* These are some "extra" functions not available in the standard LLVM-C * These are some "extra" functions not available in the standard LLVM-C
* bindings, but are required / good-to-have inorder to implement the * bindings, but are required / good-to-have inorder to implement the
@ -11,81 +41,92 @@
extern "C" { extern "C" {
#endif #endif
/** Dumps module contents to a string. See Module::print. Free the /* Notes:
returned string with LLVMDisposeMessage, after use. */ * - Some returned strings must be disposed of by LLVMDisposeMessage. These are
char *LLVMDumpModuleToString(LLVMModuleRef M); * indicated in the comments. Where it is not indicated, DO NOT call dispose.
*/
/** Dumps type to a string. See Type::print. Free the returned string with /* Wraps llvm::Module::print(). Dispose the returned string after use, via
LLVMDisposeMessage, after use. */ * LLVMDisposeMessage(). */
char *LLVMDumpTypeToString(LLVMTypeRef Ty); char *LLVMDumpModuleToString(LLVMModuleRef module);
/** Dumps value to a string. See Value::print. Free the returned string with /* Wraps llvm::Type::print(). Dispose the returned string after use, via
LLVMDisposeMessage, after use. */ * LLVMDisposeMessage(). */
char *LLVMDumpTypeToString(LLVMTypeRef type);
/* Wraps llvm::Value::print(). Dispose the returned string after use, via
* LLVMDisposeMessage(). */
char *LLVMDumpValueToString(LLVMValueRef Val); char *LLVMDumpValueToString(LLVMValueRef Val);
/* missing constant expressions */ /* Wraps llvm::IRBuilder::CreateRet(). */
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef bulder, LLVMValueRef *values,
unsigned n_values);
#if 0 /* after LLVM 2.3! */ /* Wraps llvm::IRBuilder::CreateGetResult(). */
LLVMValueRef LLVMConstVICmp(LLVMIntPredicate Predicate, LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder, LLVMValueRef value,
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); unsigned index, const char *name);
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate Predicate,
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
/* missing instructions */ /* Wraps llvm::Intrinsic::getDeclaration(). */
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef builder, int id,
LLVMTypeRef *types, unsigned n_types);
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef, LLVMIntPredicate Op, /* Wraps llvm::Module::getPointerSize(). */
LLVMValueRef LHS, LLVMValueRef RHS, unsigned LLVMModuleGetPointerSize(LLVMModuleRef module);
const char *Name);
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
LLVMValueRef LHS, LLVMValueRef RHS,
const char *Name);
#endif
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef, LLVMValueRef *Values, /* Wraps llvm::Module::getOrInsertFunction(). */
unsigned NumValues); LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef module,
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef, LLVMValueRef V, const char *name, LLVMTypeRef function_type);
unsigned Index, const char *Name);
/* intrinsics */ /* The following functions wrap various llvm::Instruction::isXXX() functions.
* All of them take an instruction and return 0 (isXXX returned false) or 1
* (isXXX returned false). */
unsigned LLVMInstIsTerminator (LLVMValueRef inst);
unsigned LLVMInstIsBinaryOp (LLVMValueRef inst);
unsigned LLVMInstIsShift (LLVMValueRef inst);
unsigned LLVMInstIsCast (LLVMValueRef inst);
unsigned LLVMInstIsLogicalShift (LLVMValueRef inst);
unsigned LLVMInstIsArithmeticShift (LLVMValueRef inst);
unsigned LLVMInstIsAssociative (LLVMValueRef inst);
unsigned LLVMInstIsCommutative (LLVMValueRef inst);
unsigned LLVMInstIsTrapping (LLVMValueRef inst);
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef B, int ID, /* Wraps llvm::Instruction::getOpcodeName(). */
LLVMTypeRef *Types, unsigned Count); const char *LLVMInstGetOpcodeName(LLVMValueRef inst);
/* module */ /* Wraps llvm::Instruction::getOpcode(). */
unsigned LLVMInstGetOpcode(LLVMValueRef inst);
unsigned LLVMModuleGetPointerSize(LLVMModuleRef M); /* Wraps llvm::ParseAssemblyString(). Returns a module reference or NULL (with
LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef M, * `out' pointing to an error message). Dispose error message after use, via
const char *Name, LLVMTypeRef FunctionTy); * LLVMDisposeMessage(). */
LLVMModuleRef LLVMGetModuleFromAssembly(const char *asmtxt, unsigned txten,
char **out);
/* instruction */ /* Wraps llvm::ParseBitcodeFile(). Returns a module reference or NULL (with
* `out' pointing to an error message). Dispose error message after use, via
* LLVMDisposeMessage(). */
LLVMModuleRef LLVMGetModuleFromBitcode(const char *bc, unsigned bclen,
char **out);
unsigned LLVMInstIsTerminator(LLVMValueRef I); /* Returns pointer to a heap-allocated block of `*len' bytes containing bit code
unsigned LLVMInstIsBinaryOp(LLVMValueRef I); * for the given module. NULL on error. */
unsigned LLVMInstIsShift(LLVMValueRef I); unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, unsigned *len);
unsigned LLVMInstIsCast(LLVMValueRef I);
unsigned LLVMInstIsLogicalShift(LLVMValueRef I);
unsigned LLVMInstIsArithmeticShift(LLVMValueRef I);
unsigned LLVMInstIsAssociative(LLVMValueRef I);
unsigned LLVMInstIsCommutative(LLVMValueRef I);
unsigned LLVMInstIsTrapping(LLVMValueRef I);
const char *LLVMInstGetOpcodeName(LLVMValueRef I); /* Wraps llvm::sys::DynamicLibrary::LoadLibraryPermanently(). Returns 0 on
unsigned LLVMInstGetOpcode(LLVMValueRef I); * failure (with errmsg filled in) and 1 on success. Dispose error message after
* use, via LLVMDisposeMessage(). */
unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg);
/* reading llvm "assembly" */ /* Passes. A few passes (listed below) are used directly from LLVM-C,
* rest are declared here.
LLVMModuleRef LLVMGetModuleFromAssembly(const char *A, unsigned Len, *
char **OutMessage); * ConstantPropagation
* GVN
/* bitcode related */ * InstructionCombining
* PromoteMemoryToRegister
LLVMModuleRef LLVMGetModuleFromBitcode(const char *BC, unsigned Len, * Reassociate
char **OutMessage); * CFGSimplification
unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef M, unsigned *Len); */
unsigned LLVMLoadLibraryPermanently(const char* filename, char **ErrMsg);
/* passes */
#define declare_pass(P) \ #define declare_pass(P) \
void LLVMAdd ## P ## Pass (LLVMPassManagerRef PM); void LLVMAdd ## P ## Pass (LLVMPassManagerRef PM);
@ -97,7 +138,6 @@ declare_pass( BreakCriticalEdges )
declare_pass( CodeGenPrepare ) declare_pass( CodeGenPrepare )
declare_pass( CondPropagation ) declare_pass( CondPropagation )
declare_pass( ConstantMerge ) declare_pass( ConstantMerge )
//LLVM-C declare_pass( ConstantPropagation )
declare_pass( DeadCodeElimination ) declare_pass( DeadCodeElimination )
declare_pass( DeadArgElimination ) declare_pass( DeadArgElimination )
declare_pass( DeadTypeElimination ) declare_pass( DeadTypeElimination )
@ -106,7 +146,6 @@ declare_pass( DeadStoreElimination )
declare_pass( GCSE ) declare_pass( GCSE )
declare_pass( GlobalDCE ) declare_pass( GlobalDCE )
declare_pass( GlobalOptimizer ) declare_pass( GlobalOptimizer )
//LLVM-C declare_pass( GVN )
declare_pass( GVNPRE ) declare_pass( GVNPRE )
declare_pass( IndMemRem ) declare_pass( IndMemRem )
declare_pass( IndVarSimplify ) declare_pass( IndVarSimplify )
@ -116,7 +155,6 @@ declare_pass( EdgeProfiler )
declare_pass( FunctionProfiler ) declare_pass( FunctionProfiler )
declare_pass( NullProfilerRS ) declare_pass( NullProfilerRS )
declare_pass( RSProfiling ) declare_pass( RSProfiling )
//LLVM-C declare_pass( InstructionCombining )
declare_pass( Internalize ) declare_pass( Internalize )
declare_pass( IPConstantPropagation ) declare_pass( IPConstantPropagation )
declare_pass( IPSCCP ) declare_pass( IPSCCP )
@ -136,18 +174,15 @@ declare_pass( LowerAllocations )
declare_pass( LowerInvoke ) declare_pass( LowerInvoke )
declare_pass( LowerSetJmp ) declare_pass( LowerSetJmp )
declare_pass( LowerSwitch ) declare_pass( LowerSwitch )
//LLVM-C declare_pass( PromoteMemoryToRegister )
declare_pass( MemCpyOpt ) declare_pass( MemCpyOpt )
declare_pass( UnifyFunctionExitNodes ) declare_pass( UnifyFunctionExitNodes )
declare_pass( PredicateSimplifier ) declare_pass( PredicateSimplifier )
declare_pass( PruneEH ) declare_pass( PruneEH )
declare_pass( RaiseAllocations ) declare_pass( RaiseAllocations )
//LLVM-C declare_pass( Reassociate )
declare_pass( DemoteRegisterToMemory ) declare_pass( DemoteRegisterToMemory )
declare_pass( ScalarReplAggregates ) declare_pass( ScalarReplAggregates )
declare_pass( SCCP ) declare_pass( SCCP )
declare_pass( SimplifyLibCalls ) declare_pass( SimplifyLibCalls )
//LLVM-C declare_pass( CFGSimplification )
declare_pass( StripSymbols ) declare_pass( StripSymbols )
declare_pass( StripDeadPrototypes ) declare_pass( StripDeadPrototypes )
declare_pass( StructRetPromotion ) declare_pass( StructRetPromotion )

View file

@ -1,3 +1,33 @@
#
# Copyright (c) 2008, Mahadevan R All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of this software, nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""Pass managers and passes. """Pass managers and passes.
This module provides the LLVM pass managers and the passes themselves. This module provides the LLVM pass managers and the passes themselves.

View file

@ -1,3 +1,33 @@
/*
* Copyright (c) 2008, Mahadevan R All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of this software, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "wrap.h" #include "wrap.h"

View file

@ -1,3 +1,33 @@
/*
* Copyright (c) 2008, Mahadevan R All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of this software, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** /**
* Functions and macros to aid in wrapping. * Functions and macros to aid in wrapping.
*/ */