[llvm] b164004 - [AMDGPU] isPassEnabled() helper to check cl::opt and OptLevel
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 6 22:15:15 PDT 2021
Author: Stanislav Mekhanoshin
Date: 2021-07-06T21:53:35-07:00
New Revision: b16400449fc763fdae2d2ce809ce61c88acb6684
URL: https://github.com/llvm/llvm-project/commit/b16400449fc763fdae2d2ce809ce61c88acb6684
DIFF: https://github.com/llvm/llvm-project/commit/b16400449fc763fdae2d2ce809ce61c88acb6684.diff
LOG: [AMDGPU] isPassEnabled() helper to check cl::opt and OptLevel
We have several checks for both cl::opt and OptLevel over our
pass config, although these checks do not properly work if
default value of a cl::opt will be false. Create a helper to
use instead and properly handle it. NFC for now.
Differential Revision: https://reviews.llvm.org/D105517
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 1b4cbc9634b9..f611c893cde4 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -785,6 +785,19 @@ class AMDGPUPassConfig : public TargetPassConfig {
bool addGCPasses() override;
std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
+
+ /// Check if a pass is enabled given \p Opt option. The option always
+ /// overrides defaults if explicitely used. Otherwise its default will
+ /// be used given that a pass shall work at an optimization \p Level
+ /// minimum.
+ bool isPassEnabled(const cl::opt<bool> &Opt,
+ CodeGenOpt::Level Level = CodeGenOpt::Default) const {
+ if (Opt.getNumOccurrences())
+ return Opt;
+ if (TM->getOptLevel() < Level)
+ return false;
+ return Opt;
+ }
};
std::unique_ptr<CSEConfigBase> AMDGPUPassConfig::getCSEConfig() const {
@@ -928,9 +941,7 @@ void AMDGPUPassConfig::addIRPasses() {
if (EnableSROA)
addPass(createSROAPass());
- if (EnableScalarIRPasses.getNumOccurrences()
- ? EnableScalarIRPasses
- : TM.getOptLevel() > CodeGenOpt::Less)
+ if (isPassEnabled(EnableScalarIRPasses))
addStraightLineScalarOptimizationPasses();
if (EnableAMDGPUAliasAnalysis) {
@@ -962,9 +973,7 @@ void AMDGPUPassConfig::addIRPasses() {
// %1 = shl %a, 2
//
// but EarlyCSE can do neither of them.
- if (EnableScalarIRPasses.getNumOccurrences()
- ? EnableScalarIRPasses
- : TM.getOptLevel() > CodeGenOpt::Less)
+ if (isPassEnabled(EnableScalarIRPasses))
addEarlyCSEOrGVNPass();
}
@@ -980,9 +989,7 @@ void AMDGPUPassConfig::addCodeGenPrepare() {
TargetPassConfig::addCodeGenPrepare();
- if (EnableLoadStoreVectorizer.getNumOccurrences()
- ? EnableLoadStoreVectorizer
- : TM->getOptLevel() > CodeGenOpt::Less)
+ if (isPassEnabled(EnableLoadStoreVectorizer))
addPass(createLoadStoreVectorizerPass());
// LowerSwitch pass may introduce unreachable blocks that can
@@ -1107,9 +1114,7 @@ void GCNPassConfig::addMachineSSAOptimization() {
if (EnableDPPCombine)
addPass(&GCNDPPCombineID);
addPass(&SILoadStoreOptimizerID);
- if (EnableSDWAPeephole.getNumOccurrences()
- ? EnableSDWAPeephole
- : TM->getOptLevel() > CodeGenOpt::Less) {
+ if (isPassEnabled(EnableSDWAPeephole)) {
addPass(&SIPeepholeSDWAID);
addPass(&EarlyMachineLICMID);
addPass(&MachineCSEID);
@@ -1200,9 +1205,7 @@ void GCNPassConfig::addOptimizedRegAlloc() {
if (OptExecMaskPreRA)
insertPass(&MachineSchedulerID, &SIOptimizeExecMaskingPreRAID);
- if (EnablePreRAOptimizations.getNumOccurrences()
- ? EnablePreRAOptimizations
- : TM->getOptLevel() > CodeGenOpt::Less)
+ if (isPassEnabled(EnablePreRAOptimizations))
insertPass(&RenameIndependentSubregsID, &GCNPreRAOptimizationsID);
// This is not an essential optimization and it has a noticeable impact on
More information about the llvm-commits
mailing list