[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / tools / llvm-reduce / deltas / ReduceUsingSimplifyCFG.cpp
blobc49fcb9855d416eebc183c1953cbb97d5e8da39e
1 //===- ReduceUsingSimplifyCFG.h - 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 call SimplifyCFG on individual basic blocks.
12 //===----------------------------------------------------------------------===//
14 #include "ReduceUsingSimplifyCFG.h"
15 #include "llvm/Analysis/TargetTransformInfo.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/Transforms/Utils/Local.h"
20 using namespace llvm;
22 static void reduceUsingSimplifyCFG(Oracle &O, ReducerWorkItem &WorkItem) {
23 Module &Program = WorkItem.getModule();
24 SmallVector<BasicBlock *, 16> ToSimplify;
25 for (auto &F : Program)
26 for (auto &BB : F)
27 if (!O.shouldKeep())
28 ToSimplify.push_back(&BB);
29 TargetTransformInfo TTI(Program.getDataLayout());
30 for (auto *BB : ToSimplify)
31 simplifyCFG(BB, TTI);
34 void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner &Test) {
35 runDeltaPass(Test, reduceUsingSimplifyCFG, "Reducing using SimplifyCFG");
37 static void reduceConditionals(Oracle &O, ReducerWorkItem &WorkItem,
38 bool Direction) {
39 Module &M = WorkItem.getModule();
40 SmallVector<BasicBlock *, 16> ToSimplify;
42 for (auto &F : M) {
43 for (auto &BB : F) {
44 auto *BR = dyn_cast<BranchInst>(BB.getTerminator());
45 if (!BR || !BR->isConditional() || O.shouldKeep())
46 continue;
48 if (Direction)
49 BR->setCondition(ConstantInt::getTrue(BR->getContext()));
50 else
51 BR->setCondition(ConstantInt::getFalse(BR->getContext()));
53 ToSimplify.push_back(&BB);
57 TargetTransformInfo TTI(M.getDataLayout());
58 for (auto *BB : ToSimplify)
59 simplifyCFG(BB, TTI);
62 void llvm::reduceConditionalsTrueDeltaPass(TestRunner &Test) {
63 runDeltaPass(
64 Test,
65 [](Oracle &O, ReducerWorkItem &WorkItem) {
66 reduceConditionals(O, WorkItem, true);
68 "Reducing conditional branches to true");
71 void llvm::reduceConditionalsFalseDeltaPass(TestRunner &Test) {
72 runDeltaPass(
73 Test,
74 [](Oracle &O, ReducerWorkItem &WorkItem) {
75 reduceConditionals(O, WorkItem, false);
77 "Reducing conditional branches to false");