Skip to content

Commit 74125fa

Browse files
committed
Address comments from MaskRay
1 parent fd56694 commit 74125fa

File tree

11 files changed

+62
-58
lines changed

11 files changed

+62
-58
lines changed

llvm/include/llvm/CodeGenData/CodeGenDataReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CodeGenDataReader {
5353

5454
/// Extract the cgdata embedded in sections from the given object file and
5555
/// merge them into the GlobalOutlineRecord. This is a static helper that
56-
/// is used by `llvm-cgdata -merge` or ThinLTO's two-codegen rounds.
56+
/// is used by `llvm-cgdata --merge` or ThinLTO's two-codegen rounds.
5757
static Error mergeFromObjectFile(const object::ObjectFile *Obj,
5858
OutlinedHashTreeRecord &GlobalOutlineRecord);
5959

llvm/test/tools/llvm-cgdata/convert.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
RUN: split-file %s %t
44

5-
RUN: llvm-cgdata -convert -format binary %t/dump.cgtext -o %t/dump.cgdata
6-
RUN: llvm-cgdata -convert -format text %t/dump.cgdata -o %t/dump-round.cgtext
7-
RUN: llvm-cgdata -convert -format binary %t/dump-round.cgtext -o %t/dump-round.cgdata
8-
RUN: llvm-cgdata -convert -format text %t/dump-round.cgtext -o %t/dump-round-round.cgtext
5+
RUN: llvm-cgdata --convert --format binary %t/dump.cgtext -o %t/dump.cgdata
6+
RUN: llvm-cgdata --convert --format text %t/dump.cgdata -o %t/dump-round.cgtext
7+
RUN: llvm-cgdata -c -f binary %t/dump-round.cgtext -o %t/dump-round.cgdata
8+
RUN: llvm-cgdata -c -f text %t/dump-round.cgtext -o %t/dump-round-round.cgtext
99
RUN: diff %t/dump.cgdata %t/dump-round.cgdata
1010
RUN: diff %t/dump-round.cgtext %t/dump-round-round.cgtext
1111

llvm/test/tools/llvm-cgdata/empty.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# Test no input file
2-
RUN: not llvm-cgdata -convert -o - 2>&1 | FileCheck %s --check-prefix=NOFILE --ignore-case
2+
RUN: not llvm-cgdata --convert --output - 2>&1 | FileCheck %s --check-prefix=NOFILE --ignore-case
33
NOFILE: error: No input file is specified.
44

55
# Test for empty cgdata file, which is invalid.
66
RUN: touch %t_emptyfile.cgtext
7-
RUN: not llvm-cgdata -convert %t_emptyfile.cgtext -format text 2>&1 | FileCheck %s --check-prefix=EMPTY
7+
RUN: not llvm-cgdata --convert %t_emptyfile.cgtext --format text 2>&1 | FileCheck %s --check-prefix=EMPTY
88
EMPTY: {{.}}emptyfile.cgtext: empty codegen data
99

1010
# Test for empty header in the text format. It can be converted to a valid binary file.
1111
RUN: printf '#' > %t_emptyheader.cgtext
12-
RUN: llvm-cgdata -convert %t_emptyheader.cgtext -format binary -o %t_emptyheader.cgdata
12+
RUN: llvm-cgdata --convert %t_emptyheader.cgtext --format binary -o %t_emptyheader.cgdata
1313

1414
# Without any cgdata other than the header, no data shows by default.
15-
RUN: llvm-cgdata -show %t_emptyheader.cgdata | count 0
15+
RUN: llvm-cgdata --show %t_emptyheader.cgdata | count 0
1616

1717
# The version number appears when asked, as it's in the header
18-
RUN: llvm-cgdata -show --cgdata-version %t_emptyheader.cgdata | FileCheck %s --check-prefix=VERSION
18+
RUN: llvm-cgdata --show --cgdata-version %t_emptyheader.cgdata | FileCheck %s --check-prefix=VERSION
1919
VERSION: Version: 1
2020

2121
# When converting a binary file (w/ the header only) to a text file, it's an empty file as the text format does not have an explicit header.
22-
RUN: llvm-cgdata -convert %t_emptyheader.cgdata -format text | count 0
22+
RUN: llvm-cgdata --convert %t_emptyheader.cgdata --format text | count 0
2323

2424
# Synthesize a header only cgdata.
2525
# struct Header {

llvm/test/tools/llvm-cgdata/error.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88
# uint64_t OutlinedHashTreeOffset;
99
# }
1010
RUN: touch %t_empty.cgdata
11-
RUN: not llvm-cgdata -show %t_empty.cgdata 2>&1 | FileCheck %s --check-prefix=EMPTY
11+
RUN: not llvm-cgdata --show %t_empty.cgdata 2>&1 | FileCheck %s --check-prefix=EMPTY
1212
EMPTY: {{.}}cgdata: empty codegen data
1313

1414
# Not a magic.
1515
RUN: printf '\xff' > %t_malformed.cgdata
16-
RUN: not llvm-cgdata -show %t_malformed.cgdata 2>&1 | FileCheck %s --check-prefix=MALFORMED
16+
RUN: not llvm-cgdata --show %t_malformed.cgdata 2>&1 | FileCheck %s --check-prefix=MALFORMED
1717
MALFORMED: {{.}}cgdata: malformed codegen data
1818

1919
# The minimum header size is 24.
2020
RUN: printf '\xffcgdata\x81' > %t_corrupt.cgdata
21-
RUN: not llvm-cgdata -show %t_corrupt.cgdata 2>&1 | FileCheck %s --check-prefix=CORRUPT
21+
RUN: not llvm-cgdata --show %t_corrupt.cgdata 2>&1 | FileCheck %s --check-prefix=CORRUPT
2222
CORRUPT: {{.}}cgdata: invalid codegen data (file header is corrupt)
2323

2424
# The current version 1 while the header says 2.
2525
RUN: printf '\xffcgdata\x81' > %t_version.cgdata
2626
RUN: printf '\x02\x00\x00\x00' >> %t_version.cgdata
2727
RUN: printf '\x00\x00\x00\x00' >> %t_version.cgdata
2828
RUN: printf '\x18\x00\x00\x00\x00\x00\x00\x00' >> %t_version.cgdata
29-
RUN: not llvm-cgdata -show %t_version.cgdata 2>&1 | FileCheck %s --check-prefix=BAD_VERSION
29+
RUN: not llvm-cgdata --show %t_version.cgdata 2>&1 | FileCheck %s --check-prefix=BAD_VERSION
3030
BAD_VERSION: {{.}}cgdata: unsupported codegen data version
3131

3232
# Header says an outlined hash tree, but the file ends after the header.
3333
RUN: printf '\xffcgdata\x81' > %t_eof.cgdata
3434
RUN: printf '\x01\x00\x00\x00' >> %t_eof.cgdata
3535
RUN: printf '\x01\x00\x00\x00' >> %t_eof.cgdata
3636
RUN: printf '\x18\x00\x00\x00\x00\x00\x00\x00' >> %t_eof.cgdata
37-
RUN: not llvm-cgdata -show %t_eof.cgdata 2>&1 | FileCheck %s --check-prefix=EOF
37+
RUN: not llvm-cgdata --show %t_eof.cgdata 2>&1 | FileCheck %s --check-prefix=EOF
3838
EOF: {{.}}cgdata: end of File

llvm/test/tools/llvm-cgdata/merge-archive.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
RUN: split-file %s %t
77

88
# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata.
9-
RUN: llvm-cgdata -convert -format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
9+
RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
1010
RUN: od -t x1 -j 24 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ]*$//' | sed 's/[ ][ ]*/\\\\/g' > %t/raw-1-bytes.txt
1111
RUN: sed -ie "s/<RAW_1_BYTES>/$(cat %t/raw-1-bytes.txt)/g" %t/merge-1.ll
1212
RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-1.ll -o %t/merge-1.o
1313

1414
# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata.
15-
RUN: llvm-cgdata -convert -format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
15+
RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
1616
RUN: od -t x1 -j 24 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ]*$//' | sed 's/[ ][ ]*/\\\\/g' > %t/raw-2-bytes.txt
1717
RUN: sed -ie "s/<RAW_2_BYTES>/$(cat %t/raw-2-bytes.txt)/g" %t/merge-2.ll
1818
RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-2.ll -o %t/merge-2.o
@@ -21,14 +21,14 @@ RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-2.ll -o %t/merge-2.o
2121
RUN: llvm-ar rcs %t/merge-archive.a %t/merge-1.o %t/merge-2.o
2222

2323
# Merge the archive into the codegen data file.
24-
RUN: llvm-cgdata -merge %t/merge-archive.a -o %t/merge-archive.cgdata
25-
RUN: llvm-cgdata -show %t/merge-archive.cgdata | FileCheck %s
24+
RUN: llvm-cgdata --merge %t/merge-archive.a -o %t/merge-archive.cgdata
25+
RUN: llvm-cgdata --show %t/merge-archive.cgdata | FileCheck %s
2626
CHECK: Outlined hash tree:
2727
CHECK-NEXT: Total Node Count: 4
2828
CHECK-NEXT: Terminal Node Count: 2
2929
CHECK-NEXT: Depth: 2
3030

31-
RUN: llvm-cgdata -convert %t/merge-archive.cgdata | FileCheck %s --check-prefix=TREE
31+
RUN: llvm-cgdata --convert %t/merge-archive.cgdata | FileCheck %s --check-prefix=TREE
3232
TREE: # Outlined stable hash tree
3333
TREE-NEXT: :outlined_hash_tree
3434
TREE-NEXT: ---

llvm/test/tools/llvm-cgdata/merge-concat.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ RUN: split-file %s %t
77

88
# Synthesize two sets of raw cgdata without the header (24 byte) from the indexed cgdata.
99
# Concatenate them in merge-concat.ll
10-
RUN: llvm-cgdata -convert -format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
10+
RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
1111
RUN: od -t x1 -j 24 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ]*$//' | sed 's/[ ][ ]*/\\\\/g' > %t/raw-1-bytes.txt
1212
RUN: sed -ie "s/<RAW_1_BYTES>/$(cat %t/raw-1-bytes.txt)/g" %t/merge-concat.ll
13-
RUN: llvm-cgdata -convert -format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
13+
RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
1414
RUN: od -t x1 -j 24 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ]*$//' | sed 's/[ ][ ]*/\\\\/g' > %t/raw-2-bytes.txt
1515
RUN: sed -ie "s/<RAW_2_BYTES>/$(cat %t/raw-2-bytes.txt)/g" %t/merge-concat.ll
1616

1717
RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-concat.ll -o %t/merge-concat.o
18-
RUN: llvm-cgdata -merge %t/merge-concat.o -o %t/merge-concat.cgdata
19-
RUN: llvm-cgdata -show %t/merge-concat.cgdata | FileCheck %s
18+
RUN: llvm-cgdata --merge %t/merge-concat.o -o %t/merge-concat.cgdata
19+
RUN: llvm-cgdata --show %t/merge-concat.cgdata | FileCheck %s
2020
CHECK: Outlined hash tree:
2121
CHECK-NEXT: Total Node Count: 4
2222
CHECK-NEXT: Terminal Node Count: 2
2323
CHECK-NEXT: Depth: 2
2424

25-
RUN: llvm-cgdata -convert %t/merge-concat.cgdata | FileCheck %s --check-prefix=TREE
25+
RUN: llvm-cgdata --convert %t/merge-concat.cgdata | FileCheck %s --check-prefix=TREE
2626
TREE: # Outlined stable hash tree
2727
TREE-NEXT: :outlined_hash_tree
2828
TREE-NEXT: ---

llvm/test/tools/llvm-cgdata/merge-double.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
RUN: split-file %s %t
77

88
# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata.
9-
RUN: llvm-cgdata -convert -format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
9+
RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata
1010
RUN: od -t x1 -j 24 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ]*$//' | sed 's/[ ][ ]*/\\\\/g' > %t/raw-1-bytes.txt
1111
RUN: sed -ie "s/<RAW_1_BYTES>/$(cat %t/raw-1-bytes.txt)/g" %t/merge-1.ll
1212
RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-1.ll -o %t/merge-1.o
1313

1414
# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata.
15-
RUN: llvm-cgdata -convert -format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
15+
RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata
1616
RUN: od -t x1 -j 24 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ]*$//' | sed 's/[ ][ ]*/\\\\/g' > %t/raw-2-bytes.txt
1717
RUN: sed -ie "s/<RAW_2_BYTES>/$(cat %t/raw-2-bytes.txt)/g" %t/merge-2.ll
1818
RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-2.ll -o %t/merge-2.o
1919

2020
# Merge two object files into the codegen data file.
21-
RUN: llvm-cgdata -merge %t/merge-1.o %t/merge-2.o -o %t/merge.cgdata
21+
RUN: llvm-cgdata --merge %t/merge-1.o %t/merge-2.o -o %t/merge.cgdata
2222

23-
RUN: llvm-cgdata -show %t/merge.cgdata | FileCheck %s
23+
RUN: llvm-cgdata --show %t/merge.cgdata | FileCheck %s
2424
CHECK: Outlined hash tree:
2525
CHECK-NEXT: Total Node Count: 4
2626
CHECK-NEXT: Terminal Node Count: 2
2727
CHECK-NEXT: Depth: 2
2828

29-
RUN: llvm-cgdata -convert %t/merge.cgdata | FileCheck %s --check-prefix=TREE
29+
RUN: llvm-cgdata --convert %t/merge.cgdata | FileCheck %s --check-prefix=TREE
3030
TREE: # Outlined stable hash tree
3131
TREE-NEXT: :outlined_hash_tree
3232
TREE-NEXT: ---

llvm/test/tools/llvm-cgdata/merge-single.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ RUN: split-file %s %t
77

88
# Merge an object file that has no cgdata (__llvm_outline). It still produces a header only cgdata.
99
RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-empty.ll -o %t/merge-empty.o
10-
RUN: llvm-cgdata -merge %t/merge-empty.o -o %t/merge-empty.cgdata
10+
RUN: llvm-cgdata --merge %t/merge-empty.o --output %t/merge-empty.cgdata
1111
# No summary appear with the header only cgdata.
12-
RUN: llvm-cgdata -show %t/merge-empty.cgdata | count 0
12+
RUN: llvm-cgdata --show %t/merge-empty.cgdata | count 0
1313

1414
# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata.
15-
RUN: llvm-cgdata -convert -format binary %t/raw-single.cgtext -o %t/raw-single.cgdata
15+
RUN: llvm-cgdata --convert --format binary %t/raw-single.cgtext -o %t/raw-single.cgdata
1616
RUN: od -t x1 -j 24 -An %t/raw-single.cgdata | tr -d '\n\r\t' | sed 's/[ ]*$//' | sed 's/[ ][ ]*/\\\\/g' > %t/raw-single-bytes.txt
1717

1818
RUN: sed -ie "s/<RAW_1_BYTES>/$(cat %t/raw-single-bytes.txt)/g" %t/merge-single.ll
1919
RUN: llc -filetype=obj -mtriple arm64-apple-darwin %t/merge-single.ll -o %t/merge-single.o
2020

2121
# Merge an object file having cgdata (__llvm_outline)
22-
RUN: llvm-cgdata -merge %t/merge-single.o -o %t/merge-single.cgdata
23-
RUN: llvm-cgdata -show %t/merge-single.cgdata | FileCheck %s
22+
RUN: llvm-cgdata -m %t/merge-single.o -o %t/merge-single.cgdata
23+
RUN: llvm-cgdata -s %t/merge-single.cgdata | FileCheck %s
2424
CHECK: Outlined hash tree:
2525
CHECK-NEXT: Total Node Count: 3
2626
CHECK-NEXT: Terminal Node Count: 1

llvm/test/tools/llvm-cgdata/show.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Test show
22

33
RUN: split-file %s %t
4-
RUN: llvm-cgdata -show %t/show.cgtext | FileCheck %s
4+
RUN: llvm-cgdata --show %t/show.cgtext | FileCheck %s
55

66
CHECK: Outlined hash tree:
77
CHECK-NEXT: Total Node Count: 3
88
CHECK-NEXT: Terminal Node Count: 1
99
CHECK-NEXT: Depth: 2
1010

1111
# Convert the text file to the binary file
12-
RUN: llvm-cgdata -convert -format binary %t/show.cgtext -o %t/show.cgdata
13-
RUN: llvm-cgdata -show %t/show.cgdata | FileCheck %s
12+
RUN: llvm-cgdata --convert --format binary %t/show.cgtext -o %t/show.cgdata
13+
RUN: llvm-cgdata --show %t/show.cgdata | FileCheck %s
1414

1515
;--- show.cgtext
1616
:outlined_hash_tree

llvm/tools/llvm-cgdata/Opts.td

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
include "llvm/Option/OptParser.td"
22

33
class F<string letter, string help> : Flag<["-"], letter>, HelpText<help>;
4+
class FF<string name, string help> : Flag<["--"], name>, HelpText<help>;
45

56
// General options
67
def generic_group : OptionGroup<"Genric Options">, HelpText<"Generic Options">;
7-
def help : F<"help", "Display this help">, Group<generic_group>;
8-
def : Flag<["-"], "h">, Alias<help>, HelpText<"Alias for --help">, Group<generic_group>;
9-
def version : F<"version", "Display the version">, Group<generic_group>;
10-
def : Flag<["-"], "v">, Alias<version>, HelpText<"Alias for --version">, Group<generic_group>;
8+
def help : FF<"help", "Display this help">, Group<generic_group>;
9+
def : F<"h", "Alias for --help">, Alias<help>, Group<generic_group>;
10+
def version : FF<"version", "Display the LLVM version">, Group<generic_group>;
11+
def : F<"v", "Alias for --version">, Alias<version>, Group<generic_group>;
1112

1213
// Action options
1314
def action_group : OptionGroup<"Action">, HelpText<"Action (required)">;
14-
def show : F<"show", "Show summary of the (indexed) codegen data file.">,
15+
def show : FF<"show", "Show summary of the (indexed) codegen data file.">,
1516
Group<action_group>;
16-
def convert : F<"convert", "Convert the (indexed) codegen data file in either text or binary format.">,
17+
def : F<"s", "Alias for --show">, Alias<show>, Group<action_group>;
18+
def convert : FF<"convert", "Convert the (indexed) codegen data file in either text or binary format.">,
1719
Group<action_group>;
18-
def merge : F<"merge", "Takes binary files having raw codegen data in custom sections, and merge them into an index codegen data file.">,
20+
def : F<"c", "Alias for --convert">, Alias<convert>, Group<action_group>;
21+
def merge : FF<"merge", "Take binary files having raw codegen data in custom sections, and merge them into an indexed codegen data file.">,
1922
Group<action_group>;
20-
def cgdata_version : Flag<["-", "--"], "cgdata-version">, HelpText<"Display the cgdata version">;
23+
def : F<"m", "Alias for --merge">, Alias<merge>, Group<action_group>;
2124

22-
// Output options
23-
def output : Option<["-", "--"], "output", KIND_SEPARATE>,
24-
HelpText<"Create output file with specified name">, MetaVarName<"<file>">;
25-
def o : JoinedOrSeparate<["-"], "o">, Alias<output>;
26-
def format : Option<["-", "--"], "format", KIND_SEPARATE>,
25+
// Additional options
26+
def cgdata_version : FF<"cgdata-version", "Display the cgdata version">;
27+
def output : Option<["--"], "output", KIND_SEPARATE>,
28+
HelpText<"Specify the name for the output file to be created">, MetaVarName<"<file>">;
29+
def : JoinedOrSeparate<["-"], "o">, Alias<output>, MetaVarName<"<file>">, HelpText<"Alias for --output">;
30+
def format : Option<["--"], "format", KIND_SEPARATE>,
2731
HelpText<"Specify the output format (text or binary)">, MetaVarName<"<value>">;
28-
def f : JoinedOrSeparate<["-"], "f">, Alias<format>;
32+
def : JoinedOrSeparate<["-"], "f">, Alias<format>, HelpText<"Alias for --format">;

llvm/tools/llvm-cgdata/llvm-cgdata.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ class CGDataOptTable : public opt::GenericOptTable {
7272
} // end anonymous namespace
7373

7474
// Options
75-
static std::string ToolName;
76-
static std::string OutputFilename = "-";
77-
static std::string Filename;
75+
static StringRef ToolName;
76+
static StringRef OutputFilename = "-";
77+
static StringRef Filename;
7878
static bool ShowCGDataVersion;
7979
static CGDataAction Action;
8080
static std::optional<CGDataFormat> OutputFormat;
@@ -267,8 +267,8 @@ static void parseArgs(int argc, char **argv) {
267267
if (Args.hasArg(OPT_help)) {
268268
Tbl.printHelp(
269269
llvm::outs(),
270-
"llvm-cgdata [options] <action> (<binary files>|<.cgdata file>)",
271-
ToolName.c_str());
270+
"llvm-cgdata <action> [options] (<binary files>|<.cgdata file>)",
271+
ToolName.str().c_str());
272272
std::exit(0);
273273
}
274274
if (Args.hasArg(OPT_version)) {

0 commit comments

Comments
 (0)