1//===-- Flang.cpp - Flang+LLVM 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#include "Flang.h"
10#include "Arch/RISCV.h"
11
12#include "clang/Basic/CodeGenOptions.h"
13#include "clang/Driver/CommonArgs.h"
14#include "clang/Driver/Options.h"
15#include "llvm/Frontend/Debug/Options.h"
16#include "llvm/Support/Path.h"
17#include "llvm/TargetParser/Host.h"
18#include "llvm/TargetParser/RISCVISAInfo.h"
19#include "llvm/TargetParser/RISCVTargetParser.h"
20
21#include <cassert>
22
23using namespace clang::driver;
24using namespace clang::driver::tools;
25using namespace clang;
26using namespace llvm::opt;
27
28/// Add -x lang to \p CmdArgs for \p Input.
29static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
30 ArgStringList &CmdArgs) {
31 CmdArgs.push_back(Elt: "-x");
32 // Map the driver type to the frontend type.
33 CmdArgs.push_back(Elt: types::getTypeName(Id: Input.getType()));
34}
35
36void Flang::addFortranDialectOptions(const ArgList &Args,
37 ArgStringList &CmdArgs) const {
38 Args.addAllArgs(Output&: CmdArgs, Ids: {options::OPT_ffixed_form,
39 options::OPT_ffree_form,
40 options::OPT_ffixed_line_length_EQ,
41 options::OPT_fopenacc,
42 options::OPT_finput_charset_EQ,
43 options::OPT_fimplicit_none,
44 options::OPT_fimplicit_none_ext,
45 options::OPT_fno_implicit_none,
46 options::OPT_fbackslash,
47 options::OPT_fno_backslash,
48 options::OPT_flogical_abbreviations,
49 options::OPT_fno_logical_abbreviations,
50 options::OPT_fxor_operator,
51 options::OPT_fno_xor_operator,
52 options::OPT_falternative_parameter_statement,
53 options::OPT_fdefault_real_8,
54 options::OPT_fdefault_integer_8,
55 options::OPT_fdefault_double_8,
56 options::OPT_flarge_sizes,
57 options::OPT_fno_automatic,
58 options::OPT_fhermetic_module_files,
59 options::OPT_frealloc_lhs,
60 options::OPT_fno_realloc_lhs,
61 options::OPT_fsave_main_program,
62 options::OPT_fd_lines_as_code,
63 options::OPT_fd_lines_as_comments,
64 options::OPT_fno_save_main_program});
65}
66
67void Flang::addPreprocessingOptions(const ArgList &Args,
68 ArgStringList &CmdArgs) const {
69 Args.addAllArgs(Output&: CmdArgs,
70 Ids: {options::OPT_P, options::OPT_D, options::OPT_U,
71 options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
72}
73
74/// @C shouldLoopVersion
75///
76/// Check if Loop Versioning should be enabled.
77/// We look for the last of one of the following:
78/// -Ofast, -O4, -O<number> and -f[no-]version-loops-for-stride.
79/// Loop versioning is disabled if the last option is
80/// -fno-version-loops-for-stride.
81/// Loop versioning is enabled if the last option is one of:
82/// -floop-versioning
83/// -Ofast
84/// -O4
85/// -O3
86/// For all other cases, loop versioning is is disabled.
87///
88/// The gfortran compiler automatically enables the option for -O3 or -Ofast.
89///
90/// @return true if loop-versioning should be enabled, otherwise false.
91static bool shouldLoopVersion(const ArgList &Args) {
92 const Arg *LoopVersioningArg = Args.getLastArg(
93 Ids: options::OPT_Ofast, Ids: options::OPT_O, Ids: options::OPT_O4,
94 Ids: options::OPT_floop_versioning, Ids: options::OPT_fno_loop_versioning);
95 if (!LoopVersioningArg)
96 return false;
97
98 if (LoopVersioningArg->getOption().matches(ID: options::OPT_fno_loop_versioning))
99 return false;
100
101 if (LoopVersioningArg->getOption().matches(ID: options::OPT_floop_versioning))
102 return true;
103
104 if (LoopVersioningArg->getOption().matches(ID: options::OPT_Ofast) ||
105 LoopVersioningArg->getOption().matches(ID: options::OPT_O4))
106 return true;
107
108 if (LoopVersioningArg->getOption().matches(ID: options::OPT_O)) {
109 StringRef S(LoopVersioningArg->getValue());
110 unsigned OptLevel = 0;
111 // Note -Os or Oz woould "fail" here, so return false. Which is the
112 // desiered behavior.
113 if (S.getAsInteger(Radix: 10, Result&: OptLevel))
114 return false;
115
116 return OptLevel > 2;
117 }
118
119 llvm_unreachable("We should not end up here");
120 return false;
121}
122
123void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
124 Args.addAllArgs(Output&: CmdArgs,
125 Ids: {options::OPT_module_dir, options::OPT_fdebug_module_writer,
126 options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
127 options::OPT_std_EQ, options::OPT_W_Joined,
128 options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ,
129 options::OPT_funderscoring, options::OPT_fno_underscoring,
130 options::OPT_funsigned, options::OPT_fno_unsigned,
131 options::OPT_finstrument_functions});
132
133 llvm::codegenoptions::DebugInfoKind DebugInfoKind;
134 if (Args.hasArg(Ids: options::OPT_gN_Group)) {
135 Arg *gNArg = Args.getLastArg(Ids: options::OPT_gN_Group);
136 DebugInfoKind = debugLevelToInfoKind(A: *gNArg);
137 } else if (Args.hasArg(Ids: options::OPT_g_Flag)) {
138 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
139 } else {
140 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
141 }
142 addDebugInfoKind(CmdArgs, DebugInfoKind);
143}
144
145void Flang::addCodegenOptions(const ArgList &Args,
146 ArgStringList &CmdArgs) const {
147 Arg *stackArrays =
148 Args.getLastArg(Ids: options::OPT_Ofast, Ids: options::OPT_fstack_arrays,
149 Ids: options::OPT_fno_stack_arrays);
150 if (stackArrays &&
151 !stackArrays->getOption().matches(ID: options::OPT_fno_stack_arrays))
152 CmdArgs.push_back(Elt: "-fstack-arrays");
153
154 handleInterchangeLoopsArgs(Args, CmdArgs);
155 handleVectorizeLoopsArgs(Args, CmdArgs);
156 handleVectorizeSLPArgs(Args, CmdArgs);
157
158 if (shouldLoopVersion(Args))
159 CmdArgs.push_back(Elt: "-fversion-loops-for-stride");
160
161 for (const auto &arg :
162 Args.getAllArgValues(Id: options::OPT_frepack_arrays_contiguity_EQ))
163 if (arg != "whole" && arg != "innermost") {
164 getToolChain().getDriver().Diag(DiagID: diag::err_drv_unsupported_option_argument)
165 << "-frepack-arrays-contiguity=" << arg;
166 }
167
168 Args.addAllArgs(
169 Output&: CmdArgs,
170 Ids: {options::OPT_fdo_concurrent_to_openmp_EQ,
171 options::OPT_flang_experimental_hlfir,
172 options::OPT_flang_deprecated_no_hlfir,
173 options::OPT_fno_ppc_native_vec_elem_order,
174 options::OPT_fppc_native_vec_elem_order, options::OPT_finit_global_zero,
175 options::OPT_fno_init_global_zero, options::OPT_frepack_arrays,
176 options::OPT_fno_repack_arrays,
177 options::OPT_frepack_arrays_contiguity_EQ,
178 options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
179 options::OPT_ftime_report, options::OPT_ftime_report_EQ,
180 options::OPT_funroll_loops, options::OPT_fno_unroll_loops});
181}
182
183void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
184 // ParsePICArgs parses -fPIC/-fPIE and their variants and returns a tuple of
185 // (RelocationModel, PICLevel, IsPIE).
186 llvm::Reloc::Model RelocationModel;
187 unsigned PICLevel;
188 bool IsPIE;
189 std::tie(args&: RelocationModel, args&: PICLevel, args&: IsPIE) =
190 ParsePICArgs(ToolChain: getToolChain(), Args);
191
192 if (auto *RMName = RelocationModelName(Model: RelocationModel)) {
193 CmdArgs.push_back(Elt: "-mrelocation-model");
194 CmdArgs.push_back(Elt: RMName);
195 }
196 if (PICLevel > 0) {
197 CmdArgs.push_back(Elt: "-pic-level");
198 CmdArgs.push_back(Elt: PICLevel == 1 ? "1" : "2");
199 if (IsPIE)
200 CmdArgs.push_back(Elt: "-pic-is-pie");
201 }
202}
203
204void Flang::AddAArch64TargetArgs(const ArgList &Args,
205 ArgStringList &CmdArgs) const {
206 // Handle -msve_vector_bits=<bits>
207 if (Arg *A = Args.getLastArg(Ids: options::OPT_msve_vector_bits_EQ)) {
208 StringRef Val = A->getValue();
209 const Driver &D = getToolChain().getDriver();
210 if (Val == "128" || Val == "256" || Val == "512" || Val == "1024" ||
211 Val == "2048" || Val == "128+" || Val == "256+" || Val == "512+" ||
212 Val == "1024+" || Val == "2048+") {
213 unsigned Bits = 0;
214 if (!Val.consume_back(Suffix: "+")) {
215 [[maybe_unused]] bool Invalid = Val.getAsInteger(Radix: 10, Result&: Bits);
216 assert(!Invalid && "Failed to parse value");
217 CmdArgs.push_back(
218 Elt: Args.MakeArgString(Str: "-mvscale-max=" + llvm::Twine(Bits / 128)));
219 }
220
221 [[maybe_unused]] bool Invalid = Val.getAsInteger(Radix: 10, Result&: Bits);
222 assert(!Invalid && "Failed to parse value");
223 CmdArgs.push_back(
224 Elt: Args.MakeArgString(Str: "-mvscale-min=" + llvm::Twine(Bits / 128)));
225 // Silently drop requests for vector-length agnostic code as it's implied.
226 } else if (Val != "scalable")
227 // Handle the unsupported values passed to msve-vector-bits.
228 D.Diag(DiagID: diag::err_drv_unsupported_option_argument)
229 << A->getSpelling() << Val;
230 }
231}
232
233void Flang::AddLoongArch64TargetArgs(const ArgList &Args,
234 ArgStringList &CmdArgs) const {
235 const Driver &D = getToolChain().getDriver();
236 // Currently, flang only support `-mabi=lp64d` in LoongArch64.
237 if (const Arg *A = Args.getLastArg(Ids: options::OPT_mabi_EQ)) {
238 StringRef V = A->getValue();
239 if (V != "lp64d") {
240 D.Diag(DiagID: diag::err_drv_argument_not_allowed_with) << "-mabi" << V;
241 }
242 }
243
244 if (const Arg *A = Args.getLastArg(Ids: options::OPT_mannotate_tablejump,
245 Ids: options::OPT_mno_annotate_tablejump)) {
246 if (A->getOption().matches(ID: options::OPT_mannotate_tablejump)) {
247 CmdArgs.push_back(Elt: "-mllvm");
248 CmdArgs.push_back(Elt: "-loongarch-annotate-tablejump");
249 }
250 }
251}
252
253void Flang::AddPPCTargetArgs(const ArgList &Args,
254 ArgStringList &CmdArgs) const {
255 const Driver &D = getToolChain().getDriver();
256 bool VecExtabi = false;
257
258 if (const Arg *A = Args.getLastArg(Ids: options::OPT_mabi_EQ)) {
259 StringRef V = A->getValue();
260 if (V == "vec-extabi")
261 VecExtabi = true;
262 else if (V == "vec-default")
263 VecExtabi = false;
264 else
265 D.Diag(DiagID: diag::err_drv_unsupported_option_argument)
266 << A->getSpelling() << V;
267 }
268
269 const llvm::Triple &T = getToolChain().getTriple();
270 if (VecExtabi) {
271 if (!T.isOSAIX()) {
272 D.Diag(DiagID: diag::err_drv_unsupported_opt_for_target)
273 << "-mabi=vec-extabi" << T.str();
274 }
275 CmdArgs.push_back(Elt: "-mabi=vec-extabi");
276 }
277}
278
279void Flang::AddRISCVTargetArgs(const ArgList &Args,
280 ArgStringList &CmdArgs) const {
281 const Driver &D = getToolChain().getDriver();
282 const llvm::Triple &Triple = getToolChain().getTriple();
283
284 StringRef ABIName = riscv::getRISCVABI(Args, Triple);
285 if (ABIName == "lp64" || ABIName == "lp64f" || ABIName == "lp64d")
286 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-mabi=" + ABIName));
287 else
288 D.Diag(DiagID: diag::err_drv_unsupported_option_argument) << "-mabi=" << ABIName;
289
290 // Handle -mrvv-vector-bits=<bits>
291 if (Arg *A = Args.getLastArg(Ids: options::OPT_mrvv_vector_bits_EQ)) {
292 StringRef Val = A->getValue();
293
294 // Get minimum VLen from march.
295 unsigned MinVLen = 0;
296 std::string Arch = riscv::getRISCVArch(Args, Triple);
297 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
298 Arch, /*EnableExperimentalExtensions*/ EnableExperimentalExtension: true);
299 // Ignore parsing error.
300 if (!errorToBool(Err: ISAInfo.takeError()))
301 MinVLen = (*ISAInfo)->getMinVLen();
302
303 // If the value is "zvl", use MinVLen from march. Otherwise, try to parse
304 // as integer as long as we have a MinVLen.
305 unsigned Bits = 0;
306 if (Val == "zvl" && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
307 Bits = MinVLen;
308 } else if (!Val.getAsInteger(Radix: 10, Result&: Bits)) {
309 // Only accept power of 2 values beteen RVVBitsPerBlock and 65536 that
310 // at least MinVLen.
311 if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
312 Bits > 65536 || !llvm::isPowerOf2_32(Value: Bits))
313 Bits = 0;
314 }
315
316 // If we got a valid value try to use it.
317 if (Bits != 0) {
318 unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
319 CmdArgs.push_back(
320 Elt: Args.MakeArgString(Str: "-mvscale-max=" + llvm::Twine(VScaleMin)));
321 CmdArgs.push_back(
322 Elt: Args.MakeArgString(Str: "-mvscale-min=" + llvm::Twine(VScaleMin)));
323 } else if (Val != "scalable") {
324 // Handle the unsupported values passed to mrvv-vector-bits.
325 D.Diag(DiagID: diag::err_drv_unsupported_option_argument)
326 << A->getSpelling() << Val;
327 }
328 }
329}
330
331void Flang::AddX86_64TargetArgs(const ArgList &Args,
332 ArgStringList &CmdArgs) const {
333 if (Arg *A = Args.getLastArg(Ids: options::OPT_masm_EQ)) {
334 StringRef Value = A->getValue();
335 if (Value == "intel" || Value == "att") {
336 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-mllvm"));
337 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-x86-asm-syntax=" + Value));
338 } else {
339 getToolChain().getDriver().Diag(DiagID: diag::err_drv_unsupported_option_argument)
340 << A->getSpelling() << Value;
341 }
342 }
343}
344
345static void addVSDefines(const ToolChain &TC, const ArgList &Args,
346 ArgStringList &CmdArgs) {
347
348 unsigned ver = 0;
349 const VersionTuple vt = TC.computeMSVCVersion(D: nullptr, Args);
350 ver = vt.getMajor() * 10000000 + vt.getMinor().value_or(u: 0) * 100000 +
351 vt.getSubminor().value_or(u: 0);
352 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-D_MSC_VER=" + Twine(ver / 100000)));
353 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-D_MSC_FULL_VER=" + Twine(ver)));
354 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-D_WIN32"));
355
356 const llvm::Triple &triple = TC.getTriple();
357 if (triple.isAArch64()) {
358 CmdArgs.push_back(Elt: "-D_M_ARM64=1");
359 } else if (triple.isX86() && triple.isArch32Bit()) {
360 CmdArgs.push_back(Elt: "-D_M_IX86=600");
361 } else if (triple.isX86() && triple.isArch64Bit()) {
362 CmdArgs.push_back(Elt: "-D_M_X64=100");
363 } else {
364 llvm_unreachable(
365 "Flang on Windows only supports X86_32, X86_64 and AArch64");
366 }
367}
368
369static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
370 ArgStringList &CmdArgs) {
371 assert(TC.getTriple().isKnownWindowsMSVCEnvironment() &&
372 "can only add VS runtime library on Windows!");
373
374 // Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI
375 // should only depend on msv(u)crt. LLVM still emits libgcc/compiler-rt
376 // functions in some cases like 128-bit integer math (__udivti3, __modti3,
377 // __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a
378 // dependency to Compiler-RT's builtin library where these are implemented.
379 CmdArgs.push_back(Elt: Args.MakeArgString(
380 Str: "--dependent-lib=" + TC.getCompilerRTBasename(Args, Component: "builtins")));
381
382 unsigned RTOptionID = options::OPT__SLASH_MT;
383 if (auto *rtl = Args.getLastArg(Ids: options::OPT_fms_runtime_lib_EQ)) {
384 RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())
385 .Case(S: "static", Value: options::OPT__SLASH_MT)
386 .Case(S: "static_dbg", Value: options::OPT__SLASH_MTd)
387 .Case(S: "dll", Value: options::OPT__SLASH_MD)
388 .Case(S: "dll_dbg", Value: options::OPT__SLASH_MDd)
389 .Default(Value: options::OPT__SLASH_MT);
390 }
391 switch (RTOptionID) {
392 case options::OPT__SLASH_MT:
393 CmdArgs.push_back(Elt: "-D_MT");
394 CmdArgs.push_back(Elt: "--dependent-lib=libcmt");
395 CmdArgs.push_back(Elt: "--dependent-lib=flang_rt.runtime.static.lib");
396 break;
397 case options::OPT__SLASH_MTd:
398 CmdArgs.push_back(Elt: "-D_MT");
399 CmdArgs.push_back(Elt: "-D_DEBUG");
400 CmdArgs.push_back(Elt: "--dependent-lib=libcmtd");
401 CmdArgs.push_back(Elt: "--dependent-lib=flang_rt.runtime.static_dbg.lib");
402 break;
403 case options::OPT__SLASH_MD:
404 CmdArgs.push_back(Elt: "-D_MT");
405 CmdArgs.push_back(Elt: "-D_DLL");
406 CmdArgs.push_back(Elt: "--dependent-lib=msvcrt");
407 CmdArgs.push_back(Elt: "--dependent-lib=flang_rt.runtime.dynamic.lib");
408 break;
409 case options::OPT__SLASH_MDd:
410 CmdArgs.push_back(Elt: "-D_MT");
411 CmdArgs.push_back(Elt: "-D_DEBUG");
412 CmdArgs.push_back(Elt: "-D_DLL");
413 CmdArgs.push_back(Elt: "--dependent-lib=msvcrtd");
414 CmdArgs.push_back(Elt: "--dependent-lib=flang_rt.runtime.dynamic_dbg.lib");
415 break;
416 }
417}
418
419void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
420 ArgStringList &CmdArgs) const {
421 if (Arg *A = Args.getLastArg(Ids: options::OPT_mcode_object_version_EQ)) {
422 StringRef Val = A->getValue();
423 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-mcode-object-version=" + Val));
424 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-mllvm"));
425 CmdArgs.push_back(
426 Elt: Args.MakeArgString(Str: "--amdhsa-code-object-version=" + Val));
427 }
428
429 const ToolChain &TC = getToolChain();
430 TC.addClangTargetOptions(DriverArgs: Args, CC1Args&: CmdArgs, DeviceOffloadKind: Action::OffloadKind::OFK_OpenMP);
431}
432
433void Flang::addTargetOptions(const ArgList &Args,
434 ArgStringList &CmdArgs) const {
435 const ToolChain &TC = getToolChain();
436 const llvm::Triple &Triple = TC.getEffectiveTriple();
437 const Driver &D = TC.getDriver();
438
439 std::string CPU = getCPUName(D, Args, T: Triple);
440 if (!CPU.empty()) {
441 CmdArgs.push_back(Elt: "-target-cpu");
442 CmdArgs.push_back(Elt: Args.MakeArgString(Str: CPU));
443 }
444
445 addOutlineAtomicsArgs(D, TC: getToolChain(), Args, CmdArgs, Triple);
446
447 // Add the target features.
448 switch (TC.getArch()) {
449 default:
450 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ ForAS: false);
451 break;
452 case llvm::Triple::aarch64:
453 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ ForAS: false);
454 AddAArch64TargetArgs(Args, CmdArgs);
455 break;
456
457 case llvm::Triple::r600:
458 case llvm::Triple::amdgcn:
459 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ ForAS: false);
460 AddAMDGPUTargetArgs(Args, CmdArgs);
461 break;
462 case llvm::Triple::riscv64:
463 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ ForAS: false);
464 AddRISCVTargetArgs(Args, CmdArgs);
465 break;
466 case llvm::Triple::x86_64:
467 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ ForAS: false);
468 AddX86_64TargetArgs(Args, CmdArgs);
469 break;
470 case llvm::Triple::ppc:
471 case llvm::Triple::ppc64:
472 case llvm::Triple::ppc64le:
473 AddPPCTargetArgs(Args, CmdArgs);
474 break;
475 case llvm::Triple::loongarch64:
476 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ ForAS: false);
477 AddLoongArch64TargetArgs(Args, CmdArgs);
478 break;
479 }
480
481 if (Arg *A = Args.getLastArg(Ids: options::OPT_fveclib)) {
482 StringRef Name = A->getValue();
483 if (Name == "SVML") {
484 if (Triple.getArch() != llvm::Triple::x86 &&
485 Triple.getArch() != llvm::Triple::x86_64)
486 D.Diag(DiagID: diag::err_drv_unsupported_opt_for_target)
487 << Name << Triple.getArchName();
488 } else if (Name == "AMDLIBM") {
489 if (Triple.getArch() != llvm::Triple::x86 &&
490 Triple.getArch() != llvm::Triple::x86_64)
491 D.Diag(DiagID: diag::err_drv_unsupported_opt_for_target)
492 << Name << Triple.getArchName();
493 } else if (Name == "libmvec") {
494 if (Triple.getArch() != llvm::Triple::x86 &&
495 Triple.getArch() != llvm::Triple::x86_64 &&
496 Triple.getArch() != llvm::Triple::aarch64 &&
497 Triple.getArch() != llvm::Triple::aarch64_be)
498 D.Diag(DiagID: diag::err_drv_unsupported_opt_for_target)
499 << Name << Triple.getArchName();
500 } else if (Name == "SLEEF" || Name == "ArmPL") {
501 if (Triple.getArch() != llvm::Triple::aarch64 &&
502 Triple.getArch() != llvm::Triple::aarch64_be)
503 D.Diag(DiagID: diag::err_drv_unsupported_opt_for_target)
504 << Name << Triple.getArchName();
505 }
506
507 if (Triple.isOSDarwin()) {
508 // flang doesn't currently suport nostdlib, nodefaultlibs. Adding these
509 // here incase they are added someday
510 if (!Args.hasArg(Ids: options::OPT_nostdlib, Ids: options::OPT_nodefaultlibs)) {
511 if (A->getValue() == StringRef{"Accelerate"}) {
512 CmdArgs.push_back(Elt: "-framework");
513 CmdArgs.push_back(Elt: "Accelerate");
514 }
515 }
516 }
517 A->render(Args, Output&: CmdArgs);
518 }
519
520 if (Triple.isKnownWindowsMSVCEnvironment()) {
521 processVSRuntimeLibrary(TC, Args, CmdArgs);
522 addVSDefines(TC, Args, CmdArgs);
523 }
524
525 // TODO: Add target specific flags, ABI, mtune option etc.
526 if (const Arg *A = Args.getLastArg(Ids: options::OPT_mtune_EQ)) {
527 CmdArgs.push_back(Elt: "-tune-cpu");
528 if (A->getValue() == StringRef{"native"})
529 CmdArgs.push_back(Elt: Args.MakeArgString(Str: llvm::sys::getHostCPUName()));
530 else
531 CmdArgs.push_back(Elt: A->getValue());
532 }
533
534 Args.addAllArgs(Output&: CmdArgs,
535 Ids: {options::OPT_fverbose_asm, options::OPT_fno_verbose_asm});
536}
537
538void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
539 const JobAction &JA, const ArgList &Args,
540 ArgStringList &CmdArgs) const {
541 bool IsOpenMPDevice = JA.isDeviceOffloading(OKind: Action::OFK_OpenMP);
542 bool IsHostOffloadingAction = JA.isHostOffloading(OKind: Action::OFK_OpenMP) ||
543 JA.isHostOffloading(OKind: C.getActiveOffloadKinds());
544
545 // Skips the primary input file, which is the input file that the compilation
546 // proccess will be executed upon (e.g. the host bitcode file) and
547 // adds other secondary input (e.g. device bitcode files for embedding to the
548 // -fembed-offload-object argument or the host IR file for proccessing
549 // during device compilation to the fopenmp-host-ir-file-path argument via
550 // OpenMPDeviceInput). This is condensed logic from the ConstructJob
551 // function inside of the Clang driver for pushing on further input arguments
552 // needed for offloading during various phases of compilation.
553 for (size_t i = 1; i < Inputs.size(); ++i) {
554 if (Inputs[i].getType() == types::TY_Nothing) {
555 // contains nothing, so it's skippable
556 } else if (IsHostOffloadingAction) {
557 CmdArgs.push_back(
558 Elt: Args.MakeArgString(Str: "-fembed-offload-object=" +
559 getToolChain().getInputFilename(Input: Inputs[i])));
560 } else if (IsOpenMPDevice) {
561 if (Inputs[i].getFilename()) {
562 CmdArgs.push_back(Elt: "-fopenmp-host-ir-file-path");
563 CmdArgs.push_back(Elt: Args.MakeArgString(Str: Inputs[i].getFilename()));
564 } else {
565 llvm_unreachable("missing openmp host-ir file for device offloading");
566 }
567 } else {
568 llvm_unreachable(
569 "unexpectedly given multiple inputs or given unknown input");
570 }
571 }
572
573 if (IsOpenMPDevice) {
574 // -fopenmp-is-target-device is passed along to tell the frontend that it is
575 // generating code for a device, so that only the relevant code is emitted.
576 CmdArgs.push_back(Elt: "-fopenmp-is-target-device");
577
578 // When in OpenMP offloading mode, enable debugging on the device.
579 Args.AddAllArgs(Output&: CmdArgs, Id0: options::OPT_fopenmp_target_debug_EQ);
580 if (Args.hasFlag(Pos: options::OPT_fopenmp_target_debug,
581 Neg: options::OPT_fno_openmp_target_debug, /*Default=*/false))
582 CmdArgs.push_back(Elt: "-fopenmp-target-debug");
583
584 // When in OpenMP offloading mode, forward assumptions information about
585 // thread and team counts in the device.
586 if (Args.hasFlag(Pos: options::OPT_fopenmp_assume_teams_oversubscription,
587 Neg: options::OPT_fno_openmp_assume_teams_oversubscription,
588 /*Default=*/false))
589 CmdArgs.push_back(Elt: "-fopenmp-assume-teams-oversubscription");
590 if (Args.hasFlag(Pos: options::OPT_fopenmp_assume_threads_oversubscription,
591 Neg: options::OPT_fno_openmp_assume_threads_oversubscription,
592 /*Default=*/false))
593 CmdArgs.push_back(Elt: "-fopenmp-assume-threads-oversubscription");
594 if (Args.hasArg(Ids: options::OPT_fopenmp_assume_no_thread_state))
595 CmdArgs.push_back(Elt: "-fopenmp-assume-no-thread-state");
596 if (Args.hasArg(Ids: options::OPT_fopenmp_assume_no_nested_parallelism))
597 CmdArgs.push_back(Elt: "-fopenmp-assume-no-nested-parallelism");
598 if (!Args.hasFlag(Pos: options::OPT_offloadlib, Neg: options::OPT_no_offloadlib,
599 Default: true))
600 CmdArgs.push_back(Elt: "-nogpulib");
601 }
602
603 addOpenMPHostOffloadingArgs(C, JA, Args, CmdArgs);
604}
605
606static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
607 ArgStringList &CmdArgs) {
608 StringRef FPContract;
609 bool HonorINFs = true;
610 bool HonorNaNs = true;
611 bool ApproxFunc = false;
612 bool SignedZeros = true;
613 bool AssociativeMath = false;
614 bool ReciprocalMath = false;
615
616 LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None;
617
618 if (const Arg *A = Args.getLastArg(Ids: options::OPT_ffp_contract)) {
619 const StringRef Val = A->getValue();
620 if (Val == "fast" || Val == "off") {
621 FPContract = Val;
622 } else if (Val == "on") {
623 // Warn instead of error because users might have makefiles written for
624 // gfortran (which accepts -ffp-contract=on)
625 D.Diag(DiagID: diag::warn_drv_unsupported_option_for_flang)
626 << Val << A->getOption().getName() << "off";
627 FPContract = "off";
628 } else
629 // Clang's "fast-honor-pragmas" option is not supported because it is
630 // non-standard
631 D.Diag(DiagID: diag::err_drv_unsupported_option_argument)
632 << A->getSpelling() << Val;
633 }
634
635 for (const Arg *A : Args) {
636 auto optId = A->getOption().getID();
637 switch (optId) {
638 // if this isn't an FP option, skip the claim below
639 default:
640 continue;
641
642 case options::OPT_fcomplex_arithmetic_EQ: {
643 StringRef Val = A->getValue();
644 if (Val == "full")
645 Range = LangOptions::ComplexRangeKind::CX_Full;
646 else if (Val == "improved")
647 Range = LangOptions::ComplexRangeKind::CX_Improved;
648 else if (Val == "basic")
649 Range = LangOptions::ComplexRangeKind::CX_Basic;
650 else {
651 D.Diag(DiagID: diag::err_drv_unsupported_option_argument)
652 << A->getSpelling() << Val;
653 }
654 break;
655 }
656 case options::OPT_fhonor_infinities:
657 HonorINFs = true;
658 break;
659 case options::OPT_fno_honor_infinities:
660 HonorINFs = false;
661 break;
662 case options::OPT_fhonor_nans:
663 HonorNaNs = true;
664 break;
665 case options::OPT_fno_honor_nans:
666 HonorNaNs = false;
667 break;
668 case options::OPT_fapprox_func:
669 ApproxFunc = true;
670 break;
671 case options::OPT_fno_approx_func:
672 ApproxFunc = false;
673 break;
674 case options::OPT_fsigned_zeros:
675 SignedZeros = true;
676 break;
677 case options::OPT_fno_signed_zeros:
678 SignedZeros = false;
679 break;
680 case options::OPT_fassociative_math:
681 AssociativeMath = true;
682 break;
683 case options::OPT_fno_associative_math:
684 AssociativeMath = false;
685 break;
686 case options::OPT_freciprocal_math:
687 ReciprocalMath = true;
688 break;
689 case options::OPT_fno_reciprocal_math:
690 ReciprocalMath = false;
691 break;
692 case options::OPT_Ofast:
693 [[fallthrough]];
694 case options::OPT_ffast_math:
695 HonorINFs = false;
696 HonorNaNs = false;
697 AssociativeMath = true;
698 ReciprocalMath = true;
699 ApproxFunc = true;
700 SignedZeros = false;
701 FPContract = "fast";
702 break;
703 case options::OPT_fno_fast_math:
704 HonorINFs = true;
705 HonorNaNs = true;
706 AssociativeMath = false;
707 ReciprocalMath = false;
708 ApproxFunc = false;
709 SignedZeros = true;
710 // -fno-fast-math should undo -ffast-math so I return FPContract to the
711 // default. It is important to check it is "fast" (the default) so that
712 // --ffp-contract=off -fno-fast-math --> -ffp-contract=off
713 if (FPContract == "fast")
714 FPContract = "";
715 break;
716 }
717
718 // If we handled this option claim it
719 A->claim();
720 }
721
722 StringRef Recip = parseMRecipOption(Diags&: D.getDiags(), Args);
723 if (!Recip.empty())
724 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-mrecip=" + Recip));
725
726 if (Range != LangOptions::ComplexRangeKind::CX_None) {
727 std::string ComplexRangeStr = renderComplexRangeOption(Range);
728 CmdArgs.push_back(Elt: Args.MakeArgString(Str: ComplexRangeStr));
729 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-fcomplex-arithmetic=" +
730 complexRangeKindToStr(Range)));
731 }
732
733 if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
734 ApproxFunc && !SignedZeros &&
735 (FPContract == "fast" || FPContract.empty())) {
736 CmdArgs.push_back(Elt: "-ffast-math");
737 return;
738 }
739
740 if (!FPContract.empty())
741 CmdArgs.push_back(Elt: Args.MakeArgString(Str: "-ffp-contract=" + FPContract));
742
743 if (!HonorINFs)
744 CmdArgs.push_back(Elt: "-menable-no-infs");
745
746 if (!HonorNaNs)
747 CmdArgs.push_back(Elt: "-menable-no-nans");
748
749 if (ApproxFunc)
750 CmdArgs.push_back(Elt: "-fapprox-func");
751
752 if (!SignedZeros)
753 CmdArgs.push_back(Elt: "-fno-signed-zeros");
754
755 if (AssociativeMath && !SignedZeros)
756 CmdArgs.push_back(Elt: "-mreassociate");
757
758 if (ReciprocalMath)
759 CmdArgs.push_back(Elt: "-freciprocal-math");
760}
761
762static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
763 const InputInfo &Input) {
764 StringRef Format = "yaml";
765 if (const Arg *A = Args.getLastArg(Ids: options::OPT_fsave_optimization_record_EQ))
766 Format = A->getValue();
767
768 CmdArgs.push_back(Elt: "-opt-record-file");
769
770 const Arg *A = Args.getLastArg(Ids: options::OPT_foptimization_record_file_EQ);
771 if (A) {
772 CmdArgs.push_back(Elt: A->getValue());
773 } else {
774 SmallString<128> F;
775
776 if (Args.hasArg(Ids: options::OPT_c) || Args.hasArg(Ids: options::OPT_S)) {
777 if (Arg *FinalOutput = Args.getLastArg(Ids: options::OPT_o))
778 F = FinalOutput->getValue();
779 }
780
781 if (F.empty()) {
782 // Use the input filename.
783 F = llvm::sys::path::stem(path: Input.getBaseInput());
784 }
785
786 SmallString<32> Extension;
787 Extension += "opt.";
788 Extension += Format;
789
790 llvm::sys::path::replace_extension(path&: F, extension: Extension);
791 CmdArgs.push_back(Elt: Args.MakeArgString(Str: F));
792 }
793
794 if (const Arg *A =
795 Args.getLastArg(Ids: options::OPT_foptimization_record_passes_EQ)) {
796 CmdArgs.push_back(Elt: "-opt-record-passes");
797 CmdArgs.push_back(Elt: A->getValue());
798 }
799
800 if (!Format.empty()) {
801 CmdArgs.push_back(Elt: "-opt-record-format");
802 CmdArgs.push_back(Elt: Format.data());
803 }
804}
805
806void Flang::ConstructJob(Compilation &C, const JobAction &JA,
807 const InputInfo &Output, const InputInfoList &Inputs,
808 const ArgList &Args, const char *LinkingOutput) const {
809 const auto &TC = getToolChain();
810 const llvm::Triple &Triple = TC.getEffectiveTriple();
811 const std::string &TripleStr = Triple.getTriple();
812
813 const Driver &D = TC.getDriver();
814 ArgStringList CmdArgs;
815 DiagnosticsEngine &Diags = D.getDiags();
816
817 // Invoke ourselves in -fc1 mode.
818 CmdArgs.push_back(Elt: "-fc1");
819
820 // Add the "effective" target triple.
821 CmdArgs.push_back(Elt: "-triple");
822 CmdArgs.push_back(Elt: Args.MakeArgString(Str: TripleStr));
823
824 if (isa<PreprocessJobAction>(Val: JA)) {
825 CmdArgs.push_back(Elt: "-E");
826 if (Args.getLastArg(Ids: options::OPT_dM)) {
827 CmdArgs.push_back(Elt: "-dM");
828 }
829 } else if (isa<CompileJobAction>(Val: JA) || isa<BackendJobAction>(Val: JA)) {
830 if (JA.getType() == types::TY_Nothing) {
831 CmdArgs.push_back(Elt: "-fsyntax-only");
832 } else if (JA.getType() == types::TY_AST) {
833 CmdArgs.push_back(Elt: "-emit-ast");
834 } else if (JA.getType() == types::TY_LLVM_IR ||
835 JA.getType() == types::TY_LTO_IR) {
836 CmdArgs.push_back(Elt: "-emit-llvm");
837 } else if (JA.getType() == types::TY_LLVM_BC ||
838 JA.getType() == types::TY_LTO_BC) {
839 CmdArgs.push_back(Elt: "-emit-llvm-bc");
840 } else if (JA.getType() == types::TY_PP_Asm) {
841 CmdArgs.push_back(Elt: "-S");
842 } else {
843 assert(false && "Unexpected output type!");
844 }
845 } else if (isa<AssembleJobAction>(Val: JA)) {
846 CmdArgs.push_back(Elt: "-emit-obj");
847 } else if (isa<PrecompileJobAction>(Val: JA)) {
848 // The precompile job action is only needed for options such as -mcpu=help.
849 // Those will already have been handled by the fc1 driver.
850 } else {
851 assert(false && "Unexpected action class for Flang tool.");
852 }
853
854 const InputInfo &Input = Inputs[0];
855 types::ID InputType = Input.getType();
856
857 // Add preprocessing options like -I, -D, etc. if we are using the
858 // preprocessor (i.e. skip when dealing with e.g. binary files).
859 if (types::getPreprocessedType(Id: InputType) != types::TY_INVALID)
860 addPreprocessingOptions(Args, CmdArgs);
861
862 addFortranDialectOptions(Args, CmdArgs);
863
864 // 'flang -E' always produces output that is suitable for use as fixed form
865 // Fortran. However it is only valid free form source if the original is also
866 // free form. Ensure this logic does not incorrectly assume fixed-form for
867 // cases where it shouldn't, such as `flang -x f95 foo.f90`.
868 bool isAtemporaryPreprocessedFile =
869 Input.isFilename() &&
870 llvm::sys::path::extension(path: Input.getFilename())
871 .ends_with(Suffix: types::getTypeTempSuffix(Id: InputType, /*CLStyle=*/false));
872 if (InputType == types::TY_PP_Fortran && isAtemporaryPreprocessedFile &&
873 !Args.getLastArg(Ids: options::OPT_ffixed_form, Ids: options::OPT_ffree_form))
874 CmdArgs.push_back(Elt: "-ffixed-form");
875
876 handleColorDiagnosticsArgs(D, Args, CmdArgs);
877
878 // LTO mode is parsed by the Clang driver library.
879 LTOKind LTOMode = D.getLTOMode();
880 assert(LTOMode != LTOK_Unknown && "Unknown LTO mode.");
881 if (LTOMode == LTOK_Full)
882 CmdArgs.push_back(Elt: "-flto=full");
883 else if (LTOMode == LTOK_Thin) {
884 Diags.Report(
885 DiagID: Diags.getCustomDiagID(L: DiagnosticsEngine::Warning,
886 FormatString: "the option '-flto=thin' is a work in progress"));
887 CmdArgs.push_back(Elt: "-flto=thin");
888 }
889
890 // -fPIC and related options.
891 addPicOptions(Args, CmdArgs);
892
893 // Floating point related options
894 addFloatingPointOptions(D, Args, CmdArgs);
895
896 // Add target args, features, etc.
897 addTargetOptions(Args, CmdArgs);
898
899 llvm::Reloc::Model RelocationModel =
900 std::get<0>(t: ParsePICArgs(ToolChain: getToolChain(), Args));
901 // Add MCModel information
902 addMCModel(D, Args, Triple, RelocationModel, CmdArgs);
903
904 // Add Codegen options
905 addCodegenOptions(Args, CmdArgs);
906
907 // Add R Group options
908 Args.AddAllArgs(Output&: CmdArgs, Id0: options::OPT_R_Group);
909
910 // Remarks can be enabled with any of the `-f.*optimization-record.*` flags.
911 if (willEmitRemarks(Args))
912 renderRemarksOptions(Args, CmdArgs, Input);
913
914 // Add other compile options
915 addOtherOptions(Args, CmdArgs);
916
917 // Disable all warnings
918 // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
919 Args.AddLastArg(Output&: CmdArgs, Ids: options::OPT_w);
920
921 // recognise options: fprofile-generate -fprofile-use=
922 Args.addAllArgs(
923 Output&: CmdArgs, Ids: {options::OPT_fprofile_generate, options::OPT_fprofile_use_EQ});
924
925 // Forward flags for OpenMP. We don't do this if the current action is an
926 // device offloading action other than OpenMP.
927 if (Args.hasFlag(Pos: options::OPT_fopenmp, PosAlias: options::OPT_fopenmp_EQ,
928 Neg: options::OPT_fno_openmp, Default: false) &&
929 (JA.isDeviceOffloading(OKind: Action::OFK_None) ||
930 JA.isDeviceOffloading(OKind: Action::OFK_OpenMP))) {
931 switch (D.getOpenMPRuntime(Args)) {
932 case Driver::OMPRT_OMP:
933 case Driver::OMPRT_IOMP5:
934 // Clang can generate useful OpenMP code for these two runtime libraries.
935 CmdArgs.push_back(Elt: "-fopenmp");
936 Args.AddAllArgs(Output&: CmdArgs, Id0: options::OPT_fopenmp_version_EQ);
937
938 if (Args.hasArg(Ids: options::OPT_fopenmp_force_usm))
939 CmdArgs.push_back(Elt: "-fopenmp-force-usm");
940
941 // FIXME: Clang supports a whole bunch more flags here.
942 break;
943 default:
944 // By default, if Clang doesn't know how to generate useful OpenMP code
945 // for a specific runtime library, we just don't pass the '-fopenmp' flag
946 // down to the actual compilation.
947 // FIXME: It would be better to have a mode which *only* omits IR
948 // generation based on the OpenMP support so that we get consistent
949 // semantic analysis, etc.
950 const Arg *A = Args.getLastArg(Ids: options::OPT_fopenmp_EQ);
951 D.Diag(DiagID: diag::warn_drv_unsupported_openmp_library)
952 << A->getSpelling() << A->getValue();
953 break;
954 }
955 }
956
957 // Pass the path to compiler resource files.
958 CmdArgs.push_back(Elt: "-resource-dir");
959 CmdArgs.push_back(Elt: D.ResourceDir.c_str());
960
961 // Offloading related options
962 addOffloadOptions(C, Inputs, JA, Args, CmdArgs);
963
964 // Forward -Xflang arguments to -fc1
965 Args.AddAllArgValues(Output&: CmdArgs, Id0: options::OPT_Xflang);
966
967 CodeGenOptions::FramePointerKind FPKeepKind =
968 getFramePointerKind(Args, Triple);
969
970 const char *FPKeepKindStr = nullptr;
971 switch (FPKeepKind) {
972 case CodeGenOptions::FramePointerKind::None:
973 FPKeepKindStr = "-mframe-pointer=none";
974 break;
975 case CodeGenOptions::FramePointerKind::Reserved:
976 FPKeepKindStr = "-mframe-pointer=reserved";
977 break;
978 case CodeGenOptions::FramePointerKind::NonLeaf:
979 FPKeepKindStr = "-mframe-pointer=non-leaf";
980 break;
981 case CodeGenOptions::FramePointerKind::All:
982 FPKeepKindStr = "-mframe-pointer=all";
983 break;
984 }
985 assert(FPKeepKindStr && "unknown FramePointerKind");
986 CmdArgs.push_back(Elt: FPKeepKindStr);
987
988 // Forward -mllvm options to the LLVM option parser. In practice, this means
989 // forwarding to `-fc1` as that's where the LLVM parser is run.
990 for (const Arg *A : Args.filtered(Ids: options::OPT_mllvm)) {
991 A->claim();
992 A->render(Args, Output&: CmdArgs);
993 }
994
995 for (const Arg *A : Args.filtered(Ids: options::OPT_mmlir)) {
996 A->claim();
997 A->render(Args, Output&: CmdArgs);
998 }
999
1000 // Remove any unsupported gfortran diagnostic options
1001 for (const Arg *A : Args.filtered(Ids: options::OPT_flang_ignored_w_Group)) {
1002 A->claim();
1003 D.Diag(DiagID: diag::warn_drv_unsupported_diag_option_for_flang)
1004 << A->getOption().getName();
1005 }
1006
1007 // Optimization level for CodeGen.
1008 if (const Arg *A = Args.getLastArg(Ids: options::OPT_O_Group)) {
1009 if (A->getOption().matches(ID: options::OPT_O4)) {
1010 CmdArgs.push_back(Elt: "-O3");
1011 D.Diag(DiagID: diag::warn_O4_is_O3);
1012 } else if (A->getOption().matches(ID: options::OPT_Ofast)) {
1013 CmdArgs.push_back(Elt: "-O3");
1014 D.Diag(DiagID: diag::warn_drv_deprecated_arg_ofast_for_flang);
1015 } else {
1016 A->render(Args, Output&: CmdArgs);
1017 }
1018 }
1019
1020 renderCommonIntegerOverflowOptions(Args, CmdArgs);
1021
1022 assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
1023 if (Output.isFilename()) {
1024 CmdArgs.push_back(Elt: "-o");
1025 CmdArgs.push_back(Elt: Output.getFilename());
1026 }
1027
1028 if (Args.getLastArg(Ids: options::OPT_save_temps_EQ))
1029 Args.AddLastArg(Output&: CmdArgs, Ids: options::OPT_save_temps_EQ);
1030
1031 addDashXForInput(Args, Input, CmdArgs);
1032
1033 bool FRecordCmdLine = false;
1034 bool GRecordCmdLine = false;
1035 if (shouldRecordCommandLine(TC, Args, FRecordCommandLine&: FRecordCmdLine, GRecordCommandLine&: GRecordCmdLine)) {
1036 const char *CmdLine = renderEscapedCommandLine(TC, Args);
1037 if (FRecordCmdLine) {
1038 CmdArgs.push_back(Elt: "-record-command-line");
1039 CmdArgs.push_back(Elt: CmdLine);
1040 }
1041 if (TC.UseDwarfDebugFlags() || GRecordCmdLine) {
1042 CmdArgs.push_back(Elt: "-dwarf-debug-flags");
1043 CmdArgs.push_back(Elt: CmdLine);
1044 }
1045 }
1046
1047 // The input could be Ty_Nothing when "querying" options such as -mcpu=help
1048 // are used.
1049 ArrayRef<InputInfo> FrontendInputs = Input;
1050 if (Input.isNothing())
1051 FrontendInputs = {};
1052
1053 for (const InputInfo &Input : FrontendInputs) {
1054 if (Input.isFilename())
1055 CmdArgs.push_back(Elt: Input.getFilename());
1056 else
1057 Input.getInputArg().renderAsInput(Args, Output&: CmdArgs);
1058 }
1059
1060 const char *Exec = Args.MakeArgString(Str: D.GetProgramPath(Name: "flang", TC));
1061 C.addCommand(C: std::make_unique<Command>(args: JA, args: *this,
1062 args: ResponseFileSupport::AtFileUTF8(),
1063 args&: Exec, args&: CmdArgs, args: Inputs, args: Output));
1064}
1065
1066Flang::Flang(const ToolChain &TC) : Tool("flang", "flang frontend", TC) {}
1067
1068Flang::~Flang() {}
1069

source code of clang/lib/Driver/ToolChains/Flang.cpp