32 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a function which calls the Generic Delta pass in order10// to reduce initializers of Global Variables in the provided Module.11//12//===----------------------------------------------------------------------===//13 14#include "ReduceGlobalVarInitializers.h"15#include "llvm/IR/GlobalValue.h"16#include "llvm/IR/Value.h"17#include "llvm/Transforms/Utils/Cloning.h"18 19using namespace llvm;20 21/// Removes all the Initialized GVs that aren't inside the desired Chunks.22void llvm::reduceGlobalsInitializersDeltaPass(Oracle &O,23 ReducerWorkItem &WorkItem) {24 // Drop initializers of out-of-chunk GVs25 for (auto &GV : WorkItem.getModule().globals())26 if (GV.hasInitializer() && !O.shouldKeep()) {27 GV.setInitializer(nullptr);28 GV.setLinkage(GlobalValue::LinkageTypes::ExternalLinkage);29 GV.setComdat(nullptr);30 }31}32