blob: 4fe3560976704ca94bda4b85bbf160e8d9e50c6b [file] [log] [blame]
Nick Lewycky3fdcc6f2010-12-31 17:31:54 +00001//===--- ToolChain.cpp - Collections of tools for one platform ------------===//
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Rafael Espindola5b222052013-03-18 20:48:54 +000010#include "Tools.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000011#include "clang/Basic/ObjCRuntime.h"
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000012#include "clang/Driver/Action.h"
13#include "clang/Driver/Driver.h"
Daniel Dunbar00577ad2010-08-23 22:35:37 +000014#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbar00577ad2010-08-23 22:35:37 +000015#include "clang/Driver/Options.h"
Reid Klecknerb1e25a12013-06-14 17:17:23 +000016#include "clang/Driver/ToolChain.h"
Bob Wilson57f6d192012-03-21 17:19:12 +000017#include "llvm/ADT/StringSwitch.h"
Reid Klecknerb1e25a12013-06-14 17:17:23 +000018#include "llvm/Option/Arg.h"
19#include "llvm/Option/ArgList.h"
20#include "llvm/Option/Option.h"
John McCall9f084a32011-07-06 00:26:06 +000021#include "llvm/Support/ErrorHandling.h"
Simon Atanasyan8e8e95c2013-04-20 08:15:03 +000022#include "llvm/Support/FileSystem.h"
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000023using namespace clang::driver;
Chris Lattner5f9e2722011-07-23 10:55:15 +000024using namespace clang;
Reid Klecknerb1e25a12013-06-14 17:17:23 +000025using namespace llvm::opt;
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000026
Rafael Espindolaaf370e62013-03-18 18:10:27 +000027ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
28 const ArgList &A)
29 : D(D), Triple(T), Args(A) {
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +000030}
31
32ToolChain::~ToolChain() {
33}
34
Daniel Dunbaree788e72009-12-21 18:54:17 +000035const Driver &ToolChain::getDriver() const {
Chandler Carruth4d7ff6e2012-01-25 09:12:06 +000036 return D;
Daniel Dunbaree788e72009-12-21 18:54:17 +000037}
38
Rafael Espindolaaf370e62013-03-18 18:10:27 +000039bool ToolChain::useIntegratedAs() const {
Rafael Espindola5470cd22013-03-18 17:52:57 +000040 return Args.hasFlag(options::OPT_integrated_as,
41 options::OPT_no_integrated_as,
42 IsIntegratedAssemblerDefault());
43}
44
Daniel Dunbard2a527e2012-11-08 03:38:26 +000045std::string ToolChain::getDefaultUniversalArchName() const {
46 // In universal driver terms, the arch name accepted by -arch isn't exactly
47 // the same as the ones that appear in the triple. Roughly speaking, this is
48 // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the
49 // only interesting special case is powerpc.
50 switch (Triple.getArch()) {
51 case llvm::Triple::ppc:
52 return "ppc";
53 case llvm::Triple::ppc64:
54 return "ppc64";
Bill Schmidtea7fb0c2013-07-26 01:36:11 +000055 case llvm::Triple::ppc64le:
56 return "ppc64le";
Daniel Dunbard2a527e2012-11-08 03:38:26 +000057 default:
58 return Triple.getArchName();
59 }
60}
61
Rafael Espindola03a86382012-09-23 03:05:41 +000062bool ToolChain::IsUnwindTablesDefault() const {
63 return false;
64}
65
Rafael Espindolaf48b93c2013-03-20 03:05:54 +000066Tool *ToolChain::getClang() const {
67 if (!Clang)
68 Clang.reset(new tools::Clang(*this));
69 return Clang.get();
70}
71
72Tool *ToolChain::buildAssembler() const {
73 return new tools::ClangAs(*this);
74}
75
76Tool *ToolChain::buildLinker() const {
77 llvm_unreachable("Linking is not supported by this toolchain");
78}
79
80Tool *ToolChain::getAssemble() const {
81 if (!Assemble)
82 Assemble.reset(buildAssembler());
83 return Assemble.get();
84}
85
86Tool *ToolChain::getClangAs() const {
87 if (!Assemble)
88 Assemble.reset(new tools::ClangAs(*this));
89 return Assemble.get();
90}
91
92Tool *ToolChain::getLink() const {
93 if (!Link)
94 Link.reset(buildLinker());
95 return Link.get();
96}
97
98Tool *ToolChain::getTool(Action::ActionClass AC) const {
Rafael Espindolac0a55d12013-03-19 00:36:57 +000099 switch (AC) {
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000100 case Action::AssembleJobClass:
101 return getAssemble();
102
103 case Action::LinkJobClass:
104 return getLink();
105
Rafael Espindolac0a55d12013-03-19 00:36:57 +0000106 case Action::InputClass:
107 case Action::BindArchClass:
Rafael Espindolac0a55d12013-03-19 00:36:57 +0000108 case Action::LipoJobClass:
109 case Action::DsymutilJobClass:
110 case Action::VerifyJobClass:
111 llvm_unreachable("Invalid tool kind.");
112
113 case Action::CompileJobClass:
114 case Action::PrecompileJobClass:
115 case Action::PreprocessJobClass:
116 case Action::AnalyzeJobClass:
117 case Action::MigrateJobClass:
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000118 return getClang();
Rafael Espindolac0a55d12013-03-19 00:36:57 +0000119 }
Benjamin Kramer4c49f7b2013-03-21 19:45:46 +0000120
121 llvm_unreachable("Invalid tool kind.");
Rafael Espindolac0a55d12013-03-19 00:36:57 +0000122}
123
Rafael Espindola29511872013-03-24 15:06:53 +0000124Tool *ToolChain::SelectTool(const JobAction &JA) const {
Rafael Espindola5b222052013-03-18 20:48:54 +0000125 if (getDriver().ShouldUseClangCompiler(JA))
Rafael Espindola29511872013-03-24 15:06:53 +0000126 return getClang();
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000127 Action::ActionClass AC = JA.getKind();
128 if (AC == Action::AssembleJobClass && useIntegratedAs())
Rafael Espindola29511872013-03-24 15:06:53 +0000129 return getClangAs();
130 return getTool(AC);
Rafael Espindola5b222052013-03-18 20:48:54 +0000131}
132
Daniel Dunbar4a7e8892010-07-14 18:46:23 +0000133std::string ToolChain::GetFilePath(const char *Name) const {
Chandler Carruth4d7ff6e2012-01-25 09:12:06 +0000134 return D.GetFilePath(Name, *this);
Mike Stump1eb44332009-09-09 15:08:12 +0000135
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000136}
137
Simon Atanasyanfc44e882012-10-03 19:52:37 +0000138std::string ToolChain::GetProgramPath(const char *Name) const {
139 return D.GetProgramPath(Name, *this);
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000140}
Daniel Dunbar41800112010-08-02 05:43:56 +0000141
142types::ID ToolChain::LookupTypeForExtension(const char *Ext) const {
143 return types::lookupTypeForExtension(Ext);
144}
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000145
Daniel Dunbarb993f5d2010-09-17 00:24:52 +0000146bool ToolChain::HasNativeLLVMSupport() const {
147 return false;
148}
149
John McCall260611a2012-06-20 06:18:46 +0000150ObjCRuntime ToolChain::getDefaultObjCRuntime(bool isNonFragile) const {
David Chisnall11d3f4c2012-07-03 20:49:52 +0000151 return ObjCRuntime(isNonFragile ? ObjCRuntime::GNUstep : ObjCRuntime::GCC,
John McCall260611a2012-06-20 06:18:46 +0000152 VersionTuple());
John McCall9f084a32011-07-06 00:26:06 +0000153}
154
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000155/// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000156//
157// FIXME: tblgen this.
158static const char *getARMTargetCPU(const ArgList &Args,
159 const llvm::Triple &Triple) {
Bob Wilson677a35b2012-03-21 16:31:37 +0000160 // For Darwin targets, the -arch option (which is translated to a
161 // corresponding -march option) should determine the architecture
162 // (and the Mach-O slice) regardless of any -mcpu options.
163 if (!Triple.isOSDarwin()) {
164 // FIXME: Warn on inconsistent use of -mcpu and -march.
165 // If we have -mcpu=, use that.
166 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
Richard Smith1d489cf2012-11-01 04:30:05 +0000167 return A->getValue();
Bob Wilson677a35b2012-03-21 16:31:37 +0000168 }
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000169
Chris Lattner5f9e2722011-07-23 10:55:15 +0000170 StringRef MArch;
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000171 if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
172 // Otherwise, if we have -march= choose the base CPU for that arch.
Richard Smith1d489cf2012-11-01 04:30:05 +0000173 MArch = A->getValue();
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000174 } else {
175 // Otherwise, use the Arch from the triple.
176 MArch = Triple.getArchName();
177 }
178
Bob Wilson57f6d192012-03-21 17:19:12 +0000179 return llvm::StringSwitch<const char *>(MArch)
180 .Cases("armv2", "armv2a","arm2")
181 .Case("armv3", "arm6")
182 .Case("armv3m", "arm7m")
Tim Northover4889a1f2013-06-13 15:02:46 +0000183 .Case("armv4", "strongarm")
184 .Case("armv4t", "arm7tdmi")
Bob Wilson57f6d192012-03-21 17:19:12 +0000185 .Cases("armv5", "armv5t", "arm10tdmi")
186 .Cases("armv5e", "armv5te", "arm1026ejs")
187 .Case("armv5tej", "arm926ej-s")
188 .Cases("armv6", "armv6k", "arm1136jf-s")
189 .Case("armv6j", "arm1136j-s")
190 .Cases("armv6z", "armv6zk", "arm1176jzf-s")
191 .Case("armv6t2", "arm1156t2-s")
Bob Wilson2503ebd2013-03-04 22:37:49 +0000192 .Cases("armv6m", "armv6-m", "cortex-m0")
Bob Wilson57f6d192012-03-21 17:19:12 +0000193 .Cases("armv7", "armv7a", "armv7-a", "cortex-a8")
Renato Golin40a94e22013-02-05 23:42:01 +0000194 .Cases("armv7l", "armv7-l", "cortex-a8")
Bob Wilson336bfa32012-09-29 23:52:50 +0000195 .Cases("armv7f", "armv7-f", "cortex-a9-mp")
196 .Cases("armv7s", "armv7-s", "swift")
Bob Wilson532f5a92013-03-04 22:37:43 +0000197 .Cases("armv7r", "armv7-r", "cortex-r4")
Bob Wilson57f6d192012-03-21 17:19:12 +0000198 .Cases("armv7m", "armv7-m", "cortex-m3")
Bob Wilson2503ebd2013-03-04 22:37:49 +0000199 .Cases("armv7em", "armv7e-m", "cortex-m4")
Joey Gouly4ec8d5b2013-06-26 17:19:48 +0000200 .Cases("armv8", "armv8a", "armv8-a", "cortex-a53")
Bob Wilson57f6d192012-03-21 17:19:12 +0000201 .Case("ep9312", "ep9312")
202 .Case("iwmmxt", "iwmmxt")
203 .Case("xscale", "xscale")
Tim Northover4889a1f2013-06-13 15:02:46 +0000204 // If all else failed, return the most base CPU with thumb interworking
205 // supported by LLVM.
Bob Wilson57f6d192012-03-21 17:19:12 +0000206 .Default("arm7tdmi");
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000207}
208
209/// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
210/// CPU.
211//
212// FIXME: This is redundant with -mcpu, why does LLVM use this.
213// FIXME: tblgen this, or kill it!
Chris Lattner5f9e2722011-07-23 10:55:15 +0000214static const char *getLLVMArchSuffixForARM(StringRef CPU) {
Bob Wilson57f6d192012-03-21 17:19:12 +0000215 return llvm::StringSwitch<const char *>(CPU)
Tim Northover4889a1f2013-06-13 15:02:46 +0000216 .Case("strongarm", "v4")
Bob Wilson57f6d192012-03-21 17:19:12 +0000217 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "v4t")
218 .Cases("arm720t", "arm9", "arm9tdmi", "v4t")
219 .Cases("arm920", "arm920t", "arm922t", "v4t")
220 .Cases("arm940t", "ep9312","v4t")
221 .Cases("arm10tdmi", "arm1020t", "v5")
222 .Cases("arm9e", "arm926ej-s", "arm946e-s", "v5e")
223 .Cases("arm966e-s", "arm968e-s", "arm10e", "v5e")
224 .Cases("arm1020e", "arm1022e", "xscale", "iwmmxt", "v5e")
225 .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "v6")
226 .Cases("arm1176jzf-s", "mpcorenovfp", "mpcore", "v6")
227 .Cases("arm1156t2-s", "arm1156t2f-s", "v6t2")
Bob Wilsonfc553452013-03-04 22:37:46 +0000228 .Cases("cortex-a5", "cortex-a7", "cortex-a8", "v7")
229 .Cases("cortex-a9", "cortex-a15", "v7")
230 .Case("cortex-r5", "v7r")
Bob Wilson57f6d192012-03-21 17:19:12 +0000231 .Case("cortex-m0", "v6m")
Bob Wilson2503ebd2013-03-04 22:37:49 +0000232 .Case("cortex-m3", "v7m")
233 .Case("cortex-m4", "v7em")
Bob Wilson336bfa32012-09-29 23:52:50 +0000234 .Case("cortex-a9-mp", "v7f")
235 .Case("swift", "v7s")
Joey Gouly4ec8d5b2013-06-26 17:19:48 +0000236 .Case("cortex-a53", "v8")
Bob Wilson57f6d192012-03-21 17:19:12 +0000237 .Default("");
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000238}
239
Chad Rosier61ab80a2011-09-20 20:44:06 +0000240std::string ToolChain::ComputeLLVMTriple(const ArgList &Args,
241 types::ID InputType) const {
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000242 switch (getTriple().getArch()) {
243 default:
244 return getTripleString();
245
246 case llvm::Triple::arm:
247 case llvm::Triple::thumb: {
248 // FIXME: Factor into subclasses.
249 llvm::Triple Triple = getTriple();
250
251 // Thumb2 is the default for V7 on Darwin.
252 //
253 // FIXME: Thumb should just be another -target-feaure, not in the triple.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000254 StringRef Suffix =
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000255 getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple));
Bob Wilson2503ebd2013-03-04 22:37:49 +0000256 bool ThumbDefault = Suffix.startswith("v6m") ||
257 (Suffix.startswith("v7") && getTriple().isOSDarwin());
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000258 std::string ArchName = "arm";
Chad Rosier61ab80a2011-09-20 20:44:06 +0000259
260 // Assembly files should start in ARM mode.
261 if (InputType != types::TY_PP_Asm &&
262 Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault))
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000263 ArchName = "thumb";
264 Triple.setArchName(ArchName + Suffix.str());
265
266 return Triple.getTriple();
267 }
268 }
269}
270
Chad Rosier61ab80a2011-09-20 20:44:06 +0000271std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
272 types::ID InputType) const {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000273 // Diagnose use of Darwin OS deployment target arguments on non-Darwin.
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000274 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ,
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000275 options::OPT_miphoneos_version_min_EQ,
276 options::OPT_mios_simulator_version_min_EQ))
Chris Lattner5f9e2722011-07-23 10:55:15 +0000277 getDriver().Diag(diag::err_drv_clang_unsupported)
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000278 << A->getAsString(Args);
279
Chad Rosier61ab80a2011-09-20 20:44:06 +0000280 return ComputeLLVMTriple(Args, InputType);
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000281}
282
Chandler Carruth88491fc2011-11-04 07:12:53 +0000283void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
284 ArgStringList &CC1Args) const {
285 // Each toolchain should provide the appropriate include flags.
286}
287
Chandler Carrutha6b25812012-11-21 23:40:23 +0000288void ToolChain::addClangTargetOptions(const ArgList &DriverArgs,
289 ArgStringList &CC1Args) const {
Rafael Espindola8af669f2012-06-19 01:26:10 +0000290}
291
Daniel Dunbarc24767c2011-12-07 23:03:15 +0000292ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
293 const ArgList &Args) const
294{
295 if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
Richard Smith1d489cf2012-11-01 04:30:05 +0000296 StringRef Value = A->getValue();
Daniel Dunbarc24767c2011-12-07 23:03:15 +0000297 if (Value == "compiler-rt")
298 return ToolChain::RLT_CompilerRT;
299 if (Value == "libgcc")
300 return ToolChain::RLT_Libgcc;
301 getDriver().Diag(diag::err_drv_invalid_rtlib_name)
302 << A->getAsString(Args);
303 }
304
305 return GetDefaultRuntimeLibType();
306}
307
Daniel Dunbar641b98b2010-09-14 23:12:35 +0000308ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
Daniel Dunbar3f16c952010-09-14 23:12:40 +0000309 if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
Richard Smith1d489cf2012-11-01 04:30:05 +0000310 StringRef Value = A->getValue();
Daniel Dunbar3f16c952010-09-14 23:12:40 +0000311 if (Value == "libc++")
312 return ToolChain::CST_Libcxx;
313 if (Value == "libstdc++")
314 return ToolChain::CST_Libstdcxx;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000315 getDriver().Diag(diag::err_drv_invalid_stdlib_name)
Daniel Dunbar3f16c952010-09-14 23:12:40 +0000316 << A->getAsString(Args);
317 }
318
Daniel Dunbar641b98b2010-09-14 23:12:35 +0000319 return ToolChain::CST_Libstdcxx;
320}
321
Chandler Carruth79cbbdc2011-12-17 23:10:01 +0000322/// \brief Utility function to add a system include directory to CC1 arguments.
323/*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs,
324 ArgStringList &CC1Args,
325 const Twine &Path) {
326 CC1Args.push_back("-internal-isystem");
327 CC1Args.push_back(DriverArgs.MakeArgString(Path));
328}
329
330/// \brief Utility function to add a system include directory with extern "C"
331/// semantics to CC1 arguments.
332///
333/// Note that this should be used rarely, and only for directories that
334/// historically and for legacy reasons are treated as having implicit extern
335/// "C" semantics. These semantics are *ignored* by and large today, but its
336/// important to preserve the preprocessor changes resulting from the
337/// classification.
338/*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
339 ArgStringList &CC1Args,
340 const Twine &Path) {
341 CC1Args.push_back("-internal-externc-isystem");
342 CC1Args.push_back(DriverArgs.MakeArgString(Path));
343}
344
Simon Atanasyan8e8e95c2013-04-20 08:15:03 +0000345void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
346 ArgStringList &CC1Args,
347 const Twine &Path) {
348 if (llvm::sys::fs::exists(Path))
349 addExternCSystemInclude(DriverArgs, CC1Args, Path);
350}
351
Chandler Carruth79cbbdc2011-12-17 23:10:01 +0000352/// \brief Utility function to add a list of system include directories to CC1.
353/*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
354 ArgStringList &CC1Args,
355 ArrayRef<StringRef> Paths) {
356 for (ArrayRef<StringRef>::iterator I = Paths.begin(), E = Paths.end();
357 I != E; ++I) {
358 CC1Args.push_back("-internal-isystem");
359 CC1Args.push_back(DriverArgs.MakeArgString(*I));
360 }
361}
362
Chandler Carruthab9fcd02011-11-04 23:49:01 +0000363void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
364 ArgStringList &CC1Args) const {
Chandler Carrutha4614422011-11-04 07:43:33 +0000365 // Header search paths should be handled by each of the subclasses.
366 // Historically, they have not been, and instead have been handled inside of
367 // the CC1-layer frontend. As the logic is hoisted out, this generic function
368 // will slowly stop being called.
369 //
370 // While it is being called, replicate a bit of a hack to propagate the
371 // '-stdlib=' flag down to CC1 so that it can in turn customize the C++
372 // header search paths with it. Once all systems are overriding this
373 // function, the CC1 flag and this line can be removed.
Chandler Carruthab9fcd02011-11-04 23:49:01 +0000374 DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
Daniel Dunbar641b98b2010-09-14 23:12:35 +0000375}
376
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000377void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
378 ArgStringList &CmdArgs) const {
Daniel Dunbar641b98b2010-09-14 23:12:35 +0000379 CXXStdlibType Type = GetCXXStdlibType(Args);
380
381 switch (Type) {
Daniel Dunbar3f16c952010-09-14 23:12:40 +0000382 case ToolChain::CST_Libcxx:
383 CmdArgs.push_back("-lc++");
384 break;
385
Daniel Dunbar641b98b2010-09-14 23:12:35 +0000386 case ToolChain::CST_Libstdcxx:
387 CmdArgs.push_back("-lstdc++");
388 break;
389 }
390}
Shantonu Sen7433fed2010-09-17 18:39:08 +0000391
392void ToolChain::AddCCKextLibArgs(const ArgList &Args,
393 ArgStringList &CmdArgs) const {
394 CmdArgs.push_back("-lcc_kext");
395}
Benjamin Kramere20e5082012-10-04 19:42:20 +0000396
397bool ToolChain::AddFastMathRuntimeIfAvailable(const ArgList &Args,
398 ArgStringList &CmdArgs) const {
399 // Check if -ffast-math or -funsafe-math is enabled.
400 Arg *A = Args.getLastArg(options::OPT_ffast_math,
401 options::OPT_fno_fast_math,
402 options::OPT_funsafe_math_optimizations,
403 options::OPT_fno_unsafe_math_optimizations);
404
405 if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
406 A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
407 return false;
408
409 // If crtfastmath.o exists add it to the arguments.
410 std::string Path = GetFilePath("crtfastmath.o");
411 if (Path == "crtfastmath.o") // Not found.
412 return false;
413
414 CmdArgs.push_back(Args.MakeArgString(Path));
415 return true;
416}