1 //===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_
11 #define CLANG_LIB_DRIVER_TOOLCHAINS_H_
13 #include "clang/Driver/Action.h"
14 #include "clang/Driver/ToolChain.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/Support/Compiler.h"
23 namespace toolchains {
25 /// Generic_GCC - A tool chain using the 'gcc' command to perform
26 /// all subcommands; this relies on gcc translating the majority of
27 /// command line options.
28 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
30 mutable llvm::DenseMap<unsigned, Tool*> Tools;
33 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
36 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
37 const ActionList &Inputs) const;
39 virtual bool IsUnwindTablesDefault() const;
40 virtual const char *GetDefaultRelocationModel() const;
41 virtual const char *GetForcedPicModel() const;
44 /// Darwin - The base Darwin tool chain.
45 class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
48 unsigned DarwinVersion[3];
51 mutable llvm::DenseMap<unsigned, Tool*> Tools;
53 /// Whether the information on the target has been initialized.
55 // FIXME: This should be eliminated. What we want to do is make this part of
56 // the "default target for arguments" selection process, once we get out of
57 // the argument translation business.
58 mutable bool TargetInitialized;
60 /// Whether we are targeting iPhoneOS target.
61 mutable bool TargetIsIPhoneOS;
63 /// Whether we are targeting the iPhoneOS simulator target.
64 mutable bool TargetIsIPhoneOSSimulator;
66 /// The OS version we are targeting.
67 mutable unsigned TargetVersion[3];
69 /// The default macosx-version-min of this tool chain; empty until
71 std::string MacosxVersionMin;
74 void AddDeploymentTarget(DerivedArgList &Args) const;
77 Darwin(const HostInfo &Host, const llvm::Triple& Triple);
80 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
82 /// @name Darwin Specific Toolchain API
85 // FIXME: Eliminate these ...Target functions and derive separate tool chains
86 // for these targets and put version in constructor.
87 void setTarget(bool IsIPhoneOS, unsigned Major, unsigned Minor,
88 unsigned Micro, bool IsIOSSim) const {
89 assert((!IsIOSSim || IsIPhoneOS) && "Unexpected deployment target!");
91 // FIXME: For now, allow reinitialization as long as values don't
92 // change. This will go away when we move away from argument translation.
93 if (TargetInitialized && TargetIsIPhoneOS == IsIPhoneOS &&
94 TargetIsIPhoneOSSimulator == IsIOSSim &&
95 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
96 TargetVersion[2] == Micro)
99 assert(!TargetInitialized && "Target already initialized!");
100 TargetInitialized = true;
101 TargetIsIPhoneOS = IsIPhoneOS;
102 TargetIsIPhoneOSSimulator = IsIOSSim;
103 TargetVersion[0] = Major;
104 TargetVersion[1] = Minor;
105 TargetVersion[2] = Micro;
108 bool isTargetIPhoneOS() const {
109 assert(TargetInitialized && "Target not initialized!");
110 return TargetIsIPhoneOS;
113 bool isTargetIOSSimulator() const {
114 assert(TargetInitialized && "Target not initialized!");
115 return TargetIsIPhoneOSSimulator;
118 bool isTargetInitialized() const { return TargetInitialized; }
120 void getTargetVersion(unsigned (&Res)[3]) const {
121 assert(TargetInitialized && "Target not initialized!");
122 Res[0] = TargetVersion[0];
123 Res[1] = TargetVersion[1];
124 Res[2] = TargetVersion[2];
127 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
128 /// invocation. For example, Darwin treats different ARM variations as
129 /// distinct architectures.
130 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
132 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
133 for (unsigned i=0; i < 3; ++i) {
134 if (A[i] > B[i]) return false;
135 if (A[i] < B[i]) return true;
140 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
141 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
142 unsigned B[3] = { V0, V1, V2 };
143 return isVersionLT(TargetVersion, B);
146 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
147 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
148 unsigned B[3] = { V0, V1, V2 };
149 return isVersionLT(TargetVersion, B);
152 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
154 /// \param Args - The input argument list.
155 /// \param CmdArgs [out] - The command argument list to append the paths
156 /// (prefixed by -L) to.
157 virtual void AddLinkSearchPathArgs(const ArgList &Args,
158 ArgStringList &CmdArgs) const = 0;
160 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
162 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
163 ArgStringList &CmdArgs) const = 0;
166 /// @name ToolChain Implementation
169 virtual types::ID LookupTypeForExtension(const char *Ext) const;
171 virtual bool HasNativeLLVMSupport() const;
173 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
174 const char *BoundArch) const;
176 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
177 const ActionList &Inputs) const;
179 virtual bool IsBlocksDefault() const {
180 // Always allow blocks on Darwin; users interested in versioning are
181 // expected to use /usr/include/Blocks.h.
184 virtual bool IsIntegratedAssemblerDefault() const {
185 #ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
188 // Default integrated assembler to on for x86.
189 return (getTriple().getArch() == llvm::Triple::x86 ||
190 getTriple().getArch() == llvm::Triple::x86_64);
193 virtual bool IsStrictAliasingDefault() const {
194 #ifdef DISABLE_DEFAULT_STRICT_ALIASING
197 return ToolChain::IsStrictAliasingDefault();
201 virtual bool IsObjCDefaultSynthPropertiesDefault() const {
205 virtual bool IsObjCNonFragileABIDefault() const {
206 // Non-fragile ABI is default for everything but i386.
207 return getTriple().getArch() != llvm::Triple::x86;
209 virtual bool IsObjCLegacyDispatchDefault() const {
210 // This is only used with the non-fragile ABI.
212 // Legacy dispatch is used everywhere except on x86_64.
213 return getTriple().getArch() != llvm::Triple::x86_64;
215 virtual bool UseObjCMixedDispatch() const {
216 // This is only used with the non-fragile ABI and non-legacy dispatch.
218 // Mixed dispatch is used everywhere except OS X before 10.6.
219 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
221 virtual bool IsUnwindTablesDefault() const;
222 virtual unsigned GetDefaultStackProtectorLevel() const {
223 // Stack protectors default to on for 10.6 and beyond.
224 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
226 virtual const char *GetDefaultRelocationModel() const;
227 virtual const char *GetForcedPicModel() const;
229 virtual bool SupportsProfiling() const;
231 virtual bool SupportsObjCGC() const;
233 virtual bool UseDwarfDebugFlags() const;
235 virtual bool UseSjLjExceptions() const;
240 /// DarwinClang - The Darwin toolchain used by Clang.
241 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
243 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple);
245 /// @name Darwin ToolChain Implementation
248 virtual void AddLinkSearchPathArgs(const ArgList &Args,
249 ArgStringList &CmdArgs) const;
251 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
252 ArgStringList &CmdArgs) const;
254 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
255 ArgStringList &CmdArgs) const;
257 virtual void AddCCKextLibArgs(const ArgList &Args,
258 ArgStringList &CmdArgs) const;
263 /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
264 class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
266 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
267 : Generic_GCC(Host, Triple) {}
269 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
271 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
274 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
276 Generic_ELF(const HostInfo &Host, const llvm::Triple& Triple)
277 : Generic_GCC(Host, Triple) {}
279 virtual bool IsIntegratedAssemblerDefault() const {
280 // Default integrated assembler to on for x86.
281 return (getTriple().getArch() == llvm::Triple::x86 ||
282 getTriple().getArch() == llvm::Triple::x86_64);
286 class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
288 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
290 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
291 const ActionList &Inputs) const;
294 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
296 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
298 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
299 const ActionList &Inputs) const;
302 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
304 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple);
306 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
307 const ActionList &Inputs) const;
310 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
312 NetBSD(const HostInfo &Host, const llvm::Triple& Triple);
314 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
315 const ActionList &Inputs) const;
318 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
320 Minix(const HostInfo &Host, const llvm::Triple& Triple);
322 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
323 const ActionList &Inputs) const;
326 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
328 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
330 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
331 const ActionList &Inputs) const;
334 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
336 Linux(const HostInfo &Host, const llvm::Triple& Triple);
338 virtual bool HasNativeLLVMSupport() const;
340 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
341 const ActionList &Inputs) const;
344 std::vector<std::string> ExtraOpts;
348 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
349 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
350 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
352 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
355 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
356 const ActionList &Inputs) const;
357 bool IsMathErrnoDefault() const;
358 bool IsUnwindTablesDefault() const;
359 const char* GetDefaultRelocationModel() const;
360 const char* GetForcedPicModel() const;
363 mutable llvm::DenseMap<unsigned, Tool*> Tools;
367 class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain {
368 mutable llvm::DenseMap<unsigned, Tool*> Tools;
371 Windows(const HostInfo &Host, const llvm::Triple& Triple);
373 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
374 const ActionList &Inputs) const;
376 virtual bool IsIntegratedAssemblerDefault() const;
377 virtual bool IsUnwindTablesDefault() const;
378 virtual const char *GetDefaultRelocationModel() const;
379 virtual const char *GetForcedPicModel() const;
382 } // end namespace toolchains
383 } // end namespace driver
384 } // end namespace clang