11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/SmallSet.h"
13#include "llvm/ADT/SmallVector.h"
14#include "llvm/Support/Path.h"
15#include "llvm/TargetParser/AMDGPUTargetParser.h"
16#include "llvm/TargetParser/Triple.h"
25 llvm::StringRef Proc) {
30 llvm::AMDGPU::GPUKind ProcKind = llvm::AMDGPU::parseArchAMDGCN(Proc);
31 if (ProcKind == llvm::AMDGPU::GK_NONE)
33 const llvm::AMDGPU::AMDGPUFeatureBitset &Features =
34 llvm::AMDGPU::getFeatureBitset(ProcKind);
36 if (Features.test(llvm::AMDGPU::FEAT_SRAMECC_ON_OFF_MODES))
37 Ret.push_back(
"sramecc");
38 if (Features.test(llvm::AMDGPU::FEAT_XNACK_ON_OFF_MODES))
39 Ret.push_back(
"xnack");
45 llvm::StringRef Processor) {
54 llvm::StringRef Processor) {
58 if (llvm::StringRef Name = llvm::AMDGPU::getCanonicalArchName(
T, Processor);
72 llvm::StringRef TargetID) {
73 auto Split = TargetID.split(
':');
83static std::optional<llvm::StringRef>
85 llvm::StringMap<bool> *FeatureMap) {
86 llvm::StringRef Processor;
89 return llvm::StringRef();
91 auto Split = TargetID.split(
':');
92 Processor = Split.first;
93 if (Processor.empty())
96 auto Features = Split.second;
100 llvm::StringMap<bool> LocalFeatureMap;
102 FeatureMap = &LocalFeatureMap;
104 while (!Features.empty()) {
105 auto Splits = Features.split(
':');
106 if (Splits.first.empty())
108 auto Sign = Splits.first.back();
109 auto Feature = Splits.first.drop_back();
110 if (Sign !=
'+' && Sign !=
'-')
112 bool IsOn = Sign ==
'+';
114 if (!FeatureMap->try_emplace(
Feature, IsOn).second)
116 Features = Splits.second;
121std::optional<llvm::StringRef>
123 llvm::StringMap<bool> *FeatureMap) {
124 auto OptionalProcessor =
127 if (!OptionalProcessor)
131 if (Processor.empty())
134 llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
137 for (
auto &&F : *FeatureMap)
138 if (!AllFeatures.count(F.first()))
147 const llvm::StringMap<bool> &Features) {
148 std::string TargetID = Processor.str();
149 std::map<const llvm::StringRef, bool> OrderedMap;
150 for (
const auto &F : Features)
151 OrderedMap[F.first()] = F.second;
152 for (
const auto &F : OrderedMap)
153 TargetID = TargetID +
':' + F.first.str() + (F.second ?
"+" :
"-");
160std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
163 llvm::StringRef TargetID;
164 llvm::StringMap<bool> Features;
165 Info(llvm::StringRef TargetID,
const llvm::StringMap<bool> &Features)
166 : TargetID(TargetID), Features(Features) {}
168 llvm::StringMap<Info> FeatureMap;
169 for (
auto &&ID : TargetIDs) {
170 llvm::StringMap<bool> Features;
172 auto [Loc, Inserted] = FeatureMap.try_emplace(Proc, ID, Features);
174 auto &ExistingFeatures = Loc->second.Features;
175 if (llvm::any_of(Features, [&](
auto &F) {
176 return ExistingFeatures.count(F.first()) == 0;
178 return std::make_pair(Loc->second.TargetID, ID);
185 llvm::StringMap<bool> ProvidedFeatures, RequestedFeatures;
186 llvm::StringRef ProvidedProc =
188 llvm::StringRef RequestedProc =
190 if (ProvidedProc != RequestedProc)
192 for (
const auto &F : ProvidedFeatures) {
193 auto Loc = RequestedFeatures.find(F.first());
196 if (Loc == RequestedFeatures.end())
199 if (Loc->second != F.second)
206 std::string
FileName = TargetID.str();
207 if (llvm::sys::path::is_style_windows(llvm::sys::path::Style::native))
214 llvm::Triple
T(OrigT);
220 if (HasTargetID &&
T.isAMDGCN()) {
221 return (
"amdgcn-" +
T.getVendorName() +
"-" +
T.getOSName() +
"-" +
222 T.getEnvironmentName())
226 return HasTargetID ? (
T.getArchName() +
"-" +
T.getVendorName() +
"-" +
227 T.getOSName() +
"-" +
T.getEnvironmentName())
229 :
T.normalize(llvm::Triple::CanonicalForm::FOUR_IDENT);
A processor an offloading action can target.
Top level wrappers for InstallAPI frontend operations.
static llvm::SmallVector< llvm::StringRef, 4 > getAllPossibleAMDGPUTargetIDFeatures(const llvm::Triple &T, llvm::StringRef Proc)
std::optional< llvm::StringRef > parseTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch, llvm::StringMap< bool > *FeatureMap)
Parse a target ID to get processor and feature map.
OffloadArch getSubArchOffloadArch(llvm::Triple::SubArchType SubArch)
static std::optional< llvm::StringRef > parseTargetIDWithFormatCheckingOnly(llvm::StringRef TargetID, llvm::StringMap< bool > *FeatureMap)
std::string sanitizeTargetIDInFileName(llvm::StringRef TargetID)
Sanitize a target ID string for use in a file name.
llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch)
Get processor name from target ID.
std::optional< std::pair< llvm::StringRef, llvm::StringRef > > getConflictTargetIDCombination(const std::set< llvm::StringRef > &TargetIDs)
Get the conflicted pair of target IDs for a compilation or a bundled code object, assuming TargetIDs ...
static llvm::StringRef getCanonicalProcessorName(const llvm::Triple &T, llvm::StringRef Processor)
Returns canonical processor name or empty string if Processor is invalid.
std::string normalizeForBundler(const llvm::Triple &T, llvm::StringRef BoundArch)
Constructs the normalized triple string used inside an offload bundle entry ID for device triple T.
bool isCompatibleTargetID(llvm::StringRef Provided, llvm::StringRef Requested)
Check whether the provided target ID is compatible with the requested target ID.
const FunctionProtoType * T
llvm::SmallVector< llvm::StringRef, 4 > getAllPossibleTargetIDFeatures(const llvm::Triple &T, llvm::StringRef Processor)
Get all feature strings that can be used in target ID for Processor.
const char * OffloadArchToString(OffloadArch A)
std::string getCanonicalTargetID(llvm::StringRef Processor, const llvm::StringMap< bool > &Features)
Returns canonical target ID, assuming Processor is canonical and all entries in Features are valid.
Represents a bound architecture for offload / multiple architecture compilation.