static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args, DiagnosticEngine &Diags, StringRef workingDirectory) { using namespace options; if (const Arg *A = Args.getLastArg(OPT_module_cache_path)) { Opts.ModuleCachePath = A->getValue(); } if (const Arg *A = Args.getLastArg(OPT_target_cpu)) Opts.TargetCPU = A->getValue(); if (const Arg *A = Args.getLastArg(OPT_index_store_path)) Opts.IndexStorePath = A->getValue(); for (const Arg *A : Args.filtered(OPT_Xcc)) { Opts.ExtraArgs.push_back(A->getValue()); } for (auto A : Args.getAllArgValues(OPT_debug_prefix_map)) { // Forward -debug-prefix-map arguments from Swift to Clang as // -fdebug-prefix-map. This is required to ensure DIFiles created there, // like "<swift-imported-modules>", have their paths remapped properly. // (Note, however, that Clang's usage of std::map means that the remapping // may not be applied in the same order, which can matter if one mapping is // a prefix of another.) Opts.ExtraArgs.push_back("-fdebug-prefix-map=" + A); } if (!workingDirectory.empty()) { // Provide a working directory to Clang as well if there are any -Xcc // options, in case some of them are search-related. But do it at the // beginning, so that an explicit -Xcc -working-directory will win. Opts.ExtraArgs.insert(Opts.ExtraArgs.begin(), { "-working-directory", workingDirectory }); } Opts.InferImportAsMember |= Args.hasArg(OPT_enable_infer_import_as_member); Opts.DumpClangDiagnostics |= Args.hasArg(OPT_dump_clang_diagnostics); if (Args.hasArg(OPT_embed_bitcode)) Opts.Mode = ClangImporterOptions::Modes::EmbedBitcode; if (auto *A = Args.getLastArg(OPT_import_objc_header)) Opts.BridgingHeader = A->getValue(); Opts.DisableSwiftBridgeAttr |= Args.hasArg(OPT_disable_swift_bridge_attr); Opts.DisableModulesValidateSystemHeaders |= Args.hasArg(OPT_disable_modules_validate_system_headers); Opts.DisableAdapterModules |= Args.hasArg(OPT_emit_imported_modules); if (const Arg *A = Args.getLastArg(OPT_pch_output_dir)) { Opts.PrecompiledHeaderOutputDir = A->getValue(); Opts.PCHDisableValidation |= Args.hasArg(OPT_pch_disable_validation); } Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support); return false; }
Optional<std::vector<std::string>> OutputFilesComputer::getOutputFilenamesFromCommandLineOrFilelist( const ArgList &args, DiagnosticEngine &diags) { if (const Arg *A = args.getLastArg(options::OPT_output_filelist)) { assert(!args.hasArg(options::OPT_o) && "don't use -o with -output-filelist"); return ArgsToFrontendOutputsConverter::readOutputFileList(A->getValue(), diags); } return args.getAllArgValues(options::OPT_o); }
// All inputs to this linker must be from CudaDeviceActions, as we need to look // at the Inputs' Actions in order to figure out which GPU architecture they // correspond to. void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const auto &TC = static_cast<const toolchains::CudaToolChain &>(getToolChain()); assert(TC.getTriple().isNVPTX() && "Wrong platform"); ArgStringList CmdArgs; CmdArgs.push_back("--cuda"); CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32"); CmdArgs.push_back(Args.MakeArgString("--create")); CmdArgs.push_back(Args.MakeArgString(Output.getFilename())); if (mustEmitDebugInfo(Args) == FullDebug) CmdArgs.push_back("-g"); for (const auto& II : Inputs) { auto *A = II.getAction(); assert(A->getInputs().size() == 1 && "Device offload action is expected to have a single input"); const char *gpu_arch_str = A->getOffloadingArch(); assert(gpu_arch_str && "Device action expected to have associated a GPU architecture!"); CudaArch gpu_arch = StringToCudaArch(gpu_arch_str); if (II.getType() == types::TY_PP_Asm && !shouldIncludePTX(Args, gpu_arch_str)) continue; // We need to pass an Arch of the form "sm_XX" for cubin files and // "compute_XX" for ptx. const char *Arch = (II.getType() == types::TY_PP_Asm) ? CudaVirtualArchToString(VirtualArchForCudaArch(gpu_arch)) : gpu_arch_str; CmdArgs.push_back(Args.MakeArgString(llvm::Twine("--image=profile=") + Arch + ",file=" + II.getFilename())); } for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_fatbinary)) CmdArgs.push_back(Args.MakeArgString(A)); const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); }
static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, DiagnosticEngine &Diags) { using namespace options; if (const Arg *A = Args.getLastArg(OPT_debug_crash_Group)) { Option Opt = A->getOption(); if (Opt.matches(OPT_debug_assert_immediately)) { debugFailWithAssertion(); } else if (Opt.matches(OPT_debug_crash_immediately)) { debugFailWithCrash(); } else if (Opt.matches(OPT_debug_assert_after_parse)) { // Set in FrontendOptions Opts.CrashMode = FrontendOptions::DebugCrashMode::AssertAfterParse; } else if (Opt.matches(OPT_debug_crash_after_parse)) { // Set in FrontendOptions Opts.CrashMode = FrontendOptions::DebugCrashMode::CrashAfterParse; } else { llvm_unreachable("Unknown debug_crash_Group option!"); } } if (const Arg *A = Args.getLastArg(OPT_dump_api_path)) { Opts.DumpAPIPath = A->getValue(); } Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil); Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil); Opts.DelayedFunctionBodyParsing |= Args.hasArg(OPT_delayed_function_body_parsing); Opts.EnableTesting |= Args.hasArg(OPT_enable_testing); Opts.EnableResilience |= Args.hasArg(OPT_enable_resilience); Opts.PrintStats |= Args.hasArg(OPT_print_stats); Opts.PrintClangStats |= Args.hasArg(OPT_print_clang_stats); Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies); Opts.DebugTimeCompilation |= Args.hasArg(OPT_debug_time_compilation); Opts.PlaygroundTransform |= Args.hasArg(OPT_playground); if (Args.hasArg(OPT_disable_playground_transform)) Opts.PlaygroundTransform = false; Opts.PlaygroundHighPerformance |= Args.hasArg(OPT_playground_high_performance); if (const Arg *A = Args.getLastArg(OPT_help, OPT_help_hidden)) { if (A->getOption().matches(OPT_help)) { Opts.PrintHelp = true; } else if (A->getOption().matches(OPT_help_hidden)) { Opts.PrintHelpHidden = true; } else { llvm_unreachable("Unknown help option parsed"); } } if (const Arg *A = Args.getLastArg(OPT_filelist)) { const Arg *primaryFileArg = Args.getLastArg(OPT_primary_file); auto primaryFileIndex = readFileList(Opts.InputFilenames, A, primaryFileArg); if (primaryFileArg) Opts.PrimaryInput = SelectedInput(primaryFileIndex); assert(!Args.hasArg(OPT_INPUT) && "mixing -filelist with inputs"); } else { for (const Arg *A : make_range(Args.filtered_begin(OPT_INPUT, OPT_primary_file), Args.filtered_end())) { if (A->getOption().matches(OPT_INPUT)) { Opts.InputFilenames.push_back(A->getValue()); } else if (A->getOption().matches(OPT_primary_file)) { Opts.PrimaryInput = SelectedInput(Opts.InputFilenames.size()); Opts.InputFilenames.push_back(A->getValue()); } else { llvm_unreachable("Unknown input-related argument!"); } } } Opts.ParseStdlib |= Args.hasArg(OPT_parse_stdlib); // Determine what the user has asked the frontend to do. FrontendOptions::ActionType &Action = Opts.RequestedAction; if (const Arg *A = Args.getLastArg(OPT_modes_Group)) { Option Opt = A->getOption(); if (Opt.matches(OPT_emit_object)) { Action = FrontendOptions::EmitObject; } else if (Opt.matches(OPT_emit_assembly)) { Action = FrontendOptions::EmitAssembly; } else if (Opt.matches(OPT_emit_ir)) { Action = FrontendOptions::EmitIR; } else if (Opt.matches(OPT_emit_bc)) { Action = FrontendOptions::EmitBC; } else if (Opt.matches(OPT_emit_sil)) { Action = FrontendOptions::EmitSIL; } else if (Opt.matches(OPT_emit_silgen)) { Action = FrontendOptions::EmitSILGen; } else if (Opt.matches(OPT_emit_sib)) { Action = FrontendOptions::EmitSIB; } else if (Opt.matches(OPT_emit_sibgen)) { Action = FrontendOptions::EmitSIBGen; } else if (Opt.matches(OPT_parse)) { Action = FrontendOptions::Parse; } else if (Opt.matches(OPT_dump_parse)) { Action = FrontendOptions::DumpParse; } else if (Opt.matches(OPT_dump_ast)) { Action = FrontendOptions::DumpAST; } else if (Opt.matches(OPT_dump_type_refinement_contexts)) { Action = FrontendOptions::DumpTypeRefinementContexts; } else if (Opt.matches(OPT_dump_interface_hash)) { Action = FrontendOptions::DumpInterfaceHash; } else if (Opt.matches(OPT_print_ast)) { Action = FrontendOptions::PrintAST; } else if (Opt.matches(OPT_repl) || Opt.matches(OPT_deprecated_integrated_repl)) { Action = FrontendOptions::REPL; } else if (Opt.matches(OPT_interpret)) { Action = FrontendOptions::Immediate; } else { llvm_unreachable("Unhandled mode option"); } } else { // We don't have a mode, so determine a default. if (Args.hasArg(OPT_emit_module, OPT_emit_module_path)) { // We've been told to emit a module, but have no other mode indicators. // As a result, put the frontend into EmitModuleOnly mode. // (Setting up module output will be handled below.) Action = FrontendOptions::EmitModuleOnly; } } if (Opts.RequestedAction == FrontendOptions::Immediate && Opts.PrimaryInput.hasValue()) { Diags.diagnose(SourceLoc(), diag::error_immediate_mode_primary_file); return true; } bool TreatAsSIL = Args.hasArg(OPT_parse_sil); if (!TreatAsSIL && Opts.InputFilenames.size() == 1) { // If we have exactly one input filename, and its extension is "sil", // treat the input as SIL. StringRef Input(Opts.InputFilenames[0]); TreatAsSIL = llvm::sys::path::extension(Input).endswith(SIL_EXTENSION); } else if (Opts.PrimaryInput.hasValue() && Opts.PrimaryInput->isFilename()) { // If we have a primary input and it's a filename with extension "sil", // treat the input as SIL. StringRef Input(Opts.InputFilenames[Opts.PrimaryInput->Index]); TreatAsSIL = llvm::sys::path::extension(Input).endswith(SIL_EXTENSION); } // If we have exactly one input filename, and its extension is "bc" or "ll", // treat the input as LLVM_IR. bool TreatAsLLVM = false; if (Opts.InputFilenames.size() == 1) { StringRef Input(Opts.InputFilenames[0]); TreatAsLLVM = llvm::sys::path::extension(Input).endswith(LLVM_BC_EXTENSION) || llvm::sys::path::extension(Input).endswith(LLVM_IR_EXTENSION); } if (Opts.RequestedAction == FrontendOptions::REPL) { if (!Opts.InputFilenames.empty()) { Diags.diagnose(SourceLoc(), diag::error_repl_requires_no_input_files); return true; } } else if (TreatAsSIL && Opts.PrimaryInput.hasValue()) { // If we have the SIL as our primary input, we can waive the one file // requirement as long as all the other inputs are SIBs. if (Opts.PrimaryInput.hasValue()) { for (unsigned i = 0, e = Opts.InputFilenames.size(); i != e; ++i) { if (i == Opts.PrimaryInput->Index) continue; StringRef File(Opts.InputFilenames[i]); if (!llvm::sys::path::extension(File).endswith(SIB_EXTENSION)) { Diags.diagnose(SourceLoc(), diag::error_mode_requires_one_sil_multi_sib); return true; } } } } else if (TreatAsSIL) { if (Opts.InputFilenames.size() != 1) { Diags.diagnose(SourceLoc(), diag::error_mode_requires_one_input_file); return true; } } else if (Opts.RequestedAction != FrontendOptions::NoneAction) { if (Opts.InputFilenames.empty()) { Diags.diagnose(SourceLoc(), diag::error_mode_requires_an_input_file); return true; } } if (Opts.RequestedAction == FrontendOptions::Immediate) { assert(!Opts.InputFilenames.empty()); Opts.ImmediateArgv.push_back(Opts.InputFilenames[0]); // argv[0] if (const Arg *A = Args.getLastArg(OPT__DASH_DASH)) { for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { Opts.ImmediateArgv.push_back(A->getValue(i)); } } } if (TreatAsSIL) Opts.InputKind = InputFileKind::IFK_SIL; else if (TreatAsLLVM) Opts.InputKind = InputFileKind::IFK_LLVM_IR; else if (Args.hasArg(OPT_parse_as_library)) Opts.InputKind = InputFileKind::IFK_Swift_Library; else if (Action == FrontendOptions::REPL) Opts.InputKind = InputFileKind::IFK_Swift_REPL; else Opts.InputKind = InputFileKind::IFK_Swift; if (const Arg *A = Args.getLastArg(OPT_output_filelist)) { readFileList(Opts.OutputFilenames, A); assert(!Args.hasArg(OPT_o) && "don't use -o with -output-filelist"); } else { Opts.OutputFilenames = Args.getAllArgValues(OPT_o); } bool UserSpecifiedModuleName = false; { const Arg *A = Args.getLastArg(OPT_module_name); StringRef ModuleName = Opts.ModuleName; if (A) { ModuleName = A->getValue(); UserSpecifiedModuleName = true; } else if (ModuleName.empty()) { // The user did not specify a module name, so determine a default fallback // based on other options. // Note: this code path will only be taken when running the frontend // directly; the driver should always pass -module-name when invoking the // frontend. if (Opts.RequestedAction == FrontendOptions::REPL) { // Default to a module named "REPL" if we're in REPL mode. ModuleName = "REPL"; } else if (!Opts.InputFilenames.empty()) { StringRef OutputFilename = Opts.getSingleOutputFilename(); if (OutputFilename.empty() || OutputFilename == "-" || llvm::sys::fs::is_directory(OutputFilename)) { ModuleName = Opts.InputFilenames[0]; } else { ModuleName = OutputFilename; } ModuleName = llvm::sys::path::stem(ModuleName); } } if (!Lexer::isIdentifier(ModuleName) || (ModuleName == STDLIB_NAME && !Opts.ParseStdlib)) { if (!Opts.actionHasOutput() || (Opts.InputKind == InputFileKind::IFK_Swift && Opts.InputFilenames.size() == 1)) { ModuleName = "main"; } else { auto DID = (ModuleName == STDLIB_NAME) ? diag::error_stdlib_module_name : diag::error_bad_module_name; Diags.diagnose(SourceLoc(), DID, ModuleName, A == nullptr); ModuleName = "__bad__"; } } Opts.ModuleName = ModuleName; } if (Opts.OutputFilenames.empty() || llvm::sys::fs::is_directory(Opts.getSingleOutputFilename())) { // No output filename was specified, or an output directory was specified. // Determine the correct output filename. // Note: this should typically only be used when invoking the frontend // directly, as the driver will always pass -o with an appropriate filename // if output is required for the requested action. StringRef Suffix; switch (Opts.RequestedAction) { case FrontendOptions::NoneAction: break; case FrontendOptions::Parse: case FrontendOptions::DumpParse: case FrontendOptions::DumpInterfaceHash: case FrontendOptions::DumpAST: case FrontendOptions::PrintAST: case FrontendOptions::DumpTypeRefinementContexts: // Textual modes. Opts.setSingleOutputFilename("-"); break; case FrontendOptions::EmitSILGen: case FrontendOptions::EmitSIL: { if (Opts.OutputFilenames.empty()) Opts.setSingleOutputFilename("-"); else Suffix = SIL_EXTENSION; break; } case FrontendOptions::EmitSIBGen: case FrontendOptions::EmitSIB: Suffix = SIB_EXTENSION; break; case FrontendOptions::EmitModuleOnly: Suffix = SERIALIZED_MODULE_EXTENSION; break; case FrontendOptions::Immediate: case FrontendOptions::REPL: // These modes have no frontend-generated output. Opts.OutputFilenames.clear(); break; case FrontendOptions::EmitAssembly: { if (Opts.OutputFilenames.empty()) Opts.setSingleOutputFilename("-"); else Suffix = "s"; break; } case FrontendOptions::EmitIR: { if (Opts.OutputFilenames.empty()) Opts.setSingleOutputFilename("-"); else Suffix = "ll"; break; } case FrontendOptions::EmitBC: { Suffix = "bc"; break; } case FrontendOptions::EmitObject: Suffix = "o"; break; } if (!Suffix.empty()) { // We need to deduce a file name. // First, if we're reading from stdin and we don't have a directory, // output to stdout. if (Opts.InputFilenames.size() == 1 && Opts.InputFilenames[0] == "-" && Opts.OutputFilenames.empty()) Opts.setSingleOutputFilename("-"); else { // We have a suffix, so determine an appropriate name. llvm::SmallString<128> Path(Opts.getSingleOutputFilename()); StringRef BaseName; if (Opts.PrimaryInput.hasValue() && Opts.PrimaryInput->isFilename()) { unsigned Index = Opts.PrimaryInput->Index; BaseName = llvm::sys::path::stem(Opts.InputFilenames[Index]); } else if (!UserSpecifiedModuleName && Opts.InputFilenames.size() == 1) { BaseName = llvm::sys::path::stem(Opts.InputFilenames[0]); } else { BaseName = Opts.ModuleName; } llvm::sys::path::append(Path, BaseName); llvm::sys::path::replace_extension(Path, Suffix); Opts.setSingleOutputFilename(Path.str()); } } if (Opts.OutputFilenames.empty()) { if (Opts.RequestedAction != FrontendOptions::REPL && Opts.RequestedAction != FrontendOptions::Immediate && Opts.RequestedAction != FrontendOptions::NoneAction) { Diags.diagnose(SourceLoc(), diag::error_no_output_filename_specified); return true; } } else if (Opts.getSingleOutputFilename() != "-" && llvm::sys::fs::is_directory(Opts.getSingleOutputFilename())) { Diags.diagnose(SourceLoc(), diag::error_implicit_output_file_is_directory, Opts.getSingleOutputFilename()); return true; } } auto determineOutputFilename = [&](std::string &output, OptSpecifier optWithoutPath, OptSpecifier optWithPath, const char *extension, bool useMainOutput) { if (const Arg *A = Args.getLastArg(optWithPath)) { Args.ClaimAllArgs(optWithoutPath); output = A->getValue(); return; } if (!Args.hasArg(optWithoutPath)) return; if (useMainOutput && !Opts.OutputFilenames.empty()) { output = Opts.getSingleOutputFilename(); return; } if (!output.empty()) return; StringRef OriginalPath; if (!Opts.OutputFilenames.empty() && Opts.getSingleOutputFilename() != "-") // Put the serialized diagnostics file next to the output file. OriginalPath = Opts.getSingleOutputFilename(); else if (Opts.PrimaryInput.hasValue() && Opts.PrimaryInput->isFilename()) // We have a primary input, so use that as the basis for the name of the // serialized diagnostics file. OriginalPath = llvm::sys::path::filename( Opts.InputFilenames[Opts.PrimaryInput->Index]); else // We don't have any better indication of name, so fall back on the // module name. OriginalPath = Opts.ModuleName; llvm::SmallString<128> Path(OriginalPath); llvm::sys::path::replace_extension(Path, extension); output = Path.str(); }; determineOutputFilename(Opts.DependenciesFilePath, OPT_emit_dependencies, OPT_emit_dependencies_path, "d", false); determineOutputFilename(Opts.ReferenceDependenciesFilePath, OPT_emit_reference_dependencies, OPT_emit_reference_dependencies_path, "swiftdeps", false); determineOutputFilename(Opts.SerializedDiagnosticsPath, OPT_serialize_diagnostics, OPT_serialize_diagnostics_path, "dia", false); determineOutputFilename(Opts.ObjCHeaderOutputPath, OPT_emit_objc_header, OPT_emit_objc_header_path, "h", false); if (const Arg *A = Args.getLastArg(OPT_emit_fixits_path)) { Opts.FixitsOutputPath = A->getValue(); } bool IsSIB = Opts.RequestedAction == FrontendOptions::EmitSIB || Opts.RequestedAction == FrontendOptions::EmitSIBGen; bool canUseMainOutputForModule = Opts.RequestedAction == FrontendOptions::EmitModuleOnly || IsSIB; auto ext = IsSIB ? SIB_EXTENSION : SERIALIZED_MODULE_EXTENSION; auto sibOpt = Opts.RequestedAction == FrontendOptions::EmitSIB ? OPT_emit_sib : OPT_emit_sibgen; determineOutputFilename(Opts.ModuleOutputPath, IsSIB ? sibOpt : OPT_emit_module, OPT_emit_module_path, ext, canUseMainOutputForModule); determineOutputFilename(Opts.ModuleDocOutputPath, OPT_emit_module_doc, OPT_emit_module_doc_path, SERIALIZED_MODULE_DOC_EXTENSION, false); if (!Opts.DependenciesFilePath.empty()) { switch (Opts.RequestedAction) { case FrontendOptions::NoneAction: case FrontendOptions::DumpParse: case FrontendOptions::DumpInterfaceHash: case FrontendOptions::DumpAST: case FrontendOptions::PrintAST: case FrontendOptions::DumpTypeRefinementContexts: case FrontendOptions::Immediate: case FrontendOptions::REPL: Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_dependencies); return true; case FrontendOptions::Parse: case FrontendOptions::EmitModuleOnly: case FrontendOptions::EmitSILGen: case FrontendOptions::EmitSIL: case FrontendOptions::EmitSIBGen: case FrontendOptions::EmitSIB: case FrontendOptions::EmitIR: case FrontendOptions::EmitBC: case FrontendOptions::EmitAssembly: case FrontendOptions::EmitObject: break; } } if (!Opts.ObjCHeaderOutputPath.empty()) { switch (Opts.RequestedAction) { case FrontendOptions::NoneAction: case FrontendOptions::DumpParse: case FrontendOptions::DumpInterfaceHash: case FrontendOptions::DumpAST: case FrontendOptions::PrintAST: case FrontendOptions::DumpTypeRefinementContexts: case FrontendOptions::Immediate: case FrontendOptions::REPL: Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_header); return true; case FrontendOptions::Parse: case FrontendOptions::EmitModuleOnly: case FrontendOptions::EmitSILGen: case FrontendOptions::EmitSIL: case FrontendOptions::EmitSIBGen: case FrontendOptions::EmitSIB: case FrontendOptions::EmitIR: case FrontendOptions::EmitBC: case FrontendOptions::EmitAssembly: case FrontendOptions::EmitObject: break; } } if (!Opts.ModuleOutputPath.empty() || !Opts.ModuleDocOutputPath.empty()) { switch (Opts.RequestedAction) { case FrontendOptions::NoneAction: case FrontendOptions::Parse: case FrontendOptions::DumpParse: case FrontendOptions::DumpInterfaceHash: case FrontendOptions::DumpAST: case FrontendOptions::PrintAST: case FrontendOptions::DumpTypeRefinementContexts: case FrontendOptions::EmitSILGen: case FrontendOptions::Immediate: case FrontendOptions::REPL: if (!Opts.ModuleOutputPath.empty()) Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module); else Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module_doc); return true; case FrontendOptions::EmitModuleOnly: case FrontendOptions::EmitSIL: case FrontendOptions::EmitSIBGen: case FrontendOptions::EmitSIB: case FrontendOptions::EmitIR: case FrontendOptions::EmitBC: case FrontendOptions::EmitAssembly: case FrontendOptions::EmitObject: break; } } if (const Arg *A = Args.getLastArg(OPT_module_link_name)) { Opts.ModuleLinkName = A->getValue(); } Opts.AlwaysSerializeDebuggingOptions |= Args.hasArg(OPT_serialize_debugging_options); Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import); Opts.ImportUnderlyingModule |= Args.hasArg(OPT_import_underlying_module); Opts.SILSerializeAll |= Args.hasArg(OPT_sil_serialize_all); if (const Arg *A = Args.getLastArg(OPT_import_objc_header)) { Opts.ImplicitObjCHeaderPath = A->getValue(); Opts.SerializeBridgingHeader |= !Opts.PrimaryInput && !Opts.ModuleOutputPath.empty(); } for (const Arg *A : make_range(Args.filtered_begin(OPT_import_module), Args.filtered_end())) { Opts.ImplicitImportModuleNames.push_back(A->getValue()); } for (const Arg *A : make_range(Args.filtered_begin(OPT_Xllvm), Args.filtered_end())) { Opts.LLVMArgs.push_back(A->getValue()); } return false; }
static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, DiagnosticEngine &Diags, const FrontendOptions &FrontendOpts, const SILOptions &SILOpts, StringRef SDKPath, StringRef ResourceDir, const llvm::Triple &Triple) { using namespace options; if (!SILOpts.SILOutputFileNameForDebugging.empty()) { Opts.DebugInfoKind = IRGenDebugInfoKind::LineTables; } else if (const Arg *A = Args.getLastArg(OPT_g_Group)) { if (A->getOption().matches(OPT_g)) Opts.DebugInfoKind = IRGenDebugInfoKind::Normal; else if (A->getOption().matches(options::OPT_gline_tables_only)) Opts.DebugInfoKind = IRGenDebugInfoKind::LineTables; else if (A->getOption().matches(options::OPT_gdwarf_types)) Opts.DebugInfoKind = IRGenDebugInfoKind::DwarfTypes; else assert(A->getOption().matches(options::OPT_gnone) && "unknown -g<kind> option"); if (Opts.DebugInfoKind > IRGenDebugInfoKind::LineTables) { ArgStringList RenderedArgs; for (auto A : Args) A->render(Args, RenderedArgs); CompilerInvocation::buildDWARFDebugFlags(Opts.DWARFDebugFlags, RenderedArgs, SDKPath, ResourceDir); // TODO: Should we support -fdebug-compilation-dir? llvm::SmallString<256> cwd; llvm::sys::fs::current_path(cwd); Opts.DebugCompilationDir = cwd.str(); } } for (const Arg *A : Args.filtered(OPT_Xcc)) { StringRef Opt = A->getValue(); if (Opt.startswith("-D") || Opt.startswith("-U")) Opts.ClangDefines.push_back(Opt); } for (const Arg *A : Args.filtered(OPT_l, OPT_framework)) { LibraryKind Kind; if (A->getOption().matches(OPT_l)) { Kind = LibraryKind::Library; } else if (A->getOption().matches(OPT_framework)) { Kind = LibraryKind::Framework; } else { llvm_unreachable("Unknown LinkLibrary option kind"); } Opts.LinkLibraries.push_back(LinkLibrary(A->getValue(), Kind)); } if (auto valueNames = Args.getLastArg(OPT_disable_llvm_value_names, OPT_enable_llvm_value_names)) { Opts.HasValueNamesSetting = true; Opts.ValueNames = valueNames->getOption().matches(OPT_enable_llvm_value_names); } Opts.DisableLLVMOptzns |= Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableLLVMARCOpts |= Args.hasArg(OPT_disable_llvm_arc_opts); Opts.DisableLLVMSLPVectorizer |= Args.hasArg(OPT_disable_llvm_slp_vectorizer); if (Args.hasArg(OPT_disable_llvm_verify)) Opts.Verify = false; Opts.EmitStackPromotionChecks |= Args.hasArg(OPT_stack_promotion_checks); if (const Arg *A = Args.getLastArg(OPT_stack_promotion_limit)) { unsigned limit; if (StringRef(A->getValue()).getAsInteger(10, limit)) { Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, A->getAsString(Args), A->getValue()); return true; } Opts.StackPromotionSizeLimit = limit; } if (Args.hasArg(OPT_autolink_force_load)) Opts.ForceLoadSymbolName = Args.getLastArgValue(OPT_module_link_name); Opts.ModuleName = FrontendOpts.ModuleName; if (Args.hasArg(OPT_use_jit)) Opts.UseJIT = true; for (const Arg *A : Args.filtered(OPT_verify_type_layout)) { Opts.VerifyTypeLayoutNames.push_back(A->getValue()); } for (const Arg *A : Args.filtered(OPT_disable_autolink_framework)) { Opts.DisableAutolinkFrameworks.push_back(A->getValue()); } Opts.GenerateProfile |= Args.hasArg(OPT_profile_generate); const Arg *ProfileUse = Args.getLastArg(OPT_profile_use); Opts.UseProfile = ProfileUse ? ProfileUse->getValue() : ""; Opts.PrintInlineTree |= Args.hasArg(OPT_print_llvm_inline_tree); Opts.UseSwiftCall = Args.hasArg(OPT_enable_swiftcall); // This is set to true by default. Opts.UseIncrementalLLVMCodeGen &= !Args.hasArg(OPT_disable_incremental_llvm_codegeneration); if (Args.hasArg(OPT_embed_bitcode)) Opts.EmbedMode = IRGenEmbedMode::EmbedBitcode; else if (Args.hasArg(OPT_embed_bitcode_marker)) Opts.EmbedMode = IRGenEmbedMode::EmbedMarker; if (Opts.EmbedMode == IRGenEmbedMode::EmbedBitcode) { // Keep track of backend options so we can embed them in a separate data // section and use them when building from the bitcode. This can be removed // when all the backend options are recorded in the IR. for (const Arg *A : Args) { // Do not encode output and input. if (A->getOption().getID() == options::OPT_o || A->getOption().getID() == options::OPT_INPUT || A->getOption().getID() == options::OPT_primary_file || A->getOption().getID() == options::OPT_embed_bitcode) continue; ArgStringList ASL; A->render(Args, ASL); for (ArgStringList::iterator it = ASL.begin(), ie = ASL.end(); it != ie; ++ it) { StringRef ArgStr(*it); Opts.CmdArgs.insert(Opts.CmdArgs.end(), ArgStr.begin(), ArgStr.end()); // using \00 to terminate to avoid problem decoding. Opts.CmdArgs.push_back('\0'); } } } if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) { Opts.SanitizeCoverage = parseSanitizerCoverageArgValue(A, Triple, Diags, Opts.Sanitizers); } else if (Opts.Sanitizers & SanitizerKind::Fuzzer) { // Automatically set coverage flags, unless coverage type was explicitly // requested. Opts.SanitizeCoverage.IndirectCalls = true; Opts.SanitizeCoverage.TraceCmp = true; Opts.SanitizeCoverage.TracePCGuard = true; Opts.SanitizeCoverage.CoverageType = llvm::SanitizerCoverageOptions::SCK_Edge; } if (Args.hasArg(OPT_disable_reflection_metadata)) { Opts.EnableReflectionMetadata = false; Opts.EnableReflectionNames = false; } if (Args.hasArg(OPT_disable_reflection_names)) { Opts.EnableReflectionNames = false; } if (Args.hasArg(OPT_enable_class_resilience)) { Opts.EnableClassResilience = true; } if (Args.hasArg(OPT_enable_resilience_bypass)) { Opts.EnableResilienceBypass = true; } for (const auto &Lib : Args.getAllArgValues(options::OPT_autolink_library)) Opts.LinkLibraries.push_back(LinkLibrary(Lib, LibraryKind::Library)); return false; }
void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const auto &TC = static_cast<const toolchains::CudaToolChain &>(getToolChain()); assert(TC.getTriple().isNVPTX() && "Wrong platform"); StringRef GPUArchName; // If this is an OpenMP action we need to extract the device architecture // from the -march=arch option. This option may come from -Xopenmp-target // flag or the default value. if (JA.isDeviceOffloading(Action::OFK_OpenMP)) { GPUArchName = Args.getLastArgValue(options::OPT_march_EQ); assert(!GPUArchName.empty() && "Must have an architecture passed in."); } else GPUArchName = JA.getOffloadingArch(); // Obtain architecture from the action. CudaArch gpu_arch = StringToCudaArch(GPUArchName); assert(gpu_arch != CudaArch::UNKNOWN && "Device action expected to have an architecture."); // Check that our installation's ptxas supports gpu_arch. if (!Args.hasArg(options::OPT_no_cuda_version_check)) { TC.CudaInstallation.CheckCudaVersionSupportsArch(gpu_arch); } ArgStringList CmdArgs; CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32"); if (Args.hasFlag(options::OPT_cuda_noopt_device_debug, options::OPT_no_cuda_noopt_device_debug, false)) { // ptxas does not accept -g option if optimization is enabled, so // we ignore the compiler's -O* options if we want debug info. CmdArgs.push_back("-g"); CmdArgs.push_back("--dont-merge-basicblocks"); CmdArgs.push_back("--return-at-end"); } else if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { // Map the -O we received to -O{0,1,2,3}. // // TODO: Perhaps we should map host -O2 to ptxas -O3. -O3 is ptxas's // default, so it may correspond more closely to the spirit of clang -O2. // -O3 seems like the least-bad option when -Osomething is specified to // clang but it isn't handled below. StringRef OOpt = "3"; if (A->getOption().matches(options::OPT_O4) || A->getOption().matches(options::OPT_Ofast)) OOpt = "3"; else if (A->getOption().matches(options::OPT_O0)) OOpt = "0"; else if (A->getOption().matches(options::OPT_O)) { // -Os, -Oz, and -O(anything else) map to -O2, for lack of better options. OOpt = llvm::StringSwitch<const char *>(A->getValue()) .Case("1", "1") .Case("2", "2") .Case("3", "3") .Case("s", "2") .Case("z", "2") .Default("2"); } CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt)); } else { // If no -O was passed, pass -O0 to ptxas -- no opt flag should correspond // to no optimizations, but ptxas's default is -O3. CmdArgs.push_back("-O0"); } // Pass -v to ptxas if it was passed to the driver. if (Args.hasArg(options::OPT_v)) CmdArgs.push_back("-v"); CmdArgs.push_back("--gpu-name"); CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch))); CmdArgs.push_back("--output-file"); CmdArgs.push_back(Args.MakeArgString(TC.getInputFilename(Output))); for (const auto& II : Inputs) CmdArgs.push_back(Args.MakeArgString(II.getFilename())); for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_ptxas)) CmdArgs.push_back(Args.MakeArgString(A)); // In OpenMP we need to generate relocatable code. if (JA.isOffloading(Action::OFK_OpenMP) && Args.hasFlag(options::OPT_fopenmp_relocatable_target, options::OPT_fnoopenmp_relocatable_target, /*Default=*/ true)) CmdArgs.push_back("-c"); const char *Exec; if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ)) Exec = A->getValue(); else Exec = Args.MakeArgString(TC.GetProgramPath("ptxas")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); }
void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdinc)) return; if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, getDriver().ResourceDir, "include"); } // Add %INCLUDE%-like directories from the -imsvc flag. for (const auto &Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc)) addSystemInclude(DriverArgs, CC1Args, Path); if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; // Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat. if (const char *cl_include_dir = getenv("INCLUDE")) { SmallVector<StringRef, 8> Dirs; StringRef(cl_include_dir) .split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false); for (StringRef Dir : Dirs) addSystemInclude(DriverArgs, CC1Args, Dir); if (!Dirs.empty()) return; } std::string VSDir; // When built with access to the proper Windows APIs, try to actually find // the correct include paths first. if (getVisualStudioInstallDir(VSDir)) { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include"); if (useUniversalCRT(VSDir)) { std::string UniversalCRTSdkPath; std::string UCRTVersion; if (getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion)) { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, UniversalCRTSdkPath, "Include", UCRTVersion, "ucrt"); } } std::string WindowsSDKDir; int major; std::string windowsSDKIncludeVersion; std::string windowsSDKLibVersion; if (getWindowsSDKDir(WindowsSDKDir, major, windowsSDKIncludeVersion, windowsSDKLibVersion)) { if (major >= 8) { // Note: windowsSDKIncludeVersion is empty for SDKs prior to v10. // Anyway, llvm::sys::path::append is able to manage it. AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include", windowsSDKIncludeVersion, "shared"); AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include", windowsSDKIncludeVersion, "um"); AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include", windowsSDKIncludeVersion, "winrt"); } else { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir, "include"); } } else { addSystemInclude(DriverArgs, CC1Args, VSDir); } return; } // As a fallback, select default install paths. // FIXME: Don't guess drives and paths like this on Windows. const StringRef Paths[] = { "C:/Program Files/Microsoft Visual Studio 10.0/VC/include", "C:/Program Files/Microsoft Visual Studio 9.0/VC/include", "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", "C:/Program Files/Microsoft Visual Studio 8/VC/include", "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" }; addSystemIncludes(DriverArgs, CC1Args, Paths); }
static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, DiagnosticEngine &Diags, const FrontendOptions &FrontendOpts, const SILOptions &SILOpts, StringRef SDKPath, StringRef ResourceDir, const llvm::Triple &Triple) { using namespace options; if (!SILOpts.SILOutputFileNameForDebugging.empty()) { Opts.DebugInfoLevel = IRGenDebugInfoLevel::LineTables; } else if (const Arg *A = Args.getLastArg(OPT_g_Group)) { if (A->getOption().matches(OPT_g)) Opts.DebugInfoLevel = IRGenDebugInfoLevel::Normal; else if (A->getOption().matches(options::OPT_gline_tables_only)) Opts.DebugInfoLevel = IRGenDebugInfoLevel::LineTables; else if (A->getOption().matches(options::OPT_gdwarf_types)) Opts.DebugInfoLevel = IRGenDebugInfoLevel::DwarfTypes; else assert(A->getOption().matches(options::OPT_gnone) && "unknown -g<kind> option"); if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables) { if (Args.hasArg(options::OPT_debug_info_store_invocation)) { ArgStringList RenderedArgs; for (auto A : Args) A->render(Args, RenderedArgs); CompilerInvocation::buildDebugFlags(Opts.DebugFlags, RenderedArgs, SDKPath, ResourceDir); } // TODO: Should we support -fdebug-compilation-dir? llvm::SmallString<256> cwd; llvm::sys::fs::current_path(cwd); Opts.DebugCompilationDir = cwd.str(); } } if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) { if (A->containsValue("dwarf")) Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF; else if (A->containsValue("codeview")) Opts.DebugInfoFormat = IRGenDebugInfoFormat::CodeView; else Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, A->getAsString(Args), A->getValue()); } else if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::None) { // If -g was specified but not -debug-info-format, DWARF is assumed. Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF; } if (Args.hasArg(options::OPT_debug_info_format) && !Args.hasArg(options::OPT_g_Group)) { const Arg *debugFormatArg = Args.getLastArg(options::OPT_debug_info_format); Diags.diagnose(SourceLoc(), diag::error_option_missing_required_argument, debugFormatArg->getAsString(Args), "-g"); } if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView && (Opts.DebugInfoLevel == IRGenDebugInfoLevel::LineTables || Opts.DebugInfoLevel == IRGenDebugInfoLevel::DwarfTypes)) { const Arg *debugFormatArg = Args.getLastArg(options::OPT_debug_info_format); Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with, debugFormatArg->getAsString(Args), Opts.DebugInfoLevel == IRGenDebugInfoLevel::LineTables ? "-gline-tables-only" : "-gdwarf_types"); } for (auto A : Args.getAllArgValues(options::OPT_debug_prefix_map)) { auto SplitMap = StringRef(A).split('='); Opts.DebugPrefixMap.addMapping(SplitMap.first, SplitMap.second); } for (const Arg *A : Args.filtered(OPT_Xcc)) { StringRef Opt = A->getValue(); if (Opt.startswith("-D") || Opt.startswith("-U")) Opts.ClangDefines.push_back(Opt); } for (const Arg *A : Args.filtered(OPT_l, OPT_framework)) { LibraryKind Kind; if (A->getOption().matches(OPT_l)) { Kind = LibraryKind::Library; } else if (A->getOption().matches(OPT_framework)) { Kind = LibraryKind::Framework; } else { llvm_unreachable("Unknown LinkLibrary option kind"); } Opts.LinkLibraries.push_back(LinkLibrary(A->getValue(), Kind)); } if (auto valueNames = Args.getLastArg(OPT_disable_llvm_value_names, OPT_enable_llvm_value_names)) { Opts.HasValueNamesSetting = true; Opts.ValueNames = valueNames->getOption().matches(OPT_enable_llvm_value_names); } Opts.DisableLLVMOptzns |= Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableSwiftSpecificLLVMOptzns |= Args.hasArg(OPT_disable_swift_specific_llvm_optzns); Opts.DisableLLVMSLPVectorizer |= Args.hasArg(OPT_disable_llvm_slp_vectorizer); if (Args.hasArg(OPT_disable_llvm_verify)) Opts.Verify = false; Opts.EmitStackPromotionChecks |= Args.hasArg(OPT_stack_promotion_checks); if (const Arg *A = Args.getLastArg(OPT_stack_promotion_limit)) { unsigned limit; if (StringRef(A->getValue()).getAsInteger(10, limit)) { Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, A->getAsString(Args), A->getValue()); return true; } Opts.StackPromotionSizeLimit = limit; } if (Args.hasArg(OPT_autolink_force_load)) Opts.ForceLoadSymbolName = Args.getLastArgValue(OPT_module_link_name); Opts.ModuleName = FrontendOpts.ModuleName; if (Args.hasArg(OPT_use_jit)) Opts.UseJIT = true; for (const Arg *A : Args.filtered(OPT_verify_type_layout)) { Opts.VerifyTypeLayoutNames.push_back(A->getValue()); } for (const Arg *A : Args.filtered(OPT_disable_autolink_framework)) { Opts.DisableAutolinkFrameworks.push_back(A->getValue()); } Opts.GenerateProfile |= Args.hasArg(OPT_profile_generate); const Arg *ProfileUse = Args.getLastArg(OPT_profile_use); Opts.UseProfile = ProfileUse ? ProfileUse->getValue() : ""; Opts.PrintInlineTree |= Args.hasArg(OPT_print_llvm_inline_tree); Opts.EnableDynamicReplacementChaining |= Args.hasArg(OPT_enable_dynamic_replacement_chaining); Opts.UseSwiftCall = Args.hasArg(OPT_enable_swiftcall); // This is set to true by default. Opts.UseIncrementalLLVMCodeGen &= !Args.hasArg(OPT_disable_incremental_llvm_codegeneration); if (Args.hasArg(OPT_embed_bitcode)) Opts.EmbedMode = IRGenEmbedMode::EmbedBitcode; else if (Args.hasArg(OPT_embed_bitcode_marker)) Opts.EmbedMode = IRGenEmbedMode::EmbedMarker; if (Opts.EmbedMode == IRGenEmbedMode::EmbedBitcode) { // Keep track of backend options so we can embed them in a separate data // section and use them when building from the bitcode. This can be removed // when all the backend options are recorded in the IR. for (const Arg *A : Args) { // Do not encode output and input. if (A->getOption().getID() == options::OPT_o || A->getOption().getID() == options::OPT_INPUT || A->getOption().getID() == options::OPT_primary_file || A->getOption().getID() == options::OPT_embed_bitcode) continue; ArgStringList ASL; A->render(Args, ASL); for (ArgStringList::iterator it = ASL.begin(), ie = ASL.end(); it != ie; ++ it) { StringRef ArgStr(*it); Opts.CmdArgs.insert(Opts.CmdArgs.end(), ArgStr.begin(), ArgStr.end()); // using \00 to terminate to avoid problem decoding. Opts.CmdArgs.push_back('\0'); } } } if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) { Opts.SanitizeCoverage = parseSanitizerCoverageArgValue(A, Triple, Diags, Opts.Sanitizers); } else if (Opts.Sanitizers & SanitizerKind::Fuzzer) { // Automatically set coverage flags, unless coverage type was explicitly // requested. Opts.SanitizeCoverage.IndirectCalls = true; Opts.SanitizeCoverage.TraceCmp = true; Opts.SanitizeCoverage.TracePCGuard = true; Opts.SanitizeCoverage.CoverageType = llvm::SanitizerCoverageOptions::SCK_Edge; } if (Args.hasArg(OPT_disable_reflection_metadata)) { Opts.EnableReflectionMetadata = false; Opts.EnableReflectionNames = false; } if (Args.hasArg(OPT_disable_reflection_names)) { Opts.EnableReflectionNames = false; } if (Args.hasArg(OPT_enable_class_resilience)) { Opts.EnableClassResilience = true; } if (Args.hasArg(OPT_enable_resilience_bypass)) { Opts.EnableResilienceBypass = true; } // PE/COFF cannot deal with the cross-module reference to the metadata parent // (e.g. NativeObject). Force the lazy initialization of the VWT always. Opts.LazyInitializeClassMetadata = Triple.isOSBinFormatCOFF(); if (const Arg *A = Args.getLastArg(OPT_read_type_info_path_EQ)) { Opts.ReadTypeInfoPath = A->getValue(); } for (const auto &Lib : Args.getAllArgValues(options::OPT_autolink_library)) Opts.LinkLibraries.push_back(LinkLibrary(Lib, LibraryKind::Library)); if (const Arg *A = Args.getLastArg(OPT_type_info_dump_filter_EQ)) { StringRef mode(A->getValue()); if (mode == "all") Opts.TypeInfoFilter = IRGenOptions::TypeInfoDumpFilter::All; else if (mode == "resilient") Opts.TypeInfoFilter = IRGenOptions::TypeInfoDumpFilter::Resilient; else if (mode == "fragile") Opts.TypeInfoFilter = IRGenOptions::TypeInfoDumpFilter::Fragile; else { Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, A->getAsString(Args), A->getValue()); } } return false; }
XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) { const Driver &D = TC.getDriver(); const llvm::Triple &Triple = TC.getTriple(); if (Args.hasFlag(options::OPT_fxray_instrument, options::OPT_fnoxray_instrument, false)) { if (Triple.getOS() == llvm::Triple::Linux) { switch (Triple.getArch()) { case llvm::Triple::x86_64: case llvm::Triple::arm: case llvm::Triple::aarch64: case llvm::Triple::ppc64le: case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: case llvm::Triple::mips64el: break; default: D.Diag(diag::err_drv_clang_unsupported) << (std::string(XRayInstrumentOption) + " on " + Triple.str()); } } else if (Triple.getOS() == llvm::Triple::FreeBSD || Triple.getOS() == llvm::Triple::OpenBSD || Triple.getOS() == llvm::Triple::NetBSD) { if (Triple.getArch() != llvm::Triple::x86_64) { D.Diag(diag::err_drv_clang_unsupported) << (std::string(XRayInstrumentOption) + " on " + Triple.str()); } } else { D.Diag(diag::err_drv_clang_unsupported) << (std::string(XRayInstrumentOption) + " on " + Triple.str()); } XRayInstrument = true; if (const Arg *A = Args.getLastArg(options::OPT_fxray_instruction_threshold_, options::OPT_fxray_instruction_threshold_EQ)) { StringRef S = A->getValue(); if (S.getAsInteger(0, InstructionThreshold) || InstructionThreshold < 0) D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S; } // By default, the back-end will not emit the lowering for XRay customevent // calls if the function is not instrumented. In the future we will change // this default to be the reverse, but in the meantime we're going to // introduce the new functionality behind a flag. if (Args.hasFlag(options::OPT_fxray_always_emit_customevents, options::OPT_fnoxray_always_emit_customevents, false)) XRayAlwaysEmitCustomEvents = true; if (Args.hasFlag(options::OPT_fxray_always_emit_typedevents, options::OPT_fnoxray_always_emit_typedevents, false)) XRayAlwaysEmitTypedEvents = true; if (!Args.hasFlag(options::OPT_fxray_link_deps, options::OPT_fnoxray_link_deps, true)) XRayRT = false; auto Bundles = Args.getAllArgValues(options::OPT_fxray_instrumentation_bundle); if (Bundles.empty()) InstrumentationBundle.Mask = XRayInstrKind::All; else for (const auto &B : Bundles) { llvm::SmallVector<StringRef, 2> BundleParts; llvm::SplitString(B, BundleParts, ","); for (const auto &P : BundleParts) { // TODO: Automate the generation of the string case table. auto Valid = llvm::StringSwitch<bool>(P) .Cases("none", "all", "function", "custom", true) .Default(false); if (!Valid) { D.Diag(clang::diag::err_drv_invalid_value) << "-fxray-instrumentation-bundle=" << P; continue; } auto Mask = parseXRayInstrValue(P); if (Mask == XRayInstrKind::None) { InstrumentationBundle.clear(); break; } InstrumentationBundle.Mask |= Mask; } } // Validate the always/never attribute files. We also make sure that they // are treated as actual dependencies. for (const auto &Filename : Args.getAllArgValues(options::OPT_fxray_always_instrument)) { if (llvm::sys::fs::exists(Filename)) { AlwaysInstrumentFiles.push_back(Filename); ExtraDeps.push_back(Filename); } else D.Diag(clang::diag::err_drv_no_such_file) << Filename; } for (const auto &Filename : Args.getAllArgValues(options::OPT_fxray_never_instrument)) { if (llvm::sys::fs::exists(Filename)) { NeverInstrumentFiles.push_back(Filename); ExtraDeps.push_back(Filename); } else D.Diag(clang::diag::err_drv_no_such_file) << Filename; } for (const auto &Filename : Args.getAllArgValues(options::OPT_fxray_attr_list)) { if (llvm::sys::fs::exists(Filename)) { AttrListFiles.push_back(Filename); ExtraDeps.push_back(Filename); } else D.Diag(clang::diag::err_drv_no_such_file) << Filename; } // Get the list of modes we want to support. auto SpecifiedModes = Args.getAllArgValues(options::OPT_fxray_modes); if (SpecifiedModes.empty()) llvm::copy(XRaySupportedModes, std::back_inserter(Modes)); else for (const auto &Arg : SpecifiedModes) { // Parse CSV values for -fxray-modes=... llvm::SmallVector<StringRef, 2> ModeParts; llvm::SplitString(Arg, ModeParts, ","); for (const auto &M : ModeParts) if (M == "none") Modes.clear(); else if (M == "all") llvm::copy(XRaySupportedModes, std::back_inserter(Modes)); else Modes.push_back(M); } // Then we want to sort and unique the modes we've collected. llvm::sort(Modes.begin(), Modes.end()); Modes.erase(std::unique(Modes.begin(), Modes.end()), Modes.end()); } }