[llvm-exegesis] Allow the randomizer to fail nicely...
Summary:
... instead of crashing.
On typical exmaple is when there are no available registers.
Reviewers: gchatelet
Subscribers: tschuett, mstojanovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73196
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h b/llvm/tools/llvm-exegesis/lib/Target.h
index bd43009..d9bddc5 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -18,6 +18,7 @@
#include "BenchmarkResult.h"
#include "BenchmarkRunner.h"
+#include "Error.h"
#include "LlvmState.h"
#include "SnippetGenerator.h"
#include "llvm/ADT/Triple.h"
@@ -108,12 +109,15 @@
virtual unsigned getMaxMemoryAccessSize() const { return 0; }
// Assigns a random operand of the right type to variable Var.
- // The default implementation only handles generic operand types.
- // The target is responsible for handling any operand
- // starting from OPERAND_FIRST_TARGET.
- virtual void randomizeMCOperand(const Instruction &Instr, const Variable &Var,
- MCOperand &AssignedValue,
- const BitVector &ForbiddenRegs) const;
+ // The target is responsible for handling any operand starting from
+ // OPERAND_FIRST_TARGET.
+ virtual Error randomizeTargetMCOperand(const Instruction &Instr,
+ const Variable &Var,
+ MCOperand &AssignedValue,
+ const BitVector &ForbiddenRegs) const {
+ return make_error<Failure>(
+ "targets with target-specific operands should implement this");
+ }
// Returns true if this instruction is supported as a back-to-back
// instructions.