Skip to content

Commit ee84344

Browse files
[𝘀𝗽𝗿] initial version
Created using spr 1.3.7
1 parent 24b87b8 commit ee84344

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# REQUIRES: exegesis-can-measure-latency, x86_64-linux
2+
3+
# Check that the snippet we generate is exactly the same between runs when we
4+
# use a fixed RNG seed.
5+
6+
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mode=latency -opcode-name=ADD64rr --benchmark-phase=prepare-snippet -random-generator-seed=5 | FileCheck %s
7+
8+
# CHECK: ---
9+
# CHECK: mode: latency
10+
# CHECK: key:
11+
# CHECK: instructions:
12+
# CHECK: - 'ADD64rr RCX RCX RAX'
13+
# CHECK: config: ''
14+
# CHECK: register_initial_values:
15+
# CHECK: - 'RCX=0x0'
16+
# CHECK: - 'RAX=0x0'

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@
2121
#include "llvm/Support/FormatVariadic.h"
2222
#include "llvm/Support/Program.h"
2323

24+
#define DEBUG_TYPE "snippet-generator"
25+
2426
namespace llvm {
2527
namespace exegesis {
2628

29+
static cl::opt<unsigned>
30+
RandomGeneratorSeed("random-generator-seed",
31+
cl::desc("The seed value to use for the random number "
32+
"generator when generating snippets."),
33+
cl::init(0));
34+
2735
std::vector<CodeTemplate> getSingleton(CodeTemplate &&CT) {
2836
std::vector<CodeTemplate> Result;
2937
Result.push_back(std::move(CT));
@@ -187,8 +195,13 @@ generateUnconstrainedCodeTemplates(const InstructionTemplate &Variant,
187195
}
188196

189197
std::mt19937 &randomGenerator() {
198+
unsigned RandomSeed = RandomGeneratorSeed;
190199
static std::random_device RandomDevice;
191-
static std::mt19937 RandomGenerator(RandomDevice());
200+
if (RandomSeed == 0) {
201+
RandomSeed = RandomDevice();
202+
}
203+
LLVM_DEBUG(dbgs() << "Using random seed " << RandomSeed << ".\n");
204+
static std::mt19937 RandomGenerator(RandomSeed);
192205
return RandomGenerator;
193206
}
194207

0 commit comments

Comments
 (0)