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/TargetParser.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");
35 if (Features & llvm::AMDGPU::FEATURE_XNACK)
36 Ret.push_back(
"xnack");
42 llvm::StringRef Processor) {
51 llvm::StringRef Processor) {
53 return llvm::AMDGPU::getCanonicalArchName(
T, Processor);
58 llvm::StringRef TargetID) {
59 auto Split = TargetID.split(
':');
69static std::optional<llvm::StringRef>
71 llvm::StringMap<bool> *FeatureMap) {
72 llvm::StringRef Processor;
75 return llvm::StringRef();
77 auto Split = TargetID.split(
':');
78 Processor = Split.first;
79 if (Processor.empty())
82 auto Features = Split.second;
86 llvm::StringMap<bool> LocalFeatureMap;
88 FeatureMap = &LocalFeatureMap;
90 while (!Features.empty()) {
91 auto Splits = Features.split(
':');
92 auto Sign = Splits.first.back();
93 auto Feature = Splits.first.drop_back();
94 if (Sign !=
'+' && Sign !=
'-')
96 bool IsOn = Sign ==
'+';
98 if (!FeatureMap->try_emplace(
Feature, IsOn).second)
100 Features = Splits.second;
105std::optional<llvm::StringRef>
107 llvm::StringMap<bool> *FeatureMap) {
108 auto OptionalProcessor =
111 if (!OptionalProcessor)
115 if (Processor.empty())
118 llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
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;
149 Info(llvm::StringRef TargetID,
const llvm::StringMap<bool> &Features)
150 : TargetID(TargetID), Features(Features) {}
152 llvm::StringMap<Info> FeatureMap;
153 for (
auto &&ID : TargetIDs) {
154 llvm::StringMap<bool> Features;
156 auto [Loc, Inserted] = FeatureMap.try_emplace(Proc, 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)
190 std::string
FileName = TargetID.str();
191 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.
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.