[llvm] [MCA] Enable customization of individual instructions (PR #155420)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 17 10:19:47 PDT 2025


================
@@ -234,3 +234,27 @@ TEST_F(X86TestBase, TestVariantInstructionsSameAddress) {
   Expected<unsigned> Cycles = P->run();
   ASSERT_TRUE(static_cast<bool>(Cycles));
 }
+
+// Test customization of instruction latency with instruments
+TEST_F(X86TestBase, TestInstructionCustomization) {
+  const unsigned ExplicitLatency = 100;
+  SmallVector<MCInst> MCIs;
+  MCInst InstructionToAdd = MCInstBuilder(X86::XOR64rr)
+                                .addReg(X86::RAX)
+                                .addReg(X86::RAX)
+                                .addReg(X86::RAX);
+  MCIs.push_back(InstructionToAdd);
+  SmallVector<std::pair<StringRef, StringRef>> InstrDescs;
+  auto LatStr = std::to_string(ExplicitLatency);
+  InstrDescs.push_back(std::make_pair(StringRef("LATENCY"), StringRef(LatStr)));
----------------
mshockwave wrote:

I thought StringRef has implicit conversion from both `const char *` and std::string. Does it work if you remove the `StringRef(...)` here?

https://github.com/llvm/llvm-project/pull/155420


More information about the llvm-commits mailing list