diff options
| author | James Miller <james@aatch.net> | 2013-05-28 11:15:31 +1200 |
|---|---|---|
| committer | James Miller <james@aatch.net> | 2013-05-29 14:16:49 +1200 |
| commit | d694e283b3ee045e8c10800a6428332a4fe4e80f (patch) | |
| tree | c348436d52d71de75cbf5ea8d5c4131873be7654 /src/rustllvm | |
| parent | e3d0c1eb0e86e04c2a6d5abe526516351cfaef3f (diff) | |
| download | rust-d694e283b3ee045e8c10800a6428332a4fe4e80f.tar.gz rust-d694e283b3ee045e8c10800a6428332a4fe4e80f.zip | |
Refactor optimization pass handling.
Refactor the optimization passes to explicitly use the passes. This commit just re-implements the same passes as were already being run. It also adds an option (behind `-Z`) to run the LLVM lint pass on the unoptimized IR.
Diffstat (limited to 'src/rustllvm')
| -rw-r--r-- | src/rustllvm/PassWrapper.cpp | 160 | ||||
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 48 | ||||
| -rw-r--r-- | src/rustllvm/rustllvm.def.in | 102 | ||||
| -rw-r--r-- | src/rustllvm/rustllvm.h | 57 |
4 files changed, 322 insertions, 45 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp new file mode 100644 index 00000000000..fd17dfb4cf8 --- /dev/null +++ b/src/rustllvm/PassWrapper.cpp @@ -0,0 +1,160 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include "rustllvm.h" + +using namespace llvm; + +// Pass conversion fns +typedef struct LLVMOpaquePass *LLVMPassRef; + +inline Pass *unwrap(LLVMPassRef P) { + return reinterpret_cast<Pass*>(P); +} + +inline LLVMPassRef wrap(const Pass *P) { + return reinterpret_cast<LLVMPassRef>(const_cast<Pass*>(P)); +} + +template<typename T> +inline T *unwrap(LLVMPassRef P) { + T *Q = (T*)unwrap(P); + assert(Q && "Invalid cast!"); + return Q; +} + +#define WRAP_PASS(name) \ + extern "C" LLVMPassRef LLVMCreate##name##Pass() { \ + return wrap(llvm::create##name##Pass()); \ + } + +extern "C" void LLVMAddPass(LLVMPassManagerRef PM, LLVMPassRef P) { + PassManagerBase * pm = unwrap(PM); + Pass * p = unwrap(P); + + pm->add(p); +} + +//////////////// +// Transforms // +// ///////////// + +// IPO Passes +WRAP_PASS(StripSymbols) +WRAP_PASS(StripNonDebugSymbols) +WRAP_PASS(StripDebugDeclare) +WRAP_PASS(StripDeadDebugInfo) +WRAP_PASS(ConstantMerge) +WRAP_PASS(GlobalOptimizer) +WRAP_PASS(GlobalDCE) +WRAP_PASS(AlwaysInliner) +WRAP_PASS(PruneEH) +WRAP_PASS(Internalize) +WRAP_PASS(DeadArgElimination) +WRAP_PASS(DeadArgHacking) +WRAP_PASS(ArgumentPromotion) +WRAP_PASS(IPConstantPropagation) +WRAP_PASS(IPSCCP) +WRAP_PASS(LoopExtractor) +WRAP_PASS(SingleLoopExtractor) +WRAP_PASS(BlockExtractor) +WRAP_PASS(StripDeadPrototypes) +WRAP_PASS(FunctionAttrs) +WRAP_PASS(MergeFunctions) +WRAP_PASS(PartialInlining) +WRAP_PASS(MetaRenamer) +WRAP_PASS(BarrierNoop) + +extern "C" LLVMPassRef LLVMCreateFunctionInliningPass(int Threshold) { + return wrap(llvm::createFunctionInliningPass(Threshold)); +} + +// Instrumentation Passes +WRAP_PASS(EdgeProfiler) +WRAP_PASS(OptimalEdgeProfiler) +WRAP_PASS(PathProfiler) +WRAP_PASS(GCOVProfiler) +WRAP_PASS(BoundsChecking) + +// Scalar Passes +WRAP_PASS(ConstantPropagation) +WRAP_PASS(SCCP) +WRAP_PASS(DeadInstElimination) +WRAP_PASS(DeadCodeElimination) +WRAP_PASS(DeadStoreElimination) +WRAP_PASS(AggressiveDCE) +WRAP_PASS(SROA) +WRAP_PASS(ScalarReplAggregates) +WRAP_PASS(IndVarSimplify) +WRAP_PASS(InstructionCombining) +WRAP_PASS(LICM) +WRAP_PASS(LoopStrengthReduce) +WRAP_PASS(GlobalMerge) +WRAP_PASS(LoopUnswitch) +WRAP_PASS(LoopInstSimplify) +WRAP_PASS(LoopUnroll) +WRAP_PASS(LoopRotate) +WRAP_PASS(LoopIdiom) +WRAP_PASS(PromoteMemoryToRegister) +WRAP_PASS(DemoteRegisterToMemory) +WRAP_PASS(Reassociate) +WRAP_PASS(JumpThreading) +WRAP_PASS(CFGSimplification) +WRAP_PASS(BreakCriticalEdges) +WRAP_PASS(LoopSimplify) +WRAP_PASS(TailCallElimination) +WRAP_PASS(LowerSwitch) +WRAP_PASS(LowerInvoke) +WRAP_PASS(BlockPlacement) +WRAP_PASS(LCSSA) +WRAP_PASS(EarlyCSE) +WRAP_PASS(GVN) +WRAP_PASS(MemCpyOpt) +WRAP_PASS(LoopDeletion) +WRAP_PASS(SimplifyLibCalls) +WRAP_PASS(CodeGenPrepare) +WRAP_PASS(InstructionNamer) +WRAP_PASS(Sinking) +WRAP_PASS(LowerAtomic) +WRAP_PASS(CorrelatedValuePropagation) +WRAP_PASS(InstructionSimplifier) +WRAP_PASS(LowerExpectIntrinsic) + +// Vectorize Passes +WRAP_PASS(BBVectorize) +WRAP_PASS(LoopVectorize) + +////////////// +// Analyses // +////////////// + +WRAP_PASS(GlobalsModRef) +WRAP_PASS(AliasAnalysisCounter) +WRAP_PASS(AAEval) +WRAP_PASS(NoAA) +WRAP_PASS(BasicAliasAnalysis) +WRAP_PASS(ScalarEvolutionAliasAnalysis) +WRAP_PASS(TypeBasedAliasAnalysis) +WRAP_PASS(ProfileLoader) +WRAP_PASS(ProfileMetadataLoader) +WRAP_PASS(NoProfileInfo) +WRAP_PASS(ProfileEstimator) +WRAP_PASS(ProfileVerifier) +WRAP_PASS(PathProfileLoader) +WRAP_PASS(NoPathProfileInfo) +WRAP_PASS(PathProfileVerifier) +WRAP_PASS(LazyValueInfo) +WRAP_PASS(DependenceAnalysis) +WRAP_PASS(CostModelAnalysis) +WRAP_PASS(InstCount) +WRAP_PASS(RegionInfo) +WRAP_PASS(ModuleDebugInfoPrinter) +WRAP_PASS(Lint) +WRAP_PASS(Verifier) diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index cff448b6a1a..4ee5df28d24 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#include "rustllvm.h" + //===----------------------------------------------------------------------=== // // This file defines alternate interfaces to core functions that are more @@ -15,50 +17,6 @@ // //===----------------------------------------------------------------------=== -#include "llvm/IR/InlineAsm.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/Linker.h" -#include "llvm/PassManager.h" -#include "llvm/IR/InlineAsm.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/Analysis/Verifier.h" -#include "llvm/Analysis/Passes.h" -#include "llvm/ADT/Triple.h" -#include "llvm/ADT/DenseSet.h" -#include "llvm/Assembly/Parser.h" -#include "llvm/Assembly/PrintModulePass.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/FormattedStream.h" -#include "llvm/Support/Timer.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/Host.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/DynamicLibrary.h" -#include "llvm/Support/Memory.h" -#include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "llvm/ExecutionEngine/JIT.h" -#include "llvm/ExecutionEngine/JITMemoryManager.h" -#include "llvm/ExecutionEngine/MCJIT.h" -#include "llvm/ExecutionEngine/Interpreter.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetOptions.h" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Transforms/IPO.h" -#include "llvm-c/Core.h" -#include "llvm-c/BitReader.h" -#include "llvm-c/Object.h" - -// Used by RustMCJITMemoryManager::getPointerToNamedFunction() -// to get around glibc issues. See the function for more information. -#ifdef __linux__ -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#endif - using namespace llvm; using namespace llvm::sys; diff --git a/src/rustllvm/rustllvm.def.in b/src/rustllvm/rustllvm.def.in index dd5dc7102d1..7e3c60cdd5f 100644 --- a/src/rustllvm/rustllvm.def.in +++ b/src/rustllvm/rustllvm.def.in @@ -584,3 +584,105 @@ LLVMConstNamedStruct LLVMStructCreateNamed LLVMStructSetBody LLVMInlineAsm +LLVMAddPass + +LLVMCreateStripSymbolsPass +LLVMCreateStripNonDebugSymbolsPass +LLVMCreateStripDebugDeclarePass +LLVMCreateStripDeadDebugInfoPass +LLVMCreateConstantMergePass +LLVMCreateGlobalOptimizerPass +LLVMCreateGlobalDCEPass +LLVMCreateAlwaysInlinerPass +LLVMCreatePruneEHPass +LLVMCreateInternalizePass +LLVMCreateDeadArgEliminationPass +LLVMCreateDeadArgHackingPass +LLVMCreateArgumentPromotionPass +LLVMCreateIPConstantPropagationPass +LLVMCreateIPSCCPPass +LLVMCreateLoopExtractorPass +LLVMCreateSingleLoopExtractorPass +LLVMCreateBlockExtractorPass +LLVMCreateStripDeadPrototypesPass +LLVMCreateFunctionAttrsPass +LLVMCreateMergeFunctionsPass +LLVMCreatePartialInliningPass +LLVMCreateMetaRenamerPass +LLVMCreateBarrierNoopPass +LLVMCreateFunctionInliningPass +LLVMCreateEdgeProfilerPass +LLVMCreateOptimalEdgeProfilerPass +LLVMCreatePathProfilerPass +LLVMCreateGCOVProfilerPass +LLVMCreateBoundsCheckingPass +LLVMCreateConstantPropagationPass +LLVMCreateSCCPPass +LLVMCreateDeadInstEliminationPass +LLVMCreateDeadCodeEliminationPass +LLVMCreateDeadStoreEliminationPass +LLVMCreateAggressiveDCEPass +LLVMCreateSROAPass +LLVMCreateScalarReplAggregatesPass +LLVMCreateIndVarSimplifyPass +LLVMCreateInstructionCombiningPass +LLVMCreateLICMPass +LLVMCreateLoopStrengthReducePass +LLVMCreateGlobalMergePass +LLVMCreateLoopUnswitchPass +LLVMCreateLoopInstSimplifyPass +LLVMCreateLoopUnrollPass +LLVMCreateLoopRotatePass +LLVMCreateLoopIdiomPass +LLVMCreatePromoteMemoryToRegisterPass +LLVMCreateDemoteRegisterToMemoryPass +LLVMCreateReassociatePass +LLVMCreateJumpThreadingPass +LLVMCreateCFGSimplificationPass +LLVMCreateBreakCriticalEdgesPass +LLVMCreateLoopSimplifyPass +LLVMCreateTailCallEliminationPass +LLVMCreateLowerSwitchPass +LLVMCreateLowerInvokePass +LLVMCreateBlockPlacementPass +LLVMCreateLCSSAPass +LLVMCreateEarlyCSEPass +LLVMCreateGVNPass +LLVMCreateMemCpyOptPass +LLVMCreateLoopDeletionPass +LLVMCreateSimplifyLibCallsPass +LLVMCreateCodeGenPreparePass +LLVMCreateInstructionNamerPass +LLVMCreateSinkingPass +LLVMCreateLowerAtomicPass +LLVMCreateCorrelatedValuePropagationPass +LLVMCreateInstructionSimplifierPass +LLVMCreateLowerExpectIntrinsicPass +LLVMCreateBBVectorizePass +LLVMCreateLoopVectorizePass +LLVMCreateGlobalsModRefPass +LLVMCreateAliasAnalysisCounterPass +LLVMCreateAAEvalPass +LLVMCreateNoAAPass +LLVMCreateBasicAliasAnalysisPass +LLVMCreateScalarEvolutionAliasAnalysisPass +LLVMCreateTypeBasedAliasAnalysisPass +LLVMCreateProfileLoaderPass +LLVMCreateProfileMetadataLoaderPass +LLVMCreateNoProfileInfoPass +LLVMCreateProfileEstimatorPass +LLVMCreateProfileVerifierPass +LLVMCreatePathProfileLoaderPass +LLVMCreateNoPathProfileInfoPass +LLVMCreatePathProfileVerifierPass +LLVMCreateDSAAPass +LLVMCreateDSOptPass +LLVMCreateSteensgaardPass +LLVMCreateLazyValueInfoPass +LLVMCreateDependenceAnalysisPass +LLVMCreateCostModelAnalysisPass +LLVMCreateInstCountPass +LLVMCreateRegionInfoPass +LLVMCreateModuleDebugInfoPrinterPass +LLVMCreateLintPass +LLVMCreateVerifierPass diff --git a/src/rustllvm/rustllvm.h b/src/rustllvm/rustllvm.h new file mode 100644 index 00000000000..1c8842f7b4a --- /dev/null +++ b/src/rustllvm/rustllvm.h @@ -0,0 +1,57 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include "llvm/IR/InlineAsm.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/Linker.h" +#include "llvm/PassManager.h" +#include "llvm/IR/InlineAsm.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/Analysis/Verifier.h" +#include "llvm/Analysis/Passes.h" +#include "llvm/Analysis/Lint.h" +#include "llvm/ADT/Triple.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/Assembly/Parser.h" +#include "llvm/Assembly/PrintModulePass.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Timer.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/Memory.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JIT.h" +#include "llvm/ExecutionEngine/JITMemoryManager.h" +#include "llvm/ExecutionEngine/MCJIT.h" +#include "llvm/ExecutionEngine/Interpreter.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetOptions.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/IPO.h" +#include "llvm/Transforms/Instrumentation.h" +#include "llvm/Transforms/Vectorize.h" +#include "llvm-c/Core.h" +#include "llvm-c/BitReader.h" +#include "llvm-c/Object.h" + +// Used by RustMCJITMemoryManager::getPointerToNamedFunction() +// to get around glibc issues. See the function for more information. +#ifdef __linux__ +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#endif + |
