Skip to content

Commit 6e5c667

Browse files
committed
Revert "[flang][Driver] Support -print-supported-cpus and associated aliases (#117199)"
This reverts commit 23d7a6c, which added support for PrecompileJobAction to LLVM Flang, in order to support the -print-supported-cpus option in fc1. Currently, Classic Flang does not support this option or the PrecompileJobAction.
1 parent f0210bc commit 6e5c667

File tree

7 files changed

+11
-111
lines changed

7 files changed

+11
-111
lines changed

Diff for: clang/include/clang/Driver/Options.td

+5-15
Original file line numberDiff line numberDiff line change
@@ -6028,24 +6028,12 @@ def target : Joined<["--"], "target=">, Flags<[NoXarchOption]>,
60286028
def darwin_target_variant : Separate<["-"], "darwin-target-variant">,
60296029
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption]>,
60306030
HelpText<"Generate code for an additional runtime variant of the deployment target">;
6031-
6032-
//===----------------------------------------------------------------------===//
6033-
// Print CPU info options (clang, clang-cl, flang)
6034-
//===----------------------------------------------------------------------===//
6035-
6036-
let Visibility = [ClangOption, CC1Option, CLOption, FlangOption, FC1Option] in {
6037-
60386031
def print_supported_cpus : Flag<["-", "--"], "print-supported-cpus">,
60396032
Group<CompileOnly_Group>,
6040-
HelpText<"Print supported cpu models for the given target (if target is not "
6041-
"specified,it will print the supported cpus for the default target)">,
6033+
Visibility<[ClangOption, CC1Option, CLOption]>,
6034+
HelpText<"Print supported cpu models for the given target (if target is not specified,"
6035+
" it will print the supported cpus for the default target)">,
60426036
MarshallingInfoFlag<FrontendOpts<"PrintSupportedCPUs">>;
6043-
6044-
def : Flag<["-"], "mcpu=help">, Alias<print_supported_cpus>;
6045-
def : Flag<["-"], "mtune=help">, Alias<print_supported_cpus>;
6046-
6047-
} // let Visibility = [ClangOption, CC1Option, CLOption, FlangOption, FC1Option]
6048-
60496037
def print_supported_extensions : Flag<["-", "--"], "print-supported-extensions">,
60506038
Visibility<[ClangOption, CC1Option, CLOption]>,
60516039
HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
@@ -6055,6 +6043,8 @@ def print_enabled_extensions : Flag<["-", "--"], "print-enabled-extensions">,
60556043
HelpText<"Print the extensions enabled by the given target and -march/-mcpu options."
60566044
" (AArch64 and RISC-V only)">,
60576045
MarshallingInfoFlag<FrontendOpts<"PrintEnabledExtensions">>;
6046+
def : Flag<["-"], "mcpu=help">, Alias<print_supported_cpus>;
6047+
def : Flag<["-"], "mtune=help">, Alias<print_supported_cpus>;
60586048
def time : Flag<["-"], "time">,
60596049
HelpText<"Time individual commands">;
60606050
def traditional_cpp : Flag<["-", "--"], "traditional-cpp">,

Diff for: clang/lib/Driver/Driver.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -4634,8 +4634,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
46344634

46354635
// Use the -mcpu=? flag as the dummy input to cc1.
46364636
Actions.clear();
4637-
Action *InputAc = C.MakeAction<InputAction>(
4638-
*A, IsFlangMode() ? types::TY_Fortran : types::TY_C);
4637+
Action *InputAc = C.MakeAction<InputAction>(*A, types::TY_C);
46394638
Actions.push_back(
46404639
C.MakeAction<PrecompileJobAction>(InputAc, types::TY_Nothing));
46414640
for (auto &I : Inputs)
@@ -6904,8 +6903,7 @@ bool Driver::ShouldUseFlangCompiler(const JobAction &JA) const {
69046903
return false;
69056904

69066905
// And say "no" if this is not a kind of action flang understands.
6907-
if (!isa<PreprocessJobAction>(JA) && !isa<PrecompileJobAction>(JA) &&
6908-
!isa<CompileJobAction>(JA)
6906+
if (!isa<PreprocessJobAction>(JA) && !isa<CompileJobAction>(JA)
69096907
#ifndef ENABLE_CLASSIC_FLANG
69106908
&& !isa<BackendJobAction>(JA)
69116909
#endif

Diff for: clang/lib/Driver/ToolChains/Flang.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
777777
}
778778
} else if (isa<AssembleJobAction>(JA)) {
779779
CmdArgs.push_back("-emit-obj");
780-
} else if (isa<PrecompileJobAction>(JA)) {
781-
// The precompile job action is only needed for options such as -mcpu=help.
782-
// Those will already have been handled by the fc1 driver.
783780
} else {
784781
assert(false && "Unexpected action class for Flang tool.");
785782
}
@@ -952,6 +949,8 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
952949
CmdArgs.push_back(Output.getFilename());
953950
}
954951

952+
assert(Input.isFilename() && "Invalid input.");
953+
955954
if (Args.getLastArg(options::OPT_save_temps_EQ))
956955
Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
957956

@@ -971,18 +970,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
971970
}
972971
}
973972

974-
// The input could be Ty_Nothing when "querying" options such as -mcpu=help
975-
// are used.
976-
ArrayRef<InputInfo> FrontendInputs = Input;
977-
if (Input.isNothing())
978-
FrontendInputs = {};
979-
980-
for (const InputInfo &Input : FrontendInputs) {
981-
if (Input.isFilename())
982-
CmdArgs.push_back(Input.getFilename());
983-
else
984-
Input.getInputArg().renderAsInput(Args, CmdArgs);
985-
}
973+
CmdArgs.push_back(Input.getFilename());
986974

987975
const char *Exec = Args.MakeArgString(D.GetProgramPath("flang", TC));
988976
C.addCommand(std::make_unique<Command>(JA, *this,

Diff for: flang/include/flang/Frontend/FrontendOptions.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ class FrontendInputFile {
236236
struct FrontendOptions {
237237
FrontendOptions()
238238
: showHelp(false), showVersion(false), instrumentedParse(false),
239-
showColors(false), printSupportedCPUs(false),
240-
needProvenanceRangeToCharBlockMappings(false) {}
239+
showColors(false), needProvenanceRangeToCharBlockMappings(false) {}
241240

242241
/// Show the -help text.
243242
unsigned showHelp : 1;
@@ -251,9 +250,6 @@ struct FrontendOptions {
251250
/// Enable color diagnostics.
252251
unsigned showColors : 1;
253252

254-
/// Print the supported cpus for the current target
255-
unsigned printSupportedCPUs : 1;
256-
257253
/// Enable Provenance to character-stream mapping. Allows e.g. IDEs to find
258254
/// symbols based on source-code location. This is not needed in regular
259255
/// compilation.

Diff for: flang/lib/Frontend/CompilerInvocation.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,6 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
638638
opts.outputFile = args.getLastArgValue(clang::driver::options::OPT_o);
639639
opts.showHelp = args.hasArg(clang::driver::options::OPT_help);
640640
opts.showVersion = args.hasArg(clang::driver::options::OPT_version);
641-
opts.printSupportedCPUs =
642-
args.hasArg(clang::driver::options::OPT_print_supported_cpus);
643641

644642
// Get the input kind (from the value passed via `-x`)
645643
InputKind dashX(Language::Unknown);

Diff for: flang/test/Driver/print-supported-cpus.f90

-46
This file was deleted.

Diff for: flang/tools/flang-driver/fc1_main.cpp

-24
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,15 @@
2121
#include "flang/Frontend/TextDiagnosticBuffer.h"
2222
#include "flang/FrontendTool/Utils.h"
2323
#include "clang/Driver/DriverDiagnostic.h"
24-
#include "llvm/MC/TargetRegistry.h"
2524
#include "llvm/Option/Arg.h"
2625
#include "llvm/Option/ArgList.h"
2726
#include "llvm/Option/OptTable.h"
2827
#include "llvm/Support/TargetSelect.h"
29-
#include "llvm/Support/raw_ostream.h"
3028

3129
#include <cstdio>
3230

3331
using namespace Fortran::frontend;
3432

35-
/// Print supported cpus of the given target.
36-
static int printSupportedCPUs(llvm::StringRef triple) {
37-
std::string error;
38-
const llvm::Target *target =
39-
llvm::TargetRegistry::lookupTarget(triple, error);
40-
if (!target) {
41-
llvm::errs() << error;
42-
return 1;
43-
}
44-
45-
// the target machine will handle the mcpu printing
46-
llvm::TargetOptions targetOpts;
47-
std::unique_ptr<llvm::TargetMachine> targetMachine(
48-
target->createTargetMachine(triple, "", "+cpuhelp", targetOpts,
49-
std::nullopt));
50-
return 0;
51-
}
52-
5333
int fc1_main(llvm::ArrayRef<const char *> argv, const char *argv0) {
5434
// Create CompilerInstance
5535
std::unique_ptr<CompilerInstance> flang(new CompilerInstance());
@@ -78,10 +58,6 @@ int fc1_main(llvm::ArrayRef<const char *> argv, const char *argv0) {
7858
llvm::InitializeAllTargetMCs();
7959
llvm::InitializeAllAsmPrinters();
8060

81-
// --print-supported-cpus takes priority over the actual compilation.
82-
if (flang->getFrontendOpts().printSupportedCPUs)
83-
return printSupportedCPUs(flang->getInvocation().getTargetOpts().triple);
84-
8561
diagsBuffer->flushDiagnostics(flang->getDiagnostics());
8662

8763
if (!success)

0 commit comments

Comments
 (0)