Skip to content

Commit da392f1

Browse files
amielczaigcbot
authored andcommitted
Legacy Pass Manager wrapper passes
This change introduces an initial wrapper for the multiple removed LLVM passes. The wrapper allows the New Pass Manager's implementation of the pass to be executed using the Legacy Pass Manager infrastructure.
1 parent 60b92e1 commit da392f1

File tree

24 files changed

+837
-14
lines changed

24 files changed

+837
-14
lines changed

IGC/AdaptorCommon/RayTracing/RayTracingInterface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ SPDX-License-Identifier: MIT
3939
#include <llvm/Transforms/Scalar.h>
4040
#include <llvm/Transforms/Utils.h>
4141
#include <llvm/Analysis/AliasAnalysis.h>
42+
#include "llvmWrapper/Transforms/Scalar/DeadStoreElimination.h"
43+
#include "llvmWrapper/Transforms/IPO/GlobalDCE.h"
44+
4245
#include "common/LLVMWarningsPop.hpp"
4346

4447
using namespace llvm;

IGC/AdaptorOCL/UnifyIROCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SPDX-License-Identifier: MIT
2323
#include <llvm/Analysis/TargetLibraryInfo.h>
2424

2525
#include <llvmWrapper/Transforms/InstCombine/InstCombineWorklist.h>
26+
#include "llvmWrapper/Transforms/IPO/GlobalDCE.h"
2627
#include <llvm/Transforms/Utils.h>
2728

2829
#include "common/LLVMWarningsPop.hpp"
@@ -405,7 +406,7 @@ static void CommonOCLBasedPasses(OpenCLProgramContext *pContext) {
405406
mpm.add(createAlwaysInlinerLegacyPass());
406407
}
407408
// The inliner sometimes fails to delete unused functions, this cleans up the remaining mess.
408-
mpm.add(createGlobalDCEPass());
409+
mpm.add(IGCLLVM::createLegacyWrappedGlobalDCEPass());
409410

410411
// Check after GlobalDCE in case of doubles in dead functions
411412
mpm.add(new ErrorCheck());

IGC/BiFManager/BiFManagerTool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ SPDX-License-Identifier: MIT
2424
#include <llvm/IR/LegacyPassManager.h>
2525
#include <llvm/Support/FileSystem.h>
2626
#include <llvm/ADT/Triple.h>
27+
#include "llvmWrapper/Transforms/IPO/GlobalDCE.h"
28+
2729
#include "common/LLVMWarningsPop.hpp"
2830
#include "BiFManagerTool.hpp"
2931

@@ -391,7 +393,7 @@ void BiFManagerTool::generateSplitedBiFModules(llvm::Module *pMainModule) {
391393

392394
// Do cleanup.
393395
llvm::legacy::PassManager mpm;
394-
mpm.add(createGlobalDCEPass()); // Delete unreachable globals.
396+
mpm.add(IGCLLVM::createLegacyWrappedGlobalDCEPass()); // Delete unreachable globals.
395397
mpm.add(createStripDeadDebugInfoPass()); // Remove dead debug info.
396398
mpm.add(createStripDeadPrototypesPass()); // Remove dead func decls.
397399

IGC/BiFManager/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ target_include_directories("${IGC_BUILD__PROJ__BiFManager}" PRIVATE ${IGC_BUILD_
3737

3838

3939
add_executable("${IGC_BUILD__PROJ__BiFManager_EXE}"
40+
${IGC_WrapperLLVM_HDR}
41+
${IGC_WrapperLLVM_SRC}
4042
"${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
4143
"${CMAKE_CURRENT_SOURCE_DIR}/BiFManagerTool.cpp"
4244
"${CMAKE_CURRENT_SOURCE_DIR}/BiFManagerCommon.cpp"

IGC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,7 @@ set(IGC_BUILD__HDR__IGC__igc_dll
16771677
${IGC_BUILD__HDR__IGC__igc_common}
16781678
${IGC_BUILD__HDR__IGC_DriverInterface__igc_dll}
16791679
${IGC_WrapperLLVM_HDR}
1680+
${IGC_WrapperLLVM_SRC}
16801681
)
16811682

16821683

IGC/Compiler/CISACodeGen/ShaderCodeGen.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ SPDX-License-Identifier: MIT
157157
#include <llvm/Transforms/Scalar.h>
158158
#include <llvm/Bitcode/BitcodeWriter.h>
159159
#include "llvmWrapper/Transforms/Scalar/ADCE.h"
160+
#include "llvmWrapper/Transforms/Scalar/CorrelatedValuePropagation.h"
161+
#include "llvmWrapper/Transforms/Scalar/DeadStoreElimination.h"
162+
#include "llvmWrapper/Transforms/Scalar/JumpThreading.h"
163+
#include "llvmWrapper/Transforms/IPO/SCCP.h"
164+
#include "llvmWrapper/Transforms/IPO/GlobalDCE.h"
165+
#include "llvmWrapper/Transforms/Scalar/MemCpyOptimizer.h"
166+
160167
#include "common/LLVMWarningsPop.hpp"
161168
#include "Compiler/CISACodeGen/PatternMatchPass.hpp"
162169
#include "Compiler/CISACodeGen/EmitVISAPass.hpp"
@@ -651,7 +658,7 @@ void AddLegalizationPasses(CodeGenContext &ctx, IGCPassManager &mpm, PSSignature
651658

652659
if (ctx.enableFunctionCall() || ctx.type == ShaderType::RAYTRACING_SHADER) {
653660
// Sort functions if subroutine/indirect fcall is enabled.
654-
mpm.add(llvm::createGlobalDCEPass());
661+
mpm.add(IGCLLVM::createLegacyWrappedGlobalDCEPass());
655662
mpm.add(new PurgeMetaDataUtils());
656663
mpm.add(createGenXCodeGenModulePass());
657664
}
@@ -746,7 +753,7 @@ void AddLegalizationPasses(CodeGenContext &ctx, IGCPassManager &mpm, PSSignature
746753
const bool allowIPConstProp = !ctx.m_hasStackCalls && IGC_IS_FLAG_DISABLED(DisableIPConstantPropagation);
747754

748755
if (allowIPConstProp) {
749-
mpm.add(createIPSCCPPass());
756+
mpm.add(IGCLLVM::createLegacyWrappedIPSCCPPass());
750757
}
751758
mpm.add(createDeadCodeEliminationPass());
752759
mpm.add(createCFGSimplificationPass());
@@ -1222,7 +1229,7 @@ void OptimizeIR(CodeGenContext *const pContext) {
12221229
const bool allowIPConstProp = !pContext->m_hasStackCalls && IGC_IS_FLAG_DISABLED(DisableIPConstantPropagation);
12231230

12241231
if (allowIPConstProp) {
1225-
mpm.add(createIPSCCPPass());
1232+
mpm.add(IGCLLVM::createLegacyWrappedIPSCCPPass());
12261233
}
12271234
// Note / todo: LLVM < 12 also runs simple constant propagation pass
12281235
// regardless of IPSCCP in this case. This pass is not available on
@@ -1263,7 +1270,7 @@ void OptimizeIR(CodeGenContext *const pContext) {
12631270
mpm.add(createScopedNoAliasAAWrapperPass());
12641271

12651272
if (pContext->m_instrTypes.hasLoadStore) {
1266-
mpm.add(llvm::createDeadStoreEliminationPass());
1273+
mpm.add(IGCLLVM::createLegacyWrappedDeadStoreEliminationPass());
12671274
mpm.add(createMarkReadOnlyLoadPass());
12681275
}
12691276

@@ -1274,7 +1281,7 @@ void OptimizeIR(CodeGenContext *const pContext) {
12741281

12751282

12761283
if (pContext->m_instrTypes.CorrelatedValuePropagationEnable) {
1277-
mpm.add(llvm::createCorrelatedValuePropagationPass());
1284+
mpm.add(IGCLLVM::createLegacyWrappedCorrelatedValuePropagationPass());
12781285
}
12791286

12801287
mpm.add(new BreakConstantExpr());
@@ -1528,7 +1535,7 @@ void OptimizeIR(CodeGenContext *const pContext) {
15281535
#if LLVM_VERSION_MAJOR >= 15
15291536
// In LLVM-12.x an extra parameter InsertFreezeWhenUnfoldingSelect = false was added
15301537
// to JumpThreading pass, but since LLVM-15.x it was removed again.
1531-
mpm.add(llvm::createJumpThreadingPass(BBDuplicateThreshold));
1538+
mpm.add(IGCLLVM::createLegacyWrappedJumpThreadingPass(BBDuplicateThreshold));
15321539
#else // LLVM_VERSION_MAJOR
15331540
mpm.add(llvm::createJumpThreadingPass(false, BBDuplicateThreshold));
15341541
#endif // LLVM_VERSION_MAJOR
@@ -1663,8 +1670,8 @@ void OptimizeIR(CodeGenContext *const pContext) {
16631670
mpm.add(createGenSimplificationPass());
16641671

16651672
if (pContext->m_instrTypes.hasLoadStore) {
1666-
mpm.add(llvm::createDeadStoreEliminationPass());
1667-
mpm.add(llvm::createMemCpyOptPass());
1673+
mpm.add(IGCLLVM::createLegacyWrappedDeadStoreEliminationPass());
1674+
mpm.add(IGCLLVM::createLegacyWrappedMemCpyOptPass());
16681675
mpm.add(createLdShrinkPass());
16691676
}
16701677

IGC/VectorCompiler/lib/GenXCodeGen/GenXTargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ SPDX-License-Identifier: MIT
9393
#include "llvm/Transforms/Utils.h"
9494
#include "llvm/Transforms/Utils/Mem2Reg.h"
9595

96+
#include "llvmWrapper/Transforms/Scalar/CorrelatedValuePropagation.h"
97+
#include "llvmWrapper/Transforms/Scalar/JumpThreading.h"
98+
9699
using namespace llvm;
97100

98101
static cl::opt<std::string>

IGC/WrapperLLVM/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,27 @@ set(IGC_WrapperLLVM_HDR
7070
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/Utils/BasicBlockUtils.h"
7171
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/InitializePasses.h"
7272
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/Scalar/ADCE.h"
73+
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/Scalar/CorrelatedValuePropagation.h"
74+
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/Scalar/DeadStoreElimination.h"
75+
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/Scalar/JumpThreading.h"
76+
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/Scalar/MemCpyOptimizer.h"
77+
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/IPO/GlobalDCE.h"
78+
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/IPO/SCCP.h"
79+
"${CMAKE_CURRENT_SOURCE_DIR}/include/llvmWrapper/Transforms/InstCombine/InstructionCombining.h"
80+
7381
"${CMAKE_CURRENT_SOURCE_DIR}/include/lldWrapper/Common/Driver.h"
7482
)
7583

7684
set(IGC_WrapperLLVM_SRC
7785
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/Scalar/ADCE.cpp"
78-
)
79-
86+
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/Scalar/CorrelatedValuePropagation.cpp"
87+
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/Scalar/DeadStoreElimination.cpp"
88+
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/Scalar/JumpThreading.cpp"
89+
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/Scalar/MemCpyOptimizer.cpp"
90+
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/IPO/GlobalDCE.cpp"
91+
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/IPO/SCCP.cpp"
92+
"${CMAKE_CURRENT_SOURCE_DIR}/lib/llvmWrapper/Transforms/InstCombine/InstructionCombining.cpp"
93+
)
8094
include_directories(
8195
"${CMAKE_CURRENT_SOURCE_DIR}/include"
8296
"${CMAKE_CURRENT_SOURCE_DIR}"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2025 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#ifndef IGCLLVM_TRANSFORMS_IPO_GLOBALDCE_LEGACY_H
10+
#define IGCLLVM_TRANSFORMS_IPO_GLOBALDCE_LEGACY_H
11+
12+
#include "llvm/IR/LegacyPassManager.h"
13+
#include "llvm/Pass.h"
14+
#include "llvm/IR/PassManager.h"
15+
#include "llvm/Passes/PassBuilder.h"
16+
17+
using namespace llvm;
18+
19+
namespace IGCLLVM {
20+
21+
struct GlobalDCELegacyPassWrapper : public ModulePass {
22+
GlobalDCELegacyPassWrapper();
23+
static char ID;
24+
bool runOnModule(llvm::Module &M);
25+
26+
private:
27+
PassBuilder PB;
28+
ModuleAnalysisManager MAM;
29+
};
30+
31+
ModulePass *createLegacyWrappedGlobalDCEPass();
32+
33+
} // end namespace IGCLLVM
34+
35+
#endif // IGCLLVM_TRANSFORMS_IPO_GLOBALDCE_LEGACY_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2025 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#ifndef IGCLLVM_TRANSFORMS_IPO_SCCP_LEGACY_H
10+
#define IGCLLVM_TRANSFORMS_IPO_SCCP_LEGACY_H
11+
12+
#include "llvm/IR/LegacyPassManager.h"
13+
#include "llvm/Pass.h"
14+
#include "llvm/IR/PassManager.h"
15+
#include "llvm/Passes/PassBuilder.h"
16+
17+
using namespace llvm;
18+
19+
namespace IGCLLVM {
20+
21+
struct IPSCCPLegacyPassWrapper : public ModulePass {
22+
IPSCCPLegacyPassWrapper();
23+
static char ID;
24+
bool runOnModule(llvm::Module &M);
25+
void getAnalysisUsage(AnalysisUsage &AU) const;
26+
27+
private:
28+
PassBuilder PB;
29+
LoopAnalysisManager LAM;
30+
FunctionAnalysisManager FAM;
31+
CGSCCAnalysisManager CGAM;
32+
ModuleAnalysisManager MAM;
33+
};
34+
35+
ModulePass *createLegacyWrappedIPSCCPPass();
36+
37+
} // end namespace IGCLLVM
38+
39+
#endif // IGCLLVM_TRANSFORMS_IPO_SCCP_LEGACY_H

0 commit comments

Comments
 (0)