mirror of
https://github.com/llvm/llvm-project.git
synced 2026-10-26 13:53:31 +08:00
[StructurizeCFG] Convert legacy pass from RegionPass to FunctionPass (#233940)
Convert StructurizeCFGLegacyPass from a RegionPass to a FunctionPass, just like the NewPM version. Possible follow-ups: - Stop using metadata to propagate information from inner to outer regions. - Remove RegionPass and RGPassManager from LLVM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b0e24233d4
commit
f337c83bbc
2 files changed
+43
-48
No files matched your search
@@ -18,7 +18,6 @@
|
||||
#include "llvm/Analysis/InstructionSimplify.h"
|
||||
#include "llvm/Analysis/RegionInfo.h"
|
||||
#include "llvm/Analysis/RegionIterator.h"
|
||||
#include "llvm/Analysis/RegionPass.h"
|
||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||
#include "llvm/Analysis/UniformityAnalysis.h"
|
||||
#include "llvm/IR/BasicBlock.h"
|
||||
@@ -360,34 +359,18 @@ public:
|
||||
bool makeUniformRegion(Region *R, UniformityInfo &UA);
|
||||
};
|
||||
|
||||
class StructurizeCFGLegacyPass : public RegionPass {
|
||||
class StructurizeCFGLegacyPass : public FunctionPass {
|
||||
bool SkipUniformRegions;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
explicit StructurizeCFGLegacyPass(bool SkipUniformRegions_ = false)
|
||||
: RegionPass(ID), SkipUniformRegions(SkipUniformRegions_) {
|
||||
: FunctionPass(ID), SkipUniformRegions(SkipUniformRegions_) {
|
||||
initializeStructurizeCFGLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnRegion(Region *R, RGPassManager &RGM) override {
|
||||
StructurizeCFG SCFG;
|
||||
SCFG.init(R);
|
||||
const ScalarOptions &Opts =
|
||||
R->getEntry()->getContext().getLibraryOptions().get<ScalarOptions>();
|
||||
if (valueOr(Opts.structurizecfg_skip_uniform_regions, SkipUniformRegions)) {
|
||||
UniformityInfo &UA =
|
||||
getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
|
||||
if (SCFG.makeUniformRegion(R, UA))
|
||||
return false;
|
||||
}
|
||||
Function *F = R->getEntry()->getParent();
|
||||
const TargetTransformInfo *TTI =
|
||||
&getAnalysis<TargetTransformInfoWrapperPass>().getTTI(*F);
|
||||
DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
return SCFG.run(R, DT, TTI);
|
||||
}
|
||||
bool runOnFunction(Function &F) override;
|
||||
|
||||
StringRef getPassName() const override { return "Structurize control flow"; }
|
||||
|
||||
@@ -395,9 +378,9 @@ public:
|
||||
AU.addRequired<UniformityInfoWrapperPass>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<TargetTransformInfoWrapperPass>();
|
||||
AU.addRequired<RegionInfoPass>();
|
||||
|
||||
AU.addPreserved<DominatorTreeWrapperPass>();
|
||||
RegionPass::getAnalysisUsage(AU);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1407,21 +1390,11 @@ void StructurizeCFGPass::printPipeline(
|
||||
OS << "<skip-uniform-regions>";
|
||||
}
|
||||
|
||||
PreservedAnalyses StructurizeCFGPass::run(Function &F,
|
||||
FunctionAnalysisManager &AM) {
|
||||
|
||||
/// Structurize every region in \p RI, processing inner regions before the
|
||||
/// regions that contain them. If \p UI is non-null, skip uniform regions.
|
||||
static bool runImpl(DominatorTree &DT, RegionInfo &RI,
|
||||
const TargetTransformInfo &TTI, UniformityInfo *UI) {
|
||||
bool Changed = false;
|
||||
DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
|
||||
auto &RI = AM.getResult<RegionInfoAnalysis>(F);
|
||||
TargetTransformInfo *TTI = &AM.getResult<TargetIRAnalysis>(F);
|
||||
const ScalarOptions &Opts =
|
||||
F.getContext().getLibraryOptions().get<ScalarOptions>();
|
||||
bool SkipUniform =
|
||||
valueOr(Opts.structurizecfg_skip_uniform_regions, SkipUniformRegions);
|
||||
UniformityInfo *UI = nullptr;
|
||||
if (SkipUniform)
|
||||
UI = &AM.getResult<UniformityInfoAnalysis>(F);
|
||||
|
||||
std::vector<Region *> Regions;
|
||||
addRegionIntoQueue(*RI.getTopLevelRegion(), Regions);
|
||||
while (!Regions.empty()) {
|
||||
@@ -1431,14 +1404,41 @@ PreservedAnalyses StructurizeCFGPass::run(Function &F,
|
||||
StructurizeCFG SCFG;
|
||||
SCFG.init(R);
|
||||
|
||||
if (SkipUniform && SCFG.makeUniformRegion(R, *UI)) {
|
||||
if (UI && SCFG.makeUniformRegion(R, *UI)) {
|
||||
Changed = true; // May have added metadata.
|
||||
continue;
|
||||
}
|
||||
|
||||
Changed |= SCFG.run(R, DT, TTI);
|
||||
Changed |= SCFG.run(R, &DT, &TTI);
|
||||
}
|
||||
if (!Changed)
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool StructurizeCFGLegacyPass::runOnFunction(Function &F) {
|
||||
const ScalarOptions &Opts =
|
||||
F.getContext().getLibraryOptions().get<ScalarOptions>();
|
||||
UniformityInfo *UI = nullptr;
|
||||
if (valueOr(Opts.structurizecfg_skip_uniform_regions, SkipUniformRegions))
|
||||
UI = &getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
|
||||
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
RegionInfo &RI = getAnalysis<RegionInfoPass>().getRegionInfo();
|
||||
const TargetTransformInfo &TTI =
|
||||
getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
|
||||
return runImpl(DT, RI, TTI, UI);
|
||||
}
|
||||
|
||||
PreservedAnalyses StructurizeCFGPass::run(Function &F,
|
||||
FunctionAnalysisManager &AM) {
|
||||
DominatorTree &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
||||
auto &RI = AM.getResult<RegionInfoAnalysis>(F);
|
||||
TargetTransformInfo &TTI = AM.getResult<TargetIRAnalysis>(F);
|
||||
const ScalarOptions &Opts =
|
||||
F.getContext().getLibraryOptions().get<ScalarOptions>();
|
||||
UniformityInfo *UI = nullptr;
|
||||
if (valueOr(Opts.structurizecfg_skip_uniform_regions, SkipUniformRegions))
|
||||
UI = &AM.getResult<UniformityInfoAnalysis>(F);
|
||||
|
||||
if (!runImpl(DT, RI, TTI, UI))
|
||||
return PreservedAnalyses::all();
|
||||
PreservedAnalyses PA;
|
||||
PA.preserve<DominatorTreeAnalysis>();
|
||||
|
||||
@@ -70,8 +70,7 @@
|
||||
; GCN-O0-NEXT: Post-Dominator Tree Construction
|
||||
; GCN-O0-NEXT: Dominance Frontier Construction
|
||||
; GCN-O0-NEXT: Detect single entry single exit regions
|
||||
; GCN-O0-NEXT: Region Pass Manager
|
||||
; GCN-O0-NEXT: Structurize control flow
|
||||
; GCN-O0-NEXT: Structurize control flow
|
||||
; GCN-O0-NEXT: Cycle Info Analysis
|
||||
; GCN-O0-NEXT: Uniformity Analysis
|
||||
; GCN-O0-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
@@ -279,8 +278,7 @@
|
||||
; GCN-O1-NEXT: Post-Dominator Tree Construction
|
||||
; GCN-O1-NEXT: Dominance Frontier Construction
|
||||
; GCN-O1-NEXT: Detect single entry single exit regions
|
||||
; GCN-O1-NEXT: Region Pass Manager
|
||||
; GCN-O1-NEXT: Structurize control flow
|
||||
; GCN-O1-NEXT: Structurize control flow
|
||||
; GCN-O1-NEXT: Cycle Info Analysis
|
||||
; GCN-O1-NEXT: Uniformity Analysis
|
||||
; GCN-O1-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
@@ -600,8 +598,7 @@
|
||||
; GCN-O1-OPTS-NEXT: Post-Dominator Tree Construction
|
||||
; GCN-O1-OPTS-NEXT: Dominance Frontier Construction
|
||||
; GCN-O1-OPTS-NEXT: Detect single entry single exit regions
|
||||
; GCN-O1-OPTS-NEXT: Region Pass Manager
|
||||
; GCN-O1-OPTS-NEXT: Structurize control flow
|
||||
; GCN-O1-OPTS-NEXT: Structurize control flow
|
||||
; GCN-O1-OPTS-NEXT: Cycle Info Analysis
|
||||
; GCN-O1-OPTS-NEXT: Uniformity Analysis
|
||||
; GCN-O1-OPTS-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
@@ -932,8 +929,7 @@
|
||||
; GCN-O2-NEXT: Post-Dominator Tree Construction
|
||||
; GCN-O2-NEXT: Dominance Frontier Construction
|
||||
; GCN-O2-NEXT: Detect single entry single exit regions
|
||||
; GCN-O2-NEXT: Region Pass Manager
|
||||
; GCN-O2-NEXT: Structurize control flow
|
||||
; GCN-O2-NEXT: Structurize control flow
|
||||
; GCN-O2-NEXT: Cycle Info Analysis
|
||||
; GCN-O2-NEXT: Uniformity Analysis
|
||||
; GCN-O2-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
@@ -1281,8 +1277,7 @@
|
||||
; GCN-O3-NEXT: Post-Dominator Tree Construction
|
||||
; GCN-O3-NEXT: Dominance Frontier Construction
|
||||
; GCN-O3-NEXT: Detect single entry single exit regions
|
||||
; GCN-O3-NEXT: Region Pass Manager
|
||||
; GCN-O3-NEXT: Structurize control flow
|
||||
; GCN-O3-NEXT: Structurize control flow
|
||||
; GCN-O3-NEXT: Cycle Info Analysis
|
||||
; GCN-O3-NEXT: Uniformity Analysis
|
||||
; GCN-O3-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
|
||||
Reference in new issue
Block a user