clang  15.0.0git
VEToolchain.cpp
Go to the documentation of this file.
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"
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  : Linux(D, Triple, Args) {
28  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/linux/ve, (== getArchSpecificLibPath)
37  // /lib/../lib64,
38  // /usr/lib/../lib64,
39  // ${BINPATH}/../lib,
40  // /lib,
41  // /usr/lib,
42  // These are OK for host, but no go for VE.
43 
44  // Define file paths from scratch here.
45  getFilePaths().clear();
46 
47  // Add library directories:
48  // ${BINPATH}/../lib/ve-unknown-linux-gnu, (== getStdlibPath)
49  // ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPath)
50  // ${SYSROOT}/opt/nec/ve/lib,
51  for (auto &Path : getStdlibPaths())
52  getFilePaths().push_back(std::move(Path));
53  getFilePaths().push_back(getArchSpecificLibPath());
54  getFilePaths().push_back(computeSysRoot() + "/opt/nec/ve/lib");
55 }
56 
58  return new tools::gnutools::Assembler(*this);
59 }
60 
62  return new tools::gnutools::Linker(*this);
63 }
64 
65 bool VEToolChain::isPICDefault() const { return false; }
66 
67 bool VEToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
68  return false;
69 }
70 
71 bool VEToolChain::isPICDefaultForced() const { return false; }
72 
73 bool VEToolChain::SupportsProfiling() const { return false; }
74 
75 bool VEToolChain::hasBlocksRuntime() const { return false; }
76 
77 void VEToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
78  ArgStringList &CC1Args) const {
79  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
80  return;
81 
82  if (DriverArgs.hasArg(options::OPT_nobuiltininc) &&
83  DriverArgs.hasArg(options::OPT_nostdlibinc))
84  return;
85 
86  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
87  SmallString<128> P(getDriver().ResourceDir);
88  llvm::sys::path::append(P, "include");
89  addSystemInclude(DriverArgs, CC1Args, P);
90  }
91 
92  if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
93  if (const char *cl_include_dir = getenv("NCC_C_INCLUDE_PATH")) {
95  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
96  StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
97  ArrayRef<StringRef> DirVec(Dirs);
98  addSystemIncludes(DriverArgs, CC1Args, DirVec);
99  } else {
100  addSystemInclude(DriverArgs, CC1Args,
101  getDriver().SysRoot + "/opt/nec/ve/include");
102  }
103  }
104 }
105 
106 void VEToolChain::addClangTargetOptions(const ArgList &DriverArgs,
107  ArgStringList &CC1Args,
108  Action::OffloadKind) const {
109  CC1Args.push_back("-nostdsysteminc");
110  bool UseInitArrayDefault = true;
111  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
112  options::OPT_fno_use_init_array, UseInitArrayDefault))
113  CC1Args.push_back("-fno-use-init-array");
114 }
115 
116 void VEToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
117  ArgStringList &CC1Args) const {
118  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
119  DriverArgs.hasArg(options::OPT_nostdlibinc) ||
120  DriverArgs.hasArg(options::OPT_nostdincxx))
121  return;
122  if (const char *cl_include_dir = getenv("NCC_CPLUS_INCLUDE_PATH")) {
124  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
125  StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
126  ArrayRef<StringRef> DirVec(Dirs);
127  addSystemIncludes(DriverArgs, CC1Args, DirVec);
128  } else {
129  // Add following paths for multiple target installation.
130  // ${INSTALLDIR}/include/ve-unknown-linux-gnu/c++/v1,
131  // ${INSTALLDIR}/include/c++/v1,
132  addLibCxxIncludePaths(DriverArgs, CC1Args);
133  }
134 }
135 
136 void VEToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
137  ArgStringList &CmdArgs) const {
138  assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
139  "Only -lc++ (aka libxx) is supported in this toolchain.");
140 
141  tools::addArchSpecificRPath(*this, Args, CmdArgs);
142 
143  CmdArgs.push_back("-lc++");
144  CmdArgs.push_back("-lc++abi");
145  CmdArgs.push_back("-lunwind");
146  // libc++ requires -lpthread under glibc environment
147  CmdArgs.push_back("-lpthread");
148  // libunwind requires -ldl under glibc environment
149  CmdArgs.push_back("-ldl");
150 }
151 
152 llvm::ExceptionHandling
153 VEToolChain::GetExceptionModel(const ArgList &Args) const {
154  // VE uses SjLj exceptions.
155  return llvm::ExceptionHandling::SjLj;
156 }
clang::driver::toolchains
Definition: AIX.h:55
VEToolchain.h
clang::driver::ToolChain::getProgramPaths
path_list & getProgramPaths()
Definition: ToolChain.h:269
Driver.h
clang::driver::toolchains::Generic_GCC::addLibCxxIncludePaths
virtual void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Gnu.cpp:3012
clang::driver::toolchains::VEToolChain::buildAssembler
Tool * buildAssembler() const override
Definition: VEToolchain.cpp:57
clang::driver::toolchains::VEToolChain::hasBlocksRuntime
bool hasBlocksRuntime() const override
hasBlocksRuntime - Given that the user is compiling with -fblocks, does this tool chain guarantee the...
Definition: VEToolchain.cpp:75
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::toolchains::VEToolChain::isPIEDefault
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition: VEToolchain.cpp:67
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:228
clang::driver::toolchains::VEToolChain::addClangTargetOptions
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: VEToolchain.cpp:106
clang::driver::toolchains::VEToolChain::AddCXXStdlibLibArgs
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: VEToolchain.cpp:136
clang::driver::toolchains::VEToolChain::AddClangCXXStdlibIncludeArgs
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: VEToolchain.cpp:116
clang::driver::toolchains::VEToolChain::AddClangSystemIncludeArgs
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: VEToolchain.cpp:77
clang::driver::ToolChain::getFilePaths
path_list & getFilePaths()
Definition: ToolChain.h:266
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
Options.h
clang::driver::tools::gnutools::Linker
Definition: Gnu.h:53
clang::driver::toolchains::VEToolChain::isPICDefaultForced
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: VEToolchain.cpp:71
llvm::opt
Definition: DiagnosticOptions.h:19
clang::driver::toolchains::VEToolChain::buildLinker
Tool * buildLinker() const override
Definition: VEToolchain.cpp:61
llvm::SmallString< 128 >
clang::driver::ToolChain::getStdlibPaths
path_list getStdlibPaths() const
Definition: ToolChain.cpp:560
clang::driver::toolchains::Linux
Definition: Linux.h:19
clang::driver::ToolChain::CST_Libcxx
@ CST_Libcxx
Definition: ToolChain.h:96
clang::driver::toolchains::Linux::computeSysRoot
std::string computeSysRoot() const override
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition: Linux.cpp:351
clang::driver::toolchains::VEToolChain::GetCXXStdlibType
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: VEToolchain.h:51
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::driver::ToolChain::addSystemIncludes
static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, ArrayRef< StringRef > Paths)
Utility function to add a list of system include directories to CC1.
Definition: ToolChain.cpp:936
clang::driver::ToolChain::getArchSpecificLibPath
std::string getArchSpecificLibPath() const
Definition: ToolChain.cpp:569
Compilation.h
clang::driver::toolchains::VEToolChain::GetExceptionModel
llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const override
GetExceptionModel - Return the tool chain exception model.
Definition: VEToolchain.cpp:153
clang::driver::toolchains::VEToolChain::VEToolChain
VEToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
VE tool chain.
Definition: VEToolchain.cpp:25
llvm::ArrayRef
Definition: LLVM.h:34
clang::driver::toolchains::VEToolChain::isPICDefault
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: VEToolchain.cpp:65
clang::driver::tools::gnutools::Assembler
Definition: Gnu.h:41
clang::driver::tools::addArchSpecificRPath
void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::toolchains::VEToolChain::SupportsProfiling
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: VEToolchain.cpp:73
CommonArgs.h
clang
Definition: CalledOnceCheck.h:17
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:72
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:88
clang::driver
Definition: Action.h:31
clang::driver::ToolChain::addSystemInclude
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:906