diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-09-02 21:17:18 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-12-08 17:34:50 +0000 |
commit | 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (patch) | |
tree | 62f873df87c7c675557a179e0c4c83fe9f3087bc /contrib/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp | |
parent | cf037972ea8863e2bab7461d77345367d2c1e054 (diff) | |
parent | 7fa27ce4a07f19b07799a767fc29416f3b625afb (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp b/contrib/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp index 3127328c363e..98ea2f21b3c8 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -42,6 +42,8 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/Threading.h" +#include "llvm/Support/VirtualFileSystem.h" +#include "llvm/Support/WithColor.h" #include "llvm/Target/CGPassBuilderOption.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/Scalar.h" @@ -99,6 +101,9 @@ static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden, cl::desc("Disable Copy Propagation pass")); static cl::opt<bool> DisablePartialLibcallInlining("disable-partial-libcall-inlining", cl::Hidden, cl::desc("Disable Partial Libcall Inlining")); +static cl::opt<bool> DisableAtExitBasedGlobalDtorLowering( + "disable-atexit-based-global-dtor-lowering", cl::Hidden, + cl::desc("For MachO, disable atexit()-based global destructor lowering")); static cl::opt<bool> EnableImplicitNullChecks( "enable-implicit-null-checks", cl::desc("Fold null checks into faulting memory operations"), @@ -168,12 +173,6 @@ static cl::opt<GlobalISelAbortMode> EnableGlobalISelAbort( clEnumValN(GlobalISelAbortMode::DisableWithDiag, "2", "Disable the abort but emit a diagnostic on failure"))); -// An option that disables inserting FS-AFDO discriminators before emit. -// This is mainly for debugging and tuning purpose. -static cl::opt<bool> - FSNoFinalDiscrim("fs-no-final-discrim", cl::init(false), cl::Hidden, - cl::desc("Do not insert FS-AFDO discriminators before " - "emit.")); // Disable MIRProfileLoader before RegAlloc. This is for for debugging and // tuning purpose. static cl::opt<bool> DisableRAFSProfileLoader( @@ -878,7 +877,7 @@ void TargetPassConfig::addIRPasses() { // For MachO, lower @llvm.global_dtors into @llvm.global_ctors with // __cxa_atexit() calls to avoid emitting the deprecated __mod_term_func. if (TM->getTargetTriple().isOSBinFormatMachO() && - TM->Options.LowerGlobalDtorsViaCxaAtExit) + !DisableAtExitBasedGlobalDtorLowering) addPass(createLowerGlobalDtorsLegacyPass()); // Make sure that no unreachable blocks are instruction selected. @@ -977,6 +976,8 @@ void TargetPassConfig::addISelPrepare() { if (requiresCodeGenSCCOrder()) addPass(new DummyCGSCCPass); + addPass(createCallBrPass()); + // Add both the safe stack and the stack protection passes: each of them will // only protect functions that have corresponding attributes. addPass(createSafeStackPass()); @@ -1082,8 +1083,8 @@ bool TargetPassConfig::addISelPasses() { if (TM->useEmulatedTLS()) addPass(createLowerEmuTLSPass()); - addPass(createPreISelIntrinsicLoweringPass()); PM->add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis())); + addPass(createPreISelIntrinsicLoweringPass()); addPass(createExpandLargeDivRemPass()); addPass(createExpandLargeFpConvertPass()); addIRPasses(); @@ -1149,9 +1150,9 @@ void TargetPassConfig::addMachinePasses() { sampleprof::FSDiscriminatorPass::Pass1)); const std::string ProfileFile = getFSProfileFile(TM); if (!ProfileFile.empty() && !DisableRAFSProfileLoader) - addPass( - createMIRProfileLoaderPass(ProfileFile, getFSRemappingFile(TM), - sampleprof::FSDiscriminatorPass::Pass1)); + addPass(createMIRProfileLoaderPass(ProfileFile, getFSRemappingFile(TM), + sampleprof::FSDiscriminatorPass::Pass1, + nullptr)); } // Run register allocation and passes that are tightly coupled with it, @@ -1219,14 +1220,6 @@ void TargetPassConfig::addMachinePasses() { addPass(&XRayInstrumentationID); addPass(&PatchableFunctionID); - if (EnableFSDiscriminator && !FSNoFinalDiscrim) - // Add FS discriminators here so that all the instruction duplicates - // in different BBs get their own discriminators. With this, we can "sum" - // the SampleFDO counters instead of using MAX. This will improve the - // SampleFDO profile quality. - addPass(createMIRAddFSDiscriminatorsPass( - sampleprof::FSDiscriminatorPass::PassLast)); - addPreEmitPass(); if (TM->Options.EnableIPRA) @@ -1252,6 +1245,10 @@ void TargetPassConfig::addMachinePasses() { addPass(createMachineOutlinerPass(RunOnAllFunctions)); } + if (EnableFSDiscriminator) + addPass(createMIRAddFSDiscriminatorsPass( + sampleprof::FSDiscriminatorPass::PassLast)); + // Machine function splitter uses the basic block sections feature. Both // cannot be enabled at the same time. Basic block sections takes precedence. // FIXME: In principle, BasicBlockSection::Labels and splitting can used @@ -1264,9 +1261,25 @@ void TargetPassConfig::addMachinePasses() { addPass(llvm::createBasicBlockSectionsPass()); } else if (TM->Options.EnableMachineFunctionSplitter || EnableMachineFunctionSplitter) { + const std::string ProfileFile = getFSProfileFile(TM); + if (!ProfileFile.empty()) { + if (EnableFSDiscriminator) { + addPass(createMIRProfileLoaderPass( + ProfileFile, getFSRemappingFile(TM), + sampleprof::FSDiscriminatorPass::PassLast, nullptr)); + } else { + // Sample profile is given, but FSDiscriminator is not + // enabled, this may result in performance regression. + WithColor::warning() + << "Using AutoFDO without FSDiscriminator for MFS may regress " + "performance."; + } + } addPass(createMachineFunctionSplitterPass()); } + addPostBBSections(); + if (!DisableCFIFixup && TM->Options.EnableCFIFixup) addPass(createCFIFixup()); @@ -1525,9 +1538,9 @@ void TargetPassConfig::addBlockPlacement() { sampleprof::FSDiscriminatorPass::Pass2)); const std::string ProfileFile = getFSProfileFile(TM); if (!ProfileFile.empty() && !DisableLayoutFSProfileLoader) - addPass( - createMIRProfileLoaderPass(ProfileFile, getFSRemappingFile(TM), - sampleprof::FSDiscriminatorPass::Pass2)); + addPass(createMIRProfileLoaderPass(ProfileFile, getFSRemappingFile(TM), + sampleprof::FSDiscriminatorPass::Pass2, + nullptr)); } if (addPass(&MachineBlockPlacementID)) { // Run a separate pass to collect block placement statistics. |