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) {
27 auto ProcKind = T.isAMDGCN() ? llvm::AMDGPU::parseArchAMDGCN(Proc)
28 : llvm::AMDGPU::parseArchR600(Proc);
29 if (ProcKind == llvm::AMDGPU::GK_NONE)
31 auto Features = T.isAMDGCN() ? llvm::AMDGPU::getArchAttrAMDGCN(ProcKind)
32 : llvm::AMDGPU::getArchAttrR600(ProcKind);
33 if (Features & llvm::AMDGPU::FEATURE_SRAMECC)
34 Ret.push_back(
"sramecc");
36 if (Features & llvm::AMDGPU::FEATURE_XNACK_ON_OFF_MODES)
37 Ret.push_back(
"xnack");
43 llvm::StringRef Processor) {
52 llvm::StringRef Processor) {
54 return llvm::AMDGPU::getCanonicalArchName(T, Processor);
59 llvm::StringRef TargetID) {
60 auto Split = TargetID.split(
':');
70static std::optional<llvm::StringRef>
72 llvm::StringMap<bool> *FeatureMap) {
73 llvm::StringRef Processor;
76 return llvm::StringRef();
78 auto Split = TargetID.split(
':');
79 Processor = Split.first;
80 if (Processor.empty())
83 auto Features = Split.second;
87 llvm::StringMap<bool> LocalFeatureMap;
89 FeatureMap = &LocalFeatureMap;
91 while (!Features.empty()) {
92 auto Splits = Features.split(
':');
93 if (Splits.first.empty())
95 auto Sign = Splits.first.back();
96 auto Feature = Splits.first.drop_back();
97 if (Sign !=
'+' && Sign !=
'-')
99 bool IsOn = Sign ==
'+';
101 if (!FeatureMap->try_emplace(
Feature, IsOn).second)
103 Features = Splits.second;
108std::optional<llvm::StringRef>
110 llvm::StringMap<bool> *FeatureMap) {
111 auto OptionalProcessor =
114 if (!OptionalProcessor)
118 if (Processor.empty())
121 llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
124 for (
auto &&F : *FeatureMap)
125 if (!AllFeatures.count(F.first()))
134 const llvm::StringMap<bool> &Features) {
135 std::string TargetID = Processor.str();
136 std::map<const llvm::StringRef, bool> OrderedMap;
137 for (
const auto &F : Features)
138 OrderedMap[F.first()] = F.second;
139 for (
const auto &F : OrderedMap)
140 TargetID = TargetID +
':' + F.first.str() + (F.second ?
"+" :
"-");
147std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
150 llvm::StringRef TargetID;
151 llvm::StringMap<bool> Features;
152 Info(llvm::StringRef TargetID,
const llvm::StringMap<bool> &Features)
153 : TargetID(TargetID), Features(Features) {}
155 llvm::StringMap<Info> FeatureMap;
156 for (
auto &&ID : TargetIDs) {
157 llvm::StringMap<bool> Features;
159 auto [Loc, Inserted] = FeatureMap.try_emplace(Proc, ID, Features);
161 auto &ExistingFeatures = Loc->second.Features;
162 if (llvm::any_of(Features, [&](
auto &F) {
163 return ExistingFeatures.count(F.first()) == 0;
165 return std::make_pair(Loc->second.TargetID, ID);
172 llvm::StringMap<bool> ProvidedFeatures, RequestedFeatures;
173 llvm::StringRef ProvidedProc =
175 llvm::StringRef RequestedProc =
177 if (ProvidedProc != RequestedProc)
179 for (
const auto &F : ProvidedFeatures) {
180 auto Loc = RequestedFeatures.find(F.first());
183 if (Loc == RequestedFeatures.end())
186 if (Loc->second != F.second)
193 std::string
FileName = TargetID.str();
194 if (llvm::sys::path::is_style_windows(llvm::sys::path::Style::native))
The JSON file list parser is used to communicate input to InstallAPI.
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.
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.