Skip to content

Commit f06e7f4

Browse files
committed
[CodeGen][NPM] Port RemoveLoadsIntoFakeUses to NPM
1 parent b4d0fba commit f06e7f4

File tree

8 files changed

+73
-12
lines changed

8 files changed

+73
-12
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- llvm/CodeGen/RemoveLoadsIntoFakeUses.h -------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CODEGEN_REMOVELOADSINTOFAKEUSES_H
10+
#define LLVM_CODEGEN_REMOVELOADSINTOFAKEUSES_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class RemoveLoadsIntoFakeUsesPass
17+
: public PassInfoMixin<RemoveLoadsIntoFakeUsesPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
22+
MachineFunctionProperties getRequiredProperties() const {
23+
return MachineFunctionProperties().set(
24+
MachineFunctionProperties::Property::NoVRegs);
25+
}
26+
};
27+
28+
} // namespace llvm
29+
30+
#endif // LLVM_CODEGEN_REMOVELOADSINTOFAKEUSES_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void initializeRegionOnlyViewerPass(PassRegistry &);
265265
void initializeRegionPrinterPass(PassRegistry &);
266266
void initializeRegionViewerPass(PassRegistry &);
267267
void initializeRegisterCoalescerLegacyPass(PassRegistry &);
268-
void initializeRemoveLoadsIntoFakeUsesPass(PassRegistry &);
268+
void initializeRemoveLoadsIntoFakeUsesLegacyPass(PassRegistry &);
269269
void initializeRemoveRedundantDebugValuesLegacyPass(PassRegistry &);
270270
void initializeRenameIndependentSubregsLegacyPass(PassRegistry &);
271271
void initializeReplaceWithVeclibLegacyPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
7171
#include "llvm/CodeGen/RegisterCoalescerPass.h"
7272
#include "llvm/CodeGen/RegisterUsageInfo.h"
73+
#include "llvm/CodeGen/RemoveLoadsIntoFakeUses.h"
7374
#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
7475
#include "llvm/CodeGen/RenameIndependentSubregs.h"
7576
#include "llvm/CodeGen/ReplaceWithVeclib.h"
@@ -998,6 +999,7 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::addMachinePasses(
998999

9991000
addPass(FuncletLayoutPass());
10001001

1002+
addPass(RemoveLoadsIntoFakeUsesPass());
10011003
addPass(StackMapLivenessPass());
10021004
addPass(LiveDebugValuesPass());
10031005
addPass(MachineSanitizerBinaryMetadata());

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ MACHINE_FUNCTION_PASS("reg-usage-collector", RegUsageInfoCollectorPass())
181181
MACHINE_FUNCTION_PASS("reg-usage-propagation", RegUsageInfoPropagationPass())
182182
MACHINE_FUNCTION_PASS("register-coalescer", RegisterCoalescerPass())
183183
MACHINE_FUNCTION_PASS("rename-independent-subregs", RenameIndependentSubregsPass())
184+
MACHINE_FUNCTION_PASS("remove-loads-into-fake-uses", RemoveLoadsIntoFakeUsesPass())
184185
MACHINE_FUNCTION_PASS("remove-redundant-debug-values", RemoveRedundantDebugValuesPass())
185186
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
186187
RequireAllMachineFunctionPropertiesPass())
@@ -292,7 +293,6 @@ DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
292293
DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
293294
DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)
294295
DUMMY_MACHINE_FUNCTION_PASS("regbankselect", RegBankSelectPass)
295-
DUMMY_MACHINE_FUNCTION_PASS("remove-loads-into-fake-uses", RemoveLoadsIntoFakeUsesPass)
296296
DUMMY_MACHINE_FUNCTION_PASS("reset-machine-function", ResetMachineFunctionPass)
297297
DUMMY_MACHINE_FUNCTION_PASS("shrink-wrap", ShrinkWrapPass)
298298
DUMMY_MACHINE_FUNCTION_PASS("stack-frame-layout", StackFrameLayoutAnalysisPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
117117
initializeRegUsageInfoCollectorLegacyPass(Registry);
118118
initializeRegUsageInfoPropagationLegacyPass(Registry);
119119
initializeRegisterCoalescerLegacyPass(Registry);
120-
initializeRemoveLoadsIntoFakeUsesPass(Registry);
120+
initializeRemoveLoadsIntoFakeUsesLegacyPass(Registry);
121121
initializeRemoveRedundantDebugValuesLegacyPass(Registry);
122122
initializeRenameIndependentSubregsLegacyPass(Registry);
123123
initializeSafeStackLegacyPassPass(Registry);

llvm/lib/CodeGen/RemoveLoadsIntoFakeUses.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
///
2323
//===----------------------------------------------------------------------===//
2424

25+
#include "llvm/CodeGen/RemoveLoadsIntoFakeUses.h"
2526
#include "llvm/ADT/PostOrderIterator.h"
2627
#include "llvm/ADT/Statistic.h"
2728
#include "llvm/CodeGen/LiveRegUnits.h"
2829
#include "llvm/CodeGen/MachineFunction.h"
2930
#include "llvm/CodeGen/MachineFunctionPass.h"
31+
#include "llvm/CodeGen/MachinePassManager.h"
3032
#include "llvm/CodeGen/MachineRegisterInfo.h"
3133
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3234
#include "llvm/IR/Function.h"
@@ -41,12 +43,13 @@ using namespace llvm;
4143
STATISTIC(NumLoadsDeleted, "Number of dead load instructions deleted");
4244
STATISTIC(NumFakeUsesDeleted, "Number of FAKE_USE instructions deleted");
4345

44-
class RemoveLoadsIntoFakeUses : public MachineFunctionPass {
46+
class RemoveLoadsIntoFakeUsesLegacy : public MachineFunctionPass {
4547
public:
4648
static char ID;
4749

48-
RemoveLoadsIntoFakeUses() : MachineFunctionPass(ID) {
49-
initializeRemoveLoadsIntoFakeUsesPass(*PassRegistry::getPassRegistry());
50+
RemoveLoadsIntoFakeUsesLegacy() : MachineFunctionPass(ID) {
51+
initializeRemoveLoadsIntoFakeUsesLegacyPass(
52+
*PassRegistry::getPassRegistry());
5053
}
5154

5255
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -66,21 +69,44 @@ class RemoveLoadsIntoFakeUses : public MachineFunctionPass {
6669
bool runOnMachineFunction(MachineFunction &MF) override;
6770
};
6871

69-
char RemoveLoadsIntoFakeUses::ID = 0;
70-
char &llvm::RemoveLoadsIntoFakeUsesID = RemoveLoadsIntoFakeUses::ID;
72+
struct RemoveLoadsIntoFakeUses {
73+
bool run(MachineFunction &MF);
74+
};
75+
76+
char RemoveLoadsIntoFakeUsesLegacy::ID = 0;
77+
char &llvm::RemoveLoadsIntoFakeUsesID = RemoveLoadsIntoFakeUsesLegacy::ID;
7178

72-
INITIALIZE_PASS_BEGIN(RemoveLoadsIntoFakeUses, DEBUG_TYPE,
79+
INITIALIZE_PASS_BEGIN(RemoveLoadsIntoFakeUsesLegacy, DEBUG_TYPE,
7380
"Remove Loads Into Fake Uses", false, false)
74-
INITIALIZE_PASS_END(RemoveLoadsIntoFakeUses, DEBUG_TYPE,
81+
INITIALIZE_PASS_END(RemoveLoadsIntoFakeUsesLegacy, DEBUG_TYPE,
7582
"Remove Loads Into Fake Uses", false, false)
7683

77-
bool RemoveLoadsIntoFakeUses::runOnMachineFunction(MachineFunction &MF) {
84+
bool RemoveLoadsIntoFakeUsesLegacy::runOnMachineFunction(MachineFunction &MF) {
85+
if (skipFunction(MF.getFunction()))
86+
return false;
87+
return RemoveLoadsIntoFakeUses().run(MF);
88+
}
89+
90+
PreservedAnalyses
91+
RemoveLoadsIntoFakeUsesPass::run(MachineFunction &MF,
92+
MachineFunctionAnalysisManager &MFAM) {
93+
MFPropsModifier _(*this, MF);
94+
95+
if (!RemoveLoadsIntoFakeUses().run(MF))
96+
return PreservedAnalyses::all();
97+
98+
auto PA = getMachineFunctionPassPreservedAnalyses();
99+
PA.preserveSet<CFGAnalyses>();
100+
return PA;
101+
}
102+
103+
bool RemoveLoadsIntoFakeUses::run(MachineFunction &MF) {
78104
// Skip this pass if we would use VarLoc-based LDV, as there may be DBG_VALUE
79105
// instructions of the restored values that would become invalid.
80106
if (!MF.useDebugInstrRef())
81107
return false;
82108
// Only run this for functions that have fake uses.
83-
if (!MF.hasFakeUses() || skipFunction(MF.getFunction()))
109+
if (!MF.hasFakeUses())
84110
return false;
85111

86112
bool AnyChanges = false;

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
145145
#include "llvm/CodeGen/RegisterCoalescerPass.h"
146146
#include "llvm/CodeGen/RegisterUsageInfo.h"
147+
#include "llvm/CodeGen/RemoveLoadsIntoFakeUses.h"
147148
#include "llvm/CodeGen/RemoveRedundantDebugValues.h"
148149
#include "llvm/CodeGen/RenameIndependentSubregs.h"
149150
#include "llvm/CodeGen/SafeStack.h"

llvm/test/CodeGen/X86/fake-use-remove-loads.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# remove-loads-into-fake-uses pass, and that if the function does not use
44
# instruction referencing then no changes are made.
55
# RUN: llc %s -run-pass remove-loads-into-fake-uses -mtriple=x86_64-unknown-linux -debug-only=remove-loads-into-fake-uses 2>&1 -o - | FileCheck %s
6+
# RUN: llc %s -passes remove-loads-into-fake-uses -mtriple=x86_64-unknown-linux -debug-only=remove-loads-into-fake-uses 2>&1 -o - | FileCheck %s
7+
68
# REQUIRES: asserts
79
#
810
## We verify that:

0 commit comments

Comments
 (0)