brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 19b69e8 Raw
51 lines · cpp
1//===- ReduceInstructions.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 uninteresting Instructions from defined functions.11//12//===----------------------------------------------------------------------===//13 14#include "ReduceInstructions.h"15#include "Utils.h"16#include "llvm/IR/Constants.h"17#include "llvm/IR/Instructions.h"18 19using namespace llvm;20 21/// Filter out cases where deleting the instruction will likely cause the22/// user/def of the instruction to fail the verifier.23//24// TODO: Technically the verifier only enforces preallocated token usage and25// there is a none token.26static bool shouldAlwaysKeep(const Instruction &I) {27  return I.isEHPad() || I.getType()->isTokenTy() || I.isSwiftError();28}29 30/// Removes out-of-chunk arguments from functions, and modifies their calls31/// accordingly. It also removes allocations of out-of-chunk arguments.32void llvm::reduceInstructionsDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {33  Module &Program = WorkItem.getModule();34 35  for (auto &F : Program) {36    for (auto &BB : F) {37      // Removing the terminator would make the block invalid. Only iterate over38      // instructions before the terminator.39      for (auto &Inst :40           make_early_inc_range(make_range(BB.begin(), std::prev(BB.end())))) {41        if (!shouldAlwaysKeep(Inst) && !O.shouldKeep()) {42          Inst.replaceAllUsesWith(isa<AllocaInst>(Inst)43                                      ? PoisonValue::get(Inst.getType())44                                      : getDefaultValue(Inst.getType()));45          Inst.eraseFromParent();46        }47      }48    }49  }50}51