Matt Arsenault a455c91601 llvm-reduce: Add reduction for invokes
Main thing I was unsure about was to whether try to delete the now
dead landing blocks, or leave that for the unreachable block reduction.

Personality function is not reduced, but that should be a separate
reduction on the function.

Fixes #58815
2023-01-03 17:03:44 -05:00

40 lines
1.3 KiB
C++

//===- ReduceInvokes.cpp - Specialized Delta Pass -------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Try to replace invokes with calls.
//
//===----------------------------------------------------------------------===//
#include "ReduceInvokes.h"
#include "Delta.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Transforms/Utils/Local.h"
static void reduceInvokesInFunction(Oracle &O, Function &F) {
for (BasicBlock &BB : F) {
InvokeInst *Invoke = dyn_cast<InvokeInst>(BB.getTerminator());
if (Invoke && !O.shouldKeep())
changeToCall(Invoke);
}
// TODO: We most likely are leaving behind dead landingpad blocks. Should we
// delete unreachable blocks now, or leave that for the unreachable block
// reduction.
}
static void reduceInvokesInModule(Oracle &O, Module &Mod) {
for (Function &F : Mod) {
if (F.hasPersonalityFn())
reduceInvokesInFunction(O, F);
}
}
void llvm::reduceInvokesDeltaPass(TestRunner &Test) {
runDeltaPass(Test, reduceInvokesInModule, "Reducing Invokes");
}