mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 19:07:53 +08:00
[CodeGen][NewPM] Port RegUsageInfoPropagation pass to NPM (#114010)
This commit is contained in:
25
llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h
Normal file
25
llvm/include/llvm/CodeGen/RegUsageInfoPropagate.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//===- llvm/CodeGen/RegUsageInfoPropagate.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_REGUSAGEINFOPROPAGATE_H
|
||||
#define LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
|
||||
|
||||
#include "llvm/CodeGen/MachinePassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class RegUsageInfoPropagationPass
|
||||
: public PassInfoMixin<RegUsageInfoPropagationPass> {
|
||||
public:
|
||||
PreservedAnalyses run(MachineFunction &MF,
|
||||
MachineFunctionAnalysisManager &MFAM);
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_REGUSAGEINFOPROPAGATE_H
|
||||
@@ -259,7 +259,7 @@ void initializeRegAllocScoringPass(PassRegistry &);
|
||||
void initializeRegBankSelectPass(PassRegistry &);
|
||||
void initializeRegToMemWrapperPassPass(PassRegistry &);
|
||||
void initializeRegUsageInfoCollectorLegacyPass(PassRegistry &);
|
||||
void initializeRegUsageInfoPropagationPass(PassRegistry &);
|
||||
void initializeRegUsageInfoPropagationLegacyPass(PassRegistry &);
|
||||
void initializeRegionInfoPassPass(PassRegistry &);
|
||||
void initializeRegionOnlyPrinterPass(PassRegistry &);
|
||||
void initializeRegionOnlyViewerPass(PassRegistry &);
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
|
||||
#include "llvm/CodeGen/RegAllocFast.h"
|
||||
#include "llvm/CodeGen/RegUsageInfoCollector.h"
|
||||
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
|
||||
#include "llvm/CodeGen/RegisterUsageInfo.h"
|
||||
#include "llvm/CodeGen/ReplaceWithVeclib.h"
|
||||
#include "llvm/CodeGen/SafeStack.h"
|
||||
|
||||
@@ -158,6 +158,7 @@ MACHINE_FUNCTION_PASS("print<machine-post-dom-tree>",
|
||||
MACHINE_FUNCTION_PASS("print<slot-indexes>", SlotIndexesPrinterPass(dbgs()))
|
||||
MACHINE_FUNCTION_PASS("print<virtregmap>", VirtRegMapPrinterPass(dbgs()))
|
||||
MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
|
||||
MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass())
|
||||
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
|
||||
RequireAllMachineFunctionPropertiesPass())
|
||||
MACHINE_FUNCTION_PASS("stack-coloring", StackColoringPass())
|
||||
@@ -252,7 +253,6 @@ DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", PrologEpilogCodeInserterPass)
|
||||
DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
|
||||
DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass)
|
||||
DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
|
||||
DUMMY_MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass)
|
||||
DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
|
||||
DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
|
||||
DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass)
|
||||
|
||||
@@ -114,7 +114,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
|
||||
initializeRAGreedyPass(Registry);
|
||||
initializeRegAllocFastPass(Registry);
|
||||
initializeRegUsageInfoCollectorLegacyPass(Registry);
|
||||
initializeRegUsageInfoPropagationPass(Registry);
|
||||
initializeRegUsageInfoPropagationLegacyPass(Registry);
|
||||
initializeRegisterCoalescerPass(Registry);
|
||||
initializeRemoveLoadsIntoFakeUsesPass(Registry);
|
||||
initializeRemoveRedundantDebugValuesPass(Registry);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
|
||||
#include "llvm/CodeGen/MachineBasicBlock.h"
|
||||
#include "llvm/CodeGen/MachineFrameInfo.h"
|
||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||
@@ -25,8 +26,10 @@
|
||||
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
||||
#include "llvm/CodeGen/Passes.h"
|
||||
#include "llvm/CodeGen/RegisterUsageInfo.h"
|
||||
#include "llvm/IR/Analysis.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Passes/CodeGenPassBuilder.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
@@ -38,26 +41,16 @@ using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
class RegUsageInfoPropagation : public MachineFunctionPass {
|
||||
class RegUsageInfoPropagation {
|
||||
public:
|
||||
RegUsageInfoPropagation() : MachineFunctionPass(ID) {
|
||||
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
||||
initializeRegUsageInfoPropagationPass(Registry);
|
||||
}
|
||||
explicit RegUsageInfoPropagation(PhysicalRegisterUsageInfo *PRUI)
|
||||
: PRUI(PRUI) {}
|
||||
|
||||
StringRef getPassName() const override { return RUIP_NAME; }
|
||||
|
||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<PhysicalRegisterUsageInfoWrapperLegacy>();
|
||||
AU.setPreservesAll();
|
||||
MachineFunctionPass::getAnalysisUsage(AU);
|
||||
}
|
||||
|
||||
static char ID;
|
||||
bool run(MachineFunction &MF);
|
||||
|
||||
private:
|
||||
PhysicalRegisterUsageInfo *PRUI;
|
||||
|
||||
static void setRegMask(MachineInstr &MI, ArrayRef<uint32_t> RegMask) {
|
||||
assert(RegMask.size() ==
|
||||
MachineOperand::getRegMaskSize(MI.getParent()->getParent()
|
||||
@@ -71,15 +64,34 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
class RegUsageInfoPropagationLegacy : public MachineFunctionPass {
|
||||
public:
|
||||
static char ID;
|
||||
RegUsageInfoPropagationLegacy() : MachineFunctionPass(ID) {
|
||||
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
||||
initializeRegUsageInfoPropagationLegacyPass(Registry);
|
||||
}
|
||||
|
||||
StringRef getPassName() const override { return RUIP_NAME; }
|
||||
|
||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<PhysicalRegisterUsageInfoWrapperLegacy>();
|
||||
AU.setPreservesAll();
|
||||
MachineFunctionPass::getAnalysisUsage(AU);
|
||||
}
|
||||
};
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
INITIALIZE_PASS_BEGIN(RegUsageInfoPropagation, "reg-usage-propagation",
|
||||
INITIALIZE_PASS_BEGIN(RegUsageInfoPropagationLegacy, "reg-usage-propagation",
|
||||
RUIP_NAME, false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfoWrapperLegacy)
|
||||
INITIALIZE_PASS_END(RegUsageInfoPropagation, "reg-usage-propagation",
|
||||
INITIALIZE_PASS_END(RegUsageInfoPropagationLegacy, "reg-usage-propagation",
|
||||
RUIP_NAME, false, false)
|
||||
|
||||
char RegUsageInfoPropagation::ID = 0;
|
||||
char RegUsageInfoPropagationLegacy::ID = 0;
|
||||
|
||||
// Assumes call instructions have a single reference to a function.
|
||||
static const Function *findCalledFunction(const Module &M,
|
||||
@@ -95,12 +107,29 @@ static const Function *findCalledFunction(const Module &M,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool RegUsageInfoPropagation::runOnMachineFunction(MachineFunction &MF) {
|
||||
const Module &M = *MF.getFunction().getParent();
|
||||
bool RegUsageInfoPropagationLegacy::runOnMachineFunction(MachineFunction &MF) {
|
||||
PhysicalRegisterUsageInfo *PRUI =
|
||||
&getAnalysis<PhysicalRegisterUsageInfoWrapperLegacy>().getPRUI();
|
||||
|
||||
LLVM_DEBUG(dbgs() << " ++++++++++++++++++++ " << getPassName()
|
||||
RegUsageInfoPropagation RUIP(PRUI);
|
||||
return RUIP.run(MF);
|
||||
}
|
||||
|
||||
PreservedAnalyses
|
||||
RegUsageInfoPropagationPass::run(MachineFunction &MF,
|
||||
MachineFunctionAnalysisManager &MFAM) {
|
||||
Module &MFA = *MF.getFunction().getParent();
|
||||
auto *PRUI = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)
|
||||
.getCachedResult<PhysicalRegisterUsageAnalysis>(MFA);
|
||||
assert(PRUI && "PhysicalRegisterUsageAnalysis not available");
|
||||
RegUsageInfoPropagation(PRUI).run(MF);
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
bool RegUsageInfoPropagation::run(MachineFunction &MF) {
|
||||
const Module &M = *MF.getFunction().getParent();
|
||||
|
||||
LLVM_DEBUG(dbgs() << " ++++++++++++++++++++ " << RUIP_NAME
|
||||
<< " ++++++++++++++++++++ \n");
|
||||
LLVM_DEBUG(dbgs() << "MachineFunction : " << MF.getName() << "\n");
|
||||
|
||||
@@ -151,5 +180,5 @@ bool RegUsageInfoPropagation::runOnMachineFunction(MachineFunction &MF) {
|
||||
}
|
||||
|
||||
FunctionPass *llvm::createRegUsageInfoPropPass() {
|
||||
return new RegUsageInfoPropagation();
|
||||
return new RegUsageInfoPropagationLegacy();
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
|
||||
#include "llvm/CodeGen/RegAllocFast.h"
|
||||
#include "llvm/CodeGen/RegUsageInfoCollector.h"
|
||||
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
|
||||
#include "llvm/CodeGen/RegisterUsageInfo.h"
|
||||
#include "llvm/CodeGen/SafeStack.h"
|
||||
#include "llvm/CodeGen/SelectOptimize.h"
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
; RUN: llc -enable-ipra -print-regusage -o /dev/null 2>&1 < %s | FileCheck %s
|
||||
|
||||
; RUN: llc -stop-after=prologepilog -o - %s \
|
||||
; RUN: | llc -x=mir -enable-ipra -passes="require<reg-usage>,function(machine-function(reg-usage-propagation,reg-usage-collector)),print<reg-usage>" -o /dev/null 2>&1 \
|
||||
; RUN: | FileCheck %s
|
||||
|
||||
target triple = "aarch64-unknown-unknown"
|
||||
declare void @bar1()
|
||||
define preserve_mostcc void @baz() #0 {
|
||||
|
||||
Reference in New Issue
Block a user