This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGfbea5aada143: [Driver] Add ClangFlags::TargetSpecific to simplify… (authored by MaskRay).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151590/new/ https://reviews.llvm.org/D151590 Files: clang/include/clang/Driver/Options.h clang/include/clang/Driver/Options.td clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/AIX.h clang/lib/Driver/ToolChains/Arch/PPC.cpp clang/lib/Driver/ToolChains/Arch/Sparc.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/mdefault-visibility-export-mapping.c
Index: clang/test/Driver/mdefault-visibility-export-mapping.c =================================================================== --- clang/test/Driver/mdefault-visibility-export-mapping.c +++ clang/test/Driver/mdefault-visibility-export-mapping.c @@ -4,4 +4,4 @@ // CHECK: "-mdefault-visibility-export-mapping=explicit" -// ERROR: unsupported option '-mdefault-visibility-export-mapping=explicit' for target 'powerpc-unknown-linux' +// ERROR: error: unsupported option '-mdefault-visibility-export-mapping=' for target 'powerpc-unknown-linux' Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -337,6 +337,7 @@ /// Get the (LLVM) name of the AMDGPU gpu we are targeting. static std::string getAMDGPUTargetGPU(const llvm::Triple &T, const ArgList &Args) { + Arg *MArch = Args.getLastArg(options::OPT_march_EQ); if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { auto GPUName = getProcessorFromTargetID(T, A->getValue()); return llvm::StringSwitch<std::string>(GPUName) @@ -349,9 +350,8 @@ .Case("aruba", "cayman") .Default(GPUName.str()); } - if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) { - return getProcessorFromTargetID(T, A->getValue()).str(); - } + if (MArch) + return getProcessorFromTargetID(T, MArch->getValue()).str(); return ""; } Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -5275,19 +5275,6 @@ << A->getSpelling() << RawTriple.str(); } - if (Args.hasArg(options::OPT_mxcoff_roptr) || - Args.hasArg(options::OPT_mno_xcoff_roptr)) { - bool HasRoptr = Args.hasFlag(options::OPT_mxcoff_roptr, - options::OPT_mno_xcoff_roptr, false); - StringRef OptStr = HasRoptr ? "-mxcoff-roptr" : "-mno-xcoff-roptr"; - if (!Triple.isOSAIX()) - D.Diag(diag::err_drv_unsupported_opt_for_target) - << OptStr << RawTriple.str(); - - if (HasRoptr) - CmdArgs.push_back("-mxcoff-roptr"); - } - if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) { StringRef V = A->getValue(), V1 = V; unsigned Size; @@ -6147,23 +6134,6 @@ } } - if (const Arg *A = Args.getLastArg(options::OPT_mignore_xcoff_visibility)) { - if (Triple.isOSAIX()) - CmdArgs.push_back("-mignore-xcoff-visibility"); - else - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getAsString(Args) << TripleStr; - } - - if (const Arg *A = - Args.getLastArg(options::OPT_mdefault_visibility_export_mapping_EQ)) { - if (Triple.isOSAIX()) - A->render(Args, CmdArgs); - else - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getAsString(Args) << TripleStr; - } - if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden, options::OPT_fno_visibility_inlines_hidden, false)) CmdArgs.push_back("-fvisibility-inlines-hidden"); @@ -6976,10 +6946,6 @@ Args.addOptInFlag(CmdArgs, options::OPT_fapple_pragma_pack, options::OPT_fno_apple_pragma_pack); - if (Args.hasFlag(options::OPT_fxl_pragma_pack, - options::OPT_fno_xl_pragma_pack, RawTriple.isOSAIX())) - CmdArgs.push_back("-fxl-pragma-pack"); - // Remarks can be enabled with any of the `-f.*optimization-record.*` flags. if (willEmitRemarks(Args) && checkRemarksOptions(D, Args, Triple)) renderRemarksOptions(Args, CmdArgs, Triple, Input, Output, JA); Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/Sparc.cpp +++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp @@ -118,12 +118,6 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args, const llvm::Triple &Triple) { - if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getSpelling() << Triple.getTriple(); - return ""; - } - if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { StringRef CPUName = A->getValue(); if (CPUName == "native") { Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -87,10 +87,6 @@ /// Get the (LLVM) name of the PowerPC cpu we are targeting. std::string ppc::getPPCTargetCPU(const Driver &D, const ArgList &Args, const llvm::Triple &T) { - if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { - D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getSpelling() << T.getTriple(); - } if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) return normalizeCPUName(A->getValue(), T); return getPPCGenericTargetCPU(T); Index: clang/lib/Driver/ToolChains/AIX.h =================================================================== --- clang/lib/Driver/ToolChains/AIX.h +++ clang/lib/Driver/ToolChains/AIX.h @@ -80,6 +80,10 @@ void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; + void addClangTargetOptions( + const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1Args, + Action::OffloadKind DeviceOffloadingKind) const override; + void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; Index: clang/lib/Driver/ToolChains/AIX.cpp =================================================================== --- clang/lib/Driver/ToolChains/AIX.cpp +++ clang/lib/Driver/ToolChains/AIX.cpp @@ -409,6 +409,18 @@ llvm_unreachable("Unexpected C++ library type; only libc++ is supported."); } +void AIX::addClangTargetOptions( + const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1Args, + Action::OffloadKind DeviceOffloadingKind) const { + Args.AddLastArg(CC1Args, options::OPT_mignore_xcoff_visibility); + Args.AddLastArg(CC1Args, options::OPT_mdefault_visibility_export_mapping_EQ); + Args.addOptInFlag(CC1Args, options::OPT_mxcoff_roptr, options::OPT_mno_xcoff_roptr); + + if (Args.hasFlag(options::OPT_fxl_pragma_pack, + options::OPT_fno_xl_pragma_pack, true)) + CC1Args.push_back("-fxl-pragma-pack"); +} + void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { // Add linker option -u__llvm_profile_runtime to cause runtime Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4885,9 +4885,15 @@ // In clang-cl, don't mention unknown arguments here since they have // already been warned about. - if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) - Diag(clang::diag::warn_drv_unused_argument) - << A->getAsString(C.getArgs()); + if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) { + if (A->getOption().hasFlag(options::TargetSpecific)) { + Diag(diag::err_drv_unsupported_opt_for_target) + << A->getSpelling() << getTargetTriple(); + } else { + Diag(clang::diag::warn_drv_unused_argument) + << A->getAsString(C.getArgs()); + } + } } } } Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -75,6 +75,10 @@ // FC1Option - This option should be accepted by flang -fc1. def FC1Option : OptionFlag; +// This is a target-specific option for compilation. Using it on an unsupported +// target will lead to an err_drv_unsupported_opt_for_target error. +def TargetSpecific : OptionFlag; + // A short name to show in documentation. The name will be interpreted as rST. class DocName<string name> { string DocName = name; } @@ -89,6 +93,8 @@ // GCC compatibility. class IgnoredGCCCompat : Flags<[HelpHidden]> {} +class TargetSpecific : Flags<[TargetSpecific]> {} + ///////// // Groups @@ -3123,7 +3129,7 @@ NormalizedValuesScope<"LangOptions::DefaultVisiblityExportMapping">, NormalizedValues<["None", "Explicit", "All"]>, HelpText<"Mapping between default visibility and export">, - Group<m_Group>, Flags<[CC1Option]>, + Group<m_Group>, Flags<[CC1Option,TargetSpecific]>, MarshallingInfoEnum<LangOpts<"DefaultVisibilityExportMapping">,"None">; defm new_infallible : BoolFOption<"new-infallible", LangOpts<"NewInfallible">, DefaultFalse, @@ -3507,7 +3513,7 @@ def mwatchos_version_min_EQ : Joined<["-"], "mwatchos-version-min=">, Group<m_Group>; def mwatchos_simulator_version_min_EQ : Joined<["-"], "mwatchos-simulator-version-min=">; def mwatchsimulator_version_min_EQ : Joined<["-"], "mwatchsimulator-version-min=">, Alias<mwatchos_simulator_version_min_EQ>; -def march_EQ : Joined<["-"], "march=">, Group<m_Group>, Flags<[CoreOption]>, +def march_EQ : Joined<["-"], "march=">, Group<m_Group>, Flags<[CoreOption,TargetSpecific]>, HelpText<"For a list of available architectures for the target use '-mcpu=help'">; def masm_EQ : Joined<["-"], "masm=">, Group<m_Group>, Flags<[NoXarchOption]>; def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group<m_Group>, Flags<[CC1Option]>, @@ -3532,7 +3538,7 @@ def mguard_EQ : Joined<["-"], "mguard=">, Group<m_Group>, Flags<[NoXarchOption]>, HelpText<"Enable or disable Control Flow Guard checks and guard tables emission">, Values<"none,cf,cf-nochecks">; -def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>, +def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>, TargetSpecific, HelpText<"For a list of available CPUs for the target use '-mcpu=help'">; def mmcu_EQ : Joined<["-"], "mmcu=">, Group<m_Group>; def msim : Flag<["-"], "msim">, Group<m_Group>; @@ -3925,9 +3931,9 @@ def msvr4_struct_return : Flag<["-"], "msvr4-struct-return">, Group<m_Group>, Flags<[CC1Option]>, HelpText<"Return small structs in registers (PPC32 only)">; -def mxcoff_roptr : Flag<["-"], "mxcoff-roptr">, Group<m_Group>, Flags<[CC1Option]>, +def mxcoff_roptr : Flag<["-"], "mxcoff-roptr">, Group<m_Group>, Flags<[CC1Option,TargetSpecific]>, HelpText<"Place constant objects with relocatable address values in the RO data section and add -bforceimprw to the linker flags (AIX only)">; -def mno_xcoff_roptr : Flag<["-"], "mno-xcoff-roptr">, Group<m_Group>; +def mno_xcoff_roptr : Flag<["-"], "mno-xcoff-roptr">, Group<m_Group>, TargetSpecific; def mvx : Flag<["-"], "mvx">, Group<m_Group>; def mno_vx : Flag<["-"], "mno-vx">, Group<m_Group>; @@ -3943,7 +3949,7 @@ HelpText<"On AIX, request creation of a build-id string, \"0xHEXSTRING\", in the string table of the loader section inside the linked binary">; def mignore_xcoff_visibility : Flag<["-"], "mignore-xcoff-visibility">, Group<m_Group>, HelpText<"Not emit the visibility attribute for asm in AIX OS or give all symbols 'unspecified' visibility in XCOFF object file">, - Flags<[CC1Option]>; + Flags<[CC1Option,TargetSpecific]>; defm backchain : BoolOption<"m", "backchain", CodeGenOpts<"Backchain">, DefaultFalse, PosFlag<SetTrue, [], "Link stack frames through backchain on System Z">, Index: clang/include/clang/Driver/Options.h =================================================================== --- clang/include/clang/Driver/Options.h +++ clang/include/clang/Driver/Options.h @@ -38,6 +38,7 @@ DXCOption = (1 << 17), CLDXCOption = (1 << 18), Ignored = (1 << 19), + TargetSpecific = (1 << 20), }; enum ID {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits