1 //===--- VE.cpp - VE ToolChain Implementations ------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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
19 using namespace clang::driver
;
20 using namespace clang::driver::toolchains
;
21 using namespace clang
;
22 using namespace llvm::opt
;
25 VEToolChain::VEToolChain(const Driver
&D
, const llvm::Triple
&Triple
,
27 : Linux(D
, Triple
, Args
) {
28 getProgramPaths().push_back("/opt/nec/ve/bin");
29 // ProgramPaths are found via 'PATH' environment variable.
31 // Default library paths are following:
32 // ${RESOURCEDIR}/lib/ve-unknown-linux-gnu,
35 // Default file paths are following:
36 // ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPath)
42 // These are OK for host, but no go for VE.
44 // Define file paths from scratch here.
45 getFilePaths().clear();
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");
57 Tool
*VEToolChain::buildAssembler() const {
58 return new tools::gnutools::Assembler(*this);
61 Tool
*VEToolChain::buildLinker() const {
62 return new tools::gnutools::Linker(*this);
65 bool VEToolChain::isPICDefault() const { return false; }
67 bool VEToolChain::isPIEDefault(const llvm::opt::ArgList
&Args
) const {
71 bool VEToolChain::isPICDefaultForced() const { return false; }
73 bool VEToolChain::SupportsProfiling() const { return false; }
75 bool VEToolChain::hasBlocksRuntime() const { return false; }
77 void VEToolChain::AddClangSystemIncludeArgs(const ArgList
&DriverArgs
,
78 ArgStringList
&CC1Args
) const {
79 if (DriverArgs
.hasArg(clang::driver::options::OPT_nostdinc
))
82 if (DriverArgs
.hasArg(options::OPT_nobuiltininc
) &&
83 DriverArgs
.hasArg(options::OPT_nostdlibinc
))
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
);
92 if (!DriverArgs
.hasArg(options::OPT_nostdlibinc
)) {
93 if (const char *cl_include_dir
= getenv("NCC_C_INCLUDE_PATH")) {
94 SmallVector
<StringRef
, 4> Dirs
;
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
);
100 addSystemInclude(DriverArgs
, CC1Args
,
101 getDriver().SysRoot
+ "/opt/nec/ve/include");
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");
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
))
122 if (const char *cl_include_dir
= getenv("NCC_CPLUS_INCLUDE_PATH")) {
123 SmallVector
<StringRef
, 4> Dirs
;
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
);
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
);
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.");
141 tools::addArchSpecificRPath(*this, Args
, CmdArgs
);
143 CmdArgs
.push_back("-lc++");
144 if (Args
.hasArg(options::OPT_fexperimental_library
))
145 CmdArgs
.push_back("-lc++experimental");
146 CmdArgs
.push_back("-lc++abi");
147 CmdArgs
.push_back("-lunwind");
148 // libc++ requires -lpthread under glibc environment
149 CmdArgs
.push_back("-lpthread");
150 // libunwind requires -ldl under glibc environment
151 CmdArgs
.push_back("-ldl");
154 llvm::ExceptionHandling
155 VEToolChain::GetExceptionModel(const ArgList
&Args
) const {
156 // VE uses SjLj exceptions.
157 return llvm::ExceptionHandling::SjLj
;