Path: blob/main/contrib/llvm-project/llvm/lib/TargetParser/PPCTargetParser.cpp
213765 views
//===---- PPCTargetParser.cpp - Parser for target features ------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements a target parser to recognise hardware features9// for PPC CPUs.10//11//===----------------------------------------------------------------------===//1213#include "llvm/TargetParser/PPCTargetParser.h"14#include "llvm/ADT/StringSwitch.h"15#include "llvm/TargetParser/Host.h"1617#define GET_SUBTARGETFEATURES_ENUM18#define GET_SUBTARGETFEATURES_KV19#include "llvm/TargetParser/PPCGenTargetFeatures.inc"2021namespace llvm {22namespace PPC {2324struct CPUInfo {25StringLiteral Name;26// FIXME: add the features field for this CPU.27};2829constexpr CPUInfo PPCCPUInfo[] = {30#define PPC_CPU(Name, Linux_SUPPORT_METHOD, LinuxID, AIX_SUPPORT_METHOD, \31AIXID) \32{Name},33#include "llvm/TargetParser/PPCTargetParser.def"34};3536static const CPUInfo *getCPUInfoByName(StringRef CPU) {37for (auto &C : PPCCPUInfo)38if (C.Name == CPU)39return &C;40return nullptr;41}4243StringRef normalizeCPUName(StringRef CPUName) {44// Clang/LLVM does not actually support code generation45// for the 405 CPU. However, there are uses of this CPU ID46// in projects that previously used GCC and rely on Clang47// accepting it. Clang has always ignored it and passed the48// generic CPU ID to the back end.49return StringSwitch<StringRef>(CPUName)50.Cases("common", "405", "generic")51.Cases("ppc440", "440fp", "440")52.Cases("630", "power3", "pwr3")53.Case("G3", "g3")54.Case("G4", "g4")55.Case("G4+", "g4+")56.Case("8548", "e500")57.Case("ppc970", "970")58.Case("G5", "g5")59.Case("ppca2", "a2")60.Case("power4", "pwr4")61.Case("power5", "pwr5")62.Case("power5x", "pwr5x")63.Case("power5+", "pwr5+")64.Case("power6", "pwr6")65.Case("power6x", "pwr6x")66.Case("power7", "pwr7")67.Case("power8", "pwr8")68.Case("power9", "pwr9")69.Case("power10", "pwr10")70.Case("power11", "pwr11")71.Cases("powerpc", "powerpc32", "ppc")72.Case("powerpc64", "ppc64")73.Case("powerpc64le", "ppc64le")74.Default(CPUName);75}7677void fillValidCPUList(SmallVectorImpl<StringRef> &Values) {78for (const auto &C : PPCCPUInfo)79Values.emplace_back(C.Name);80}8182void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) {83for (const auto &C : PPCCPUInfo)84Values.emplace_back(C.Name);85}8687bool isValidCPU(StringRef CPU) {88const CPUInfo *Info = getCPUInfoByName(CPU);89if (!Info)90return false;91return true;92}9394StringRef getNormalizedPPCTargetCPU(const Triple &T, StringRef CPUName) {95if (!CPUName.empty()) {96if (CPUName == "native") {97StringRef CPU = sys::getHostCPUName();98if (!CPU.empty() && CPU != "generic")99return CPU;100}101102StringRef CPU = normalizeCPUName(CPUName);103if (CPU != "generic" && CPU != "native")104return CPU;105}106107// LLVM may default to generating code for the native CPU, but, like gcc, we108// default to a more generic option for each architecture. (except on AIX)109if (T.isOSAIX())110return "pwr7";111else if (T.getArch() == Triple::ppc64le)112return "ppc64le";113else if (T.getArch() == Triple::ppc64)114return "ppc64";115116return "ppc";117}118119StringRef getNormalizedPPCTuneCPU(const Triple &T, StringRef CPUName) {120return getNormalizedPPCTargetCPU(T, CPUName);121}122123std::optional<StringMap<bool>> getPPCDefaultTargetFeatures(const Triple &T,124StringRef CPU) {125std::optional<StringMap<bool>> FeaturesOpt =126getCPUDefaultTargetFeatures(CPU, BasicPPCSubTypeKV, BasicPPCFeatureKV);127128if (!FeaturesOpt.has_value())129return std::nullopt;130131StringMap<bool> Features = FeaturesOpt.value();132// FIXME: We need to check for the processor model 8548, since the backend133// does not support this processor. When this processor model is implemented134// within the backend, the following code can be removed.135if (CPU == "8548")136Features["spe"] = true;137138// The target feature `quadword-atomics` is only supported for 64-bit139// POWER8 and above.140if (Features.find("quadword-atomics") != Features.end() && !T.isArch64Bit())141Features["quadword-atomics"] = false;142return Features;143}144} // namespace PPC145} // namespace llvm146147148