Skip to content

Commit 67c86b5

Browse files
Make blocks_per_json_file flag not output extra files (llvm#63)
Currently, the logic in convert_bhive_to_llvm_exegesis_input will create extra (empty) files as the output at the end runs unconditionally rather than when there are actually blocks to output. This means that if we have a number of blocks that is an exact multiple of the value in blocks_per_json_file, we end up getting no blocks after the loop, which means we output an empty JSON file. Fixes llvm#61.
1 parent c1231ad commit 67c86b5

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

gematria/datasets/convert_bhive_to_llvm_exegesis_input.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ int main(int argc, char* argv[]) {
346346
file_counter++;
347347
}
348348

349-
if (!json_output_dir.empty()) {
349+
if (!json_output_dir.empty() && processed_snippets.size() != 0) {
350350
size_t json_file_number = file_counter / blocks_per_json_file;
351351
bool write_successfully = WriteJsonFile(std::move(processed_snippets),
352352
json_file_number, json_output_dir);
Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
11
; Test that splitting a dataset among multiple JSON files works as expected.
22

3-
; Test currently fails as underlying functionality needs to be fixed, see #61.
4-
; XFAIL: *
5-
63
; RUN: split-file %s %t
74
; RUN: mkdir %t.jsondir
8-
; RUN: %convert_bhive_to_llvm_exegesis_input --json_output_dir=%t.jsondir --bhive_csv=%t/test.csv
5+
; RUN: %convert_bhive_to_llvm_exegesis_input --json_output_dir=%t.jsondir --bhive_csv=%t/test.csv --blocks_per_json_file=1
96
; RUN: cat %t.jsondir/0.json | FileCheck --check-prefix FILE1 %s
107
; RUN: cat %t.jsondir/1.json | FileCheck --check-prefix FILE2 %s
118

12-
; FILE1-CHECK: [
13-
; FILE1-CHECK: {
14-
; FILE1-CHECK: "Hex": "85c044897c2460",
15-
; FILE1-CHECK: "MemoryDefinitions": [
16-
; FILE1-CHECK: {
17-
; FILE1-CHECK: "Name": "MEM",
18-
; FILE1-CHECK: "Size": 4096,
19-
; FILE1-CHECK: "Value": 305419776
20-
; FILE1-CHECK: }
21-
; FILE1-CHECK: ],
22-
; FILE1-CHECK: "MemoryMappings": [
23-
; FILE1-CHECK: {
24-
; FILE1-CHECK: "Address": 65536,
25-
; FILE1-CHECK: "Value": "MEM"
26-
; FILE1-CHECK: }
27-
; FILE1-CHECK: ]
28-
; FILE1-CHECK: }
29-
; FILE1-CHECK: ]
9+
; Ensure that we don't have any "leftover" files.
10+
; RUN: ls %t.jsondir | FileCheck --check-prefix DIR %s
11+
12+
; FILE1: [
13+
; FILE1: {
14+
; FILE1: "Hex": "85c044897c2460",
15+
; FILE1: "MemoryDefinitions": [
16+
; FILE1: {
17+
; FILE1: "Name": "MEM",
18+
; FILE1: "Size": 4096,
19+
; FILE1: "Value": 305419776
20+
; FILE1: }
21+
; FILE1: ],
22+
; FILE1: "MemoryMappings": [
23+
; FILE1: {
24+
; FILE1: "Address": 65536,
25+
; FILE1: "Value": "MEM"
26+
; FILE1: }
27+
; FILE1: ]
28+
; FILE1: }
29+
; FILE1: ]
30+
31+
; FILE2: [
32+
; FILE2: {
33+
; FILE2: "Hex": "3b31",
34+
; FILE2: "MemoryDefinitions": [
35+
; FILE2: {
36+
; FILE2: "Name": "MEM",
37+
; FILE2: "Size": 4096,
38+
; FILE2: "Value": 305419776
39+
; FILE2: }
40+
; FILE2: ],
41+
; FILE2: "MemoryMappings": [
42+
; FILE2: {
43+
; FILE2: "Address": 65536,
44+
; FILE2: "Value": "MEM"
45+
; FILE2: }
46+
; FILE2: ]
47+
; FILE2: }
48+
; FILE2: ]
3049

31-
; FILE2-CHECK: [
32-
; FILE2-CHECK: {
33-
; FILE2-CHECK: "Hex": "3b31",
34-
; FILE2-CHECK: "MemoryDefinitions": [
35-
; FILE2-CHECK: {
36-
; FILE2-CHECK: "Name": "MEM",
37-
; FILE2-CHECK: "Size": 4096,
38-
; FILE2-CHECK: "Value": 305419776
39-
; FILE2-CHECK: }
40-
; FILE2-CHECK: ],
41-
; FILE2-CHECK: "MemoryMappings": [
42-
; FILE2-CHECK: {
43-
; FILE2-CHECK: "Address": 65536,
44-
; FILE2-CHECK: "Value": "MEM"
45-
; FILE2-CHECK: }
46-
; FILE2-CHECK: ]
47-
; FILE2-CHECK: }
48-
; FILE2-CHECK: ]
50+
; DIR: 0.json
51+
; DIR: 1.json
52+
; DIR-NOT: 2.json
4953

5054
;--- test.csv
51-
3b31,45.000000
5255
85c044897c2460,98.000000
56+
3b31,45.000000

0 commit comments

Comments
 (0)