10#include "llvm/ADT/STLExtras.h"
11#include "llvm/ADT/SmallSet.h"
12#include "llvm/Support/raw_ostream.h"
13#include "llvm/TargetParser/TargetParser.h"
14#include "llvm/TargetParser/Triple.h"
22 llvm::StringRef Proc) {
25 auto ProcKind =
T.isAMDGCN() ? llvm::AMDGPU::parseArchAMDGCN(Proc)
26 : llvm::AMDGPU::parseArchR600(Proc);
27 if (ProcKind == llvm::AMDGPU::GK_NONE)
29 auto Features =
T.isAMDGCN() ? llvm::AMDGPU::getArchAttrAMDGCN(ProcKind)
30 : llvm::AMDGPU::getArchAttrR600(ProcKind);
31 if (Features & llvm::AMDGPU::FEATURE_SRAMECC)
32 Ret.push_back(
"sramecc");
33 if (Features & llvm::AMDGPU::FEATURE_XNACK)
34 Ret.push_back(
"xnack");
40 llvm::StringRef Processor) {
49 llvm::StringRef Processor) {
51 return llvm::AMDGPU::getCanonicalArchName(
T, Processor);
56 llvm::StringRef TargetID) {
57 auto Split = TargetID.split(
':');
67static std::optional<llvm::StringRef>
69 llvm::StringMap<bool> *FeatureMap) {
70 llvm::StringRef Processor;
73 return llvm::StringRef();
75 auto Split = TargetID.split(
':');
76 Processor = Split.first;
77 if (Processor.empty())
80 auto Features = Split.second;
84 llvm::StringMap<bool> LocalFeatureMap;
86 FeatureMap = &LocalFeatureMap;
88 while (!Features.empty()) {
89 auto Splits = Features.split(
':');
90 auto Sign = Splits.first.back();
91 auto Feature = Splits.first.drop_back();
92 if (Sign !=
'+' && Sign !=
'-')
94 bool IsOn = Sign ==
'+';
96 if (!FeatureMap->try_emplace(Feature, IsOn).second)
98 Features = Splits.second;
103std::optional<llvm::StringRef>
105 llvm::StringMap<bool> *FeatureMap) {
106 auto OptionalProcessor =
109 if (!OptionalProcessor)
113 if (Processor.empty())
116 llvm::SmallSet<llvm::StringRef, 4> AllFeatures;
118 AllFeatures.insert(F);
120 for (
auto &&F : *FeatureMap)
121 if (!AllFeatures.count(F.first()))
130 const llvm::StringMap<bool> &Features) {
131 std::string TargetID = Processor.str();
132 std::map<const llvm::StringRef, bool> OrderedMap;
133 for (
const auto &F : Features)
134 OrderedMap[F.first()] = F.second;
135 for (
const auto &F : OrderedMap)
136 TargetID = TargetID +
':' + F.first.str() + (F.second ?
"+" :
"-");
143std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
146 llvm::StringRef TargetID;
147 llvm::StringMap<bool> Features;
148 Info(llvm::StringRef TargetID,
const llvm::StringMap<bool> &Features)
149 : TargetID(TargetID), Features(Features) {}
151 llvm::StringMap<Info> FeatureMap;
152 for (
auto &&
ID : TargetIDs) {
153 llvm::StringMap<bool> Features;
155 auto [
Loc, Inserted] = FeatureMap.try_emplace(Proc,
ID, Features);
157 auto &ExistingFeatures =
Loc->second.Features;
158 if (llvm::any_of(Features, [&](
auto &F) {
159 return ExistingFeatures.count(F.first()) == 0;
161 return std::make_pair(
Loc->second.TargetID,
ID);
168 llvm::StringMap<bool> ProvidedFeatures, RequestedFeatures;
169 llvm::StringRef ProvidedProc =
171 llvm::StringRef RequestedProc =
173 if (ProvidedProc != RequestedProc)
175 for (
const auto &F : ProvidedFeatures) {
176 auto Loc = RequestedFeatures.find(F.first());
179 if (
Loc == RequestedFeatures.end())
182 if (
Loc->second != F.second)
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)
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.
const FunctionProtoType * T
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.