10#include "llvm/ADT/SmallSet.h"
11#include "llvm/Support/raw_ostream.h"
12#include "llvm/TargetParser/TargetParser.h"
13#include "llvm/TargetParser/Triple.h"
21 llvm::StringRef Proc) {
24 auto ProcKind =
T.isAMDGCN() ? llvm::AMDGPU::parseArchAMDGCN(Proc)
25 : llvm::AMDGPU::parseArchR600(Proc);
26 if (ProcKind == llvm::AMDGPU::GK_NONE)
28 auto Features =
T.isAMDGCN() ? llvm::AMDGPU::getArchAttrAMDGCN(ProcKind)
29 : llvm::AMDGPU::getArchAttrR600(ProcKind);
30 if (Features & llvm::AMDGPU::FEATURE_SRAMECC)
31 Ret.push_back(
"sramecc");
32 if (Features & llvm::AMDGPU::FEATURE_XNACK)
33 Ret.push_back(
"xnack");
39 llvm::StringRef Processor) {
48 llvm::StringRef Processor) {
50 return llvm::AMDGPU::getCanonicalArchName(
T, Processor);
55 llvm::StringRef TargetID) {
56 auto Split = TargetID.split(
':');
66static std::optional<llvm::StringRef>
68 llvm::StringMap<bool> *FeatureMap) {
69 llvm::StringRef Processor;
72 return llvm::StringRef();
74 auto Split = TargetID.split(
':');
75 Processor = Split.first;
76 if (Processor.empty())
79 auto Features = Split.second;
83 llvm::StringMap<bool> LocalFeatureMap;
85 FeatureMap = &LocalFeatureMap;
87 while (!Features.empty()) {
88 auto Splits = Features.split(
':');
89 auto Sign = Splits.first.back();
90 auto Feature = Splits.first.drop_back();
91 if (Sign !=
'+' && Sign !=
'-')
93 bool IsOn = Sign ==
'+';
94 auto Loc = FeatureMap->find(Feature);
96 if (
Loc != FeatureMap->end())
98 (*FeatureMap)[Feature] = IsOn;
99 Features = Splits.second;
104std::optional<llvm::StringRef>
106 llvm::StringMap<bool> *FeatureMap) {
107 auto OptionalProcessor =
110 if (!OptionalProcessor)
114 if (Processor.empty())
117 llvm::SmallSet<llvm::StringRef, 4> AllFeatures;
119 AllFeatures.insert(F);
121 for (
auto &&F : *FeatureMap)
122 if (!AllFeatures.count(F.first()))
131 const llvm::StringMap<bool> &Features) {
132 std::string TargetID = Processor.str();
133 std::map<const llvm::StringRef, bool> OrderedMap;
134 for (
const auto &F : Features)
135 OrderedMap[F.first()] = F.second;
136 for (
const auto &F : OrderedMap)
137 TargetID = TargetID +
':' + F.first.str() + (F.second ?
"+" :
"-");
144std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
147 llvm::StringRef TargetID;
148 llvm::StringMap<bool> Features;
150 llvm::StringMap<Info> FeatureMap;
151 for (
auto &&
ID : TargetIDs) {
152 llvm::StringMap<bool> Features;
154 auto Loc = FeatureMap.find(Proc);
155 if (
Loc == FeatureMap.end())
156 FeatureMap[Proc] = Info{
ID, Features};
158 auto &ExistingFeatures =
Loc->second.Features;
159 if (llvm::any_of(Features, [&](
auto &F) {
160 return ExistingFeatures.count(F.first()) == 0;
162 return std::make_pair(
Loc->second.TargetID,
ID);
169 llvm::StringMap<bool> ProvidedFeatures, RequestedFeatures;
170 llvm::StringRef ProvidedProc =
172 llvm::StringRef RequestedProc =
174 if (ProvidedProc != RequestedProc)
176 for (
const auto &F : ProvidedFeatures) {
177 auto Loc = RequestedFeatures.find(F.first());
180 if (
Loc == RequestedFeatures.end())
183 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.