1 //===- ReduceGlobalValues.cpp - Specialized Delta Pass --------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements a function which calls the Generic Delta pass to reduce
10 // global value attributes/specifiers.
12 //===----------------------------------------------------------------------===//
14 #include "ReduceGlobalValues.h"
15 #include "llvm/IR/GlobalValue.h"
19 static bool shouldReduceDSOLocal(GlobalValue
&GV
) {
20 return GV
.isDSOLocal() && !GV
.isImplicitDSOLocal();
23 static bool shouldReduceVisibility(GlobalValue
&GV
) {
24 return GV
.getVisibility() != GlobalValue::VisibilityTypes::DefaultVisibility
;
27 static bool shouldReduceUnnamedAddress(GlobalValue
&GV
) {
28 return GV
.getUnnamedAddr() != GlobalValue::UnnamedAddr::None
;
31 static bool shouldReduceDLLStorageClass(GlobalValue
&GV
) {
32 return GV
.getDLLStorageClass() !=
33 GlobalValue::DLLStorageClassTypes::DefaultStorageClass
;
36 static bool shouldReduceThreadLocal(GlobalValue
&GV
) {
37 return GV
.isThreadLocal();
40 static bool shouldReduceLinkage(GlobalValue
&GV
) {
41 return !GV
.hasExternalLinkage();
44 static void reduceGVs(Oracle
&O
, ReducerWorkItem
&Program
) {
45 for (auto &GV
: Program
.getModule().global_values()) {
46 if (shouldReduceDSOLocal(GV
) && !O
.shouldKeep())
47 GV
.setDSOLocal(false);
48 if (shouldReduceVisibility(GV
) && !O
.shouldKeep()) {
49 bool IsImplicitDSOLocal
= GV
.isImplicitDSOLocal();
50 GV
.setVisibility(GlobalValue::VisibilityTypes::DefaultVisibility
);
51 if (IsImplicitDSOLocal
)
52 GV
.setDSOLocal(false);
54 if (shouldReduceUnnamedAddress(GV
) && !O
.shouldKeep())
55 GV
.setUnnamedAddr(GlobalValue::UnnamedAddr::None
);
56 if (shouldReduceDLLStorageClass(GV
) && !O
.shouldKeep())
57 GV
.setDLLStorageClass(
58 GlobalValue::DLLStorageClassTypes::DefaultStorageClass
);
59 if (shouldReduceThreadLocal(GV
) && !O
.shouldKeep())
60 GV
.setThreadLocal(false);
61 if (shouldReduceLinkage(GV
) && !O
.shouldKeep()) {
62 bool IsImplicitDSOLocal
= GV
.isImplicitDSOLocal();
63 GV
.setLinkage(GlobalValue::ExternalLinkage
);
64 if (IsImplicitDSOLocal
)
65 GV
.setDSOLocal(false);
70 void llvm::reduceGlobalValuesDeltaPass(TestRunner
&Test
) {
71 runDeltaPass(Test
, reduceGVs
, "Reducing GlobalValues");