diff --git a/llvm/test/tools/llvm-reduce/custom-delta-passes.ll b/llvm/test/tools/llvm-reduce/custom-delta-passes.ll --- 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 --- /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 --- 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 --- a/llvm/tools/llvm-reduce/CMakeLists.txt +++ b/llvm/tools/llvm-reduce/CMakeLists.txt @@ -25,7 +25,7 @@ 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 --- 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 @@ 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/ReduceModuleInlineAsm.h b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.h rename from llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h rename to llvm/tools/llvm-reduce/deltas/ReduceModuleData.h --- 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/ReduceModuleData.cpp b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp new file mode 100644 --- /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 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.cpp b/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp deleted file mode 100644 --- 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 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 --- 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 @@ "deltas/ReduceGlobalVars.cpp", "deltas/ReduceInstructions.cpp", "deltas/ReduceMetadata.cpp", - "deltas/ReduceModuleInlineAsm.cpp", + "deltas/ReduceModuleData.cpp", "deltas/ReduceOperandBundles.cpp", "deltas/ReduceSpecialGlobals.cpp", "llvm-reduce.cpp",