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 | |
14 | static bool shouldReduceSection(GlobalObject &GO) { return GO.hasSection(); } |
15 | |
16 | static bool shouldReduceAlign(GlobalVariable *GV) { |
17 | return GV->getAlign().has_value(); |
18 | } |
19 | |
20 | static bool shouldReduceAlign(Function *F) { return F->getAlign().has_value(); } |
21 | |
22 | static bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); } |
23 | |
24 | void 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>(Val: &GO)) { |
29 | if (shouldReduceAlign(GV) && !O.shouldKeep()) |
30 | GV->setAlignment(MaybeAlign()); |
31 | } |
32 | if (auto *F = dyn_cast<Function>(Val: &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 |