clang 23.0.0git
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"
11#include "clang/Driver/Driver.h"
13#include "llvm/ADT/StringSwitch.h"
14#include "llvm/Option/ArgList.h"
15#include "llvm/TargetParser/Host.h"
16
17using namespace clang::driver;
18using namespace clang::driver::tools;
19using namespace clang;
20using namespace llvm::opt;
21
22const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
23 return llvm::StringSwitch<const char *>(Name)
24 .Case("pwr7", "-mpower7")
25 .Case("power7", "-mpower7")
26 .Case("pwr8", "-mpower8")
27 .Case("power8", "-mpower8")
28 .Case("ppc64le", "-mpower8")
29 .Case("pwr9", "-mpower9")
30 .Case("power9", "-mpower9")
31 .Case("pwr10", "-mpower10")
32 .Case("power10", "-mpower10")
33 .Case("pwr11", "-mpower11")
34 .Case("power11", "-mpower11")
35 .Default("-many");
36}
37
38void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
39 const ArgList &Args,
40 std::vector<StringRef> &Features) {
41 if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
42 Features.push_back("+spe");
43
44 handleTargetFeaturesGroup(D, Triple, Args, Features,
45 options::OPT_m_ppc_Features_Group);
46
47 ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
48 if (FloatABI == ppc::FloatABI::Soft)
49 Features.push_back("-hard-float");
50
51 ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
52 if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
53 Features.push_back("+secure-plt");
54
55 bool UseSeparateSections = isUseSeparateSections(Triple);
56 bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
57 if (Args.hasArg(options::OPT_maix_small_local_exec_tls) ||
58 Args.hasArg(options::OPT_maix_small_local_dynamic_tls)) {
59 if (!Triple.isOSAIX() || !Triple.isArch64Bit())
60 D.Diag(diag::err_opt_not_valid_on_target)
61 << "-maix-small-local-[exec|dynamic]-tls";
62
63 // The -maix-small-local-[exec|dynamic]-tls option should only be used with
64 // -fdata-sections, as having data sections turned off with this option
65 // is not ideal for performance. Moreover, the
66 // small-local-[exec|dynamic]-tls region is a limited resource, and should
67 // not be used for variables that may be replaced.
68 if (!Args.hasFlag(options::OPT_fdata_sections,
69 options::OPT_fno_data_sections,
70 UseSeparateSections || HasDefaultDataSections))
71 D.Diag(diag::err_drv_argument_only_allowed_with)
72 << "-maix-small-local-[exec|dynamic]-tls" << "-fdata-sections";
73 }
74
75 if (Args.hasArg(options::OPT_maix_shared_lib_tls_model_opt) &&
76 !(Triple.isOSAIX() && Triple.isArch64Bit()))
77 D.Diag(diag::err_opt_not_valid_on_target)
78 << "-maix-shared-lib-tls-model-opt";
79
80 // The integrated assembler counts as a "modern AIX assembler" for the
81 // purposes of the modern-aix-as.
82 if (Args.hasFlag(options::OPT_fintegrated_as, options::OPT_fno_integrated_as,
83 true) &&
84 Triple.isOSAIX())
85 Features.push_back("+modern-aix-as");
86
87 if (Arg *A = Args.getLastArg(options::OPT_mnoaix_use_ptrgl,
88 options::OPT_maix_use_ptrgl)) {
89 if (!Triple.isOSAIX())
90 D.Diag(diag::err_drv_unsupported_opt_for_target)
91 << A->getAsString(Args) << Triple.str();
92 else if (A->getOption().matches(options::OPT_maix_use_ptrgl))
93 Features.push_back("+use-ptrgl-helper");
94 }
95}
96
97ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
98 const ArgList &Args) {
99 if (Args.getLastArg(options::OPT_msecure_plt))
101 if (Triple.isPPC32SecurePlt())
103 else
105}
106
107ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
109 if (Arg *A =
110 Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
111 options::OPT_mfloat_abi_EQ)) {
112 if (A->getOption().matches(options::OPT_msoft_float))
114 else if (A->getOption().matches(options::OPT_mhard_float))
116 else {
117 ABI = llvm::StringSwitch<ppc::FloatABI>(A->getValue())
118 .Case("soft", ppc::FloatABI::Soft)
119 .Case("hard", ppc::FloatABI::Hard)
120 .Default(ppc::FloatABI::Invalid);
121 if (ABI == ppc::FloatABI::Invalid && !StringRef(A->getValue()).empty()) {
122 D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
124 }
125 }
126 }
127
128 // If unspecified, choose the default based on the platform.
129 if (ABI == ppc::FloatABI::Invalid) {
131 }
132
133 return ABI;
134}
135
136bool ppc::hasPPCAbiArg(const ArgList &Args, const char *Value) {
137 Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
138 return A && (A->getValue() == StringRef(Value));
139}
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:99
DiagnosticBuilder Diag(unsigned DiagID) const
Definition Driver.h:169
FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args)
const char * getPPCAsmModeForCPU(StringRef Name)
Definition PPC.cpp:22
void getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< llvm::StringRef > &Features)
ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value)
void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
Iterate Args and convert -mxxx to +xxx and -mno-xxx to -xxx and append it to Features.
bool isUseSeparateSections(const llvm::Triple &Triple)
The JSON file list parser is used to communicate input to InstallAPI.