Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/Arch/PPC.cpp
Line
Count
Source (jump to first uncovered line)
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"
12
#include "clang/Driver/DriverDiagnostic.h"
13
#include "clang/Driver/Options.h"
14
#include "llvm/ADT/StringSwitch.h"
15
#include "llvm/Option/ArgList.h"
16
#include "llvm/Support/Host.h"
17
18
using namespace clang::driver;
19
using namespace clang::driver::tools;
20
using namespace clang;
21
using namespace llvm::opt;
22
23
/// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
24
401
std::string ppc::getPPCTargetCPU(const ArgList &Args) {
25
401
  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
26
91
    StringRef CPUName = A->getValue();
27
91
28
91
    if (CPUName == "native") {
29
0
      std::string CPU = std::string(llvm::sys::getHostCPUName());
30
0
      if (!CPU.empty() && CPU != "generic")
31
0
        return CPU;
32
0
      else
33
0
        return "";
34
91
    }
35
91
36
91
    return llvm::StringSwitch<const char *>(CPUName)
37
91
        .Case("common", "generic")
38
91
        .Case("440", "440")
39
91
        .Case("440fp", "440")
40
91
        .Case("450", "450")
41
91
        .Case("601", "601")
42
91
        .Case("602", "602")
43
91
        .Case("603", "603")
44
91
        .Case("603e", "603e")
45
91
        .Case("603ev", "603ev")
46
91
        .Case("604", "604")
47
91
        .Case("604e", "604e")
48
91
        .Case("620", "620")
49
91
        .Case("630", "pwr3")
50
91
        .Case("G3", "g3")
51
91
        .Case("7400", "7400")
52
91
        .Case("G4", "g4")
53
91
        .Case("7450", "7450")
54
91
        .Case("G4+", "g4+")
55
91
        .Case("750", "750")
56
91
        .Case("8548", "e500")
57
91
        .Case("970", "970")
58
91
        .Case("G5", "g5")
59
91
        .Case("a2", "a2")
60
91
        .Case("a2q", "a2q")
61
91
        .Case("e500", "e500")
62
91
        .Case("e500mc", "e500mc")
63
91
        .Case("e5500", "e5500")
64
91
        .Case("power3", "pwr3")
65
91
        .Case("power4", "pwr4")
66
91
        .Case("power5", "pwr5")
67
91
        .Case("power5x", "pwr5x")
68
91
        .Case("power6", "pwr6")
69
91
        .Case("power6x", "pwr6x")
70
91
        .Case("power7", "pwr7")
71
91
        .Case("power8", "pwr8")
72
91
        .Case("power9", "pwr9")
73
91
        .Case("future", "future")
74
91
        .Case("pwr3", "pwr3")
75
91
        .Case("pwr4", "pwr4")
76
91
        .Case("pwr5", "pwr5")
77
91
        .Case("pwr5x", "pwr5x")
78
91
        .Case("pwr6", "pwr6")
79
91
        .Case("pwr6x", "pwr6x")
80
91
        .Case("pwr7", "pwr7")
81
91
        .Case("pwr8", "pwr8")
82
91
        .Case("pwr9", "pwr9")
83
91
        .Case("powerpc", "ppc")
84
91
        .Case("powerpc64", "ppc64")
85
91
        .Case("powerpc64le", "ppc64le")
86
91
        .Default("");
87
91
  }
88
310
89
310
  return "";
90
310
}
91
92
10
const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
93
10
  return llvm::StringSwitch<const char *>(Name)
94
10
        .Case("pwr7", "-mpower7")
95
10
        .Case("power7", "-mpower7")
96
10
        .Case("pwr8", "-mpower8")
97
10
        .Case("power8", "-mpower8")
98
10
        .Case("ppc64le", "-mpower8")
99
10
        .Case("pwr9", "-mpower9")
100
10
        .Case("power9", "-mpower9")
101
10
        .Default("-many");
102
10
}
103
104
void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
105
                               const ArgList &Args,
106
390
                               std::vector<StringRef> &Features) {
107
390
  if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
108
2
    Features.push_back("+spe");
109
390
110
390
  handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group);
111
390
112
390
  ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
113
390
  if (FloatABI == ppc::FloatABI::Soft)
114
9
    Features.push_back("-hard-float");
115
390
116
390
  ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
117
390
  if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
118
24
    Features.push_back("+secure-plt");
119
390
}
120
121
ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
122
390
                                              const ArgList &Args) {
123
390
  if (Args.getLastArg(options::OPT_msecure_plt))
124
1
    return ppc::ReadGOTPtrMode::SecurePlt;
125
389
  if ((Triple.isOSFreeBSD() && 
Triple.getOSMajorVersion() >= 1310
) ||
126
389
      
Triple.isOSNetBSD()386
||
Triple.isOSOpenBSD()377
||
Triple.isMusl()373
)
127
23
    return ppc::ReadGOTPtrMode::SecurePlt;
128
366
  else
129
366
    return ppc::ReadGOTPtrMode::Bss;
130
389
}
131
132
744
ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
133
744
  ppc::FloatABI ABI = ppc::FloatABI::Invalid;
134
744
  if (Arg *A =
135
26
          Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
136
26
                          options::OPT_mfloat_abi_EQ)) {
137
26
    if (A->getOption().matches(options::OPT_msoft_float))
138
12
      ABI = ppc::FloatABI::Soft;
139
14
    else if (A->getOption().matches(options::OPT_mhard_float))
140
4
      ABI = ppc::FloatABI::Hard;
141
10
    else {
142
10
      ABI = llvm::StringSwitch<ppc::FloatABI>(A->getValue())
143
10
                .Case("soft", ppc::FloatABI::Soft)
144
10
                .Case("hard", ppc::FloatABI::Hard)
145
10
                .Default(ppc::FloatABI::Invalid);
146
10
      if (ABI == ppc::FloatABI::Invalid && 
!StringRef(A->getValue()).empty()2
) {
147
2
        D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
148
2
        ABI = ppc::FloatABI::Hard;
149
2
      }
150
10
    }
151
26
  }
152
744
153
744
  // If unspecified, choose the default based on the platform.
154
744
  if (ABI == ppc::FloatABI::Invalid) {
155
718
    ABI = ppc::FloatABI::Hard;
156
718
  }
157
744
158
744
  return ABI;
159
744
}
160
161
114
bool ppc::hasPPCAbiArg(const ArgList &Args, const char *Value) {
162
114
  Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
163
114
  return A && 
(A->getValue() == StringRef(Value))21
;
164
114
}