clang  14.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 file paths are:
32  // ${RESOURCEDIR}/lib/linux/ve (== getArchSpecificLibPath)
33  // /lib/../lib64
34  // /usr/lib/../lib64
35  // ${BINPATH}/../lib
36  // /lib
37  // /usr/lib
38  //
39  // These are OK for host, but no go for VE. So, defines them all
40  // from scratch here.
41  getFilePaths().clear();
42  getFilePaths().push_back(getArchSpecificLibPath());
43  getFilePaths().push_back(computeSysRoot() + "/opt/nec/ve/lib");
44 }
45 
47  return new tools::gnutools::Assembler(*this);
48 }
49 
51  return new tools::gnutools::Linker(*this);
52 }
53 
54 bool VEToolChain::isPICDefault() const { return false; }
55 
56 bool VEToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
57  return false;
58 }
59 
60 bool VEToolChain::isPICDefaultForced() const { return false; }
61 
62 bool VEToolChain::SupportsProfiling() const { return false; }
63 
64 bool VEToolChain::hasBlocksRuntime() const { return false; }
65 
66 void VEToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
67  ArgStringList &CC1Args) const {
68  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
69  return;
70 
71  if (DriverArgs.hasArg(options::OPT_nobuiltininc) &&
72  DriverArgs.hasArg(options::OPT_nostdlibinc))
73  return;
74 
75  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
76  SmallString<128> P(getDriver().ResourceDir);
77  llvm::sys::path::append(P, "include");
78  addSystemInclude(DriverArgs, CC1Args, P);
79  }
80 
81  if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
82  if (const char *cl_include_dir = getenv("NCC_C_INCLUDE_PATH")) {
84  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
85  StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
86  ArrayRef<StringRef> DirVec(Dirs);
87  addSystemIncludes(DriverArgs, CC1Args, DirVec);
88  } else {
89  addSystemInclude(DriverArgs, CC1Args,
90  getDriver().SysRoot + "/opt/nec/ve/include");
91  }
92  }
93 }
94 
95 void VEToolChain::addClangTargetOptions(const ArgList &DriverArgs,
96  ArgStringList &CC1Args,
97  Action::OffloadKind) const {
98  CC1Args.push_back("-nostdsysteminc");
99  bool UseInitArrayDefault = true;
100  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
101  options::OPT_fno_use_init_array, UseInitArrayDefault))
102  CC1Args.push_back("-fno-use-init-array");
103 }
104 
105 void VEToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
106  ArgStringList &CC1Args) const {
107  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
108  DriverArgs.hasArg(options::OPT_nostdlibinc) ||
109  DriverArgs.hasArg(options::OPT_nostdincxx))
110  return;
111  if (const char *cl_include_dir = getenv("NCC_CPLUS_INCLUDE_PATH")) {
113  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
114  StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
115  ArrayRef<StringRef> DirVec(Dirs);
116  addSystemIncludes(DriverArgs, CC1Args, DirVec);
117  } else {
118  SmallString<128> P(getDriver().ResourceDir);
119  llvm::sys::path::append(P, "include/c++/v1");
120  addSystemInclude(DriverArgs, CC1Args, P);
121  }
122 }
123 
124 void VEToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
125  ArgStringList &CmdArgs) const {
126  assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
127  "Only -lc++ (aka libxx) is supported in this toolchain.");
128 
129  tools::addArchSpecificRPath(*this, Args, CmdArgs);
130 
131  CmdArgs.push_back("-lc++");
132  CmdArgs.push_back("-lc++abi");
133  CmdArgs.push_back("-lunwind");
134  // libc++ requires -lpthread under glibc environment
135  CmdArgs.push_back("-lpthread");
136  // libunwind requires -ldl under glibc environment
137  CmdArgs.push_back("-ldl");
138 }
139 
140 llvm::ExceptionHandling
141 VEToolChain::GetExceptionModel(const ArgList &Args) const {
142  // VE uses SjLj exceptions.
143  return llvm::ExceptionHandling::SjLj;
144 }
clang::driver::toolchains
Definition: AIX.h:55
VEToolchain.h
clang::driver::ToolChain::getProgramPaths
path_list & getProgramPaths()
Definition: ToolChain.h:262
Driver.h
clang::driver::toolchains::VEToolChain::buildAssembler
Tool * buildAssembler() const override
Definition: VEToolchain.cpp:46
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:64
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:56
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:221
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:95
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:124
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:105
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:66
clang::driver::ToolChain::getFilePaths
path_list & getFilePaths()
Definition: ToolChain.h:259
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:60
llvm::opt
Definition: DiagnosticOptions.h:19
clang::driver::toolchains::VEToolChain::buildLinker
Tool * buildLinker() const override
Definition: VEToolchain.cpp:50
llvm::SmallString< 128 >
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:348
clang::driver::toolchains::VEToolChain::GetCXXStdlibType
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: VEToolchain.h:52
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:867
clang::driver::ToolChain::getArchSpecificLibPath
std::string getArchSpecificLibPath() const
Definition: ToolChain.cpp:500
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:141
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:54
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:62
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:59
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:85
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:837