clang  9.0.0
PPC.cpp
Go to the documentation of this file.
1 //===--- PPC.cpp - PPC Helpers for Tools ------------------------*- 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 //===----------------------------------------------------------------------===//
8 
9 #include "PPC.h"
10 #include "ToolChains/CommonArgs.h"
11 #include "clang/Driver/Driver.h"
13 #include "clang/Driver/Options.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/Option/ArgList.h"
16 
17 using namespace clang::driver;
18 using namespace clang::driver::tools;
19 using namespace clang;
20 using namespace llvm::opt;
21 
22 /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
23 std::string ppc::getPPCTargetCPU(const ArgList &Args) {
24  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
25  StringRef CPUName = A->getValue();
26 
27  if (CPUName == "native") {
28  std::string CPU = llvm::sys::getHostCPUName();
29  if (!CPU.empty() && CPU != "generic")
30  return CPU;
31  else
32  return "";
33  }
34 
35  return llvm::StringSwitch<const char *>(CPUName)
36  .Case("common", "generic")
37  .Case("440", "440")
38  .Case("440fp", "440")
39  .Case("450", "450")
40  .Case("601", "601")
41  .Case("602", "602")
42  .Case("603", "603")
43  .Case("603e", "603e")
44  .Case("603ev", "603ev")
45  .Case("604", "604")
46  .Case("604e", "604e")
47  .Case("620", "620")
48  .Case("630", "pwr3")
49  .Case("G3", "g3")
50  .Case("7400", "7400")
51  .Case("G4", "g4")
52  .Case("7450", "7450")
53  .Case("G4+", "g4+")
54  .Case("750", "750")
55  .Case("970", "970")
56  .Case("G5", "g5")
57  .Case("a2", "a2")
58  .Case("a2q", "a2q")
59  .Case("e500mc", "e500mc")
60  .Case("e5500", "e5500")
61  .Case("power3", "pwr3")
62  .Case("power4", "pwr4")
63  .Case("power5", "pwr5")
64  .Case("power5x", "pwr5x")
65  .Case("power6", "pwr6")
66  .Case("power6x", "pwr6x")
67  .Case("power7", "pwr7")
68  .Case("power8", "pwr8")
69  .Case("power9", "pwr9")
70  .Case("pwr3", "pwr3")
71  .Case("pwr4", "pwr4")
72  .Case("pwr5", "pwr5")
73  .Case("pwr5x", "pwr5x")
74  .Case("pwr6", "pwr6")
75  .Case("pwr6x", "pwr6x")
76  .Case("pwr7", "pwr7")
77  .Case("pwr8", "pwr8")
78  .Case("pwr9", "pwr9")
79  .Case("powerpc", "ppc")
80  .Case("powerpc64", "ppc64")
81  .Case("powerpc64le", "ppc64le")
82  .Default("");
83  }
84 
85  return "";
86 }
87 
88 const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
89  return llvm::StringSwitch<const char *>(Name)
90  .Case("pwr7", "-mpower7")
91  .Case("power7", "-mpower7")
92  .Case("pwr8", "-mpower8")
93  .Case("power8", "-mpower8")
94  .Case("ppc64le", "-mpower8")
95  .Case("pwr9", "-mpower9")
96  .Case("power9", "-mpower9")
97  .Default("-many");
98 }
99 
100 void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
101  const ArgList &Args,
102  std::vector<StringRef> &Features) {
103  handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group);
104 
106  if (FloatABI == ppc::FloatABI::Soft)
107  Features.push_back("-hard-float");
108 
109  ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
110  if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
111  Features.push_back("+secure-plt");
112 }
113 
114 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
115  const ArgList &Args) {
116  if (Args.getLastArg(options::OPT_msecure_plt))
118  if (Triple.isOSNetBSD() || Triple.isOSOpenBSD() || Triple.isMusl())
120  else
122 }
123 
124 ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
126  if (Arg *A =
127  Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
128  options::OPT_mfloat_abi_EQ)) {
129  if (A->getOption().matches(options::OPT_msoft_float))
130  ABI = ppc::FloatABI::Soft;
131  else if (A->getOption().matches(options::OPT_mhard_float))
132  ABI = ppc::FloatABI::Hard;
133  else {
134  ABI = llvm::StringSwitch<ppc::FloatABI>(A->getValue())
135  .Case("soft", ppc::FloatABI::Soft)
136  .Case("hard", ppc::FloatABI::Hard)
137  .Default(ppc::FloatABI::Invalid);
138  if (ABI == ppc::FloatABI::Invalid && !StringRef(A->getValue()).empty()) {
139  D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
140  ABI = ppc::FloatABI::Hard;
141  }
142  }
143  }
144 
145  // If unspecified, choose the default based on the platform.
146  if (ABI == ppc::FloatABI::Invalid) {
147  ABI = ppc::FloatABI::Hard;
148  }
149 
150  return ABI;
151 }
152 
153 bool ppc::hasPPCAbiArg(const ArgList &Args, const char *Value) {
154  Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
155  return A && (A->getValue() == StringRef(Value));
156 }
const char * getPPCAsmModeForCPU(StringRef Name)
Definition: PPC.cpp:88
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:108
FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args)
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:57
bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value)
std::string getPPCTargetCPU(const llvm::opt::ArgList &Args)
ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Dataflow Directional Tag Classes.
void getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< llvm::StringRef > &Features)