|
17 | 17 | #include "llvm/ADT/StringExtras.h"
|
18 | 18 | #include "llvm/ADT/StringRef.h"
|
19 | 19 | #include "llvm/ADT/Twine.h"
|
| 20 | +#include "llvm/Support/Error.h" |
20 | 21 | #include "llvm/Support/FileSystem.h"
|
21 | 22 | #include "llvm/Support/FormatVariadic.h"
|
22 | 23 | #include "llvm/Support/Program.h"
|
@@ -77,9 +78,12 @@ Error SnippetGenerator::generateConfigurations(
|
77 | 78 | BC.Info = CT.Info;
|
78 | 79 | BC.Key.Instructions.reserve(CT.Instructions.size());
|
79 | 80 | for (InstructionTemplate &IT : CT.Instructions) {
|
80 |
| - if (auto error = randomizeUnsetVariables(State, ForbiddenRegs, IT)) |
81 |
| - return error; |
82 |
| - BC.Key.Instructions.push_back(IT.build()); |
| 81 | + if (auto Error = randomizeUnsetVariables(State, ForbiddenRegs, IT)) |
| 82 | + return Error; |
| 83 | + MCInst Inst = IT.build(); |
| 84 | + if (auto Error = validateGeneratedInstruction(State, Inst)) |
| 85 | + return Error; |
| 86 | + BC.Key.Instructions.push_back(Inst); |
83 | 87 | }
|
84 | 88 | if (CT.ScratchSpacePointerInReg)
|
85 | 89 | BC.LiveIns.push_back(CT.ScratchSpacePointerInReg);
|
@@ -282,5 +286,21 @@ Error randomizeUnsetVariables(const LLVMState &State,
|
282 | 286 | return Error::success();
|
283 | 287 | }
|
284 | 288 |
|
| 289 | +Error validateGeneratedInstruction(const LLVMState &State, const MCInst &Inst) { |
| 290 | + for (const auto &Operand : Inst) { |
| 291 | + if (!Operand.isValid()) { |
| 292 | + // Mention the particular opcode - it is not necessarily the "main" |
| 293 | + // opcode being benchmarked by this snippet. For example, serial snippet |
| 294 | + // generator uses one more opcode when in SERIAL_VIA_NON_MEMORY_INSTR |
| 295 | + // execution mode. |
| 296 | + const auto OpcodeName = State.getInstrInfo().getName(Inst.getOpcode()); |
| 297 | + return make_error<Failure>("Not all operands were initialized by the " |
| 298 | + "snippet generator for " + |
| 299 | + OpcodeName + " opcode."); |
| 300 | + } |
| 301 | + } |
| 302 | + return Error::success(); |
| 303 | +} |
| 304 | + |
285 | 305 | } // namespace exegesis
|
286 | 306 | } // namespace llvm
|
0 commit comments