ReduceSpecialGlobals.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 "Utils.h"
  19. #include "llvm/ADT/StringRef.h"
  20. #include "llvm/IR/Constants.h"
  21. #include "llvm/IR/GlobalValue.h"
  22. using namespace llvm;
  23. static StringRef SpecialGlobalNames[] = {"llvm.used", "llvm.compiler.used"};
  24. /// Removes all special globals aren't inside any of the
  25. /// desired Chunks.
  26. static void extractSpecialGlobalsFromModule(Oracle &O,
  27. ReducerWorkItem &WorkItem) {
  28. Module &Program = WorkItem.getModule();
  29. for (StringRef Name : SpecialGlobalNames) {
  30. if (auto *Used = Program.getNamedGlobal(Name)) {
  31. Used->replaceAllUsesWith(getDefaultValue(Used->getType()));
  32. Used->eraseFromParent();
  33. }
  34. }
  35. }
  36. void llvm::reduceSpecialGlobalsDeltaPass(TestRunner &Test) {
  37. runDeltaPass(Test, extractSpecialGlobalsFromModule,
  38. "Reducing Special Globals");
  39. }