Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/SPIRV.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- SPIRV.cpp - SPIR-V Tool 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
#include "SPIRV.h"
9
#include "CommonArgs.h"
10
#include "clang/Driver/Compilation.h"
11
#include "clang/Driver/Driver.h"
12
#include "clang/Driver/InputInfo.h"
13
#include "clang/Driver/Options.h"
14
15
using namespace clang::driver;
16
using namespace clang::driver::toolchains;
17
using namespace clang::driver::tools;
18
using namespace llvm::opt;
19
20
void SPIRV::constructTranslateCommand(Compilation &C, const Tool &T,
21
                                      const JobAction &JA,
22
                                      const InputInfo &Output,
23
                                      const InputInfo &Input,
24
34
                                      const llvm::opt::ArgStringList &Args) {
25
34
  llvm::opt::ArgStringList CmdArgs(Args);
26
34
  CmdArgs.push_back(Input.getFilename());
27
28
34
  if (Input.getType() == types::TY_PP_Asm)
29
3
    CmdArgs.push_back("-to-binary");
30
34
  if (Output.getType() == types::TY_PP_Asm)
31
7
    CmdArgs.push_back("--spirv-tools-dis");
32
33
34
  CmdArgs.append({"-o", Output.getFilename()});
34
35
34
  const char *Exec =
36
34
      C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
37
34
  C.addCommand(std::make_unique<Command>(JA, T, ResponseFileSupport::None(),
38
34
                                         Exec, CmdArgs, Input, Output));
39
34
}
40
41
void SPIRV::Translator::ConstructJob(Compilation &C, const JobAction &JA,
42
                                     const InputInfo &Output,
43
                                     const InputInfoList &Inputs,
44
                                     const ArgList &Args,
45
25
                                     const char *LinkingOutput) const {
46
25
  claimNoWarnArgs(Args);
47
25
  if (Inputs.size() != 1)
48
0
    llvm_unreachable("Invalid number of input files.");
49
25
  constructTranslateCommand(C, *this, JA, Output, Inputs[0], {});
50
25
}
51
52
25
clang::driver::Tool *SPIRVToolChain::getTranslator() const {
53
25
  if (!Translator)
54
23
    Translator = std::make_unique<SPIRV::Translator>(*this);
55
25
  return Translator.get();
56
25
}
57
58
75
clang::driver::Tool *SPIRVToolChain::SelectTool(const JobAction &JA) const {
59
75
  Action::ActionClass AC = JA.getKind();
60
75
  return SPIRVToolChain::getTool(AC);
61
75
}
62
63
75
clang::driver::Tool *SPIRVToolChain::getTool(Action::ActionClass AC) const {
64
75
  switch (AC) {
65
50
  default:
66
50
    break;
67
50
  case Action::BackendJobClass:
68
25
  case Action::AssembleJobClass:
69
25
    return SPIRVToolChain::getTranslator();
70
75
  }
71
50
  return ToolChain::getTool(AC);
72
75
}
73
5
clang::driver::Tool *SPIRVToolChain::buildLinker() const {
74
5
  return new tools::SPIRV::Linker(*this);
75
5
}
76
77
void SPIRV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
78
                                 const InputInfo &Output,
79
                                 const InputInfoList &Inputs,
80
                                 const ArgList &Args,
81
5
                                 const char *LinkingOutput) const {
82
5
  const ToolChain &ToolChain = getToolChain();
83
5
  std::string Linker = ToolChain.GetProgramPath(getShortName());
84
5
  ArgStringList CmdArgs;
85
5
  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
86
87
5
  CmdArgs.push_back("-o");
88
5
  CmdArgs.push_back(Output.getFilename());
89
90
5
  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
91
5
                                         Args.MakeArgString(Linker), CmdArgs,
92
5
                                         Inputs, Output));
93
5
}