[PATCH] D158815: [opt] Add option to strip optnone attribute

Aiden Grossman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 24 22:36:08 PDT 2023


aidengrossman created this revision.
Herald added a project: All.
aidengrossman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch adds in the -strip-optnone option to opt which allows for
stripping the optnone attribute from all functions in a module. I often
find myself dealing with bitcode from projects with arbitrary build
systems that have applied the optnone attribute for various reasons and
having the ability to do this in opt would be quite convenient. It's
possible to remove the attribute by disassembling to textual IR, running
sed, and then running opt over the result, but this option makes things
just a bit easier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158815

Files:
  llvm/docs/CommandGuide/opt.rst
  llvm/test/Other/opt-strip-optnone.ll
  llvm/tools/opt/opt.cpp


Index: llvm/tools/opt/opt.cpp
===================================================================
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -280,6 +280,10 @@
     PassPlugins("load-pass-plugin",
                 cl::desc("Load passes from plugin library"));
 
+static cl::opt<bool> StripOptnone(
+    "strip-optnone",
+    cl::desc("Strip the optnone attribute from all functions in the module."));
+
 //===----------------------------------------------------------------------===//
 // CodeGen-related helper functions.
 //
@@ -541,6 +545,12 @@
     return 1;
   }
 
+  if (StripOptnone) {
+    for (Function &F : *M) {
+      F.removeFnAttr(Attribute::AttrKind::OptimizeNone);
+    }
+  }
+
   // Strip debug info before running the verifier.
   if (StripDebug)
     StripDebugInfo(*M);
Index: llvm/test/Other/opt-strip-optnone.ll
===================================================================
--- /dev/null
+++ llvm/test/Other/opt-strip-optnone.ll
@@ -0,0 +1,9 @@
+; RUN: opt %s -strip-optnone -S | FileCheck %s
+
+define i64 @f1 (i64 %a) optnone noinline {
+  ret i64 %a 
+}
+
+; CHECK: define i64 @f1(i64 %a) {
+; CHECK:   ret i64 %a
+; CHECK: }
Index: llvm/docs/CommandGuide/opt.rst
===================================================================
--- llvm/docs/CommandGuide/opt.rst
+++ llvm/docs/CommandGuide/opt.rst
@@ -97,6 +97,11 @@
 
  Print all available passes and exit.
 
+.. option:: -strip-optnone
+
+ Strips the ``optnone`` attribute from all functions in the loaded module which
+ allows for function passes to run over all functions within the module.
+
 EXIT STATUS
 -----------
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158815.553362.patch
Type: text/x-patch
Size: 1624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230825/3c3b56f8/attachment.bin>


More information about the llvm-commits mailing list