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