[llvm-dev] Adding LoopNest case to getIRName

raghesh via llvm-dev llvm-dev at lists.llvm.org
Tue May 11 23:25:39 PDT 2021


Hi All

While working on a LoopNest pass, I hit 'unreachable code' in the
getIRName, which is invoked as part of debugging options (like
-debug-pass-manager). It is figured out that within getIRName, LoopNest is
not handled. I could fix it with the following patch.

diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp
b/llvm/lib/Passes/StandardInstrumentations.cpp
index e64df0b1147f..65e0e7d4cf27 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Analysis/LazyCallGraph.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/Function.h"
+#include "llvm/Analysis/LoopNestAnalysis.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassInstrumentation.h"
 #include "llvm/IR/PassManager.h"
@@ -285,6 +286,17 @@ std::string getIRName(Any IR) {
     return OS.str();
   }

+  if (any_isa<const LoopNest *>(IR)) {
+    const Loop *L = &any_cast<const LoopNest *>(IR)->getOutermostLoop();
+    std::string S;
+    raw_string_ostream OS(S);
+    assert(L && "Loop should be valid for printing");
+    L->print(OS, /*Verbose*/ false, /*PrintNested*/ false);
+    return OS.str();
+  }
+
   llvm_unreachable("Unknown wrapped IR type");
 }

Just wanted to make sure that this is the right fix and if it is so we can
upstream this change.

Regards,
------------------------------
Raghesh Aloor
AMD India Pvt. Ltd.
Bengaluru.
------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210512/e37e9e15/attachment.html>


More information about the llvm-dev mailing list