diff --git a/llvm/docs/CommandGuide/opt.rst b/llvm/docs/CommandGuide/opt.rst --- a/llvm/docs/CommandGuide/opt.rst +++ b/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 ----------- diff --git a/llvm/test/Other/opt-strip-optnone.ll b/llvm/test/Other/opt-strip-optnone.ll new file mode 100644 --- /dev/null +++ b/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: } diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -280,6 +280,10 @@ PassPlugins("load-pass-plugin", cl::desc("Load passes from plugin library")); +static cl::opt 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);