19#include "llvm/IR/IntrinsicsAMDGPU.h"
22#define DEBUG_TYPE "amdgpu-lower-intrinsics"
28class AMDGPULowerIntrinsicsImpl {
42class AMDGPULowerIntrinsicsLegacy :
public ModulePass {
48 bool runOnModule(
Module &M)
override;
65bool AMDGPULowerIntrinsicsImpl::run() {
68 for (Function &
F : M) {
69 switch (
F.getIntrinsicID()) {
72 case Intrinsic::amdgcn_s_barrier:
73 case Intrinsic::amdgcn_s_barrier_signal:
74 case Intrinsic::amdgcn_s_barrier_signal_isfirst:
75 case Intrinsic::amdgcn_s_barrier_wait:
86bool AMDGPULowerIntrinsicsImpl::visitBarrier(IntrinsicInst &
I) {
87 assert(
I.getIntrinsicID() == Intrinsic::amdgcn_s_barrier ||
88 I.getIntrinsicID() == Intrinsic::amdgcn_s_barrier_signal ||
89 I.getIntrinsicID() == Intrinsic::amdgcn_s_barrier_signal_isfirst ||
90 I.getIntrinsicID() == Intrinsic::amdgcn_s_barrier_wait);
92 const GCNSubtarget &
ST = TM.
getSubtarget<GCNSubtarget>(*
I.getFunction());
93 bool IsSingleWaveWG =
false;
96 unsigned WGMaxSize =
ST.getFlatWorkGroupSizes(*
I.getFunction()).second;
97 IsSingleWaveWG = WGMaxSize <=
ST.getWavefrontSize();
102 if (IsSingleWaveWG) {
104 if (
I.getIntrinsicID() == Intrinsic::amdgcn_s_barrier ||
105 I.getIntrinsicID() == Intrinsic::amdgcn_s_barrier_wait) {
106 B.CreateIntrinsic(
B.getVoidTy(), Intrinsic::amdgcn_wave_barrier, {});
107 }
else if (
I.getIntrinsicID() ==
108 Intrinsic::amdgcn_s_barrier_signal_isfirst) {
110 I.replaceAllUsesWith(
B.getInt1(
true));
116 if (
I.getIntrinsicID() == Intrinsic::amdgcn_s_barrier &&
117 ST.hasSplitBarriers()) {
121 B.CreateIntrinsic(
B.getVoidTy(), Intrinsic::amdgcn_s_barrier_signal,
123 B.CreateIntrinsic(
B.getVoidTy(), Intrinsic::amdgcn_s_barrier_wait,
134 AMDGPULowerIntrinsicsImpl Impl(M, TM);
142bool AMDGPULowerIntrinsicsLegacy::runOnModule(
Module &M) {
143 auto &TPC = getAnalysis<TargetPassConfig>();
146 AMDGPULowerIntrinsicsImpl Impl(M, TM);
150#define PASS_DESC "AMDGPU lower intrinsics"
157char AMDGPULowerIntrinsicsLegacy::
ID = 0;
160 return new AMDGPULowerIntrinsicsLegacy;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
The AMDGPU TargetMachine interface definition for hw codegen targets.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
uint64_t IntrinsicInst * II
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static bool forEachCall(Function &Intrin, T Callback)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
A wrapper class for inspecting calls to intrinsic functions.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
Target-Independent Code Generator Pass Configuration Options.
iterator_range< user_iterator > users()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
ModulePass * createAMDGPULowerIntrinsicsLegacyPass()
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)