SimplifyInstructions.cpp 1.6 KB

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