-
Notifications
You must be signed in to change notification settings - Fork 13.5k
StructurizeCFG: Add SkipUniformRegions pass parameter to new PM version #102812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arsenm
merged 1 commit into
main
from
users/arsenm/structurizecfg-pass-parameter-skip-uniform-regions
Aug 12, 2024
Merged
StructurizeCFG: Add SkipUniformRegions pass parameter to new PM version #102812
arsenm
merged 1 commit into
main
from
users/arsenm/structurizecfg-pass-parameter-skip-uniform-regions
Aug 12, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Aug 11, 2024
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesKeep respecting the old cl::opt for now. Full diff: https://github.com/llvm/llvm-project/pull/102812.diff 5 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Scalar/StructurizeCFG.h b/llvm/include/llvm/Transforms/Scalar/StructurizeCFG.h
index 50d41acd529e76..f68067d9354583 100644
--- a/llvm/include/llvm/Transforms/Scalar/StructurizeCFG.h
+++ b/llvm/include/llvm/Transforms/Scalar/StructurizeCFG.h
@@ -13,6 +13,15 @@
namespace llvm {
struct StructurizeCFGPass : PassInfoMixin<StructurizeCFGPass> {
+private:
+ bool SkipUniformRegions;
+
+public:
+ StructurizeCFGPass(bool SkipUniformRegions = false);
+
+ void printPipeline(raw_ostream &OS,
+ function_ref<StringRef(StringRef)> MapClassName2PassName);
+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
} // namespace llvm
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 7bc1c870ce5191..46f43f3de4705c 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1085,6 +1085,11 @@ Expected<bool> parseSeparateConstOffsetFromGEPPassOptions(StringRef Params) {
"SeparateConstOffsetFromGEP");
}
+Expected<bool> parseStructurizeCFGPassOptions(StringRef Params) {
+ return PassBuilder::parseSinglePassOption(Params, "skip-uniform-regions",
+ "StructurizeCFG");
+}
+
Expected<OptimizationLevel>
parseFunctionSimplificationPipelineOptions(StringRef Params) {
std::optional<OptimizationLevel> L = parseOptLevel(Params);
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 95842d15a35bf6..0cec9fbd7cd05e 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -458,7 +458,6 @@ FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
FUNCTION_PASS("stack-protector", StackProtectorPass(TM))
FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
-FUNCTION_PASS("structurizecfg", StructurizeCFGPass())
FUNCTION_PASS("tailcallelim", TailCallElimPass())
FUNCTION_PASS("tlshoist", TLSVariableHoistPass())
FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
@@ -586,6 +585,12 @@ FUNCTION_PASS_WITH_PARAMS(
"sroa", "SROAPass",
[](SROAOptions PreserveCFG) { return SROAPass(PreserveCFG); },
parseSROAOptions, "preserve-cfg;modify-cfg")
+FUNCTION_PASS_WITH_PARAMS(
+ "structurizecfg", "StructurizeCFG",
+ [](bool SkipUniformRegions) {
+ return StructurizeCFGPass(SkipUniformRegions);
+ },
+ parseStructurizeCFGPassOptions, "skip-uniform-regions")
FUNCTION_PASS_WITH_PARAMS(
"win-eh-prepare", "WinEHPreparePass",
[](bool DemoteCatchSwitchPHIOnly) {
diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
index 9c711ec183821f..a6ed58ac9d47f2 100644
--- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -1212,20 +1212,46 @@ static void addRegionIntoQueue(Region &R, std::vector<Region *> &Regions) {
addRegionIntoQueue(*E, Regions);
}
+StructurizeCFGPass::StructurizeCFGPass(bool SkipUniformRegions_)
+ : SkipUniformRegions(SkipUniformRegions_) {
+ if (ForceSkipUniformRegions.getNumOccurrences())
+ SkipUniformRegions = ForceSkipUniformRegions.getValue();
+}
+
+void StructurizeCFGPass::printPipeline(
+ raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
+ static_cast<PassInfoMixin<StructurizeCFGPass> *>(this)->printPipeline(
+ OS, MapClassName2PassName);
+ if (SkipUniformRegions)
+ OS << "<skip-uniform-regions>";
+}
+
PreservedAnalyses StructurizeCFGPass::run(Function &F,
FunctionAnalysisManager &AM) {
bool Changed = false;
DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
auto &RI = AM.getResult<RegionInfoAnalysis>(F);
+
+ UniformityInfo *UI = nullptr;
+ if (SkipUniformRegions)
+ UI = &AM.getResult<UniformityInfoAnalysis>(F);
+
std::vector<Region *> Regions;
addRegionIntoQueue(*RI.getTopLevelRegion(), Regions);
while (!Regions.empty()) {
Region *R = Regions.back();
+ Regions.pop_back();
+
StructurizeCFG SCFG;
SCFG.init(R);
+
+ if (SkipUniformRegions && SCFG.makeUniformRegion(R, *UI)) {
+ Changed = true; // May have added metadata.
+ continue;
+ }
+
Changed |= SCFG.run(R, DT);
- Regions.pop_back();
}
if (!Changed)
return PreservedAnalyses::all();
diff --git a/llvm/test/Transforms/StructurizeCFG/AMDGPU/uniform-regions.ll b/llvm/test/Transforms/StructurizeCFG/AMDGPU/uniform-regions.ll
index ae73eedd4f502b..34c73ab8fd74f3 100644
--- a/llvm/test/Transforms/StructurizeCFG/AMDGPU/uniform-regions.ll
+++ b/llvm/test/Transforms/StructurizeCFG/AMDGPU/uniform-regions.ll
@@ -1,5 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -mtriple=amdgcn-- -S -o - -structurizecfg -structurizecfg-skip-uniform-regions -structurizecfg-relaxed-uniform-regions < %s | FileCheck %s
+; RUN: opt -mtriple=amdgcn-- -S -o - -passes='structurizecfg<skip-uniform-regions>' -structurizecfg-relaxed-uniform-regions < %s | FileCheck %s
+; RUN: opt -mtriple=amdgcn-- -S -o - -passes=structurizecfg -structurizecfg-skip-uniform-regions -structurizecfg-relaxed-uniform-regions < %s | FileCheck %s
define amdgpu_cs void @uniform(i32 inreg %v) {
; CHECK-LABEL: @uniform(
|
0bf4c6c
to
20d5538
Compare
fb38b82
to
306343c
Compare
This was referenced Aug 11, 2024
jdoerfert
approved these changes
Aug 11, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
This was referenced Aug 12, 2024
e7184ca
to
47c8556
Compare
Base automatically changed from
users/arsenm/newpm/amdgpu-port-amdgpulatecodegenprepare
to
main
August 12, 2024 11:09
Keep respecting the old cl::opt for now.
306343c
to
74f668e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Keep respecting the old cl::opt for now.