clang 24.0.0git
HIPSPV.h
Go to the documentation of this file.
1//===--- HIPSPV.h - HIP 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#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
10#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
11
12#include "SPIRV.h"
13#include "clang/Driver/Driver.h"
14#include "clang/Driver/Tool.h"
16
17namespace clang {
18namespace driver {
19namespace tools {
20namespace HIPSPV {
21
22// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
23// device library, then compiles it to SPIR-V in a shared object.
24class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
25public:
26 Linker(const ToolChain &TC) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
27
28 bool hasIntegratedCPP() const override { return false; }
29
30 void ConstructJob(Compilation &C, const JobAction &JA,
31 const InputInfo &Output, const InputInfoList &Inputs,
32 const llvm::opt::ArgList &TCArgs,
33 const char *LinkingOutput) const override;
34
35private:
36 void constructLinkAndEmitSpirvCommand(Compilation &C, const JobAction &JA,
37 const InputInfoList &Inputs,
38 const InputInfo &Output,
39 const llvm::opt::ArgList &Args) const;
40};
41
42} // namespace HIPSPV
43} // namespace tools
44
45namespace toolchains {
46
47class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
48public:
49 HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
50 const ToolChain &HostTC, const llvm::opt::ArgList &Args);
51 HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple,
52 const llvm::opt::ArgList &Args);
53
54 const llvm::Triple *getAuxTriple() const override {
55 return HostTC ? &HostTC->getTriple() : nullptr;
56 }
57
58 // Keep IsIntegratedBackendDefault() at the base class' "true": it also
59 // decides whether clang's compile and backend jobs are collapsed into a
60 // single -cc1 invocation, so making it depend on whether the SPIR-V backend
61 // was built would change the device compilation job layout of every HIPSPV
62 // compile. The fallback to the external llvm-spirv translator is decided in
63 // HIPSPV::Linker::constructLinkAndEmitSpirvCommand instead.
64 bool IsIntegratedBackendSupported() const override;
65 bool IsNonIntegratedBackendSupported() const override { return true; }
66
67 void
68 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
69 llvm::opt::ArgStringList &CC1Args, BoundArch BA,
70 Action::OffloadKind DeviceOffloadKind) const override;
71 void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
72 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
73 void
74 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
75 llvm::opt::ArgStringList &CC1Args) const override;
76 void AddClangCXXStdlibIncludeArgs(
77 const llvm::opt::ArgList &Args,
78 llvm::opt::ArgStringList &CC1Args) const override;
79 void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
80 llvm::opt::ArgStringList &CC1Args) const override;
81 void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
82 llvm::opt::ArgStringList &CC1Args) const override;
84 getDeviceLibs(const llvm::opt::ArgList &Args, BoundArch BA,
85 const Action::OffloadKind DeviceOffloadKind) const override;
86
88 getSupportedSanitizers(BoundArch BA,
89 Action::OffloadKind DeviceOffloadKind) const override;
90
91 VersionTuple
92 computeMSVCVersion(const Driver *D,
93 const llvm::opt::ArgList &Args) const override;
94
95 void adjustDebugInfoKind(llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
96 const llvm::opt::ArgList &Args) const override;
97 bool IsMathErrnoDefault() const override { return false; }
98 bool useIntegratedAs() const override { return true; }
99 bool isCrossCompiling() const override { return true; }
100 bool isPICDefault() const override { return false; }
101 bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
102 return false;
103 }
104 bool isPICDefaultForced() const override { return false; }
105 bool SupportsProfiling() const override { return false; }
106
107 LTOKind getDefaultLTOMode() const override { return LTOK_Full; }
108 LTOKind
109 getLTOMode(const llvm::opt::ArgList &Args,
110 Action::OffloadKind Kind = Action::OFK_None) const override;
111
112 const ToolChain *HostTC = nullptr;
113
114protected:
115 Tool *buildLinker() const override;
116};
117
118} // end namespace toolchains
119} // end namespace driver
120} // end namespace clang
121
122#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Compilation - A set of tasks to perform for a single driver invocation.
Definition Compilation.h:46
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:95
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:96
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition ToolChain.cpp:91
Tool - Information on a specific compilation tool.
Definition Tool.h:32
Tool(const char *Name, const char *ShortName, const ToolChain &TC)
Definition Tool.cpp:14
bool useIntegratedAs() const override
Check if the toolchain should use the integrated assembler.
Definition HIPSPV.h:98
Tool * buildLinker() const override
Definition HIPSPV.cpp:304
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition HIPSPV.h:97
const llvm::Triple * getAuxTriple() const override
Get the toolchain's aux triple, if it has one.
Definition HIPSPV.h:54
bool IsNonIntegratedBackendSupported() const override
IsNonIntegratedBackendSupported - Does this tool chain support -fno-integrated-objemitter.
Definition HIPSPV.h:65
LTOKind getDefaultLTOMode() const override
Returns the default LTO mode for this toolchain.
Definition HIPSPV.h:107
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition HIPSPV.h:100
HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple, const ToolChain &HostTC, const llvm::opt::ArgList &Args)
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition HIPSPV.h:101
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition HIPSPV.h:99
HIPSPVToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition HIPSPV.h:104
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition HIPSPV.h:105
Linker(const ToolChain &TC)
Definition HIPSPV.h:26
bool hasIntegratedCPP() const override
Definition HIPSPV.h:28
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
Definition Driver.h:59
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:51
The JSON file list parser is used to communicate input to InstallAPI.
Represents a bound architecture for offload / multiple architecture compilation.