brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 49a1870 Raw
51 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a function which calls the Generic Delta pass in order10// to reduce function bodies in the provided Module.11//12//===----------------------------------------------------------------------===//13 14#include "ReduceFunctionBodies.h"15#include "Utils.h"16#include "llvm/IR/Instructions.h"17 18using namespace llvm;19 20/// Removes all the bodies of defined functions that aren't inside any of the21/// desired Chunks.22void llvm::reduceFunctionBodiesDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {23  // Delete out-of-chunk function bodies24  for (auto &F : WorkItem.getModule()) {25    if (!F.isDeclaration() && !hasAliasUse(F) && !O.shouldKeep()) {26      F.deleteBody();27      F.setComdat(nullptr);28    }29  }30}31 32void llvm::reduceFunctionDataDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {33  for (Function &F : WorkItem.getModule()) {34    if (F.hasPersonalityFn()) {35      if (none_of(F,36                  [](const BasicBlock &BB) {37                    return BB.isEHPad() || isa<ResumeInst>(BB.getTerminator());38                  }) &&39          !O.shouldKeep()) {40        F.setPersonalityFn(nullptr);41      }42    }43 44    if (F.hasPrefixData() && !O.shouldKeep())45      F.setPrefixData(nullptr);46 47    if (F.hasPrologueData() && !O.shouldKeep())48      F.setPrologueData(nullptr);49  }50}51