ReduceFunctionBodies.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //===- ReduceFunctions.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 reduce function bodies in the provided Module.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "ReduceFunctionBodies.h"
  14. #include "Delta.h"
  15. #include "llvm/IR/GlobalValue.h"
  16. using namespace llvm;
  17. /// Removes all the bodies of defined functions that aren't inside any of the
  18. /// desired Chunks.
  19. static void extractFunctionBodiesFromModule(Oracle &O, Module &Program) {
  20. // Delete out-of-chunk function bodies
  21. std::vector<Function *> FuncDefsToReduce;
  22. for (auto &F : Program)
  23. if (!F.isDeclaration() && !O.shouldKeep()) {
  24. F.deleteBody();
  25. F.setComdat(nullptr);
  26. }
  27. }
  28. void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) {
  29. errs() << "*** Reducing Function Bodies...\n";
  30. runDeltaPass(Test, extractFunctionBodiesFromModule);
  31. errs() << "----------------------------\n";
  32. }