diff options
Diffstat (limited to 'llvm/tools/llvm-reduce')
-rw-r--r-- | llvm/tools/llvm-reduce/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/tools/llvm-reduce/DeltaManager.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp | 50 | ||||
-rw-r--r-- | llvm/tools/llvm-reduce/deltas/SimplifyInstructions.h | 18 |
4 files changed, 71 insertions, 0 deletions
diff --git a/llvm/tools/llvm-reduce/CMakeLists.txt b/llvm/tools/llvm-reduce/CMakeLists.txt index dccf147..fc478e6 100644 --- a/llvm/tools/llvm-reduce/CMakeLists.txt +++ b/llvm/tools/llvm-reduce/CMakeLists.txt @@ -43,6 +43,7 @@ add_llvm_tool(llvm-reduce deltas/ReduceIRReferences.cpp deltas/ReduceVirtualRegisters.cpp deltas/ReduceRegisterUses.cpp + deltas/SimplifyInstructions.cpp llvm-reduce.cpp DEPENDS diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp index 0d7d1a5..d947de8 100644 --- a/llvm/tools/llvm-reduce/DeltaManager.cpp +++ b/llvm/tools/llvm-reduce/DeltaManager.cpp @@ -38,6 +38,7 @@ #include "deltas/ReduceRegisterUses.h" #include "deltas/ReduceSpecialGlobals.h" #include "deltas/ReduceVirtualRegisters.h" +#include "deltas/SimplifyInstructions.h" #include "llvm/Support/CommandLine.h" using namespace llvm; @@ -62,6 +63,7 @@ static cl::opt<std::string> DELTA_PASS("metadata", reduceMetadataDeltaPass) \ DELTA_PASS("arguments", reduceArgumentsDeltaPass) \ DELTA_PASS("instructions", reduceInstructionsDeltaPass) \ + DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass) \ DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass) \ DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) \ DELTA_PASS("operands-undef", reduceOperandsUndefDeltaPass) \ diff --git a/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp b/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp new file mode 100644 index 0000000..6e2e52a --- /dev/null +++ b/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp @@ -0,0 +1,50 @@ +//===- SimplifyInstructions.cpp - Specialized Delta Pass ------------------===// +// +// 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 in order +// to simplify Instructions in defined functions. +// +//===----------------------------------------------------------------------===// + +#include "SimplifyInstructions.h" +#include "llvm/Analysis/InstructionSimplify.h" +#include "llvm/IR/Constants.h" + +using namespace llvm; + +/// Calls simplifyInstruction in each instruction in functions, and replaces +/// their values. +static void extractInstrFromModule(Oracle &O, Module &Program) { + std::vector<Instruction *> InstsToDelete; + + const DataLayout &DL = Program.getDataLayout(); + + std::vector<Instruction *> InstToDelete; + for (auto &F : Program) { + for (auto &BB : F) { + for (auto &Inst : BB) { + if (O.shouldKeep()) + continue; + + SimplifyQuery Q(DL, &Inst); + if (Value *Simplified = simplifyInstruction(&Inst, Q)) { + Inst.replaceAllUsesWith(Simplified); + InstToDelete.push_back(&Inst); + } + } + } + } + + for (Instruction *I : InstToDelete) + I->eraseFromParent(); +} + +void llvm::simplifyInstructionsDeltaPass(TestRunner &Test) { + outs() << "*** Simplifying Instructions...\n"; + runDeltaPass(Test, extractInstrFromModule); +} diff --git a/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.h b/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.h new file mode 100644 index 0000000..215cffc --- /dev/null +++ b/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.h @@ -0,0 +1,18 @@ +//===- SimplifyInstructions.h - Specialized Delta Pass ----------*- C++- *-===// +// +// 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_SIMPLIFYINSTRUCTIONS_H +#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_SIMPLIFYINSTRUCTIONS_H + +#include "Delta.h" + +namespace llvm { +void simplifyInstructionsDeltaPass(TestRunner &Test); +} // namespace llvm + +#endif |