[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / TextAPI / Architecture.cpp
blob51ca91db13008ca1c603bc9fff8eeba0a8e5932b
1 //===- Architecture.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implements the architecture helper functions.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/Architecture.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/BinaryFormat/MachO.h"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/raw_ostream.h"
18 #include "llvm/TargetParser/Triple.h"
20 namespace llvm {
21 namespace MachO {
23 Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) {
24 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
25 if (CPUType == (Type) && \
26 (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \
27 return AK_##Arch;
28 #include "llvm/TextAPI/Architecture.def"
29 #undef ARCHINFO
31 return AK_unknown;
34 Architecture getArchitectureFromName(StringRef Name) {
35 return StringSwitch<Architecture>(Name)
36 #define ARCHINFO(Arch, Type, Subtype, NumBits) .Case(#Arch, AK_##Arch)
37 #include "llvm/TextAPI/Architecture.def"
38 #undef ARCHINFO
39 .Default(AK_unknown);
42 StringRef getArchitectureName(Architecture Arch) {
43 switch (Arch) {
44 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
45 case AK_##Arch: \
46 return #Arch;
47 #include "llvm/TextAPI/Architecture.def"
48 #undef ARCHINFO
49 case AK_unknown:
50 return "unknown";
53 // Appease some compilers that cannot figure out that this is a fully covered
54 // switch statement.
55 return "unknown";
58 std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) {
59 switch (Arch) {
60 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
61 case AK_##Arch: \
62 return std::make_pair(Type, Subtype);
63 #include "llvm/TextAPI/Architecture.def"
64 #undef ARCHINFO
65 case AK_unknown:
66 return std::make_pair(0, 0);
69 // Appease some compilers that cannot figure out that this is a fully covered
70 // switch statement.
71 return std::make_pair(0, 0);
74 Architecture mapToArchitecture(const Triple &Target) {
75 return getArchitectureFromName(Target.getArchName());
78 bool is64Bit(Architecture Arch) {
79 switch (Arch) {
80 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
81 case AK_##Arch: \
82 return NumBits == 64;
83 #include "llvm/TextAPI/Architecture.def"
84 #undef ARCHINFO
85 case AK_unknown:
86 return false;
89 llvm_unreachable("Fully handled switch case above.");
92 raw_ostream &operator<<(raw_ostream &OS, Architecture Arch) {
93 OS << getArchitectureName(Arch);
94 return OS;
97 } // end namespace MachO.
98 } // end namespace llvm.