Debian Codegraph @

llvm-project/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp

raw
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 #include "llvm/IR/Constants.h"
17
18 using namespace llvm;
19
20 /// Calls simplifyInstruction in each instruction in functions, and replaces
21 /// their values.
22 static void extractInstrFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
23 std::vector<Instruction *> InstsToDelete;
24
25 Module &Program = WorkItem.getModule();
26 const DataLayout &DL = Program.getDataLayout();
27
28 std::vector<Instruction *> InstToDelete;
29 for (auto &F : Program) {
30 for (auto &BB : F) {
31 for (auto &Inst : BB) {
32
33 SimplifyQuery Q(DL, &Inst);
34 if (Value *Simplified = simplifyInstruction(&Inst, Q)) {
35 if (O.shouldKeep())
36 continue;
37 Inst.replaceAllUsesWith(Simplified);
38 InstToDelete.push_back(&Inst);
39 }
40 }
41 }
42 }
43
44 for (Instruction *I : InstToDelete)
45 I->eraseFromParent();
46 }
47
48 void llvm::simplifyInstructionsDeltaPass(TestRunner &Test) {
49 runDeltaPass(Test, extractInstrFromModule, "Simplifying Instructions");
50 }