diff --git a/llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll b/llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll new file mode 100644 index 0000000000000..fa4dba8551f10 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/remove-module-inline-asm.ll @@ -0,0 +1,11 @@ +; 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 4b37ff622bbfe..44818edc728ad 100644 --- a/llvm/tools/llvm-reduce/CMakeLists.txt +++ b/llvm/tools/llvm-reduce/CMakeLists.txt @@ -25,6 +25,7 @@ add_llvm_tool(llvm-reduce deltas/ReduceGlobalVars.cpp deltas/ReduceInstructions.cpp deltas/ReduceMetadata.cpp + deltas/ReduceModuleInlineAsm.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 797b6802d0e79..c336e3dd0e61b 100644 --- a/llvm/tools/llvm-reduce/DeltaManager.cpp +++ b/llvm/tools/llvm-reduce/DeltaManager.cpp @@ -25,6 +25,7 @@ #include "deltas/ReduceGlobalVars.h" #include "deltas/ReduceInstructions.h" #include "deltas/ReduceMetadata.h" +#include "deltas/ReduceModuleInlineAsm.h" #include "deltas/ReduceOperandBundles.h" #include "deltas/ReduceSpecialGlobals.h" @@ -45,6 +46,7 @@ void runDeltaPasses(TestRunner &Tester) { reduceInstructionsDeltaPass(Tester); reduceOperandBundesDeltaPass(Tester); reduceAttributesDeltaPass(Tester); + reduceModuleInlineAsmDeltaPass(Tester); // TODO: Implement the remaining Delta Passes } -} // namespace llvm \ No newline at end of file +} // namespace llvm diff --git a/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp b/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp new file mode 100644 index 0000000000000..b74bd0ae08dbd --- /dev/null +++ b/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.cpp @@ -0,0 +1,32 @@ +//===- 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/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h b/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h new file mode 100644 index 0000000000000..6d31c8f008d21 --- /dev/null +++ b/llvm/tools/llvm-reduce/deltas/ReduceModuleInlineAsm.h @@ -0,0 +1,18 @@ +//===- ReduceModuleInlineAsm.h --------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCE_MODULEINLINEASM_H +#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCE_MODULEINLINEASM_H + +#include "Delta.h" + +namespace llvm { +void reduceModuleInlineAsmDeltaPass(TestRunner &Test); +} // namespace llvm + +#endif 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 eb1492b6f03d1..018d2acbeb93a 100644 --- a/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn @@ -23,6 +23,7 @@ executable("llvm-reduce") { "deltas/ReduceGlobalVars.cpp", "deltas/ReduceInstructions.cpp", "deltas/ReduceMetadata.cpp", + "deltas/ReduceModuleInlineAsm.cpp", "deltas/ReduceOperandBundles.cpp", "deltas/ReduceSpecialGlobals.cpp", "llvm-reduce.cpp",