Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions clang/lib/Basic/OffloadArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ namespace clang {

namespace {
struct OffloadArchToStringMap {
OffloadArch arch;
const char *arch_name;
const char *virtual_arch_name;
OffloadArch Arch;
const char *ArchName;
const char *VirtualArchName;
};
} // namespace

#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just define the special sm_20 w/o using this macro

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that is simpler - bd5e7a2

#define SM(sm) SM2(sm, "compute_" #sm)
#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
static const OffloadArchToStringMap arch_names[] = {
static const OffloadArchToStringMap ArchNames[] = {
// clang-format off
{OffloadArch::UNUSED, "", ""},
SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
Expand Down Expand Up @@ -97,30 +97,30 @@ static const OffloadArchToStringMap arch_names[] = {
#undef GFX

const char *OffloadArchToString(OffloadArch A) {
auto result = std::find_if(
std::begin(arch_names), std::end(arch_names),
[A](const OffloadArchToStringMap &map) { return A == map.arch; });
if (result == std::end(arch_names))
auto Result = std::find_if(
std::begin(ArchNames), std::end(ArchNames),
[A](const OffloadArchToStringMap &Map) { return A == Map.Arch; });
if (Result == std::end(ArchNames))
return "unknown";
return result->arch_name;
return Result->ArchName;
}

const char *OffloadArchToVirtualArchString(OffloadArch A) {
auto result = std::find_if(
std::begin(arch_names), std::end(arch_names),
[A](const OffloadArchToStringMap &map) { return A == map.arch; });
if (result == std::end(arch_names))
auto Result = std::find_if(
std::begin(ArchNames), std::end(ArchNames),
[A](const OffloadArchToStringMap &Map) { return A == Map.Arch; });
if (Result == std::end(ArchNames))
return "unknown";
return result->virtual_arch_name;
return Result->VirtualArchName;
}

OffloadArch StringToOffloadArch(llvm::StringRef S) {
auto result = std::find_if(
std::begin(arch_names), std::end(arch_names),
[S](const OffloadArchToStringMap &map) { return S == map.arch_name; });
if (result == std::end(arch_names))
auto Result = std::find_if(
std::begin(ArchNames), std::end(ArchNames),
[S](const OffloadArchToStringMap &Map) { return S == Map.ArchName; });
if (Result == std::end(ArchNames))
return OffloadArch::UNKNOWN;
return result->arch;
return Result->Arch;
}

} // namespace clang
Loading