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/Constants.h" 16 #include "llvm/IR/GlobalValue.h" 17 18 using namespace llvm; 19 20 /// Sets dso_local to false for all global values. 21 static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep, 22 Module *Program) { 23 Oracle O(ChunksToKeep); 24 25 // remove dso_local from global values 26 for (auto &GV : Program->global_values()) 27 if (GV.isDSOLocal() && !O.shouldKeep()) { 28 GV.setDSOLocal(false); 29 } 30 } 31 32 /// Counts the amount of global values with dso_local and displays their 33 /// respective name & index 34 static int countGVs(Module *Program) { 35 // TODO: Silence index with --quiet flag 36 outs() << "----------------------------\n"; 37 outs() << "GlobalValue Index Reference:\n"; 38 int GVCount = 0; 39 for (auto &GV : Program->global_values()) 40 if (GV.isDSOLocal()) 41 outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n"; 42 outs() << "----------------------------\n"; 43 return GVCount; 44 } 45 46 void llvm::reduceGlobalValuesDeltaPass(TestRunner &Test) { 47 outs() << "*** Reducing GlobalValues...\n"; 48 int GVCount = countGVs(Test.getProgram()); 49 runDeltaPass(Test, GVCount, extractGVsFromModule); 50 } 51