Coverage Report

Created: 2020-09-22 08:39

/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
445
std::string ppc::getPPCTargetCPU(const ArgList &Args) {
25
445
  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
26
96
    StringRef CPUName = A->getValue();
27
28
96
    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
96
    }
35
36
96
    return llvm::StringSwitch<const char *>(CPUName)
37
96
        .Case("common", "generic")
38
96
        .Case("440", "440")
39
96
        .Case("440fp", "440")
40
96
        .Case("450", "450")
41
96
        .Case("601", "601")
42
96
        .Case("602", "602")
43
96
        .Case("603", "603")
44
96
        .Case("603e", "603e")
45
96
        .Case("603ev", "603ev")
46
96
        .Case("604", "604")
47
96
        .Case("604e", "604e")
48
96
        .Case("620", "620")
49
96
        .Case("630", "pwr3")
50
96
        .Case("G3", "g3")
51
96
        .Case("7400", "7400")
52
96
        .Case("G4", "g4")
53
96
        .Case("7450", "7450")
54
96
        .Case("G4+", "g4+")
55
96
        .Case("750", "750")
56
96
        .Case("8548", "e500")
57
96
        .Case("970", "970")
58
96
        .Case("G5", "g5")
59
96
        .Case("a2", "a2")
60
96
        .Case("e500", "e500")
61
96
        .Case("e500mc", "e500mc")
62
96
        .Case("e5500", "e5500")
63
96
        .Case("power3", "pwr3")
64
96
        .Case("power4", "pwr4")
65
96
        .Case("power5", "pwr5")
66
96
        .Case("power5x", "pwr5x")
67
96
        .Case("power6", "pwr6")
68
96
        .Case("power6x", "pwr6x")
69
96
        .Case("power7", "pwr7")
70
96
        .Case("power8", "pwr8")
71
96
        .Case("power9", "pwr9")
72
96
        .Case("power10", "pwr10")
73
96
        .Case("future", "future")
74
96
        .Case("pwr3", "pwr3")
75
96
        .Case("pwr4", "pwr4")
76
96
        .Case("pwr5", "pwr5")
77
96
        .Case("pwr5x", "pwr5x")
78
96
        .Case("pwr6", "pwr6")
79
96
        .Case("pwr6x", "pwr6x")
80
96
        .Case("pwr7", "pwr7")
81
96
        .Case("pwr8", "pwr8")
82
96
        .Case("pwr9", "pwr9")
83
96
        .Case("pwr10", "pwr10")
84
96
        .Case("powerpc", "ppc")
85
96
        .Case("powerpc64", "ppc64")
86
96
        .Case("powerpc64le", "ppc64le")
87
96
        .Default("");
88
96
  }
89
90
349
  return "";
91
349
}
92
93
10
const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
94
10
  return llvm::StringSwitch<const char *>(Name)
95
10
      .Case("pwr7", "-mpower7")
96
10
      .Case("power7", "-mpower7")
97
10
      .Case("pwr8", "-mpower8")
98
10
      .Case("power8", "-mpower8")
99
10
      .Case("ppc64le", "-mpower8")
100
10
      .Case("pwr9", "-mpower9")
101
10
      .Case("power9", "-mpower9")
102
10
      .Case("pwr10", "-mpower10")
103
10
      .Case("power10", "-mpower10")
104
10
      .Default("-many");
105
10
}
106
107
void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
108
                               const ArgList &Args,
109
434
                               std::vector<StringRef> &Features) {
110
434
  if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
111
2
    Features.push_back("+spe");
112
113
434
  handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group);
114
115
434
  ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
116
434
  if (FloatABI == ppc::FloatABI::Soft)
117
9
    Features.push_back("-hard-float");
118
119
434
  ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
120
434
  if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
121
27
    Features.push_back("+secure-plt");
122
434
}
123
124
ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
125
434
                                              const ArgList &Args) {
126
434
  if (Args.getLastArg(options::OPT_msecure_plt))
127
1
    return ppc::ReadGOTPtrMode::SecurePlt;
128
433
  if ((Triple.isOSFreeBSD() && 
Triple.getOSMajorVersion() >= 1314
) ||
129
428
      Triple.isOSNetBSD() || 
Triple.isOSOpenBSD()419
||
Triple.isMusl()414
)
130
26
    return ppc::ReadGOTPtrMode::SecurePlt;
131
407
  else
132
407
    return ppc::ReadGOTPtrMode::Bss;
133
433
}
134
135
832
ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
136
832
  ppc::FloatABI ABI = ppc::FloatABI::Invalid;
137
832
  if (Arg *A =
138
26
          Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
139
26
                          options::OPT_mfloat_abi_EQ)) {
140
26
    if (A->getOption().matches(options::OPT_msoft_float))
141
12
      ABI = ppc::FloatABI::Soft;
142
14
    else if (A->getOption().matches(options::OPT_mhard_float))
143
4
      ABI = ppc::FloatABI::Hard;
144
10
    else {
145
10
      ABI = llvm::StringSwitch<ppc::FloatABI>(A->getValue())
146
10
                .Case("soft", ppc::FloatABI::Soft)
147
10
                .Case("hard", ppc::FloatABI::Hard)
148
10
                .Default(ppc::FloatABI::Invalid);
149
10
      if (ABI == ppc::FloatABI::Invalid && 
!StringRef(A->getValue()).empty()2
) {
150
2
        D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
151
2
        ABI = ppc::FloatABI::Hard;
152
2
      }
153
10
    }
154
26
  }
155
156
  // If unspecified, choose the default based on the platform.
157
832
  if (ABI == ppc::FloatABI::Invalid) {
158
806
    ABI = ppc::FloatABI::Hard;
159
806
  }
160
161
832
  return ABI;
162
832
}
163
164
110
bool ppc::hasPPCAbiArg(const ArgList &Args, const char *Value) {
165
110
  Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
166
110
  return A && 
(A->getValue() == StringRef(Value))19
;
167
110
}