Index: llvm/lib/Target/AMDGPU/AMDGPU.h =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPU.h +++ llvm/lib/Target/AMDGPU/AMDGPU.h @@ -232,6 +232,16 @@ PreservedAnalyses run(Function &, FunctionAnalysisManager &); }; +class AMDGPULowerKernelArgumentsPass + : public PassInfoMixin { +private: + TargetMachine &TM; + +public: + AMDGPULowerKernelArgumentsPass(TargetMachine &TM) : TM(TM){}; + PreservedAnalyses run(Function &, FunctionAnalysisManager &); +}; + FunctionPass *createAMDGPUAnnotateUniformValues(); ModulePass *createAMDGPUPrintfRuntimeBinding(); Index: llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp +++ llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp @@ -24,7 +24,7 @@ namespace { -class AMDGPULowerKernelArguments : public FunctionPass{ +class AMDGPULowerKernelArguments : public FunctionPass { public: static char ID; @@ -55,14 +55,11 @@ return InsPt; } -bool AMDGPULowerKernelArguments::runOnFunction(Function &F) { +static bool lowerKernelArguments(Function &F, const TargetMachine &TM) { CallingConv::ID CC = F.getCallingConv(); if (CC != CallingConv::AMDGPU_KERNEL || F.arg_empty()) return false; - auto &TPC = getAnalysis(); - - const TargetMachine &TM = TPC.getTM(); const GCNSubtarget &ST = TM.getSubtarget(F); LLVMContext &Ctx = F.getParent()->getContext(); const DataLayout &DL = F.getParent()->getDataLayout(); @@ -232,6 +229,12 @@ return true; } +bool AMDGPULowerKernelArguments::runOnFunction(Function &F) { + auto &TPC = getAnalysis(); + const TargetMachine &TM = TPC.getTM(); + return lowerKernelArguments(F, TM); +} + INITIALIZE_PASS_BEGIN(AMDGPULowerKernelArguments, DEBUG_TYPE, "AMDGPU Lower Kernel Arguments", false, false) INITIALIZE_PASS_END(AMDGPULowerKernelArguments, DEBUG_TYPE, "AMDGPU Lower Kernel Arguments", @@ -242,3 +245,16 @@ FunctionPass *llvm::createAMDGPULowerKernelArgumentsPass() { return new AMDGPULowerKernelArguments(); } + +PreservedAnalyses +AMDGPULowerKernelArgumentsPass::run(Function &F, FunctionAnalysisManager &AM) { + bool Changed = lowerKernelArguments(F, TM); + if (Changed) { + // TODO: Preserves a lot more. + PreservedAnalyses PA; + PA.preserveSet(); + return PA; + } + + return PreservedAnalyses::all(); +} Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -665,6 +665,10 @@ PM.addPass(AMDGPUCodeGenPreparePass(*this)); return true; } + if (PassName == "amdgpu-lower-kernel-arguments") { + PM.addPass(AMDGPULowerKernelArgumentsPass(*this)); + return true; + } return false; }); Index: llvm/test/CodeGen/AMDGPU/lower-kernargs.ll =================================================================== --- llvm/test/CodeGen/AMDGPU/lower-kernargs.ll +++ llvm/test/CodeGen/AMDGPU/lower-kernargs.ll @@ -1,6 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals -; RUN: opt -mtriple=amdgcn-amd-amdhsa -S -o - -amdgpu-lower-kernel-arguments %s | FileCheck -check-prefixes=GCN,HSA %s -; RUN: opt -mtriple=amdgcn-- -S -o - -amdgpu-lower-kernel-arguments %s | FileCheck -check-prefixes=GCN,MESA %s +; RUN: opt -mtriple=amdgcn-amd-amdhsa -S -o - -passes=amdgpu-lower-kernel-arguments %s | FileCheck -check-prefixes=GCN,HSA %s +; RUN: opt -mtriple=amdgcn-- -S -o - -passes=amdgpu-lower-kernel-arguments %s | FileCheck -check-prefixes=GCN,MESA %s target datalayout = "A5"