Replaced PASS_* constants with pass name lookup.
This commit is contained in:
parent
6fb55db69d
commit
2d79cfa437
6 changed files with 176 additions and 214 deletions
17
llvm/_core.c
17
llvm/_core.c
|
|
@ -853,12 +853,24 @@ _wrap_obj2obj(LLVMInitializeFunctionPassManager, LLVMPassManagerRef, int)
|
|||
_wrap_objobj2obj(LLVMRunFunctionPassManager, LLVMPassManagerRef, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMFinalizeFunctionPassManager, LLVMPassManagerRef, int)
|
||||
_wrap_obj2none(LLVMDisposePassManager, LLVMPassManagerRef)
|
||||
_wrap_none2str(LLVMDumpPasses)
|
||||
_wrap_objstr2obj(LLVMAddPassByName, LLVMPassManagerRef, int)
|
||||
|
||||
static PyObject *
|
||||
_wLLVMInitializePasses(PyObject * self, PyObject * args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
LLVMInitializePasses();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
/* Passes */
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
|
||||
|
||||
#define _wrap_pass(P) \
|
||||
_wrap_obj2none( LLVMAdd ## P ## Pass, LLVMPassManagerRef)
|
||||
|
||||
|
|
@ -1683,8 +1695,13 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMRunFunctionPassManager )
|
||||
_method( LLVMFinalizeFunctionPassManager )
|
||||
_method( LLVMDisposePassManager )
|
||||
_method( LLVMDumpPasses )
|
||||
_method( LLVMAddPassByName )
|
||||
_method( LLVMInitializePasses )
|
||||
|
||||
/* Passes */
|
||||
|
||||
|
||||
_pass( AAEval )
|
||||
_pass( AggressiveDCE )
|
||||
_pass( AliasAnalysisCounter )
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* 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
|
||||
* * 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.
|
||||
*
|
||||
|
|
@ -78,6 +78,22 @@
|
|||
|
||||
//using namespace llvm;
|
||||
|
||||
/*
|
||||
* For use in LLVMDumpPasses to dump passes.
|
||||
*/
|
||||
class PassRegistryPrinter : public llvm::PassRegistrationListener{
|
||||
public:
|
||||
std::ostringstream stringstream;
|
||||
|
||||
void passEnumerate(const llvm::PassInfo * pass_info){
|
||||
stringstream << pass_info->getPassArgument()
|
||||
<< "\t"
|
||||
<< pass_info->getPassName()
|
||||
<< "\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Helper method for LLVMDumpXXXToString() methods. */
|
||||
template <typename W, typename UW>
|
||||
char *do_print(W obj)
|
||||
|
|
@ -90,6 +106,44 @@ char *do_print(W obj)
|
|||
return strdup(buf.str().c_str());
|
||||
}
|
||||
|
||||
int LLVMAddPassByName(LLVMPassManagerRef pm, const char * name)
|
||||
{
|
||||
using namespace llvm;
|
||||
const PassInfo * pi = Pass::lookupPassInfo(StringRef(name));
|
||||
if (pi){
|
||||
unwrap(pm)->add(pi->createPass());
|
||||
return 1; // success
|
||||
} else {
|
||||
return 0; // fail -- cannot find pass
|
||||
}
|
||||
}
|
||||
|
||||
void LLVMInitializePasses(){
|
||||
using namespace llvm;
|
||||
PassRegistry ®istry = *PassRegistry::getPassRegistry();
|
||||
initializeCore(registry);
|
||||
initializeScalarOpts(registry);
|
||||
initializeVectorization(registry);
|
||||
initializeIPO(registry);
|
||||
initializeAnalysis(registry);
|
||||
initializeIPA(registry);
|
||||
initializeTransformUtils(registry);
|
||||
initializeInstCombine(registry);
|
||||
initializeInstrumentation(registry);
|
||||
initializeTarget(registry);
|
||||
}
|
||||
|
||||
|
||||
const char * LLVMDumpPasses()
|
||||
{
|
||||
using namespace llvm;
|
||||
PassRegistry ®istry = *PassRegistry::getPassRegistry();
|
||||
PassRegistryPrinter prp;
|
||||
registry.enumerateWith(&prp);
|
||||
return strdup(prp.stringstream.str().c_str());
|
||||
}
|
||||
|
||||
|
||||
int LLVMIsLiteralStruct(LLVMTypeRef type)
|
||||
{
|
||||
return llvm::unwrap<llvm::StructType>(type)->isLiteral();
|
||||
|
|
@ -263,7 +317,7 @@ void unwrap_cvec(W *values, unsigned n, std::vector<const UW *>& out)
|
|||
}
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef builder,
|
||||
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef builder,
|
||||
LLVMValueRef *values, unsigned n_values)
|
||||
{
|
||||
assert(values);
|
||||
|
|
@ -277,7 +331,7 @@ LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef builder,
|
|||
return llvm::wrap(builderp->CreateAggregateRet(&values_vec[0], values_vec.size()));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder,
|
||||
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder,
|
||||
LLVMValueRef value, unsigned index, const char *name)
|
||||
{
|
||||
assert(name);
|
||||
|
|
@ -380,7 +434,7 @@ LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef module, int id,
|
|||
llvm::Module *modulep = llvm::unwrap(module);
|
||||
assert(modulep);
|
||||
|
||||
llvm::Function *intfunc = llvm::Intrinsic::getDeclaration(modulep,
|
||||
llvm::Function *intfunc = llvm::Intrinsic::getDeclaration(modulep,
|
||||
llvm::Intrinsic::ID(id), types_vec[0]);
|
||||
|
||||
return wrap(intfunc);
|
||||
|
|
@ -428,7 +482,7 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bitcode, unsigned bclen,
|
|||
return wrap(modulep);
|
||||
}
|
||||
|
||||
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, unsigned int mode,
|
||||
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, unsigned int mode,
|
||||
char **out)
|
||||
{
|
||||
llvm::Module *sourcep = llvm::unwrap(src);
|
||||
|
|
|
|||
43
llvm/extra.h
43
llvm/extra.h
|
|
@ -11,7 +11,7 @@
|
|||
* 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
|
||||
* * 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.
|
||||
*
|
||||
|
|
@ -41,6 +41,19 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int LLVMAddPassByName(LLVMPassManagerRef pm, const char * name);
|
||||
|
||||
/*
|
||||
* Wraps initialize*
|
||||
*/
|
||||
void LLVMInitializePasses();
|
||||
|
||||
/*
|
||||
* Wraps PassRegistry::enumerateWith()
|
||||
* Returns a '\n' separated string of all passes available to `opt`.
|
||||
*/
|
||||
const char * LLVMDumpPasses();
|
||||
|
||||
/*
|
||||
* Wraps StructType::isLiteral()
|
||||
*/
|
||||
|
|
@ -48,7 +61,7 @@ int LLVMIsLiteralStruct(LLVMTypeRef type);
|
|||
|
||||
/*
|
||||
* Wraps StructType::create()
|
||||
*/
|
||||
*/
|
||||
LLVMTypeRef LLVMStructTypeIdentified(const char * name);
|
||||
|
||||
/*
|
||||
|
|
@ -58,18 +71,18 @@ void LLVMSetStructBody(LLVMTypeRef type, LLVMTypeRef* elemtys, unsigned elemct,
|
|||
|
||||
/*
|
||||
* Wraps llvm::StructType::setName()
|
||||
*/
|
||||
*/
|
||||
void LLVMSetStructName(LLVMTypeRef type, const char * name);
|
||||
|
||||
|
||||
/*
|
||||
* Wraps llvm::Module::getModuleIdentifier()
|
||||
*/
|
||||
*/
|
||||
char *LLVMGetModuleIdentifier(LLVMModuleRef module);
|
||||
|
||||
/*
|
||||
* Wraps llvm::Module::setModuleIdentifier()
|
||||
*/
|
||||
*/
|
||||
void LLVMSetModuleIdentifier(LLVMModuleRef module, const char * name);
|
||||
|
||||
/* Notes:
|
||||
|
|
@ -129,14 +142,14 @@ LLVMValueRef LLVMConstVICmp(LLVMIntPredicate predicate, LLVMValueRef lhs,
|
|||
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate predicate, LLVMValueRef lhs,
|
||||
LLVMValueRef rhs);
|
||||
|
||||
/* Wraps llvm::IRBuilder::CreateVICmp(). */
|
||||
/* Wraps llvm::IRBuilder::CreateVICmp(). */
|
||||
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef builder, LLVMIntPredicate predicate,
|
||||
LLVMValueRef lhs, LLVMValueRef rhs, const char *name);
|
||||
|
||||
/* Wraps llvm::IRBuilder::CreateVFCmp(). */
|
||||
/* Wraps llvm::IRBuilder::CreateVFCmp(). */
|
||||
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef builder, LLVMRealPredicate predicate,
|
||||
LLVMValueRef lhs, LLVMValueRef rhs, const char *name);
|
||||
|
||||
|
||||
/* Wraps llvm::Intrinsic::getDeclaration(). */
|
||||
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef builder, int id,
|
||||
LLVMTypeRef *types, unsigned n_types);
|
||||
|
|
@ -151,12 +164,12 @@ void LLVMSetDoesNotThrow(LLVMValueRef fn, int DoesNotThrow);
|
|||
unsigned LLVMModuleGetPointerSize(LLVMModuleRef module);
|
||||
|
||||
/* Wraps llvm::Module::getOrInsertFunction(). */
|
||||
LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef module,
|
||||
LLVMValueRef LLVMModuleGetOrInsertFunction(LLVMModuleRef module,
|
||||
const char *name, LLVMTypeRef function_type);
|
||||
|
||||
/* Wraps llvm::GlobalVariable::hasInitializer(). */
|
||||
/* Wraps llvm::GlobalVariable::hasInitializer(). */
|
||||
int LLVMHasInitializer(LLVMValueRef global_var);
|
||||
|
||||
|
||||
/* 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). */
|
||||
|
|
@ -197,7 +210,7 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bc, unsigned bclen,
|
|||
/* Wraps llvm::Linker::LinkModules(). Returns 0 on failure (with errmsg
|
||||
* filled in) and 1 on success. Dispose error message after use with
|
||||
* LLVMDisposeMessage(). */
|
||||
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src,
|
||||
unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src,
|
||||
unsigned int, char **errmsg);
|
||||
|
||||
/* Returns pointer to a heap-allocated block of `*len' bytes containing bit code
|
||||
|
|
@ -209,12 +222,12 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, unsigned *len);
|
|||
* use, via LLVMDisposeMessage(). */
|
||||
unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg);
|
||||
|
||||
/* Wraps llvm::ExecutionEngine::getPointerToFunction(). Returns a pointer
|
||||
/* Wraps llvm::ExecutionEngine::getPointerToFunction(). Returns a pointer
|
||||
* to the JITted function. */
|
||||
void *LLVMGetPointerToFunction(LLVMExecutionEngineRef ee, LLVMValueRef fn);
|
||||
|
||||
/* Wraps llvm::InlineFunction(). Inlines a function. C is the call
|
||||
* instruction, created by LLVMBuildCall. Even if it fails, the Function
|
||||
/* Wraps llvm::InlineFunction(). Inlines a function. C is the call
|
||||
* instruction, created by LLVMBuildCall. Even if it fails, the Function
|
||||
* containing the call is still in a proper state (not changed). */
|
||||
//int LLVMInlineFunction(LLVMValueRef call);
|
||||
|
||||
|
|
|
|||
230
llvm/passes.py
230
llvm/passes.py
|
|
@ -40,188 +40,6 @@ import llvm.ee as ee # target data
|
|||
import llvm.core as core # module, function etc.
|
||||
import llvm._core as _core # C wrappers
|
||||
|
||||
|
||||
# passes
|
||||
PASS_AAEVAL = 1
|
||||
PASS_AGGRESSIVE_DCE = 3
|
||||
PASS_ALIAS_ANALYSIS_COUNTER = 4
|
||||
PASS_ALWAYS_INLINER = 5
|
||||
PASS_ARGUMENT_PROMOTION = 6
|
||||
PASS_BASIC_ALIAS_ANALYSIS = 7
|
||||
PASS_BLOCK_PLACEMENT = 8
|
||||
PASS_BREAK_CRITICAL_EDGES = 9
|
||||
PASS_CFG_SIMPLIFICATION = 10
|
||||
PASS_CODE_GEN_PREPARE = 11
|
||||
PASS_CONSTANT_MERGE = 12
|
||||
PASS_CONSTANT_PROPAGATION = 13
|
||||
PASS_DBG_INFO_PRINTER = 14
|
||||
PASS_DEAD_ARG_ELIMINATION = 15
|
||||
PASS_DEAD_CODE_ELIMINATION = 16
|
||||
PASS_DEAD_INST_ELIMINATION = 17
|
||||
PASS_DEAD_STORE_ELIMINATION = 18
|
||||
PASS_DEAD_TYPE_ELIMINATION = 19
|
||||
PASS_DEMOTE_REGISTER_TO_MEMORY = 20
|
||||
PASS_DOM_ONLY_PRINTER = 21
|
||||
PASS_DOM_ONLY_VIEWER = 22
|
||||
PASS_DOM_PRINTER = 23
|
||||
PASS_DOM_VIEWER = 24
|
||||
PASS_EDGE_PROFILER = 25
|
||||
PASS_FUNCTION_ATTRS = 26
|
||||
PASS_FUNCTION_INLINING = 27
|
||||
#PASS_GEP_SPLITTER = 28
|
||||
PASS_GLOBAL_DCE = 29
|
||||
PASS_GLOBAL_OPTIMIZER = 30
|
||||
PASS_GLOBALS_MOD_REF = 31
|
||||
PASS_GVN = 32
|
||||
PASS_IND_VAR_SIMPLIFY = 33
|
||||
PASS_INST_COUNT = 34
|
||||
PASS_INSTRUCTION_COMBINING = 35
|
||||
PASS_INSTRUCTION_NAMER = 36
|
||||
PASS_IP_CONSTANT_PROPAGATION = 37
|
||||
PASS_IPSCCP = 38
|
||||
PASS_JUMP_THREADING = 39
|
||||
PASS_LAZY_VALUE_INFO = 40
|
||||
PASS_LCSSA = 41
|
||||
PASS_LICM = 42
|
||||
#PASS_LIVE_VALUES = 43
|
||||
PASS_LOOP_DELETION = 44
|
||||
PASS_LOOP_DEPENDENCE_ANALYSIS = 45
|
||||
PASS_LOOP_EXTRACTOR = 46
|
||||
#PASS_LOOP_INDEX_SPLIT = 47
|
||||
PASS_LOOP_ROTATE = 48
|
||||
PASS_LOOP_SIMPLIFY = 49
|
||||
PASS_LOOP_STRENGTH_REDUCE = 50
|
||||
PASS_LOOP_UNROLL = 51
|
||||
PASS_LOOP_UNSWITCH = 52
|
||||
PASS_LOWER_INVOKE = 53
|
||||
PASS_LOWER_SET_JMP = 54
|
||||
PASS_LOWER_SWITCH = 55
|
||||
PASS_MEM_CPY_OPT = 56
|
||||
PASS_MERGE_FUNCTIONS = 57
|
||||
PASS_NO_AA = 58
|
||||
PASS_NO_PROFILE_INFO = 59
|
||||
PASS_OPTIMAL_EDGE_PROFILER = 60
|
||||
PASS_PARTIAL_INLINING = 61
|
||||
#PASS_PARTIAL_SPECIALIZATION = 62
|
||||
#PASS_POST_DOM_ONLY_PRINTER = 63
|
||||
#PASS_POST_DOM_ONLY_VIEWER = 64
|
||||
#PASS_POST_DOM_PRINTER = 65
|
||||
#PASS_POST_DOM_VIEWER = 66
|
||||
PASS_PROFILE_ESTIMATOR = 67
|
||||
PASS_PROFILE_LOADER = 68
|
||||
PASS_PROFILE_VERIFIER = 69
|
||||
PASS_PROMOTE_MEMORY_TO_REGISTER = 70
|
||||
PASS_PRUNE_EH = 71
|
||||
PASS_REASSOCIATE = 72
|
||||
PASS_SCALAR_EVOLUTION_ALIAS_ANALYSIS = 73
|
||||
PASS_SCALAR_REPL_AGGREGATES = 74
|
||||
PASS_SCCP = 76
|
||||
#PASS_SIMPLIFY_HALF_POWR_LIB_CALLS = 77
|
||||
PASS_SIMPLIFY_LIB_CALLS = 78
|
||||
PASS_SINGLE_LOOP_EXTRACTOR = 79
|
||||
PASS_STRIP_DEAD_PROTOTYPES = 82
|
||||
PASS_STRIP_NON_DEBUG_SYMBOLS = 83
|
||||
PASS_STRIP_SYMBOLS = 84
|
||||
PASS_STRUCT_RET_PROMOTION = 85
|
||||
PASS_TAIL_CALL_ELIMINATION = 86
|
||||
PASS_TAIL_DUPLICATION = 87
|
||||
PASS_UNIFY_FUNCTION_EXIT_NODES = 88
|
||||
PASS_INTERNALIZE = 89
|
||||
|
||||
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# Helper functions
|
||||
#===----------------------------------------------------------------------===
|
||||
|
||||
_pass_creator = {
|
||||
PASS_AAEVAL : _core.LLVMAddAAEvalPass,
|
||||
PASS_AGGRESSIVE_DCE : _core.LLVMAddAggressiveDCEPass,
|
||||
PASS_ALIAS_ANALYSIS_COUNTER : _core.LLVMAddAliasAnalysisCounterPass,
|
||||
PASS_ALWAYS_INLINER : _core.LLVMAddAlwaysInlinerPass,
|
||||
PASS_ARGUMENT_PROMOTION : _core.LLVMAddArgumentPromotionPass,
|
||||
PASS_BASIC_ALIAS_ANALYSIS : _core.LLVMAddBasicAliasAnalysisPass,
|
||||
PASS_BLOCK_PLACEMENT : _core.LLVMAddBlockPlacementPass,
|
||||
PASS_BREAK_CRITICAL_EDGES : _core.LLVMAddBreakCriticalEdgesPass,
|
||||
PASS_CFG_SIMPLIFICATION : _core.LLVMAddCFGSimplificationPass,
|
||||
PASS_CODE_GEN_PREPARE : _core.LLVMAddCodeGenPreparePass,
|
||||
PASS_CONSTANT_MERGE : _core.LLVMAddConstantMergePass,
|
||||
PASS_CONSTANT_PROPAGATION : _core.LLVMAddConstantPropagationPass,
|
||||
PASS_DBG_INFO_PRINTER : _core.LLVMAddDbgInfoPrinterPass,
|
||||
PASS_DEAD_ARG_ELIMINATION : _core.LLVMAddDeadArgEliminationPass,
|
||||
PASS_DEAD_CODE_ELIMINATION : _core.LLVMAddDeadCodeEliminationPass,
|
||||
PASS_DEAD_INST_ELIMINATION : _core.LLVMAddDeadInstEliminationPass,
|
||||
PASS_DEAD_STORE_ELIMINATION : _core.LLVMAddDeadStoreEliminationPass,
|
||||
# PASS_DEAD_TYPE_ELIMINATION : _core.LLVMAddDeadTypeEliminationPass,
|
||||
PASS_DEMOTE_REGISTER_TO_MEMORY : _core.LLVMAddDemoteRegisterToMemoryPass,
|
||||
PASS_DOM_ONLY_PRINTER : _core.LLVMAddDomOnlyPrinterPass,
|
||||
PASS_DOM_ONLY_VIEWER : _core.LLVMAddDomOnlyViewerPass,
|
||||
PASS_DOM_PRINTER : _core.LLVMAddDomPrinterPass,
|
||||
PASS_DOM_VIEWER : _core.LLVMAddDomViewerPass,
|
||||
PASS_EDGE_PROFILER : _core.LLVMAddEdgeProfilerPass,
|
||||
PASS_FUNCTION_ATTRS : _core.LLVMAddFunctionAttrsPass,
|
||||
PASS_FUNCTION_INLINING : _core.LLVMAddFunctionInliningPass,
|
||||
# PASS_GEP_SPLITTER : _core.LLVMAddGEPSplitterPass,
|
||||
PASS_GLOBAL_DCE : _core.LLVMAddGlobalDCEPass,
|
||||
PASS_GLOBAL_OPTIMIZER : _core.LLVMAddGlobalOptimizerPass,
|
||||
PASS_GLOBALS_MOD_REF : _core.LLVMAddGlobalsModRefPass,
|
||||
PASS_GVN : _core.LLVMAddGVNPass,
|
||||
PASS_IND_VAR_SIMPLIFY : _core.LLVMAddIndVarSimplifyPass,
|
||||
PASS_INST_COUNT : _core.LLVMAddInstCountPass,
|
||||
PASS_INSTRUCTION_COMBINING : _core.LLVMAddInstructionCombiningPass,
|
||||
PASS_INSTRUCTION_NAMER : _core.LLVMAddInstructionNamerPass,
|
||||
PASS_IP_CONSTANT_PROPAGATION : _core.LLVMAddIPConstantPropagationPass,
|
||||
PASS_IPSCCP : _core.LLVMAddIPSCCPPass,
|
||||
PASS_JUMP_THREADING : _core.LLVMAddJumpThreadingPass,
|
||||
PASS_LAZY_VALUE_INFO : _core.LLVMAddLazyValueInfoPass,
|
||||
PASS_LCSSA : _core.LLVMAddLCSSAPass,
|
||||
PASS_LICM : _core.LLVMAddLICMPass,
|
||||
# PASS_LIVE_VALUES : _core.LLVMAddLiveValuesPass,
|
||||
PASS_LOOP_DELETION : _core.LLVMAddLoopDeletionPass,
|
||||
PASS_LOOP_DEPENDENCE_ANALYSIS : _core.LLVMAddLoopDependenceAnalysisPass,
|
||||
PASS_LOOP_EXTRACTOR : _core.LLVMAddLoopExtractorPass,
|
||||
# PASS_LOOP_INDEX_SPLIT : _core.LLVMAddLoopIndexSplitPass,
|
||||
PASS_LOOP_ROTATE : _core.LLVMAddLoopRotatePass,
|
||||
PASS_LOOP_SIMPLIFY : _core.LLVMAddLoopSimplifyPass,
|
||||
PASS_LOOP_STRENGTH_REDUCE : _core.LLVMAddLoopStrengthReducePass,
|
||||
PASS_LOOP_UNROLL : _core.LLVMAddLoopUnrollPass,
|
||||
PASS_LOOP_UNSWITCH : _core.LLVMAddLoopUnswitchPass,
|
||||
PASS_LOWER_INVOKE : _core.LLVMAddLowerInvokePass,
|
||||
PASS_LOWER_SWITCH : _core.LLVMAddLowerSwitchPass,
|
||||
PASS_MEM_CPY_OPT : _core.LLVMAddMemCpyOptPass,
|
||||
PASS_MERGE_FUNCTIONS : _core.LLVMAddMergeFunctionsPass,
|
||||
PASS_NO_AA : _core.LLVMAddNoAAPass,
|
||||
PASS_NO_PROFILE_INFO : _core.LLVMAddNoProfileInfoPass,
|
||||
PASS_OPTIMAL_EDGE_PROFILER : _core.LLVMAddOptimalEdgeProfilerPass,
|
||||
PASS_PARTIAL_INLINING : _core.LLVMAddPartialInliningPass,
|
||||
# PASS_PARTIAL_SPECIALIZATION : _core.LLVMAddPartialSpecializationPass,
|
||||
# PASS_POST_DOM_ONLY_PRINTER : _core.LLVMAddPostDomOnlyPrinterPass,
|
||||
# PASS_POST_DOM_ONLY_VIEWER : _core.LLVMAddPostDomOnlyViewerPass,
|
||||
# PASS_POST_DOM_PRINTER : _core.LLVMAddPostDomPrinterPass,
|
||||
# PASS_POST_DOM_VIEWER : _core.LLVMAddPostDomViewerPass,
|
||||
PASS_PROFILE_ESTIMATOR : _core.LLVMAddProfileEstimatorPass,
|
||||
PASS_PROFILE_LOADER : _core.LLVMAddProfileLoaderPass,
|
||||
PASS_PROFILE_VERIFIER : _core.LLVMAddProfileVerifierPass,
|
||||
PASS_PROMOTE_MEMORY_TO_REGISTER : _core.LLVMAddPromoteMemoryToRegisterPass,
|
||||
PASS_PRUNE_EH : _core.LLVMAddPruneEHPass,
|
||||
PASS_REASSOCIATE : _core.LLVMAddReassociatePass,
|
||||
PASS_SCALAR_EVOLUTION_ALIAS_ANALYSIS : _core.LLVMAddScalarEvolutionAliasAnalysisPass,
|
||||
PASS_SCALAR_REPL_AGGREGATES : _core.LLVMAddScalarReplAggregatesPass,
|
||||
PASS_SCCP : _core.LLVMAddSCCPPass,
|
||||
# PASS_SIMPLIFY_HALF_POWR_LIB_CALLS : _core.LLVMAddSimplifyHalfPowrLibCallsPass,
|
||||
PASS_SIMPLIFY_LIB_CALLS : _core.LLVMAddSimplifyLibCallsPass,
|
||||
PASS_SINGLE_LOOP_EXTRACTOR : _core.LLVMAddSingleLoopExtractorPass,
|
||||
PASS_STRIP_DEAD_PROTOTYPES : _core.LLVMAddStripDeadPrototypesPass,
|
||||
PASS_STRIP_NON_DEBUG_SYMBOLS : _core.LLVMAddStripNonDebugSymbolsPass,
|
||||
PASS_STRIP_SYMBOLS : _core.LLVMAddStripSymbolsPass,
|
||||
# PASS_STRUCT_RET_PROMOTION : _core.LLVMAddStructRetPromotionPass,
|
||||
PASS_TAIL_CALL_ELIMINATION : _core.LLVMAddTailCallEliminationPass,
|
||||
# PASS_TAIL_DUPLICATION : _core.LLVMAddTailDuplicationPass,
|
||||
PASS_UNIFY_FUNCTION_EXIT_NODES : _core.LLVMAddUnifyFunctionExitNodesPass,
|
||||
PASS_INTERNALIZE : _core.LLVMAddInternalize2Pass,
|
||||
}
|
||||
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# Pass manager
|
||||
#===----------------------------------------------------------------------===
|
||||
|
|
@ -238,26 +56,27 @@ class PassManager(object):
|
|||
def __del__(self):
|
||||
_core.LLVMDisposePassManager(self.ptr)
|
||||
|
||||
def add(self, tgt_data_or_pass_id):
|
||||
if isinstance(tgt_data_or_pass_id, ee.TargetData):
|
||||
self._add_target_data(tgt_data_or_pass_id)
|
||||
elif tgt_data_or_pass_id in _pass_creator:
|
||||
self._add_pass(tgt_data_or_pass_id)
|
||||
def add(self, tgt_data_or_pass_name):
|
||||
if isinstance(tgt_data_or_pass_name, ee.TargetData):
|
||||
self._add_target_data(tgt_data_or_pass_name)
|
||||
elif isinstance(tgt_data_or_pass_name, basestring):
|
||||
self._add_pass(tgt_data_or_pass_name)
|
||||
else:
|
||||
raise llvm.LLVMException("invalid pass_id (%s)" % str(tgt_data_or_pass_id))
|
||||
raise llvm.LLVMException("invalid pass_id (%s)" % str(tgt_data_or_pass_name))
|
||||
|
||||
def _add_target_data(self, tgt):
|
||||
_core.LLVMAddTargetData(tgt.ptr, self.ptr)
|
||||
|
||||
def _add_pass(self, pass_id):
|
||||
cfn = _pass_creator[pass_id]
|
||||
cfn(self.ptr)
|
||||
def _add_pass(self, pass_name):
|
||||
status = _core.LLVMAddPassByName(self.ptr, pass_name)
|
||||
if not status:
|
||||
assert pass_name not in PASSES, "Registered but not found?"
|
||||
raise llvm.LLVMException('Invalid pass name "%s"' % pass_name)
|
||||
|
||||
def run(self, module):
|
||||
core.check_is_module(module)
|
||||
return _core.LLVMRunPassManager(self.ptr, module.ptr)
|
||||
|
||||
|
||||
class FunctionPassManager(PassManager):
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -279,3 +98,30 @@ class FunctionPassManager(PassManager):
|
|||
def finalize(self):
|
||||
_core.LLVMFinalizeFunctionPassManager(self.ptr)
|
||||
|
||||
# Intialize passes
|
||||
PASSES = None
|
||||
|
||||
def _dump_all_passes():
|
||||
passes_sep_by_line = _core.LLVMDumpPasses()
|
||||
strip = lambda S : S.strip()
|
||||
for line in passes_sep_by_line.splitlines():
|
||||
passarg, passname = map(strip, line.split('\t', 1))
|
||||
if passarg:
|
||||
yield passarg, passname
|
||||
|
||||
def _initialize_passes():
|
||||
global PASSES
|
||||
_core.LLVMInitializePasses()
|
||||
PASSES = dict(_dump_all_passes())
|
||||
|
||||
# build globals
|
||||
def transform(name):
|
||||
return "PASS_%s" % (name.upper().replace('-', '_'))
|
||||
|
||||
global_symbols = globals()
|
||||
for i in PASSES:
|
||||
assert i not in global_symbols
|
||||
global_symbols[transform(i)] = i
|
||||
|
||||
_initialize_passes()
|
||||
|
||||
|
|
|
|||
30
llvm/wrap.h
30
llvm/wrap.h
|
|
@ -355,6 +355,21 @@ _w ## func (PyObject *self, PyObject *args) \
|
|||
return ctor_ ## outtype ( func ()); \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrap LLVM functions of the type
|
||||
* const char * func()
|
||||
*/
|
||||
#define _wrap_none2str(func) \
|
||||
static PyObject * \
|
||||
_w ## func (PyObject *self, PyObject *args) \
|
||||
{ \
|
||||
if (!PyArg_ParseTuple(args, "")) \
|
||||
return NULL; \
|
||||
return PyBytes_FromString(func()); \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrap LLVM functions of the type
|
||||
* const char *func(intype1 arg1)
|
||||
|
|
@ -1231,6 +1246,21 @@ _w ## func (PyObject *self, PyObject *args) \
|
|||
return ctor_ ## outtype ( func ()); \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrap LLVM functions of the type
|
||||
* const char * func()
|
||||
*/
|
||||
#define _wrap_none2str(func) \
|
||||
static PyObject * \
|
||||
_w ## func (PyObject *self, PyObject *args) \
|
||||
{ \
|
||||
if (!PyArg_ParseTuple(args, "")) \
|
||||
return NULL; \
|
||||
return PyBytes_FromString(func()); \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrap LLVM functions of the type
|
||||
* const char *func(intype1 arg1)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class TestPasses(unittest.TestCase):
|
|||
pm.add( TargetData.new('') )
|
||||
|
||||
# Add the inlining pass.
|
||||
pm.add( PASS_FUNCTION_INLINING )
|
||||
pm.add( PASS_INLINE )
|
||||
|
||||
# Run it!
|
||||
pm.run(m)
|
||||
|
|
@ -88,7 +88,7 @@ class TestPasses(unittest.TestCase):
|
|||
fpm.add( TargetData.new('') )
|
||||
|
||||
# Add a DCE pass
|
||||
fpm.add( PASS_AGGRESSIVE_DCE )
|
||||
fpm.add( PASS_ADCE )
|
||||
|
||||
# Run the pass on the function 'test1'
|
||||
fpm.run( m.get_function_named('test1') )
|
||||
|
|
@ -100,6 +100,8 @@ class TestPasses(unittest.TestCase):
|
|||
# Make sure test1 is modified
|
||||
self.assertNotEqual(str(fn_test1).strip(), original_test1.strip())
|
||||
|
||||
def test_dump_passes(self):
|
||||
self.assertTrue(len(PASSES)>0, msg="Cannot have no passes")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue