1 //===- ReduceModuleData.cpp -----------------------------------------------===// 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 reduce pass to reduce various module data. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "ReduceModuleData.h" 14 15 using namespace llvm; 16 17 static void clearModuleData(std::vector<Chunk> ChunksToKeep, Module *Program) { 18 Oracle O(ChunksToKeep); 19 20 if (!Program->getModuleIdentifier().empty() && !O.shouldKeep()) 21 Program->setModuleIdentifier(""); 22 if (!Program->getSourceFileName().empty() && !O.shouldKeep()) 23 Program->setSourceFileName(""); 24 if (!Program->getDataLayoutStr().empty() && !O.shouldKeep()) 25 Program->setDataLayout(""); 26 if (!Program->getTargetTriple().empty() && !O.shouldKeep()) 27 Program->setTargetTriple(""); 28 // TODO: clear line by line rather than all at once 29 if (!Program->getModuleInlineAsm().empty() && !O.shouldKeep()) 30 Program->setModuleInlineAsm(""); 31 } 32 33 static int countModuleData(Module *M) { 34 int Count = 0; 35 if (!M->getModuleIdentifier().empty()) 36 ++Count; 37 if (!M->getSourceFileName().empty()) 38 ++Count; 39 if (!M->getDataLayoutStr().empty()) 40 ++Count; 41 if (!M->getTargetTriple().empty()) 42 ++Count; 43 if (!M->getModuleInlineAsm().empty()) 44 ++Count; 45 return Count; 46 } 47 48 void llvm::reduceModuleDataDeltaPass(TestRunner &Test) { 49 outs() << "*** Reducing Module Data...\n"; 50 int Count = countModuleData(Test.getProgram()); 51 runDeltaPass(Test, Count, clearModuleData); 52 } 53