ReduceSpecialGlobals.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //===- ReduceSpecialGlobals.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 special globals, like @llvm.used, in the provided Module.
  11. //
  12. // For more details about special globals, see
  13. // https://llvm.org/docs/LangRef.html#intrinsic-global-variables
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #include "ReduceSpecialGlobals.h"
  17. #include "Delta.h"
  18. #include "llvm/ADT/StringRef.h"
  19. #include "llvm/IR/Constants.h"
  20. #include "llvm/IR/GlobalValue.h"
  21. using namespace llvm;
  22. static StringRef SpecialGlobalNames[] = {"llvm.used", "llvm.compiler.used"};
  23. /// Removes all special globals aren't inside any of the
  24. /// desired Chunks.
  25. static void extractSpecialGlobalsFromModule(Oracle &O, Module &Program) {
  26. for (StringRef Name : SpecialGlobalNames) {
  27. if (auto *Used = Program.getNamedGlobal(Name)) {
  28. Used->replaceAllUsesWith(UndefValue::get(Used->getType()));
  29. Used->eraseFromParent();
  30. }
  31. }
  32. }
  33. void llvm::reduceSpecialGlobalsDeltaPass(TestRunner &Test) {
  34. errs() << "*** Reducing Special Globals ...\n";
  35. runDeltaPass(Test, extractSpecialGlobalsFromModule);
  36. errs() << "----------------------------\n";
  37. }