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