Skip to content

Commit e721bc9

Browse files
committed
[clang][cli] Generate and round-trip CodeGen options
This patch implements generation of remaining codegen options and tests it by performing parse-generate-parse round trip. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D96056
1 parent ec12f5f commit e721bc9

File tree

6 files changed

+375
-39
lines changed

6 files changed

+375
-39
lines changed

clang/include/clang/Basic/XRayInstr.h

+5
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ struct XRayInstrSet {
6565
XRayInstrMask Mask = 0;
6666
};
6767

68+
/// Parses a command line argument into a mask.
6869
XRayInstrMask parseXRayInstrValue(StringRef Value);
6970

71+
/// Serializes a set into a list of command line arguments.
72+
void serializeXRayInstrValue(XRayInstrSet Set,
73+
SmallVectorImpl<StringRef> &Values);
74+
7075
} // namespace clang
7176

7277
#endif // LLVM_CLANG_BASIC_XRAYINSTR_H

clang/include/clang/Driver/Options.td

+1-6
Original file line numberDiff line numberDiff line change
@@ -4453,12 +4453,7 @@ def migrator_no_finalize_removal : Flag<["-"], "no-finalize-removal">,
44534453
//===----------------------------------------------------------------------===//
44544454

44554455
let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
4456-
def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">,
4457-
Values<"line-tables-only,line-directives-only,constructor,limited,standalone,unused-types">,
4458-
NormalizedValuesScope<"codegenoptions">,
4459-
NormalizedValues<["DebugLineTablesOnly", "DebugDirectivesOnly", "DebugInfoConstructor",
4460-
"LimitedDebugInfo", "FullDebugInfo", "UnusedTypeInfo"]>,
4461-
MarshallingInfoString<CodeGenOpts<"DebugInfo">, "NoDebugInfo">, AutoNormalizeEnum;
4456+
def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
44624457
def debug_info_macro : Flag<["-"], "debug-info-macro">,
44634458
HelpText<"Emit macro debug information">,
44644459
MarshallingInfoFlag<CodeGenOpts<"MacroDebugInfo">>;

clang/include/clang/Frontend/CompilerInvocation.h

+17-3
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,26 @@ class CompilerInvocation : public CompilerInvocationBase {
266266
StringAllocator SA, const llvm::Triple &T);
267267

268268
/// Parse command line options that map to CodeGenOptions.
269-
static bool ParseCodeGenArgs(CodeGenOptions &Opts, llvm::opt::ArgList &Args,
270-
InputKind IK, DiagnosticsEngine &Diags,
271-
const llvm::Triple &T,
269+
static bool ParseCodeGenArgsImpl(CodeGenOptions &Opts,
270+
llvm::opt::ArgList &Args, InputKind IK,
271+
DiagnosticsEngine &Diags,
272+
const llvm::Triple &T,
273+
const std::string &OutputFile,
274+
const LangOptions &LangOptsRef);
275+
276+
static bool ParseCodeGenArgs(CompilerInvocation &Res, CodeGenOptions &Opts,
277+
llvm::opt::ArgList &Args, InputKind IK,
278+
DiagnosticsEngine &Diags, const llvm::Triple &T,
272279
const std::string &OutputFile,
273280
const LangOptions &LangOptsRef);
274281

282+
// Generate command line options from CodeGenOptions.
283+
static void GenerateCodeGenArgs(const CodeGenOptions &Opts,
284+
SmallVectorImpl<const char *> &Args,
285+
StringAllocator SA, const llvm::Triple &T,
286+
const std::string &OutputFile,
287+
const LangOptions *LangOpts);
288+
275289
/// Parse command line options that map to HeaderSearchOptions.
276290
static void ParseHeaderSearchArgs(CompilerInvocation &Res,
277291
HeaderSearchOptions &Opts,

clang/lib/Basic/XRayInstr.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/Basic/XRayInstr.h"
14+
#include "llvm/ADT/SmallVector.h"
1415
#include "llvm/ADT/StringSwitch.h"
1516

1617
namespace clang {
@@ -30,4 +31,30 @@ XRayInstrMask parseXRayInstrValue(StringRef Value) {
3031
return ParsedKind;
3132
}
3233

34+
void serializeXRayInstrValue(XRayInstrSet Set,
35+
SmallVectorImpl<StringRef> &Values) {
36+
if (Set.Mask == XRayInstrKind::All) {
37+
Values.push_back("all");
38+
return;
39+
}
40+
41+
if (Set.Mask == XRayInstrKind::None) {
42+
Values.push_back("none");
43+
return;
44+
}
45+
46+
if (Set.has(XRayInstrKind::Custom))
47+
Values.push_back("custom");
48+
49+
if (Set.has(XRayInstrKind::Typed))
50+
Values.push_back("typed");
51+
52+
if (Set.has(XRayInstrKind::FunctionEntry) &&
53+
Set.has(XRayInstrKind::FunctionExit))
54+
Values.push_back("function");
55+
else if (Set.has(XRayInstrKind::FunctionEntry))
56+
Values.push_back("function-entry");
57+
else if (Set.has(XRayInstrKind::FunctionExit))
58+
Values.push_back("function-exit");
59+
}
3360
} // namespace clang

0 commit comments

Comments
 (0)