ReduceFunctionBodies.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "Utils.h"
  16. #include "llvm/IR/GlobalValue.h"
  17. #include "llvm/IR/Instructions.h"
  18. using namespace llvm;
  19. /// Removes all the bodies of defined functions that aren't inside any of the
  20. /// desired Chunks.
  21. static void extractFunctionBodiesFromModule(Oracle &O,
  22. ReducerWorkItem &WorkItem) {
  23. // Delete out-of-chunk function bodies
  24. for (auto &F : WorkItem.getModule()) {
  25. if (!F.isDeclaration() && !hasAliasUse(F) && !O.shouldKeep()) {
  26. F.deleteBody();
  27. F.setComdat(nullptr);
  28. }
  29. }
  30. }
  31. void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) {
  32. runDeltaPass(Test, extractFunctionBodiesFromModule,
  33. "Reducing Function Bodies");
  34. }
  35. static void reduceFunctionData(Oracle &O, ReducerWorkItem &WorkItem) {
  36. for (Function &F : WorkItem.getModule()) {
  37. if (F.hasPersonalityFn()) {
  38. if (none_of(F,
  39. [](const BasicBlock &BB) {
  40. return BB.isEHPad() || isa<ResumeInst>(BB.getTerminator());
  41. }) &&
  42. !O.shouldKeep()) {
  43. F.setPersonalityFn(nullptr);
  44. }
  45. }
  46. if (F.hasPrefixData() && !O.shouldKeep())
  47. F.setPrefixData(nullptr);
  48. if (F.hasPrologueData() && !O.shouldKeep())
  49. F.setPrologueData(nullptr);
  50. }
  51. }
  52. void llvm::reduceFunctionDataDeltaPass(TestRunner &Test) {
  53. runDeltaPass(Test, reduceFunctionData, "Reducing Function Data");
  54. }