ReduceAliases.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===- ReduceAliases.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 aliases in the provided Module.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "ReduceAliases.h"
  14. #include "Delta.h"
  15. #include "Utils.h"
  16. #include "llvm/IR/Constants.h"
  17. #include "llvm/IR/GlobalValue.h"
  18. #include "llvm/Transforms/Utils/ModuleUtils.h"
  19. using namespace llvm;
  20. /// Removes all aliases aren't inside any of the
  21. /// desired Chunks.
  22. static void extractAliasesFromModule(Oracle &O, ReducerWorkItem &Program) {
  23. for (auto &GA : make_early_inc_range(Program.getModule().aliases())) {
  24. if (!O.shouldKeep()) {
  25. GA.replaceAllUsesWith(GA.getAliasee());
  26. GA.eraseFromParent();
  27. }
  28. }
  29. }
  30. static void extractIFuncsFromModule(Oracle &O, Module &Program) {
  31. std::vector<GlobalIFunc *> IFuncs;
  32. for (GlobalIFunc &GI : Program.ifuncs()) {
  33. if (!O.shouldKeep())
  34. IFuncs.push_back(&GI);
  35. }
  36. if (!IFuncs.empty())
  37. lowerGlobalIFuncUsersAsGlobalCtor(Program, IFuncs);
  38. }
  39. void llvm::reduceAliasesDeltaPass(TestRunner &Test) {
  40. runDeltaPass(Test, extractAliasesFromModule, "Reducing Aliases");
  41. }
  42. void llvm::reduceIFuncsDeltaPass(TestRunner &Test) {
  43. runDeltaPass(Test, extractIFuncsFromModule, "Reducing Ifuncs");
  44. }