1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[PGO] Control Height Reduction

Summary:
Control height reduction merges conditional blocks of code and reduces the
number of conditional branches in the hot path based on profiles.

if (hot_cond1) { // Likely true.
  do_stg_hot1();
}
if (hot_cond2) { // Likely true.
  do_stg_hot2();
}

->

if (hot_cond1 && hot_cond2) { // Hot path.
  do_stg_hot1();
  do_stg_hot2();
} else { // Cold path.
  if (hot_cond1) {
    do_stg_hot1();
  }
  if (hot_cond2) {
    do_stg_hot2();
  }
}

This speeds up some internal benchmarks up to ~30%.

Reviewers: davidxl

Reviewed By: davidxl

Subscribers: xbolva00, dmgreen, mehdi_amini, llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D50591

llvm-svn: 341386
This commit is contained in:
Hiroshi Yamauchi 2018-09-04 17:19:13 +00:00
parent e97aca491d
commit a56dc5d07f
11 changed files with 3983 additions and 0 deletions

View File

@ -103,6 +103,7 @@ void initializeCodeGenPreparePass(PassRegistry&);
void initializeConstantHoistingLegacyPassPass(PassRegistry&); void initializeConstantHoistingLegacyPassPass(PassRegistry&);
void initializeConstantMergeLegacyPassPass(PassRegistry&); void initializeConstantMergeLegacyPassPass(PassRegistry&);
void initializeConstantPropagationPass(PassRegistry&); void initializeConstantPropagationPass(PassRegistry&);
void initializeControlHeightReductionLegacyPassPass(PassRegistry&);
void initializeCorrelatedValuePropagationPass(PassRegistry&); void initializeCorrelatedValuePropagationPass(PassRegistry&);
void initializeCostModelAnalysisPass(PassRegistry&); void initializeCostModelAnalysisPass(PassRegistry&);
void initializeCrossDSOCFIPass(PassRegistry&); void initializeCrossDSOCFIPass(PassRegistry&);

View File

@ -88,6 +88,7 @@ namespace {
(void) llvm::createCalledValuePropagationPass(); (void) llvm::createCalledValuePropagationPass();
(void) llvm::createConstantMergePass(); (void) llvm::createConstantMergePass();
(void) llvm::createConstantPropagationPass(); (void) llvm::createConstantPropagationPass();
(void) llvm::createControlHeightReductionLegacyPass();
(void) llvm::createCostModelAnalysisPass(); (void) llvm::createCostModelAnalysisPass();
(void) llvm::createDeadArgEliminationPass(); (void) llvm::createDeadArgEliminationPass();
(void) llvm::createDeadCodeEliminationPass(); (void) llvm::createDeadCodeEliminationPass();

View File

@ -0,0 +1,32 @@
//===- ControlHeightReduction.h - Control Height Reduction ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This pass merges conditional blocks of code and reduces the number of
// conditional branches in the hot paths based on profiles.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_CONTROLHEIGHTREDUCTION_H
#define LLVM_TRANSFORMS_INSTRUMENTATION_CONTROLHEIGHTREDUCTION_H
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
namespace llvm {
class ControlHeightReductionPass :
public PassInfoMixin<ControlHeightReductionPass> {
public:
ControlHeightReductionPass();
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};
} // end namespace llvm
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_CONTROLHEIGHTREDUCTION_H

View File

@ -113,6 +113,13 @@ extern char &LoopSimplifyID;
/// This function returns a new pass that downgrades the debug info in the /// This function returns a new pass that downgrades the debug info in the
/// module to line tables only. /// module to line tables only.
ModulePass *createStripNonLineTableDebugInfoPass(); ModulePass *createStripNonLineTableDebugInfoPass();
//===----------------------------------------------------------------------===//
//
// ControlHeightReudction - Merges conditional blocks of code and reduces the
// number of conditional branches in the hot paths based on profiles.
//
FunctionPass *createControlHeightReductionLegacyPass();
} }
#endif #endif

View File

@ -87,6 +87,7 @@
#include "llvm/Transforms/IPO/WholeProgramDevirt.h" #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
#include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/Transforms/Instrumentation/BoundsChecking.h" #include "llvm/Transforms/Instrumentation/BoundsChecking.h"
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h" #include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
#include "llvm/Transforms/Instrumentation/InstrProfiling.h" #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h" #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
@ -193,6 +194,10 @@ static cl::opt<bool> EnableSyntheticCounts(
static Regex DefaultAliasRegex( static Regex DefaultAliasRegex(
"^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$"); "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
static cl::opt<bool>
EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
cl::desc("Enable control height reduction optimization (CHR)"));
static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) { static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
switch (Level) { switch (Level) {
case PassBuilder::O0: case PassBuilder::O0:
@ -486,6 +491,10 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
FPM.addPass(InstCombinePass()); FPM.addPass(InstCombinePass());
invokePeepholeEPCallbacks(FPM, Level); invokePeepholeEPCallbacks(FPM, Level);
if (EnableCHR && Level == O3 && PGOOpt &&
(!PGOOpt->ProfileUseFile.empty() || !PGOOpt->SampleProfileFile.empty()))
FPM.addPass(ControlHeightReductionPass());
return FPM; return FPM;
} }

View File

@ -148,6 +148,7 @@ FUNCTION_PASS("bounds-checking", BoundsCheckingPass())
FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass()) FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass()) FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass())
FUNCTION_PASS("consthoist", ConstantHoistingPass()) FUNCTION_PASS("consthoist", ConstantHoistingPass())
FUNCTION_PASS("chr", ControlHeightReductionPass())
FUNCTION_PASS("correlated-propagation", CorrelatedValuePropagationPass()) FUNCTION_PASS("correlated-propagation", CorrelatedValuePropagationPass())
FUNCTION_PASS("dce", DCEPass()) FUNCTION_PASS("dce", DCEPass())
FUNCTION_PASS("div-rem-pairs", DivRemPairsPass()) FUNCTION_PASS("div-rem-pairs", DivRemPairsPass())

View File

@ -152,6 +152,10 @@ static cl::opt<bool> EnableGVNSink(
"enable-gvn-sink", cl::init(false), cl::Hidden, "enable-gvn-sink", cl::init(false), cl::Hidden,
cl::desc("Enable the GVN sinking pass (default = off)")); cl::desc("Enable the GVN sinking pass (default = off)"));
static cl::opt<bool>
EnableCHR("enable-chr", cl::init(true), cl::Hidden,
cl::desc("Enable control height reduction optimization (CHR)"));
PassManagerBuilder::PassManagerBuilder() { PassManagerBuilder::PassManagerBuilder() {
OptLevel = 2; OptLevel = 2;
SizeLevel = 0; SizeLevel = 0;
@ -411,6 +415,10 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
// Clean up after everything. // Clean up after everything.
addInstructionCombiningPass(MPM); addInstructionCombiningPass(MPM);
addExtensionsToPM(EP_Peephole, MPM); addExtensionsToPM(EP_Peephole, MPM);
if (EnableCHR && OptLevel >= 3 &&
(!PGOInstrUse.empty() || !PGOSampleUse.empty()))
MPM.add(createControlHeightReductionLegacyPass());
} }
void PassManagerBuilder::populateModulePassManager( void PassManagerBuilder::populateModulePassManager(

View File

@ -2,6 +2,7 @@ add_llvm_library(LLVMInstrumentation
AddressSanitizer.cpp AddressSanitizer.cpp
BoundsChecking.cpp BoundsChecking.cpp
CGProfile.cpp CGProfile.cpp
ControlHeightReduction.cpp
DataFlowSanitizer.cpp DataFlowSanitizer.cpp
GCOVProfiling.cpp GCOVProfiling.cpp
MemorySanitizer.cpp MemorySanitizer.cpp

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,7 @@ void llvm::initializeInstrumentation(PassRegistry &Registry) {
initializeAddressSanitizerPass(Registry); initializeAddressSanitizerPass(Registry);
initializeAddressSanitizerModulePass(Registry); initializeAddressSanitizerModulePass(Registry);
initializeBoundsCheckingLegacyPassPass(Registry); initializeBoundsCheckingLegacyPassPass(Registry);
initializeControlHeightReductionLegacyPassPass(Registry);
initializeGCOVProfilerLegacyPassPass(Registry); initializeGCOVProfilerLegacyPassPass(Registry);
initializePGOInstrumentationGenLegacyPassPass(Registry); initializePGOInstrumentationGenLegacyPassPass(Registry);
initializePGOInstrumentationUseLegacyPassPass(Registry); initializePGOInstrumentationUseLegacyPassPass(Registry);

File diff suppressed because it is too large Load Diff