Skip to content

Commit aaa5e52

Browse files
adding new pass registry to spirv
1 parent 1cfd9fd commit aaa5e52

File tree

6 files changed

+69
-1
lines changed

6 files changed

+69
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===- SPIRVPassRegistry.def - Registry of SPIRV passes -----*- 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+
// This file is used as the registry of passes that are part of the
10+
// SPIRV backend.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
// NOTE: NO INCLUDE GUARD DESIRED!
15+
16+
17+
#ifndef FUNCTION_PASS
18+
#define FUNCTION_PASS(NAME, CREATE_PASS)
19+
#endif
20+
FUNCTION_PASS("spirv-structurizer", SPIRVStructurizerWrapper())
21+
#undef FUNCTION_PASS

llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
#include "Analysis/SPIRVConvergenceRegionAnalysis.h"
1212
#include "SPIRV.h"
13+
#include "SPIRVStructurizerWrapper.h"
1314
#include "SPIRVSubtarget.h"
1415
#include "SPIRVTargetMachine.h"
1516
#include "SPIRVUtils.h"
1617
#include "llvm/ADT/DenseMap.h"
1718
#include "llvm/ADT/SmallPtrSet.h"
1819
#include "llvm/Analysis/LoopInfo.h"
1920
#include "llvm/CodeGen/IntrinsicLowering.h"
21+
#include "llvm/IR/Analysis.h"
2022
#include "llvm/IR/CFG.h"
2123
#include "llvm/IR/Dominators.h"
2224
#include "llvm/IR/IRBuilder.h"
@@ -1224,3 +1226,12 @@ INITIALIZE_PASS_END(SPIRVStructurizer, "spirv-structurizer",
12241226
FunctionPass *llvm::createSPIRVStructurizerPass() {
12251227
return new SPIRVStructurizer();
12261228
}
1229+
1230+
PreservedAnalyses SPIRVStructurizerWrapper::run(Function &F, FunctionAnalysisManager &AF){
1231+
FunctionPass *StructurizerPass = createSPIRVStructurizerPass();
1232+
if (!StructurizerPass->runOnFunction(F))
1233+
return PreservedAnalyses::all();
1234+
PreservedAnalyses PA;
1235+
PA.preserveSet<CFGAnalyses>();
1236+
return PA;
1237+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===- SPIRVStructurizerWrapper.h - New pass manager wrapper from SPIRV Structurizer -----------*- 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+
// \file New pass manager wrapper from SPIRV Structurizer.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_DIRECTX_SPIRVSTRUCTURIZER_H
14+
#define LLVM_LIB_TARGET_DIRECTX_SPIRVSTRUCTURIZER_H
15+
16+
#include "llvm/IR/PassManager.h"
17+
18+
namespace llvm {
19+
20+
class SPIRVStructurizerWrapper : public PassInfoMixin<SPIRVStructurizerWrapper> {
21+
public:
22+
PreservedAnalyses run(Function &M, FunctionAnalysisManager &AM);
23+
};
24+
25+
} // namespace llvm
26+
27+
#endif // LLVM_LIB_TARGET_DIRECTX_SPIRVSTRUCTURIZER_H

llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "SPIRVTargetMachine.h"
1414
#include "SPIRV.h"
15+
#include "SPIRVStructurizerWrapper.h"
1516
#include "SPIRVCallLowering.h"
1617
#include "SPIRVGlobalRegistry.h"
1718
#include "SPIRVLegalizerInfo.h"
@@ -28,6 +29,7 @@
2829
#include "llvm/InitializePasses.h"
2930
#include "llvm/MC/TargetRegistry.h"
3031
#include "llvm/Pass.h"
32+
#include "llvm/Passes/PassBuilder.h"
3133
#include "llvm/Target/TargetOptions.h"
3234
#include "llvm/Transforms/Scalar/Reg2Mem.h"
3335
#include "llvm/Transforms/Utils.h"
@@ -93,6 +95,11 @@ SPIRVTargetMachine::SPIRVTargetMachine(const Target &T, const Triple &TT,
9395
setRequiresStructuredCFG(false);
9496
}
9597

98+
void SPIRVTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
99+
#define GET_PASS_REGISTRY "SPIRVPassRegistry.def"
100+
#include "llvm/Passes/TargetPassRegistry.inc"
101+
}
102+
96103
namespace {
97104
// SPIR-V Code Generator Pass Configuration Options.
98105
class SPIRVPassConfig : public TargetPassConfig {

llvm/lib/Target/SPIRV/SPIRVTargetMachine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class SPIRVTargetMachine : public CodeGenTargetMachineImpl {
4343
TargetLoweringObjectFile *getObjFileLowering() const override {
4444
return TLOF.get();
4545
}
46+
47+
void registerPassBuilderCallbacks(PassBuilder &PB) override;
4648
};
4749
} // namespace llvm
4850

llvm/tools/opt/optdriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
376376
"expand-large-fp-convert",
377377
"callbrprepare",
378378
"scalarizer",
379-
"spirv-structurizer"};
379+
};
380380
for (const auto &P : PassNamePrefix)
381381
if (Pass.starts_with(P))
382382
return true;

0 commit comments

Comments
 (0)