180ba72b0SArthur Eubanks //===- ReduceGlobalObjects.cpp --------------------------------------------===// 280ba72b0SArthur Eubanks // 380ba72b0SArthur Eubanks // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 480ba72b0SArthur Eubanks // See https://llvm.org/LICENSE.txt for license information. 580ba72b0SArthur Eubanks // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 680ba72b0SArthur Eubanks // 780ba72b0SArthur Eubanks //===----------------------------------------------------------------------===// 880ba72b0SArthur Eubanks 980ba72b0SArthur Eubanks #include "ReduceGlobalObjects.h" 1080ba72b0SArthur Eubanks #include "llvm/IR/GlobalObject.h" 1180ba72b0SArthur Eubanks 1280ba72b0SArthur Eubanks using namespace llvm; 1380ba72b0SArthur Eubanks shouldReduceSection(GlobalObject & GO)1480ba72b0SArthur Eubanksstatic bool shouldReduceSection(GlobalObject &GO) { return GO.hasSection(); } 1580ba72b0SArthur Eubanks shouldReduceAlign(GlobalObject & GO)1680ba72b0SArthur Eubanksstatic bool shouldReduceAlign(GlobalObject &GO) { 17064a08cdSKazu Hirata return GO.getAlign().has_value(); 1880ba72b0SArthur Eubanks } 1980ba72b0SArthur Eubanks shouldReduceComdat(GlobalObject & GO)206ae63c90SArthur Eubanksstatic bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); } 216ae63c90SArthur Eubanks reduceGOs(Oracle & O,ReducerWorkItem & Program)22*23cc36e4SMatt Arsenaultstatic void reduceGOs(Oracle &O, ReducerWorkItem &Program) { 23*23cc36e4SMatt Arsenault for (auto &GO : Program.getModule().global_objects()) { 2480ba72b0SArthur Eubanks if (shouldReduceSection(GO) && !O.shouldKeep()) 2580ba72b0SArthur Eubanks GO.setSection(""); 2680ba72b0SArthur Eubanks if (shouldReduceAlign(GO) && !O.shouldKeep()) 2780ba72b0SArthur Eubanks GO.setAlignment(MaybeAlign()); 286ae63c90SArthur Eubanks if (shouldReduceComdat(GO) && !O.shouldKeep()) 296ae63c90SArthur Eubanks GO.setComdat(nullptr); 3080ba72b0SArthur Eubanks } 3180ba72b0SArthur Eubanks } 3280ba72b0SArthur Eubanks reduceGlobalObjectsDeltaPass(TestRunner & Test)3380ba72b0SArthur Eubanksvoid llvm::reduceGlobalObjectsDeltaPass(TestRunner &Test) { 342592ccdeSArthur Eubanks runDeltaPass(Test, reduceGOs, "Reducing GlobalObjects"); 3580ba72b0SArthur Eubanks } 36