Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Driver/ToolChains/AMDGPU.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- AMDGPU.cpp - AMDGPU ToolChain Implementations ----------*- 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 "AMDGPU.h"
10
#include "CommonArgs.h"
11
#include "InputInfo.h"
12
#include "clang/Driver/Compilation.h"
13
#include "clang/Driver/DriverDiagnostic.h"
14
#include "llvm/Option/ArgList.h"
15
16
using namespace clang::driver;
17
using namespace clang::driver::tools;
18
using namespace clang::driver::toolchains;
19
using namespace clang;
20
using namespace llvm::opt;
21
22
void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
23
                                  const InputInfo &Output,
24
                                  const InputInfoList &Inputs,
25
                                  const ArgList &Args,
26
9
                                  const char *LinkingOutput) const {
27
9
28
9
  std::string Linker = getToolChain().GetProgramPath(getShortName());
29
9
  ArgStringList CmdArgs;
30
9
  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
31
9
  CmdArgs.push_back("-shared");
32
9
  CmdArgs.push_back("-o");
33
9
  CmdArgs.push_back(Output.getFilename());
34
9
  C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker),
35
9
                                          CmdArgs, Inputs));
36
9
}
37
38
void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
39
                                     const llvm::opt::ArgList &Args,
40
198
                                     std::vector<StringRef> &Features) {
41
198
  if (const Arg *dAbi = Args.getLastArg(options::OPT_mamdgpu_debugger_abi))
42
2
    D.Diag(diag::err_drv_clang_unsupported) << dAbi->getAsString(Args);
43
198
44
198
  if (Args.getLastArg(options::OPT_mwavefrontsize64)) {
45
1
    Features.push_back("-wavefrontsize16");
46
1
    Features.push_back("-wavefrontsize32");
47
1
    Features.push_back("+wavefrontsize64");
48
1
  }
49
198
  if (Args.getLastArg(options::OPT_mno_wavefrontsize64)) {
50
1
    Features.push_back("-wavefrontsize16");
51
1
    Features.push_back("+wavefrontsize32");
52
1
    Features.push_back("-wavefrontsize64");
53
1
  }
54
198
55
198
  handleTargetFeaturesGroup(
56
198
    Args, Features, options::OPT_m_amdgpu_Features_Group);
57
198
}
58
59
/// AMDGPU Toolchain
60
AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
61
                                 const ArgList &Args)
62
    : Generic_ELF(D, Triple, Args),
63
      OptionsDefault({{options::OPT_O, "3"},
64
30
                      {options::OPT_cl_std_EQ, "CL1.2"}}) {}
65
66
9
Tool *AMDGPUToolChain::buildLinker() const {
67
9
  return new tools::amdgpu::Linker(*this);
68
9
}
69
70
DerivedArgList *
71
AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
72
29
                               Action::OffloadKind DeviceOffloadKind) const {
73
29
74
29
  DerivedArgList *DAL =
75
29
      Generic_ELF::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
76
29
77
29
  // Do nothing if not OpenCL (-x cl)
78
29
  if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
79
17
    return DAL;
80
12
81
12
  if (!DAL)
82
12
    DAL = new DerivedArgList(Args.getBaseArgs());
83
12
  for (auto *A : Args)
84
103
    DAL->append(A);
85
12
86
12
  const OptTable &Opts = getDriver().getOpts();
87
12
88
12
  // Phase 1 (.cl -> .bc)
89
12
  if (Args.hasArg(options::OPT_c) && Args.hasArg(options::OPT_emit_llvm)) {
90
12
    DAL->AddFlagArg(nullptr, Opts.getOption(getTriple().isArch64Bit()
91
12
                                                ? options::OPT_m64
92
12
                                                : 
options::OPT_m320
));
93
12
94
12
    // Have to check OPT_O4, OPT_O0 & OPT_Ofast separately
95
12
    // as they defined that way in Options.td
96
12
    if (!Args.hasArg(options::OPT_O, options::OPT_O0, options::OPT_O4,
97
12
                     options::OPT_Ofast))
98
4
      DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O),
99
4
                        getOptionDefault(options::OPT_O));
100
12
  }
101
12
102
12
  return DAL;
103
12
}
104
105
void AMDGPUToolChain::addClangTargetOptions(
106
    const llvm::opt::ArgList &DriverArgs,
107
    llvm::opt::ArgStringList &CC1Args,
108
26
    Action::OffloadKind DeviceOffloadingKind) const {
109
26
  // Default to "hidden" visibility, as object level linking will not be
110
26
  // supported for the foreseeable future.
111
26
  if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
112
26
                         options::OPT_fvisibility_ms_compat)) {
113
24
    CC1Args.push_back("-fvisibility");
114
24
    CC1Args.push_back("hidden");
115
24
    CC1Args.push_back("-fapply-global-visibility-to-externs");
116
24
  }
117
26
}