llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-amdgpu Author: Shilei Tian (shiltian) <details> <summary>Changes</summary> --- Full diff: https://github.com/llvm/llvm-project/pull/101760.diff 5 Files Affected: - (modified) llvm/lib/Target/AMDGPU/AMDGPU.h (+8-3) - (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp (+5-6) - (modified) llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def (+11-1) - (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+26-3) - (modified) llvm/test/CodeGen/AMDGPU/simple-indirect-call-2.ll (+1-1) ``````````diff diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h index 50aef36724f70..d8ed1d9db00e5 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPU.h +++ b/llvm/lib/Target/AMDGPU/AMDGPU.h @@ -283,17 +283,22 @@ class AMDGPULowerKernelArgumentsPass PreservedAnalyses run(Function &, FunctionAnalysisManager &); }; +struct AMDGPUAttributorOptions { + bool IsClosedWorld = false; +}; + class AMDGPUAttributorPass : public PassInfoMixin<AMDGPUAttributorPass> { private: TargetMachine &TM; + AMDGPUAttributorOptions Options; + /// Asserts whether we can assume whole program visibility. bool HasWholeProgramVisibility = false; public: - AMDGPUAttributorPass(TargetMachine &TM, - bool HasWholeProgramVisibility = false) - : TM(TM), HasWholeProgramVisibility(HasWholeProgramVisibility) {}; + AMDGPUAttributorPass(TargetMachine &TM, AMDGPUAttributorOptions Options = {}) + : TM(TM), Options(Options) {}; PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); }; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp index 576494b1a564d..357ba0fadbcf1 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp @@ -1025,7 +1025,7 @@ static void addPreloadKernArgHint(Function &F, TargetMachine &TM) { } static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, - bool HasWholeProgramVisibility) { + AMDGPUAttributorOptions Options) { SetVector<Function *> Functions; for (Function &F : M) { if (!F.isIntrinsic()) @@ -1043,7 +1043,7 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, &AAUnderlyingObjects::ID, &AAIndirectCallInfo::ID, &AAInstanceInfo::ID}); AttributorConfig AC(CGUpdater); - AC.IsClosedWorldModule = HasWholeProgramVisibility; + AC.IsClosedWorldModule = Options.IsClosedWorld; AC.Allowed = &Allowed; AC.IsModulePass = true; AC.DefaultInitializeLiveInternals = false; @@ -1102,7 +1102,7 @@ class AMDGPUAttributorLegacy : public ModulePass { bool runOnModule(Module &M) override { AnalysisGetter AG(this); - return runImpl(M, AG, *TM, /*HasWholeProgramVisibility=*/false); + return runImpl(M, AG, *TM, /*Options=*/{}); } void getAnalysisUsage(AnalysisUsage &AU) const override { @@ -1123,9 +1123,8 @@ PreservedAnalyses llvm::AMDGPUAttributorPass::run(Module &M, AnalysisGetter AG(FAM); // TODO: Probably preserves CFG - return runImpl(M, AG, TM, HasWholeProgramVisibility) - ? PreservedAnalyses::none() - : PreservedAnalyses::all(); + return runImpl(M, AG, TM, Options) ? PreservedAnalyses::none() + : PreservedAnalyses::all(); } char AMDGPUAttributorLegacy::ID = 0; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def b/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def index 57fc3314dd970..0adf11d27a2f5 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def +++ b/llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def @@ -17,7 +17,6 @@ #define MODULE_PASS(NAME, CREATE_PASS) #endif MODULE_PASS("amdgpu-always-inline", AMDGPUAlwaysInlinePass()) -MODULE_PASS("amdgpu-attributor", AMDGPUAttributorPass(*this)) MODULE_PASS("amdgpu-lower-buffer-fat-pointers", AMDGPULowerBufferFatPointersPass(*this)) MODULE_PASS("amdgpu-lower-ctor-dtor", AMDGPUCtorDtorLoweringPass()) @@ -26,6 +25,17 @@ MODULE_PASS("amdgpu-printf-runtime-binding", AMDGPUPrintfRuntimeBindingPass()) MODULE_PASS("amdgpu-unify-metadata", AMDGPUUnifyMetadataPass()) #undef MODULE_PASS +#ifndef MODULE_PASS_WITH_PARAMS +#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) +#endif +MODULE_PASS_WITH_PARAMS( + "amdgpu-attributor", "AMDGPUAttributorPass", + [=](AMDGPUAttributorOptions Options) { + return AMDGPUAttributorPass(*this, Options); + }, + parseAMDGPUAttributorPassOptions, "closed-world") +#undef MODULE_PASS_WITH_PARAMS + #ifndef FUNCTION_PASS #define FUNCTION_PASS(NAME, CREATE_PASS) #endif diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp index 50cc2d871d4ec..700408cd55e62 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -54,6 +54,7 @@ #include "llvm/InitializePasses.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Passes/PassBuilder.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Transforms/HipStdPar/HipStdPar.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" @@ -661,6 +662,24 @@ Error AMDGPUTargetMachine::buildCodeGenPipeline( return CGPB.buildPipeline(MPM, Out, DwoOut, FileType); } +Expected<AMDGPUAttributorOptions> +parseAMDGPUAttributorPassOptions(StringRef Params) { + AMDGPUAttributorOptions Result; + while (!Params.empty()) { + StringRef ParamName; + std::tie(ParamName, Params) = Params.split(';'); + if (ParamName == "closed-world") { + Result.IsClosedWorld = true; + } else { + return make_error<StringError>( + formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName) + .str(), + inconvertibleErrorCode()); + } + } + return Result; +} + void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) { #define GET_PASS_REGISTRY "AMDGPUPassRegistry.def" @@ -739,9 +758,13 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) { OptimizationLevel Level, ThinOrFullLTOPhase Phase) { if (Level != OptimizationLevel::O0) { - MPM.addPass(AMDGPUAttributorPass( - *this, Phase == ThinOrFullLTOPhase::FullLTOPostLink || - Phase == ThinOrFullLTOPhase::ThinLTOPostLink)); + { + AMDGPUAttributorOptions Options; + Options.IsClosedWorld = + (Phase == ThinOrFullLTOPhase::FullLTOPostLink) || + (Phase == ThinOrFullLTOPhase::ThinLTOPostLink); + MPM.addPass(AMDGPUAttributorPass(*this, Options)); + } } }); diff --git a/llvm/test/CodeGen/AMDGPU/simple-indirect-call-2.ll b/llvm/test/CodeGen/AMDGPU/simple-indirect-call-2.ll index 9c3457e87dbf3..850446c414049 100644 --- a/llvm/test/CodeGen/AMDGPU/simple-indirect-call-2.ll +++ b/llvm/test/CodeGen/AMDGPU/simple-indirect-call-2.ll @@ -1,6 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-attributor %s | FileCheck --check-prefixes=CHECK,OW %s -; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-attributor -attributor-assume-closed-world=1 %s | FileCheck --check-prefixes=CHECK,CW %s +; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes='amdgpu-attributor<closed-world>' %s | FileCheck --check-prefixes=CHECK,CW %s target datalayout = "A5" `````````` </details> https://github.com/llvm/llvm-project/pull/101760 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits