[PATCH] D146304: [llvm-exegesis] Skip codegen of known-invalid snippets
Pavel Kosov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 25 06:44:42 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG742fa941f21d: [llvm-exegesis] Skip codegen of known-invalid snippets (authored by kpdev42).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146304/new/
https://reviews.llvm.org/D146304
Files:
llvm/test/tools/llvm-exegesis/AArch64/all-opcodes.test
llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp
llvm/tools/llvm-exegesis/lib/SnippetGenerator.h
Index: llvm/tools/llvm-exegesis/lib/SnippetGenerator.h
===================================================================
--- llvm/tools/llvm-exegesis/lib/SnippetGenerator.h
+++ llvm/tools/llvm-exegesis/lib/SnippetGenerator.h
@@ -107,6 +107,9 @@
const BitVector &ForbiddenRegs,
InstructionTemplate &IT);
+// Sanity check generated instruction.
+Error validateGeneratedInstruction(const LLVMState &State, const MCInst &Inst);
+
} // namespace exegesis
} // namespace llvm
Index: llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp
+++ llvm/tools/llvm-exegesis/lib/SnippetGenerator.cpp
@@ -17,6 +17,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Program.h"
@@ -77,9 +78,12 @@
BC.Info = CT.Info;
BC.Key.Instructions.reserve(CT.Instructions.size());
for (InstructionTemplate &IT : CT.Instructions) {
- if (auto error = randomizeUnsetVariables(State, ForbiddenRegs, IT))
- return error;
- BC.Key.Instructions.push_back(IT.build());
+ if (auto Error = randomizeUnsetVariables(State, ForbiddenRegs, IT))
+ return Error;
+ MCInst Inst = IT.build();
+ if (auto Error = validateGeneratedInstruction(State, Inst))
+ return Error;
+ BC.Key.Instructions.push_back(Inst);
}
if (CT.ScratchSpacePointerInReg)
BC.LiveIns.push_back(CT.ScratchSpacePointerInReg);
@@ -282,5 +286,21 @@
return Error::success();
}
+Error validateGeneratedInstruction(const LLVMState &State, const MCInst &Inst) {
+ for (const auto &Operand : Inst) {
+ if (!Operand.isValid()) {
+ // Mention the particular opcode - it is not necessarily the "main"
+ // opcode being benchmarked by this snippet. For example, serial snippet
+ // generator uses one more opcode when in SERIAL_VIA_NON_MEMORY_INSTR
+ // execution mode.
+ const auto OpcodeName = State.getInstrInfo().getName(Inst.getOpcode());
+ return make_error<Failure>("Not all operands were initialized by the "
+ "snippet generator for " +
+ OpcodeName + " opcode.");
+ }
+ }
+ return Error::success();
+}
+
} // namespace exegesis
} // namespace llvm
Index: llvm/test/tools/llvm-exegesis/AArch64/all-opcodes.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-exegesis/AArch64/all-opcodes.test
@@ -0,0 +1,10 @@
+# Test that we can just use --opcode-index=-1 to generate snippets for
+# all supported opcodes and gracefully handle unsupported ones.
+
+# RUN: llvm-exegesis --mtriple=aarch64-linux-gnu --mcpu=cortex-a55 --benchmark-phase=prepare-and-assemble-snippet \
+# RUN: --mode=latency --opcode-index=-1 | FileCheck %s
+# RUN: llvm-exegesis --mtriple=aarch64-linux-gnu --mcpu=cortex-a55 --benchmark-phase=prepare-and-assemble-snippet \
+# RUN: --mode=uops --opcode-index=-1 | FileCheck %s
+
+# 100 means "quite a lot"
+# CHECK-COUNT-100: assembled_snippet: {{.*}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146304.553457.patch
Type: text/x-patch
Size: 3406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230825/aa2d33c7/attachment.bin>
More information about the llvm-commits
mailing list