40 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "ReduceGlobalObjects.h"10#include "llvm/IR/GlobalObject.h"11 12using namespace llvm;13 14static bool shouldReduceSection(GlobalObject &GO) { return GO.hasSection(); }15 16static bool shouldReduceAlign(GlobalVariable *GV) {17 return GV->getAlign().has_value();18}19 20static bool shouldReduceAlign(Function *F) { return F->getAlign().has_value(); }21 22static bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); }23 24void llvm::reduceGlobalObjectsDeltaPass(Oracle &O, ReducerWorkItem &Program) {25 for (auto &GO : Program.getModule().global_objects()) {26 if (shouldReduceSection(GO) && !O.shouldKeep())27 GO.setSection("");28 if (auto *GV = dyn_cast<GlobalVariable>(&GO)) {29 if (shouldReduceAlign(GV) && !O.shouldKeep())30 GV->setAlignment(MaybeAlign());31 }32 if (auto *F = dyn_cast<Function>(&GO)) {33 if (shouldReduceAlign(F) && !O.shouldKeep())34 F->setAlignment(MaybeAlign());35 }36 if (shouldReduceComdat(GO) && !O.shouldKeep())37 GO.setComdat(nullptr);38 }39}40