[llvm] d2e1036 - [llvm-reduce] Remove various module data

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 09:45:48 PDT 2021


Author: Arthur Eubanks
Date: 2021-08-24T09:45:31-07:00
New Revision: d2e103644be383493fe1dcbcc45547b592de2fb6

URL: https://github.com/llvm/llvm-project/commit/d2e103644be383493fe1dcbcc45547b592de2fb6
DIFF: https://github.com/llvm/llvm-project/commit/d2e103644be383493fe1dcbcc45547b592de2fb6.diff

LOG: [llvm-reduce] Remove various module data

This removes the data layout, target triple, source filename, and module
identifier when possible.

Reviewed By: swamulism

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

Added: 
    llvm/test/tools/llvm-reduce/remove-module-data.ll
    llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp
    llvm/tools/llvm-reduce/deltas/ReduceModuleData.h

Modified: 
    llvm/test/tools/llvm-reduce/custom-delta-passes.ll
    llvm/tools/llvm-reduce/CMakeLists.txt
    llvm/tools/llvm-reduce/DeltaManager.cpp
    llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn

Removed: 
    llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll
    llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp
    llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/custom-delta-passes.ll b/llvm/test/tools/llvm-reduce/custom-delta-passes.ll
index ef4ffdaf65bfd..7c36d52e8885e 100644
--- a/llvm/test/tools/llvm-reduce/custom-delta-passes.ll
+++ b/llvm/test/tools/llvm-reduce/custom-delta-passes.ll
@@ -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
index 0000000000000..b4b0fec8bee35
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/remove-module-data.ll
@@ -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
index fa4dba8551f10..0000000000000
--- a/llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll
+++ /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()

diff  --git a/llvm/tools/llvm-reduce/CMakeLists.txt b/llvm/tools/llvm-reduce/CMakeLists.txt
index 44818edc728ad..e91c068d0a001 100644
--- a/llvm/tools/llvm-reduce/CMakeLists.txt
+++ b/llvm/tools/llvm-reduce/CMakeLists.txt
@@ -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

diff  --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index 19e99131935d4..664e59af1ce9e 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -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
index 0000000000000..8aa3c5ff8860b
--- /dev/null
+++ b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp
@@ -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);
+}

diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.h
similarity index 57%
rename from llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h
rename to llvm/tools/llvm-reduce/deltas/ReduceModuleData.h
index 6d31c8f008d21..972c53460d760 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h
+++ b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.h
@@ -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
index b74bd0ae08dbd..0000000000000
--- a/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp
+++ /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);
-}

diff  --git a/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn b/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn
index 018d2acbeb93a..c0f0d844a1d68 100644
--- a/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn
@@ -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",


        


More information about the llvm-commits mailing list