xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/PS4CPU.h (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
1 //===--- PS4CPU.h - PS4CPU 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_PS4CPU_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_PS4CPU_H
11 
12 #include "Gnu.h"
13 #include "clang/Basic/LangOptions.h"
14 #include "clang/Driver/Tool.h"
15 #include "clang/Driver/ToolChain.h"
16 
17 namespace clang {
18 namespace driver {
19 namespace tools {
20 
21 namespace PScpu {
22 // Functions/classes in this namespace support both PS4 and PS5.
23 
24 void addProfileRTArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
25                       llvm::opt::ArgStringList &CmdArgs);
26 
27 void addSanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
28                       llvm::opt::ArgStringList &CmdArgs);
29 
30 class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
31 public:
32   Assembler(const ToolChain &TC) : Tool("PScpu::Assembler", "assembler", TC) {}
33 
34   bool hasIntegratedCPP() const override { return false; }
35 
36   void ConstructJob(Compilation &C, const JobAction &JA,
37                     const InputInfo &Output, const InputInfoList &Inputs,
38                     const llvm::opt::ArgList &TCArgs,
39                     const char *LinkingOutput) const override;
40 };
41 
42 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
43 public:
44   Linker(const ToolChain &TC) : Tool("PScpu::Linker", "linker", TC) {}
45 
46   bool hasIntegratedCPP() const override { return false; }
47   bool isLinkJob() const override { return true; }
48 
49   void ConstructJob(Compilation &C, const JobAction &JA,
50                     const InputInfo &Output, const InputInfoList &Inputs,
51                     const llvm::opt::ArgList &TCArgs,
52                     const char *LinkingOutput) const override;
53 };
54 } // namespace PScpu
55 } // namespace tools
56 
57 namespace toolchains {
58 
59 // Common Toolchain base class for PS4 and PS5.
60 class LLVM_LIBRARY_VISIBILITY PS4PS5Base : public Generic_ELF {
61 public:
62   PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
63              const llvm::opt::ArgList &Args, StringRef Platform,
64              const char *EnvVar);
65 
66   // No support for finding a C++ standard library yet.
67   void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
68                              llvm::opt::ArgStringList &CC1Args) const override {
69   }
70   void
71   addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
72                            llvm::opt::ArgStringList &CC1Args) const override {}
73 
74   bool IsMathErrnoDefault() const override { return false; }
75   bool IsObjCNonFragileABIDefault() const override { return true; }
76   bool HasNativeLLVMSupport() const override { return true; }
77   bool isPICDefault() const override { return true; }
78 
79   LangOptions::StackProtectorMode
80   GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
81     return LangOptions::SSPStrong;
82   }
83 
84   llvm::DebuggerKind getDefaultDebuggerTuning() const override {
85     return llvm::DebuggerKind::SCE;
86   }
87 
88   SanitizerMask getSupportedSanitizers() const override;
89 
90   void addClangTargetOptions(
91       const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
92       Action::OffloadKind DeviceOffloadingKind) const override;
93 
94   llvm::DenormalMode getDefaultDenormalModeForType(
95       const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
96       const llvm::fltSemantics *FPType) const override {
97     // DAZ and FTZ are on by default.
98     return llvm::DenormalMode::getPreserveSign();
99   }
100 
101   bool useRelaxRelocations() const override { return true; }
102 
103   // Helper methods for PS4/PS5.
104   virtual const char *getLinkerBaseName() const = 0;
105   virtual std::string qualifyPSCmdName(StringRef CmdName) const = 0;
106   virtual void addSanitizerArgs(const llvm::opt::ArgList &Args,
107                                 llvm::opt::ArgStringList &CmdArgs,
108                                 const char *Prefix,
109                                 const char *Suffix) const = 0;
110   virtual const char *getProfileRTLibName() const = 0;
111 
112 protected:
113   Tool *buildLinker() const override;
114 };
115 
116 // PS4-specific Toolchain class.
117 class LLVM_LIBRARY_VISIBILITY PS4CPU : public PS4PS5Base {
118 public:
119   PS4CPU(const Driver &D, const llvm::Triple &Triple,
120          const llvm::opt::ArgList &Args);
121 
122   unsigned GetDefaultDwarfVersion() const override { return 4; }
123 
124   // PS4 toolchain uses legacy thin LTO API, which is not
125   // capable of unit splitting.
126   bool canSplitThinLTOUnit() const override { return false; }
127 
128   const char *getLinkerBaseName() const override { return "ld"; }
129   std::string qualifyPSCmdName(StringRef CmdName) const override {
130     return Twine("orbis-", CmdName).str();
131   }
132   void addSanitizerArgs(const llvm::opt::ArgList &Args,
133                         llvm::opt::ArgStringList &CmdArgs, const char *Prefix,
134                         const char *Suffix) const override;
135   const char *getProfileRTLibName() const override {
136     return "libclang_rt.profile-x86_64.a";
137   }
138 
139 protected:
140   Tool *buildAssembler() const override;
141 };
142 
143 // PS5-specific Toolchain class.
144 class LLVM_LIBRARY_VISIBILITY PS5CPU : public PS4PS5Base {
145 public:
146   PS5CPU(const Driver &D, const llvm::Triple &Triple,
147          const llvm::opt::ArgList &Args);
148 
149   unsigned GetDefaultDwarfVersion() const override { return 5; }
150 
151   SanitizerMask getSupportedSanitizers() const override;
152 
153   const char *getLinkerBaseName() const override { return "lld"; }
154   std::string qualifyPSCmdName(StringRef CmdName) const override {
155     return Twine("prospero-", CmdName).str();
156   }
157   void addSanitizerArgs(const llvm::opt::ArgList &Args,
158                         llvm::opt::ArgStringList &CmdArgs, const char *Prefix,
159                         const char *Suffix) const override;
160   const char *getProfileRTLibName() const override {
161     return "libclang_rt.profile-x86_64_nosubmission.a";
162   }
163 
164 protected:
165   Tool *buildAssembler() const override;
166 };
167 
168 } // end namespace toolchains
169 } // end namespace driver
170 } // end namespace clang
171 
172 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_PS4CPU_H
173