1 //===--- PPC.cpp - PPC Helpers for Tools ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "ToolChains/CommonArgs.h"
12 #include "clang/Driver/Driver.h"
13 #include "clang/Driver/DriverDiagnostic.h"
14 #include "clang/Driver/Options.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/Option/ArgList.h"
18 using namespace clang::driver;
19 using namespace clang::driver::tools;
20 using namespace clang;
21 using namespace llvm::opt;
23 /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
24 std::string ppc::getPPCTargetCPU(const ArgList &Args) {
25 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
26 StringRef CPUName = A->getValue();
28 if (CPUName == "native") {
29 std::string CPU = llvm::sys::getHostCPUName();
30 if (!CPU.empty() && CPU != "generic")
36 return llvm::StringSwitch<const char *>(CPUName)
37 .Case("common", "generic")
45 .Case("603ev", "603ev")
60 .Case("e500mc", "e500mc")
61 .Case("e5500", "e5500")
62 .Case("power3", "pwr3")
63 .Case("power4", "pwr4")
64 .Case("power5", "pwr5")
65 .Case("power5x", "pwr5x")
66 .Case("power6", "pwr6")
67 .Case("power6x", "pwr6x")
68 .Case("power7", "pwr7")
69 .Case("power8", "pwr8")
70 .Case("power9", "pwr9")
74 .Case("pwr5x", "pwr5x")
76 .Case("pwr6x", "pwr6x")
80 .Case("powerpc", "ppc")
81 .Case("powerpc64", "ppc64")
82 .Case("powerpc64le", "ppc64le")
89 const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
90 return llvm::StringSwitch<const char *>(Name)
91 .Case("pwr7", "-mpower7")
92 .Case("power7", "-mpower7")
93 .Case("pwr8", "-mpower8")
94 .Case("power8", "-mpower8")
95 .Case("ppc64le", "-mpower8")
96 .Case("pwr9", "-mpower9")
97 .Case("power9", "-mpower9")
101 void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
103 std::vector<StringRef> &Features) {
104 handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group);
106 ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
107 if (FloatABI == ppc::FloatABI::Soft)
108 Features.push_back("-hard-float");
111 ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
112 ppc::FloatABI ABI = ppc::FloatABI::Invalid;
114 Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
115 options::OPT_mfloat_abi_EQ)) {
116 if (A->getOption().matches(options::OPT_msoft_float))
117 ABI = ppc::FloatABI::Soft;
118 else if (A->getOption().matches(options::OPT_mhard_float))
119 ABI = ppc::FloatABI::Hard;
121 ABI = llvm::StringSwitch<ppc::FloatABI>(A->getValue())
122 .Case("soft", ppc::FloatABI::Soft)
123 .Case("hard", ppc::FloatABI::Hard)
124 .Default(ppc::FloatABI::Invalid);
125 if (ABI == ppc::FloatABI::Invalid && !StringRef(A->getValue()).empty()) {
126 D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
127 ABI = ppc::FloatABI::Hard;
132 // If unspecified, choose the default based on the platform.
133 if (ABI == ppc::FloatABI::Invalid) {
134 ABI = ppc::FloatABI::Hard;
140 bool ppc::hasPPCAbiArg(const ArgList &Args, const char *Value) {
141 Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
142 return A && (A->getValue() == StringRef(Value));