[llvm-reduce] Remove various module data
authorArthur Eubanks <aeubanks@google.com>
Mon, 23 Aug 2021 17:58:16 +0000 (10:58 -0700)
committerArthur Eubanks <aeubanks@google.com>
Tue, 24 Aug 2021 16:45:31 +0000 (09:45 -0700)
This removes the data layout, target triple, source filename, and module
identifier when possible.

Reviewed By: swamulism

Differential Revision: https://reviews.llvm.org/D108568

llvm/test/tools/llvm-reduce/custom-delta-passes.ll
llvm/test/tools/llvm-reduce/remove-module-data.ll [new file with mode: 0644]
llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll [deleted file]
llvm/tools/llvm-reduce/CMakeLists.txt
llvm/tools/llvm-reduce/DeltaManager.cpp
llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp [new file with mode: 0644]
llvm/tools/llvm-reduce/deltas/ReduceModuleData.h [moved from llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h with 57% similarity]
llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp [deleted file]
llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn

index ef4ffda..7c36d52 100644 (file)
@@ -1,12 +1,12 @@
-; RUN: llvm-reduce --delta-passes=module-inline-asm --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: llvm-reduce --delta-passes=module-data --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
 ; RUN: FileCheck --check-prefix=CHECK-NOCHANGE %s < %t
 ; RUN: llvm-reduce --delta-passes=function-bodies --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
 ; RUN: FileCheck --check-prefix=CHECK-CHANGE %s < %t
-; RUN: llvm-reduce --delta-passes=function-bodies,module-inline-asm --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: llvm-reduce --delta-passes=function-bodies,module-data --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
 ; RUN: FileCheck --check-prefix=CHECK-CHANGE %s < %t
 
 ; RUN: not llvm-reduce --delta-passes=foo --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2>&1 | FileCheck %s --check-prefix=ERROR
-; RUN: not llvm-reduce --delta-passes='function-bodies;module-inline-asm' --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2>&1 | FileCheck %s --check-prefix=ERROR
+; RUN: not llvm-reduce --delta-passes='function-bodies;module-data' --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2>&1 | FileCheck %s --check-prefix=ERROR
 
 ; RUN: llvm-reduce --print-delta-passes --test FileCheck %s 2>&1 | FileCheck %s --check-prefix=PRINT
 
diff --git a/llvm/test/tools/llvm-reduce/remove-module-data.ll b/llvm/test/tools/llvm-reduce/remove-module-data.ll
new file mode 100644 (file)
index 0000000..b4b0fec
--- /dev/null
@@ -0,0 +1,28 @@
+; REQUIRES: x86-registered-target
+
+; RUN: opt %s -S | FileCheck --check-prefix=CHECK-FILE %s
+; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t
+
+; CHECK-INTERESTINGNESS: declare
+
+; CHECK-FILE: ModuleID
+; CHECK-FILE: source_filename
+; CHECK-FILE: datalayout
+; CHECK-FILE: triple
+; CHECK-FILE: module asm
+; CHECK-FILE: declare void @g
+
+; CHECK-FINAL-NOT: ModuleID
+; CHECK-FINAL-NOT: source_filename
+; CHECK-FINAL-NOT: datalayout
+; CHECK-FINAL-NOT: triple
+; CHECK-FINAL-NOT: module asm
+; CHECK-FINAL: declare void @g
+
+source_filename = "/tmp/a.cc"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+module asm "foo"
+
+declare void @g()
diff --git a/llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll b/llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll
deleted file mode 100644 (file)
index fa4dba8..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
-; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t
-
-; CHECK-INTERESTINGNESS: declare
-
-; CHECK-FINAL-NOT: module asm
-; CHECK-FINAL: declare void @g
-
-module asm "foo"
-
-declare void @g()
index 44818ed..e91c068 100644 (file)
@@ -25,7 +25,7 @@ add_llvm_tool(llvm-reduce
   deltas/ReduceGlobalVars.cpp
   deltas/ReduceInstructions.cpp
   deltas/ReduceMetadata.cpp
-  deltas/ReduceModuleInlineAsm.cpp
+  deltas/ReduceModuleData.cpp
   deltas/ReduceOperandBundles.cpp
   deltas/ReduceSpecialGlobals.cpp
   llvm-reduce.cpp
index 19e9913..664e59a 100644 (file)
@@ -25,7 +25,7 @@
 #include "deltas/ReduceGlobalVars.h"
 #include "deltas/ReduceInstructions.h"
 #include "deltas/ReduceMetadata.h"
-#include "deltas/ReduceModuleInlineAsm.h"
+#include "deltas/ReduceModuleData.h"
 #include "deltas/ReduceOperandBundles.h"
 #include "deltas/ReduceSpecialGlobals.h"
 #include "llvm/Support/CommandLine.h"
@@ -51,7 +51,7 @@ static cl::opt<std::string>
   DELTA_PASS("instructions", reduceInstructionsDeltaPass)                      \
   DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass)                  \
   DELTA_PASS("attributes", reduceAttributesDeltaPass)                          \
-  DELTA_PASS("module-inline-asm", reduceModuleInlineAsmDeltaPass)
+  DELTA_PASS("module-data", reduceModuleDataDeltaPass)
 
 static void runAllDeltaPasses(TestRunner &Tester) {
 #define DELTA_PASS(NAME, FUNC) FUNC(Tester);
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp
new file mode 100644 (file)
index 0000000..8aa3c5f
--- /dev/null
@@ -0,0 +1,36 @@
+//===- ReduceModuleData.cpp -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a reduce pass to reduce various module data.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ReduceModuleData.h"
+
+using namespace llvm;
+
+static void clearModuleData(std::vector<Chunk> ChunksToKeep, Module *Program) {
+  Oracle O(ChunksToKeep);
+
+  if (!O.shouldKeep())
+    Program->setModuleIdentifier("");
+  if (!O.shouldKeep())
+    Program->setSourceFileName("");
+  if (!O.shouldKeep())
+    Program->setDataLayout("");
+  if (!O.shouldKeep())
+    Program->setTargetTriple("");
+  // TODO: clear line by line rather than all at once
+  if (!O.shouldKeep())
+    Program->setModuleInlineAsm("");
+}
+
+void llvm::reduceModuleDataDeltaPass(TestRunner &Test) {
+  outs() << "*** Reducing Module Data...\n";
+  runDeltaPass(Test, 5, clearModuleData);
+}
@@ -1,4 +1,4 @@
-//===- ReduceModuleInlineAsm.h --------------------------------------------===//
+//===- ReduceModuleData.h --------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCE_MODULEINLINEASM_H
-#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCE_MODULEINLINEASM_H
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEMODULEDATA_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEMODULEDATA_H
 
 #include "Delta.h"
 
 namespace llvm {
-void reduceModuleInlineAsmDeltaPass(TestRunner &Test);
+void reduceModuleDataDeltaPass(TestRunner &Test);
 } // namespace llvm
 
 #endif
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp b/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp
deleted file mode 100644 (file)
index b74bd0a..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-//===- ReduceModuleInlineAsm.cpp ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements a function which calls the Generic Delta pass to reduce
-// module inline asm.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ReduceModuleInlineAsm.h"
-#include "llvm/IR/Constants.h"
-#include "llvm/IR/GlobalValue.h"
-
-using namespace llvm;
-
-static void clearModuleInlineAsm(std::vector<Chunk> ChunksToKeep,
-                                 Module *Program) {
-  Oracle O(ChunksToKeep);
-
-  // TODO: clear line by line rather than all at once
-  if (!O.shouldKeep())
-    Program->setModuleInlineAsm("");
-}
-
-void llvm::reduceModuleInlineAsmDeltaPass(TestRunner &Test) {
-  outs() << "*** Reducing Module Inline Asm...\n";
-  runDeltaPass(Test, 1, clearModuleInlineAsm);
-}
index 018d2ac..c0f0d84 100644 (file)
@@ -23,7 +23,7 @@ executable("llvm-reduce") {
     "deltas/ReduceGlobalVars.cpp",
     "deltas/ReduceInstructions.cpp",
     "deltas/ReduceMetadata.cpp",
-    "deltas/ReduceModuleInlineAsm.cpp",
+    "deltas/ReduceModuleData.cpp",
     "deltas/ReduceOperandBundles.cpp",
     "deltas/ReduceSpecialGlobals.cpp",
     "llvm-reduce.cpp",