ReduceGlobalValues.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===- ReduceGlobalValues.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 to reduce
  10. // global value attributes/specifiers.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "ReduceGlobalValues.h"
  14. #include "llvm/IR/GlobalValue.h"
  15. using namespace llvm;
  16. static bool shouldReduceDSOLocal(GlobalValue &GV) {
  17. return GV.isDSOLocal() && !GV.isImplicitDSOLocal();
  18. }
  19. static bool shouldReduceVisibility(GlobalValue &GV) {
  20. return GV.getVisibility() != GlobalValue::VisibilityTypes::DefaultVisibility;
  21. }
  22. static bool shouldReduceUnnamedAddress(GlobalValue &GV) {
  23. return GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None;
  24. }
  25. static bool shouldReduceDLLStorageClass(GlobalValue &GV) {
  26. return GV.getDLLStorageClass() !=
  27. GlobalValue::DLLStorageClassTypes::DefaultStorageClass;
  28. }
  29. static bool shouldReduceThreadLocal(GlobalValue &GV) {
  30. return GV.isThreadLocal();
  31. }
  32. static void reduceGVs(Oracle &O, Module &Program) {
  33. for (auto &GV : Program.global_values()) {
  34. if (shouldReduceDSOLocal(GV) && !O.shouldKeep())
  35. GV.setDSOLocal(false);
  36. if (shouldReduceVisibility(GV) && !O.shouldKeep()) {
  37. bool IsImplicitDSOLocal = GV.isImplicitDSOLocal();
  38. GV.setVisibility(GlobalValue::VisibilityTypes::DefaultVisibility);
  39. if (IsImplicitDSOLocal)
  40. GV.setDSOLocal(false);
  41. }
  42. if (shouldReduceUnnamedAddress(GV) && !O.shouldKeep())
  43. GV.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
  44. if (shouldReduceDLLStorageClass(GV) && !O.shouldKeep())
  45. GV.setDLLStorageClass(
  46. GlobalValue::DLLStorageClassTypes::DefaultStorageClass);
  47. if (shouldReduceThreadLocal(GV) && !O.shouldKeep())
  48. GV.setThreadLocal(false);
  49. }
  50. }
  51. void llvm::reduceGlobalValuesDeltaPass(TestRunner &Test) {
  52. outs() << "*** Reducing GlobalValues...\n";
  53. runDeltaPass(Test, reduceGVs);
  54. }