| 1 | //===- SimplifyInstructions.cpp - Specialized Delta Pass ------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements a function which calls the Generic Delta pass in order |
| 10 | // to simplify Instructions in defined functions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SimplifyInstructions.h" |
| 15 | #include "llvm/Analysis/InstructionSimplify.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | /// Calls simplifyInstruction in each instruction in functions, and replaces |
| 20 | /// their values. |
| 21 | void llvm::simplifyInstructionsDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) { |
| 22 | Module &Program = WorkItem.getModule(); |
| 23 | const DataLayout &DL = Program.getDataLayout(); |
| 24 | |
| 25 | for (auto &F : Program) { |
| 26 | for (auto &BB : F) { |
| 27 | for (auto &Inst : make_early_inc_range(Range&: BB)) { |
| 28 | SimplifyQuery Q(DL, &Inst); |
| 29 | if (Value *Simplified = simplifyInstruction(I: &Inst, Q)) { |
| 30 | if (O.shouldKeep()) |
| 31 | continue; |
| 32 | Inst.replaceAllUsesWith(V: Simplified); |
| 33 | Inst.eraseFromParent(); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 |