Skip to content

Commit 73b0e8a

Browse files
authored
[AMDGPU][NewPM] Port AMDGPUOpenCLEnqueuedBlockLowering to NPM (#122434)
1 parent a1a3e01 commit 73b0e8a

File tree

6 files changed

+60
-15
lines changed

6 files changed

+60
-15
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ void initializeAMDGPUExternalAAWrapperPass(PassRegistry&);
444444

445445
void initializeAMDGPUArgumentUsageInfoPass(PassRegistry &);
446446

447-
ModulePass *createAMDGPUOpenCLEnqueuedBlockLoweringPass();
448-
void initializeAMDGPUOpenCLEnqueuedBlockLoweringPass(PassRegistry &);
449-
extern char &AMDGPUOpenCLEnqueuedBlockLoweringID;
447+
ModulePass *createAMDGPUOpenCLEnqueuedBlockLoweringLegacyPass();
448+
void initializeAMDGPUOpenCLEnqueuedBlockLoweringLegacyPass(PassRegistry &);
449+
extern char &AMDGPUOpenCLEnqueuedBlockLoweringLegacyID;
450450

451451
void initializeGCNNSAReassignPass(PassRegistry &);
452452
extern char &GCNNSAReassignID;

llvm/lib/Target/AMDGPU/AMDGPUOpenCLEnqueuedBlockLowering.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//
3232
//===----------------------------------------------------------------------===//
3333

34+
#include "AMDGPUOpenCLEnqueuedBlockLowering.h"
3435
#include "AMDGPU.h"
3536
#include "llvm/ADT/DenseSet.h"
3637
#include "llvm/ADT/SmallString.h"
@@ -48,31 +49,49 @@ using namespace llvm;
4849
namespace {
4950

5051
/// Lower enqueued blocks.
51-
class AMDGPUOpenCLEnqueuedBlockLowering : public ModulePass {
52+
class AMDGPUOpenCLEnqueuedBlockLowering {
53+
public:
54+
bool run(Module &M);
55+
};
56+
57+
class AMDGPUOpenCLEnqueuedBlockLoweringLegacy : public ModulePass {
5258
public:
5359
static char ID;
5460

55-
explicit AMDGPUOpenCLEnqueuedBlockLowering() : ModulePass(ID) {}
61+
explicit AMDGPUOpenCLEnqueuedBlockLoweringLegacy() : ModulePass(ID) {}
5662

5763
private:
5864
bool runOnModule(Module &M) override;
5965
};
6066

6167
} // end anonymous namespace
6268

63-
char AMDGPUOpenCLEnqueuedBlockLowering::ID = 0;
69+
char AMDGPUOpenCLEnqueuedBlockLoweringLegacy::ID = 0;
6470

65-
char &llvm::AMDGPUOpenCLEnqueuedBlockLoweringID =
66-
AMDGPUOpenCLEnqueuedBlockLowering::ID;
71+
char &llvm::AMDGPUOpenCLEnqueuedBlockLoweringLegacyID =
72+
AMDGPUOpenCLEnqueuedBlockLoweringLegacy::ID;
6773

68-
INITIALIZE_PASS(AMDGPUOpenCLEnqueuedBlockLowering, DEBUG_TYPE,
74+
INITIALIZE_PASS(AMDGPUOpenCLEnqueuedBlockLoweringLegacy, DEBUG_TYPE,
6975
"Lower OpenCL enqueued blocks", false, false)
7076

71-
ModulePass* llvm::createAMDGPUOpenCLEnqueuedBlockLoweringPass() {
72-
return new AMDGPUOpenCLEnqueuedBlockLowering();
77+
ModulePass *llvm::createAMDGPUOpenCLEnqueuedBlockLoweringLegacyPass() {
78+
return new AMDGPUOpenCLEnqueuedBlockLoweringLegacy();
79+
}
80+
81+
bool AMDGPUOpenCLEnqueuedBlockLoweringLegacy::runOnModule(Module &M) {
82+
AMDGPUOpenCLEnqueuedBlockLowering Impl;
83+
return Impl.run(M);
84+
}
85+
86+
PreservedAnalyses
87+
AMDGPUOpenCLEnqueuedBlockLoweringPass::run(Module &M, ModuleAnalysisManager &) {
88+
AMDGPUOpenCLEnqueuedBlockLowering Impl;
89+
if (Impl.run(M))
90+
return PreservedAnalyses::none();
91+
return PreservedAnalyses::all();
7392
}
7493

75-
bool AMDGPUOpenCLEnqueuedBlockLowering::runOnModule(Module &M) {
94+
bool AMDGPUOpenCLEnqueuedBlockLowering::run(Module &M) {
7695
DenseSet<Function *> Callers;
7796
auto &C = M.getContext();
7897
bool Changed = false;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===- AMDGPUOpenCLEnqueuedBlockLowering.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_LIB_TARGET_AMDGPU_OPENCLENQUEUEDBLOCKLOWERING_H
10+
#define LLVM_LIB_TARGET_AMDGPU_OPENCLENQUEUEDBLOCKLOWERING_H
11+
12+
#include "llvm/IR/PassManager.h"
13+
14+
namespace llvm {
15+
class AMDGPUOpenCLEnqueuedBlockLoweringPass
16+
: public PassInfoMixin<AMDGPUOpenCLEnqueuedBlockLoweringPass> {
17+
public:
18+
AMDGPUOpenCLEnqueuedBlockLoweringPass() = default;
19+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
20+
};
21+
} // namespace llvm
22+
23+
#endif // LLVM_LIB_TARGET_AMDGPU_OPENCLENQUEUEDBLOCKLOWERING_H

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ MODULE_PASS("amdgpu-lower-buffer-fat-pointers",
2121
AMDGPULowerBufferFatPointersPass(*this))
2222
MODULE_PASS("amdgpu-lower-ctor-dtor", AMDGPUCtorDtorLoweringPass())
2323
MODULE_PASS("amdgpu-sw-lower-lds", AMDGPUSwLowerLDSPass(*this))
24+
MODULE_PASS("amdgpu-lower-enqueued-block", AMDGPUOpenCLEnqueuedBlockLoweringPass())
2425
MODULE_PASS("amdgpu-lower-module-lds", AMDGPULowerModuleLDSPass(*this))
2526
MODULE_PASS("amdgpu-perf-hint",
2627
AMDGPUPerfHintAnalysisPass(

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "AMDGPUIGroupLP.h"
2323
#include "AMDGPUISelDAGToDAG.h"
2424
#include "AMDGPUMacroFusion.h"
25+
#include "AMDGPUOpenCLEnqueuedBlockLowering.h"
2526
#include "AMDGPUPerfHintAnalysis.h"
2627
#include "AMDGPURemoveIncompatibleFunctions.h"
2728
#include "AMDGPUSplitModule.h"
@@ -501,7 +502,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
501502
initializeAMDGPULowerKernelArgumentsPass(*PR);
502503
initializeAMDGPUPromoteKernelArgumentsPass(*PR);
503504
initializeAMDGPULowerKernelAttributesPass(*PR);
504-
initializeAMDGPUOpenCLEnqueuedBlockLoweringPass(*PR);
505+
initializeAMDGPUOpenCLEnqueuedBlockLoweringLegacyPass(*PR);
505506
initializeAMDGPUPostLegalizerCombinerPass(*PR);
506507
initializeAMDGPUPreLegalizerCombinerPass(*PR);
507508
initializeAMDGPURegBankCombinerPass(*PR);
@@ -1175,7 +1176,7 @@ void AMDGPUPassConfig::addIRPasses() {
11751176
addPass(createR600OpenCLImageTypeLoweringPass());
11761177

11771178
// Replace OpenCL enqueued block function pointers with global variables.
1178-
addPass(createAMDGPUOpenCLEnqueuedBlockLoweringPass());
1179+
addPass(createAMDGPUOpenCLEnqueuedBlockLoweringLegacyPass());
11791180

11801181
// Lower LDS accesses to global memory pass if address sanitizer is enabled.
11811182
if (EnableSwLowerLDS)
@@ -1944,7 +1945,7 @@ void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
19441945
addPass(AMDGPUAlwaysInlinePass());
19451946
addPass(AlwaysInlinerPass());
19461947

1947-
// TODO: Missing OpenCLEnqueuedBlockLowering
1948+
addPass(AMDGPUOpenCLEnqueuedBlockLoweringPass());
19481949

19491950
// Runs before PromoteAlloca so the latter can account for function uses
19501951
if (EnableLowerModuleLDS)

llvm/test/CodeGen/AMDGPU/enqueue-kernel.ll

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_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals --include-generated-funcs
22
; RUN: opt -data-layout=A5 -amdgpu-lower-enqueued-block -S < %s | FileCheck %s
3+
; RUN: opt -data-layout=A5 -mtriple=amdgcn -passes=amdgpu-lower-enqueued-block -S < %s | FileCheck %s
34

45
%struct.ndrange_t = type { i32 }
56
%opencl.queue_t = type opaque

0 commit comments

Comments
 (0)