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

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 16 10:33:55 PDT 2025


================
@@ -42,8 +43,35 @@ CustomBehaviour::getEndViews(llvm::MCInstPrinter &IP,
   return std::vector<std::unique_ptr<View>>();
 }
 
+const llvm::StringRef LatencyInstrument::DESC_NAME = "LATENCY";
+
+bool InstrumentManager::supportsInstrumentType(StringRef Type) const {
+  return EnableInstruments && Type == LatencyInstrument::DESC_NAME;
+}
+
+bool InstrumentManager::canCustomize(
+    const llvm::SmallVector<Instrument *> &IVec) const {
+  for (const auto I : IVec) {
+    if (I->canCustomize())
+      return true;
+  }
+  return false;
+}
+
+void InstrumentManager::customize(const llvm::SmallVector<Instrument *> &IVec,
+                                  InstrDesc &ID) const {
+  for (const auto I : IVec) {
+    if (I->canCustomize())
+      I->customize(ID);
+  }
+}
+
 UniqueInstrument InstrumentManager::createInstrument(llvm::StringRef Desc,
                                                      llvm::StringRef Data) {
+  if (!EnableInstruments)
+    return std::make_unique<Instrument>(Desc, Data);
+  if (Desc == LatencyInstrument::DESC_NAME)
+    return std::make_unique<LatencyInstrument>(Data);
   return std::make_unique<Instrument>(Desc, Data);
----------------
mshockwave wrote:

I know LLVM prefers early exits, but having two identical returns here just feel a little odd. Maybe this will be better?
```
if (EnableInstruments) {
 if (Desc == LatencyInstrument::DESC_NAME)
  // create latency instrument
}
// create default instrument
```

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


More information about the llvm-commits mailing list