10#include "llvm/ADT/STLExtras.h"
11#include "llvm/ADT/SmallSet.h"
12#include "llvm/ADT/SmallVector.h"
13#include "llvm/Support/Path.h"
14#include "llvm/TargetParser/AMDGPUTargetParser.h"
15#include "llvm/TargetParser/Triple.h"
24 llvm::StringRef Proc) {
29 llvm::AMDGPU::GPUKind ProcKind = llvm::AMDGPU::parseArchAMDGCN(Proc);
30 if (ProcKind == llvm::AMDGPU::GK_NONE)
32 const llvm::AMDGPU::AMDGPUFeatureBitset &Features =
33 llvm::AMDGPU::getFeatureBitset(ProcKind);
34 if (Features.test(llvm::AMDGPU::FEAT_SRAMECC_SUPPORT))
35 Ret.push_back(
"sramecc");
37 if (Features.test(llvm::AMDGPU::FEAT_XNACK_ON_OFF_MODES))
38 Ret.push_back(
"xnack");
44 llvm::StringRef Processor) {
53 llvm::StringRef Processor) {
55 return llvm::AMDGPU::getCanonicalArchName(
T, Processor);
60 llvm::StringRef TargetID) {
61 auto Split = TargetID.split(
':');
71static std::optional<llvm::StringRef>
73 llvm::StringMap<bool> *FeatureMap) {
74 llvm::StringRef Processor;
77 return llvm::StringRef();
79 auto Split = TargetID.split(
':');
80 Processor = Split.first;
81 if (Processor.empty())
84 auto Features = Split.second;
88 llvm::StringMap<bool> LocalFeatureMap;
90 FeatureMap = &LocalFeatureMap;
92 while (!Features.empty()) {
93 auto Splits = Features.split(
':');
94 if (Splits.first.empty())
96 auto Sign = Splits.first.back();
97 auto Feature = Splits.first.drop_back();
98 if (Sign !=
'+' && Sign !=
'-')
100 bool IsOn = Sign ==
'+';
102 if (!FeatureMap->try_emplace(
Feature, IsOn).second)
104 Features = Splits.second;
109std::optional<llvm::StringRef>
111 llvm::StringMap<bool> *FeatureMap) {
112 auto OptionalProcessor =
115 if (!OptionalProcessor)
119 if (Processor.empty())
122 llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
125 for (
auto &&F : *FeatureMap)
126 if (!AllFeatures.count(F.first()))
135 const llvm::StringMap<bool> &Features) {
136 std::string TargetID = Processor.str();
137 std::map<const llvm::StringRef, bool> OrderedMap;
138 for (
const auto &F : Features)
139 OrderedMap[F.first()] = F.second;
140 for (
const auto &F : OrderedMap)
141 TargetID = TargetID +
':' + F.first.str() + (F.second ?
"+" :
"-");
148std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
151 llvm::StringRef TargetID;
152 llvm::StringMap<bool> Features;
153 Info(llvm::StringRef TargetID,
const llvm::StringMap<bool> &Features)
154 : TargetID(TargetID), Features(Features) {}
156 llvm::StringMap<Info> FeatureMap;
157 for (
auto &&ID : TargetIDs) {
158 llvm::StringMap<bool> Features;
160 auto [Loc, Inserted] = FeatureMap.try_emplace(Proc, ID, Features);
162 auto &ExistingFeatures = Loc->second.Features;
163 if (llvm::any_of(Features, [&](
auto &F) {
164 return ExistingFeatures.count(F.first()) == 0;
166 return std::make_pair(Loc->second.TargetID, ID);
173 llvm::StringMap<bool> ProvidedFeatures, RequestedFeatures;
174 llvm::StringRef ProvidedProc =
176 llvm::StringRef RequestedProc =
178 if (ProvidedProc != RequestedProc)
180 for (
const auto &F : ProvidedFeatures) {
181 auto Loc = RequestedFeatures.find(F.first());
184 if (Loc == RequestedFeatures.end())
187 if (Loc->second != F.second)
194 std::string
FileName = TargetID.str();
195 if (llvm::sys::path::is_style_windows(llvm::sys::path::Style::native))
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.
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.
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.
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.