| 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 "Utils.h" |
| 17 |
#include "llvm/IR/GlobalValue.h" |
| 18 |
#include "llvm/IR/Instructions.h" |
| 19 |
|
| 20 |
using namespace llvm; |
| 21 |
|
| 22 |
/// Removes all the bodies of defined functions that aren't inside any of the |
| 23 |
/// desired Chunks. |
| 24 |
static void extractFunctionBodiesFromModule(Oracle &O, |
| 25 |
ReducerWorkItem &WorkItem) { |
| 26 |
// Delete out-of-chunk function bodies |
| 27 |
for (auto &F : WorkItem.getModule()) { |
| 28 |
if (!F.isDeclaration() && !hasAliasUse(F) && !O.shouldKeep()) { |
| 29 |
F.deleteBody(); |
| 30 |
F.setComdat(nullptr); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) { |
| 36 |
runDeltaPass(Test, extractFunctionBodiesFromModule, |
| 37 |
"Reducing Function Bodies"); |
| 38 |
} |
| 39 |
|
| 40 |
static void reduceFunctionData(Oracle &O, ReducerWorkItem &WorkItem) { |
| 41 |
for (Function &F : WorkItem.getModule()) { |
| 42 |
if (F.hasPersonalityFn()) { |
| 43 |
if (none_of(F, |
| 44 |
[](const BasicBlock &BB) { |
| 45 |
return BB.isEHPad() || isa<ResumeInst>(BB.getTerminator()); |
| 46 |
}) && |
| 47 |
!O.shouldKeep()) { |
| 48 |
F.setPersonalityFn(nullptr); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if (F.hasPrefixData() && !O.shouldKeep()) |
| 53 |
F.setPrefixData(nullptr); |
| 54 |
|
| 55 |
if (F.hasPrologueData() && !O.shouldKeep()) |
| 56 |
F.setPrologueData(nullptr); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
void llvm::reduceFunctionDataDeltaPass(TestRunner &Test) { |
| 61 |
runDeltaPass(Test, reduceFunctionData, "Reducing Function Data"); |
| 62 |
} |