-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CodeGen][NewPM] Port RegUsageInfoCollector pass to NPM #113874
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
optimisan
merged 5 commits into
main
from
users/Akshat-Oke/10-28-_codegen_newpm_port_regusageinfocollector_pass_to_npm
Nov 15, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d2f2780
[CodeGen][NewPM] Port RegUsageInfoCollector pass to NPM
optimisan 3b38548
update tests and pass name in debug
optimisan 3608f47
fix incorrect changes
optimisan d564fe5
propagate PhysicalRegisterUsageAnalysis renaming
optimisan cd123fe
change irtranslator to prologepilog
optimisan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===- llvm/CodeGen/RegUsageInfoCollector.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_CODEGEN_REGUSAGEINFOCOLLECTOR_H | ||
#define LLVM_CODEGEN_REGUSAGEINFOCOLLECTOR_H | ||
|
||
#include "llvm/CodeGen/MachinePassManager.h" | ||
|
||
namespace llvm { | ||
|
||
class RegUsageInfoCollectorPass | ||
: public AnalysisInfoMixin<RegUsageInfoCollectorPass> { | ||
public: | ||
PreservedAnalyses run(MachineFunction &MF, | ||
MachineFunctionAnalysisManager &MFAM); | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_CODEGEN_REGUSAGEINFOCOLLECTOR_H |
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
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 |
---|---|---|
|
@@ -16,9 +16,11 @@ | |
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/CodeGen/RegUsageInfoCollector.h" | ||
#include "llvm/ADT/Statistic.h" | ||
#include "llvm/CodeGen/MachineFunctionPass.h" | ||
#include "llvm/CodeGen/MachineOperand.h" | ||
#include "llvm/CodeGen/MachinePassManager.h" | ||
#include "llvm/CodeGen/MachineRegisterInfo.h" | ||
#include "llvm/CodeGen/Passes.h" | ||
#include "llvm/CodeGen/RegisterUsageInfo.h" | ||
|
@@ -36,11 +38,23 @@ STATISTIC(NumCSROpt, | |
|
||
namespace { | ||
|
||
class RegUsageInfoCollector : public MachineFunctionPass { | ||
class RegUsageInfoCollector { | ||
PhysicalRegisterUsageInfo &PRUI; | ||
|
||
public: | ||
RegUsageInfoCollector() : MachineFunctionPass(ID) { | ||
PassRegistry &Registry = *PassRegistry::getPassRegistry(); | ||
initializeRegUsageInfoCollectorPass(Registry); | ||
RegUsageInfoCollector(PhysicalRegisterUsageInfo &PRUI) : PRUI(PRUI) {} | ||
bool run(MachineFunction &MF); | ||
|
||
// Call getCalleeSaves and then also set the bits for subregs and | ||
// fully saved superregs. | ||
static void computeCalleeSavedRegs(BitVector &SavedRegs, MachineFunction &MF); | ||
}; | ||
|
||
class RegUsageInfoCollectorLegacy : public MachineFunctionPass { | ||
public: | ||
static char ID; | ||
RegUsageInfoCollectorLegacy() : MachineFunctionPass(ID) { | ||
initializeRegUsageInfoCollectorLegacyPass(*PassRegistry::getPassRegistry()); | ||
} | ||
|
||
StringRef getPassName() const override { | ||
|
@@ -54,26 +68,19 @@ class RegUsageInfoCollector : public MachineFunctionPass { | |
} | ||
|
||
bool runOnMachineFunction(MachineFunction &MF) override; | ||
|
||
// Call getCalleeSaves and then also set the bits for subregs and | ||
// fully saved superregs. | ||
static void computeCalleeSavedRegs(BitVector &SavedRegs, MachineFunction &MF); | ||
|
||
static char ID; | ||
}; | ||
|
||
} // end of anonymous namespace | ||
|
||
char RegUsageInfoCollector::ID = 0; | ||
char RegUsageInfoCollectorLegacy::ID = 0; | ||
|
||
INITIALIZE_PASS_BEGIN(RegUsageInfoCollector, "RegUsageInfoCollector", | ||
INITIALIZE_PASS_BEGIN(RegUsageInfoCollectorLegacy, "RegUsageInfoCollector", | ||
"Register Usage Information Collector", false, false) | ||
INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfoWrapperLegacy) | ||
INITIALIZE_PASS_END(RegUsageInfoCollector, "RegUsageInfoCollector", | ||
INITIALIZE_PASS_END(RegUsageInfoCollectorLegacy, "RegUsageInfoCollector", | ||
"Register Usage Information Collector", false, false) | ||
|
||
FunctionPass *llvm::createRegUsageInfoCollector() { | ||
return new RegUsageInfoCollector(); | ||
return new RegUsageInfoCollectorLegacy(); | ||
} | ||
|
||
// TODO: Move to hook somwehere? | ||
|
@@ -97,14 +104,32 @@ static bool isCallableFunction(const MachineFunction &MF) { | |
} | ||
} | ||
|
||
bool RegUsageInfoCollector::runOnMachineFunction(MachineFunction &MF) { | ||
PreservedAnalyses | ||
RegUsageInfoCollectorPass::run(MachineFunction &MF, | ||
MachineFunctionAnalysisManager &MFAM) { | ||
Module &MFA = *MF.getFunction().getParent(); | ||
auto *PRUI = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF) | ||
.getCachedResult<PhysicalRegisterUsageAnalysis>(MFA); | ||
assert(PRUI && "PhysicalRegisterUsageAnalysis not available"); | ||
RegUsageInfoCollector(*PRUI).run(MF); | ||
return PreservedAnalyses::all(); | ||
} | ||
|
||
bool RegUsageInfoCollectorLegacy::runOnMachineFunction(MachineFunction &MF) { | ||
PhysicalRegisterUsageInfo &PRUI = | ||
getAnalysis<PhysicalRegisterUsageInfoWrapperLegacy>().getPRUI(); | ||
return RegUsageInfoCollector(PRUI).run(MF); | ||
} | ||
|
||
bool RegUsageInfoCollector::run(MachineFunction &MF) { | ||
MachineRegisterInfo *MRI = &MF.getRegInfo(); | ||
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); | ||
const TargetMachine &TM = MF.getTarget(); | ||
|
||
LLVM_DEBUG(dbgs() << " -------------------- " << getPassName() | ||
<< " -------------------- \nFunction Name : " | ||
<< MF.getName() << '\n'); | ||
LLVM_DEBUG( | ||
dbgs() | ||
<< " -------------------- Register Usage Information Collector Pass" | ||
<< " -------------------- \nFunction Name : " << MF.getName() << '\n'); | ||
Comment on lines
+129
to
+132
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. Unrelated but we shouldn't need this redundant printing of the pass name inside the passes themselves |
||
|
||
// Analyzing the register usage may be expensive on some targets. | ||
if (!isCallableFunction(MF)) { | ||
|
@@ -129,8 +154,6 @@ bool RegUsageInfoCollector::runOnMachineFunction(MachineFunction &MF) { | |
|
||
const Function &F = MF.getFunction(); | ||
|
||
PhysicalRegisterUsageInfo &PRUI = | ||
getAnalysis<PhysicalRegisterUsageInfoWrapperLegacy>().getPRUI(); | ||
PRUI.setTargetMachine(TM); | ||
|
||
LLVM_DEBUG(dbgs() << "Clobbered Registers: "); | ||
|
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
Oops, something went wrong.
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.
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.
Why not just use getResult and not assert?
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.
The machine function's OuterAnalysisProxy can't run the module analysis (as we are inside a module)