Auto merge of #48346 - emilio:pgo, r=alexcrichton
Add basic PGO support. This PR adds two mutually exclusive options for profile usage and generation using LLVM's instruction profile generation (the same as clang uses), `-C pgo-use` and `-C pgo-gen`. See each commit for details.
This commit is contained in:
commit
13a86f4d85
18 changed files with 212 additions and 10 deletions
|
@ -44,6 +44,10 @@
|
|||
|
||||
#include "llvm-c/Transforms/PassManagerBuilder.h"
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
#define PGO_AVAILABLE
|
||||
#endif
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::legacy;
|
||||
|
||||
|
@ -428,12 +432,27 @@ extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
|||
|
||||
extern "C" void LLVMRustConfigurePassManagerBuilder(
|
||||
LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
|
||||
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize) {
|
||||
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize,
|
||||
const char* PGOGenPath, const char* PGOUsePath) {
|
||||
// Ignore mergefunc for now as enabling it causes crashes.
|
||||
// unwrap(PMBR)->MergeFunctions = MergeFunctions;
|
||||
unwrap(PMBR)->SLPVectorize = SLPVectorize;
|
||||
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
|
||||
unwrap(PMBR)->LoopVectorize = LoopVectorize;
|
||||
|
||||
#ifdef PGO_AVAILABLE
|
||||
if (PGOGenPath) {
|
||||
assert(!PGOUsePath);
|
||||
unwrap(PMBR)->EnablePGOInstrGen = true;
|
||||
unwrap(PMBR)->PGOInstrGen = PGOGenPath;
|
||||
}
|
||||
if (PGOUsePath) {
|
||||
assert(!PGOGenPath);
|
||||
unwrap(PMBR)->PGOInstrUse = PGOUsePath;
|
||||
}
|
||||
#else
|
||||
assert(!PGOGenPath && !PGOUsePath && "Should've caught earlier");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
|
||||
|
@ -766,6 +785,15 @@ LLVMRustThinLTOAvailable() {
|
|||
#endif
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustPGOAvailable() {
|
||||
#ifdef PGO_AVAILABLE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
|
||||
// Here you'll find an implementation of ThinLTO as used by the Rust compiler
|
||||
|
|
|
@ -1021,6 +1021,7 @@ enum class LLVMRustDiagnosticKind {
|
|||
OptimizationRemarkAnalysisAliasing,
|
||||
OptimizationRemarkOther,
|
||||
OptimizationFailure,
|
||||
PGOProfile,
|
||||
};
|
||||
|
||||
static LLVMRustDiagnosticKind toRust(DiagnosticKind Kind) {
|
||||
|
@ -1043,6 +1044,8 @@ static LLVMRustDiagnosticKind toRust(DiagnosticKind Kind) {
|
|||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute;
|
||||
case DK_OptimizationRemarkAnalysisAliasing:
|
||||
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing;
|
||||
case DK_PGOProfile:
|
||||
return LLVMRustDiagnosticKind::PGOProfile;
|
||||
default:
|
||||
return (Kind >= DK_FirstRemark && Kind <= DK_LastRemark)
|
||||
? LLVMRustDiagnosticKind::OptimizationRemarkOther
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue