1 //===- ReduceFunctions.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 in order
10 // to reduce function bodies in the provided Module.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "ReduceFunctionBodies.h"
15 #include "Delta.h"
16 #include "llvm/IR/GlobalValue.h"
17 
18 using namespace llvm;
19 
20 /// Removes all the bodies of defined functions that aren't inside any of the
21 /// desired Chunks.
extractFunctionBodiesFromModule(Oracle & O,Module & Program)22 static void extractFunctionBodiesFromModule(Oracle &O, Module &Program) {
23   // Delete out-of-chunk function bodies
24   std::vector<Function *> FuncDefsToReduce;
25   for (auto &F : Program)
26     if (!F.isDeclaration() && !O.shouldKeep()) {
27       F.deleteBody();
28       F.setComdat(nullptr);
29     }
30 }
31 
reduceFunctionBodiesDeltaPass(TestRunner & Test)32 void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) {
33   errs() << "*** Reducing Function Bodies...\n";
34   runDeltaPass(Test, extractFunctionBodiesFromModule);
35   errs() << "----------------------------\n";
36 }
37