From 7022498ac2f236e411e8a0f9a48669e754000a4b Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 20 Aug 2024 00:10:45 +0400 Subject: [PATCH] AMDGPU/NewPM: Start implementing addCodeGenPrepare (#102816) --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 11 +++++++++++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp index f15d02ac9301ef..04b96a32a8970a 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -73,6 +73,7 @@ #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/FixIrreducible.h" #include "llvm/Transforms/Utils/LCSSA.h" +#include "llvm/Transforms/Utils/LowerSwitch.h" #include "llvm/Transforms/Utils/SimplifyLibCalls.h" #include "llvm/Transforms/Utils/UnifyLoopExits.h" #include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h" @@ -1768,6 +1769,16 @@ AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder( ShadowStackGCLoweringPass>(); } +void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(AddIRPass &addPass) const { + Base::addCodeGenPrepare(addPass); + + // LowerSwitch pass may introduce unreachable blocks that can cause unexpected + // behavior for subsequent passes. Placing it here seems better that these + // blocks would get cleaned up by UnreachableBlockElim inserted next in the + // pass flow. + addPass(LowerSwitchPass()); +} + void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const { const bool LateCFGStructurize = AMDGPUTargetMachine::EnableLateStructurizeCFG; const bool DisableStructurizer = AMDGPUTargetMachine::DisableStructurizer; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h index 4dffddd2d44ccf..576bf40e3328d5 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h @@ -165,11 +165,14 @@ class AMDGPUPassConfig : public TargetPassConfig { class AMDGPUCodeGenPassBuilder : public CodeGenPassBuilder { + using Base = CodeGenPassBuilder; + public: AMDGPUCodeGenPassBuilder(GCNTargetMachine &TM, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC); + void addCodeGenPrepare(AddIRPass &) const; void addPreISel(AddIRPass &addPass) const; void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const; Error addInstSelector(AddMachinePass &) const;