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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ReduceGlobalObjects.h"
10 #include "llvm/IR/GlobalObject.h"
11 
12 using namespace llvm;
13 
shouldReduceSection(GlobalObject & GO)14 static bool shouldReduceSection(GlobalObject &GO) { return GO.hasSection(); }
15 
shouldReduceAlign(GlobalObject & GO)16 static bool shouldReduceAlign(GlobalObject &GO) {
17   return GO.getAlign().has_value();
18 }
19 
reduceGOs(Oracle & O,Module & Program)20 static void reduceGOs(Oracle &O, Module &Program) {
21   for (auto &GO : Program.global_objects()) {
22     if (shouldReduceSection(GO) && !O.shouldKeep())
23       GO.setSection("");
24     if (shouldReduceAlign(GO) && !O.shouldKeep())
25       GO.setAlignment(MaybeAlign());
26   }
27 }
28 
reduceGlobalObjectsDeltaPass(TestRunner & Test)29 void llvm::reduceGlobalObjectsDeltaPass(TestRunner &Test) {
30   outs() << "*** Reducing GlobalObjects...\n";
31   runDeltaPass(Test, reduceGOs);
32 }
33