-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU][NewPM] Port SIOptimizeVGPRLiveRange pass to NPM. #117686
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
cdevadas
merged 2 commits into
main
from
users/cdevadas/port-si-optimize-vgpr-lr-to-npm
Nov 29, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "SIOptimizeVGPRLiveRange.h" | ||
#include "AMDGPU.h" | ||
#include "GCNSubtarget.h" | ||
#include "MCTargetDesc/AMDGPUMCTargetDesc.h" | ||
|
@@ -86,7 +87,7 @@ using namespace llvm; | |
|
||
namespace { | ||
|
||
class SIOptimizeVGPRLiveRange : public MachineFunctionPass { | ||
class SIOptimizeVGPRLiveRange { | ||
private: | ||
const SIRegisterInfo *TRI = nullptr; | ||
const SIInstrInfo *TII = nullptr; | ||
|
@@ -96,7 +97,10 @@ class SIOptimizeVGPRLiveRange : public MachineFunctionPass { | |
MachineRegisterInfo *MRI = nullptr; | ||
|
||
public: | ||
static char ID; | ||
SIOptimizeVGPRLiveRange(LiveVariables *LV, MachineDominatorTree *MDT, | ||
MachineLoopInfo *Loops) | ||
: LV(LV), MDT(MDT), Loops(Loops) {} | ||
bool run(MachineFunction &MF); | ||
|
||
MachineBasicBlock *getElseTarget(MachineBasicBlock *MBB) const; | ||
|
||
|
@@ -136,8 +140,13 @@ class SIOptimizeVGPRLiveRange : public MachineFunctionPass { | |
Register Reg, MachineBasicBlock *LoopHeader, | ||
SmallSetVector<MachineBasicBlock *, 2> &LoopBlocks, | ||
SmallVectorImpl<MachineInstr *> &Instructions) const; | ||
}; | ||
|
||
SIOptimizeVGPRLiveRange() : MachineFunctionPass(ID) {} | ||
class SIOptimizeVGPRLiveRangeLegacy : public MachineFunctionPass { | ||
public: | ||
static char ID; | ||
|
||
SIOptimizeVGPRLiveRangeLegacy() : MachineFunctionPass(ID) {} | ||
|
||
bool runOnMachineFunction(MachineFunction &MF) override; | ||
|
||
|
@@ -611,35 +620,59 @@ void SIOptimizeVGPRLiveRange::optimizeWaterfallLiveRange( | |
} | ||
} | ||
|
||
char SIOptimizeVGPRLiveRange::ID = 0; | ||
char SIOptimizeVGPRLiveRangeLegacy::ID = 0; | ||
|
||
INITIALIZE_PASS_BEGIN(SIOptimizeVGPRLiveRange, DEBUG_TYPE, | ||
INITIALIZE_PASS_BEGIN(SIOptimizeVGPRLiveRangeLegacy, DEBUG_TYPE, | ||
"SI Optimize VGPR LiveRange", false, false) | ||
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass) | ||
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass) | ||
INITIALIZE_PASS_DEPENDENCY(LiveVariablesWrapperPass) | ||
INITIALIZE_PASS_END(SIOptimizeVGPRLiveRange, DEBUG_TYPE, | ||
INITIALIZE_PASS_END(SIOptimizeVGPRLiveRangeLegacy, DEBUG_TYPE, | ||
"SI Optimize VGPR LiveRange", false, false) | ||
|
||
char &llvm::SIOptimizeVGPRLiveRangeID = SIOptimizeVGPRLiveRange::ID; | ||
char &llvm::SIOptimizeVGPRLiveRangeLegacyID = SIOptimizeVGPRLiveRangeLegacy::ID; | ||
|
||
FunctionPass *llvm::createSIOptimizeVGPRLiveRangeLegacyPass() { | ||
return new SIOptimizeVGPRLiveRangeLegacy(); | ||
} | ||
|
||
bool SIOptimizeVGPRLiveRangeLegacy::runOnMachineFunction(MachineFunction &MF) { | ||
if (skipFunction(MF.getFunction())) | ||
return false; | ||
|
||
FunctionPass *llvm::createSIOptimizeVGPRLiveRangePass() { | ||
return new SIOptimizeVGPRLiveRange(); | ||
LiveVariables *LV = &getAnalysis<LiveVariablesWrapperPass>().getLV(); | ||
MachineDominatorTree *MDT = | ||
&getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree(); | ||
MachineLoopInfo *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI(); | ||
return SIOptimizeVGPRLiveRange(LV, MDT, Loops).run(MF); | ||
} | ||
|
||
bool SIOptimizeVGPRLiveRange::runOnMachineFunction(MachineFunction &MF) { | ||
PreservedAnalyses | ||
SIOptimizeVGPRLiveRangePass::run(MachineFunction &MF, | ||
MachineFunctionAnalysisManager &MFAM) { | ||
MFPropsModifier _(*this, MF); | ||
LiveVariables *LV = &MFAM.getResult<LiveVariablesAnalysis>(MF); | ||
MachineDominatorTree *MDT = &MFAM.getResult<MachineDominatorTreeAnalysis>(MF); | ||
MachineLoopInfo *Loops = &MFAM.getResult<MachineLoopAnalysis>(MF); | ||
|
||
bool Changed = SIOptimizeVGPRLiveRange(LV, MDT, Loops).run(MF); | ||
if (!Changed) | ||
return PreservedAnalyses::all(); | ||
|
||
auto PA = getMachineFunctionPassPreservedAnalyses(); | ||
PA.preserve<LiveVariablesAnalysis>(); | ||
PA.preserve<DominatorTreeAnalysis>(); | ||
PA.preserve<MachineLoopAnalysis>(); | ||
PA.preserveSet<CFGAnalyses>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should fix old pm in follow up |
||
return PA; | ||
} | ||
|
||
bool SIOptimizeVGPRLiveRange::run(MachineFunction &MF) { | ||
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>(); | ||
TII = ST.getInstrInfo(); | ||
TRI = &TII->getRegisterInfo(); | ||
MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree(); | ||
Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI(); | ||
LV = &getAnalysis<LiveVariablesWrapperPass>().getLV(); | ||
MRI = &MF.getRegInfo(); | ||
|
||
if (skipFunction(MF.getFunction())) | ||
return false; | ||
|
||
bool MadeChange = false; | ||
|
||
// TODO: we need to think about the order of visiting the blocks to get | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===- SIOptimizeVGPRLiveRange.h --------------------------------*- C++- *-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_AMDGPU_SIOPTIMIZEVGPRLIVERANGE_H | ||
#define LLVM_LIB_TARGET_AMDGPU_SIOPTIMIZEVGPRLIVERANGE_H | ||
|
||
#include "llvm/CodeGen/MachinePassManager.h" | ||
|
||
namespace llvm { | ||
class SIOptimizeVGPRLiveRangePass | ||
: public PassInfoMixin<SIOptimizeVGPRLiveRangePass> { | ||
public: | ||
PreservedAnalyses run(MachineFunction &MF, | ||
MachineFunctionAnalysisManager &MFAM); | ||
|
||
MachineFunctionProperties getRequiredProperties() const { | ||
return MachineFunctionProperties().set( | ||
MachineFunctionProperties::Property::IsSSA); | ||
} | ||
|
||
MachineFunctionProperties getClearedProperties() const { | ||
return MachineFunctionProperties().set( | ||
MachineFunctionProperties::Property::NoPHIs); | ||
} | ||
}; | ||
} // namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_AMDGPU_SIOPTIMIZEVGPRLIVERANGE_H |
1 change: 1 addition & 0 deletions
1
llvm/test/CodeGen/AMDGPU/opt-vgpr-live-range-verifier-error.mir
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
1 change: 1 addition & 0 deletions
1
llvm/test/CodeGen/AMDGPU/si-opt-vgpr-liverange-bug-deadlanes.mir
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
1 change: 1 addition & 0 deletions
1
llvm/test/CodeGen/AMDGPU/si-optimize-vgpr-live-range-dbg-instr.mir
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
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.
Uh oh!
There was an error while loading. Please reload this page.