[PATCH] D103129: [llvm-reduce] Don't delete arguments of debug intrinsics

Langston Barrett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 25 17:24:02 PDT 2021


langston-barrett created this revision.
langston-barrett added a reviewer: aeubanks.
langston-barrett requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The argument reduction pass shouldn't remove arguments of debug
intrinsics, because the resulting module is ill-formed, and so
inherently uninteresting.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103129

Files:
  llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
  llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp


Index: llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
@@ -14,6 +14,7 @@
 #include "ReduceArguments.h"
 #include "Delta.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/Intrinsics.h"
 #include <set>
 #include <vector>
 
@@ -38,6 +39,16 @@
     }
 }
 
+/// Returns whether or not this function should be considered a candidate for
+/// argument removal. Currently, functions with no arguments and debug
+/// intrinsics are not considered. Debug intrinsics aren't considered because
+/// they must have exactly three arguments for the resulting module to be valid.
+static bool shouldRemoveArguments(const Function &F) {
+  const auto iid = F.getIntrinsicID();
+  return !F.arg_empty() && iid != Intrinsic::dbg_addr &&
+         iid != Intrinsic::dbg_declare && iid != Intrinsic::dbg_value;
+}
+
 /// Removes out-of-chunk arguments from functions, and modifies their calls
 /// accordingly. It also removes allocations of out-of-chunk arguments.
 static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
@@ -48,7 +59,7 @@
   std::vector<Function *> Funcs;
   // Get inside-chunk arguments, as well as their parent function
   for (auto &F : *Program)
-    if (!F.arg_empty()) {
+    if (shouldRemoveArguments(F)) {
       Funcs.push_back(&F);
       for (auto &A : F.args())
         if (O.shouldKeep())
@@ -108,7 +119,7 @@
   outs() << "Param Index Reference:\n";
   int ArgsCount = 0;
   for (auto &F : *Program)
-    if (!F.arg_empty()) {
+    if (shouldRemoveArguments(F)) {
       outs() << "  " << F.getName() << "\n";
       for (auto &A : F.args())
         outs() << "\t" << ++ArgsCount << ": " << A.getName() << "\n";
Index: llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
@@ -0,0 +1,10 @@
+; llvm-reduce shouldn't remove arguments of debug intrinsics, because the resulting module will be ill-formed.
+;
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments --test=opt --test-arg=-verify --test-arg=-disable-output --output=%t %s
+; RUN: cat %t | FileCheck %s
+; CHECK: declare void @llvm.dbg.addr(metadata, metadata, metadata)
+declare void @llvm.dbg.addr(metadata, metadata, metadata)
+; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata)
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata)
+declare void @llvm.dbg.value(metadata, metadata, metadata)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103129.347829.patch
Type: text/x-patch
Size: 2733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210526/88b5f08a/attachment.bin>


More information about the llvm-commits mailing list