Skip to content

Commit 7ef9eb5

Browse files
committed
[AMDGPU][NewPM] Port SIOptimizeExecMaskingPreRA to NPM
1 parent c31b0c4 commit 7ef9eb5

7 files changed

+62
-13
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ struct AMDGPUUnifyMetadataPass : PassInfoMixin<AMDGPUUnifyMetadataPass> {
368368
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
369369
};
370370

371-
void initializeSIOptimizeExecMaskingPreRAPass(PassRegistry&);
371+
void initializeSIOptimizeExecMaskingPreRALegacyPass(PassRegistry &);
372372
extern char &SIOptimizeExecMaskingPreRAID;
373373

374374
void initializeSIOptimizeVGPRLiveRangeLegacyPass(PassRegistry &);

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ MACHINE_FUNCTION_PASS("si-lower-sgpr-spills", SILowerSGPRSpillsPass())
108108
MACHINE_FUNCTION_PASS("si-lower-wwm-copies", SILowerWWMCopiesPass())
109109
MACHINE_FUNCTION_PASS("si-opt-vgpr-liverange", SIOptimizeVGPRLiveRangePass())
110110
MACHINE_FUNCTION_PASS("si-optimize-exec-masking", SIOptimizeExecMaskingPass())
111+
MACHINE_FUNCTION_PASS("si-optimize-exec-masking-pre-ra", SIOptimizeExecMaskingPreRAPass())
111112
MACHINE_FUNCTION_PASS("si-peephole-sdwa", SIPeepholeSDWAPass())
112113
MACHINE_FUNCTION_PASS("si-pre-allocate-wwm-regs", SIPreAllocateWWMRegsPass())
113114
MACHINE_FUNCTION_PASS("si-shrink-instructions", SIShrinkInstructionsPass())
@@ -127,7 +128,6 @@ DUMMY_MACHINE_FUNCTION_PASS("si-insert-waitcnts", SIInsertWaitcntsPass())
127128
DUMMY_MACHINE_FUNCTION_PASS("si-late-branch-lowering", SILateBranchLoweringPass())
128129
DUMMY_MACHINE_FUNCTION_PASS("si-memory-legalizer", SIMemoryLegalizerPass())
129130
DUMMY_MACHINE_FUNCTION_PASS("si-mode-register", SIModeRegisterPass())
130-
DUMMY_MACHINE_FUNCTION_PASS("si-optimize-exec-masking-pre-ra", SIOptimizeExecMaskingPreRAPass())
131131
DUMMY_MACHINE_FUNCTION_PASS("si-pre-emit-peephole", SIPreEmitPeepholePass())
132132
// TODO: Move amdgpu-preload-kern-arg-prolog to MACHINE_FUNCTION_PASS since it
133133
// already exists.

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "SIMachineFunctionInfo.h"
4747
#include "SIMachineScheduler.h"
4848
#include "SIOptimizeExecMasking.h"
49+
#include "SIOptimizeExecMaskingPreRA.h"
4950
#include "SIOptimizeVGPRLiveRange.h"
5051
#include "SIPeepholeSDWA.h"
5152
#include "SIPreAllocateWWMRegs.h"
@@ -495,7 +496,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
495496
initializeSIFoldOperandsLegacyPass(*PR);
496497
initializeSIPeepholeSDWALegacyPass(*PR);
497498
initializeSIShrinkInstructionsLegacyPass(*PR);
498-
initializeSIOptimizeExecMaskingPreRAPass(*PR);
499+
initializeSIOptimizeExecMaskingPreRALegacyPass(*PR);
499500
initializeSIOptimizeVGPRLiveRangeLegacyPass(*PR);
500501
initializeSILoadStoreOptimizerLegacyPass(*PR);
501502
initializeAMDGPUCtorDtorLoweringLegacyPass(*PR);

llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
///
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "SIOptimizeExecMaskingPreRA.h"
1516
#include "AMDGPU.h"
1617
#include "GCNSubtarget.h"
1718
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -25,7 +26,7 @@ using namespace llvm;
2526

2627
namespace {
2728

28-
class SIOptimizeExecMaskingPreRA : public MachineFunctionPass {
29+
class SIOptimizeExecMaskingPreRA {
2930
private:
3031
const SIRegisterInfo *TRI;
3132
const SIInstrInfo *TII;
@@ -42,11 +43,18 @@ class SIOptimizeExecMaskingPreRA : public MachineFunctionPass {
4243
bool optimizeVcndVcmpPair(MachineBasicBlock &MBB);
4344
bool optimizeElseBranch(MachineBasicBlock &MBB);
4445

46+
public:
47+
SIOptimizeExecMaskingPreRA(LiveIntervals *LIS) : LIS(LIS) {}
48+
bool run(MachineFunction &MF);
49+
};
50+
51+
class SIOptimizeExecMaskingPreRALegacy : public MachineFunctionPass {
4552
public:
4653
static char ID;
4754

48-
SIOptimizeExecMaskingPreRA() : MachineFunctionPass(ID) {
49-
initializeSIOptimizeExecMaskingPreRAPass(*PassRegistry::getPassRegistry());
55+
SIOptimizeExecMaskingPreRALegacy() : MachineFunctionPass(ID) {
56+
initializeSIOptimizeExecMaskingPreRALegacyPass(
57+
*PassRegistry::getPassRegistry());
5058
}
5159

5260
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -64,18 +72,18 @@ class SIOptimizeExecMaskingPreRA : public MachineFunctionPass {
6472

6573
} // End anonymous namespace.
6674

67-
INITIALIZE_PASS_BEGIN(SIOptimizeExecMaskingPreRA, DEBUG_TYPE,
75+
INITIALIZE_PASS_BEGIN(SIOptimizeExecMaskingPreRALegacy, DEBUG_TYPE,
6876
"SI optimize exec mask operations pre-RA", false, false)
6977
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
70-
INITIALIZE_PASS_END(SIOptimizeExecMaskingPreRA, DEBUG_TYPE,
78+
INITIALIZE_PASS_END(SIOptimizeExecMaskingPreRALegacy, DEBUG_TYPE,
7179
"SI optimize exec mask operations pre-RA", false, false)
7280

73-
char SIOptimizeExecMaskingPreRA::ID = 0;
81+
char SIOptimizeExecMaskingPreRALegacy::ID = 0;
7482

75-
char &llvm::SIOptimizeExecMaskingPreRAID = SIOptimizeExecMaskingPreRA::ID;
83+
char &llvm::SIOptimizeExecMaskingPreRAID = SIOptimizeExecMaskingPreRALegacy::ID;
7684

7785
FunctionPass *llvm::createSIOptimizeExecMaskingPreRAPass() {
78-
return new SIOptimizeExecMaskingPreRA();
86+
return new SIOptimizeExecMaskingPreRALegacy();
7987
}
8088

8189
// See if there is a def between \p AndIdx and \p SelIdx that needs to live
@@ -340,15 +348,29 @@ bool SIOptimizeExecMaskingPreRA::optimizeElseBranch(MachineBasicBlock &MBB) {
340348
return true;
341349
}
342350

343-
bool SIOptimizeExecMaskingPreRA::runOnMachineFunction(MachineFunction &MF) {
351+
PreservedAnalyses
352+
SIOptimizeExecMaskingPreRAPass::run(MachineFunction &MF,
353+
MachineFunctionAnalysisManager &MFAM) {
354+
auto &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
355+
SIOptimizeExecMaskingPreRA(&LIS).run(MF);
356+
return PreservedAnalyses::all();
357+
}
358+
359+
bool SIOptimizeExecMaskingPreRALegacy::runOnMachineFunction(
360+
MachineFunction &MF) {
344361
if (skipFunction(MF.getFunction()))
345362
return false;
346363

364+
auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
365+
return SIOptimizeExecMaskingPreRA(LIS).run(MF);
366+
}
367+
368+
bool SIOptimizeExecMaskingPreRA::run(MachineFunction &MF) {
347369
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
348370
TRI = ST.getRegisterInfo();
349371
TII = ST.getInstrInfo();
350372
MRI = &MF.getRegInfo();
351-
LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
373+
// LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
352374

353375
const bool Wave32 = ST.isWave32();
354376
AndOpc = Wave32 ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===- SIOptimizeExecMaskingPreRA.h.h ---------------------------------------*-
2+
//C++- *-===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_LIB_TARGET_AMDGPU_SIOPTIMIZEEXECMASKINGPRERA_H
11+
#define LLVM_LIB_TARGET_AMDGPU_SIOPTIMIZEEXECMASKINGPRERA_H
12+
13+
#include "llvm/CodeGen/MachinePassManager.h"
14+
15+
namespace llvm {
16+
class SIOptimizeExecMaskingPreRAPass
17+
: public PassInfoMixin<SIOptimizeExecMaskingPreRAPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
};
22+
} // namespace llvm
23+
24+
#endif // LLVM_LIB_TARGET_AMDGPU_SIOPTIMIZEEXECMASKINGPRERA_H

llvm/test/CodeGen/AMDGPU/collapse-endcf-broken.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=amdgcn -verify-machineinstrs -run-pass=si-optimize-exec-masking-pre-ra %s -o - | FileCheck -check-prefix=GXN %s
3+
# RUN: llc -mtriple=amdgcn -verify-machineinstrs -passes=si-optimize-exec-masking-pre-ra %s -o - | FileCheck -check-prefix=GXN %s
34

45
# FIXME: This is a miscompile, and the s_or_b64s need to be preserved.
56

llvm/test/CodeGen/AMDGPU/optimize-exec-mask-pre-ra-non-empty-but-used-interval.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=gfx1100 -run-pass=si-optimize-exec-masking-pre-ra,greedy -verify-machineinstrs -o - %s
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -passes=si-optimize-exec-masking-pre-ra,greedy -verify-machineinstrs -o - %s
23

34
# This sample can trigger a "Non-empty but used interval" assert in regalloc if
45
# SIOptimizeExecMaskingPreRA does not update live intervals correctly.

0 commit comments

Comments
 (0)