ReduceGlobalVarInitializers.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. //===- ReduceGlobalVars.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 initializers of Global Variables in the provided Module.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "ReduceGlobalVarInitializers.h"
  14. #include "llvm/IR/Constants.h"
  15. #include "llvm/IR/GlobalValue.h"
  16. using namespace llvm;
  17. /// Removes all the Initialized GVs that aren't inside the desired Chunks.
  18. static void extractGVsFromModule(Oracle &O, Module &Program) {
  19. // Drop initializers of out-of-chunk GVs
  20. for (auto &GV : Program.globals())
  21. if (GV.hasInitializer() && !O.shouldKeep()) {
  22. GV.setInitializer(nullptr);
  23. GV.setLinkage(GlobalValue::LinkageTypes::ExternalLinkage);
  24. GV.setComdat(nullptr);
  25. }
  26. }
  27. void llvm::reduceGlobalsInitializersDeltaPass(TestRunner &Test) {
  28. outs() << "*** Reducing GVs initializers...\n";
  29. runDeltaPass(Test, extractGVsFromModule);
  30. }