aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorAkshat Oke <Akshat.Oke@amd.com>2024-11-15 10:49:00 +0530
committerGitHub <noreply@github.com>2024-11-15 10:49:00 +0530
commit7b54976d11a5fc6aa1f22e9d96bcb4c81bbf2abf (patch)
tree7048b2127275e580fa68e4ffb57600dabbd301c2 /llvm/lib/CodeGen
parent4e600751d2f7e8e7b85a71b7128b68444bdde91b (diff)
downloadllvm-7b54976d11a5fc6aa1f22e9d96bcb4c81bbf2abf.zip
llvm-7b54976d11a5fc6aa1f22e9d96bcb4c81bbf2abf.tar.gz
llvm-7b54976d11a5fc6aa1f22e9d96bcb4c81bbf2abf.tar.bz2
[CodeGen][NewPM] Port RegisterUsageInfo to NPM (#113873)
And add to the codegen pipeline if ipra is enabled with a `RequireAnalysisPass` since this is a module pass.
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/RegUsageInfoCollector.cpp7
-rw-r--r--llvm/lib/CodeGen/RegUsageInfoPropagate.cpp7
-rw-r--r--llvm/lib/CodeGen/RegisterUsageInfo.cpp29
3 files changed, 35 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
index 44524cc..4e88080 100644
--- a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
+++ b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
@@ -48,7 +48,7 @@ public:
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.addRequired<PhysicalRegisterUsageInfo>();
+ AU.addRequired<PhysicalRegisterUsageInfoWrapperLegacy>();
AU.setPreservesAll();
MachineFunctionPass::getAnalysisUsage(AU);
}
@@ -68,7 +68,7 @@ char RegUsageInfoCollector::ID = 0;
INITIALIZE_PASS_BEGIN(RegUsageInfoCollector, "RegUsageInfoCollector",
"Register Usage Information Collector", false, false)
-INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfo)
+INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfoWrapperLegacy)
INITIALIZE_PASS_END(RegUsageInfoCollector, "RegUsageInfoCollector",
"Register Usage Information Collector", false, false)
@@ -129,7 +129,8 @@ bool RegUsageInfoCollector::runOnMachineFunction(MachineFunction &MF) {
const Function &F = MF.getFunction();
- PhysicalRegisterUsageInfo &PRUI = getAnalysis<PhysicalRegisterUsageInfo>();
+ PhysicalRegisterUsageInfo &PRUI =
+ getAnalysis<PhysicalRegisterUsageInfoWrapperLegacy>().getPRUI();
PRUI.setTargetMachine(TM);
LLVM_DEBUG(dbgs() << "Clobbered Registers: ");
diff --git a/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp b/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp
index d356962..5ffe6ac 100644
--- a/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp
+++ b/llvm/lib/CodeGen/RegUsageInfoPropagate.cpp
@@ -50,7 +50,7 @@ public:
bool runOnMachineFunction(MachineFunction &MF) override;
void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.addRequired<PhysicalRegisterUsageInfo>();
+ AU.addRequired<PhysicalRegisterUsageInfoWrapperLegacy>();
AU.setPreservesAll();
MachineFunctionPass::getAnalysisUsage(AU);
}
@@ -75,7 +75,7 @@ private:
INITIALIZE_PASS_BEGIN(RegUsageInfoPropagation, "reg-usage-propagation",
RUIP_NAME, false, false)
-INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfo)
+INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfoWrapperLegacy)
INITIALIZE_PASS_END(RegUsageInfoPropagation, "reg-usage-propagation",
RUIP_NAME, false, false)
@@ -97,7 +97,8 @@ static const Function *findCalledFunction(const Module &M,
bool RegUsageInfoPropagation::runOnMachineFunction(MachineFunction &MF) {
const Module &M = *MF.getFunction().getParent();
- PhysicalRegisterUsageInfo *PRUI = &getAnalysis<PhysicalRegisterUsageInfo>();
+ PhysicalRegisterUsageInfo *PRUI =
+ &getAnalysis<PhysicalRegisterUsageInfoWrapperLegacy>().getPRUI();
LLVM_DEBUG(dbgs() << " ++++++++++++++++++++ " << getPassName()
<< " ++++++++++++++++++++ \n");
diff --git a/llvm/lib/CodeGen/RegisterUsageInfo.cpp b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
index 1b1be98..6a3e34b 100644
--- a/llvm/lib/CodeGen/RegisterUsageInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
@@ -16,8 +16,10 @@
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/Analysis.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
@@ -32,10 +34,10 @@ static cl::opt<bool> DumpRegUsage(
"print-regusage", cl::init(false), cl::Hidden,
cl::desc("print register usage details collected for analysis."));
-INITIALIZE_PASS(PhysicalRegisterUsageInfo, "reg-usage-info",
+INITIALIZE_PASS(PhysicalRegisterUsageInfoWrapperLegacy, "reg-usage-info",
"Register Usage Information Storage", false, true)
-char PhysicalRegisterUsageInfo::ID = 0;
+char PhysicalRegisterUsageInfoWrapperLegacy::ID = 0;
void PhysicalRegisterUsageInfo::setTargetMachine(const TargetMachine &TM) {
this->TM = &TM;
@@ -97,3 +99,26 @@ void PhysicalRegisterUsageInfo::print(raw_ostream &OS, const Module *M) const {
OS << "\n";
}
}
+
+bool PhysicalRegisterUsageInfo::invalidate(
+ Module &M, const PreservedAnalyses &PA,
+ ModuleAnalysisManager::Invalidator &) {
+ auto PAC = PA.getChecker<PhysicalRegisterUsageAnalysis>();
+ return !PAC.preservedWhenStateless();
+}
+
+AnalysisKey PhysicalRegisterUsageAnalysis::Key;
+PhysicalRegisterUsageInfo
+PhysicalRegisterUsageAnalysis::run(Module &M, ModuleAnalysisManager &) {
+ PhysicalRegisterUsageInfo PRUI;
+ PRUI.doInitialization(M);
+ return PRUI;
+}
+
+PreservedAnalyses
+PhysicalRegisterUsageInfoPrinterPass::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ auto *PRUI = &AM.getResult<PhysicalRegisterUsageAnalysis>(M);
+ PRUI->print(OS, &M);
+ return PreservedAnalyses::all();
+}