Skip to content

Commit fd56694

Browse files
committed
Use Opt to re-configure llvm-cgdata
- Action options are required, starting with : convert, show, merge. - -format option is added, to generalize an output option: text, or binary.
1 parent 911820b commit fd56694

File tree

12 files changed

+232
-114
lines changed

12 files changed

+232
-114
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/dump.test renamed to 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 dump -binary %t/dump.cgtext -o %t/dump.cgdata
6-
RUN: llvm-cgdata dump -text %t/dump.cgdata -o %t/dump-round.cgtext
7-
RUN: llvm-cgdata dump -binary %t/dump-round.cgtext -o %t/dump-round.cgdata
8-
RUN: llvm-cgdata dump -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 -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
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# Test no input file
2-
RUN: not llvm-cgdata dump -o - 2>&1 | FileCheck %s --check-prefix=NOFILE --ignore-case
3-
NOFILE: error: No such file or directory
2+
RUN: not llvm-cgdata -convert -o - 2>&1 | FileCheck %s --check-prefix=NOFILE --ignore-case
3+
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 dump %t_emptyfile.cgtext -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 dump %t_emptyheader.cgtext -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 dump %t_emptyheader.cgdata -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 dump -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 dump -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 dump %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 dump -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 dump -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 dump %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 dump -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 dump -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 dump %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 -o %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 dump -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 -merge %t/merge-single.o -o %t/merge-single.cgdata
23+
RUN: llvm-cgdata -show %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 dump -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/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ set(LLVM_LINK_COMPONENTS
33
CodeGenData
44
Core
55
Object
6+
Option
67
Support
78
)
89

10+
set(LLVM_TARGET_DEFINITIONS Opts.td)
11+
tablegen(LLVM Opts.inc -gen-opt-parser-defs)
12+
add_public_tablegen_target(CGDataOptsTableGen)
13+
914
add_llvm_tool(llvm-cgdata
1015
llvm-cgdata.cpp
1116

1217
DEPENDS
1318
intrinsics_gen
19+
CGDataOptsTableGen
1420
GENERATE_DRIVER
1521
)

llvm/tools/llvm-cgdata/Opts.td

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include "llvm/Option/OptParser.td"
2+
3+
class F<string letter, string help> : Flag<["-"], letter>, HelpText<help>;
4+
5+
// General options
6+
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>;
11+
12+
// Action options
13+
def action_group : OptionGroup<"Action">, HelpText<"Action (required)">;
14+
def show : F<"show", "Show summary of the (indexed) codegen data file.">,
15+
Group<action_group>;
16+
def convert : F<"convert", "Convert the (indexed) codegen data file in either text or binary format.">,
17+
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.">,
19+
Group<action_group>;
20+
def cgdata_version : Flag<["-", "--"], "cgdata-version">, HelpText<"Display the cgdata version">;
21+
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>,
27+
HelpText<"Specify the output format (text or binary)">, MetaVarName<"<value>">;
28+
def f : JoinedOrSeparate<["-"], "f">, Alias<format>;

0 commit comments

Comments
 (0)