diff --git a/llvm/test/tools/llvm-reduce/inline-calls.ll b/llvm/test/tools/llvm-reduce/inline-calls.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/inline-calls.ll @@ -0,0 +1,21 @@ +; RUN: llvm-reduce --delta-passes=inline-calls --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t +; RUN: FileCheck --check-prefixes=CHECK-FINAL --input-file=%t %s + +; CHECK-INTERESTINGNESS: define i32 @fn1 +; CHECK-INTERESTINGNESS: define i32 @fn2 + +; CHECK-FINAL-NOT: call i32 +; CHECK-FINAL: @fn1 +; CHECK-FINAL: add +; CHECK-FINAL: @fn2 +; CHECK-FINAL: add + +define i32 @fn1(i32 %a) { + %b = call i32 @fn2(i32 %a) + ret i32 %b +} + +define i32 @fn2(i32 %a) { + %b = add i32 %a, 1 + ret i32 %b +} 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 @@ -24,6 +24,7 @@ TestRunner.cpp deltas/Delta.cpp deltas/Utils.cpp + deltas/InlineCalls.cpp deltas/ReduceAliases.cpp deltas/ReduceArguments.cpp deltas/ReduceAttributes.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 @@ -15,6 +15,7 @@ #include "ReducerWorkItem.h" #include "TestRunner.h" #include "deltas/Delta.h" +#include "deltas/InlineCalls.h" #include "deltas/ReduceAliases.h" #include "deltas/ReduceArguments.h" #include "deltas/ReduceAttributes.h" @@ -88,6 +89,7 @@ DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass) \ DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \ DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass) \ + DELTA_PASS("inline-calls", inlineCallsDeltaPass) \ DELTA_PASS("attributes", reduceAttributesDeltaPass) \ DELTA_PASS("module-data", reduceModuleDataDeltaPass) \ DELTA_PASS("opcodes", reduceOpcodesDeltaPass) \ diff --git a/llvm/tools/llvm-reduce/deltas/InlineCalls.h b/llvm/tools/llvm-reduce/deltas/InlineCalls.h new file mode 100644 --- /dev/null +++ b/llvm/tools/llvm-reduce/deltas/InlineCalls.h @@ -0,0 +1,18 @@ +//===- InlineCalls.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_INLINECALLS_H +#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_INLINECALLS_H + +#include "Delta.h" + +namespace llvm { +void inlineCallsDeltaPass(TestRunner &Test); +} // namespace llvm + +#endif diff --git a/llvm/tools/llvm-reduce/deltas/InlineCalls.cpp b/llvm/tools/llvm-reduce/deltas/InlineCalls.cpp new file mode 100644 --- /dev/null +++ b/llvm/tools/llvm-reduce/deltas/InlineCalls.cpp @@ -0,0 +1,41 @@ +//===- InlineCalls.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 +// +//===----------------------------------------------------------------------===// + +#include "InlineCalls.h" +#include "Delta.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/Transforms/Utils/Cloning.h" + +using namespace llvm; + +/// Removes all aliases aren't inside any of the +/// desired Chunks. +static void inlineCalls(Oracle &O, Module &Program) { + std::vector CBs; + for (Function &F : Program.functions()) { + for (Instruction &I : instructions(F)) { + if (auto *CB = dyn_cast(&I); CB && !CB->isIndirectCall()) { + if (!O.shouldKeep()) + CBs.push_back(CB); + } + } + } + for (auto *CB : CBs) { + InlineFunctionInfo IFI; + // There are various cases where inlining can fail; we don't want to copy + // all those conditions here to check beforehand if inlining will fail, so + // *shrug* if some fail. + InlineFunction(*CB, IFI); + } +} + +void llvm::inlineCallsDeltaPass(TestRunner &Test) { + errs() << "*** Inlining calls ...\n"; + runDeltaPass(Test, inlineCalls); + errs() << "----------------------------\n"; +} 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 @@ -16,6 +16,7 @@ "ReducerWorkItem.cpp", "TestRunner.cpp", "deltas/Delta.cpp", + "deltas/InlineCalls.cpp", "deltas/ReduceAliases.cpp", "deltas/ReduceArguments.cpp", "deltas/ReduceAttributes.cpp",