Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/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
#include "llvm/Support/TargetParser.h"
16
17
using namespace clang::driver;
18
using namespace clang::driver::tools;
19
using namespace clang::driver::toolchains;
20
using namespace clang;
21
using namespace llvm::opt;
22
23
void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
24
                                  const InputInfo &Output,
25
                                  const InputInfoList &Inputs,
26
                                  const ArgList &Args,
27
9
                                  const char *LinkingOutput) const {
28
9
29
9
  std::string Linker = getToolChain().GetProgramPath(getShortName());
30
9
  ArgStringList CmdArgs;
31
9
  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
32
9
  CmdArgs.push_back("-shared");
33
9
  CmdArgs.push_back("-o");
34
9
  CmdArgs.push_back(Output.getFilename());
35
9
  C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Linker),
36
9
                                          CmdArgs, Inputs));
37
9
}
38
39
void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
40
                                     const llvm::opt::ArgList &Args,
41
247
                                     std::vector<StringRef> &Features) {
42
247
  if (const Arg *dAbi = Args.getLastArg(options::OPT_mamdgpu_debugger_abi))
43
2
    D.Diag(diag::err_drv_clang_unsupported) << dAbi->getAsString(Args);
44
247
45
247
  if (Args.getLastArg(options::OPT_mwavefrontsize64)) {
46
1
    Features.push_back("-wavefrontsize16");
47
1
    Features.push_back("-wavefrontsize32");
48
1
    Features.push_back("+wavefrontsize64");
49
1
  }
50
247
  if (Args.getLastArg(options::OPT_mno_wavefrontsize64)) {
51
1
    Features.push_back("-wavefrontsize16");
52
1
    Features.push_back("+wavefrontsize32");
53
1
    Features.push_back("-wavefrontsize64");
54
1
  }
55
247
56
247
  handleTargetFeaturesGroup(
57
247
    Args, Features, options::OPT_m_amdgpu_Features_Group);
58
247
}
59
60
/// AMDGPU Toolchain
61
AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
62
                                 const ArgList &Args)
63
    : Generic_ELF(D, Triple, Args),
64
      OptionsDefault({{options::OPT_O, "3"},
65
43
                      {options::OPT_cl_std_EQ, "CL1.2"}}) {}
66
67
9
Tool *AMDGPUToolChain::buildLinker() const {
68
9
  return new tools::amdgpu::Linker(*this);
69
9
}
70
71
DerivedArgList *
72
AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
73
42
                               Action::OffloadKind DeviceOffloadKind) const {
74
42
75
42
  DerivedArgList *DAL =
76
42
      Generic_ELF::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
77
42
78
42
  // Do nothing if not OpenCL (-x cl)
79
42
  if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
80
30
    return DAL;
81
12
82
12
  if (!DAL)
83
12
    DAL = new DerivedArgList(Args.getBaseArgs());
84
12
  for (auto *A : Args)
85
103
    DAL->append(A);
86
12
87
12
  const OptTable &Opts = getDriver().getOpts();
88
12
89
12
  // Phase 1 (.cl -> .bc)
90
12
  if (Args.hasArg(options::OPT_c) && Args.hasArg(options::OPT_emit_llvm)) {
91
12
    DAL->AddFlagArg(nullptr, Opts.getOption(getTriple().isArch64Bit()
92
12
                                                ? options::OPT_m64
93
12
                                                : 
options::OPT_m320
));
94
12
95
12
    // Have to check OPT_O4, OPT_O0 & OPT_Ofast separately
96
12
    // as they defined that way in Options.td
97
12
    if (!Args.hasArg(options::OPT_O, options::OPT_O0, options::OPT_O4,
98
12
                     options::OPT_Ofast))
99
4
      DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_O),
100
4
                        getOptionDefault(options::OPT_O));
101
12
  }
102
12
103
12
  return DAL;
104
12
}
105
106
llvm::DenormalMode AMDGPUToolChain::getDefaultDenormalModeForType(
107
    const llvm::opt::ArgList &DriverArgs, Action::OffloadKind DeviceOffloadKind,
108
78
    const llvm::fltSemantics *FPType) const {
109
78
  // Denormals should always be enabled for f16 and f64.
110
78
  if (!FPType || 
FPType != &llvm::APFloat::IEEEsingle()39
)
111
39
    return llvm::DenormalMode::getIEEE();
112
39
113
39
  if (DeviceOffloadKind == Action::OFK_Cuda) {
114
0
    if (FPType && FPType == &llvm::APFloat::IEEEsingle() &&
115
0
        DriverArgs.hasFlag(options::OPT_fcuda_flush_denormals_to_zero,
116
0
                           options::OPT_fno_cuda_flush_denormals_to_zero,
117
0
                           false))
118
0
      return llvm::DenormalMode::getPreserveSign();
119
39
  }
120
39
121
39
  const StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_mcpu_EQ);
122
39
  auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
123
39
124
39
  // Default to enabling f32 denormals by default on subtargets where fma is
125
39
  // fast with denormals
126
39
127
39
  const unsigned ArchAttr = llvm::AMDGPU::getArchAttrAMDGCN(Kind);
128
39
  const bool DefaultDenormsAreZeroForTarget =
129
39
    (ArchAttr & llvm::AMDGPU::FEATURE_FAST_FMA_F32) &&
130
39
    
(ArchAttr & llvm::AMDGPU::FEATURE_FAST_DENORMAL_F32)16
;
131
39
132
39
  // TODO: There are way too many flags that change this. Do we need to check
133
39
  // them all?
134
39
  bool DAZ = DriverArgs.hasArg(options::OPT_cl_denorms_are_zero) ||
135
39
             
!DefaultDenormsAreZeroForTarget35
;
136
39
  // Outputs are flushed to zero, preserving sign
137
39
  return DAZ ? 
llvm::DenormalMode::getPreserveSign()38
:
138
39
               
llvm::DenormalMode::getIEEE()1
;
139
39
}
140
141
void AMDGPUToolChain::addClangTargetOptions(
142
    const llvm::opt::ArgList &DriverArgs,
143
    llvm::opt::ArgStringList &CC1Args,
144
39
    Action::OffloadKind DeviceOffloadingKind) const {
145
39
  // Default to "hidden" visibility, as object level linking will not be
146
39
  // supported for the foreseeable future.
147
39
  if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
148
39
                         options::OPT_fvisibility_ms_compat)) {
149
37
    CC1Args.push_back("-fvisibility");
150
37
    CC1Args.push_back("hidden");
151
37
    CC1Args.push_back("-fapply-global-visibility-to-externs");
152
37
  }
153
39
}