xref: /llvm-project/llvm/tools/llvm-reduce/deltas/ReduceInvokes.cpp (revision 333ffafb4500cad19aec81e841686ade1f31f67f)
1 //===- ReduceInvokes.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 // Try to replace invokes with calls.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "ReduceInvokes.h"
14 #include "Delta.h"
15 #include "llvm/IR/Instructions.h"
16 #include "llvm/Transforms/Utils/Local.h"
17 
18 using namespace llvm;
19 
reduceInvokesInFunction(Oracle & O,Function & F)20 static void reduceInvokesInFunction(Oracle &O, Function &F) {
21   for (BasicBlock &BB : F) {
22     InvokeInst *Invoke = dyn_cast<InvokeInst>(BB.getTerminator());
23     if (Invoke && !O.shouldKeep())
24       changeToCall(Invoke);
25   }
26 
27   // TODO: We most likely are leaving behind dead landingpad blocks. Should we
28   // delete unreachable blocks now, or leave that for the unreachable block
29   // reduction.
30 }
31 
reduceInvokesInModule(Oracle & O,ReducerWorkItem & WorkItem)32 static void reduceInvokesInModule(Oracle &O, ReducerWorkItem &WorkItem) {
33   for (Function &F : WorkItem.getModule()) {
34     if (F.hasPersonalityFn())
35       reduceInvokesInFunction(O, F);
36   }
37 }
38 
reduceInvokesDeltaPass(TestRunner & Test)39 void llvm::reduceInvokesDeltaPass(TestRunner &Test) {
40   runDeltaPass(Test, reduceInvokesInModule, "Reducing Invokes");
41 }
42