Skip to content

[AMDGPU] Port AMDGPURewriteUndefForPHI to new pass manager #66008

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
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,19 @@ extern char &AMDGPURemoveIncompatibleFunctionsID;
void initializeAMDGPULateCodeGenPreparePass(PassRegistry &);
extern char &AMDGPULateCodeGenPrepareID;

FunctionPass *createAMDGPURewriteUndefForPHIPass();
void initializeAMDGPURewriteUndefForPHIPass(PassRegistry &);
extern char &AMDGPURewriteUndefForPHIPassID;
FunctionPass *createAMDGPURewriteUndefForPHILegacyPass();
void initializeAMDGPURewriteUndefForPHILegacyPass(PassRegistry &);
extern char &AMDGPURewriteUndefForPHILegacyPassID;

class AMDGPURewriteUndefForPHIPass
: public PassInfoMixin<AMDGPURewriteUndefForPHIPass> {
private:
TargetMachine &TM;

public:
AMDGPURewriteUndefForPHIPass(TargetMachine &TM) : TM(TM){};
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

void initializeSIAnnotateControlFlowPass(PassRegistry&);
extern char &SIAnnotateControlFlowPassID;
Expand Down
32 changes: 23 additions & 9 deletions llvm/lib/Target/AMDGPU/AMDGPURewriteUndefForPHI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ using namespace llvm;

namespace {

class AMDGPURewriteUndefForPHI : public FunctionPass {
class AMDGPURewriteUndefForPHILegacy : public FunctionPass {
public:
static char ID;
AMDGPURewriteUndefForPHI() : FunctionPass(ID) {
initializeAMDGPURewriteUndefForPHIPass(*PassRegistry::getPassRegistry());
AMDGPURewriteUndefForPHILegacy() : FunctionPass(ID) {
initializeAMDGPURewriteUndefForPHILegacyPass(*PassRegistry::getPassRegistry());
}
bool runOnFunction(Function &F) override;
StringRef getPassName() const override {
Expand All @@ -91,13 +91,13 @@ class AMDGPURewriteUndefForPHI : public FunctionPass {
};

} // end anonymous namespace
char AMDGPURewriteUndefForPHI::ID = 0;
char AMDGPURewriteUndefForPHILegacy::ID = 0;

INITIALIZE_PASS_BEGIN(AMDGPURewriteUndefForPHI, DEBUG_TYPE,
INITIALIZE_PASS_BEGIN(AMDGPURewriteUndefForPHILegacy, DEBUG_TYPE,
"Rewrite undef for PHI", false, false)
INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_END(AMDGPURewriteUndefForPHI, DEBUG_TYPE,
INITIALIZE_PASS_END(AMDGPURewriteUndefForPHILegacy, DEBUG_TYPE,
"Rewrite undef for PHI", false, false)

bool rewritePHIs(Function &F, UniformityInfo &UA, DominatorTree *DT) {
Expand Down Expand Up @@ -170,13 +170,27 @@ bool rewritePHIs(Function &F, UniformityInfo &UA, DominatorTree *DT) {
return Changed;
}

bool AMDGPURewriteUndefForPHI::runOnFunction(Function &F) {
bool AMDGPURewriteUndefForPHILegacy::runOnFunction(Function &F) {
UniformityInfo &UA =
getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
return rewritePHIs(F, UA, DT);
}

FunctionPass *llvm::createAMDGPURewriteUndefForPHIPass() {
return new AMDGPURewriteUndefForPHI();
PreservedAnalyses
AMDGPURewriteUndefForPHIPass::run(Function &F, FunctionAnalysisManager &AM) {
UniformityInfo &UA = AM.getResult<UniformityInfoAnalysis>(F);
DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why address of here?

bool Changed = rewritePHIs(F, UA, DT);
if (Changed) {
PreservedAnalyses PA;
PA.preserveSet<CFGAnalyses>();
return PA;
}

return PreservedAnalyses::all();
}

FunctionPass *llvm::createAMDGPURewriteUndefForPHILegacyPass() {
return new AMDGPURewriteUndefForPHILegacy();
}
8 changes: 6 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeAMDGPURemoveIncompatibleFunctionsPass(*PR);
initializeAMDGPULowerModuleLDSLegacyPass(*PR);
initializeAMDGPURewriteOutArgumentsPass(*PR);
initializeAMDGPURewriteUndefForPHIPass(*PR);
initializeAMDGPURewriteUndefForPHILegacyPass(*PR);
initializeAMDGPUUnifyMetadataPass(*PR);
initializeSIAnnotateControlFlowPass(*PR);
initializeAMDGPUInsertDelayAluPass(*PR);
Expand Down Expand Up @@ -663,6 +663,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
PM.addPass(AMDGPULowerKernelArgumentsPass(*this));
return true;
}
if (PassName == "amdgpu-rewrite-undef-for-phi") {
PM.addPass(AMDGPURewriteUndefForPHIPass(*this));
return true;
}
return false;
});

Expand Down Expand Up @@ -1150,7 +1154,7 @@ bool GCNPassConfig::addPreISel() {
// TODO: Move this right after structurizeCFG to avoid extra divergence
// analysis. This depends on stopping SIAnnotateControlFlow from making
// control flow modifications.
addPass(createAMDGPURewriteUndefForPHIPass());
addPass(createAMDGPURewriteUndefForPHILegacyPass());
}
addPass(createLCSSAPass());

Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AMDGPU/rewrite-undef-for-phi.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -mtriple=amdgcn-- -S -amdgpu-rewrite-undef-for-phi %s | FileCheck -check-prefix=OPT %s
; RUN: opt -mtriple=amdgcn-- -S -passes=amdgpu-rewrite-undef-for-phi %s | FileCheck -check-prefix=OPT %s

define amdgpu_ps float @basic(float inreg %c, i32 %x) #0 {
; OPT-LABEL: @basic(
Expand Down