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");
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 if (Splits.first.empty())
94 auto Sign = Splits.first.back();
95 auto Feature = Splits.first.drop_back();
96 if (Sign !=
'+' && Sign !=
'-')
98 bool IsOn = Sign ==
'+';
100 if (!FeatureMap->try_emplace(
Feature, IsOn).second)
102 Features = Splits.second;
107std::optional<llvm::StringRef>
109 llvm::StringMap<bool> *FeatureMap) {
110 auto OptionalProcessor =
113 if (!OptionalProcessor)
117 if (Processor.empty())
120 llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
123 for (
auto &&F : *FeatureMap)
124 if (!AllFeatures.count(F.first()))
133 const llvm::StringMap<bool> &Features) {
134 std::string TargetID = Processor.str();
135 std::map<const llvm::StringRef, bool> OrderedMap;
136 for (
const auto &F : Features)
137 OrderedMap[F.first()] = F.second;
138 for (
const auto &F : OrderedMap)
139 TargetID = TargetID +
':' + F.first.str() + (F.second ?
"+" :
"-");
146std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
149 llvm::StringRef TargetID;
150 llvm::StringMap<bool> Features;
151 Info(llvm::StringRef TargetID,
const llvm::StringMap<bool> &Features)
152 : TargetID(TargetID), Features(Features) {}
154 llvm::StringMap<Info> FeatureMap;
155 for (
auto &&ID : TargetIDs) {
156 llvm::StringMap<bool> Features;
158 auto [Loc, Inserted] = FeatureMap.try_emplace(Proc, ID, Features);
160 auto &ExistingFeatures = Loc->second.Features;
161 if (llvm::any_of(Features, [&](
auto &F) {
162 return ExistingFeatures.count(F.first()) == 0;
164 return std::make_pair(Loc->second.TargetID, ID);
171 llvm::StringMap<bool> ProvidedFeatures, RequestedFeatures;
172 llvm::StringRef ProvidedProc =
174 llvm::StringRef RequestedProc =
176 if (ProvidedProc != RequestedProc)
178 for (
const auto &F : ProvidedFeatures) {
179 auto Loc = RequestedFeatures.find(F.first());
182 if (Loc == RequestedFeatures.end())
185 if (Loc->second != F.second)
192 std::string
FileName = TargetID.str();
193 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.