[llvm] [llvm-mca] Skip instrumentation pass when -disable-im is set (PR #211759)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 09:24:48 PDT 2026


================
@@ -537,31 +537,45 @@ int main(int argc, char **argv) {
   }
 
   // Parse the input and create InstrumentRegion that llvm-mca
-  // can use to improve analysis.
-  MCContext ICtx(TheTriple, *MAI, *MRI, *STI, &SrcMgr);
-  std::unique_ptr<MCObjectFileInfo> IMOFI(
-      TheTarget->createMCObjectFileInfo(ICtx, /*PIC=*/false));
-  ICtx.setObjectFileInfo(IMOFI.get());
-  mca::AsmInstrumentRegionGenerator IRG(*TheTarget, SrcMgr, ICtx, *MAI, *STI,
-                                        *MCII, *IM);
-  Expected<const mca::InstrumentRegions &> InstrumentRegionsOrErr =
-      IRG.parseInstrumentRegions(std::move(IPtemp),
-                                 shouldSkip(SkipType::PARSE_FAILURE));
-  if (!InstrumentRegionsOrErr) {
-    if (auto Err = handleErrors(InstrumentRegionsOrErr.takeError(),
-                                [](const StringError &E) {
-                                  WithColor::error() << E.getMessage() << '\n';
-                                })) {
-      // Default case.
-      WithColor::error() << toString(std::move(Err)) << '\n';
+  // can use to improve analysis. Do not parse instrument regions if the
+  // -disable-im flag is set.
+  mca::InstrumentRegions EmptyInstrumentRegions(SrcMgr);
+  const mca::InstrumentRegions *InstrumentRegions = &EmptyInstrumentRegions;
+
+  std::unique_ptr<MCContext> ICtx;
+  std::unique_ptr<MCObjectFileInfo> IMOFI;
+  std::unique_ptr<mca::AsmInstrumentRegionGenerator> IRG;
+
+  if (!IM->shouldIgnoreInstruments()) {
+    ICtx = std::make_unique<MCContext>(TheTriple, *MAI, *MRI, *STI, &SrcMgr);
+    IMOFI.reset(TheTarget->createMCObjectFileInfo(*ICtx, /*PIC=*/false));
+    ICtx->setObjectFileInfo(IMOFI.get());
+    IRG = std::make_unique<mca::AsmInstrumentRegionGenerator>(
+        *TheTarget, SrcMgr, *ICtx, *MAI, *STI, *MCII, *IM);
+
+    Expected<const mca::InstrumentRegions &> InstrumentRegionsOrErr =
+        IRG->parseInstrumentRegions(std::move(IPtemp),
+                                   shouldSkip(SkipType::PARSE_FAILURE));
----------------
mshockwave wrote:

have you run clang-format through this code?

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


More information about the llvm-commits mailing list