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