[llvm] llvm-extract now supports unnamed basic blocks. (PR #112850)

Allin Lee via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 00:50:01 PDT 2024


https://github.com/AllinLeeYL created https://github.com/llvm/llvm-project/pull/112850

This PR enables the llvm-extract tool to support unnamed basic blocks with only a few lines of modification on llvm/tools/llvm-extract/llvm-extract.cpp.

>From 26c5d93dc949aac9074020f29f564c27abc1564f Mon Sep 17 00:00:00 2001
From: Allin Lee <allinleeme at gmail.com>
Date: Fri, 18 Oct 2024 15:40:51 +0800
Subject: [PATCH] llvm-extract now supports unnamed basic blocks.

---
 llvm/tools/llvm-extract/llvm-extract.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/llvm/tools/llvm-extract/llvm-extract.cpp b/llvm/tools/llvm-extract/llvm-extract.cpp
index 5fc9a31ab4ad7c..73123a699dd82f 100644
--- a/llvm/tools/llvm-extract/llvm-extract.cpp
+++ b/llvm/tools/llvm-extract/llvm-extract.cpp
@@ -355,9 +355,23 @@ int main(int argc, char **argv) {
       for (StringRef BBName : P.second) {
         // The function has been materialized, so add its matching basic blocks
         // to the block extractor list, or fail if a name is not found.
+#ifndef NDEBUG
+        auto Res = llvm::find_if(*P.first, [&](const BasicBlock &BB) {
+          return BB.getNameOrAsOperand() == BBName;
+        });
+#else
         auto Res = llvm::find_if(*P.first, [&](const BasicBlock &BB) {
           return BB.getName() == BBName;
         });
+        if (Res == P.first->end() && std::isdigit(BBName)) {
+          Res = llvm::find_if(*P.first, [&](const BasicBlock &BB) {
+            std::string tmpName;
+            raw_string_ostream OS(tmpName);
+            BB.printAsOperand(OS, false);
+            return OS.str() == BBName;
+          });
+        }
+#endif
         if (Res == P.first->end()) {
           errs() << argv[0] << ": function " << P.first->getName()
                  << " doesn't contain a basic block named '" << BBName



More information about the llvm-commits mailing list