xref: /openbsd-src/gnu/llvm/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp (revision d415bd752c734aee168c4ee86ff32e8cc249eb16)
173471bf0Spatrick //===- ReduceGlobalVars.cpp - Specialized Delta Pass ----------------------===//
273471bf0Spatrick //
373471bf0Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
473471bf0Spatrick // See https://llvm.org/LICENSE.txt for license information.
573471bf0Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
673471bf0Spatrick //
773471bf0Spatrick //===----------------------------------------------------------------------===//
873471bf0Spatrick //
973471bf0Spatrick // This file implements a function which calls the Generic Delta pass in order
1073471bf0Spatrick // to reduce initializers of Global Variables in the provided Module.
1173471bf0Spatrick //
1273471bf0Spatrick //===----------------------------------------------------------------------===//
1373471bf0Spatrick 
1473471bf0Spatrick #include "ReduceGlobalVarInitializers.h"
1573471bf0Spatrick #include "llvm/IR/Constants.h"
1673471bf0Spatrick #include "llvm/IR/GlobalValue.h"
1773471bf0Spatrick 
1873471bf0Spatrick using namespace llvm;
1973471bf0Spatrick 
2073471bf0Spatrick /// Removes all the Initialized GVs that aren't inside the desired Chunks.
extractGVsFromModule(Oracle & O,ReducerWorkItem & WorkItem)21*d415bd75Srobert static void extractGVsFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
2273471bf0Spatrick   // Drop initializers of out-of-chunk GVs
23*d415bd75Srobert   for (auto &GV : WorkItem.getModule().globals())
2473471bf0Spatrick     if (GV.hasInitializer() && !O.shouldKeep()) {
2573471bf0Spatrick       GV.setInitializer(nullptr);
2673471bf0Spatrick       GV.setLinkage(GlobalValue::LinkageTypes::ExternalLinkage);
2773471bf0Spatrick       GV.setComdat(nullptr);
2873471bf0Spatrick     }
2973471bf0Spatrick }
3073471bf0Spatrick 
reduceGlobalsInitializersDeltaPass(TestRunner & Test)3173471bf0Spatrick void llvm::reduceGlobalsInitializersDeltaPass(TestRunner &Test) {
32*d415bd75Srobert   runDeltaPass(Test, extractGVsFromModule, "Reducing GV Initializers");
3373471bf0Spatrick }
34