[llvm] r333860 - [opt] Add a -strip-module-flags option
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 3 17:11:48 PDT 2018
Author: vedantk
Date: Sun Jun 3 17:11:48 2018
New Revision: 333860
URL: http://llvm.org/viewvc/llvm-project?rev=333860&view=rev
Log:
[opt] Add a -strip-module-flags option
The -strip-module-flags option strips llvm.module.flags metadata from a
module at the beginning of the opt pipeline.
This will be used to test whether the output of a pass is debug info
(DI) invariant.
E.g, after applying synthetic debug info to a test case, we'd like to
strip out all DI-related metadata and check that the final IR is
identical to a baseline file without any DI applied, to check that
optimizations aren't inhibited by debug info.
Added:
llvm/trunk/test/DebugInfo/strip-module-flags.ll
Modified:
llvm/trunk/tools/opt/opt.cpp
Added: llvm/trunk/test/DebugInfo/strip-module-flags.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/strip-module-flags.ll?rev=333860&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/strip-module-flags.ll (added)
+++ llvm/trunk/test/DebugInfo/strip-module-flags.ll Sun Jun 3 17:11:48 2018
@@ -0,0 +1,7 @@
+; RUN: opt -strip-module-flags < %s -S -o - | FileCheck %s
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+
+; CHECK-NOT: llvm.module.flags
+; CHECK-NOT: Debug Info Version
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=333860&r1=333859&r2=333860&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Sun Jun 3 17:11:48 2018
@@ -121,6 +121,9 @@ static cl::opt<bool>
StripDebug("strip-debug",
cl::desc("Strip debugger symbol info from translation unit"));
+static cl::opt<bool> StripModuleFlags("strip-module-flags",
+ cl::desc("Strip module flags metadata"));
+
static cl::opt<bool>
DisableInline("disable-inlining", cl::desc("Do not run the inliner pass"));
@@ -500,6 +503,11 @@ int main(int argc, char **argv) {
if (StripDebug)
StripDebugInfo(*M);
+ // Erase module flags metadata, if requested.
+ if (StripModuleFlags)
+ if (NamedMDNode *ModFlags = M->getModuleFlagsMetadata())
+ M->eraseNamedMetadata(ModFlags);
+
// If we are supposed to override the target triple or data layout, do so now.
if (!TargetTriple.empty())
M->setTargetTriple(Triple::normalize(TargetTriple));
More information about the llvm-commits
mailing list