10 #include "llvm/ADT/SmallSet.h"
11 #include "llvm/ADT/Triple.h"
12 #include "llvm/Support/TargetParser.h"
13 #include "llvm/Support/raw_ostream.h"
20 llvm::StringRef Proc) {
23 auto ProcKind = T.isAMDGCN() ? llvm::AMDGPU::parseArchAMDGCN(Proc)
24 : llvm::AMDGPU::parseArchR600(Proc);
25 if (ProcKind == llvm::AMDGPU::GK_NONE)
27 auto Features = T.isAMDGCN() ? llvm::AMDGPU::getArchAttrAMDGCN(ProcKind)
28 : llvm::AMDGPU::getArchAttrR600(ProcKind);
29 if (Features & llvm::AMDGPU::FEATURE_SRAMECC)
30 Ret.push_back(
"sramecc");
31 if (Features & llvm::AMDGPU::FEATURE_XNACK)
32 Ret.push_back(
"xnack");
38 llvm::StringRef Processor) {
47 llvm::StringRef Processor) {
49 return llvm::AMDGPU::getCanonicalArchName(T, Processor);
54 llvm::StringRef TargetID) {
55 auto Split = TargetID.split(
':');
67 llvm::StringMap<bool> *FeatureMap) {
68 llvm::StringRef Processor;
71 return llvm::StringRef();
73 auto Split = TargetID.split(
':');
74 Processor =
Split.first;
75 if (Processor.empty())
78 auto Features =
Split.second;
82 llvm::StringMap<bool> LocalFeatureMap;
84 FeatureMap = &LocalFeatureMap;
86 while (!Features.empty()) {
87 auto Splits = Features.split(
':');
88 auto Sign = Splits.first.back();
89 auto Feature = Splits.first.drop_back();
90 if (Sign !=
'+' && Sign !=
'-')
92 bool IsOn = Sign ==
'+';
93 auto Loc = FeatureMap->find(Feature);
95 if (Loc != FeatureMap->end())
97 (*FeatureMap)[Feature] = IsOn;
98 Features = Splits.second;
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) {
132 std::map<const llvm::StringRef, bool> OrderedMap;
133 for (
const auto &F : Features)
134 OrderedMap[F.first()] = F.second;
135 for (
auto F : OrderedMap)
136 TargetID = TargetID +
':' + F.first.str() + (F.second ?
"+" :
"-");
146 llvm::StringRef TargetID;
147 llvm::StringMap<bool> Features;
149 llvm::StringMap<Info> FeatureMap;
150 for (
auto &&
ID : TargetIDs) {
151 llvm::StringMap<bool> Features;
153 auto Loc = FeatureMap.find(Proc);
154 if (Loc == FeatureMap.end())
155 FeatureMap[Proc] = Info{
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);