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 shouldReduceDSOLocal(GlobalValue & GV)19static bool shouldReduceDSOLocal(GlobalValue &GV) { 20 return GV.isDSOLocal() && !GV.isImplicitDSOLocal(); 21 } 22 shouldReduceVisibility(GlobalValue & GV)23static bool shouldReduceVisibility(GlobalValue &GV) { 24 return GV.getVisibility() != GlobalValue::VisibilityTypes::DefaultVisibility; 25 } 26 shouldReduceUnnamedAddress(GlobalValue & GV)27static bool shouldReduceUnnamedAddress(GlobalValue &GV) { 28 return GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None; 29 } 30 shouldReduceDLLStorageClass(GlobalValue & GV)31static bool shouldReduceDLLStorageClass(GlobalValue &GV) { 32 return GV.getDLLStorageClass() != 33 GlobalValue::DLLStorageClassTypes::DefaultStorageClass; 34 } 35 shouldReduceThreadLocal(GlobalValue & GV)36static bool shouldReduceThreadLocal(GlobalValue &GV) { 37 return GV.isThreadLocal(); 38 } 39 reduceGVs(Oracle & O,ReducerWorkItem & Program)40static 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 reduceGlobalValuesDeltaPass(TestRunner & Test)60void llvm::reduceGlobalValuesDeltaPass(TestRunner &Test) { 61 runDeltaPass(Test, reduceGVs, "Reducing GlobalValues"); 62 } 63