ReduceGlobalObjects.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //===- ReduceGlobalObjects.cpp --------------------------------------------===//
  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. #include "ReduceGlobalObjects.h"
  9. #include "llvm/IR/GlobalObject.h"
  10. using namespace llvm;
  11. static bool shouldReduceSection(GlobalObject &GO) { return GO.hasSection(); }
  12. static bool shouldReduceAlign(GlobalObject &GO) {
  13. return GO.getAlign().has_value();
  14. }
  15. static bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); }
  16. static void reduceGOs(Oracle &O, ReducerWorkItem &Program) {
  17. for (auto &GO : Program.getModule().global_objects()) {
  18. if (shouldReduceSection(GO) && !O.shouldKeep())
  19. GO.setSection("");
  20. if (shouldReduceAlign(GO) && !O.shouldKeep())
  21. GO.setAlignment(MaybeAlign());
  22. if (shouldReduceComdat(GO) && !O.shouldKeep())
  23. GO.setComdat(nullptr);
  24. }
  25. }
  26. void llvm::reduceGlobalObjectsDeltaPass(TestRunner &Test) {
  27. runDeltaPass(Test, reduceGOs, "Reducing GlobalObjects");
  28. }