Coverage Report

Created: 2019-07-24 05:18

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