Skip to content

Commit 619a4c3

Browse files
committed
fixup! Address review comments
1 parent 14913ca commit 619a4c3

File tree

4 files changed

+46
-23
lines changed

4 files changed

+46
-23
lines changed

llvm/include/llvm/Support/Compression.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ADT/ArrayRef.h"
1717
#include "llvm/Support/DataTypes.h"
18+
#include "llvm/Support/YAMLTraits.h"
1819

1920
namespace llvm {
2021
template <typename T> class SmallVectorImpl;
@@ -126,6 +127,16 @@ Error decompress(DebugCompressionType T, ArrayRef<uint8_t> Input,
126127

127128
} // End of namespace compression
128129

130+
namespace yaml {
131+
// Related YAML traits.
132+
template <> struct ScalarEnumerationTraits<compression::Format> {
133+
static void enumeration(IO &Io, compression::Format &Format) {
134+
Io.enumCase(Format, "zstd", compression::Format::Zstd);
135+
Io.enumCase(Format, "zlib", compression::Format::Zlib);
136+
}
137+
};
138+
} // namespace yaml
139+
129140
} // End of namespace llvm
130141

131142
#endif

llvm/test/tools/llvm-exegesis/serialize-obj-file.test

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --benchmark-phase=assemble-measured-code --mode=latency --benchmarks-file=%t.yaml
1+
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --exegesis-serialize-benchmarks --benchmark-phase=assemble-measured-code \
2+
# RUN: --mode=latency --benchmarks-file=%t.yaml
23
# RUN: FileCheck --input-file=%t.yaml %s --check-prefixes=CHECK,SERIALIZE
34
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --run-measurement=%t.yaml --mode=latency --benchmark-phase=dry-run-measurement --use-dummy-perf-counters \
45
# RUN: --dump-object-to-disk=%t.o | FileCheck %s --check-prefixes=CHECK,DESERIALIZE
56
# RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefix=OBJDUMP
6-
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --mode=latency --benchmark-phase=dry-run-measurement --use-dummy-perf-counters | \
7-
# RUN: FileCheck %s --check-prefix=NO-SERIALIZE
8-
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --mode=latency --benchmark-phase=assemble-measured-code --repetition-mode=min | \
9-
# RUN: FileCheck %s --check-prefix=NO-SERIALIZE
10-
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --mode=latency --benchmark-phase=assemble-measured-code --repetition-mode=middle-half-loop | \
11-
# RUN: FileCheck %s --check-prefix=NO-SERIALIZE
12-
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --mode=latency --benchmark-phase=assemble-measured-code --repetition-mode=middle-half-duplicate | \
7+
8+
# We should not serialie benchmarks by default.
9+
# RUN: llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --benchmark-phase=assemble-measured-code --mode=latency | \
1310
# RUN: FileCheck %s --check-prefix=NO-SERIALIZE
11+
12+
# We currently don't support serialization for repetition modes that require more than one snippets.
13+
# RUN: not llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --mode=latency --exegesis-serialize-benchmarks --benchmark-phase=assemble-measured-code \
14+
# RUN: --repetition-mode=min 2>&1 | FileCheck %s --check-prefix=NOT-SUPPORTED
15+
# RUN: not llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --mode=latency --exegesis-serialize-benchmarks --benchmark-phase=assemble-measured-code \
16+
# RUN: --repetition-mode=middle-half-loop 2>&1 | FileCheck %s --check-prefix=NOT-SUPPORTED
17+
# RUN: not llvm-exegesis -mtriple=riscv64 -mcpu=sifive-p470 --opcode-name=SH3ADD --mode=latency --exegesis-serialize-benchmarks --benchmark-phase=assemble-measured-code \
18+
# RUN: --repetition-mode=middle-half-duplicate 2>&1 | FileCheck %s --check-prefix=NOT-SUPPORTED
19+
1420
# REQUIRES: riscv-registered-target && native-registered-exegesis-target
1521
# REQUIRES: zlib || zstd
1622

@@ -29,6 +35,7 @@
2935

3036
# OBJDUMP: sh3add
3137

32-
# Negative tests: we shouldn't serialize object files in some scenarios.
38+
# Negative tests.
3339

40+
# NOT-SUPPORTED: -exegesis-serialize-benchmarks currently only supports -repetition-mode of loop and duplicate.
3441
# NO-SERIALIZE-NOT: object_file:

llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,6 @@ template <> struct ScalarTraits<exegesis::RegisterValue> {
287287
static const bool flow = true;
288288
};
289289

290-
template <> struct ScalarEnumerationTraits<compression::Format> {
291-
static void enumeration(IO &Io, compression::Format &Format) {
292-
Io.enumCase(Format, "zstd", compression::Format::Zstd);
293-
Io.enumCase(Format, "zlib", compression::Format::Zlib);
294-
}
295-
};
296-
297290
template <> struct MappingContextTraits<exegesis::BenchmarkKey, YamlContext> {
298291
static void mapping(IO &Io, exegesis::BenchmarkKey &Obj,
299292
YamlContext &Context) {

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/ADT/Twine.h"
2121
#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
22+
#include "llvm/Support/CommandLine.h"
2223
#include "llvm/Support/CrashRecoveryContext.h"
2324
#include "llvm/Support/Error.h"
2425
#include "llvm/Support/FileSystem.h"
@@ -51,6 +52,14 @@
5152
#endif // __linux__
5253

5354
namespace llvm {
55+
56+
static cl::opt<bool>
57+
SerializeBenchmarks("exegesis-serialize-benchmarks",
58+
cl::desc("Generate fully-serialized benchmarks "
59+
"that can later be deserialized and "
60+
"resuming the measurement."),
61+
cl::init(false));
62+
5463
namespace exegesis {
5564

5665
BenchmarkRunner::BenchmarkRunner(const LLVMState &State, Benchmark::ModeE Mode,
@@ -664,16 +673,19 @@ BenchmarkRunner::getRunnableConfiguration(
664673
LoopBodySize, GenerateMemoryInstructions);
665674
if (Error E = Snippet.takeError())
666675
return std::move(E);
667-
// There is no need to serialize/deserialize the object file if we're
668-
// simply running end-to-end measurements.
669-
// Same goes for any repetition mode that requires more than a single
670-
// snippet.
671-
if (BenchmarkPhaseSelector < BenchmarkPhaseSelectorE::Measure &&
672-
(RepetitionMode == Benchmark::Loop ||
673-
RepetitionMode == Benchmark::Duplicate)) {
676+
677+
// Generate fully-serialized benchmarks.
678+
if (SerializeBenchmarks) {
679+
if (RepetitionMode != Benchmark::Loop &&
680+
RepetitionMode != Benchmark::Duplicate)
681+
return make_error<Failure>(
682+
"-exegesis-serialize-benchmarks currently "
683+
"only supports -repetition-mode of loop and duplicate.");
684+
674685
if (Error E = BenchmarkResult.setObjectFile(*Snippet))
675686
return std::move(E);
676687
}
688+
677689
RC.ObjectFile = getObjectFromBuffer(*Snippet);
678690
}
679691

0 commit comments

Comments
 (0)