Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/clang/lib/Driver/ToolChains/VEToolchain.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- VE.cpp - VE 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 "VEToolchain.h"
10
#include "CommonArgs.h"
11
#include "clang/Driver/Compilation.h"
12
#include "clang/Driver/Driver.h"
13
#include "clang/Driver/Options.h"
14
#include "llvm/Option/ArgList.h"
15
#include "llvm/Support/FileSystem.h"
16
#include "llvm/Support/Path.h"
17
#include <cstdlib> // ::getenv
18
19
using namespace clang::driver;
20
using namespace clang::driver::toolchains;
21
using namespace clang;
22
using namespace llvm::opt;
23
24
/// VE tool chain
25
VEToolChain::VEToolChain(const Driver &D, const llvm::Triple &Triple,
26
                         const ArgList &Args)
27
0
    : Linux(D, Triple, Args) {
28
0
  getProgramPaths().push_back("/opt/nec/ve/bin");
29
  // ProgramPaths are found via 'PATH' environment variable.
30
31
  // Default library paths are following:
32
  //   ${RESOURCEDIR}/lib/ve-unknown-linux-gnu,
33
  // These are OK.
34
35
  // Default file paths are following:
36
  //   ${RESOURCEDIR}/lib/ve-unknown-linux-gnu, (== getArchSpecificLibPaths)
37
  //   ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
38
  //   /lib/../lib64,
39
  //   /usr/lib/../lib64,
40
  //   ${BINPATH}/../lib,
41
  //   /lib,
42
  //   /usr/lib,
43
  // These are OK for host, but no go for VE.
44
45
  // Define file paths from scratch here.
46
0
  getFilePaths().clear();
47
48
  // Add library directories:
49
  //   ${BINPATH}/../lib/ve-unknown-linux-gnu, (== getStdlibPath)
50
  //   ${RESOURCEDIR}/lib/ve-unknown-linux-gnu, (== getArchSpecificLibPaths)
51
  //   ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
52
  //   ${SYSROOT}/opt/nec/ve/lib,
53
0
  if (std::optional<std::string> Path = getStdlibPath())
54
0
    getFilePaths().push_back(std::move(*Path));
55
0
  for (const auto &Path : getArchSpecificLibPaths())
56
0
    getFilePaths().push_back(Path);
57
0
  getFilePaths().push_back(computeSysRoot() + "/opt/nec/ve/lib");
58
0
}
59
60
0
Tool *VEToolChain::buildAssembler() const {
61
0
  return new tools::gnutools::Assembler(*this);
62
0
}
63
64
0
Tool *VEToolChain::buildLinker() const {
65
0
  return new tools::gnutools::Linker(*this);
66
0
}
67
68
0
bool VEToolChain::isPICDefault() const { return false; }
69
70
0
bool VEToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
71
0
  return false;
72
0
}
73
74
0
bool VEToolChain::isPICDefaultForced() const { return false; }
75
76
0
bool VEToolChain::SupportsProfiling() const { return false; }
77
78
0
bool VEToolChain::hasBlocksRuntime() const { return false; }
79
80
void VEToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
81
0
                                            ArgStringList &CC1Args) const {
82
0
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
83
0
    return;
84
85
0
  if (DriverArgs.hasArg(options::OPT_nobuiltininc) &&
86
0
      DriverArgs.hasArg(options::OPT_nostdlibinc))
87
0
    return;
88
89
0
  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
90
0
    SmallString<128> P(getDriver().ResourceDir);
91
0
    llvm::sys::path::append(P, "include");
92
0
    addSystemInclude(DriverArgs, CC1Args, P);
93
0
  }
94
95
0
  if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
96
0
    if (const char *cl_include_dir = getenv("NCC_C_INCLUDE_PATH")) {
97
0
      SmallVector<StringRef, 4> Dirs;
98
0
      const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
99
0
      StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
100
0
      ArrayRef<StringRef> DirVec(Dirs);
101
0
      addSystemIncludes(DriverArgs, CC1Args, DirVec);
102
0
    } else {
103
0
      addSystemInclude(DriverArgs, CC1Args,
104
0
                       getDriver().SysRoot + "/opt/nec/ve/include");
105
0
    }
106
0
  }
107
0
}
108
109
void VEToolChain::addClangTargetOptions(const ArgList &DriverArgs,
110
                                        ArgStringList &CC1Args,
111
0
                                        Action::OffloadKind) const {
112
0
  CC1Args.push_back("-nostdsysteminc");
113
0
  bool UseInitArrayDefault = true;
114
0
  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
115
0
                          options::OPT_fno_use_init_array, UseInitArrayDefault))
116
0
    CC1Args.push_back("-fno-use-init-array");
117
0
}
118
119
void VEToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
120
0
                                               ArgStringList &CC1Args) const {
121
0
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
122
0
      DriverArgs.hasArg(options::OPT_nostdlibinc) ||
123
0
      DriverArgs.hasArg(options::OPT_nostdincxx))
124
0
    return;
125
0
  if (const char *cl_include_dir = getenv("NCC_CPLUS_INCLUDE_PATH")) {
126
0
    SmallVector<StringRef, 4> Dirs;
127
0
    const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
128
0
    StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
129
0
    ArrayRef<StringRef> DirVec(Dirs);
130
0
    addSystemIncludes(DriverArgs, CC1Args, DirVec);
131
0
  } else {
132
    // Add following paths for multiple target installation.
133
    //   ${INSTALLDIR}/include/ve-unknown-linux-gnu/c++/v1,
134
    //   ${INSTALLDIR}/include/c++/v1,
135
0
    addLibCxxIncludePaths(DriverArgs, CC1Args);
136
0
  }
137
0
}
138
139
void VEToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
140
0
                                      ArgStringList &CmdArgs) const {
141
0
  assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
142
0
         "Only -lc++ (aka libxx) is supported in this toolchain.");
143
144
0
  tools::addArchSpecificRPath(*this, Args, CmdArgs);
145
146
  // Add paths for libc++.so and other shared libraries.
147
0
  if (std::optional<std::string> Path = getStdlibPath()) {
148
0
    CmdArgs.push_back("-rpath");
149
0
    CmdArgs.push_back(Args.MakeArgString(*Path));
150
0
  }
151
152
0
  CmdArgs.push_back("-lc++");
153
0
  if (Args.hasArg(options::OPT_fexperimental_library))
154
0
    CmdArgs.push_back("-lc++experimental");
155
0
  CmdArgs.push_back("-lc++abi");
156
0
  CmdArgs.push_back("-lunwind");
157
  // libc++ requires -lpthread under glibc environment
158
0
  CmdArgs.push_back("-lpthread");
159
  // libunwind requires -ldl under glibc environment
160
0
  CmdArgs.push_back("-ldl");
161
0
}
162
163
llvm::ExceptionHandling
164
0
VEToolChain::GetExceptionModel(const ArgList &Args) const {
165
  // VE uses SjLj exceptions.
166
0
  return llvm::ExceptionHandling::SjLj;
167
0
}