From ce7b6ed81c1ae86004ba1763ba60bbdb87784202 Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Mon, 18 May 2026 21:13:34 -0400 Subject: [PATCH] [NFC][AMDGPU] Remove AMDGPU related code from generic TargetParser.cpp --- clang/lib/Basic/TargetID.cpp | 2 +- clang/lib/Basic/Targets/AMDGPU.cpp | 1 + clang/lib/Basic/Targets/AMDGPU.h | 2 +- clang/lib/Basic/Targets/SPIR.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.cpp | 2 +- clang/lib/Driver/ToolChains/AMDGPU.h | 2 +- clang/lib/Driver/ToolChains/Arch/AMDGPU.cpp | 2 - clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +- clang/lib/Sema/SemaAMDGPU.cpp | 2 +- flang/lib/Frontend/CompilerInstance.cpp | 2 +- .../llvm/TargetParser/AMDGPUTargetParser.h | 109 +++ llvm/include/llvm/TargetParser/TargetParser.h | 91 +-- llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp | 2 +- llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp | 2 +- .../AMDGPU/AMDGPUPreloadKernArgProlog.cpp | 2 +- .../Target/AMDGPU/AMDGPUWaitSGPRHazards.cpp | 2 +- llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h | 2 +- .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp | 2 +- .../lib/Target/AMDGPU/GCNHazardRecognizer.cpp | 2 +- .../AMDGPU/MCA/AMDGPUCustomBehaviour.cpp | 1 + .../Target/AMDGPU/MCA/AMDGPUCustomBehaviour.h | 1 - .../AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp | 2 +- .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp | 2 +- .../MCTargetDesc/AMDGPUMCKernelDescriptor.cpp | 2 +- .../MCTargetDesc/AMDGPUTargetStreamer.cpp | 2 +- llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp | 2 +- llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp | 2 +- .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp | 2 +- llvm/lib/TargetParser/AMDGPUTargetParser.cpp | 659 ++++++++++++++++++ llvm/lib/TargetParser/CMakeLists.txt | 1 + llvm/lib/TargetParser/TargetParser.cpp | 644 +---------------- .../Target/AMDGPU/AMDGPUUnitTests.cpp | 2 +- mlir/lib/Target/LLVM/ROCDL/Target.cpp | 2 +- 33 files changed, 797 insertions(+), 760 deletions(-) create mode 100644 llvm/include/llvm/TargetParser/AMDGPUTargetParser.h create mode 100644 llvm/lib/TargetParser/AMDGPUTargetParser.cpp diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp index 446577930b017..6d9ba55ccd9d7 100644 --- a/clang/lib/Basic/TargetID.cpp +++ b/clang/lib/Basic/TargetID.cpp @@ -11,7 +11,7 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Path.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include "llvm/TargetParser/Triple.h" #include #include diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp index 48ba5d94df581..6b077dfa8e142 100644 --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -17,6 +17,7 @@ #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" #include "llvm/ADT/SmallString.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace clang; using namespace clang::targets; diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h index 38c92e73708f8..f1bfca4c42417 100644 --- a/clang/lib/Basic/Targets/AMDGPU.h +++ b/clang/lib/Basic/Targets/AMDGPU.h @@ -19,7 +19,7 @@ #include "llvm/ADT/StringSet.h" #include "llvm/Support/AMDGPUAddrSpace.h" #include "llvm/Support/Compiler.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include "llvm/TargetParser/Triple.h" #include diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp index b6d6b213d78ed..8fdb45acf381f 100644 --- a/clang/lib/Basic/Targets/SPIR.cpp +++ b/clang/lib/Basic/Targets/SPIR.cpp @@ -14,7 +14,7 @@ #include "AMDGPU.h" #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace clang; using namespace clang::targets; diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index d2d8e56eb22be..5c3baa6898126 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -22,8 +22,8 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include "llvm/TargetParser/Host.h" -#include "llvm/TargetParser/TargetParser.h" #include #include diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h index 20b9365c91bbf..ebc02fa477894 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.h +++ b/clang/lib/Driver/ToolChains/AMDGPU.h @@ -15,7 +15,7 @@ #include "clang/Driver/ToolChain.h" #include "clang/Options/Options.h" #include "llvm/ADT/SmallString.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include diff --git a/clang/lib/Driver/ToolChains/Arch/AMDGPU.cpp b/clang/lib/Driver/ToolChains/Arch/AMDGPU.cpp index 8a9cb7ef5b367..461ec590faf40 100644 --- a/clang/lib/Driver/ToolChains/Arch/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AMDGPU.cpp @@ -7,10 +7,8 @@ //===----------------------------------------------------------------------===// #include "AMDGPU.h" -#include "clang/Basic/TargetID.h" #include "clang/Driver/Driver.h" #include "clang/Options/Options.h" -#include "llvm/TargetParser/TargetParser.h" using namespace clang::driver; using namespace clang::driver::tools; diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 9c2d1955a9e12..6b6bfc284e495 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -58,9 +58,9 @@ #include "llvm/Support/Threading.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/YAMLParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include "llvm/TargetParser/Host.h" #include "llvm/TargetParser/PPCTargetParser.h" -#include "llvm/TargetParser/TargetParser.h" #include using namespace clang::driver; diff --git a/clang/lib/Sema/SemaAMDGPU.cpp b/clang/lib/Sema/SemaAMDGPU.cpp index 96a4648f06314..1d2b3898c92d6 100644 --- a/clang/lib/Sema/SemaAMDGPU.cpp +++ b/clang/lib/Sema/SemaAMDGPU.cpp @@ -26,7 +26,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/Support/AMDGPUAddrSpace.h" #include "llvm/Support/AtomicOrdering.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include #include diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp index 28011e8bf685a..3e820d386f8a9 100644 --- a/flang/lib/Frontend/CompilerInstance.cpp +++ b/flang/lib/Frontend/CompilerInstance.cpp @@ -29,8 +29,8 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include "llvm/TargetParser/PPCTargetParser.h" -#include "llvm/TargetParser/TargetParser.h" #include "llvm/TargetParser/Triple.h" using namespace Fortran::frontend; diff --git a/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h b/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h new file mode 100644 index 0000000000000..7c192b36b6ec8 --- /dev/null +++ b/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h @@ -0,0 +1,109 @@ +//===-- AMDGPUTargetParser - Parser for AMDGPU features ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a target parser to recognise AMDGPU hardware features. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TARGETPARSER_AMDGPUTARGETPARSER_H +#define LLVM_TARGETPARSER_AMDGPUTARGETPARSER_H + +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Compiler.h" +#include +#include + +namespace llvm { + +template class SmallVectorImpl; +class Triple; + +namespace AMDGPU { + +/// GPU kinds supported by the AMDGPU target. +enum GPUKind : uint32_t { + // Not specified processor. + GK_NONE = 0, + +#define R600_GPU(NAME, ENUM, FEATURES) ENUM, +#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) ENUM, +#include "AMDGPUTargetParser.def" + + GK_AMDGCN_GENERIC_FIRST = GK_GFX9_GENERIC, + GK_AMDGCN_GENERIC_LAST = GK_GFX12_5_GENERIC, +}; + +/// Instruction set architecture version. +struct IsaVersion { + unsigned Major; + unsigned Minor; + unsigned Stepping; +}; + +// This isn't comprehensive for now, just things that are needed from the +// frontend driver. +enum ArchFeatureKind : uint32_t { + FEATURE_NONE = 0, + + // These features only exist for r600, and are implied true for amdgcn. + FEATURE_FMA = 1 << 1, + FEATURE_LDEXP = 1 << 2, + FEATURE_FP64 = 1 << 3, + + // Common features. + FEATURE_FAST_FMA_F32 = 1 << 4, + FEATURE_FAST_DENORMAL_F32 = 1 << 5, + + // Wavefront 32 is available. + FEATURE_WAVE32 = 1 << 6, + + // Xnack is available. + FEATURE_XNACK = 1 << 7, + + // Sram-ecc is available. + FEATURE_SRAMECC = 1 << 8, + + // WGP mode is supported. + FEATURE_WGP = 1 << 9, + + // Xnack is available by default + FEATURE_XNACK_ALWAYS = 1 << 10 +}; + +enum FeatureError : uint32_t { + NO_ERROR = 0, + INVALID_FEATURE_COMBINATION, + UNSUPPORTED_TARGET_FEATURE +}; + +LLVM_ABI StringRef getArchFamilyNameAMDGCN(GPUKind AK); + +LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK); +LLVM_ABI StringRef getArchNameR600(GPUKind AK); +LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch); +LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU); +LLVM_ABI GPUKind parseArchR600(StringRef CPU); +LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK); +LLVM_ABI unsigned getArchAttrR600(GPUKind AK); + +LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl &Values); +LLVM_ABI void fillValidArchListR600(SmallVectorImpl &Values); + +LLVM_ABI IsaVersion getIsaVersion(StringRef GPU); + +/// Fills Features map with default values for given target GPU. +/// \p Features contains overriding target features and this function returns +/// default target features with entries overridden by \p Features. +LLVM_ABI std::pair +fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap &Features); +} // namespace AMDGPU + +} // namespace llvm + +#endif diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h index caf57c804db46..b65ff37dfc958 100644 --- a/llvm/include/llvm/TargetParser/TargetParser.h +++ b/llvm/include/llvm/TargetParser/TargetParser.h @@ -19,99 +19,10 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Compiler.h" +#include namespace llvm { -template class SmallVectorImpl; -class Triple; - -// Target specific information in their own namespaces. -// (ARM/AArch64/X86 are declared in ARM/AArch64/X86TargetParser.h) -// These should be generated from TableGen because the information is already -// there, and there is where new information about targets will be added. -// FIXME: To TableGen this we need to make some table generated files available -// even if the back-end is not compiled with LLVM, plus we need to create a new -// back-end to TableGen to create these clean tables. -namespace AMDGPU { - -/// GPU kinds supported by the AMDGPU target. -enum GPUKind : uint32_t { - // Not specified processor. - GK_NONE = 0, - -#define R600_GPU(NAME, ENUM, FEATURES) ENUM, -#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) ENUM, -#include "AMDGPUTargetParser.def" - - GK_AMDGCN_GENERIC_FIRST = GK_GFX9_GENERIC, - GK_AMDGCN_GENERIC_LAST = GK_GFX12_5_GENERIC, -}; - -/// Instruction set architecture version. -struct IsaVersion { - unsigned Major; - unsigned Minor; - unsigned Stepping; -}; - -// This isn't comprehensive for now, just things that are needed from the -// frontend driver. -enum ArchFeatureKind : uint32_t { - FEATURE_NONE = 0, - - // These features only exist for r600, and are implied true for amdgcn. - FEATURE_FMA = 1 << 1, - FEATURE_LDEXP = 1 << 2, - FEATURE_FP64 = 1 << 3, - - // Common features. - FEATURE_FAST_FMA_F32 = 1 << 4, - FEATURE_FAST_DENORMAL_F32 = 1 << 5, - - // Wavefront 32 is available. - FEATURE_WAVE32 = 1 << 6, - - // Xnack is available. - FEATURE_XNACK = 1 << 7, - - // Sram-ecc is available. - FEATURE_SRAMECC = 1 << 8, - - // WGP mode is supported. - FEATURE_WGP = 1 << 9, - - // Xnack is available by default - FEATURE_XNACK_ALWAYS = 1 << 10 -}; - -enum FeatureError : uint32_t { - NO_ERROR = 0, - INVALID_FEATURE_COMBINATION, - UNSUPPORTED_TARGET_FEATURE -}; - -LLVM_ABI StringRef getArchFamilyNameAMDGCN(GPUKind AK); - -LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK); -LLVM_ABI StringRef getArchNameR600(GPUKind AK); -LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch); -LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU); -LLVM_ABI GPUKind parseArchR600(StringRef CPU); -LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK); -LLVM_ABI unsigned getArchAttrR600(GPUKind AK); - -LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl &Values); -LLVM_ABI void fillValidArchListR600(SmallVectorImpl &Values); - -LLVM_ABI IsaVersion getIsaVersion(StringRef GPU); - -/// Fills Features map with default values for given target GPU. -/// \p Features contains overriding target features and this function returns -/// default target features with entries overridden by \p Features. -LLVM_ABI std::pair -fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap &Features); -} // namespace AMDGPU - struct BasicSubtargetFeatureKV { const char *Key; ///< K-V key string unsigned Value; ///< K-V integer value diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp index 7b567bd65a0f8..9ae6e69c5fb79 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -50,7 +50,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; using namespace llvm::AMDGPU; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp index e262d4e715fea..873aae5daae94 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp @@ -13,7 +13,7 @@ #include "AMDGPUMIRFormatter.h" #include "SIMachineFunctionInfo.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernArgProlog.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernArgProlog.cpp index 90c4f4e6680c2..c943d6fa2dd92 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernArgProlog.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernArgProlog.cpp @@ -31,7 +31,7 @@ #include "GCNSubtarget.h" #include "SIMachineFunctionInfo.h" #include "llvm/CodeGen/MachineFunctionPass.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUWaitSGPRHazards.cpp b/llvm/lib/Target/AMDGPU/AMDGPUWaitSGPRHazards.cpp index faef40862d718..a04163599aab9 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUWaitSGPRHazards.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUWaitSGPRHazards.cpp @@ -17,7 +17,7 @@ #include "MCTargetDesc/AMDGPUMCTargetDesc.h" #include "SIInstrInfo.h" #include "llvm/ADT/SetVector.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h b/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h index 111b28af3b47e..24dbcdf8cc475 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h +++ b/llvm/lib/Target/AMDGPU/AMDGPUWaitcntUtils.h @@ -13,7 +13,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" namespace llvm { diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp index 5f00d7b28051d..b573ff6eec429 100644 --- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -43,7 +43,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/MathExtras.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include using namespace llvm; diff --git a/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp b/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp index 8e2306682dbc3..8ab90d953200e 100644 --- a/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp +++ b/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp @@ -21,7 +21,7 @@ #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/ScheduleDAG.h" #include "llvm/Support/Debug.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; diff --git a/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.cpp b/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.cpp index 9ec12131d7236..6c81cbcad3330 100644 --- a/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.cpp +++ b/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.cpp @@ -18,6 +18,7 @@ #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/WithColor.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" namespace llvm::mca { diff --git a/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.h b/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.h index aeb5c032daee4..c764ff71f5d0c 100644 --- a/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.h +++ b/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.h @@ -20,7 +20,6 @@ #include "Utils/AMDGPUBaseInfo.h" #include "llvm/ADT/SmallVector.h" #include "llvm/MCA/CustomBehaviour.h" -#include "llvm/TargetParser/TargetParser.h" namespace llvm { namespace mca { diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp index 95da56f420b2d..d71dcf225df50 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp @@ -21,7 +21,7 @@ #include "llvm/MC/MCValue.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/EndianStream.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; using namespace llvm::AMDGPU; diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp index 9ffa4458abdc6..19c5ac6a647ce 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp @@ -20,7 +20,7 @@ #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; using namespace llvm::AMDGPU; diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCKernelDescriptor.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCKernelDescriptor.cpp index 296b248dfa23a..a37fe6741ea55 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCKernelDescriptor.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCKernelDescriptor.cpp @@ -12,7 +12,7 @@ #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCSubtargetInfo.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; using namespace llvm::AMDGPU; diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp index d6509fdd2b21a..d2d11f0786a16 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp @@ -31,7 +31,7 @@ #include "llvm/Support/AMDHSAKernelDescriptor.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormattedStream.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; using namespace llvm::AMDGPU; diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp index fc99fc5b0bd43..f2397f27b1570 100644 --- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp +++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp @@ -40,7 +40,7 @@ #include "llvm/IR/Dominators.h" #include "llvm/InitializePasses.h" #include "llvm/Support/DebugCounter.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp index fe87c5afda1b8..25922c5af7da1 100644 --- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp +++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp @@ -28,7 +28,7 @@ #include "llvm/Support/AMDGPUAddrSpace.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Debug.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" using namespace llvm; using namespace llvm::AMDGPU; diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp index 9df73f958a133..b7c46d70ac685 100644 --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp @@ -26,7 +26,7 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Support/CommandLine.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include #define GET_INSTRINFO_NAMED_OPS diff --git a/llvm/lib/TargetParser/AMDGPUTargetParser.cpp b/llvm/lib/TargetParser/AMDGPUTargetParser.cpp new file mode 100644 index 0000000000000..756b7c2154ca2 --- /dev/null +++ b/llvm/lib/TargetParser/AMDGPUTargetParser.cpp @@ -0,0 +1,659 @@ +//===-- AMDGPUTargetParser - Parser for AMDGPU features ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a target parser to recognise AMDGPU hardware features. +// +//===----------------------------------------------------------------------===// + +#include "llvm/TargetParser/AMDGPUTargetParser.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/TargetParser/Triple.h" + +using namespace llvm; +using namespace AMDGPU; + +StringRef llvm::AMDGPU::getArchFamilyNameAMDGCN(GPUKind AK) { + StringRef ArchName = getArchNameAMDGCN(AK); + assert((AK >= GK_AMDGCN_GENERIC_FIRST && AK <= GK_AMDGCN_GENERIC_LAST) == + ArchName.ends_with("-generic") && + "Generic AMDGCN arch not classified correctly!"); + if (AK >= GK_AMDGCN_GENERIC_FIRST && AK <= GK_AMDGCN_GENERIC_LAST) { + // Return the part before the first '-', e.g. "gfx9-4-generic" -> "gfx9". + return ArchName.take_front(ArchName.find('-')); + } + return ArchName.empty() ? "" : ArchName.drop_back(2); +} + +StringRef llvm::AMDGPU::getArchNameAMDGCN(GPUKind AK) { + switch (AK) { +#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) \ + case ENUM: \ + return NAME; +#include "llvm/TargetParser/AMDGPUTargetParser.def" + default: + return ""; + } +} + +StringRef llvm::AMDGPU::getArchNameR600(GPUKind AK) { + switch (AK) { +#define R600_GPU(NAME, ENUM, FEATURES) \ + case ENUM: \ + return NAME; +#include "llvm/TargetParser/AMDGPUTargetParser.def" + default: + return ""; + } +} + +AMDGPU::GPUKind llvm::AMDGPU::parseArchAMDGCN(StringRef CPU) { + return StringSwitch(CPU) +#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) .Case(NAME, ENUM) +#define AMDGCN_GPU_ALIAS(NAME, ENUM) .Case(NAME, ENUM) +#include "llvm/TargetParser/AMDGPUTargetParser.def" + .Default(AMDGPU::GPUKind::GK_NONE); +} + +AMDGPU::GPUKind llvm::AMDGPU::parseArchR600(StringRef CPU) { + return StringSwitch(CPU) +#define R600_GPU(NAME, ENUM, FEATURES) .Case(NAME, ENUM) +#define R600_GPU_ALIAS(NAME, ENUM) .Case(NAME, ENUM) +#include "llvm/TargetParser/AMDGPUTargetParser.def" + .Default(AMDGPU::GPUKind::GK_NONE); +} + +unsigned AMDGPU::getArchAttrAMDGCN(GPUKind AK) { + switch (AK) { +#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) \ + case ENUM: \ + return FEATURES; +#include "llvm/TargetParser/AMDGPUTargetParser.def" + default: + return FEATURE_NONE; + } +} + +unsigned AMDGPU::getArchAttrR600(GPUKind AK) { + switch (AK) { +#define R600_GPU(NAME, ENUM, FEATURES) \ + case ENUM: \ + return FEATURES; +#include "llvm/TargetParser/AMDGPUTargetParser.def" + default: + return FEATURE_NONE; + } +} + +void AMDGPU::fillValidArchListAMDGCN(SmallVectorImpl &Values) { + // XXX: Should this only report unique canonical names? + Values.append({ +#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) NAME, +#define AMDGCN_GPU_ALIAS(NAME, ENUM) NAME, +#include "llvm/TargetParser/AMDGPUTargetParser.def" + }); +} + +void AMDGPU::fillValidArchListR600(SmallVectorImpl &Values) { + Values.append({ +#define R600_GPU(NAME, ENUM, FEATURES) NAME, +#define R600_GPU_ALIAS(NAME, ENUM) NAME, +#include "llvm/TargetParser/AMDGPUTargetParser.def" + }); +} + +AMDGPU::IsaVersion AMDGPU::getIsaVersion(StringRef GPU) { + AMDGPU::GPUKind AK = parseArchAMDGCN(GPU); + if (AK == AMDGPU::GPUKind::GK_NONE) { + if (GPU == "generic-hsa") + return {7, 0, 0}; + if (GPU == "generic") + return {6, 0, 0}; + return {0, 0, 0}; + } + + switch (AK) { +#define MAKE_ISAVERSION(A, B, C) {A, B, C} +#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) \ + case ENUM: \ + return MAKE_ISAVERSION ISAVERSION; +#include "llvm/TargetParser/AMDGPUTargetParser.def" +#undef MAKE_ISAVERSION + default: + return {0, 0, 0}; + } +} + +StringRef AMDGPU::getCanonicalArchName(const Triple &T, StringRef Arch) { + assert(T.isAMDGPU()); + auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(Arch) : parseArchR600(Arch); + if (ProcKind == GK_NONE) + return StringRef(); + + return T.isAMDGCN() ? getArchNameAMDGCN(ProcKind) : getArchNameR600(ProcKind); +} + +static std::pair +insertWaveSizeFeature(StringRef GPU, const Triple &T, + const StringMap &DefaultFeatures, + StringMap &Features) { + const bool IsNullGPU = GPU.empty(); + const bool TargetHasWave32 = DefaultFeatures.count("wavefrontsize32"); + const bool TargetHasWave64 = DefaultFeatures.count("wavefrontsize64"); + + auto Wave32Itr = Features.find("wavefrontsize32"); + auto Wave64Itr = Features.find("wavefrontsize64"); + const bool EnableWave32 = + Wave32Itr != Features.end() && Wave32Itr->getValue(); + const bool EnableWave64 = + Wave64Itr != Features.end() && Wave64Itr->getValue(); + const bool DisableWave32 = + Wave32Itr != Features.end() && !Wave32Itr->getValue(); + const bool DisableWave64 = + Wave64Itr != Features.end() && !Wave64Itr->getValue(); + + if (EnableWave32 && EnableWave64) + return {AMDGPU::INVALID_FEATURE_COMBINATION, + "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"}; + if (DisableWave32 && DisableWave64) + return {AMDGPU::INVALID_FEATURE_COMBINATION, + "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"}; + + if (!IsNullGPU) { + if (TargetHasWave64) { + if (EnableWave32) + return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize32"}; + if (DisableWave64) + return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize64"}; + } + + if (TargetHasWave32) { + if (EnableWave64) + return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize64"}; + if (DisableWave32) + return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize32"}; + } + } + + // Don't assume any wavesize with an unknown subtarget. + // Default to wave32 if target supports both. + if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 && + !TargetHasWave64) + Features.insert(std::make_pair("wavefrontsize32", true)); + + for (const auto &Entry : DefaultFeatures) { + if (!Features.count(Entry.getKey())) + Features[Entry.getKey()] = Entry.getValue(); + } + + return {NO_ERROR, StringRef()}; +} + +/// Fills Features map with default values for given target GPU. +/// \p Features contains overriding target features and this function returns +/// default target features with entries overridden by \p Features. +static void fillAMDGCNFeatureMap(StringRef GPU, const Triple &T, + StringMap &Features) { + AMDGPU::GPUKind Kind = parseArchAMDGCN(GPU); + switch (Kind) { + case GK_GFX1251: + case GK_GFX1250: + Features["swmmac-gfx1200-insts"] = true; + Features["swmmac-gfx1250-insts"] = true; + [[fallthrough]]; + case GK_GFX1310: + Features["cube-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + Features["lerp-inst"] = true; + Features["qsad-insts"] = true; + Features["sad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + [[fallthrough]]; + case GK_GFX12_5_GENERIC: + Features["ci-insts"] = true; + Features["dot7-insts"] = true; + Features["dot8-insts"] = true; + Features["dl-insts"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["gfx8-insts"] = true; + Features["gfx9-insts"] = true; + Features["gfx10-insts"] = true; + Features["gfx10-3-insts"] = true; + Features["gfx11-insts"] = true; + Features["gfx12-insts"] = true; + Features["gfx1250-insts"] = true; + Features["bitop3-insts"] = true; + Features["prng-inst"] = true; + Features["tanh-insts"] = true; + Features["tensor-cvt-lut-insts"] = true; + Features["transpose-load-f4f6-insts"] = true; + Features["bf16-trans-insts"] = true; + Features["bf16-cvt-insts"] = true; + Features["bf16-pk-insts"] = true; + Features["fp8-conversion-insts"] = true; + Features["fp8e5m3-insts"] = true; + Features["permlane16-swap"] = true; + Features["ashr-pk-insts"] = true; + Features["add-min-max-insts"] = true; + Features["pk-add-min-max-insts"] = true; + Features["atomic-buffer-pk-add-bf16-inst"] = true; + Features["vmem-pref-insts"] = true; + Features["atomic-fadd-rtn-insts"] = true; + Features["atomic-buffer-global-pk-add-f16-insts"] = true; + Features["atomic-flat-pk-add-16-insts"] = true; + Features["atomic-global-pk-add-bf16-inst"] = true; + Features["atomic-ds-pk-add-16-insts"] = true; + Features["setprio-inc-wg-inst"] = true; + Features["s-wakeup-barrier-inst"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + Features["atomic-fmin-fmax-global-f64"] = true; + Features["wavefrontsize32"] = true; + Features["clusters"] = true; + Features["mcast-load-insts"] = true; + break; + case GK_GFX1201: + case GK_GFX1200: + case GK_GFX12_GENERIC: + Features["ci-insts"] = true; + Features["dot7-insts"] = true; + Features["dot8-insts"] = true; + Features["dot9-insts"] = true; + Features["dot10-insts"] = true; + Features["dot11-insts"] = true; + Features["dot12-insts"] = true; + Features["dl-insts"] = true; + Features["atomic-ds-pk-add-16-insts"] = true; + Features["atomic-flat-pk-add-16-insts"] = true; + Features["atomic-buffer-global-pk-add-f16-insts"] = true; + Features["atomic-buffer-pk-add-bf16-inst"] = true; + Features["atomic-global-pk-add-bf16-inst"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["gfx8-insts"] = true; + Features["gfx9-insts"] = true; + Features["gfx10-insts"] = true; + Features["gfx10-3-insts"] = true; + Features["gfx11-insts"] = true; + Features["gfx12-insts"] = true; + Features["atomic-fadd-rtn-insts"] = true; + Features["image-insts"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + Features["fp8-conversion-insts"] = true; + Features["wmma-128b-insts"] = true; + Features["swmmac-gfx1200-insts"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + break; + case GK_GFX1170: + case GK_GFX1171: + case GK_GFX1172: + Features["ci-insts"] = true; + Features["dot7-insts"] = true; + Features["dot8-insts"] = true; + Features["dot9-insts"] = true; + Features["dot10-insts"] = true; + Features["dot12-insts"] = true; + Features["dl-insts"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["gfx8-insts"] = true; + Features["gfx9-insts"] = true; + Features["gfx10-insts"] = true; + Features["gfx10-3-insts"] = true; + Features["gfx11-insts"] = true; + Features["atomic-fadd-rtn-insts"] = true; + Features["image-insts"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + Features["gws"] = true; + Features["dot11-insts"] = true; + Features["fp8-conversion-insts"] = true; + Features["wmma-128b-insts"] = true; + Features["swmmac-gfx1200-insts"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + break; + case GK_GFX1153: + case GK_GFX1152: + case GK_GFX1151: + case GK_GFX1150: + case GK_GFX1103: + case GK_GFX1102: + case GK_GFX1101: + case GK_GFX1100: + case GK_GFX11_GENERIC: + Features["ci-insts"] = true; + Features["dot5-insts"] = true; + Features["dot7-insts"] = true; + Features["dot8-insts"] = true; + Features["dot9-insts"] = true; + Features["dot10-insts"] = true; + Features["dot12-insts"] = true; + Features["dl-insts"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["gfx8-insts"] = true; + Features["gfx9-insts"] = true; + Features["gfx10-insts"] = true; + Features["gfx10-3-insts"] = true; + Features["gfx11-insts"] = true; + Features["atomic-fadd-rtn-insts"] = true; + Features["image-insts"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + Features["gws"] = true; + Features["wmma-256b-insts"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + break; + case GK_GFX1036: + case GK_GFX1035: + case GK_GFX1034: + case GK_GFX1033: + case GK_GFX1032: + case GK_GFX1031: + case GK_GFX1030: + case GK_GFX10_3_GENERIC: + Features["ci-insts"] = true; + Features["dot1-insts"] = true; + Features["dot2-insts"] = true; + Features["dot5-insts"] = true; + Features["dot6-insts"] = true; + Features["dot7-insts"] = true; + Features["dot10-insts"] = true; + Features["dl-insts"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["gfx8-insts"] = true; + Features["gfx9-insts"] = true; + Features["gfx10-insts"] = true; + Features["gfx10-3-insts"] = true; + Features["image-insts"] = true; + Features["s-memrealtime"] = true; + Features["s-memtime-inst"] = true; + Features["gws"] = true; + Features["vmem-to-lds-load-insts"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + Features["atomic-fmin-fmax-global-f64"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + break; + case GK_GFX1012: + case GK_GFX1011: + Features["dot1-insts"] = true; + Features["dot2-insts"] = true; + Features["dot5-insts"] = true; + Features["dot6-insts"] = true; + Features["dot7-insts"] = true; + Features["dot10-insts"] = true; + [[fallthrough]]; + case GK_GFX1013: + case GK_GFX1010: + case GK_GFX10_1_GENERIC: + Features["dl-insts"] = true; + Features["ci-insts"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["gfx8-insts"] = true; + Features["gfx9-insts"] = true; + Features["gfx10-insts"] = true; + Features["image-insts"] = true; + Features["s-memrealtime"] = true; + Features["s-memtime-inst"] = true; + Features["gws"] = true; + Features["vmem-to-lds-load-insts"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + Features["atomic-fmin-fmax-global-f64"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + break; + case GK_GFX950: + Features["bitop3-insts"] = true; + Features["fp6bf6-cvt-scale-insts"] = true; + Features["fp4-cvt-scale-insts"] = true; + Features["bf8-cvt-scale-insts"] = true; + Features["fp8-cvt-scale-insts"] = true; + Features["f16bf16-to-fp6bf6-cvt-scale-insts"] = true; + Features["f32-to-f16bf16-cvt-sr-insts"] = true; + Features["prng-inst"] = true; + Features["permlane16-swap"] = true; + Features["permlane32-swap"] = true; + Features["ashr-pk-insts"] = true; + Features["dot12-insts"] = true; + Features["dot13-insts"] = true; + Features["atomic-buffer-pk-add-bf16-inst"] = true; + Features["gfx950-insts"] = true; + [[fallthrough]]; + case GK_GFX942: + Features["fp8-insts"] = true; + Features["fp8-conversion-insts"] = true; + if (Kind != GK_GFX950) + Features["xf32-insts"] = true; + [[fallthrough]]; + case GK_GFX9_4_GENERIC: + Features["gfx940-insts"] = true; + Features["atomic-ds-pk-add-16-insts"] = true; + Features["atomic-flat-pk-add-16-insts"] = true; + Features["atomic-global-pk-add-bf16-inst"] = true; + Features["gfx90a-insts"] = true; + Features["atomic-buffer-global-pk-add-f16-insts"] = true; + Features["atomic-fadd-rtn-insts"] = true; + Features["dot3-insts"] = true; + Features["dot4-insts"] = true; + Features["dot5-insts"] = true; + Features["dot6-insts"] = true; + Features["mai-insts"] = true; + Features["dl-insts"] = true; + Features["dot1-insts"] = true; + Features["dot2-insts"] = true; + Features["dot7-insts"] = true; + Features["dot10-insts"] = true; + Features["gfx9-insts"] = true; + Features["gfx8-insts"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["s-memrealtime"] = true; + Features["ci-insts"] = true; + Features["s-memtime-inst"] = true; + Features["gws"] = true; + Features["vmem-to-lds-load-insts"] = true; + Features["atomic-fmin-fmax-global-f64"] = true; + Features["wavefrontsize64"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + break; + case GK_GFX90A: + Features["gfx90a-insts"] = true; + Features["atomic-buffer-global-pk-add-f16-insts"] = true; + Features["atomic-fadd-rtn-insts"] = true; + Features["atomic-fmin-fmax-global-f64"] = true; + [[fallthrough]]; + case GK_GFX908: + Features["dot3-insts"] = true; + Features["dot4-insts"] = true; + Features["dot5-insts"] = true; + Features["dot6-insts"] = true; + Features["mai-insts"] = true; + [[fallthrough]]; + case GK_GFX906: + Features["dl-insts"] = true; + Features["dot1-insts"] = true; + Features["dot2-insts"] = true; + Features["dot7-insts"] = true; + Features["dot10-insts"] = true; + [[fallthrough]]; + case GK_GFX90C: + case GK_GFX909: + case GK_GFX904: + case GK_GFX902: + case GK_GFX900: + case GK_GFX9_GENERIC: + Features["gfx9-insts"] = true; + Features["vmem-to-lds-load-insts"] = true; + [[fallthrough]]; + case GK_GFX810: + case GK_GFX805: + case GK_GFX803: + case GK_GFX802: + case GK_GFX801: + Features["gfx8-insts"] = true; + Features["16-bit-insts"] = true; + Features["dpp"] = true; + Features["s-memrealtime"] = true; + Features["ci-insts"] = true; + Features["image-insts"] = true; + Features["s-memtime-inst"] = true; + Features["gws"] = true; + Features["wavefrontsize64"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + break; + case GK_GFX705: + case GK_GFX704: + case GK_GFX703: + case GK_GFX702: + case GK_GFX701: + case GK_GFX700: + Features["ci-insts"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["qsad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["mqsad-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + Features["image-insts"] = true; + Features["s-memtime-inst"] = true; + Features["gws"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + Features["atomic-fmin-fmax-global-f64"] = true; + Features["wavefrontsize64"] = true; + break; + case GK_GFX602: + case GK_GFX601: + case GK_GFX600: + Features["image-insts"] = true; + Features["s-memtime-inst"] = true; + Features["gws"] = true; + Features["atomic-fmin-fmax-global-f32"] = true; + Features["atomic-fmin-fmax-global-f64"] = true; + Features["wavefrontsize64"] = true; + Features["cube-insts"] = true; + Features["lerp-inst"] = true; + Features["sad-insts"] = true; + Features["msad-insts"] = true; + Features["mqsad-pk-insts"] = true; + Features["cvt-pknorm-vop2-insts"] = true; + break; + case GK_NONE: + break; + default: + llvm_unreachable("Unhandled GPU!"); + } +} + +/// Fills Features map with default values for given target GPU. +/// \p Features contains overriding target features and this function returns +/// default target features with entries overridden by \p Features. +std::pair +AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, + StringMap &Features) { + // XXX - What does the member GPU mean if device name string passed here? + if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) { + // AMDGCN SPIRV must support the union of all AMDGCN features. + SmallVector GPUs; + fillValidArchListAMDGCN(GPUs); + + static const Triple AMDGCN("amdgcn-amd-amdhsa"); + StringMap Tmp; + for (auto &&GPU : GPUs) { + fillAMDGCNFeatureMap(GPU, AMDGCN, Tmp); + for (auto &&[F, B] : Tmp) + Features[F] = B; + } + Features["wavefrontsize32"] = true; + Features["wavefrontsize64"] = true; + } else if (T.isAMDGCN()) { + StringMap DefaultFeatures; + fillAMDGCNFeatureMap(GPU, T, DefaultFeatures); + return insertWaveSizeFeature(GPU, T, DefaultFeatures, Features); + } else { + if (GPU.empty()) + GPU = "r600"; + + switch (llvm::AMDGPU::parseArchR600(GPU)) { + case GK_CAYMAN: + case GK_CYPRESS: + case GK_RV770: + case GK_RV670: + // TODO: Add fp64 when implemented. + break; + case GK_TURKS: + case GK_CAICOS: + case GK_BARTS: + case GK_SUMO: + case GK_REDWOOD: + case GK_JUNIPER: + case GK_CEDAR: + case GK_RV730: + case GK_RV710: + case GK_RS880: + case GK_R630: + case GK_R600: + break; + default: + llvm_unreachable("Unhandled GPU!"); + } + } + return {NO_ERROR, StringRef()}; +} diff --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt index 8d474497f5308..89f54ab6ab7a0 100644 --- a/llvm/lib/TargetParser/CMakeLists.txt +++ b/llvm/lib/TargetParser/CMakeLists.txt @@ -15,6 +15,7 @@ endif() add_llvm_component_library(LLVMTargetParser AArch64TargetParser.cpp + AMDGPUTargetParser.cpp ARMTargetParserCommon.cpp ARMTargetParser.cpp AVRTargetParser.cpp diff --git a/llvm/lib/TargetParser/TargetParser.cpp b/llvm/lib/TargetParser/TargetParser.cpp index 3c2958d46521a..52c5e6d800194 100644 --- a/llvm/lib/TargetParser/TargetParser.cpp +++ b/llvm/lib/TargetParser/TargetParser.cpp @@ -13,17 +13,14 @@ #include "llvm/TargetParser/TargetParser.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/TargetParser/Triple.h" using namespace llvm; -using namespace AMDGPU; /// Find KV in array using binary search. static const BasicSubtargetSubTypeKV * find(StringRef S, ArrayRef A) { // Binary search the array - auto F = llvm::lower_bound(A, S); + const BasicSubtargetSubTypeKV *F = llvm::lower_bound(A, S); // If not found then return NULL if (F == A.end() || StringRef(F->Key) != S) return nullptr; @@ -65,642 +62,3 @@ std::optional> llvm::getCPUDefaultTargetFeatures( } return DefaultFeatures; } - -StringRef llvm::AMDGPU::getArchFamilyNameAMDGCN(GPUKind AK) { - StringRef ArchName = getArchNameAMDGCN(AK); - assert((AK >= GK_AMDGCN_GENERIC_FIRST && AK <= GK_AMDGCN_GENERIC_LAST) == - ArchName.ends_with("-generic") && - "Generic AMDGCN arch not classified correctly!"); - if (AK >= GK_AMDGCN_GENERIC_FIRST && AK <= GK_AMDGCN_GENERIC_LAST) { - // Return the part before the first '-', e.g. "gfx9-4-generic" -> "gfx9". - return ArchName.take_front(ArchName.find('-')); - } - return ArchName.empty() ? "" : ArchName.drop_back(2); -} - -StringRef llvm::AMDGPU::getArchNameAMDGCN(GPUKind AK) { - switch (AK) { -#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) \ - case ENUM: \ - return NAME; -#include "llvm/TargetParser/AMDGPUTargetParser.def" - default: - return ""; - } -} - -StringRef llvm::AMDGPU::getArchNameR600(GPUKind AK) { - switch (AK) { -#define R600_GPU(NAME, ENUM, FEATURES) \ - case ENUM: \ - return NAME; -#include "llvm/TargetParser/AMDGPUTargetParser.def" - default: - return ""; - } -} - -AMDGPU::GPUKind llvm::AMDGPU::parseArchAMDGCN(StringRef CPU) { - return StringSwitch(CPU) -#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) .Case(NAME, ENUM) -#define AMDGCN_GPU_ALIAS(NAME, ENUM) .Case(NAME, ENUM) -#include "llvm/TargetParser/AMDGPUTargetParser.def" - .Default(AMDGPU::GPUKind::GK_NONE); -} - -AMDGPU::GPUKind llvm::AMDGPU::parseArchR600(StringRef CPU) { - return StringSwitch(CPU) -#define R600_GPU(NAME, ENUM, FEATURES) .Case(NAME, ENUM) -#define R600_GPU_ALIAS(NAME, ENUM) .Case(NAME, ENUM) -#include "llvm/TargetParser/AMDGPUTargetParser.def" - .Default(AMDGPU::GPUKind::GK_NONE); -} - -unsigned AMDGPU::getArchAttrAMDGCN(GPUKind AK) { - switch (AK) { -#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) \ - case ENUM: \ - return FEATURES; -#include "llvm/TargetParser/AMDGPUTargetParser.def" - default: - return FEATURE_NONE; - } -} - -unsigned AMDGPU::getArchAttrR600(GPUKind AK) { - switch (AK) { -#define R600_GPU(NAME, ENUM, FEATURES) \ - case ENUM: \ - return FEATURES; -#include "llvm/TargetParser/AMDGPUTargetParser.def" - default: - return FEATURE_NONE; - } -} - -void AMDGPU::fillValidArchListAMDGCN(SmallVectorImpl &Values) { - // XXX: Should this only report unique canonical names? - Values.append({ -#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) NAME, -#define AMDGCN_GPU_ALIAS(NAME, ENUM) NAME, -#include "llvm/TargetParser/AMDGPUTargetParser.def" - }); -} - -void AMDGPU::fillValidArchListR600(SmallVectorImpl &Values) { - Values.append({ -#define R600_GPU(NAME, ENUM, FEATURES) NAME, -#define R600_GPU_ALIAS(NAME, ENUM) NAME, -#include "llvm/TargetParser/AMDGPUTargetParser.def" - }); -} - -AMDGPU::IsaVersion AMDGPU::getIsaVersion(StringRef GPU) { - AMDGPU::GPUKind AK = parseArchAMDGCN(GPU); - if (AK == AMDGPU::GPUKind::GK_NONE) { - if (GPU == "generic-hsa") - return {7, 0, 0}; - if (GPU == "generic") - return {6, 0, 0}; - return {0, 0, 0}; - } - - switch (AK) { -#define MAKE_ISAVERSION(A, B, C) {A, B, C} -#define AMDGCN_GPU(NAME, ENUM, ISAVERSION, FEATURES) \ - case ENUM: \ - return MAKE_ISAVERSION ISAVERSION; -#include "llvm/TargetParser/AMDGPUTargetParser.def" -#undef MAKE_ISAVERSION - default: - return {0, 0, 0}; - } -} - -StringRef AMDGPU::getCanonicalArchName(const Triple &T, StringRef Arch) { - assert(T.isAMDGPU()); - auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(Arch) : parseArchR600(Arch); - if (ProcKind == GK_NONE) - return StringRef(); - - return T.isAMDGCN() ? getArchNameAMDGCN(ProcKind) : getArchNameR600(ProcKind); -} - -static std::pair -insertWaveSizeFeature(StringRef GPU, const Triple &T, - const StringMap &DefaultFeatures, - StringMap &Features) { - const bool IsNullGPU = GPU.empty(); - const bool TargetHasWave32 = DefaultFeatures.count("wavefrontsize32"); - const bool TargetHasWave64 = DefaultFeatures.count("wavefrontsize64"); - - auto Wave32Itr = Features.find("wavefrontsize32"); - auto Wave64Itr = Features.find("wavefrontsize64"); - const bool EnableWave32 = - Wave32Itr != Features.end() && Wave32Itr->getValue(); - const bool EnableWave64 = - Wave64Itr != Features.end() && Wave64Itr->getValue(); - const bool DisableWave32 = - Wave32Itr != Features.end() && !Wave32Itr->getValue(); - const bool DisableWave64 = - Wave64Itr != Features.end() && !Wave64Itr->getValue(); - - if (EnableWave32 && EnableWave64) - return {AMDGPU::INVALID_FEATURE_COMBINATION, - "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"}; - if (DisableWave32 && DisableWave64) - return {AMDGPU::INVALID_FEATURE_COMBINATION, - "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"}; - - if (!IsNullGPU) { - if (TargetHasWave64) { - if (EnableWave32) - return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize32"}; - if (DisableWave64) - return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize64"}; - } - - if (TargetHasWave32) { - if (EnableWave64) - return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize64"}; - if (DisableWave32) - return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize32"}; - } - } - - // Don't assume any wavesize with an unknown subtarget. - // Default to wave32 if target supports both. - if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 && - !TargetHasWave64) - Features.insert(std::make_pair("wavefrontsize32", true)); - - for (const auto &Entry : DefaultFeatures) { - if (!Features.count(Entry.getKey())) - Features[Entry.getKey()] = Entry.getValue(); - } - - return {NO_ERROR, StringRef()}; -} - -/// Fills Features map with default values for given target GPU. -/// \p Features contains overriding target features and this function returns -/// default target features with entries overridden by \p Features. -static void fillAMDGCNFeatureMap(StringRef GPU, const Triple &T, - StringMap &Features) { - AMDGPU::GPUKind Kind = parseArchAMDGCN(GPU); - switch (Kind) { - case GK_GFX1251: - case GK_GFX1250: - Features["swmmac-gfx1200-insts"] = true; - Features["swmmac-gfx1250-insts"] = true; - [[fallthrough]]; - case GK_GFX1310: - Features["cube-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - Features["lerp-inst"] = true; - Features["qsad-insts"] = true; - Features["sad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - [[fallthrough]]; - case GK_GFX12_5_GENERIC: - Features["ci-insts"] = true; - Features["dot7-insts"] = true; - Features["dot8-insts"] = true; - Features["dl-insts"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["gfx8-insts"] = true; - Features["gfx9-insts"] = true; - Features["gfx10-insts"] = true; - Features["gfx10-3-insts"] = true; - Features["gfx11-insts"] = true; - Features["gfx12-insts"] = true; - Features["gfx1250-insts"] = true; - Features["bitop3-insts"] = true; - Features["prng-inst"] = true; - Features["tanh-insts"] = true; - Features["tensor-cvt-lut-insts"] = true; - Features["transpose-load-f4f6-insts"] = true; - Features["bf16-trans-insts"] = true; - Features["bf16-cvt-insts"] = true; - Features["bf16-pk-insts"] = true; - Features["fp8-conversion-insts"] = true; - Features["fp8e5m3-insts"] = true; - Features["permlane16-swap"] = true; - Features["ashr-pk-insts"] = true; - Features["add-min-max-insts"] = true; - Features["pk-add-min-max-insts"] = true; - Features["atomic-buffer-pk-add-bf16-inst"] = true; - Features["vmem-pref-insts"] = true; - Features["atomic-fadd-rtn-insts"] = true; - Features["atomic-buffer-global-pk-add-f16-insts"] = true; - Features["atomic-flat-pk-add-16-insts"] = true; - Features["atomic-global-pk-add-bf16-inst"] = true; - Features["atomic-ds-pk-add-16-insts"] = true; - Features["setprio-inc-wg-inst"] = true; - Features["s-wakeup-barrier-inst"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - Features["atomic-fmin-fmax-global-f64"] = true; - Features["wavefrontsize32"] = true; - Features["clusters"] = true; - Features["mcast-load-insts"] = true; - break; - case GK_GFX1201: - case GK_GFX1200: - case GK_GFX12_GENERIC: - Features["ci-insts"] = true; - Features["dot7-insts"] = true; - Features["dot8-insts"] = true; - Features["dot9-insts"] = true; - Features["dot10-insts"] = true; - Features["dot11-insts"] = true; - Features["dot12-insts"] = true; - Features["dl-insts"] = true; - Features["atomic-ds-pk-add-16-insts"] = true; - Features["atomic-flat-pk-add-16-insts"] = true; - Features["atomic-buffer-global-pk-add-f16-insts"] = true; - Features["atomic-buffer-pk-add-bf16-inst"] = true; - Features["atomic-global-pk-add-bf16-inst"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["gfx8-insts"] = true; - Features["gfx9-insts"] = true; - Features["gfx10-insts"] = true; - Features["gfx10-3-insts"] = true; - Features["gfx11-insts"] = true; - Features["gfx12-insts"] = true; - Features["atomic-fadd-rtn-insts"] = true; - Features["image-insts"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - Features["fp8-conversion-insts"] = true; - Features["wmma-128b-insts"] = true; - Features["swmmac-gfx1200-insts"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - break; - case GK_GFX1170: - case GK_GFX1171: - case GK_GFX1172: - Features["ci-insts"] = true; - Features["dot7-insts"] = true; - Features["dot8-insts"] = true; - Features["dot9-insts"] = true; - Features["dot10-insts"] = true; - Features["dot12-insts"] = true; - Features["dl-insts"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["gfx8-insts"] = true; - Features["gfx9-insts"] = true; - Features["gfx10-insts"] = true; - Features["gfx10-3-insts"] = true; - Features["gfx11-insts"] = true; - Features["atomic-fadd-rtn-insts"] = true; - Features["image-insts"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - Features["gws"] = true; - Features["dot11-insts"] = true; - Features["fp8-conversion-insts"] = true; - Features["wmma-128b-insts"] = true; - Features["swmmac-gfx1200-insts"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - break; - case GK_GFX1153: - case GK_GFX1152: - case GK_GFX1151: - case GK_GFX1150: - case GK_GFX1103: - case GK_GFX1102: - case GK_GFX1101: - case GK_GFX1100: - case GK_GFX11_GENERIC: - Features["ci-insts"] = true; - Features["dot5-insts"] = true; - Features["dot7-insts"] = true; - Features["dot8-insts"] = true; - Features["dot9-insts"] = true; - Features["dot10-insts"] = true; - Features["dot12-insts"] = true; - Features["dl-insts"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["gfx8-insts"] = true; - Features["gfx9-insts"] = true; - Features["gfx10-insts"] = true; - Features["gfx10-3-insts"] = true; - Features["gfx11-insts"] = true; - Features["atomic-fadd-rtn-insts"] = true; - Features["image-insts"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - Features["gws"] = true; - Features["wmma-256b-insts"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - break; - case GK_GFX1036: - case GK_GFX1035: - case GK_GFX1034: - case GK_GFX1033: - case GK_GFX1032: - case GK_GFX1031: - case GK_GFX1030: - case GK_GFX10_3_GENERIC: - Features["ci-insts"] = true; - Features["dot1-insts"] = true; - Features["dot2-insts"] = true; - Features["dot5-insts"] = true; - Features["dot6-insts"] = true; - Features["dot7-insts"] = true; - Features["dot10-insts"] = true; - Features["dl-insts"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["gfx8-insts"] = true; - Features["gfx9-insts"] = true; - Features["gfx10-insts"] = true; - Features["gfx10-3-insts"] = true; - Features["image-insts"] = true; - Features["s-memrealtime"] = true; - Features["s-memtime-inst"] = true; - Features["gws"] = true; - Features["vmem-to-lds-load-insts"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - Features["atomic-fmin-fmax-global-f64"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - break; - case GK_GFX1012: - case GK_GFX1011: - Features["dot1-insts"] = true; - Features["dot2-insts"] = true; - Features["dot5-insts"] = true; - Features["dot6-insts"] = true; - Features["dot7-insts"] = true; - Features["dot10-insts"] = true; - [[fallthrough]]; - case GK_GFX1013: - case GK_GFX1010: - case GK_GFX10_1_GENERIC: - Features["dl-insts"] = true; - Features["ci-insts"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["gfx8-insts"] = true; - Features["gfx9-insts"] = true; - Features["gfx10-insts"] = true; - Features["image-insts"] = true; - Features["s-memrealtime"] = true; - Features["s-memtime-inst"] = true; - Features["gws"] = true; - Features["vmem-to-lds-load-insts"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - Features["atomic-fmin-fmax-global-f64"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - break; - case GK_GFX950: - Features["bitop3-insts"] = true; - Features["fp6bf6-cvt-scale-insts"] = true; - Features["fp4-cvt-scale-insts"] = true; - Features["bf8-cvt-scale-insts"] = true; - Features["fp8-cvt-scale-insts"] = true; - Features["f16bf16-to-fp6bf6-cvt-scale-insts"] = true; - Features["f32-to-f16bf16-cvt-sr-insts"] = true; - Features["prng-inst"] = true; - Features["permlane16-swap"] = true; - Features["permlane32-swap"] = true; - Features["ashr-pk-insts"] = true; - Features["dot12-insts"] = true; - Features["dot13-insts"] = true; - Features["atomic-buffer-pk-add-bf16-inst"] = true; - Features["gfx950-insts"] = true; - [[fallthrough]]; - case GK_GFX942: - Features["fp8-insts"] = true; - Features["fp8-conversion-insts"] = true; - if (Kind != GK_GFX950) - Features["xf32-insts"] = true; - [[fallthrough]]; - case GK_GFX9_4_GENERIC: - Features["gfx940-insts"] = true; - Features["atomic-ds-pk-add-16-insts"] = true; - Features["atomic-flat-pk-add-16-insts"] = true; - Features["atomic-global-pk-add-bf16-inst"] = true; - Features["gfx90a-insts"] = true; - Features["atomic-buffer-global-pk-add-f16-insts"] = true; - Features["atomic-fadd-rtn-insts"] = true; - Features["dot3-insts"] = true; - Features["dot4-insts"] = true; - Features["dot5-insts"] = true; - Features["dot6-insts"] = true; - Features["mai-insts"] = true; - Features["dl-insts"] = true; - Features["dot1-insts"] = true; - Features["dot2-insts"] = true; - Features["dot7-insts"] = true; - Features["dot10-insts"] = true; - Features["gfx9-insts"] = true; - Features["gfx8-insts"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["s-memrealtime"] = true; - Features["ci-insts"] = true; - Features["s-memtime-inst"] = true; - Features["gws"] = true; - Features["vmem-to-lds-load-insts"] = true; - Features["atomic-fmin-fmax-global-f64"] = true; - Features["wavefrontsize64"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - break; - case GK_GFX90A: - Features["gfx90a-insts"] = true; - Features["atomic-buffer-global-pk-add-f16-insts"] = true; - Features["atomic-fadd-rtn-insts"] = true; - Features["atomic-fmin-fmax-global-f64"] = true; - [[fallthrough]]; - case GK_GFX908: - Features["dot3-insts"] = true; - Features["dot4-insts"] = true; - Features["dot5-insts"] = true; - Features["dot6-insts"] = true; - Features["mai-insts"] = true; - [[fallthrough]]; - case GK_GFX906: - Features["dl-insts"] = true; - Features["dot1-insts"] = true; - Features["dot2-insts"] = true; - Features["dot7-insts"] = true; - Features["dot10-insts"] = true; - [[fallthrough]]; - case GK_GFX90C: - case GK_GFX909: - case GK_GFX904: - case GK_GFX902: - case GK_GFX900: - case GK_GFX9_GENERIC: - Features["gfx9-insts"] = true; - Features["vmem-to-lds-load-insts"] = true; - [[fallthrough]]; - case GK_GFX810: - case GK_GFX805: - case GK_GFX803: - case GK_GFX802: - case GK_GFX801: - Features["gfx8-insts"] = true; - Features["16-bit-insts"] = true; - Features["dpp"] = true; - Features["s-memrealtime"] = true; - Features["ci-insts"] = true; - Features["image-insts"] = true; - Features["s-memtime-inst"] = true; - Features["gws"] = true; - Features["wavefrontsize64"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - break; - case GK_GFX705: - case GK_GFX704: - case GK_GFX703: - case GK_GFX702: - case GK_GFX701: - case GK_GFX700: - Features["ci-insts"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["qsad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["mqsad-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - Features["image-insts"] = true; - Features["s-memtime-inst"] = true; - Features["gws"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - Features["atomic-fmin-fmax-global-f64"] = true; - Features["wavefrontsize64"] = true; - break; - case GK_GFX602: - case GK_GFX601: - case GK_GFX600: - Features["image-insts"] = true; - Features["s-memtime-inst"] = true; - Features["gws"] = true; - Features["atomic-fmin-fmax-global-f32"] = true; - Features["atomic-fmin-fmax-global-f64"] = true; - Features["wavefrontsize64"] = true; - Features["cube-insts"] = true; - Features["lerp-inst"] = true; - Features["sad-insts"] = true; - Features["msad-insts"] = true; - Features["mqsad-pk-insts"] = true; - Features["cvt-pknorm-vop2-insts"] = true; - break; - case GK_NONE: - break; - default: - llvm_unreachable("Unhandled GPU!"); - } -} - -/// Fills Features map with default values for given target GPU. -/// \p Features contains overriding target features and this function returns -/// default target features with entries overridden by \p Features. -std::pair -AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, - StringMap &Features) { - // XXX - What does the member GPU mean if device name string passed here? - if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) { - // AMDGCN SPIRV must support the union of all AMDGCN features. - SmallVector GPUs; - fillValidArchListAMDGCN(GPUs); - - static const Triple AMDGCN("amdgcn-amd-amdhsa"); - StringMap Tmp; - for (auto &&GPU : GPUs) { - fillAMDGCNFeatureMap(GPU, AMDGCN, Tmp); - for (auto &&[F, B] : Tmp) - Features[F] = B; - } - Features["wavefrontsize32"] = true; - Features["wavefrontsize64"] = true; - } else if (T.isAMDGCN()) { - StringMap DefaultFeatures; - fillAMDGCNFeatureMap(GPU, T, DefaultFeatures); - return insertWaveSizeFeature(GPU, T, DefaultFeatures, Features); - } else { - if (GPU.empty()) - GPU = "r600"; - - switch (llvm::AMDGPU::parseArchR600(GPU)) { - case GK_CAYMAN: - case GK_CYPRESS: - case GK_RV770: - case GK_RV670: - // TODO: Add fp64 when implemented. - break; - case GK_TURKS: - case GK_CAICOS: - case GK_BARTS: - case GK_SUMO: - case GK_REDWOOD: - case GK_JUNIPER: - case GK_CEDAR: - case GK_RV730: - case GK_RV710: - case GK_RS880: - case GK_R630: - case GK_R600: - break; - default: - llvm_unreachable("Unhandled GPU!"); - } - } - return {NO_ERROR, StringRef()}; -} diff --git a/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp b/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp index 78cad1d9d65b6..103891bbedecd 100644 --- a/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp +++ b/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp @@ -12,7 +12,7 @@ #include "GCNSubtarget.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp index 917c0ed399b77..56bf2a030760e 100644 --- a/mlir/lib/Target/LLVM/ROCDL/Target.cpp +++ b/mlir/lib/Target/LLVM/ROCDL/Target.cpp @@ -39,7 +39,7 @@ #include "llvm/Support/Program.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/AMDGPUTargetParser.h" #include #include