Use the new C API for PassManagerBuilder.
This commit is contained in:
parent
4cee063976
commit
6402b63b4f
|
@ -2,7 +2,7 @@
|
||||||
# rustc LLVM-extensions (C++) library variables and rules
|
# rustc LLVM-extensions (C++) library variables and rules
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
RUSTLLVM_OBJS_CS := $(addprefix rustllvm/, Passes.cpp RustWrapper.cpp)
|
RUSTLLVM_OBJS_CS := $(addprefix rustllvm/, RustWrapper.cpp)
|
||||||
|
|
||||||
RUSTLLVM_DEF := rustllvm/rustllvm$(CFG_DEF_SUFFIX)
|
RUSTLLVM_DEF := rustllvm/rustllvm$(CFG_DEF_SUFFIX)
|
||||||
|
|
||||||
|
|
|
@ -117,19 +117,34 @@ mod write {
|
||||||
if opts.optimize != 0u {
|
if opts.optimize != 0u {
|
||||||
let fpm = mk_pass_manager();
|
let fpm = mk_pass_manager();
|
||||||
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
|
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
|
||||||
llvm::LLVMAddStandardFunctionPasses(fpm.llpm, 2u);
|
|
||||||
|
let FPMB = llvm::LLVMPassManagerBuilderCreate();
|
||||||
|
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u);
|
||||||
|
llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(FPMB,
|
||||||
|
fpm.llpm);
|
||||||
|
llvm::LLVMPassManagerBuilderDispose(FPMB);
|
||||||
|
|
||||||
llvm::LLVMRunPassManager(fpm.llpm, llmod);
|
llvm::LLVMRunPassManager(fpm.llpm, llmod);
|
||||||
let threshold: uint = 225u;
|
let threshold: uint = 225u;
|
||||||
if opts.optimize == 3u { threshold = 275u; }
|
if opts.optimize == 3u { threshold = 275u; }
|
||||||
llvm::LLVMAddStandardModulePasses(pm.llpm,
|
|
||||||
// optimization level
|
|
||||||
opts.optimize,
|
|
||||||
False, // optimize for size
|
|
||||||
True, // unit-at-a-time
|
|
||||||
True, // unroll loops
|
|
||||||
True, // simplify lib calls
|
|
||||||
threshold); // inline threshold
|
|
||||||
|
|
||||||
|
let MPMB = llvm::LLVMPassManagerBuilderCreate();
|
||||||
|
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB, opts.optimize);
|
||||||
|
llvm::LLVMPassManagerBuilderSetSizeLevel(MPMB, 0);
|
||||||
|
llvm::LLVMPassManagerBuilderSetDisableUnitAtATime(MPMB, False);
|
||||||
|
llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(MPMB, False);
|
||||||
|
llvm::LLVMPassManagerBuilderSetDisableSimplifyLibCalls(MPMB,
|
||||||
|
False);
|
||||||
|
|
||||||
|
if threshold != 0u {
|
||||||
|
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(MPMB,
|
||||||
|
threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm::LLVMPassManagerBuilderPopulateModulePassManager(MPMB,
|
||||||
|
pm.llpm);
|
||||||
|
|
||||||
|
llvm::LLVMPassManagerBuilderDispose(MPMB);
|
||||||
}
|
}
|
||||||
if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
|
if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
|
||||||
if is_object_or_assembly_or_exe(opts.output_type) {
|
if is_object_or_assembly_or_exe(opts.output_type) {
|
||||||
|
|
|
@ -141,6 +141,7 @@ native "cdecl" mod llvm = "rustllvm" {
|
||||||
type ModuleProviderRef;
|
type ModuleProviderRef;
|
||||||
type MemoryBufferRef;
|
type MemoryBufferRef;
|
||||||
type PassManagerRef;
|
type PassManagerRef;
|
||||||
|
type PassManagerBuilderRef;
|
||||||
type UseRef;
|
type UseRef;
|
||||||
type TargetDataRef;
|
type TargetDataRef;
|
||||||
|
|
||||||
|
@ -798,13 +799,29 @@ native "cdecl" mod llvm = "rustllvm" {
|
||||||
fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
|
fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
|
||||||
fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
|
fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
|
||||||
|
|
||||||
fn LLVMAddStandardFunctionPasses(PM: PassManagerRef,
|
fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
|
||||||
OptimizationLevel: uint);
|
fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
|
||||||
fn LLVMAddStandardModulePasses(PM: PassManagerRef,
|
fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
|
||||||
OptimizationLevel: uint,
|
OptimizationLevel: uint);
|
||||||
OptimizeSize: Bool, UnitAtATime: Bool,
|
fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
|
||||||
UnrollLoops: Bool, SimplifyLibCalls: Bool,
|
Value: Bool);
|
||||||
InliningThreshold: uint);
|
fn LLVMPassManagerBuilderSetDisableUnitAtATime(PMB: PassManagerBuilderRef,
|
||||||
|
Value: Bool);
|
||||||
|
fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef,
|
||||||
|
Value: Bool);
|
||||||
|
fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(PMB:
|
||||||
|
PassManagerBuilderRef,
|
||||||
|
Value: Bool);
|
||||||
|
fn LLVMPassManagerBuilderUseInlinerWithThreshold(PMB:
|
||||||
|
PassManagerBuilderRef,
|
||||||
|
threshold: uint);
|
||||||
|
fn LLVMPassManagerBuilderPopulateModulePassManager(PMB:
|
||||||
|
PassManagerBuilderRef,
|
||||||
|
PM: PassManagerRef);
|
||||||
|
|
||||||
|
fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB:
|
||||||
|
PassManagerBuilderRef,
|
||||||
|
PM: PassManagerRef);
|
||||||
|
|
||||||
/** Destroys a memory buffer. */
|
/** Destroys a memory buffer. */
|
||||||
fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
|
fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
#include "llvm/Analysis/Passes.h"
|
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
||||||
#include "llvm/Transforms/IPO.h"
|
|
||||||
#include "llvm/PassManager.h"
|
|
||||||
#include "llvm-c/Core.h"
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
using namespace llvm;
|
|
||||||
|
|
||||||
extern "C" void LLVMAddStandardFunctionPasses(LLVMPassManagerRef PM,
|
|
||||||
unsigned int OptimizationLevel) {
|
|
||||||
PassManagerBuilder PMBuilder;
|
|
||||||
PMBuilder.OptLevel = OptimizationLevel;
|
|
||||||
FunctionPassManager *FPM = (FunctionPassManager*) unwrap(PM);
|
|
||||||
PMBuilder.populateFunctionPassManager(*FPM);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMAddStandardModulePasses(LLVMPassManagerRef PM,
|
|
||||||
unsigned int OptimizationLevel, LLVMBool OptimizeSize,
|
|
||||||
LLVMBool UnitAtATime, LLVMBool UnrollLoops, LLVMBool SimplifyLibCalls,
|
|
||||||
unsigned int InliningThreshold) {
|
|
||||||
|
|
||||||
PassManagerBuilder PMBuilder;
|
|
||||||
PMBuilder.OptLevel = OptimizationLevel;
|
|
||||||
PMBuilder.SizeLevel = OptimizeSize;
|
|
||||||
PMBuilder.DisableUnitAtATime = !UnitAtATime;
|
|
||||||
PMBuilder.DisableUnrollLoops = !UnrollLoops;
|
|
||||||
|
|
||||||
PMBuilder.DisableSimplifyLibCalls = !SimplifyLibCalls;
|
|
||||||
|
|
||||||
if (InliningThreshold)
|
|
||||||
PMBuilder.Inliner = createFunctionInliningPass(InliningThreshold);
|
|
||||||
|
|
||||||
PassManager *MPM = (PassManager*) unwrap(PM);
|
|
||||||
PMBuilder.populateModulePassManager(*MPM);
|
|
||||||
}
|
|
||||||
|
|
|
@ -45,14 +45,6 @@ extern "C" const char *LLVMRustGetLastError(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM);
|
extern "C" void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM);
|
||||||
extern "C" void LLVMAddStandardModulePasses(LLVMPassManagerRef PM,
|
|
||||||
unsigned int OptimizationLevel, bool OptimizeSize, bool UnitAtATime,
|
|
||||||
bool UnrollLoops, bool SimplifyLibCalls,
|
|
||||||
unsigned int InliningThreshold);
|
|
||||||
|
|
||||||
int *RustHackToFetchPassesO = (int*)LLVMAddBasicAliasAnalysisPass;
|
|
||||||
int *RustHackToFetchPasses2O = (int*)LLVMAddStandardModulePasses;
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
|
extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
|
||||||
static std::string err;
|
static std::string err;
|
||||||
|
|
|
@ -57,21 +57,17 @@ LLVMAddLoopIdiomPass
|
||||||
LLVMAddLoopRotatePass
|
LLVMAddLoopRotatePass
|
||||||
LLVMAddLoopUnrollPass
|
LLVMAddLoopUnrollPass
|
||||||
LLVMAddLoopUnswitchPass
|
LLVMAddLoopUnswitchPass
|
||||||
LLVMAddLowerSetJmpPass
|
|
||||||
LLVMAddMemCpyOptPass
|
LLVMAddMemCpyOptPass
|
||||||
LLVMAddModule
|
LLVMAddModule
|
||||||
LLVMAddModuleProvider
|
LLVMAddModuleProvider
|
||||||
LLVMAddPromoteMemoryToRegisterPass
|
LLVMAddPromoteMemoryToRegisterPass
|
||||||
LLVMAddPruneEHPass
|
LLVMAddPruneEHPass
|
||||||
LLVMAddRaiseAllocationsPass
|
|
||||||
LLVMAddReassociatePass
|
LLVMAddReassociatePass
|
||||||
LLVMAddSCCPPass
|
LLVMAddSCCPPass
|
||||||
LLVMAddScalarReplAggregatesPass
|
LLVMAddScalarReplAggregatesPass
|
||||||
LLVMAddScalarReplAggregatesPassSSA
|
LLVMAddScalarReplAggregatesPassSSA
|
||||||
LLVMAddScalarReplAggregatesPassWithThreshold
|
LLVMAddScalarReplAggregatesPassWithThreshold
|
||||||
LLVMAddSimplifyLibCallsPass
|
LLVMAddSimplifyLibCallsPass
|
||||||
LLVMAddStandardFunctionPasses
|
|
||||||
LLVMAddStandardModulePasses
|
|
||||||
LLVMAddStripDeadPrototypesPass
|
LLVMAddStripDeadPrototypesPass
|
||||||
LLVMAddStripSymbolsPass
|
LLVMAddStripSymbolsPass
|
||||||
LLVMAddTailCallEliminationPass
|
LLVMAddTailCallEliminationPass
|
||||||
|
@ -489,7 +485,6 @@ LLVMIsAUIToFPInst
|
||||||
LLVMIsAUnaryInstruction
|
LLVMIsAUnaryInstruction
|
||||||
LLVMIsAUndefValue
|
LLVMIsAUndefValue
|
||||||
LLVMIsAUnreachableInst
|
LLVMIsAUnreachableInst
|
||||||
LLVMIsAUnwindInst
|
|
||||||
LLVMIsAUser
|
LLVMIsAUser
|
||||||
LLVMIsAVAArgInst
|
LLVMIsAVAArgInst
|
||||||
LLVMIsAZExtInst
|
LLVMIsAZExtInst
|
||||||
|
@ -522,6 +517,16 @@ LLVMPPCFP128Type
|
||||||
LLVMPPCFP128TypeInContext
|
LLVMPPCFP128TypeInContext
|
||||||
LLVMParseBitcode
|
LLVMParseBitcode
|
||||||
LLVMParseBitcodeInContext
|
LLVMParseBitcodeInContext
|
||||||
|
LLVMPassManagerBuilderCreate
|
||||||
|
LLVMPassManagerBuilderDispose
|
||||||
|
LLVMPassManagerBuilderPopulateModulePassManager
|
||||||
|
LLVMPassManagerBuilderSetDisableSimplifyLibCalls
|
||||||
|
LLVMPassManagerBuilderSetDisableUnitAtATime
|
||||||
|
LLVMPassManagerBuilderPopulateFunctionPassManager
|
||||||
|
LLVMPassManagerBuilderSetDisableUnrollLoops
|
||||||
|
LLVMPassManagerBuilderSetOptLevel
|
||||||
|
LLVMPassManagerBuilderSetSizeLevel
|
||||||
|
LLVMPassManagerBuilderUseInlinerWithThreshold
|
||||||
LLVMPointerSize
|
LLVMPointerSize
|
||||||
LLVMPointerType
|
LLVMPointerType
|
||||||
LLVMPositionBuilder
|
LLVMPositionBuilder
|
||||||
|
|
Loading…
Reference in New Issue