[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / TextAPI / Target.cpp
bloba50abeeca194c49c5121e11fddcd23784c923f7a
1 //===- Target.cpp -----------------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/TextAPI/Target.h"
10 #include "llvm/ADT/StringSwitch.h"
11 #include "llvm/ADT/Twine.h"
12 #include "llvm/Support/raw_ostream.h"
14 namespace llvm {
15 namespace MachO {
17 Expected<Target> Target::create(StringRef TargetValue) {
18 auto Result = TargetValue.split('-');
19 auto ArchitectureStr = Result.first;
20 auto Architecture = getArchitectureFromName(ArchitectureStr);
21 auto PlatformStr = Result.second;
22 PlatformType Platform;
23 Platform = StringSwitch<PlatformType>(PlatformStr)
24 #define PLATFORM(platform, id, name, build_name, target, tapi_target, \
25 marketing) \
26 .Case(#tapi_target, PLATFORM_##platform)
27 #include "llvm/BinaryFormat/MachO.def"
28 .Default(PLATFORM_UNKNOWN);
30 if (Platform == PLATFORM_UNKNOWN) {
31 if (PlatformStr.starts_with("<") && PlatformStr.ends_with(">")) {
32 PlatformStr = PlatformStr.drop_front().drop_back();
33 unsigned long long RawValue;
34 if (!PlatformStr.getAsInteger(10, RawValue))
35 Platform = (PlatformType)RawValue;
39 return Target{Architecture, Platform};
42 Target::operator std::string() const {
43 auto Version = MinDeployment.empty() ? "" : MinDeployment.getAsString();
45 return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) +
46 Version + ")")
47 .str();
50 raw_ostream &operator<<(raw_ostream &OS, const Target &Target) {
51 OS << std::string(Target);
52 return OS;
55 PlatformVersionSet mapToPlatformVersionSet(ArrayRef<Target> Targets) {
56 PlatformVersionSet Result;
57 for (const auto &Target : Targets)
58 Result.insert({Target.Platform, Target.MinDeployment});
59 return Result;
62 PlatformSet mapToPlatformSet(ArrayRef<Target> Targets) {
63 PlatformSet Result;
64 for (const auto &Target : Targets)
65 Result.insert(Target.Platform);
66 return Result;
69 ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets) {
70 ArchitectureSet Result;
71 for (const auto &Target : Targets)
72 Result.set(Target.Arch);
73 return Result;
76 std::string getTargetTripleName(const Target &Targ) {
77 auto Version =
78 Targ.MinDeployment.empty() ? "" : Targ.MinDeployment.getAsString();
80 return (getArchitectureName(Targ.Arch) + "-apple-" +
81 getOSAndEnvironmentName(Targ.Platform, Version))
82 .str();
85 } // end namespace MachO.
86 } // end namespace llvm.