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 // FIXME: Remove this once there is a proper way to detect an ARC runtime
65 ARCSimulator_HasARCRuntime,
66 ARCSimulator_NoARCRuntime
67 } ARCRuntimeForSimulator;
70 /// Whether we are targeting iPhoneOS target.
71 mutable bool TargetIsIPhoneOS;
73 /// Whether we are targeting the iPhoneOS simulator target.
74 mutable bool TargetIsIPhoneOSSimulator;
76 /// The OS version we are targeting.
77 mutable unsigned TargetVersion[3];
79 /// The default macosx-version-min of this tool chain; empty until
81 std::string MacosxVersionMin;
83 bool hasARCRuntime() const;
86 void AddDeploymentTarget(DerivedArgList &Args) const;
89 Darwin(const HostInfo &Host, const llvm::Triple& Triple);
92 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
94 /// @name Darwin Specific Toolchain API
97 // FIXME: Eliminate these ...Target functions and derive separate tool chains
98 // for these targets and put version in constructor.
99 void setTarget(bool IsIPhoneOS, unsigned Major, unsigned Minor,
100 unsigned Micro, bool IsIOSSim) const {
101 assert((!IsIOSSim || IsIPhoneOS) && "Unexpected deployment target!");
103 // FIXME: For now, allow reinitialization as long as values don't
104 // change. This will go away when we move away from argument translation.
105 if (TargetInitialized && TargetIsIPhoneOS == IsIPhoneOS &&
106 TargetIsIPhoneOSSimulator == IsIOSSim &&
107 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
108 TargetVersion[2] == Micro)
111 assert(!TargetInitialized && "Target already initialized!");
112 TargetInitialized = true;
113 TargetIsIPhoneOS = IsIPhoneOS;
114 TargetIsIPhoneOSSimulator = IsIOSSim;
115 TargetVersion[0] = Major;
116 TargetVersion[1] = Minor;
117 TargetVersion[2] = Micro;
120 bool isTargetIPhoneOS() const {
121 assert(TargetInitialized && "Target not initialized!");
122 return TargetIsIPhoneOS;
125 bool isTargetIOSSimulator() const {
126 assert(TargetInitialized && "Target not initialized!");
127 return TargetIsIPhoneOSSimulator;
130 bool isTargetInitialized() const { return TargetInitialized; }
132 void getTargetVersion(unsigned (&Res)[3]) const {
133 assert(TargetInitialized && "Target not initialized!");
134 Res[0] = TargetVersion[0];
135 Res[1] = TargetVersion[1];
136 Res[2] = TargetVersion[2];
139 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
140 /// invocation. For example, Darwin treats different ARM variations as
141 /// distinct architectures.
142 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
144 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
145 for (unsigned i=0; i < 3; ++i) {
146 if (A[i] > B[i]) return false;
147 if (A[i] < B[i]) return true;
152 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
153 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
154 unsigned B[3] = { V0, V1, V2 };
155 return isVersionLT(TargetVersion, B);
158 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
159 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
160 unsigned B[3] = { V0, V1, V2 };
161 return isVersionLT(TargetVersion, B);
164 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
166 /// \param Args - The input argument list.
167 /// \param CmdArgs [out] - The command argument list to append the paths
168 /// (prefixed by -L) to.
169 virtual void AddLinkSearchPathArgs(const ArgList &Args,
170 ArgStringList &CmdArgs) const = 0;
172 /// AddLinkARCArgs - Add the linker arguments to link the ARC runtime library.
173 virtual void AddLinkARCArgs(const ArgList &Args,
174 ArgStringList &CmdArgs) const = 0;
176 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
178 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
179 ArgStringList &CmdArgs) const = 0;
182 /// @name ToolChain Implementation
185 virtual types::ID LookupTypeForExtension(const char *Ext) const;
187 virtual bool HasNativeLLVMSupport() const;
189 virtual void configureObjCRuntime(ObjCRuntime &runtime) const;
191 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
192 const char *BoundArch) const;
194 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
195 const ActionList &Inputs) const;
197 virtual bool IsBlocksDefault() const {
198 // Always allow blocks on Darwin; users interested in versioning are
199 // expected to use /usr/include/Blocks.h.
202 virtual bool IsIntegratedAssemblerDefault() const {
203 #ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
206 // Default integrated assembler to on for x86.
207 return (getTriple().getArch() == llvm::Triple::x86 ||
208 getTriple().getArch() == llvm::Triple::x86_64);
211 virtual bool IsStrictAliasingDefault() const {
212 #ifdef DISABLE_DEFAULT_STRICT_ALIASING
215 return ToolChain::IsStrictAliasingDefault();
219 virtual bool IsObjCDefaultSynthPropertiesDefault() const {
223 virtual bool IsObjCNonFragileABIDefault() const {
224 // Non-fragile ABI is default for everything but i386.
225 return getTriple().getArch() != llvm::Triple::x86;
227 virtual bool IsObjCLegacyDispatchDefault() const {
228 // This is only used with the non-fragile ABI.
230 // Legacy dispatch is used everywhere except on x86_64.
231 return getTriple().getArch() != llvm::Triple::x86_64;
233 virtual bool UseObjCMixedDispatch() const {
234 // This is only used with the non-fragile ABI and non-legacy dispatch.
236 // Mixed dispatch is used everywhere except OS X before 10.6.
237 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
239 virtual bool IsUnwindTablesDefault() const;
240 virtual unsigned GetDefaultStackProtectorLevel() const {
241 // Stack protectors default to on for 10.6 and beyond.
242 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
244 virtual const char *GetDefaultRelocationModel() const;
245 virtual const char *GetForcedPicModel() const;
247 virtual bool SupportsProfiling() const;
249 virtual bool SupportsObjCGC() const;
251 virtual bool UseDwarfDebugFlags() const;
253 virtual bool UseSjLjExceptions() const;
258 /// DarwinClang - The Darwin toolchain used by Clang.
259 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
261 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple);
263 /// @name Darwin ToolChain Implementation
266 virtual void AddLinkSearchPathArgs(const ArgList &Args,
267 ArgStringList &CmdArgs) const;
269 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
270 ArgStringList &CmdArgs) const;
271 void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
272 const char *DarwinStaticLib) const;
274 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
275 ArgStringList &CmdArgs) const;
277 virtual void AddCCKextLibArgs(const ArgList &Args,
278 ArgStringList &CmdArgs) const;
280 virtual void AddLinkARCArgs(const ArgList &Args,
281 ArgStringList &CmdArgs) const;
285 /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
286 class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
288 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
289 : Generic_GCC(Host, Triple) {}
291 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
293 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
296 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
298 Generic_ELF(const HostInfo &Host, const llvm::Triple& Triple)
299 : Generic_GCC(Host, Triple) {}
301 virtual bool IsIntegratedAssemblerDefault() const {
302 // Default integrated assembler to on for x86.
303 return (getTriple().getArch() == llvm::Triple::x86 ||
304 getTriple().getArch() == llvm::Triple::x86_64);
308 class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
310 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
312 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
313 const ActionList &Inputs) const;
316 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
318 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
320 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
321 const ActionList &Inputs) const;
324 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
326 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple);
328 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
329 const ActionList &Inputs) const;
332 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
333 const llvm::Triple ToolTriple;
336 NetBSD(const HostInfo &Host, const llvm::Triple& Triple,
337 const llvm::Triple& ToolTriple);
339 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
340 const ActionList &Inputs) const;
343 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
345 Minix(const HostInfo &Host, const llvm::Triple& Triple);
347 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
348 const ActionList &Inputs) const;
351 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
353 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
355 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
356 const ActionList &Inputs) const;
359 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
361 Linux(const HostInfo &Host, const llvm::Triple& Triple);
363 virtual bool HasNativeLLVMSupport() const;
365 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
366 const ActionList &Inputs) const;
369 std::vector<std::string> ExtraOpts;
373 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
374 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
375 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
377 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
380 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
381 const ActionList &Inputs) const;
382 bool IsMathErrnoDefault() const;
383 bool IsUnwindTablesDefault() const;
384 const char* GetDefaultRelocationModel() const;
385 const char* GetForcedPicModel() const;
388 mutable llvm::DenseMap<unsigned, Tool*> Tools;
392 class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain {
393 mutable llvm::DenseMap<unsigned, Tool*> Tools;
396 Windows(const HostInfo &Host, const llvm::Triple& Triple);
398 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
399 const ActionList &Inputs) const;
401 virtual bool IsIntegratedAssemblerDefault() const;
402 virtual bool IsUnwindTablesDefault() const;
403 virtual const char *GetDefaultRelocationModel() const;
404 virtual const char *GetForcedPicModel() const;
407 } // end namespace toolchains
408 } // end namespace driver
409 } // end namespace clang