Skip to content

Commit da13754

Browse files
authored
AMDGPU/NewPM Port SILoadStoreOptimizer to NPM (#106362)
1 parent 358165d commit da13754

File tree

7 files changed

+86
-22
lines changed

7 files changed

+86
-22
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ FunctionPass *createSIPeepholeSDWAPass();
4040
FunctionPass *createSILowerI1CopiesLegacyPass();
4141
FunctionPass *createAMDGPUGlobalISelDivergenceLoweringPass();
4242
FunctionPass *createSIShrinkInstructionsPass();
43-
FunctionPass *createSILoadStoreOptimizerPass();
43+
FunctionPass *createSILoadStoreOptimizerLegacyPass();
4444
FunctionPass *createSIWholeQuadModePass();
4545
FunctionPass *createSIFixControlFlowLiveIntervalsPass();
4646
FunctionPass *createSIOptimizeExecMaskingPreRAPass();
@@ -190,8 +190,8 @@ extern char &AMDGPUMarkLastScratchLoadID;
190190
void initializeSILowerSGPRSpillsPass(PassRegistry &);
191191
extern char &SILowerSGPRSpillsID;
192192

193-
void initializeSILoadStoreOptimizerPass(PassRegistry &);
194-
extern char &SILoadStoreOptimizerID;
193+
void initializeSILoadStoreOptimizerLegacyPass(PassRegistry &);
194+
extern char &SILoadStoreOptimizerLegacyID;
195195

196196
void initializeSIWholeQuadModePass(PassRegistry &);
197197
extern char &SIWholeQuadModeID;

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
9999
MACHINE_FUNCTION_PASS("si-i1-copies", SILowerI1CopiesPass())
100100
MACHINE_FUNCTION_PASS("si-fold-operands", SIFoldOperandsPass());
101101
MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
102+
MACHINE_FUNCTION_PASS("si-load-store-opt", SILoadStoreOptimizerPass())
102103
#undef MACHINE_FUNCTION_PASS

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "R600TargetMachine.h"
3737
#include "SIFixSGPRCopies.h"
3838
#include "SIFoldOperands.h"
39+
#include "SILoadStoreOptimizer.h"
3940
#include "SIMachineFunctionInfo.h"
4041
#include "SIMachineScheduler.h"
4142
#include "TargetInfo/AMDGPUTargetInfo.h"
@@ -417,7 +418,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
417418
initializeSIShrinkInstructionsPass(*PR);
418419
initializeSIOptimizeExecMaskingPreRAPass(*PR);
419420
initializeSIOptimizeVGPRLiveRangePass(*PR);
420-
initializeSILoadStoreOptimizerPass(*PR);
421+
initializeSILoadStoreOptimizerLegacyPass(*PR);
421422
initializeAMDGPUCtorDtorLoweringLegacyPass(*PR);
422423
initializeAMDGPUAlwaysInlinePass(*PR);
423424
initializeAMDGPUSwLowerLDSLegacyPass(*PR);
@@ -1271,7 +1272,7 @@ void GCNPassConfig::addMachineSSAOptimization() {
12711272
addPass(&SIFoldOperandsLegacyID);
12721273
if (EnableDPPCombine)
12731274
addPass(&GCNDPPCombineLegacyID);
1274-
addPass(&SILoadStoreOptimizerID);
1275+
addPass(&SILoadStoreOptimizerLegacyID);
12751276
if (isPassEnabled(EnableSDWAPeephole)) {
12761277
addPass(&SIPeepholeSDWAID);
12771278
addPass(&EarlyMachineLICMID);

llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
//
5858
//===----------------------------------------------------------------------===//
5959

60+
#include "SILoadStoreOptimizer.h"
6061
#include "AMDGPU.h"
6162
#include "GCNSubtarget.h"
6263
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -104,7 +105,7 @@ struct AddressRegs {
104105
// GFX10 image_sample instructions can have 12 vaddrs + srsrc + ssamp.
105106
const unsigned MaxAddressRegs = 12 + 1 + 1;
106107

107-
class SILoadStoreOptimizer : public MachineFunctionPass {
108+
class SILoadStoreOptimizer {
108109
struct CombineInfo {
109110
MachineBasicBlock::iterator I;
110111
unsigned EltSize;
@@ -295,17 +296,21 @@ class SILoadStoreOptimizer : public MachineFunctionPass {
295296
static InstClassEnum getCommonInstClass(const CombineInfo &CI,
296297
const CombineInfo &Paired);
297298

298-
public:
299-
static char ID;
300-
301-
SILoadStoreOptimizer() : MachineFunctionPass(ID) {
302-
initializeSILoadStoreOptimizerPass(*PassRegistry::getPassRegistry());
303-
}
304-
305299
bool optimizeInstsWithSameBaseAddr(std::list<CombineInfo> &MergeList,
306300
bool &OptimizeListAgain);
307301
bool optimizeBlock(std::list<std::list<CombineInfo> > &MergeableInsts);
308302

303+
public:
304+
SILoadStoreOptimizer(AliasAnalysis *AA) : AA(AA) {}
305+
bool run(MachineFunction &MF);
306+
};
307+
308+
class SILoadStoreOptimizerLegacy : public MachineFunctionPass {
309+
public:
310+
static char ID;
311+
312+
SILoadStoreOptimizerLegacy() : MachineFunctionPass(ID) {}
313+
309314
bool runOnMachineFunction(MachineFunction &MF) override;
310315

311316
StringRef getPassName() const override { return "SI Load Store Optimizer"; }
@@ -882,18 +887,18 @@ void SILoadStoreOptimizer::CombineInfo::setMI(MachineBasicBlock::iterator MI,
882887

883888
} // end anonymous namespace.
884889

885-
INITIALIZE_PASS_BEGIN(SILoadStoreOptimizer, DEBUG_TYPE,
890+
INITIALIZE_PASS_BEGIN(SILoadStoreOptimizerLegacy, DEBUG_TYPE,
886891
"SI Load Store Optimizer", false, false)
887892
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
888-
INITIALIZE_PASS_END(SILoadStoreOptimizer, DEBUG_TYPE, "SI Load Store Optimizer",
889-
false, false)
893+
INITIALIZE_PASS_END(SILoadStoreOptimizerLegacy, DEBUG_TYPE,
894+
"SI Load Store Optimizer", false, false)
890895

891-
char SILoadStoreOptimizer::ID = 0;
896+
char SILoadStoreOptimizerLegacy::ID = 0;
892897

893-
char &llvm::SILoadStoreOptimizerID = SILoadStoreOptimizer::ID;
898+
char &llvm::SILoadStoreOptimizerLegacyID = SILoadStoreOptimizerLegacy::ID;
894899

895-
FunctionPass *llvm::createSILoadStoreOptimizerPass() {
896-
return new SILoadStoreOptimizer();
900+
FunctionPass *llvm::createSILoadStoreOptimizerLegacyPass() {
901+
return new SILoadStoreOptimizerLegacy();
897902
}
898903

899904
static void addDefsUsesToList(const MachineInstr &MI,
@@ -2522,10 +2527,15 @@ SILoadStoreOptimizer::optimizeInstsWithSameBaseAddr(
25222527
return Modified;
25232528
}
25242529

2525-
bool SILoadStoreOptimizer::runOnMachineFunction(MachineFunction &MF) {
2530+
bool SILoadStoreOptimizerLegacy::runOnMachineFunction(MachineFunction &MF) {
25262531
if (skipFunction(MF.getFunction()))
25272532
return false;
2533+
return SILoadStoreOptimizer(
2534+
&getAnalysis<AAResultsWrapperPass>().getAAResults())
2535+
.run(MF);
2536+
}
25282537

2538+
bool SILoadStoreOptimizer::run(MachineFunction &MF) {
25292539
STM = &MF.getSubtarget<GCNSubtarget>();
25302540
if (!STM->loadStoreOptEnabled())
25312541
return false;
@@ -2534,7 +2544,6 @@ bool SILoadStoreOptimizer::runOnMachineFunction(MachineFunction &MF) {
25342544
TRI = &TII->getRegisterInfo();
25352545

25362546
MRI = &MF.getRegInfo();
2537-
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
25382547

25392548
LLVM_DEBUG(dbgs() << "Running SILoadStoreOptimizer\n");
25402549

@@ -2571,3 +2580,24 @@ bool SILoadStoreOptimizer::runOnMachineFunction(MachineFunction &MF) {
25712580

25722581
return Modified;
25732582
}
2583+
2584+
PreservedAnalyses
2585+
SILoadStoreOptimizerPass::run(MachineFunction &MF,
2586+
MachineFunctionAnalysisManager &MFAM) {
2587+
MFPropsModifier _(*this, MF);
2588+
2589+
if (MF.getFunction().hasOptNone())
2590+
return PreservedAnalyses::all();
2591+
2592+
auto &FAM = MFAM.getResult<FunctionAnalysisManagerMachineFunctionProxy>(MF)
2593+
.getManager();
2594+
AAResults &AA = FAM.getResult<AAManager>(MF.getFunction());
2595+
2596+
bool Changed = SILoadStoreOptimizer(&AA).run(MF);
2597+
if (!Changed)
2598+
return PreservedAnalyses::all();
2599+
2600+
PreservedAnalyses PA = getMachineFunctionPassPreservedAnalyses();
2601+
PA.preserveSet<CFGAnalyses>();
2602+
return PA;
2603+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===--- SILoadStoreOptimizer.h -------------------------------------------===//
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_LIB_TARGET_AMDGPU_SILOADSTOREOPTIMIZER_H
10+
#define LLVM_LIB_TARGET_AMDGPU_SILOADSTOREOPTIMIZER_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class SILoadStoreOptimizerPass
17+
: public PassInfoMixin<SILoadStoreOptimizerPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
22+
MachineFunctionProperties getRequiredProperties() {
23+
return MachineFunctionProperties().set(
24+
MachineFunctionProperties::Property::IsSSA);
25+
}
26+
};
27+
28+
} // namespace llvm
29+
30+
#endif // LLVM_LIB_TARGET_AMDGPU_SILOADSTOREOPTIMIZER_H

llvm/test/CodeGen/AMDGPU/load-store-opt-dlc.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 -run-pass=si-load-store-opt -verify-machineinstrs -o - %s | FileCheck %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 -passes=si-load-store-opt -verify-machineinstrs -o - %s | FileCheck %s
23

34
# The purpose of this test is to make sure we are combining relevant memory
45
# operations correctly with/without DLC bit.

llvm/test/CodeGen/AMDGPU/load-store-opt-scc.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a -run-pass=si-load-store-opt -verify-machineinstrs -o - %s | FileCheck %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a -passes=si-load-store-opt -verify-machineinstrs -o - %s | FileCheck %s
23

34
# The purpose of this test is to make sure we are combining relevant memory
45
# operations correctly with/without SCC bit.

0 commit comments

Comments
 (0)