Skip to content

Commit 737c414

Browse files
committed
Revert "[clang][flang][mlir] Support -frecord-command-line option (#102975)"
This reverts commit b3533a1. It caused test failures in shared library builds: https://lab.llvm.org/buildbot/#/builders/80/builds/3854
1 parent 708567a commit 737c414

File tree

23 files changed

+59
-245
lines changed

23 files changed

+59
-245
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,18 +1994,16 @@ def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group<f_clang_Grou
19941994
Visibility<[ClangOption, CC1Option]>,
19951995
MarshallingInfoFlag<LangOpts<"CommentOpts.ParseAllComments">>;
19961996
def frecord_command_line : Flag<["-"], "frecord-command-line">,
1997-
DocBrief<[{Generate a section named ".GCC.command.line" containing the
1997+
DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
19981998
driver command-line. After linking, the section may contain multiple command
19991999
lines, which will be individually terminated by null bytes. Separate arguments
20002000
within a command line are combined with spaces; spaces and backslashes within an
20012001
argument are escaped with backslashes. This format differs from the format of
20022002
the equivalent section produced by GCC with the -frecord-gcc-switches flag.
20032003
This option is currently only supported on ELF targets.}]>,
2004-
Group<f_Group>,
2005-
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
2004+
Group<f_clang_Group>;
20062005
def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
2007-
Group<f_Group>,
2008-
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
2006+
Group<f_clang_Group>;
20092007
def : Flag<["-"], "frecord-gcc-switches">, Alias<frecord_command_line>;
20102008
def : Flag<["-"], "fno-record-gcc-switches">, Alias<fno_record_command_line>;
20112009
def fcommon : Flag<["-"], "fcommon">, Group<f_Group>,
@@ -7149,9 +7147,6 @@ def mrelocation_model : Separate<["-"], "mrelocation-model">,
71497147
NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", "DynamicNoPIC"]>,
71507148
MarshallingInfoEnum<CodeGenOpts<"RelocationModel">, "PIC_">;
71517149
def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
7152-
def record_command_line : Separate<["-"], "record-command-line">,
7153-
HelpText<"The string to embed in the .LLVM.command.line section.">,
7154-
MarshallingInfoString<CodeGenOpts<"RecordCommandLine">>;
71557150

71567151
} // let Visibility = [CC1Option, CC1AsOption, FC1Option]
71577152

@@ -7172,6 +7167,9 @@ def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">,
71727167
def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
71737168
HelpText<"The string to embed in the Dwarf debug flags record.">,
71747169
MarshallingInfoString<CodeGenOpts<"DwarfDebugFlags">>;
7170+
def record_command_line : Separate<["-"], "record-command-line">,
7171+
HelpText<"The string to embed in the .LLVM.command.line section.">,
7172+
MarshallingInfoString<CodeGenOpts<"RecordCommandLine">>;
71757173
def compress_debug_sections_EQ : Joined<["-", "--"], "compress-debug-sections=">,
71767174
HelpText<"DWARF debug sections compression type">, Values<"none,zlib,zstd">,
71777175
NormalizedValuesScope<"llvm::DebugCompressionType">, NormalizedValues<["None", "Zlib", "Zstd"]>,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) {
9494
<< "-static";
9595
}
9696

97+
// Add backslashes to escape spaces and other backslashes.
98+
// This is used for the space-separated argument list specified with
99+
// the -dwarf-debug-flags option.
100+
static void EscapeSpacesAndBackslashes(const char *Arg,
101+
SmallVectorImpl<char> &Res) {
102+
for (; *Arg; ++Arg) {
103+
switch (*Arg) {
104+
default:
105+
break;
106+
case ' ':
107+
case '\\':
108+
Res.push_back('\\');
109+
break;
110+
}
111+
Res.push_back(*Arg);
112+
}
113+
}
114+
97115
/// Apply \a Work on the current tool chain \a RegularToolChain and any other
98116
/// offloading tool chain that is associated with the current action \a JA.
99117
static void
@@ -7687,10 +7705,31 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
76877705
// Also record command line arguments into the debug info if
76887706
// -grecord-gcc-switches options is set on.
76897707
// By default, -gno-record-gcc-switches is set on and no recording.
7690-
auto GRecordSwitches = false;
7691-
auto FRecordSwitches = false;
7692-
if (shouldRecordCommandLine(TC, Args, FRecordSwitches, GRecordSwitches)) {
7693-
auto FlagsArgString = renderEscapedCommandLine(TC, Args);
7708+
auto GRecordSwitches =
7709+
Args.hasFlag(options::OPT_grecord_command_line,
7710+
options::OPT_gno_record_command_line, false);
7711+
auto FRecordSwitches =
7712+
Args.hasFlag(options::OPT_frecord_command_line,
7713+
options::OPT_fno_record_command_line, false);
7714+
if (FRecordSwitches && !Triple.isOSBinFormatELF() &&
7715+
!Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
7716+
D.Diag(diag::err_drv_unsupported_opt_for_target)
7717+
<< Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
7718+
<< TripleStr;
7719+
if (TC.UseDwarfDebugFlags() || GRecordSwitches || FRecordSwitches) {
7720+
ArgStringList OriginalArgs;
7721+
for (const auto &Arg : Args)
7722+
Arg->render(Args, OriginalArgs);
7723+
7724+
SmallString<256> Flags;
7725+
EscapeSpacesAndBackslashes(Exec, Flags);
7726+
for (const char *OriginalArg : OriginalArgs) {
7727+
SmallString<128> EscapedArg;
7728+
EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
7729+
Flags += " ";
7730+
Flags += EscapedArg;
7731+
}
7732+
auto FlagsArgString = Args.MakeArgString(Flags);
76947733
if (TC.UseDwarfDebugFlags() || GRecordSwitches) {
76957734
CmdArgs.push_back("-dwarf-debug-flags");
76967735
CmdArgs.push_back(FlagsArgString);
@@ -8690,10 +8729,10 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
86908729

86918730
SmallString<256> Flags;
86928731
const char *Exec = getToolChain().getDriver().getClangProgramPath();
8693-
escapeSpacesAndBackslashes(Exec, Flags);
8732+
EscapeSpacesAndBackslashes(Exec, Flags);
86948733
for (const char *OriginalArg : OriginalArgs) {
86958734
SmallString<128> EscapedArg;
8696-
escapeSpacesAndBackslashes(OriginalArg, EscapedArg);
8735+
EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
86978736
Flags += " ";
86988737
Flags += EscapedArg;
86998738
}

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,62 +2960,3 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
29602960
}
29612961
}
29622962
}
2963-
2964-
void tools::escapeSpacesAndBackslashes(const char *Arg,
2965-
llvm::SmallVectorImpl<char> &Res) {
2966-
for (; *Arg; ++Arg) {
2967-
switch (*Arg) {
2968-
default:
2969-
break;
2970-
case ' ':
2971-
case '\\':
2972-
Res.push_back('\\');
2973-
break;
2974-
}
2975-
Res.push_back(*Arg);
2976-
}
2977-
}
2978-
2979-
const char *tools::renderEscapedCommandLine(const ToolChain &TC,
2980-
const llvm::opt::ArgList &Args) {
2981-
const Driver &D = TC.getDriver();
2982-
const char *Exec = D.getClangProgramPath();
2983-
2984-
llvm::opt::ArgStringList OriginalArgs;
2985-
for (const auto &Arg : Args)
2986-
Arg->render(Args, OriginalArgs);
2987-
2988-
llvm::SmallString<256> Flags;
2989-
escapeSpacesAndBackslashes(Exec, Flags);
2990-
for (const char *OriginalArg : OriginalArgs) {
2991-
llvm::SmallString<128> EscapedArg;
2992-
escapeSpacesAndBackslashes(OriginalArg, EscapedArg);
2993-
Flags += " ";
2994-
Flags += EscapedArg;
2995-
}
2996-
2997-
return Args.MakeArgString(Flags);
2998-
}
2999-
3000-
bool tools::shouldRecordCommandLine(const ToolChain &TC,
3001-
const llvm::opt::ArgList &Args,
3002-
bool &FRecordCommandLine,
3003-
bool &GRecordCommandLine) {
3004-
const Driver &D = TC.getDriver();
3005-
const llvm::Triple &Triple = TC.getEffectiveTriple();
3006-
const std::string &TripleStr = Triple.getTriple();
3007-
3008-
FRecordCommandLine =
3009-
Args.hasFlag(options::OPT_frecord_command_line,
3010-
options::OPT_fno_record_command_line, false);
3011-
GRecordCommandLine =
3012-
Args.hasFlag(options::OPT_grecord_command_line,
3013-
options::OPT_gno_record_command_line, false);
3014-
if (FRecordCommandLine && !Triple.isOSBinFormatELF() &&
3015-
!Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
3016-
D.Diag(diag::err_drv_unsupported_opt_for_target)
3017-
<< Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
3018-
<< TripleStr;
3019-
3020-
return FRecordCommandLine || TC.UseDwarfDebugFlags() || GRecordCommandLine;
3021-
}

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -233,31 +233,6 @@ void addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
233233
const llvm::Reloc::Model &RelocationModel,
234234
llvm::opt::ArgStringList &CmdArgs);
235235

236-
/// Add backslashes to escape spaces and other backslashes.
237-
/// This is used for the space-separated argument list specified with
238-
/// the -dwarf-debug-flags option.
239-
void escapeSpacesAndBackslashes(const char *Arg,
240-
llvm::SmallVectorImpl<char> &Res);
241-
242-
/// Join the args in the given ArgList, escape spaces and backslashes and
243-
/// return the joined string. This is used when saving the command line as a
244-
/// result of using either the -frecord-command-line or -grecord-command-line
245-
/// options. The lifetime of the returned c-string will match that of the Args
246-
/// argument.
247-
const char *renderEscapedCommandLine(const ToolChain &TC,
248-
const llvm::opt::ArgList &Args);
249-
250-
/// Check if the command line should be recorded in the object file. This is
251-
/// done if either -frecord-command-line or -grecord-command-line options have
252-
/// been passed. This also does some error checking since -frecord-command-line
253-
/// is currently only supported on ELF platforms. The last two boolean
254-
/// arguments are out parameters and will be set depending on the command
255-
/// line options that were passed.
256-
bool shouldRecordCommandLine(const ToolChain &TC,
257-
const llvm::opt::ArgList &Args,
258-
bool &FRecordCommandLine,
259-
bool &GRecordCommandLine);
260-
261236
} // end namespace tools
262237
} // end namespace driver
263238
} // end namespace clang

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -885,20 +885,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
885885

886886
addDashXForInput(Args, Input, CmdArgs);
887887

888-
bool FRecordCmdLine = false;
889-
bool GRecordCmdLine = false;
890-
if (shouldRecordCommandLine(TC, Args, FRecordCmdLine, GRecordCmdLine)) {
891-
const char *CmdLine = renderEscapedCommandLine(TC, Args);
892-
if (FRecordCmdLine) {
893-
CmdArgs.push_back("-record-command-line");
894-
CmdArgs.push_back(CmdLine);
895-
}
896-
if (TC.UseDwarfDebugFlags() || GRecordCmdLine) {
897-
CmdArgs.push_back("-dwarf-debug-flags");
898-
CmdArgs.push_back(CmdLine);
899-
}
900-
}
901-
902888
CmdArgs.push_back(Input.getFilename());
903889

904890
// TODO: Replace flang-new with flang once the new driver replaces the

flang/include/flang/Frontend/CodeGenOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
6363
/// The directory where temp files are stored if specified by -save-temps
6464
std::optional<std::string> SaveTempsDir;
6565

66-
/// The string containing the commandline for the llvm.commandline metadata.
67-
std::optional<std::string> RecordCommandLine;
68-
6966
/// The name of the file to which the backend should save YAML optimization
7067
/// records.
7168
std::string OptRecordFile;

flang/include/flang/Lower/Bridge.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#define FORTRAN_LOWER_BRIDGE_H
1515

1616
#include "flang/Common/Fortran.h"
17-
#include "flang/Frontend/CodeGenOptions.h"
18-
#include "flang/Frontend/TargetOptions.h"
1917
#include "flang/Lower/AbstractConverter.h"
2018
#include "flang/Lower/EnvironmentDefault.h"
2119
#include "flang/Lower/LoweringOptions.h"
@@ -67,13 +65,11 @@ class LoweringBridge {
6765
const Fortran::lower::LoweringOptions &loweringOptions,
6866
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
6967
const Fortran::common::LanguageFeatureControl &languageFeatures,
70-
const llvm::TargetMachine &targetMachine,
71-
const Fortran::frontend::TargetOptions &targetOptions,
72-
const Fortran::frontend::CodeGenOptions &codeGenOptions) {
68+
const llvm::TargetMachine &targetMachine, llvm::StringRef tuneCPU) {
7369
return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics,
7470
targetCharacteristics, allCooked, triple, kindMap,
7571
loweringOptions, envDefaults, languageFeatures,
76-
targetMachine, targetOptions, codeGenOptions);
72+
targetMachine, tuneCPU);
7773
}
7874

7975
//===--------------------------------------------------------------------===//
@@ -152,9 +148,7 @@ class LoweringBridge {
152148
const Fortran::lower::LoweringOptions &loweringOptions,
153149
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
154150
const Fortran::common::LanguageFeatureControl &languageFeatures,
155-
const llvm::TargetMachine &targetMachine,
156-
const Fortran::frontend::TargetOptions &targetOptions,
157-
const Fortran::frontend::CodeGenOptions &codeGenOptions);
151+
const llvm::TargetMachine &targetMachine, const llvm::StringRef tuneCPU);
158152
LoweringBridge() = delete;
159153
LoweringBridge(const LoweringBridge &) = delete;
160154

flang/include/flang/Optimizer/Dialect/Support/FIRContext.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ void setIdent(mlir::ModuleOp mod, llvm::StringRef ident);
7777
/// Get the compiler identifier from the Module.
7878
llvm::StringRef getIdent(mlir::ModuleOp mod);
7979

80-
/// Set the command line used in this invocation.
81-
void setCommandline(mlir::ModuleOp mod, llvm::StringRef cmdLine);
82-
83-
/// Get the command line used in this invocation.
84-
llvm::StringRef getCommandline(mlir::ModuleOp mod);
85-
8680
/// Helper for determining the target from the host, etc. Tools may use this
8781
/// function to provide a consistent interpretation of the `--target=<string>`
8882
/// command-line option.

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
348348
if (auto *a = args.getLastArg(clang::driver::options::OPT_save_temps_EQ))
349349
opts.SaveTempsDir = a->getValue();
350350

351-
// -record-command-line option.
352-
if (const llvm::opt::Arg *a =
353-
args.getLastArg(clang::driver::options::OPT_record_command_line)) {
354-
opts.RecordCommandLine = a->getValue();
355-
}
356-
357351
// -mlink-builtin-bitcode
358352
for (auto *a :
359353
args.filtered(clang::driver::options::OPT_mlink_builtin_bitcode))

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ bool CodeGenAction::beginSourceFileAction() {
302302
kindMap, ci.getInvocation().getLoweringOpts(),
303303
ci.getInvocation().getFrontendOpts().envDefaults,
304304
ci.getInvocation().getFrontendOpts().features, targetMachine,
305-
ci.getInvocation().getTargetOpts(), ci.getInvocation().getCodeGenOpts());
305+
ci.getInvocation().getTargetOpts().cpuToTuneFor);
306306

307307
// Fetch module from lb, so we can set
308308
mlirModule = std::make_unique<mlir::ModuleOp>(lb.getModule());

0 commit comments

Comments
 (0)