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. extractInstrFromModule(Oracle & O,Module & Program)22static void extractInstrFromModule(Oracle &O, Module &Program) { 23 std::vector<Instruction *> InstsToDelete; 24 25 const DataLayout &DL = Program.getDataLayout(); 26 27 std::vector<Instruction *> InstToDelete; 28 for (auto &F : Program) { 29 for (auto &BB : F) { 30 for (auto &Inst : BB) { 31 if (O.shouldKeep()) 32 continue; 33 34 SimplifyQuery Q(DL, &Inst); 35 if (Value *Simplified = simplifyInstruction(&Inst, Q)) { 36 Inst.replaceAllUsesWith(Simplified); 37 InstToDelete.push_back(&Inst); 38 } 39 } 40 } 41 } 42 43 for (Instruction *I : InstToDelete) 44 I->eraseFromParent(); 45 } 46 simplifyInstructionsDeltaPass(TestRunner & Test)47void llvm::simplifyInstructionsDeltaPass(TestRunner &Test) { 48 outs() << "*** Simplifying Instructions...\n"; 49 runDeltaPass(Test, extractInstrFromModule); 50 } 51